add sound and anvil damage

This commit is contained in:
ShockedPlot7560 2024-08-10 23:51:38 +02:00
parent 804731d87f
commit 654b44447e
No known key found for this signature in database
GPG Key ID: D7539B420F1FA86E

View File

@ -23,14 +23,20 @@ declare(strict_types=1);
namespace pocketmine\inventory\transaction;
use pocketmine\block\Anvil;
use pocketmine\block\inventory\AnvilInventory;
use pocketmine\block\utils\AnvilHelper;
use pocketmine\block\utils\AnvilResult;
use pocketmine\block\VanillaBlocks;
use pocketmine\event\player\PlayerUseAnvilEvent;
use pocketmine\item\Item;
use pocketmine\item\VanillaItems;
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\world\sound\AnvilBreakSound;
use pocketmine\world\sound\AnvilUseSound;
use function count;
use function mt_rand;
class AnvilTransaction extends InventoryTransaction{
private ?Item $baseItem = null;
@ -115,6 +121,26 @@ class AnvilTransaction extends InventoryTransaction{
if($this->source->hasFiniteResources()){
$this->source->getXpManager()->subtractXpLevels($this->expectedResult->getRepairCost());
}
$inventory = $this->source->getCurrentWindow();
if($inventory instanceof AnvilInventory){
$world = $inventory->getHolder()->getWorld();
if(mt_rand(0, 12) === 0){
$anvilBlock = $world->getBlock($inventory->getHolder());
if($anvilBlock instanceof Anvil){
$newDamage = $anvilBlock->getDamage() + 1;
if($newDamage > Anvil::VERY_DAMAGED){
$newBlock = VanillaBlocks::AIR();
$world->addSound($inventory->getHolder(), new AnvilBreakSound());
}else{
$newBlock = $anvilBlock->setDamage($newDamage);
}
$world->setBlock($inventory->getHolder(), $newBlock);
}
}
$world->addSound($inventory->getHolder(), new AnvilUseSound());
}
}
protected function callExecuteEvent() : bool{