예제 #1
0
파일: Slab.cs 프로젝트: LiveMC/SharpMC
 public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
 {
     var prevblock = world.GetBlock(Coordinates);
     if (prevblock.Id == Id && prevblock.Metadata == Metadata)
     {
         DoubleSlab ds = new DoubleSlab(Metadata) {Coordinates = Coordinates};
         world.SetBlock(ds);
     }
     else if (prevblock.Id == Id && prevblock.Metadata != Metadata)
     {
         if (player.Gamemode != Gamemode.Creative)
         {
             player.Inventory.AddItem((short)Id, Metadata, 1);
         }
         return true;
     }
     else
     {
         bool upper = ((mouseLocation.Y >= 8 && face != BlockFace.PositiveY) || face == BlockFace.NegativeY);
         BitArray b = new BitArray(new byte[] {Metadata});
         b[3] = upper;
         Metadata = ConvertToByte(b);
         world.SetBlock(this);
     }
     return true;
 }
예제 #2
0
        public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
        {
            blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
            var bl = world.GetBlock(blockCoordinates);

            var slot = 0;
            var hand0 = player.Inventory.GetItemInHand(0);
            var hand1 = player.Inventory.GetItemInHand(1);
            if (hand0.Id == Id)
            {
                slot = player.Inventory.CurrentSlot + 36;
            }
            else if (hand1.Id == Id)
            {
                slot = 45;
            }

            //player.SendChat("Block: " + bl.Id, ChatColor.Bold);
            if (bl.Id == 65535) return;

            if (bl.Id == 8)
            {
                //Water
                player.Inventory.SetSlot(slot, 326, 0, 1);
                world.SetBlock(new BlockAir() {Coordinates = blockCoordinates}, true, true);
            }

            if (bl.Id == 10)
            {
                //lava
                player.Inventory.SetSlot(slot, 327, 0, 1);
                world.SetBlock(new BlockAir() { Coordinates = blockCoordinates }, true, true);
            }
        }
예제 #3
0
        public override void DoPhysics(Level level)
        {
            CheckForHarden(level, (int) Coordinates.X, (int) Coordinates.Y, (int) Coordinates.Z);

            if (level.GetBlock(Coordinates).Id == Id)
            {
                SetToFlowing(level);
            }
        }
예제 #4
0
파일: Door.cs 프로젝트: LiveMC/SharpMC
        public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
        {
            var direction = player.GetDirection();
            var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face);

            Block block = new Door(Id);
            block.Coordinates = coordinates;
            block.Metadata = direction;

            var x = (int) blockCoordinates.X;
            var y = (int) blockCoordinates.Y;
            var z = (int) blockCoordinates.Z;

            var xd = 0;
            var zd = 0;

            if (direction == 0) zd = 1;
            if (direction == 1) xd = -1;
            if (direction == 2) zd = -1;
            if (direction == 3) xd = 1;

            var i1 = (world.GetBlock(new Vector3(x - xd, y, z - zd)).IsSolid ? 1 : 0) +
                     (world.GetBlock(new Vector3(x - xd, y + 1, z - zd)).IsSolid ? 1 : 0);
            var j1 = (world.GetBlock(new Vector3(x + xd, y, z + zd)).IsSolid ? 1 : 0) +
                     (world.GetBlock(new Vector3(x + xd, y + 1, z + zd)).IsSolid ? 1 : 0);
            var flag = world.GetBlock(new Vector3(x - xd, y, z - zd)).Id == block.Id ||
                       world.GetBlock(new Vector3(x - xd, y + 1, z - zd)).Id == block.Id;
            var flag1 = world.GetBlock(new Vector3(x + xd, y, z + zd)).Id == block.Id ||
                        world.GetBlock(new Vector3(x + xd, y + 1, z + zd)).Id == block.Id;
            var flag2 = false;

            if (flag && !flag1)
            {
                flag2 = true;
            }
            else if (j1 > i1)
            {
                flag2 = true;
            }

            var c2 = coordinates;
            c2.Y++;

            Block blockUpper = new Door(Id);
            blockUpper.Coordinates = c2;
            blockUpper.Metadata = (byte) (0x08 | (flag2 ? 1 : 0));

            world.SetBlock(block);
            world.SetBlock(blockUpper);

            return true;
        }
