コード例 #1
0
        void HandleFlower(int index, BlockID block)
        {
            int x = index % map.Width;
            int y = (index / map.Width) / map.Length;
            int z = (index / map.Width) % map.Length;

            if (!game.Lighting.IsLit(x, y, z))
            {
                game.UpdateBlock(x, y, z, Block.Air);
                physics.ActivateNeighbours(x, y, z, index);
                return;
            }

            BlockID below = Block.Dirt;

            if (y > 0)
            {
                below = map.blocks[index - map.Width * map.Length];
            }
            if (!(below == Block.Dirt || below == Block.Grass))
            {
                game.UpdateBlock(x, y, z, Block.Air);
                physics.ActivateNeighbours(x, y, z, index);
            }
        }
コード例 #2
0
        void HandleFlower(Vector3I pos, BlockRaw block)
        {
            //int x = index % map.Width;
            //int y = (index / map.Width) / map.Length;
            //int z = (index / map.Width) % map.Length;

            if (!game.Lighting.IsLit(pos.X, pos.Y, pos.Z))
            {
                game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
                physics.ActivateNeighbours(pos.X, pos.Y, pos.Z, 0);
                return;
            }

            BlockRaw below = Block.Dirt;

            if (pos.Y > 0)
            {
                below = (BlockRaw)map.GetBlock(pos.X, pos.Y - 1, pos.Z);
            }
            if (!(below == Block.Dirt || below == Block.Grass))
            {
                game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
                physics.ActivateNeighbours(pos.X, pos.Y, pos.Z, 0);
            }
        }
コード例 #3
0
ファイル: TNTPhysics.cs プロジェクト: derekdinan/Survival
        // Algorithm source: http://minecraft.gamepedia.com/Explosion
        public void Explode(float power, int x, int y, int z)
        {
            if (rayDirs == null)
            {
                InitExplosionCache();
            }

            game.UpdateBlock(x, y, z, Block.Air);
            int index = (y * map.Length + z) * map.Width + x;

            physics.ActivateNeighbours(x, y, z, index);

            Vector3 basePos = new Vector3(x, y, z);

            for (int i = 0; i < rayDirs.Length; i++)
            {
                Vector3 dir       = rayDirs[i] * stepLen;
                Vector3 position  = basePos;
                float   intensity = (float)(0.7 + rnd.NextDouble() * 0.6) * power;
                while (intensity > 0)
                {
                    position  += dir;
                    intensity -= stepLen * 0.75f;
                    Vector3I P = Vector3I.Floor(position);
                    if (!map.IsValidPos(P))
                    {
                        break;
                    }

                    int  newX     = P.X;
                    int  newY     = P.Y;
                    int  newZ     = P.Z;
                    bool isTNT    = false;
                    int  newIndex = (newY * game.World.Length + newZ) * game.World.Width + newX;
                    if (map.blocks[newIndex] == Block.TNT)
                    {
                        isTNT = true;
                    }

                    BlockID block = map.GetBlock(P);
                    intensity -= (hardness[block] / 5 + 0.3f) * stepLen;
                    if (intensity > 0 && block != 0)
                    {
                        game.UpdateBlock(P.X, P.Y, P.Z, Block.Air);
                        index = (P.Y * map.Length + P.Z) * map.Width + P.X;
                        physics.ActivateNeighbours(P.X, P.Y, P.Z, index);
                        if (isTNT)
                        {
                            HandleTnt2(newIndex, block);
                        }
                    }
                }
            }
        }
コード例 #4
0
        void DoFalling(int index, BlockRaw block)
        {
            int found = -1, start = index;

            // Find lowest air block
            while (index >= oneY)
            {
                index -= oneY;
                BlockRaw other = map.blocks1[index];
                if (other == Block.Air || (other >= Block.Water && other <= Block.StillLava))
                {
                    found = index;
                }
                else
                {
                    break;
                }
            }
            if (found == -1)
            {
                return;
            }

            int x = found % width;
            int y = found / oneY;             // posIndex / (width * length)
            int z = (found / width) % length;

            game.UpdateBlock(x, y, z, block);

            x = start % width;
            y = start / oneY;             // posIndex / (width * length)
            z = (start / width) % length;
            game.UpdateBlock(x, y, z, Block.Air);
            physics.ActivateNeighbours(x, y, z, start);
        }
コード例 #5
0
ファイル: TNTPhysics.cs プロジェクト: yzaroui/ClassicalSharp
        public void Explode(int power, int x, int y, int z)
        {
            if (blocksTnt == null)
            {
                InitExplosionCache();
            }

            game.UpdateBlock(x, y, z, Block.Air);
            int index = (y * map.Length + z) * map.Width + x;

            physics.ActivateNeighbours(x, y, z, index);

            int powerSquared = power * power;

            for (int dy = -power; dy <= power; dy++)
            {
                for (int dz = -power; dz <= power; dz++)
                {
                    for (int dx = -power; dx <= power; dx++)
                    {
                        if (dx * dx + dy * dy + dz * dz > powerSquared)
                        {
                            continue;
                        }

                        int xx = x + dx, yy = y + dy, zz = z + dz;
                        if (!map.IsValidPos(xx, yy, zz))
                        {
                            continue;
                        }
                        index = (yy * map.Length + zz) * map.Width + xx;

                        BlockID block = map.blocks[index];
                        if (block < Block.CpeCount && blocksTnt[block])
                        {
                            continue;
                        }

                        game.UpdateBlock(xx, yy, zz, Block.Air);
                        physics.ActivateNeighbours(xx, yy, zz, index);
                    }
                }
            }
        }
コード例 #6
0
        void DoFalling(Vector3I pos, BlockRaw block)
        {
            int      start = pos.Y, y = pos.Y;
            Vector3I found = new Vector3I(-1, -1, -1);

            // Find lowest air block
            //while (index >= oneY) {
            while (y >= 1)
            {
                //index -= oneY;
                y -= 1;
                BlockRaw other = (BlockRaw)map.GetBlock(pos.X, y, pos.Z);
                if (other == Block.Air || (other >= Block.Water && other <= Block.StillLava))
                {
                    found = new Vector3I(pos.X, y, pos.Z);
                }
                else
                {
                    break;
                }
            }
            if (found.X == -1 || found.Y == -1 || found.Z == -1)
            {
                return;
            }

            //int x = found % width;
            //int y = found / oneY; // posIndex / (width * length)
            //int z = (found / width) % length;
            game.UpdateBlock(found.X, found.Y, found.Z, block);

            //x = start % width;
            //y = start / oneY; // posIndex / (width * length)
            //z = (start / width) % length;
            game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
            physics.ActivateNeighbours(pos.X, pos.Y, pos.Z, start);
        }