mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 10:49:10 +00:00
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:
parent
55be0716d8
commit
7b6d76871c
@ -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));
|
||||
}
|
||||
|
@ -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){
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()){
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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())){
|
||||
|
@ -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);
|
||||
|
@ -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()){
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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){
|
||||
|
@ -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();
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user