mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
FlowerPot: allow removing the planted item
closes #4896 closes #4898 this is not completely consistent with client-side predictions due to a bug in the client, which I believe is a problem limited to the legacy transaction system.
This commit is contained in:
parent
7d1464f0a1
commit
4fc712119f
@ -82,6 +82,10 @@ class FlowerPot extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->isValidPlant($block);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isValidPlant(Block $block) : bool{
|
||||||
return
|
return
|
||||||
$block instanceof Cactus ||
|
$block instanceof Cactus ||
|
||||||
$block instanceof DeadBush ||
|
$block instanceof DeadBush ||
|
||||||
@ -115,10 +119,28 @@ class FlowerPot extends Flowable{
|
|||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$plant = $item->getBlock();
|
$plant = $item->getBlock();
|
||||||
if(!$this->canAddPlant($plant)){
|
if($this->plant !== null){
|
||||||
|
if($this->isValidPlant($plant)){
|
||||||
|
//for some reason, vanilla doesn't remove the contents of the pot if the held item is plantable
|
||||||
|
//and will also cause a new plant to be placed if clicking on the side
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$removedItems = [$this->plant->asItem()];
|
||||||
|
if($player !== null){
|
||||||
|
//this one just has to be a weirdo :(
|
||||||
|
//this is the only block that directly adds items to the player inventory instead of just dropping items
|
||||||
|
$removedItems = $player->getInventory()->addItem(...$removedItems);
|
||||||
|
}
|
||||||
|
foreach($removedItems as $drops){
|
||||||
|
$this->position->getWorld()->dropItem($this->position->add(0.5, 0.5, 0.5), $drops);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setPlant(null);
|
||||||
|
$this->position->getWorld()->setBlock($this->position, $this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$this->setPlant($plant);
|
$this->setPlant($plant);
|
||||||
$item->pop();
|
$item->pop();
|
||||||
$this->position->getWorld()->setBlock($this->position, $this);
|
$this->position->getWorld()->setBlock($this->position, $this);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user