Exemple #1
0
        public void FlowTo(int x, int y, int z, int level)
        {
            if (level > m_fluidBlock.MaxLevel)
            {
                return;
            }
            int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(x, y, z);
            int contents  = Terrain.ExtractContents(cellValue);
            int data      = Terrain.ExtractData(cellValue);

            if (m_fluidBlock.IsTheSameFluid(contents))
            {
                int level2 = FluidBlock.GetLevel(data);
                if (level < level2)
                {
                    Set(x, y, z, Terrain.MakeBlockValue(contents, 0, FluidBlock.SetLevel(data, level)));
                }
            }
            else
            {
                OnFluidInteract(cellValue, x, y, z, Terrain.MakeBlockValue(m_fluidBlock.BlockIndex, 0, FluidBlock.SetLevel(0, level)));
            }
        }
Exemple #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();
     }
 }
Exemple #3
0
 public override BlockPlacementData GetDigValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, int toolValue, TerrainRaycastResult raycastResult)
 {
     return(new BlockPlacementData
     {
         Value = (Terrain.ExtractData(value) & 65536) != 0 ? Terrain.ReplaceData(MagmaBlock.Index
                                                                                 , FluidBlock.SetIsTop(FluidBlock.SetLevel(0, 4), toolValue == MagmaBucketBlock.Index)) : 0,
         CellFace = raycastResult.CellFace
     });
 }