diff --git a/src/block/Dirt.php b/src/block/Dirt.php index 29df9f545..9264c0808 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -28,6 +28,7 @@ use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; +use pocketmine\world\sound\ItemUseOnBlockSound; class Dirt extends Opaque{ @@ -60,7 +61,10 @@ class Dirt extends Opaque{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face === Facing::UP and $item instanceof Hoe){ $item->applyDamage(1); - $this->position->getWorld()->setBlock($this->position, $this->coarse ? VanillaBlocks::DIRT() : VanillaBlocks::FARMLAND()); + + $newBlock = $this->coarse ? VanillaBlocks::DIRT() : VanillaBlocks::FARMLAND(); + $this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); + $this->position->getWorld()->setBlock($this->position, $newBlock); return true; } diff --git a/src/block/Grass.php b/src/block/Grass.php index e6a128850..08565455f 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -33,6 +33,7 @@ use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\utils\Random; use pocketmine\world\generator\object\TallGrass as TallGrassObject; +use pocketmine\world\sound\ItemUseOnBlockSound; use function mt_rand; class Grass extends Opaque{ @@ -97,12 +98,16 @@ class Grass extends Opaque{ return true; }elseif($item instanceof Hoe){ $item->applyDamage(1); - $this->position->getWorld()->setBlock($this->position, VanillaBlocks::FARMLAND()); + $newBlock = VanillaBlocks::FARMLAND(); + $this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); + $this->position->getWorld()->setBlock($this->position, $newBlock); return true; }elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === BlockLegacyIds::AIR){ $item->applyDamage(1); - $this->position->getWorld()->setBlock($this->position, VanillaBlocks::GRASS_PATH()); + $newBlock = VanillaBlocks::GRASS_PATH(); + $this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); + $this->position->getWorld()->setBlock($this->position, $newBlock); return true; } diff --git a/src/world/sound/ItemUseOnBlockSound.php b/src/world/sound/ItemUseOnBlockSound.php new file mode 100644 index 000000000..cdebc2c64 --- /dev/null +++ b/src/world/sound/ItemUseOnBlockSound.php @@ -0,0 +1,48 @@ +block; } + + public function encode(Vector3 $pos) : array{ + return [LevelSoundEventPacket::nonActorSound( + LevelSoundEvent::ITEM_USE_ON, + $pos, + false, + RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()) + )]; + } +}