public void ChangeCell(int x, int y, int z, int value, bool updateModificationCounter = true) { if (!Terrain.IsCellValid(x, y, z)) { return; } int cellValueFast = Terrain.GetCellValueFast(x, y, z); value = Terrain.ReplaceLight(value, 0); cellValueFast = Terrain.ReplaceLight(cellValueFast, 0); if (value == cellValueFast) { return; } Terrain.SetCellValueFast(x, y, z, value); TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x, z); if (chunkAtCell != null) { if (updateModificationCounter) { chunkAtCell.ModificationCounter++; } TerrainUpdater.DowngradeChunkNeighborhoodState(chunkAtCell.Coords, 1, TerrainChunkState.InvalidLight, forceGeometryRegeneration: false); } m_modifiedCells[new Point3(x, y, z)] = true; int num = Terrain.ExtractContents(cellValueFast); int num2 = Terrain.ExtractContents(value); if (num2 != num) { SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num); for (int i = 0; i < blockBehaviors.Length; i++) { blockBehaviors[i].OnBlockRemoved(cellValueFast, value, x, y, z); } SubsystemBlockBehavior[] blockBehaviors2 = m_subsystemBlockBehaviors.GetBlockBehaviors(num2); for (int j = 0; j < blockBehaviors2.Length; j++) { blockBehaviors2[j].OnBlockAdded(value, cellValueFast, x, y, z); } } else { SubsystemBlockBehavior[] blockBehaviors3 = m_subsystemBlockBehaviors.GetBlockBehaviors(num2); for (int k = 0; k < blockBehaviors3.Length; k++) { blockBehaviors3[k].OnBlockModified(value, cellValueFast, x, y, z); } } }
public void PaintFastSelective(Terrain terrain, int x, int y, int z, int minX, int maxX, int minY, int maxY, int minZ, int maxZ, int onlyInValue) { Cell[] cells = Cells; for (int i = 0; i < cells.Length; i++) { Cell cell = cells[i]; int num = cell.X + x; int num2 = cell.Y + y; int num3 = cell.Z + z; if (num >= minX && num < maxX && num2 >= minY && num2 < maxY && num3 >= minZ && num3 < maxZ) { int cellValueFast = terrain.GetCellValueFast(num, num2, num3); if (onlyInValue == cellValueFast) { terrain.SetCellValueFast(num, num2, num3, cell.Value); } } } }
public void GenerateFluidTerrainVertices(BlockGeometryGenerator generator, int value, int x, int y, int z, Color sideColor, Color topColor, TerrainGeometrySubset[] subset) { int data = Terrain.ExtractData(value); if (GetIsTop(data)) { Terrain terrain = generator.Terrain; int cellValueFast = terrain.GetCellValueFast(x - 1, y, z - 1); int cellValueFast2 = terrain.GetCellValueFast(x, y, z - 1); int cellValueFast3 = terrain.GetCellValueFast(x + 1, y, z - 1); int cellValueFast4 = terrain.GetCellValueFast(x - 1, y, z); int cellValueFast5 = terrain.GetCellValueFast(x + 1, y, z); int cellValueFast6 = terrain.GetCellValueFast(x - 1, y, z + 1); int cellValueFast7 = terrain.GetCellValueFast(x, y, z + 1); int cellValueFast8 = terrain.GetCellValueFast(x + 1, y, z + 1); float h = CalculateNeighborHeight(cellValueFast); float num = CalculateNeighborHeight(cellValueFast2); float h2 = CalculateNeighborHeight(cellValueFast3); float num2 = CalculateNeighborHeight(cellValueFast4); float num3 = CalculateNeighborHeight(cellValueFast5); float h3 = CalculateNeighborHeight(cellValueFast6); float num4 = CalculateNeighborHeight(cellValueFast7); float h4 = CalculateNeighborHeight(cellValueFast8); float levelHeight = GetLevelHeight(GetLevel(data)); float height = CalculateFluidVertexHeight(h, num, num2, levelHeight); float height2 = CalculateFluidVertexHeight(num, h2, levelHeight, num3); float height3 = CalculateFluidVertexHeight(levelHeight, num3, num4, h4); float height4 = CalculateFluidVertexHeight(num2, levelHeight, h3, num4); float x2 = ZeroSubst(num3, levelHeight) - ZeroSubst(num2, levelHeight); float x3 = ZeroSubst(num4, levelHeight) - ZeroSubst(num, levelHeight); int overrideTopTextureSlot = DefaultTextureSlot - (int)MathUtils.Sign(x2) - 16 * (int)MathUtils.Sign(x3); generator.GenerateCubeVertices(this, value, x, y, z, height, height2, height3, height4, sideColor, topColor, topColor, topColor, topColor, overrideTopTextureSlot, subset); } else { generator.GenerateCubeVertices(this, value, x, y, z, sideColor, subset); } }
public virtual Device GetDevice(Terrain terrain, int x, int y, int z) { int value = terrain.GetCellValueFast(x, y, z); var device = GetItem(ref value); return (device is Device d) ? d.Create(new Point3(x, y, z)) : null; }
public static bool IsPowered(Terrain terrain, int x, int y, int z) { var chunk = terrain.GetChunkAtCell(x, z); if (y < 0 || y > 127 || chunk == null) { return(false); } int cellValue = terrain.GetCellValueFast(x + 1, y, z); if (FurnaceNBlock.GetHeatLevel(cellValue) != 0) { cellValue = Terrain.ExtractContents(cellValue); if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index) { return(true); } } cellValue = terrain.GetCellValueFast(x - 1, y, z); if (FurnaceNBlock.GetHeatLevel(cellValue) != 0) { cellValue = Terrain.ExtractContents(cellValue); if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index) { return(true); } } if (y < 127) { cellValue = chunk.GetCellValueFast(x & 15, y + 1, z & 15); if (FurnaceNBlock.GetHeatLevel(cellValue) != 0) { cellValue = Terrain.ExtractContents(cellValue); if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index) { return(true); } } } if (y > 0) { cellValue = chunk.GetCellValueFast(x & 15, y - 1, z & 15); if (FurnaceNBlock.GetHeatLevel(cellValue) != 0) { cellValue = Terrain.ExtractContents(cellValue); if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index) { return(true); } } } cellValue = terrain.GetCellValueFast(x, y, z + 1); if (FurnaceNBlock.GetHeatLevel(cellValue) != 0) { cellValue = Terrain.ExtractContents(cellValue); if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index) { return(true); } } cellValue = terrain.GetCellValueFast(x, y, z - 1); if (FurnaceNBlock.GetHeatLevel(cellValue) != 0) { cellValue = Terrain.ExtractContents(cellValue); if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index) { return(true); } } return(false); }