Block: add face and clickVector to onActivate() parameters, closes #267

this is an old old old issue, i don't know why it wasn't addressed sooner.
This commit is contained in:
Dylan K. Taylor 2019-02-13 14:29:59 +00:00
parent 55be0716d8
commit 7b6d76871c
28 changed files with 45 additions and 31 deletions

View File

@ -78,7 +78,7 @@ class Anvil extends Fallable{
return AxisAlignedBB::one()->squash(Facing::axis(Facing::rotateY($this->facing, false)), 1 / 8); 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){ if($player instanceof Player){
$player->addWindow(new AnvilInventory($this)); $player->addWindow(new AnvilInventory($this));
} }

View File

@ -148,7 +148,7 @@ class Bed extends Transparent{
return null; 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){ if($player !== null){
$other = $this->getOtherHalf(); $other = $this->getOtherHalf();
if($other === null){ if($other === null){

View File

@ -402,11 +402,13 @@ class Block extends Position implements BlockIds, Metadatable{
* Do actions when activated by Item. Returns if it has done anything * Do actions when activated by Item. Returns if it has done anything
* *
* @param Item $item * @param Item $item
* @param int $face
* @param Vector3 $clickVector
* @param Player|null $player * @param Player|null $player
* *
* @return bool * @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; return false;
} }

View File

@ -63,7 +63,7 @@ abstract class Button extends Flowable{
abstract protected function getActivationTime() : int; 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){ if(!$this->powered){
$this->powered = true; $this->powered = true;
$this->level->setBlock($this, $this); $this->level->setBlock($this, $this);

View File

@ -96,7 +96,7 @@ class Cake extends Transparent implements FoodSource{
return false; 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){ if($player !== null){
$player->consumeObject($this); $player->consumeObject($this);
return true; return true;

View File

@ -106,7 +106,7 @@ class Chest extends Transparent{
return false; 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){ if($player instanceof Player){
$chest = $this->getLevel()->getTile($this); $chest = $this->getLevel()->getTile($this);

View File

@ -25,12 +25,14 @@ namespace pocketmine\block;
use pocketmine\item\Hoe; use pocketmine\item\Hoe;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
class CoarseDirt extends Dirt{ class CoarseDirt extends Dirt{
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 Hoe){ if($face === Facing::UP and $item instanceof Hoe){
$item->applyDamage(1); $item->applyDamage(1);
$this->getLevel()->setBlock($this, BlockFactory::get(Block::DIRT)); $this->getLevel()->setBlock($this, BlockFactory::get(Block::DIRT));
return true; return true;

View File

@ -94,7 +94,7 @@ class CocoaBlock extends Transparent{
return false; 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 if($this->age < 2 and $item->getId() === Item::DYE and $item->getDamage() === 15){ //bone meal
$this->age++; $this->age++;
$this->level->setBlock($this, $this); $this->level->setBlock($this, $this);

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\inventory\CraftingGrid; use pocketmine\inventory\CraftingGrid;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
class CraftingTable extends Solid{ class CraftingTable extends Solid{
@ -47,7 +48,7 @@ class CraftingTable extends Solid{
return BlockToolType::TYPE_AXE; 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){ if($player instanceof Player){
$player->setCraftingGrid(new CraftingGrid($player, CraftingGrid::SIZE_BIG)); $player->setCraftingGrid(new CraftingGrid($player, CraftingGrid::SIZE_BIG));
} }

View File

@ -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 if($this->age < 7 and $item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
$block = clone $this; $block = clone $this;
$block->age += mt_rand(2, 5); $block->age += mt_rand(2, 5);

View File

@ -27,6 +27,7 @@ use pocketmine\block\utils\BlockDataValidator;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing; use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
class DaylightSensor extends Transparent{ class DaylightSensor extends Transparent{
@ -93,7 +94,7 @@ class DaylightSensor extends Transparent{
return AxisAlignedBB::one()->trim(Facing::UP, 0.5); 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->inverted = !$this->inverted;
$this->level->setBlock($this, $this); $this->level->setBlock($this, $this);
return true; return true;

View File

@ -25,6 +25,8 @@ namespace pocketmine\block;
use pocketmine\item\Hoe; use pocketmine\item\Hoe;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
class Dirt extends Solid{ class Dirt extends Solid{
@ -39,8 +41,8 @@ class Dirt extends Solid{
return BlockToolType::TYPE_SHOVEL; return BlockToolType::TYPE_SHOVEL;
} }
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 Hoe){ if($face === Facing::UP and $item instanceof Hoe){
$item->applyDamage(1); $item->applyDamage(1);
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND)); $this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND));

View File

@ -134,7 +134,7 @@ abstract class Door extends Transparent{
return false; 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; $this->open = !$this->open;
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);

View File

@ -28,6 +28,7 @@ use pocketmine\item\Item;
use pocketmine\item\TieredTool; use pocketmine\item\TieredTool;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing; use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\EnchantTable as TileEnchantingTable; use pocketmine\tile\EnchantTable as TileEnchantingTable;
@ -67,7 +68,7 @@ class EnchantingTable extends Transparent{
return AxisAlignedBB::one()->trim(Facing::UP, 0.25); 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){ if($player instanceof Player){
//TODO lock //TODO lock

View File

@ -27,6 +27,7 @@ use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\item\TieredTool; use pocketmine\item\TieredTool;
use pocketmine\math\Facing; use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\EnderChest as TileEnderChest; use pocketmine\tile\EnderChest as TileEnderChest;
@ -62,7 +63,7 @@ class EnderChest extends Chest{
return TieredTool::TIER_WOODEN; 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){ if($player instanceof Player){
$enderChest = $this->getLevel()->getTile($this); $enderChest = $this->getLevel()->getTile($this);
if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){ if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){

View File

@ -76,7 +76,7 @@ class FenceGate extends Transparent{
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); 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->open = !$this->open;
if($this->open and $player !== null){ if($this->open and $player !== null){
$playerFacing = $player->getHorizontalFacing(); $playerFacing = $player->getHorizontalFacing();

View File

@ -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); $pot = $this->getLevel()->getTile($this);
if(!($pot instanceof TileFlowerPot)){ if(!($pot instanceof TileFlowerPot)){
return false; return false;

View File

@ -106,7 +106,7 @@ class Furnace extends Solid{
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); 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){ if($player instanceof Player){
$furnace = $this->getLevel()->getTile($this); $furnace = $this->getLevel()->getTile($this);
if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){ if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){

View File

@ -30,6 +30,7 @@ use pocketmine\item\ItemFactory;
use pocketmine\item\Shovel; use pocketmine\item\Shovel;
use pocketmine\level\generator\object\TallGrass as TallGrassObject; use pocketmine\level\generator\object\TallGrass as TallGrassObject;
use pocketmine\math\Facing; use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\Random; use pocketmine\utils\Random;
use function mt_rand; 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){ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){
$item->pop(); $item->pop();
TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2); TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);

View File

@ -63,7 +63,7 @@ class ItemFrame extends Flowable{
return "Item Frame"; 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); $tile = $this->level->getTile($this);
if($tile instanceof TileItemFrame){ if($tile instanceof TileItemFrame){
if($tile->hasItem()){ if($tile->hasItem()){

View File

@ -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->powered = !$this->powered;
$this->level->setBlock($this, $this); $this->level->setBlock($this, $this);
$this->level->broadcastLevelSoundEvent( $this->level->broadcastLevelSoundEvent(

View File

@ -75,7 +75,7 @@ class RedstoneOre extends Solid{
return $this->getLevel()->setBlock($this, $this, false); 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){ if(!$this->lit){
$this->lit = true; $this->lit = true;
$this->getLevel()->setBlock($this, $this); //no return here - this shouldn't prevent block placement $this->getLevel()->setBlock($this, $this); //no return here - this shouldn't prevent block placement

View File

@ -97,7 +97,7 @@ class RedstoneRepeater extends Flowable{
return false; 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){ if(++$this->delay > 4){
$this->delay = 1; $this->delay = 1;
} }

View File

@ -65,7 +65,7 @@ class Sapling extends Flowable{
return false; 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 if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
//TODO: change log type //TODO: change log type
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType); Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType);

View File

@ -59,7 +59,7 @@ class Sugarcane extends Flowable{
return "Sugarcane"; 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($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){ if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){

View File

@ -52,7 +52,7 @@ class TNT extends Solid{
return 0; 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){ if($item instanceof FlintSteel){
$item->applyDamage(1); $item->applyDamage(1);
$this->ignite(); $this->ignite();

View File

@ -87,7 +87,7 @@ class Trapdoor extends Transparent{
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); 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->open = !$this->open;
$this->level->setBlock($this, $this); $this->level->setBlock($this, $this);
$this->level->addSound($this, new DoorSound()); $this->level->addSound($this, new DoorSound());

View File

@ -1794,7 +1794,7 @@ class Level implements ChunkManager, Metadatable{
$ev = new PlayerInteractEvent($player, $item, $blockClicked, $clickVector, $face, PlayerInteractEvent::RIGHT_CLICK_BLOCK); $ev = new PlayerInteractEvent($player, $item, $blockClicked, $clickVector, $face, PlayerInteractEvent::RIGHT_CLICK_BLOCK);
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
if(!$player->isSneaking() and $blockClicked->onActivate($item, $player)){ if(!$player->isSneaking() and $blockClicked->onActivate($item, $face, $clickVector, $player)){
return true; return true;
} }
@ -1804,7 +1804,7 @@ class Level implements ChunkManager, Metadatable{
}else{ }else{
return false; return false;
} }
}elseif($blockClicked->onActivate($item, $player)){ }elseif($blockClicked->onActivate($item, $face, $clickVector, $player)){
return true; return true;
} }