Ejemplo n.º 1
1
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            Log.Warn("Player " + player.Username + " should be banned for hacking!");

            var block = world.GetBlock(blockCoordinates);
            if (block is Tnt)
            {
                world.SetBlock(new Air() {Coordinates = block.Coordinates});
                new PrimedTnt(world)
                {
                    KnownPosition = new PlayerLocation(blockCoordinates.X, blockCoordinates.Y, blockCoordinates.Z),
                    Fuse = (byte) (new Random().Next(0, 20) + 10)
                }.SpawnEntity();
            }
            else if (block.IsSolid)
            {
                var affectedBlock = world.GetBlock(GetNewCoordinatesFromFace(blockCoordinates, BlockFace.Up));
                if (affectedBlock.Id == 0)
                {
                    var fire = new Fire
                    {
                        Coordinates = affectedBlock.Coordinates
                    };
                    world.SetBlock(fire);
                }
            }
        }
Ejemplo n.º 2
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);
            if (face == BlockFace.Up) // On top of block
            {
                Block skull = new Block(144);
                skull.Coordinates = coor;
                skull.Metadata = 1; // Skull on floor, rotation in block entity
                world.SetBlock(skull);
            }
            else if (face == BlockFace.Down) // At the bottom of block
            {
                // Doesn't work, ignore if that happen.
                return;
            }
            else
            {
                Block skull = new Block(144);
                skull.Coordinates = coor;
                skull.Metadata = (byte) face; // Skull on floor, rotation in block entity
                world.SetBlock(skull);
            }

            // Then we create and set the sign block entity that has all the intersting data

            var skullBlockEntity = new SkullBlockEntity
            {
                Coordinates = coor,
                Rotation = (byte)((int)(Math.Floor(((player.KnownPosition.Yaw)) * 16 / 360) + 0.5) & 0x0f),
                SkullType = (byte) Metadata
            };

            world.SetBlockEntity(skullBlockEntity);
        }
Ejemplo n.º 3
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);
            if (face == BlockFace.Up) // On top of block
            {
                // Standing Sign
                var sign = new StandingSign();
                sign.Coordinates = coor;
                // metadata for sign is a value 0-15 that signify the orientation of the sign. Same as PC metadata.
                sign.Metadata = (byte) ((int) (Math.Floor((player.KnownPosition.Yaw + 180)*16/360) + 0.5) & 0x0f);
                world.SetBlock(sign);
            }
            else if (face == BlockFace.North) // At the bottom of block
            {
                // Doesn't work, ignore if that happen.
                return;
            }
            else
            {
                // Wall sign
                var sign = new WallSign();
                sign.Coordinates = coor;
                sign.Metadata = (byte) face;
                world.SetBlock(sign);
            }

            // Then we create and set the sign block entity that has all the intersting data

            var signBlockEntity = new Sign
            {
                Coordinates = coor
            };

            world.SetBlockEntity(signBlockEntity);
        }
Ejemplo n.º 4
0
        public override void BreakBlock(Level level)
        {
            BlockCoordinates direction = new BlockCoordinates();
            switch (Metadata & 0x07)
            {
                case 0:
                    direction = Level.East;
                    break; // West
                case 1:
                    direction = Level.North;
                    break; // North
                case 2:
                    direction = Level.West;
                    break; // East
                case 3:
                    direction = Level.South;
                    break; // South
            }

            // Remove bed
            if ((Metadata & 0x08) != 0x08)
            {
                direction = direction*-1;
            }

            level.SetBlock(new Air {Coordinates = Coordinates + direction});
            level.SetBlock(new Air {Coordinates = Coordinates});
        }
Ejemplo n.º 5
0
        public override void BreakBlock(Level level)
        {
            // Remove door
            if ((Metadata & 0x08) == 0x08) // Is Upper?
            {
                level.SetBlock(new Air {Coordinates = Coordinates + Level.Down});
            }
            else
            {
                level.SetBlock(new Air {Coordinates = Coordinates + Level.Up});
            }

            level.SetBlock(new Air {Coordinates = Coordinates});
        }