예제 #5
0
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
     var block = world.GetBlock(blockCoordinates);
     ConsoleFunctions.WriteInfoLine("Block: " + block.Id);
     if (block.Id != 46)
     {
         var affectedBlock = world.GetBlock(blockCoordinates);
         if (affectedBlock.Id == 0)
         {
             var fire = new BlockFire
             {
                 Coordinates = affectedBlock.Coordinates
             };
             world.SetBlock(fire);
         }
     }
     else
     {
         new PrimedTNTEntity(world) {KnownPosition = blockCoordinates.ToPlayerLocation()}.SpawnEntity();
     }
 }
예제 #6
0
        private void CheckForHarden(Level world, int x, int y, int z)
        {
            var block = world.GetBlock(new Vector3(x, y, z));
            {
                var harden = false;
                if (block is BlockFlowingLava || block is BlockStationaryLava)
                {
                    if (IsWater(world, x, y, z))
                    {
                        harden = true;
                    }

                    if (harden || IsWater(world, x, y, z + 1))
                    {
                        harden = true;
                    }

                    if (harden || IsWater(world, x - 1, y, z))
                    {
                        harden = true;
                    }

                    if (harden || IsWater(world, x + 1, y, z))
                    {
                        harden = true;
                    }

                    if (harden || IsWater(world, x, y + 1, z))
                    {
                        harden = true;
                    }

                    if (harden)
                    {
                        int meta = block.Metadata;

                        if (meta == 0)
                        {
                            world.SetBlock(new BlockObsidian {Coordinates = new Vector3(x, y, z)});
                        }
                        else if (meta <= 4)
                        {
                            world.SetBlock(new BlockCobbleStone {Coordinates = new Vector3(x, y, z)});
                        }
                    }
                }
            }
        }
예제 #7
0
파일: InfoTool.cs 프로젝트: LiveMC/SharpMC
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     var blockatpos = world.GetBlock(blockCoordinates);
     if (!(blockatpos is BlockAir))
     {
         BitArray b = new BitArray(new byte[] {blockatpos.Metadata});
         ConsoleFunctions.WriteLine("\n\n");
         ConsoleFunctions.WriteInfoLine("------------------------------------");
         ConsoleFunctions.WriteInfoLine("Block: " + blockatpos);
         ConsoleFunctions.WriteInfoLine("------------------------------------");
         for (int i = 0; i < b.Count; i++)
         {
             ConsoleFunctions.WriteInfoLine("Bit " + i + ": " + b[i]);
         }
         ConsoleFunctions.WriteInfoLine("------------------------------------\n\n");
         player.SendChat("Info tool used, Metadata written to chat!", ChatColor.Gold);
     }
 }
예제 #8
0
파일: Flowing.cs 프로젝트: LiveMC/SharpMC
        private void SetToStill(Level world, int x, int y, int z)
        {
            var meta = world.GetBlock(new Vector3(x, y, z)).Metadata;

            var stillBlock = BlockFactory.GetBlockById((byte) (Id + 1));
            stillBlock.Metadata = meta;
            stillBlock.Coordinates = new Vector3(x, y, z);
            world.SetBlock(stillBlock, applyPhysics: false);
        }
예제 #9
0
파일: Flowing.cs 프로젝트: LiveMC/SharpMC
 private bool IsWater(Level world, int x, int y, int z)
 {
     var block = world.GetBlock(new Vector3(x, y, z));
     return block is BlockFlowingWater || block is BlockStationaryWater;
 }
예제 #10
0
파일: Flowing.cs 프로젝트: LiveMC/SharpMC
        private bool[] GetOptimalFlowDirections(Level world, int x, int y, int z)
        {
            int l;
            int x2;

            for (l = 0; l < 4; ++l)
            {
                _flowCost[l] = 1000;
                x2 = x;
                var z2 = z;

                if (l == 0)
                {
                    x2 = x - 1;
                }

                if (l == 1)
                {
                    ++x2;
                }

                if (l == 2)
                {
                    z2 = z - 1;
                }

                if (l == 3)
                {
                    ++z2;
                }

                if (!BlocksFluid(world, x2, y, z2) &&
                    (!IsSameMaterial(world.GetBlock(new Vector3(x2, y, z2))) || world.GetBlock(new Vector3(x2, y, z2)).Metadata != 0))
                {
                    if (BlocksFluid(world, x2, y - 1, z2))
                    {
                        _flowCost[l] = CalculateFlowCost(world, x2, y, z2, 1, l);
                    }
                    else
                    {
                        _flowCost[l] = 0;
                    }
                }
            }

            l = _flowCost[0];

            for (x2 = 1; x2 < 4; ++x2)
            {
                if (_flowCost[x2] < l)
                {
                    l = _flowCost[x2];
                }
            }

            for (x2 = 0; x2 < 4; ++x2)
            {
                _optimalFlowDirections[x2] = _flowCost[x2] == l;
            }

            return _optimalFlowDirections;
        }
