예제 #1
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);
            }
        }
예제 #2
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;
 }
예제 #3
0
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
     var d = new BlockRedstoneDust {Coordinates = blockCoordinates};
     //d.SetPowerLevel(new Random().Next(0,15));
     world.SetBlock(d, true, true);
 }
예제 #4
0
        public void SetPowerLevel(int target, Level lvl)
        {
            if (target < 0 || target > 15) throw new IndexOutOfRangeException("target");

            var newbits = new BitArray(new int[] { target });
            var rawbits = new BitArray(new byte[] { Metadata });

            rawbits[0] = newbits[0];
            rawbits[1] = newbits[1];
            rawbits[2] = newbits[2];
            rawbits[3] = newbits[3];

            Metadata = ConvertToByte(rawbits);
            lvl.SetBlock(this);
        }
예제 #5
0
파일: ItemSign.cs 프로젝트: LiveMC/SharpMC
        public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
        {
            blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
            if (face == BlockFace.PositiveY)
            {
                var bss = new BlockStandingSign
                {
                    Coordinates = blockCoordinates,
                    Metadata = 0x00
                };

                var rawbytes = new BitArray(new byte[] {bss.Metadata});

                var direction = player.GetDirection();
                switch (direction)
                {
                    case 0:
                        //South
                        rawbytes[2] = true;
                        break;
                    case 1:
                        //West
                        rawbytes[3] = true;
                        break;
                    case 2:
                        //North DONE
                        rawbytes[2] = true;
                        rawbytes[3] = true;
                        break;
                    case 3:
                        //East

                        break;
                }
                bss.Metadata = ConvertToByte(rawbytes);
                world.SetBlock(bss);
                new SignEditorOpen(player.Wrapper)
                {
                    Coordinates = blockCoordinates
                }.Write();
            }
            else
            {
                //TODO: implement wall signs
            }
        }
예제 #6
0
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
     //var slot = player.Inventory.CurrentSlot + 36;
     //player.Inventory.SetSlot(slot, 325, 0, 1); //'Empty' the bucket.
     var hand0 = player.Inventory.GetItemInHand(0);
     var hand1 = player.Inventory.GetItemInHand(1);
     if (hand0.Id == Id)
     {
         var slot = player.Inventory.CurrentSlot + 36;
         player.Inventory.SetSlot(slot, 325, 0, 1);
     }
     else if (hand1.Id == Id)
     {
         var slot = 45;
         player.Inventory.SetSlot(slot, 325, 0, 1);
     }
     world.SetBlock(new BlockFlowingWater {Coordinates = blockCoordinates}, true, true); //Place the water
     //	world.GetBlock(blockCoordinates).OnTick(world); //Update the water
 }
예제 #7
0
 public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
 {
     byte direction = player.GetDirection();
     byte upper = (byte)((mouseLocation.Y >= 8 && face != BlockFace.PositiveY) || face == BlockFace.NegativeY ? 0x04 : 0x00);
     switch (direction)
     {
         case 0:
             Metadata = (byte)(0 | upper);
             break;
         case 1:
             Metadata = (byte)(2 | upper);
             break;
         case 2:
             Metadata = (byte)(1 | upper);
             break;
         case 3:
             Metadata = (byte)(3 | upper);
             break;
     }
     world.SetBlock(this);
     return true;
 }
예제 #8
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();
     }
 }
예제 #9
0
파일: Flowing.cs 프로젝트: LiveMC/SharpMC
        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 - 1))
                    {
                        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)});
                        }
                    }
                }
            }
        }
예제 #10
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;
        }
예제 #11
0
        public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
        {
            var bits = new BitArray(new byte[] { Metadata });

            if (bits[3])
            {
                bits[3] = false;
            }
            else
            {
                bits[3] = true;
            }

            Metadata = ConvertToByte(bits);
            world.SetBlock(this);
        }
예제 #12
0
        public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
        {
            var rawbits = new BitArray(new byte[] { 0x00 });

            byte direction = player.GetDirection();
            if (face == BlockFace.PositiveY)
            {
                switch (direction)
                {
                    case 0:
                        //South
                        rawbits[1] = true;
                        rawbits[2] = true;
                        break;
                    case 1:
                        //West
                        rawbits[0] = true;
                        rawbits[2] = true;
                        break;
                    case 2:
                        //North
                        rawbits[1] = true;
                        rawbits[2] = true;
                        break;
                    case 3:
                        //East
                        rawbits[0] = true;
                        rawbits[2] = true;
                        break;
                }
            }
            else if (face == BlockFace.NegativeY)
            {
                rawbits[0] = true;
                rawbits[1] = true;
                rawbits[2] = true;
            }
            else if (face == BlockFace.PositiveZ)
            {
                rawbits[0] = true;
                rawbits[1] = true;
            }
            else if (face == BlockFace.NegativeZ)
            {
                rawbits[2] = true;
            }
            else if (face == BlockFace.PositiveX)
            {
                rawbits[0] = true;
            }
            else if (face == BlockFace.NegativeX)
            {
                rawbits[1] = true;
            }

            Metadata = ConvertToByte(rawbits);

            world.SetBlock(this);
            return true;
        }
예제 #13
0
파일: Block.cs 프로젝트: LiveMC/SharpMC
 public virtual void BreakBlock(Level world)
 {
     world.SetBlock(new Block(0) {Coordinates = Coordinates});
 }
예제 #14
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());
            }
        }
예제 #15
0
 private void SetToFlowing(Level world)
 {
     var flowingBlock = BlockFactory.GetBlockById((byte) (Id - 1));
     flowingBlock.Metadata = Metadata;
     flowingBlock.Coordinates = Coordinates;
     world.SetBlock(flowingBlock, applyPhysics: false);
     world.ScheduleBlockTick(flowingBlock, 5);
 }
예제 #16
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);
        }
예제 #17
0
파일: BlockTNT.cs 프로젝트: LiveMC/SharpMC
 public override void BreakBlock(Level world)
 {
     world.SetBlock(new BlockAir {Coordinates = Coordinates});
 }