diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 0c0c0b0ae..1a035b355 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -78,7 +78,7 @@ class Anvil extends Fallable{ return AxisAlignedBB::one()->squash(Facing::axis(Facing::rotateY($this->facing, false)), 1 / 8); } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ $player->addWindow(new AnvilInventory($this)); } diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index 1672346cb..286b8feb5 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -148,7 +148,7 @@ class Bed extends Transparent{ return null; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $other = $this->getOtherHalf(); if($other === null){ diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 681d16e9d..e290d6c4f 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -402,11 +402,13 @@ class Block extends Position implements BlockIds, Metadatable{ * Do actions when activated by Item. Returns if it has done anything * * @param Item $item + * @param int $face + * @param Vector3 $clickVector * @param Player|null $player * * @return bool */ - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ return false; } diff --git a/src/pocketmine/block/Button.php b/src/pocketmine/block/Button.php index 54d16b337..bc472bbe3 100644 --- a/src/pocketmine/block/Button.php +++ b/src/pocketmine/block/Button.php @@ -63,7 +63,7 @@ abstract class Button extends Flowable{ abstract protected function getActivationTime() : int; - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->powered){ $this->powered = true; $this->level->setBlock($this, $this); diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 5518c467e..47d21e438 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -96,7 +96,7 @@ class Cake extends Transparent implements FoodSource{ return false; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $player->consumeObject($this); return true; diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 24736b3db..b55a25828 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -106,7 +106,7 @@ class Chest extends Transparent{ return false; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ $chest = $this->getLevel()->getTile($this); diff --git a/src/pocketmine/block/CoarseDirt.php b/src/pocketmine/block/CoarseDirt.php index 2f3a3eb25..23b16f716 100644 --- a/src/pocketmine/block/CoarseDirt.php +++ b/src/pocketmine/block/CoarseDirt.php @@ -25,12 +25,14 @@ namespace pocketmine\block; use pocketmine\item\Hoe; use pocketmine\item\Item; +use pocketmine\math\Facing; +use pocketmine\math\Vector3; use pocketmine\Player; class CoarseDirt extends Dirt{ - public function onActivate(Item $item, Player $player = null) : bool{ - if($item instanceof Hoe){ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + if($face === Facing::UP and $item instanceof Hoe){ $item->applyDamage(1); $this->getLevel()->setBlock($this, BlockFactory::get(Block::DIRT)); return true; diff --git a/src/pocketmine/block/CocoaBlock.php b/src/pocketmine/block/CocoaBlock.php index 9328fb9fc..72fdb5a52 100644 --- a/src/pocketmine/block/CocoaBlock.php +++ b/src/pocketmine/block/CocoaBlock.php @@ -94,7 +94,7 @@ class CocoaBlock extends Transparent{ return false; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($this->age < 2 and $item->getId() === Item::DYE and $item->getDamage() === 15){ //bone meal $this->age++; $this->level->setBlock($this, $this); diff --git a/src/pocketmine/block/CraftingTable.php b/src/pocketmine/block/CraftingTable.php index 1576e389d..113cfb6b6 100644 --- a/src/pocketmine/block/CraftingTable.php +++ b/src/pocketmine/block/CraftingTable.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\inventory\CraftingGrid; use pocketmine\item\Item; +use pocketmine\math\Vector3; use pocketmine\Player; class CraftingTable extends Solid{ @@ -47,7 +48,7 @@ class CraftingTable extends Solid{ return BlockToolType::TYPE_AXE; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ $player->setCraftingGrid(new CraftingGrid($player, CraftingGrid::SIZE_BIG)); } diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index c56c678b2..4a575a8f9 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -60,7 +60,7 @@ abstract class Crops extends Flowable{ } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($this->age < 7 and $item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal $block = clone $this; $block->age += mt_rand(2, 5); diff --git a/src/pocketmine/block/DaylightSensor.php b/src/pocketmine/block/DaylightSensor.php index 9fdbd267c..cdf9814a3 100644 --- a/src/pocketmine/block/DaylightSensor.php +++ b/src/pocketmine/block/DaylightSensor.php @@ -27,6 +27,7 @@ use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; +use pocketmine\math\Vector3; use pocketmine\Player; class DaylightSensor extends Transparent{ @@ -93,7 +94,7 @@ class DaylightSensor extends Transparent{ return AxisAlignedBB::one()->trim(Facing::UP, 0.5); } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->inverted = !$this->inverted; $this->level->setBlock($this, $this); return true; diff --git a/src/pocketmine/block/Dirt.php b/src/pocketmine/block/Dirt.php index e810b0ab5..c19c9ff66 100644 --- a/src/pocketmine/block/Dirt.php +++ b/src/pocketmine/block/Dirt.php @@ -25,6 +25,8 @@ namespace pocketmine\block; use pocketmine\item\Hoe; use pocketmine\item\Item; +use pocketmine\math\Facing; +use pocketmine\math\Vector3; use pocketmine\Player; class Dirt extends Solid{ @@ -39,8 +41,8 @@ class Dirt extends Solid{ return BlockToolType::TYPE_SHOVEL; } - public function onActivate(Item $item, Player $player = null) : bool{ - if($item instanceof Hoe){ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + if($face === Facing::UP and $item instanceof Hoe){ $item->applyDamage(1); $this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND)); diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index d2602c952..424b6a4b3 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -134,7 +134,7 @@ abstract class Door extends Transparent{ return false; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->open = !$this->open; $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); diff --git a/src/pocketmine/block/EnchantingTable.php b/src/pocketmine/block/EnchantingTable.php index 30db64abe..b8719674b 100644 --- a/src/pocketmine/block/EnchantingTable.php +++ b/src/pocketmine/block/EnchantingTable.php @@ -28,6 +28,7 @@ use pocketmine\item\Item; use pocketmine\item\TieredTool; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; +use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\EnchantTable as TileEnchantingTable; @@ -67,7 +68,7 @@ class EnchantingTable extends Transparent{ return AxisAlignedBB::one()->trim(Facing::UP, 0.25); } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ //TODO lock diff --git a/src/pocketmine/block/EnderChest.php b/src/pocketmine/block/EnderChest.php index 34f6e68b6..c4d861086 100644 --- a/src/pocketmine/block/EnderChest.php +++ b/src/pocketmine/block/EnderChest.php @@ -27,6 +27,7 @@ use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\TieredTool; use pocketmine\math\Facing; +use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\EnderChest as TileEnderChest; @@ -62,7 +63,7 @@ class EnderChest extends Chest{ return TieredTool::TIER_WOODEN; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ $enderChest = $this->getLevel()->getTile($this); if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){ diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 4be8fd463..0914d202d 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -76,7 +76,7 @@ class FenceGate extends Transparent{ return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->open = !$this->open; if($this->open and $player !== null){ $playerFacing = $player->getHorizontalFacing(); diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index c3061f8b1..35968885b 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -80,7 +80,7 @@ class FlowerPot extends Flowable{ } } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $pot = $this->getLevel()->getTile($this); if(!($pot instanceof TileFlowerPot)){ return false; diff --git a/src/pocketmine/block/Furnace.php b/src/pocketmine/block/Furnace.php index 3f3882956..5f1449496 100644 --- a/src/pocketmine/block/Furnace.php +++ b/src/pocketmine/block/Furnace.php @@ -106,7 +106,7 @@ class Furnace extends Solid{ return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ $furnace = $this->getLevel()->getTile($this); if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){ diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index 607d851b0..fadb3aaee 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -30,6 +30,7 @@ use pocketmine\item\ItemFactory; use pocketmine\item\Shovel; use pocketmine\level\generator\object\TallGrass as TallGrassObject; use pocketmine\math\Facing; +use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\utils\Random; use function mt_rand; @@ -99,7 +100,10 @@ class Grass extends Solid{ } } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + if($face !== Facing::UP){ + return false; + } if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ $item->pop(); TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2); diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index 583e85b3f..566b40402 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -63,7 +63,7 @@ class ItemFrame extends Flowable{ return "Item Frame"; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $tile = $this->level->getTile($this); if($tile instanceof TileItemFrame){ if($tile->hasItem()){ diff --git a/src/pocketmine/block/Lever.php b/src/pocketmine/block/Lever.php index 11a8f4efe..16873081d 100644 --- a/src/pocketmine/block/Lever.php +++ b/src/pocketmine/block/Lever.php @@ -119,7 +119,7 @@ class Lever extends Flowable{ } } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->powered = !$this->powered; $this->level->setBlock($this, $this); $this->level->broadcastLevelSoundEvent( diff --git a/src/pocketmine/block/RedstoneOre.php b/src/pocketmine/block/RedstoneOre.php index 798a9cc59..3a452c21e 100644 --- a/src/pocketmine/block/RedstoneOre.php +++ b/src/pocketmine/block/RedstoneOre.php @@ -75,7 +75,7 @@ class RedstoneOre extends Solid{ return $this->getLevel()->setBlock($this, $this, false); } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->lit){ $this->lit = true; $this->getLevel()->setBlock($this, $this); //no return here - this shouldn't prevent block placement diff --git a/src/pocketmine/block/RedstoneRepeater.php b/src/pocketmine/block/RedstoneRepeater.php index a8b98836d..4917890d9 100644 --- a/src/pocketmine/block/RedstoneRepeater.php +++ b/src/pocketmine/block/RedstoneRepeater.php @@ -97,7 +97,7 @@ class RedstoneRepeater extends Flowable{ return false; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(++$this->delay > 4){ $this->delay = 1; } diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index adacce1b8..e99ce48f1 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -65,7 +65,7 @@ class Sapling extends Flowable{ return false; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal //TODO: change log type Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType); diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index dcf03cbf7..d9ce7087e 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -59,7 +59,7 @@ class Sugarcane extends Flowable{ return "Sugarcane"; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){ for($y = 1; $y < 3; ++$y){ diff --git a/src/pocketmine/block/TNT.php b/src/pocketmine/block/TNT.php index 76421375b..3a9caf54d 100644 --- a/src/pocketmine/block/TNT.php +++ b/src/pocketmine/block/TNT.php @@ -52,7 +52,7 @@ class TNT extends Solid{ return 0; } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($item instanceof FlintSteel){ $item->applyDamage(1); $this->ignite(); diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index a943d6ad1..85583ac77 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -87,7 +87,7 @@ class Trapdoor extends Transparent{ return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onActivate(Item $item, Player $player = null) : bool{ + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->open = !$this->open; $this->level->setBlock($this, $this); $this->level->addSound($this, new DoorSound()); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index c8ee60798..4359f1b44 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1794,7 +1794,7 @@ class Level implements ChunkManager, Metadatable{ $ev = new PlayerInteractEvent($player, $item, $blockClicked, $clickVector, $face, PlayerInteractEvent::RIGHT_CLICK_BLOCK); $ev->call(); if(!$ev->isCancelled()){ - if(!$player->isSneaking() and $blockClicked->onActivate($item, $player)){ + if(!$player->isSneaking() and $blockClicked->onActivate($item, $face, $clickVector, $player)){ return true; } @@ -1804,7 +1804,7 @@ class Level implements ChunkManager, Metadatable{ }else{ return false; } - }elseif($blockClicked->onActivate($item, $player)){ + }elseif($blockClicked->onActivate($item, $face, $clickVector, $player)){ return true; }