예제 #11
0
파일: Flowing.cs 프로젝트: LiveMC/SharpMC
 private int GetFlowDecay(Level world, int x, int y, int z)
 {
     var block = world.GetBlock(new Vector3(x, y, z));
     return IsSameMaterial(block) ? block.Metadata : -1;
 }
예제 #12
0
파일: Flowing.cs 프로젝트: LiveMC/SharpMC
        private void Flow(Level world, int x, int y, int z, int decay)
        {
            if (CanBeFlownInto(world, x, y, z))
            {
                var oldBlock = world.GetBlock(new Vector3(x, y, z));
                if (oldBlock is Flowing || oldBlock.Id == 0)
                {
                }
                else
                {
                    oldBlock.DoDrop(world);
                }
                oldBlock.BreakBlock(world);

                var newBlock = BlockFactory.GetBlockById(Id);
                newBlock.Coordinates = new Vector3(x, y, z);
                newBlock.Metadata = (byte) decay;
                world.SetBlock(newBlock, applyPhysics: true);
                world.ScheduleBlockTick(newBlock, TickRate());
            }
        }
예제 #13
0
파일: Flowing.cs 프로젝트: LiveMC/SharpMC
        private bool CanBeFlownInto(Level world, int x, int y, int z)
        {
            var block = world.GetBlock(new Vector3(x, y, z));

            return !IsSameMaterial(block) && (!(block is BlockFlowingLava) && !(block is BlockStationaryLava)) &&
                   !BlocksFluid(block);
        }
예제 #14
0
파일: Flowing.cs 프로젝트: LiveMC/SharpMC
        private int CalculateFlowCost(Level world, int x, int y, int z, int accumulatedCost, int prevDirection)
        {
            var cost = 1000;

            for (var direction = 0; direction < 4; ++direction)
            {
                if ((direction != 0 || prevDirection != 1)
                    && (direction != 1 || prevDirection != 0)
                    && (direction != 2 || prevDirection != 3)
                    && (direction != 3 || prevDirection != 2))
                {
                    var x2 = x;
                    var z2 = z;

                    if (direction == 0)
                    {
                        x2 = x - 1;
                    }

                    if (direction == 1)
                    {
                        ++x2;
                    }

                    if (direction == 2)
                    {
                        z2 = z - 1;
                    }

                    if (direction == 3)
                    {
                        ++z2;
                    }

                    if (!BlocksFluid(world, x2, y, z2) &&
                        (!IsSameMaterial(world.GetBlock(new Vector3(x2, y, z2))) ||
                         world.GetBlock(new Vector3(x2, y, z2)).Metadata != 0))
                    {
                        if (!BlocksFluid(world, x2, y - 1, z2))
                        {
                            return accumulatedCost;
                        }

                        if (accumulatedCost < 4)
                        {
                            var j2 = CalculateFlowCost(world, x2, y, z2, accumulatedCost + 1, direction);

                            if (j2 < cost)
                            {
                                cost = j2;
                            }
                        }
                    }
                }
            }

            return cost;
        }
예제 #15
0
파일: Flowing.cs 프로젝트: LiveMC/SharpMC
        private bool BlocksFluid(Level world, int x, int y, int z)
        {
            var block = world.GetBlock(new Vector3(x, y, z));

            return BlocksFluid(block);
        }
예제 #16
0
파일: Block.cs 프로젝트: LiveMC/SharpMC
 protected virtual bool CanPlace(Level world, Vector3 blockCoordinates)
 {
     return world.GetBlock(blockCoordinates).IsReplacible;
 }