Ejemplo n.º 6
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            byte direction = player.GetDirection();

            var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face);

            // Base block, meta sets orientation
            Block block = new WoodenDoor();
            block.Coordinates = coordinates;
            block.Metadata = direction;

            int x = blockCoordinates.X;
            int y = blockCoordinates.Y;
            int z = blockCoordinates.Z;

            int xd = 0;
            int zd = 0;

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

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

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

            if (!block.CanPlace(world, face)) return;

            // The upper doore block, meta marks upper and
            // sets orientation based on ajecent blocks
            Block blockUpper = new WoodenDoor();
            blockUpper.Coordinates = coordinates + Level.Up;
            blockUpper.Metadata = (byte) (0x08 | (flag2 ? 1 : 0));

            world.SetBlock(block);
            world.SetBlock(blockUpper);
        }
Ejemplo n.º 7
0
		private void CheckForHarden(Level world, int x, int y, int z)
		{
			Block block = world.GetBlock(x, y, z);
			{
				bool harden = false;
				if (block is FlowingLava || block is StationaryLava)
				{
					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 Obsidian {Coordinates = new BlockCoordinates(x, y, z)});
						}
						else if (meta <= 4)
						{
							world.SetBlock(new Cobblestone {Coordinates = new BlockCoordinates(x, y, z)});
						}
					}
				}
			}
		}
Ejemplo n.º 8
0
        public override void UseItem(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords)
        {
            //if (player.GameMode != GameMode.Creative)
            //{
            //	Item itemStackInHand = player.Inventory.GetItemInHand();
            //	itemStackInHand.Count--;

            //	if (itemStackInHand.Count <= 0)
            //	{
            //		// set empty
            //		player.Inventory.Slots[player.Inventory.Slots.IndexOf(itemStackInHand)] = new ItemAir();
            //	}
            //}

            _block.Coordinates = GetNewCoordinatesFromFace(targetCoordinates, face);
            _block.Metadata = (byte) Metadata;

            if ((player.GetBoundingBox() - 0.01f).Intersects(_block.GetBoundingBox()))
            {
                Log.Debug("Can't build where you are standing: " + _block.GetBoundingBox());
                return;
            }
            if (!_block.CanPlace(world, face)) return;

            if (_block.PlaceBlock(world, player, targetCoordinates, face, faceCoords)) return; // Handled

            world.SetBlock(_block);
        }
Ejemplo n.º 9
0
        // 000 001 010 011 100
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            byte direction = player.GetDirection();

            byte upper = (byte) ((faceCoords.Y > 0.5 && face != BlockFace.Up) || face == BlockFace.Down ? 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;
        }
Ejemplo n.º 10
0
		public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face)
		{
			Metadata = (byte) (Metadata | (0x8));
			world.SetBlock(this);
			world.ScheduleBlockTick(this, TickRate);
			return true;
		}
Ejemplo n.º 11
0
		public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			Metadata = (byte) face;

			world.SetBlock(this);
			return true;
		}
Ejemplo n.º 12
0
		private void SetDoubleSlab(Level world, BlockCoordinates coordinates)
		{
			Block slab = BlockFactory.GetBlockById((byte) (Id - 1));
			slab.Coordinates = coordinates;
			slab.Metadata = (byte) Metadata;
			world.SetBlock(slab);
		}
Ejemplo n.º 13
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            byte direction = player.GetDirection();

            switch (face)
            {
                case BlockFace.South: // ok
                    Metadata = 0;
                    break;
                case BlockFace.North:
                    Metadata = 1;
                    break;
                case BlockFace.West:
                    Metadata = 2;
                    break;
                case BlockFace.East: // ok
                    Metadata = 3;
                    break;
            }

            Log.Warn($"Direction={direction}, face={face}, metadata={Metadata}");

            world.SetBlock(this);

            return true;
        }
Ejemplo n.º 14
0
		public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			if (face == BlockFace.Down) return true;

			switch (face)
			{
				case BlockFace.Up:
					Metadata = 5;
					break;
				case BlockFace.East:
					Metadata = 4;
					break;
				case BlockFace.West:
					Metadata = 3;
					break;
				case BlockFace.North:
					Metadata = 2;
					break;
				case BlockFace.South:
					Metadata = 1;
					break;
			}

			world.SetBlock(this);
			return true;
		}
