From b4d55e4384e8f63b64db23a4fad8d1cb9da1d320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Le=C3=B3n?= <58715544+JavierLeon9966@users.noreply.github.com> Date: Wed, 18 Oct 2023 06:40:01 -0300 Subject: [PATCH] Fixed dirt and grass block interactions when clicking on sides other than the top (#6071) --- src/block/Dirt.php | 7 ++++++- src/block/Grass.php | 29 ++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/block/Dirt.php b/src/block/Dirt.php index 539454b41..fd6dc9d09 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -59,7 +59,12 @@ class Dirt extends Opaque{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $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); $newBlock = $this->dirtType->equals(DirtType::NORMAL()) ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT(); diff --git a/src/block/Grass.php b/src/block/Grass.php index 709dc6a9d..f3fd96a34 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -82,7 +82,7 @@ class Grass extends Opaque{ } 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; } $world = $this->position->getWorld(); @@ -91,20 +91,23 @@ class Grass extends Opaque{ TallGrassObject::growGrass($world, $this->position, new Random(mt_rand()), 8, 2); return true; - }elseif($item instanceof Hoe){ - $item->applyDamage(1); - $newBlock = VanillaBlocks::FARMLAND(); - $world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); - $world->setBlock($this->position, $newBlock); + } + if($face !== Facing::DOWN){ + if($item instanceof Hoe){ + $item->applyDamage(1); + $newBlock = VanillaBlocks::FARMLAND(); + $world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); + $world->setBlock($this->position, $newBlock); - return true; - }elseif($item instanceof Shovel && $this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::AIR){ - $item->applyDamage(1); - $newBlock = VanillaBlocks::GRASS_PATH(); - $world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); - $world->setBlock($this->position, $newBlock); + return true; + }elseif($item instanceof Shovel){ + $item->applyDamage(1); + $newBlock = VanillaBlocks::GRASS_PATH(); + $world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); + $world->setBlock($this->position, $newBlock); - return true; + return true; + } } return false;