コード例 #1
0
        public void UpdateIsTop(int value, int x, int y, int z)
        {
            Terrain terrain = base.SubsystemTerrain.Terrain;

            if (y < 255)
            {
                TerrainChunk chunkAtCell = terrain.GetChunkAtCell(x, z);
                if (chunkAtCell != null)
                {
                    int  num      = TerrainChunk.CalculateCellIndex(x & 0xF, y, z & 0xF);
                    int  contents = Terrain.ExtractContents(chunkAtCell.GetCellValueFast(num + 1));
                    int  data     = Terrain.ExtractData(value);
                    bool isTop    = !m_fluidBlock.IsTheSameFluid(contents);
                    chunkAtCell.SetCellValueFast(num, Terrain.ReplaceData(value, FluidBlock.SetIsTop(data, isTop)));
                }
            }
        }
コード例 #2
0
 public void SpreadFluid()
 {
     for (int i = 0; i < 2; i++)
     {
         foreach (Point3 key in m_toUpdate.Keys)
         {
             int x         = key.X;
             int y         = key.Y;
             int z         = key.Z;
             int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(x, y, z);
             int contents  = Terrain.ExtractContents(cellValue);
             int data      = Terrain.ExtractData(cellValue);
             int level     = FluidBlock.GetLevel(data);
             if (m_fluidBlock.IsTheSameFluid(contents))
             {
                 int cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(x, y - 1, z);
                 int contents2  = Terrain.ExtractContents(cellValue2);
                 int data2      = Terrain.ExtractData(cellValue2);
                 int level2     = FluidBlock.GetLevel(data2);
                 int num        = m_fluidBlock.MaxLevel + 1;
                 int num2       = 0;
                 for (int j = 0; j < 4; j++)
                 {
                     int cellValue3 = base.SubsystemTerrain.Terrain.GetCellValue(x + m_sideNeighbors[j].X, y, z + m_sideNeighbors[j].Y);
                     int contents3  = Terrain.ExtractContents(cellValue3);
                     if (m_fluidBlock.IsTheSameFluid(contents3))
                     {
                         int level3 = FluidBlock.GetLevel(Terrain.ExtractData(cellValue3));
                         num = MathUtils.Min(num, level3);
                         if (level3 == 0)
                         {
                             num2++;
                         }
                     }
                 }
                 if (level != 0 && level <= num)
                 {
                     int contents4 = Terrain.ExtractContents(base.SubsystemTerrain.Terrain.GetCellValue(x, y + 1, z));
                     if (!m_fluidBlock.IsTheSameFluid(contents4))
                     {
                         if (num + 1 > m_fluidBlock.MaxLevel)
                         {
                             Set(x, y, z, 0);
                         }
                         else
                         {
                             Set(x, y, z, Terrain.MakeBlockValue(contents, 0, FluidBlock.SetLevel(data, num + 1)));
                         }
                         continue;
                     }
                 }
                 if (m_generateSources && level != 0 && num2 >= 2)
                 {
                     Set(x, y, z, Terrain.MakeBlockValue(contents, 0, FluidBlock.SetLevel(data, 0)));
                 }
                 else if (m_fluidBlock.IsTheSameFluid(contents2))
                 {
                     if (level2 > 1)
                     {
                         Set(x, y - 1, z, Terrain.MakeBlockValue(contents2, 0, FluidBlock.SetLevel(data2, 1)));
                     }
                 }
                 else if (!OnFluidInteract(cellValue2, x, y - 1, z, Terrain.MakeBlockValue(m_fluidBlock.BlockIndex, 0, FluidBlock.SetLevel(0, 1))) && level < m_fluidBlock.MaxLevel)
                 {
                     m_visited.Clear();
                     int num3 = LevelAtNearestFall(x + 1, y, z, level + 1, m_visited);
                     int num4 = LevelAtNearestFall(x - 1, y, z, level + 1, m_visited);
                     int num5 = LevelAtNearestFall(x, y, z + 1, level + 1, m_visited);
                     int num6 = LevelAtNearestFall(x, y, z - 1, level + 1, m_visited);
                     int num7 = MathUtils.Min(num3, num4, num5, num6);
                     if (num3 == num7)
                     {
                         FlowTo(x + 1, y, z, level + 1);
                         FlowTo(x, y, z - 1, m_fluidBlock.MaxLevel);
                         FlowTo(x, y, z + 1, m_fluidBlock.MaxLevel);
                     }
                     if (num4 == num7)
                     {
                         FlowTo(x - 1, y, z, level + 1);
                         FlowTo(x, y, z - 1, m_fluidBlock.MaxLevel);
                         FlowTo(x, y, z + 1, m_fluidBlock.MaxLevel);
                     }
                     if (num5 == num7)
                     {
                         FlowTo(x, y, z + 1, level + 1);
                         FlowTo(x - 1, y, z, m_fluidBlock.MaxLevel);
                         FlowTo(x + 1, y, z, m_fluidBlock.MaxLevel);
                     }
                     if (num6 == num7)
                     {
                         FlowTo(x, y, z - 1, level + 1);
                         FlowTo(x - 1, y, z, m_fluidBlock.MaxLevel);
                         FlowTo(x + 1, y, z, m_fluidBlock.MaxLevel);
                     }
                 }
             }
         }
         m_toUpdate.Clear();
         foreach (KeyValuePair <Point3, int> item in m_toSet)
         {
             int        x2           = item.Key.X;
             int        y2           = item.Key.Y;
             int        z2           = item.Key.Z;
             int        value        = item.Value;
             int        contents5    = Terrain.ExtractContents(item.Value);
             int        cellContents = base.SubsystemTerrain.Terrain.GetCellContents(x2, y2, z2);
             FluidBlock fluidBlock   = BlocksManager.FluidBlocks[cellContents];
             if (fluidBlock != null && !fluidBlock.IsTheSameFluid(contents5))
             {
                 base.SubsystemTerrain.DestroyCell(0, x2, y2, z2, value, noDrop: false, noParticleSystem: false);
             }
             else
             {
                 base.SubsystemTerrain.ChangeCell(x2, y2, z2, value);
             }
         }
         m_toSet.Clear();
         base.SubsystemTerrain.ProcessModifiedCells();
     }
 }