Ejemplo n.º 15
0
		private void SetToFlowing(Level world)
		{
			Block flowingBlock = BlockFactory.GetBlockById((byte) (Id - 1));
			flowingBlock.Metadata = Metadata;
			flowingBlock.Coordinates = Coordinates;
			world.SetBlock(flowingBlock, applyPhysics: false);
			world.ScheduleBlockTick(flowingBlock, 5);
		}
Ejemplo n.º 16
0
        public override void UseItem(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords)
        {
            _block.Coordinates = GetNewCoordinatesFromFace(targetCoordinates, face);
            _block.Metadata = (byte) Metadata;

            if (!_block.CanPlace(world)) return;

            if (_block.PlaceBlock(world, player, targetCoordinates, face, faceCoords)) return; // Handled

            world.SetBlock(_block);
        }
Ejemplo n.º 17
0
 public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
 {
     Block block = world.GetBlock(blockCoordinates);
     if (block is Grass)
     {
         GrassPath grassPath = new GrassPath
         {
             Coordinates = blockCoordinates,
         };
         world.SetBlock(grassPath);
     }
 }
Ejemplo n.º 18
0
		public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			Block block = world.GetBlock(blockCoordinates);
			if (block is Grass || block is Dirt || block is GrassPath)
			{
				Farmland farmland = new Farmland
				{
					Coordinates = blockCoordinates,
					Metadata = 0
				};
				world.SetBlock(farmland);
			}
		}
Ejemplo n.º 19
0
		public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
			if (Metadata == 8 || Metadata == 10) //Prevent some kind of cheating...
			{
				Block block = BlockFactory.GetBlockById((byte) Metadata);
				block.Coordinates = coordinates;
				if (!block.CanPlace(world, face)) return;
				world.SetBlock(block);
				block.PlaceBlock(world, player, block.Coordinates, face, faceCoords);
			}

			FuelEfficiency = (short) (Metadata == 10 ? 1000 : 0);
		}
Ejemplo n.º 20
0
        public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face)
        {
            Block block = this;
            // Remove door
            if ((Metadata & 0x08) == 0x08) // Is Upper?
            {
                block = world.GetBlock(GetNewCoordinatesFromFace(blockCoordinates, BlockFace.Down));
            }

            block.Metadata ^= 0x04;
            world.SetBlock(block);

            return true;
        }
Ejemplo n.º 21
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            if (NeedBlockRevert)
            {
                var coord = GetNewCoordinatesFromFace(blockCoordinates, face);

                Log.Info("Reset block");
                // Resend the block to removed the new one
                Block block = world.GetBlock(coord);
                world.SetBlock(block);
            }

            Action(this, world, player, blockCoordinates);
        }
Ejemplo n.º 22
0
		public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			// 8 = 1000
			byte upperBit = 0x08;
			// 7 = 0111
			byte materialMask = 0x07;

			Block existingBlock = world.GetBlock(blockCoordinates);

			var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
			Block newBlock = world.GetBlock(coordinates);

			if (face == BlockFace.Up && faceCoords.Y == 0.5 && existingBlock.Id == Id && (existingBlock.Metadata & materialMask) == Metadata)
			{
				// Replace with double block
				SetDoubleSlab(world, blockCoordinates);
				return;
			}

			if (face == BlockFace.Down && faceCoords.Y == 0.5 && (existingBlock.Metadata & materialMask) == Metadata)
			{
				// Replace with double block
				SetDoubleSlab(world, blockCoordinates);
				return;
			}

			if (newBlock.Id != Id || (newBlock.Metadata & materialMask) != Metadata)
			{
				Block slab = BlockFactory.GetBlockById((byte) (Id));
				slab.Coordinates = coordinates;
				slab.Metadata = (byte) Metadata;
				if (face != BlockFace.Up && faceCoords.Y > 0.5 || (face == BlockFace.Down && faceCoords.Y == 0.0))
				{
					slab.Metadata |= upperBit;
				}
				world.SetBlock(slab);
				return;
			}

			// Same material in existing block, make double slab

			{
				// Create double slab, replace existing
				SetDoubleSlab(world, coordinates);
			}
		}
