Esempio n. 1
0
 public void DrawSigns(Camera camera)
 {
     if (m_nearTexts.Count > 0)
     {
         TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(m_renderTarget, useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);
         foreach (TextData nearText in m_nearTexts)
         {
             if (nearText.TextureLocation.HasValue)
             {
                 int       cellValue = m_subsystemTerrain.Terrain.GetCellValue(nearText.Point.X, nearText.Point.Y, nearText.Point.Z);
                 int       num       = Terrain.ExtractContents(cellValue);
                 SignBlock signBlock = BlocksManager.Blocks[num] as SignBlock;
                 if (signBlock != null)
                 {
                     int       data = Terrain.ExtractData(cellValue);
                     BlockMesh signSurfaceBlockMesh = signBlock.GetSignSurfaceBlockMesh(data);
                     if (signSurfaceBlockMesh != null)
                     {
                         TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(nearText.Point.X, nearText.Point.Z);
                         if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                         {
                             nearText.Light = Terrain.ExtractLight(cellValue);
                         }
                         float   num2              = LightingManager.LightIntensityByLightValue[nearText.Light];
                         Color   color             = new Color(num2, num2, num2);
                         float   x                 = 0f;
                         float   x2                = nearText.UsedTextureWidth / 128f;
                         float   x3                = (float)nearText.TextureLocation.Value / 32f;
                         float   x4                = ((float)nearText.TextureLocation.Value + nearText.UsedTextureHeight / 32f) / 32f;
                         Vector3 signSurfaceNormal = signBlock.GetSignSurfaceNormal(data);
                         Vector3 vector            = new Vector3(nearText.Point.X, nearText.Point.Y, nearText.Point.Z);
                         float   num3              = Vector3.Dot(camera.ViewPosition - (vector + new Vector3(0.5f)), signSurfaceNormal);
                         Vector3 v                 = MathUtils.Max(0.01f * num3, 0.005f) * signSurfaceNormal;
                         for (int i = 0; i < signSurfaceBlockMesh.Indices.Count / 3; i++)
                         {
                             BlockMeshVertex blockMeshVertex  = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3]];
                             BlockMeshVertex blockMeshVertex2 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 1]];
                             BlockMeshVertex blockMeshVertex3 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 2]];
                             Vector3         p  = blockMeshVertex.Position + vector + v;
                             Vector3         p2 = blockMeshVertex2.Position + vector + v;
                             Vector3         p3 = blockMeshVertex3.Position + vector + v;
                             Vector2         textureCoordinates  = blockMeshVertex.TextureCoordinates;
                             Vector2         textureCoordinates2 = blockMeshVertex2.TextureCoordinates;
                             Vector2         textureCoordinates3 = blockMeshVertex3.TextureCoordinates;
                             textureCoordinates.X  = MathUtils.Lerp(x, x2, textureCoordinates.X);
                             textureCoordinates2.X = MathUtils.Lerp(x, x2, textureCoordinates2.X);
                             textureCoordinates3.X = MathUtils.Lerp(x, x2, textureCoordinates3.X);
                             textureCoordinates.Y  = MathUtils.Lerp(x3, x4, textureCoordinates.Y);
                             textureCoordinates2.Y = MathUtils.Lerp(x3, x4, textureCoordinates2.Y);
                             textureCoordinates3.Y = MathUtils.Lerp(x3, x4, textureCoordinates3.Y);
                             texturedBatch3D.QueueTriangle(p, p2, p3, textureCoordinates, textureCoordinates2, textureCoordinates3, color);
                         }
                     }
                 }
             }
         }
         m_primitivesRenderer3D.Flush(camera.ViewProjectionMatrix);
     }
 }
