mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 20:58:34 +00:00
Fixed dirt and grass block interactions when clicking on sides other than the top (#6071)
This commit is contained in:
parent
932116fa52
commit
b4d55e4384
@ -59,7 +59,12 @@ class Dirt extends Opaque{
|
|||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
if($face === Facing::UP && $item instanceof Hoe){
|
if($face !== Facing::DOWN && $item instanceof Hoe){
|
||||||
|
$up = $this->getSide(Facing::UP);
|
||||||
|
if($up->getTypeId() !== BlockTypeIds::AIR){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$item->applyDamage(1);
|
$item->applyDamage(1);
|
||||||
|
|
||||||
$newBlock = $this->dirtType->equals(DirtType::NORMAL()) ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT();
|
$newBlock = $this->dirtType->equals(DirtType::NORMAL()) ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT();
|
||||||
|
@ -82,7 +82,7 @@ class Grass extends Opaque{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
if($face !== Facing::UP){
|
if($this->getSide(Facing::UP)->getTypeId() !== BlockTypeIds::AIR){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
@ -91,14 +91,16 @@ class Grass extends Opaque{
|
|||||||
TallGrassObject::growGrass($world, $this->position, new Random(mt_rand()), 8, 2);
|
TallGrassObject::growGrass($world, $this->position, new Random(mt_rand()), 8, 2);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($item instanceof Hoe){
|
}
|
||||||
|
if($face !== Facing::DOWN){
|
||||||
|
if($item instanceof Hoe){
|
||||||
$item->applyDamage(1);
|
$item->applyDamage(1);
|
||||||
$newBlock = VanillaBlocks::FARMLAND();
|
$newBlock = VanillaBlocks::FARMLAND();
|
||||||
$world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock));
|
$world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock));
|
||||||
$world->setBlock($this->position, $newBlock);
|
$world->setBlock($this->position, $newBlock);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($item instanceof Shovel && $this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::AIR){
|
}elseif($item instanceof Shovel){
|
||||||
$item->applyDamage(1);
|
$item->applyDamage(1);
|
||||||
$newBlock = VanillaBlocks::GRASS_PATH();
|
$newBlock = VanillaBlocks::GRASS_PATH();
|
||||||
$world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock));
|
$world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock));
|
||||||
@ -106,6 +108,7 @@ class Grass extends Opaque{
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user