public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Wire"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Wire").ParentBone); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Wire").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(0.9375f, 0f, 0f)); for (int i = 0; i < 6; i++) { Vector3 v = CellFace.FaceToVector3(i); Vector3 v2 = new Vector3(0.5f, 0.5f, 0.5f) - 0.5f * v; Vector3 v3; Vector3 v4; if (v.X != 0f) { v3 = new Vector3(0f, 1f, 0f); v4 = new Vector3(0f, 0f, 1f); } else if (v.Y != 0f) { v3 = new Vector3(1f, 0f, 0f); v4 = new Vector3(0f, 0f, 1f); } else { v3 = new Vector3(1f, 0f, 0f); v4 = new Vector3(0f, 1f, 0f); } Vector3 v5 = v2 - 0.5f * v3 - 0.5f * v4; Vector3 v6 = v2 + 0.5f * v3 + 0.5f * v4 + 0.05f * v; m_collisionBoxesByFace[i] = new BoundingBox(Vector3.Min(v5, v6), Vector3.Max(v5, v6)); } }
public Pipe(int id = 0) : base("Pipe" + id.ToString()) { var model = ContentManager.Get <Model>("Models/Battery"); var meshes = new BlockMesh[6]; int i; BlockMesh blockMesh; ModelMeshPart meshPart = model.FindMesh("Battery").MeshParts[0]; Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Battery").ParentBone); for (i = 0; i < 6; i++) { blockMesh = new BlockMesh(); var vector = CellFace.FaceToVector3(i); blockMesh.AppendModelMeshPart(meshPart, boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.2f, 0f) * Matrix.CreateScale(1f, 0.66f, 1f) * ((i < 4) ? (Matrix.CreateTranslation(0f, -0.5f, 0f) * Matrix.CreateRotationX(i * 3.14159274f / 2f + 3.14159274f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)) : ((i != 4) ? (Matrix.CreateTranslation(0f, -0.5f, 0f) * Matrix.CreateRotationZ(-1.57079637f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)) : (Matrix.CreateTranslation(0f, -0.5f, 0f) * Matrix.CreateRotationZ(1.57079637f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)))), false, false, false, false, Color.LightGray); blockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(-2f / 16f, 4f / 16f, 0f)); blockMesh.TransformPositions(Matrix.CreateTranslation(new Vector3(0.5f))); meshes[i] = blockMesh; } for (i = 0; i < 63; i++) { Meshes[i] = new BlockMesh(); for (int j = 0; j < 6; j++) { if (((i + 1) >> j & 1) != 0) { Meshes[i].AppendBlockMesh(meshes[j]); } } } }
public override void OnAdded() { CellFace cellFace = base.CellFaces[0]; int data = Terrain.ExtractData(base.SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z)); int mountingFace = SevenSegmentDisplayBlock.GetMountingFace(data); m_color = LedBlock.LedColors[SevenSegmentDisplayBlock.GetColor(data)]; for (int i = 0; i < 7; i++) { Vector3 v = new Vector3((float)cellFace.X + 0.5f, (float)cellFace.Y + 0.5f, (float)cellFace.Z + 0.5f); Vector3 vector = CellFace.FaceToVector3(mountingFace); Vector3 vector2 = (mountingFace < 4) ? Vector3.UnitY : Vector3.UnitX; Vector3 v2 = Vector3.Cross(vector, vector2); m_glowPoints[i] = m_subsystemGlow.AddGlowPoint(); m_glowPoints[i].Position = v - 0.4375f * CellFace.FaceToVector3(mountingFace) + m_centers[i].X * 0.0625f * v2 + m_centers[i].Y * 0.0625f * vector2; m_glowPoints[i].Forward = vector; m_glowPoints[i].Right = v2 * m_sizes[i].X * 0.0625f; m_glowPoints[i].Up = vector2 * m_sizes[i].Y * 0.0625f; m_glowPoints[i].Color = Color.Transparent; m_glowPoints[i].Size = 1.35f; m_glowPoints[i].FarSize = 1.35f; m_glowPoints[i].FarDistance = 1f; m_glowPoints[i].Type = ((m_sizes[i].X > m_sizes[i].Y) ? GlowPointType.HorizontalRectangle : GlowPointType.VerticalRectangle); } }
public override void OnAdded() { CellFace cellFace = base.CellFaces[0]; int data = Terrain.ExtractData(base.SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z)); int mountingFace = FourLedBlock.GetMountingFace(data); m_color = LedBlock.LedColors[FourLedBlock.GetColor(data)]; for (int i = 0; i < 4; i++) { int num = (i % 2 == 0) ? 1 : (-1); int num2 = (i / 2 == 0) ? 1 : (-1); Vector3 v = new Vector3((float)cellFace.X + 0.5f, (float)cellFace.Y + 0.5f, (float)cellFace.Z + 0.5f); Vector3 vector = CellFace.FaceToVector3(mountingFace); Vector3 vector2 = (mountingFace < 4) ? Vector3.UnitY : Vector3.UnitX; Vector3 vector3 = Vector3.Cross(vector, vector2); m_glowPoints[i] = m_subsystemGlow.AddGlowPoint(); m_glowPoints[i].Position = v - 0.4375f * CellFace.FaceToVector3(mountingFace) + 0.25f * vector3 * num + 0.25f * vector2 * num2; m_glowPoints[i].Forward = vector; m_glowPoints[i].Up = vector2; m_glowPoints[i].Right = vector3; m_glowPoints[i].Color = Color.Transparent; m_glowPoints[i].Size = 0.26f; m_glowPoints[i].FarSize = 0.26f; m_glowPoints[i].FarDistance = 1f; m_glowPoints[i].Type = GlowPointType.Square; } }
public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem) { if (!ComponentEngine.IsPowered(Utils.Terrain, cellFace.X, cellFace.Y, cellFace.Z) || worldItem.Velocity.Length() < 20f) { return; } int l; Vector3 v = CellFace.FaceToVector3(cellFace.Face); var position = new Vector3(cellFace.Point) + new Vector3(0.5f) - 0.75f * v; if (Terrain.ExtractContents(worldItem.Value) == 6) { for (l = 0; l < 5; l++) { Utils.SubsystemProjectiles.FireProjectile(79, position, -20f * v, Vector3.Zero, null); } worldItem.ToRemove = true; } else { var list = new List <BlockDropValue>(8); BlocksManager.Blocks[Terrain.ExtractContents(worldItem.Value)].GetDropValues(SubsystemTerrain, worldItem.Value, 0, 3, list, out bool s); for (l = 0; l < list.Count; l++) { var blockDropValue = list[l]; for (int i = 0; i <= blockDropValue.Count; i++) { Utils.SubsystemProjectiles.FireProjectile(blockDropValue.Value, position, -20f * v, Vector3.Zero, null); } } worldItem.ToRemove = true; } }
public WireDevice() { for (int i = 0; i < 6; i++) { Vector3 vector = CellFace.FaceToVector3(i); Vector3 v2; Vector3 v3; if (vector.X != 0f) { v2 = new Vector3(0f, 1f, 0f); v3 = new Vector3(0f, 0f, 1f); } else if (vector.Y != 0f) { v2 = new Vector3(1f, 0f, 0f); v3 = new Vector3(0f, 0f, 1f); } else { v2 = new Vector3(1f, 0f, 0f); v3 = new Vector3(0f, 1f, 0f); } Vector3 v = new Vector3(0.5f, 0.5f, 0.5f) - 0.5f * vector; Vector3 v4 = v - 0.5f * v2 - 0.5f * v3; Vector3 v5 = v + 0.5f * v2 + 0.5f * v3 + 0.05f * vector; m_collisionBoxesByFace[i] = new BoundingBox(Vector3.Min(v4, v5), Vector3.Max(v4, v5)); } }
public SoundGeneratorElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) : base(subsystemElectricity, cellFace) { m_subsystemNoise = subsystemElectricity.Project.FindSubsystem <SubsystemNoise>(throwOnError: true); m_subsystemParticles = subsystemElectricity.Project.FindSubsystem <SubsystemParticles>(throwOnError: true); Vector3 vector = CellFace.FaceToVector3(cellFace.Face); Vector3 position = new Vector3(cellFace.Point) + new Vector3(0.5f) - 0.2f * vector; m_particleSystem = new SoundParticleSystem(subsystemElectricity.SubsystemTerrain, position, vector); }
public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem) { if (worldItem.ToRemove) { return; } Vector3 v = CellFace.FaceToVector3((SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z) - DiversionBlock.Index) >> 14); Utils.SubsystemProjectiles.FireProjectile(worldItem.Value, new Vector3(cellFace.X + 0.5f, cellFace.Y + 0.5f, cellFace.Z + 0.5f) + 0.75f * v, 30f * v, Vector3.Zero, null); worldItem.ToRemove = true; }
public MotionDetectorElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) : base(subsystemElectricity, cellFace) { m_subsystemBodies = subsystemElectricity.Project.FindSubsystem <SubsystemBodies>(throwOnError: true); m_center = new Vector3(cellFace.X, cellFace.Y, cellFace.Z) + new Vector3(0.5f) - 0.25f * m_direction; m_direction = CellFace.FaceToVector3(cellFace.Face); Vector3 vector = Vector3.One - new Vector3(MathUtils.Abs(m_direction.X), MathUtils.Abs(m_direction.Y), MathUtils.Abs(m_direction.Z)); Vector3 vector2 = m_center - 8f * vector; Vector3 vector3 = m_center + 8f * (vector + m_direction); m_corner1 = new Vector2(vector2.X, vector2.Z); m_corner2 = new Vector2(vector3.X, vector3.Z); }
public bool Place(Vector3 position, int face, int value) { var result = Utils.SubsystemTerrain.Raycast(position, position + CellFace.FaceToVector3(face) * 8f, true, true, null); var componentMiner = SubsystemPlayers.FindNearestPlayer(position).ComponentMiner; if (result.HasValue && componentMiner.Place(result.Value, value)) { if (componentMiner.ComponentCreature.PlayerStats != null) { componentMiner.ComponentCreature.PlayerStats.BlocksPlaced--; } return(true); } return(false); }
public override void OnAdded() { m_glowPoint = m_subsystemGlow.AddGlowPoint(); CellFace cellFace = base.CellFaces[0]; int mountingFace = MulticoloredLedBlock.GetMountingFace(Terrain.ExtractData(base.SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z))); Vector3 v = new Vector3((float)cellFace.X + 0.5f, (float)cellFace.Y + 0.5f, (float)cellFace.Z + 0.5f); m_glowPoint.Position = v - 0.4375f * CellFace.FaceToVector3(mountingFace); m_glowPoint.Forward = CellFace.FaceToVector3(mountingFace); m_glowPoint.Up = ((mountingFace < 4) ? Vector3.UnitY : Vector3.UnitX); m_glowPoint.Right = Vector3.Cross(m_glowPoint.Forward, m_glowPoint.Up); m_glowPoint.Color = Color.Transparent; m_glowPoint.Size = 0.0324f; m_glowPoint.FarSize = 0.0324f; m_glowPoint.FarDistance = 0f; m_glowPoint.Type = GlowPointType.Square; }
protected void DispenseItem(Point3 point, int face, int value, MachineMode mode) { Vector3 vector = CellFace.FaceToVector3(face); var vector2 = new Vector3(point) + new Vector3(0.5f) + 0.6f * vector; if (mode != 0) { if (Utils.SubsystemProjectiles.FireProjectile(value, vector2, 1f * m_random.UniformFloat(39f, 41f) * (vector + m_random.Vector3(0.025f, false) + new Vector3(0f, 0.05f, 0f)), Vector3.Zero, null) != null) { Utils.SubsystemAudio.PlaySound("Audio/DispenserShoot", 1f, 0f, vector2, 4f, true); } else { DispenseItem(point, face, value, MachineMode.Dispense); } } }
public static void CalculateLightingTables() { float x = MathUtils.Lerp(0f, 0.1f, SettingsManager.Brightness); for (int i = 0; i < 16; i++) { LightIntensityByLightValue[i] = MathUtils.Saturate(MathUtils.Lerp(x, 1f, MathUtils.Pow((float)i / 15f, 1.25f))); } for (int j = 0; j < 6; j++) { float num = CalculateLighting(CellFace.FaceToVector3(j)); for (int k = 0; k < 16; k++) { LightIntensityByLightValueAndFace[k + j * 16] = LightIntensityByLightValue[k] * num; } } }
public bool Place() { Point3 coordinates = m_componentBlockEntity.Coordinates; int cellValue = Utils.Terrain.GetCellValue(coordinates.X, coordinates.Y, coordinates.Z); if (Terrain.ExtractContents(cellValue) != Bullet2Block.Index || (Terrain.ExtractData(cellValue) >> 10) == 0) { return(false); } int num = 0; int slotValue; while (true) { if (num >= SlotsCount - 1) { return(false); } slotValue = GetSlotValue(num); int slotCount = GetSlotCount(num); if (slotValue != 0 && slotCount > 0) { break; } num++; } int face = FourDirectionalBlock.GetDirection(cellValue); for (num = RemoveSlotItems(num, 1); num-- > 0;) { var position = new Vector3(coordinates) + new Vector3(0.5f); Vector3 vector = CellFace.FaceToVector3(face); if (!Place(position + vector, face, slotValue) && DispenseItem) { Vector3 vector2 = position + 0.6f * vector; Utils.SubsystemPickables.AddPickable(slotValue, 1, vector2, 1.8f * (vector + m_random.Vector3(0.2f, false)), null); Utils.SubsystemAudio.PlaySound("Audio/DispenserDispense", 1f, 0f, new Vector3(vector2.X, vector2.Y, vector2.Z), 3f, true); } } return(true); }
public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult) { Vector3 forward = Matrix.CreateFromQuaternion(componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation).Forward; float num = float.NegativeInfinity; int cutFace = 0; for (int i = 0; i < 6; i++) { float num2 = Vector3.Dot(CellFace.FaceToVector3(i), forward); if (num2 > num) { num = num2; cutFace = i; } } BlockPlacementData result = default(BlockPlacementData); result.Value = Terrain.MakeBlockValue(BlockIndex, 0, SetCutFace(0, cutFace)); result.CellFace = raycastResult.CellFace; return(result); }
public void DispenseItem(Point3 point, int face, int value, DispenserBlock.Mode mode) { Vector3 vector = CellFace.FaceToVector3(face); Vector3 position = new Vector3((float)point.X + 0.5f, (float)point.Y + 0.5f, (float)point.Z + 0.5f) + 0.6f * vector; if (mode == DispenserBlock.Mode.Dispense) { float s = 1.8f; m_subsystemPickables.AddPickable(value, 1, position, s * (vector + m_random.Vector3(0.2f)), null); m_subsystemAudio.PlaySound("Audio/DispenserDispense", 1f, 0f, new Vector3(position.X, position.Y, position.Z), 3f, autoDelay: true); return; } float s2 = m_random.Float(39f, 41f); if (m_subsystemProjectiles.FireProjectile(value, position, s2 * (vector + m_random.Vector3(0.025f) + new Vector3(0f, 0.05f, 0f)), Vector3.Zero, null) != null) { m_subsystemAudio.PlaySound("Audio/DispenserShoot", 1f, 0f, new Vector3(position.X, position.Y, position.Z), 4f, autoDelay: true); } else { DispenseItem(point, face, value, DispenserBlock.Mode.Dispense); } }
public override void OnAdded() { CellFace cellFace = base.CellFaces[0]; int data = Terrain.ExtractData(base.SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z)); int mountingFace = FourLedBlock.GetMountingFace(data); m_color = LedBlock.LedColors[FourLedBlock.GetColor(data)]; Vector3 v = new Vector3((float)cellFace.X + 0.5f, (float)cellFace.Y + 0.5f, (float)cellFace.Z + 0.5f); Vector3 vector = CellFace.FaceToVector3(mountingFace); Vector3 vector2 = (mountingFace < 4) ? Vector3.UnitY : Vector3.UnitX; Vector3 right = Vector3.Cross(vector, vector2); m_glowPoint = m_subsystemGlow.AddGlowPoint(); m_glowPoint.Position = v - 0.4375f * CellFace.FaceToVector3(mountingFace); m_glowPoint.Forward = vector; m_glowPoint.Up = vector2; m_glowPoint.Right = right; m_glowPoint.Color = Color.Transparent; m_glowPoint.Size = 0.52f; m_glowPoint.FarSize = 0.52f; m_glowPoint.FarDistance = 1f; m_glowPoint.Type = GlowPointType.Square; }
public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { IInventory inventory = componentMiner.Inventory; int activeBlockValue = componentMiner.ActiveBlockValue; int num = Terrain.ExtractContents(activeBlockValue); if (num == 90) { object obj = componentMiner.Raycast(ray, RaycastMode.Gathering); if (obj is TerrainRaycastResult) { CellFace cellFace = ((TerrainRaycastResult)obj).CellFace; int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z); int num2 = Terrain.ExtractContents(cellValue); int data = Terrain.ExtractData(cellValue); Block block = BlocksManager.Blocks[num2]; if (block is WaterBlock && FluidBlock.GetLevel(data) == 0) { int value = Terrain.ReplaceContents(activeBlockValue, 91); inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex)); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { inventory.AddSlotItems(inventory.ActiveSlotIndex, value, 1); } base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false); return(true); } if (block is MagmaBlock && FluidBlock.GetLevel(data) == 0) { int value2 = Terrain.ReplaceContents(activeBlockValue, 93); inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex)); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { inventory.AddSlotItems(inventory.ActiveSlotIndex, value2, 1); } base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false); return(true); } } else if (obj is BodyRaycastResult) { ComponentUdder componentUdder = ((BodyRaycastResult)obj).ComponentBody.Entity.FindComponent <ComponentUdder>(); if (componentUdder != null && componentUdder.Milk(componentMiner)) { int value3 = Terrain.ReplaceContents(activeBlockValue, 110); inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex)); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { inventory.AddSlotItems(inventory.ActiveSlotIndex, value3, 1); } m_subsystemAudio.PlaySound("Audio/Milked", 1f, 0f, ray.Position, 2f, autoDelay: true); } return(true); } } if (num == 91) { TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction); if (terrainRaycastResult.HasValue && componentMiner.Place(terrainRaycastResult.Value, Terrain.MakeBlockValue(18))) { inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { int value4 = Terrain.ReplaceContents(activeBlockValue, 90); inventory.AddSlotItems(inventory.ActiveSlotIndex, value4, 1); } return(true); } } if (num == 93) { TerrainRaycastResult?terrainRaycastResult2 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction); if (terrainRaycastResult2.HasValue) { if (componentMiner.Place(terrainRaycastResult2.Value, Terrain.MakeBlockValue(92))) { inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { int value5 = Terrain.ReplaceContents(activeBlockValue, 90); inventory.AddSlotItems(inventory.ActiveSlotIndex, value5, 1); } } return(true); } } switch (num) { case 110: case 245: return(true); case 251: case 252: return(true); case 128: case 129: { TerrainRaycastResult?terrainRaycastResult3 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Digging); if (terrainRaycastResult3.HasValue) { CellFace cellFace2 = terrainRaycastResult3.Value.CellFace; int cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z); int num3 = Terrain.ExtractContents(cellValue2); Block block2 = BlocksManager.Blocks[num3]; if (block2 is IPaintableBlock) { Vector3 normal = CellFace.FaceToVector3(terrainRaycastResult3.Value.CellFace.Face); Vector3 position = terrainRaycastResult3.Value.HitPoint(); int? num4 = (num == 128) ? null : new int?(PaintBucketBlock.GetColor(Terrain.ExtractData(activeBlockValue))); Color color = num4.HasValue ? SubsystemPalette.GetColor(base.SubsystemTerrain, num4) : new Color(128, 128, 128, 128); int value6 = ((IPaintableBlock)block2).Paint(base.SubsystemTerrain, cellValue2, num4); base.SubsystemTerrain.ChangeCell(cellFace2.X, cellFace2.Y, cellFace2.Z, value6); componentMiner.DamageActiveTool(1); m_subsystemAudio.PlayRandomSound("Audio/Paint", 0.4f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentBody.Position, 2f, autoDelay: true); m_subsystemParticles.AddParticleSystem(new PaintParticleSystem(base.SubsystemTerrain, position, normal, color)); } return(true); } break; } } return(false); }
public void DrawReticleHighlight(Camera camera) { if (camera.Eye.HasValue && m_highlightRaycastResult is TerrainRaycastResult) { TerrainRaycastResult terrainRaycastResult = (TerrainRaycastResult)m_highlightRaycastResult; Vector3 vector = terrainRaycastResult.HitPoint(); Vector3 vector2 = (!(BlocksManager.Blocks[Terrain.ExtractContents(terrainRaycastResult.Value)] is CrossBlock)) ? CellFace.FaceToVector3(terrainRaycastResult.CellFace.Face) : (-terrainRaycastResult.Ray.Direction); float num = Vector3.Distance(camera.ViewPosition, vector); float s = 0.03f + MathUtils.Min(0.008f * num, 0.04f); float s2 = 0.01f * num; Vector3 v = (MathUtils.Abs(Vector3.Dot(vector2, Vector3.UnitY)) < 0.5f) ? Vector3.UnitY : Vector3.UnitX; Vector3 vector3 = Vector3.Normalize(Vector3.Cross(vector2, v)); Vector3 v2 = Vector3.Normalize(Vector3.Cross(vector2, vector3)); Subtexture subtexture = ContentManager.Get <Subtexture>("Textures/Atlas/Reticle"); TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(subtexture.Texture, useAlphaTest: false, 0, DepthStencilState.DepthRead, null, null, SamplerState.LinearClamp); Vector3 p = vector + s * (-vector3 + v2) + s2 * vector2; Vector3 p2 = vector + s * (vector3 + v2) + s2 * vector2; Vector3 p3 = vector + s * (vector3 - v2) + s2 * vector2; Vector3 p4 = vector + s * (-vector3 - v2) + s2 * vector2; Vector2 texCoord = new Vector2(subtexture.TopLeft.X, subtexture.TopLeft.Y); Vector2 texCoord2 = new Vector2(subtexture.BottomRight.X, subtexture.TopLeft.Y); Vector2 texCoord3 = new Vector2(subtexture.BottomRight.X, subtexture.BottomRight.Y); Vector2 texCoord4 = new Vector2(subtexture.TopLeft.X, subtexture.BottomRight.Y); texturedBatch3D.QueueQuad(p, p2, p3, p4, texCoord, texCoord2, texCoord3, texCoord4, Color.White); texturedBatch3D.Flush(camera.ViewProjectionMatrix); } }
public static void GenerateWireVertices(BlockGeometryGenerator generator, int value, int x, int y, int z, int mountingFace, float centerBoxSize, Vector2 centerOffset, TerrainGeometrySubset subset) { var terrain = generator.Terrain; Color color = WireBlock.WireColor; int num = Terrain.ExtractContents(value); if (num == ElementBlock.Index) { int?color2 = PaintableItemBlock.GetColor(Terrain.ExtractData(value)); if (color2.HasValue) { color = SubsystemPalette.GetColor(generator, color2); } } float num3 = LightingManager.LightIntensityByLightValue[Terrain.ExtractLight(value)]; Vector3 v = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - 0.5f * CellFace.FaceToVector3(mountingFace); Vector3 vector = CellFace.FaceToVector3(mountingFace); var v2 = new Vector2(0.9376f, 0.0001f); var v3 = new Vector2(0.03125f, 0.00550781237f); Point3 point = CellFace.FaceToPoint3(mountingFace); int cellContents = terrain.GetCellContents(x - point.X, y - point.Y, z - point.Z); bool flag = cellContents == 2 || cellContents == 7 || cellContents == 8 || cellContents == 6 || cellContents == 62 || cellContents == 72; Vector3 v4 = CellFace.FaceToVector3(SubsystemElectricity.GetConnectorFace(mountingFace, ElectricConnectorDirection.Top)); Vector3 vector2 = CellFace.FaceToVector3(SubsystemElectricity.GetConnectorFace(mountingFace, ElectricConnectorDirection.Left)) * centerOffset.X + v4 * centerOffset.Y; int num4 = 0; var paths = new DynamicArray <ElectricConnectionPath>(); ElementBlock.Block.GetAllConnectedNeighbors(terrain, ElementBlock.Block.GetDevice(x, y, z, value), mountingFace, paths); foreach (ElectricConnectionPath tmpConnectionPath in paths) { if ((num4 & (1 << tmpConnectionPath.ConnectorFace)) == 0) { ElectricConnectorDirection?connectorDirection = SubsystemElectricity.GetConnectorDirection(mountingFace, 0, tmpConnectionPath.ConnectorFace); if (centerOffset != Vector2.Zero || connectorDirection != ElectricConnectorDirection.In) { num4 |= 1 << tmpConnectionPath.ConnectorFace; Color color3 = color; if (num != ElementBlock.Index) { int cellValue = terrain.GetCellValue(x + tmpConnectionPath.NeighborOffsetX, y + tmpConnectionPath.NeighborOffsetY, z + tmpConnectionPath.NeighborOffsetZ); if (Terrain.ExtractContents(cellValue) == ElementBlock.Index) { int?color4 = PaintableItemBlock.GetColor(Terrain.ExtractData(cellValue)); if (color4.HasValue) { color3 = SubsystemPalette.GetColor(generator, color4); } } } Vector3 vector3 = (connectorDirection != ElectricConnectorDirection.In) ? CellFace.FaceToVector3(tmpConnectionPath.ConnectorFace) : (-Vector3.Normalize(vector2)); var vector4 = Vector3.Cross(vector, vector3); float s = (centerBoxSize >= 0f) ? MathUtils.Max(0.03125f, centerBoxSize / 2f) : (centerBoxSize / 2f); float num5 = (connectorDirection == ElectricConnectorDirection.In) ? 0.03125f : 0.5f; float num6 = (connectorDirection == ElectricConnectorDirection.In) ? 0f : ((tmpConnectionPath.ConnectorFace == tmpConnectionPath.NeighborFace) ? (num5 + 0.03125f) : ((tmpConnectionPath.ConnectorFace != CellFace.OppositeFace(tmpConnectionPath.NeighborFace)) ? num5 : (num5 - 0.03125f))); Vector3 vector5 = v - vector4 * 0.03125f + vector3 * s + vector2; Vector3 vector6 = v - vector4 * 0.03125f + vector3 * num5; Vector3 vector7 = v + vector4 * 0.03125f + vector3 * num5; Vector3 vector8 = v + vector4 * 0.03125f + vector3 * s + vector2; Vector3 vector9 = v + vector * 0.03125f + vector3 * (centerBoxSize / 2f) + vector2; Vector3 vector10 = v + vector * 0.03125f + vector3 * num6; if (flag && centerBoxSize == 0f) { Vector3 v5 = 0.25f * BlockGeometryGenerator.GetRandomWireOffset(0.5f * (vector5 + vector8), vector); vector5 += v5; vector8 += v5; vector9 += v5; } Vector2 vector11 = v2 + v3 * new Vector2(MathUtils.Max(0.0625f, centerBoxSize), 0f); Vector2 vector12 = v2 + v3 * new Vector2(num5 * 2f, 0f); Vector2 vector13 = v2 + v3 * new Vector2(num5 * 2f, 1f); Vector2 vector14 = v2 + v3 * new Vector2(MathUtils.Max(0.0625f, centerBoxSize), 1f); Vector2 vector15 = v2 + v3 * new Vector2(centerBoxSize, 0.5f); Vector2 vector16 = v2 + v3 * new Vector2(num6 * 2f, 0.5f); float num9 = 0.5f * (num3 + LightingManager.LightIntensityByLightValue[Terrain.ExtractLight(terrain.GetCellValue(x + tmpConnectionPath.NeighborOffsetX, y + tmpConnectionPath.NeighborOffsetY, z + tmpConnectionPath.NeighborOffsetZ))]); float num10 = LightingManager.CalculateLighting(-vector4); float num11 = LightingManager.CalculateLighting(vector4); float num12 = LightingManager.CalculateLighting(vector); float num13 = num10 * num3; float num14 = num10 * num9; float num15 = num11 * num9; float num16 = num11 * num3; float num17 = num12 * num3; float num18 = num12 * num9; var color5 = new Color((byte)(color3.R * num13), (byte)(color3.G * num13), (byte)(color3.B * num13)); var color6 = new Color((byte)(color3.R * num14), (byte)(color3.G * num14), (byte)(color3.B * num14)); var color7 = new Color((byte)(color3.R * num15), (byte)(color3.G * num15), (byte)(color3.B * num15)); var color8 = new Color((byte)(color3.R * num16), (byte)(color3.G * num16), (byte)(color3.B * num16)); var color9 = new Color((byte)(color3.R * num17), (byte)(color3.G * num17), (byte)(color3.B * num17)); var color10 = new Color((byte)(color3.R * num18), (byte)(color3.G * num18), (byte)(color3.B * num18)); int count = subset.Vertices.Count; subset.Vertices.Count += 6; TerrainVertex[] array = subset.Vertices.Array; BlockGeometryGenerator.SetupVertex(vector5.X, vector5.Y, vector5.Z, color5, vector11.X, vector11.Y, ref array[count]); BlockGeometryGenerator.SetupVertex(vector6.X, vector6.Y, vector6.Z, color6, vector12.X, vector12.Y, ref array[count + 1]); BlockGeometryGenerator.SetupVertex(vector7.X, vector7.Y, vector7.Z, color7, vector13.X, vector13.Y, ref array[count + 2]); BlockGeometryGenerator.SetupVertex(vector8.X, vector8.Y, vector8.Z, color8, vector14.X, vector14.Y, ref array[count + 3]); BlockGeometryGenerator.SetupVertex(vector9.X, vector9.Y, vector9.Z, color9, vector15.X, vector15.Y, ref array[count + 4]); BlockGeometryGenerator.SetupVertex(vector10.X, vector10.Y, vector10.Z, color10, vector16.X, vector16.Y, ref array[count + 5]); int count2 = subset.Indices.Count; subset.Indices.Count += (connectorDirection == ElectricConnectorDirection.In) ? 15 : 12; ushort[] array2 = subset.Indices.Array; array2[count2] = (ushort)count; array2[count2 + 1] = (ushort)(count + 5); array2[count2 + 2] = (ushort)(count + 1); array2[count2 + 3] = (ushort)(count + 5); array2[count2 + 4] = (ushort)count; array2[count2 + 5] = (ushort)(count + 4); array2[count2 + 6] = (ushort)(count + 4); array2[count2 + 7] = (ushort)(count + 2); array2[count2 + 8] = (ushort)(count + 5); array2[count2 + 9] = (ushort)(count + 2); array2[count2 + 10] = (ushort)(count + 4); array2[count2 + 11] = (ushort)(count + 3); if (connectorDirection == ElectricConnectorDirection.In) { array2[count2 + 12] = (ushort)(count + 2); array2[count2 + 13] = (ushort)(count + 1); array2[count2 + 14] = (ushort)(count + 5); } } } } if (centerBoxSize == 0f && (num4 != 0 || (num == ElementBlock.Index && (Terrain.ExtractData(value) & 1023) == 5))) { for (int i = 0; i < 6; i++) { if (i != mountingFace && i != CellFace.OppositeFace(mountingFace) && (num4 & (1 << i)) == 0) { Vector3 vector17 = CellFace.FaceToVector3(i); var v6 = Vector3.Cross(vector, vector17); Vector3 vector18 = v - v6 * 0.03125f + vector17 * 0.03125f; Vector3 vector19 = v + v6 * 0.03125f + vector17 * 0.03125f; Vector3 vector20 = v + vector * 0.03125f; if (flag) { Vector3 v7 = 0.25f * BlockGeometryGenerator.GetRandomWireOffset(0.5f * (vector18 + vector19), vector); vector18 += v7; vector19 += v7; vector20 += v7; } Vector2 vector21 = v2 + v3 * new Vector2(0.0625f, 0f); Vector2 vector22 = v2 + v3 * new Vector2(0.0625f, 1f); Vector2 vector23 = v2 + v3 * new Vector2(0f, 0.5f); float num19 = LightingManager.CalculateLighting(vector17) * num3; float num20 = LightingManager.CalculateLighting(vector) * num3; var color11 = new Color((byte)(color.R * num19), (byte)(color.G * num19), (byte)(color.B * num19)); var color12 = new Color((byte)(color.R * num20), (byte)(color.G * num20), (byte)(color.B * num20)); int count3 = subset.Vertices.Count; subset.Vertices.Count += 3; var array3 = subset.Vertices.Array; BlockGeometryGenerator.SetupVertex(vector18.X, vector18.Y, vector18.Z, color11, vector21.X, vector21.Y, ref array3[count3]); BlockGeometryGenerator.SetupVertex(vector19.X, vector19.Y, vector19.Z, color11, vector22.X, vector22.Y, ref array3[count3 + 1]); BlockGeometryGenerator.SetupVertex(vector20.X, vector20.Y, vector20.Z, color12, vector23.X, vector23.Y, ref array3[count3 + 2]); int count4 = subset.Indices.Count; subset.Indices.Count += 3; ushort[] array4 = subset.Indices.Array; array4[count4] = (ushort)count3; array4[count4 + 1] = (ushort)(count3 + 2); array4[count4 + 2] = (ushort)(count3 + 1); } } } }
protected void Driller(Point3 point, int face) { Vector3 vector = CellFace.FaceToVector3(face); int x = point.X; int y = point.Y; int z = point.Z; int slotValue = GetSlotValue(8); if (!(ComponentEngine.IsPowered(Utils.Terrain, x, y, z) || Utils.SubsystemGameInfo.WorldSettings.GameMode == 0) || BlocksManager.Blocks[Terrain.ExtractContents(slotValue)].Durability <= 0) { return; } int[] array = new[] { 0, 0, 1, 1, 1, 0, -1, -1, -1 }, array2 = new[] { 0, -1, -1, 0, 1, 1, 1, 0, -1 }; int num2 = 0; Vector3 v = Vector3.Zero; for (int l = 1; l < 19; l++) { for (int m = 0; m < 9; m++) { x = point.X - (int)vector.X * l; y = point.Y - (int)vector.Y * l; z = point.Z - (int)vector.Z * l; if (vector.X != 0f) { y = point.Y + array[m]; z = point.Z + array2[m]; v = new Vector3(0f, array[m] / (float)l, array2[m] / (float)l); } if (vector.Y != 0f) { x = point.X + array[m]; z = point.Z + array2[m]; v = new Vector3(array[m] / (float)l, 0f, array2[m] / (float)l); } if (vector.Z != 0f) { x = point.X + array[m]; y = point.Y + array2[m]; v = new Vector3(array[m] / (float)l, array2[m] / (float)l, 0f); } int cellValue = Terrain.ReplaceLight(Utils.Terrain.GetCellValue(x, y, z), 0); Block block = BlocksManager.Blocks[Terrain.ExtractContents(cellValue)]; if (num2 == 0 && block.BlockIndex == 92) { num2 = 9; } if (block.IsPlaceable && !block.IsDiggingTransparent && !block.DefaultIsInteractive) { Utils.SubsystemTerrain.ChangeCell(x, y, z, 0, true); Utils.SubsystemProjectiles.FireProjectile(cellValue, new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - 0.25f * vector, 60f * (vector - v), Vector3.Zero, null); RemoveSlotItems(8, 1); AddSlotItems(8, BlocksManager.DamageItem(slotValue, 1 + num2), 1); return; } } } }
public Vector3 HitPoint(float offsetFromSurface = 0f) { return(Ray.Position + Ray.Direction * Distance + CellFace.FaceToVector3(CellFace.Face) * offsetFromSurface); }