Esempio n. 2
0
        public void GrowFlower(int value, int x, int y, int z, int pollPass)
        {
            int data = Terrain.ExtractData(value);

            if (FlowerBlock.GetIsSmall(data) && Terrain.ExtractLight(base.SubsystemTerrain.Terrain.GetCellValueFast(x, y + 1, z)) >= 9)
            {
                int data2  = FlowerBlock.SetIsSmall(data, isSmall: false);
                int value2 = Terrain.ReplaceData(value, data2);
                m_toReplace[new Point3(x, y, z)] = new Replacement
                {
                    Value         = value2,
                    RequiredValue = value
                };
            }
        }
        public override void OnPoll(int value, int x, int y, int z, int pollPass)
        {
            if (Terrain.ExtractData(value) != 0 || m_subsystemGameInfo.WorldSettings.EnvironmentBehaviorMode != 0)
            {
                return;
            }
            int num = Terrain.ExtractLight(base.SubsystemTerrain.Terrain.GetCellValue(x, y + 1, z));

            if (num == 0)
            {
                m_toUpdate[new Point3(x, y, z)] = Terrain.ReplaceContents(value, 8);
            }
            if (num < 13)
            {
                return;
            }
            for (int i = x - 1; i <= x + 1; i++)
            {
                for (int j = z - 1; j <= z + 1; j++)
                {
                    for (int k = y - 2; k <= y + 1; k++)
                    {
                        int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(i, k, j);
                        if (Terrain.ExtractContents(cellValue) != 2)
                        {
                            continue;
                        }
                        int cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(i, k + 1, j);
                        if (KillsGrassIfOnTopOfIt(cellValue2) || Terrain.ExtractLight(cellValue2) < 13 || !(m_random.Float(0f, 1f) < 0.1f))
                        {
                            continue;
                        }
                        int num2 = Terrain.ReplaceContents(cellValue, 8);
                        m_toUpdate[new Point3(i, k, j)] = num2;
                        if (Terrain.ExtractContents(cellValue2) == 0)
                        {
                            int temperature = base.SubsystemTerrain.Terrain.GetTemperature(i, j);
                            int humidity    = base.SubsystemTerrain.Terrain.GetHumidity(i, j);
                            int num3        = PlantsManager.GenerateRandomPlantValue(m_random, num2, temperature, humidity, k + 1);
                            if (num3 != 0)
                            {
                                m_toUpdate[new Point3(i, k + 1, j)] = num3;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public override void OnPoll(int value, int x, int y, int z, int pollPass)
        {
            if (m_subsystemGameInfo.WorldSettings.EnvironmentBehaviorMode != 0)
            {
                return;
            }
            int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(x, y + 1, z);

            if (Terrain.ExtractContents(cellValue) == 0 && Terrain.ExtractLight(cellValue) >= 12)
            {
                int cellContents  = base.SubsystemTerrain.Terrain.GetCellContents(x, y - 1, z);
                int cellContents2 = base.SubsystemTerrain.Terrain.GetCellContents(x, y - 2, z);
                if ((cellContents != 127 || cellContents2 != 127) && m_random.Float(0f, 1f) < 0.25f)
                {
                    m_toUpdate[new Point3(x, y + 1, z)] = Terrain.MakeBlockValue(127, 0, 0);
                }
            }
        }
Esempio n. 5
0
 public int GetCellLightFast(int x, int y, int z)
 {
     return(Terrain.ExtractLight(GetCellValueFast(x, y, z)));
 }
Esempio n. 6
0
        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);
                    }
                }
            }
        }
        public void GenerateGeometry(MovingBlockSet movingBlockSet)
        {
            Point3 point = default(Point3);

            point.X = ((movingBlockSet.CurrentVelocity.X > 0f) ? ((int)MathUtils.Floor(movingBlockSet.Position.X)) : (point.X = (int)MathUtils.Ceiling(movingBlockSet.Position.X)));
            point.Y = ((movingBlockSet.CurrentVelocity.Y > 0f) ? ((int)MathUtils.Floor(movingBlockSet.Position.Y)) : (point.Y = (int)MathUtils.Ceiling(movingBlockSet.Position.Y)));
            point.Z = ((movingBlockSet.CurrentVelocity.Z > 0f) ? ((int)MathUtils.Floor(movingBlockSet.Position.Z)) : (point.Z = (int)MathUtils.Ceiling(movingBlockSet.Position.Z)));
            if (!(point != movingBlockSet.GeometryGenerationPosition))
            {
                return;
            }
            Point3 p      = new Point3(movingBlockSet.Box.Left, movingBlockSet.Box.Top, movingBlockSet.Box.Near);
            Point3 point2 = new Point3(movingBlockSet.Box.Width, movingBlockSet.Box.Height, movingBlockSet.Box.Depth);

            point2.Y = MathUtils.Min(point2.Y, 254);
            if (m_blockGeometryGenerator == null)
            {
                int x = 2;
                x = (int)MathUtils.NextPowerOf2((uint)x);
                m_blockGeometryGenerator = new BlockGeometryGenerator(new Terrain(), m_subsystemTerrain, null, base.Project.FindSubsystem <SubsystemFurnitureBlockBehavior>(throwOnError: true), null, base.Project.FindSubsystem <SubsystemPalette>(throwOnError: true));
                for (int i = 0; i < x; i++)
                {
                    for (int j = 0; j < x; j++)
                    {
                        m_blockGeometryGenerator.Terrain.AllocateChunk(i, j);
                    }
                }
            }
            Terrain terrain = m_subsystemTerrain.Terrain;

            for (int k = 0; k < point2.X + 2; k++)
            {
                for (int l = 0; l < point2.Z + 2; l++)
                {
                    int x2         = k + p.X + point.X - 1;
                    int z          = l + p.Z + point.Z - 1;
                    int shaftValue = terrain.GetShaftValue(x2, z);
                    m_blockGeometryGenerator.Terrain.SetTemperature(k, l, Terrain.ExtractTemperature(shaftValue));
                    m_blockGeometryGenerator.Terrain.SetHumidity(k, l, Terrain.ExtractHumidity(shaftValue));
                    for (int m = 0; m < point2.Y + 2; m++)
                    {
                        int y     = m + p.Y + point.Y - 1;
                        int light = Terrain.ExtractLight(terrain.GetCellValue(x2, y, z));
                        m_blockGeometryGenerator.Terrain.SetCellValueFast(k, m, l, Terrain.MakeBlockValue(0, light, 0));
                    }
                }
            }
            m_blockGeometryGenerator.Terrain.SeasonTemperature = terrain.SeasonTemperature;
            m_blockGeometryGenerator.Terrain.SeasonHumidity    = terrain.SeasonHumidity;
            foreach (MovingBlock block in movingBlockSet.Blocks)
            {
                int x3    = block.Offset.X - p.X + 1;
                int y2    = block.Offset.Y - p.Y + 1;
                int z2    = block.Offset.Z - p.Z + 1;
                int value = Terrain.ReplaceLight(light: m_blockGeometryGenerator.Terrain.GetCellLightFast(x3, y2, z2), value: block.Value);
                m_blockGeometryGenerator.Terrain.SetCellValueFast(x3, y2, z2, value);
            }
            m_blockGeometryGenerator.ResetCache();
            movingBlockSet.Vertices.Clear();
            movingBlockSet.Indices.Clear();
            for (int n = 1; n < point2.X + 1; n++)
            {
                for (int num = 1; num < point2.Y + 1; num++)
                {
                    for (int num2 = 1; num2 < point2.Z + 1; num2++)
                    {
                        int cellValueFast = m_blockGeometryGenerator.Terrain.GetCellValueFast(n, num, num2);
                        int num3          = Terrain.ExtractContents(cellValueFast);
                        if (num3 != 0)
                        {
                            BlocksManager.Blocks[num3].GenerateTerrainVertices(m_blockGeometryGenerator, movingBlockSet.Geometry, cellValueFast, n, num, num2);
                        }
                    }
                }
            }
            movingBlockSet.GeometryOffset             = new Vector3(p) - new Vector3(1f);
            movingBlockSet.GeometryGenerationPosition = point;
        }
Esempio n. 8
0
        public void GrowPumpkin(int value, int x, int y, int z, int pollPass)
        {
            if (Terrain.ExtractLight(base.SubsystemTerrain.Terrain.GetCellValueFast(x, y + 1, z)) < 9)
            {
                return;
            }
            int data = Terrain.ExtractData(value);
            int size = BasePumpkinBlock.GetSize(data);

            if (BasePumpkinBlock.GetIsDead(data) || size >= 7)
            {
                return;
            }
            int   cellValueFast = base.SubsystemTerrain.Terrain.GetCellValueFast(x, y - 1, z);
            int   num           = Terrain.ExtractContents(cellValueFast);
            int   data2         = Terrain.ExtractData(cellValueFast);
            bool  flag          = num == 168 && SoilBlock.GetHydration(data2);
            int   num2          = (num == 168) ? SoilBlock.GetNitrogen(data2) : 0;
            int   num3          = 4;
            float num4          = 0.15f;

            if (num == 168)
            {
                num3--;
                num4 -= 0.05f;
            }
            if (num2 > 0)
            {
                num3--;
                num4 -= 0.05f;
            }
            if (flag)
            {
                num3--;
                num4 -= 0.05f;
            }
            if (pollPass % MathUtils.Max(num3, 1) == 0)
            {
                int data3 = BasePumpkinBlock.SetSize(data, MathUtils.Min(size + 1, 7));
                if (m_random.Float(0f, 1f) < num4)
                {
                    data3 = BasePumpkinBlock.SetIsDead(data3, isDead: true);
                }
                int         value2 = Terrain.ReplaceData(value, data3);
                Replacement value3 = m_toReplace[new Point3(x, y, z)] = new Replacement
                {
                    Value         = value2,
                    RequiredValue = value
                };
                if (num == 168 && size + 1 == 7)
                {
                    int data4  = SoilBlock.SetNitrogen(data2, MathUtils.Max(num2 - 3, 0));
                    int value4 = Terrain.ReplaceData(cellValueFast, data4);
                    Dictionary <Point3, Replacement> toReplace = m_toReplace;
                    Point3 key = new Point3(x, y - 1, z);
                    value3 = new Replacement
                    {
                        Value         = value4,
                        RequiredValue = cellValueFast
                    };
                    toReplace[key] = value3;
                }
            }
        }
Esempio n. 9
0
        public void GrowCotton(int value, int x, int y, int z, int pollPass)
        {
            if (Terrain.ExtractLight(base.SubsystemTerrain.Terrain.GetCellValueFast(x, y + 1, z)) < 9)
            {
                return;
            }
            int data = Terrain.ExtractData(value);
            int size = CottonBlock.GetSize(data);

            if (size >= 2)
            {
                return;
            }
            Replacement value3;

            if (CottonBlock.GetIsWild(data))
            {
                if (size < 2)
                {
                    int data2  = CottonBlock.SetSize(CottonBlock.SetIsWild(data, isWild: true), size + 1);
                    int value2 = Terrain.ReplaceData(value, data2);
                    Dictionary <Point3, Replacement> toReplace = m_toReplace;
                    Point3 key = new Point3(x, y, z);
                    value3 = new Replacement
                    {
                        Value         = value2,
                        RequiredValue = value
                    };
                    toReplace[key] = value3;
                }
                return;
            }
            int cellValueFast = base.SubsystemTerrain.Terrain.GetCellValueFast(x, y - 1, z);

            if (Terrain.ExtractContents(cellValueFast) == 168)
            {
                int   data3     = Terrain.ExtractData(cellValueFast);
                bool  hydration = SoilBlock.GetHydration(data3);
                int   nitrogen  = SoilBlock.GetNitrogen(data3);
                int   num       = 6;
                float num2      = 0.8f;
                if (nitrogen > 0)
                {
                    num  -= 2;
                    num2 -= 0.4f;
                }
                if (hydration)
                {
                    num  -= 2;
                    num2 -= 0.4f;
                }
                if (pollPass % MathUtils.Max(num, 1) == 0)
                {
                    int data4 = CottonBlock.SetSize(data, MathUtils.Min(size + 1, 2));
                    if (m_random.Float(0f, 1f) < num2 && size == 1)
                    {
                        data4 = CottonBlock.SetIsWild(data4, isWild: true);
                    }
                    int value4 = Terrain.ReplaceData(value, data4);
                    value3 = (m_toReplace[new Point3(x, y, z)] = new Replacement
                    {
                        Value = value4,
                        RequiredValue = value
                    });
                    if (size + 1 == 2)
                    {
                        int data5  = SoilBlock.SetNitrogen(data3, MathUtils.Max(nitrogen - 1, 0));
                        int value5 = Terrain.ReplaceData(cellValueFast, data5);
                        Dictionary <Point3, Replacement> toReplace2 = m_toReplace;
                        Point3 key2 = new Point3(x, y - 1, z);
                        value3 = new Replacement
                        {
                            Value         = value5,
                            RequiredValue = cellValueFast
                        };
                        toReplace2[key2] = value3;
                    }
                }
            }
            else
            {
                int value6 = Terrain.ReplaceData(value, CottonBlock.SetIsWild(data, isWild: true));
                Dictionary <Point3, Replacement> toReplace3 = m_toReplace;
                Point3 key3 = new Point3(x, y, z);
                value3 = new Replacement
                {
                    Value         = value6,
                    RequiredValue = value
                };
                toReplace3[key3] = value3;
            }
        }
Esempio n. 10
0
        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
            TerrainGeometrySubset        subsetAlphaTest = geometry.SubsetAlphaTest;
            DynamicArray <TerrainVertex> vertices        = subsetAlphaTest.Vertices;
            DynamicArray <ushort>        indices         = subsetAlphaTest.Indices;
            int   count        = vertices.Count;
            int   data         = Terrain.ExtractData(value);
            int   num          = Terrain.ExtractLight(value);
            int   mountingFace = GetMountingFace(data);
            float s            = LightingManager.LightIntensityByLightValueAndFace[num + 16 * mountingFace];
            Color color        = Color.White * s;

            switch (mountingFace)
            {
            case 2:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z + 1, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z + 1, color, DefaultTextureSlot, 1, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z + 1, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z + 1, color, DefaultTextureSlot, 3, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 2));
                break;

            case 3:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z, color, DefaultTextureSlot, 3, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z + 1, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z + 1, color, DefaultTextureSlot, 1, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 2));
                break;

            case 0:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z, color, DefaultTextureSlot, 1, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z, color, DefaultTextureSlot, 3, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                break;

            case 1:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z, color, DefaultTextureSlot, 3, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z + 1, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z + 1, color, DefaultTextureSlot, 1, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                break;
            }
        }