Ejemplo n.º 23
0
        public override void UseItem(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords)
        {
            ItemStack itemStackInHand = player.Inventory.GetItemInHand();
            itemStackInHand.Count--;
            if (itemStackInHand.Count <= 0)
            {
                // set empty
                player.Inventory.Slots[player.Inventory.Slots.IndexOf(itemStackInHand)] = new ItemStack();
            }

            _block.Coordinates = GetNewCoordinatesFromFace(targetCoordinates, face);
            _block.Metadata = (byte) Metadata;

            if (player.GetBoundingBox().Intersects(_block.GetBoundingBox())) return;
            if (!_block.CanPlace(world, face)) return;

            if (_block.PlaceBlock(world, player, targetCoordinates, face, faceCoords)) return; // Handled

            world.SetBlock(_block);
        }
Ejemplo n.º 24
0
		public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			byte direction = player.GetDirection();

			switch (direction)
			{
				case 1:
					Metadata = 2;
					break; // West
				case 2:
					Metadata = 5;
					break; // North
				case 3:
					Metadata = 3;
					break; // East
				case 0:
					Metadata = 4;
					break; // South 
			}

			world.SetBlock(this);

			return true;
		}
Ejemplo n.º 25
0
		public override void OnTick(Level world)
		{
			Random random = new Random();

			int x = Coordinates.X;
			int y = Coordinates.Y;
			int z = Coordinates.Z;

			int currentDecay = GetFlowDecay(world, x, y, z);
			byte multiplier = 1;

			if (this is FlowingLava)
			{
				multiplier = 2;
			}

			bool flag = true;
			int tickRate = TickRate();

			if (currentDecay > 0)
			{
				int smallestFlowDecay = -100;
				_adjacentSources = 0;
				smallestFlowDecay = GetSmallestFlowDecay(world, x - 1, y, z, smallestFlowDecay);
				smallestFlowDecay = GetSmallestFlowDecay(world, x + 1, y, z, smallestFlowDecay);
				smallestFlowDecay = GetSmallestFlowDecay(world, x, y, z - 1, smallestFlowDecay);
				smallestFlowDecay = GetSmallestFlowDecay(world, x, y, z + 1, smallestFlowDecay);
				int newDecay = smallestFlowDecay + multiplier;
				if (newDecay >= 8 || smallestFlowDecay < 0)
				{
					newDecay = -1;
				}

				if (GetFlowDecay(world, x, y + 1, z) >= 0)
				{
					int topFlowDecay = GetFlowDecay(world, x, y + 1, z);

					if (topFlowDecay >= 8)
					{
						newDecay = topFlowDecay;
					}
					else
					{
						newDecay = topFlowDecay + 8;
					}
				}

				if (_adjacentSources >= 2 && this is FlowingWater)
				{
					if (world.GetBlock(x, y - 1, z).IsSolid)
					{
						newDecay = 0;
					}
					else if (IsSameMaterial(world.GetBlock(x, y - 1, z)) && world.GetBlock(x, y - 1, z).Metadata == 0)
					{
						newDecay = 0;
					}
				}

				if (this is FlowingLava && currentDecay < 8 && newDecay < 8 && newDecay > currentDecay && random.Next(4) != 0)
				{
					//newDecay = currentDecay;
					//flag = false;
					tickRate *= 4;
				}

				if (newDecay == currentDecay)
				{
					if (flag)
					{
						SetToStill(world, x, y, z);
					}
				}
				else
				{
					currentDecay = newDecay;
					if (newDecay < 0)
					{
						world.SetAir(x, y, z);
					}
					else
					{
						world.SetData(x, y, z, (byte) newDecay);
						world.ApplyPhysics(x, y, z);
						world.ScheduleBlockTick(this, tickRate); // Schedule tick
					}
				}
			}
			else
			{
				SetToStill(world, x, y, z);
			}

			if (CanBeFlownInto(world, x, y - 1, z) /* || world.GetBlock(x, y - 1, z) is Flowing*/)
			{
				if (this is FlowingLava && (world.GetBlock(x, y - 1, z) is FlowingWater || world.GetBlock(x, y - 1, z) is StationaryWater))
				{
					world.SetBlock(new Cobblestone {Coordinates = new BlockCoordinates(x, y - 1, z)});
					return;
				}

				if (currentDecay >= 8)
				{
					Flow(world, x, y - 1, z, currentDecay);
				}
				else
				{
					Flow(world, x, y - 1, z, currentDecay + 8);
				}
			}
			else if (currentDecay >= 0 && (currentDecay == 0 || BlocksFluid(world, x, y - 1, z)))
			{
				bool[] optimalFlowDirections = GetOptimalFlowDirections(world, x, y, z);

				int newDecay = currentDecay + multiplier;
				if (currentDecay >= 8)
				{
					newDecay = 1;
				}

				if (newDecay >= 8)
				{
					return;
				}

				if (optimalFlowDirections[0])
				{
					Flow(world, x - 1, y, z, newDecay);
				}

				if (optimalFlowDirections[1])
				{
					Flow(world, x + 1, y, z, newDecay);
				}

				if (optimalFlowDirections[2])
				{
					Flow(world, x, y, z - 1, newDecay);
				}

				if (optimalFlowDirections[3])
				{
					Flow(world, x, y, z + 1, newDecay);
				}
			}
		}
