Example #1
0
        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);
                }
            }
        }