Ejemplo n.º 26
0
		public virtual void BreakBlock(Level world)
		{
			world.SetBlock(new Air {Coordinates = Coordinates});
			BlockUpdate(world, Coordinates);
		}
Ejemplo n.º 27
0
        public override void OnTick(Level level)
        {
            if (Inventory == null) return;

            Furnace furnace = level.GetBlock(Coordinates) as Furnace;
            if (furnace == null) return;

            if (!(furnace is LitFurnace))
            {
                Item fuel = GetFuel();
                Item ingredient = GetIngredient();
                Item smelt = ingredient.GetSmelt();
                // To light a furnace you need both fule and proper ingredient.
                if (fuel.Count > 0 && fuel.FuelEfficiency > 0 && smelt != null)
                {
                    LitFurnace litFurnace = new LitFurnace
                    {
                        Coordinates = furnace.Coordinates,
                        Metadata = furnace.Metadata
                    };

                    level.SetBlock(litFurnace);
                    furnace = litFurnace;

                    BurnTime = GetFuelEfficiency(fuel);
                    FuelEfficiency = BurnTime;
                    CookTime = 0;
                    Inventory.DecreaseSlot(1);
                }
            }

            if (furnace is LitFurnace)
            {
                if (BurnTime > 0)
                {
                    BurnTime--;
                    BurnTick = (short) Math.Ceiling((double) BurnTime/FuelEfficiency*200d);

                    Item ingredient = GetIngredient();
                    Item smelt = ingredient.GetSmelt();
                    if (smelt != null)
                    {
                        CookTime++;
                        if (CookTime >= 200)
                        {
                            Inventory.DecreaseSlot(0);
                            Inventory.IncreaseSlot(2, smelt.Id, smelt.Metadata);

                            CookTime = 0;
                        }
                    }
                    else
                    {
                        CookTime = 0;
                    }
                }

                if (BurnTime <= 0)
                {
                    var fuel = GetFuel();
                    Item ingredient = GetIngredient();
                    Item smelt = ingredient.GetSmelt();
                    if (fuel.Count > 0 && fuel.FuelEfficiency > 0 && smelt != null)
                    {
                        Inventory.DecreaseSlot(1);

                        CookTime = 0;
                        BurnTime = GetFuelEfficiency(fuel);
                        FuelEfficiency = BurnTime;
                        BurnTick = (short) Math.Ceiling((double) BurnTime/FuelEfficiency*200d);
                    }
                    else
                    {
                        // No more fule or nothin more to smelt.
                        Furnace unlitFurnace = new Furnace
                        {
                            Coordinates = furnace.Coordinates,
                            Metadata = furnace.Metadata
                        };

                        level.SetBlock(unlitFurnace);
                        FuelEfficiency = 0;
                        BurnTick = 0;
                        BurnTime = 0;
                        CookTime = 0;
                    }
                }
            }

            foreach (var observer in Inventory.Observers)
            {
                var cookTimeSetData = McpeContainerSetData.CreateObject();
                cookTimeSetData.windowId = Inventory.WindowsId;
                cookTimeSetData.property = 0;
                cookTimeSetData.value = CookTime;
                observer.SendPackage(cookTimeSetData);

                var burnTimeSetData = McpeContainerSetData.CreateObject();
                burnTimeSetData.windowId = Inventory.WindowsId;
                burnTimeSetData.property = 1;
                burnTimeSetData.value = BurnTick;
                observer.SendPackage(burnTimeSetData);
            }
        }
Ejemplo n.º 28
0
        public override void OnTick(Level level)
        {
            if (Inventory == null) return;

            Furnace furnace = level.GetBlock(Coordinates) as Furnace;
            if (furnace == null) return;

            if (!(furnace is LitFurnace))
            {
                if (GetFuel().Id != 0)
                {
                    LitFurnace litFurnace = new LitFurnace
                    {
                        Coordinates = furnace.Coordinates,
                        Metadata = furnace.Metadata
                    };

                    level.SetBlock(litFurnace);
                    furnace = litFurnace;

                    BurnTime = GetFuelEfficiency(GetFuel());
                    FuelEfficiency = BurnTime;
                    CookTime = 0;
                    Inventory.DecreaseSlot(1);
                }
            }

            if (!(furnace is LitFurnace)) return;

            if (BurnTime > 0)
            {
                BurnTime--;
                BurnTick = (short) Math.Ceiling((double) BurnTime/FuelEfficiency*200d);

                if (GetIngredient().Id != 0)
                {
                    CookTime++;
                    if (CookTime >= 200)
                    {
                        Item result = GetResult(GetIngredient());
                        if (result != null)
                        {
                            Inventory.DecreaseSlot(0);
                            Inventory.IncreaseSlot(2, result.Id, result.Metadata);
                        }

                        CookTime = 0;
                    }
                }
                else
                {
                    CookTime = 0;
                }
            }

            if (BurnTime <= 0)
            {
                if (!Inventory.DecreaseSlot(1))
                {
                    //CookTime = 0;
                    BurnTime = GetFuelEfficiency(GetFuel());
                    FuelEfficiency = BurnTime;
                    BurnTick = (short) Math.Ceiling((double) BurnTime/FuelEfficiency*200d);
                }
                else
                {
                    // No more fule
                    Furnace unlitFurnace = new Furnace
                    {
                        Coordinates = furnace.Coordinates,
                        Metadata = furnace.Metadata
                    };

                    level.SetBlock(unlitFurnace);
                    FuelEfficiency = 0;
                    BurnTick = 0;
                    BurnTime = 0;
                    CookTime = 0;
                }
            }

            level.RelayBroadcast(new McpeContainerSetData
            {
                windowId = Inventory.WindowsId,
                property = 0,
                value = CookTime
            });

            level.RelayBroadcast(new McpeContainerSetData
            {
                windowId = Inventory.WindowsId,
                property = 1,
                value = BurnTick
            });
        }
Ejemplo n.º 29
0
		private void Flow(Level world, int x, int y, int z, int decay)
		{
			if (CanBeFlownInto(world, x, y, z))
			{
				//Block block = world.GetBlock(x, y, z);

				//if (this is FlowingLava)
				//{
				//	this.fizz(world, i, j, k);
				//}
				//else
				//{
				//	block.DoDrop(world, i, j, k, world.getData(i, j, k), 0);
				//}

				Block newBlock = BlockFactory.GetBlockById(Id);
				newBlock.Coordinates = new BlockCoordinates(x, y, z);
				newBlock.Metadata = (byte) decay;
				world.SetBlock(newBlock, applyPhysics: true);
				world.ScheduleBlockTick(newBlock, TickRate());
			}
		}
Ejemplo n.º 30
0
		private void SetToStill(Level world, int x, int y, int z)
		{
			byte meta = world.GetBlock(x, y, z).Metadata;

			Block stillBlock = BlockFactory.GetBlockById((byte) (Id + 1));
			stillBlock.Metadata = meta;
			stillBlock.Coordinates = new BlockCoordinates(x, y, z);
			world.SetBlock(stillBlock, applyPhysics: false);
		}