Added FurnaceType->getCookSound()

This commit is contained in:
Dylan K. Taylor 2022-01-25 19:01:49 +00:00
parent 0bf5f97fe9
commit ea161af4e5
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 11 additions and 15 deletions

View File

@ -26,14 +26,9 @@ namespace pocketmine\block;
use pocketmine\block\tile\Furnace as TileFurnace; use pocketmine\block\tile\Furnace as TileFurnace;
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait; use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait; use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait;
use pocketmine\crafting\FurnaceType;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\world\sound\BlastFurnaceSound;
use pocketmine\world\sound\FurnaceSound;
use pocketmine\world\sound\SmokerSound;
use function mt_rand; use function mt_rand;
class Furnace extends Opaque{ class Furnace extends Opaque{
@ -91,12 +86,7 @@ class Furnace extends Opaque{
$furnace = $this->position->getWorld()->getTile($this->position); $furnace = $this->position->getWorld()->getTile($this->position);
if($furnace instanceof TileFurnace && $furnace->onUpdate()){ if($furnace instanceof TileFurnace && $furnace->onUpdate()){
if(mt_rand(1, 60) === 1){ //in vanilla this is between 1 and 5 seconds; try to average about 3 if(mt_rand(1, 60) === 1){ //in vanilla this is between 1 and 5 seconds; try to average about 3
$this->position->getWorld()->addSound($this->position, match($furnace->getFurnaceType()->id()){ $this->position->getWorld()->addSound($this->position, $furnace->getFurnaceType()->getCookSound());
FurnaceType::FURNACE()->id() => new FurnaceSound(),
FurnaceType::BLAST_FURNACE()->id() => new BlastFurnaceSound(),
FurnaceType::SMOKER()->id() => new SmokerSound(),
default => throw new AssumptionFailedError("Unreachable")
});
} }
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, 1); //TODO: check this $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, 1); //TODO: check this
} }

View File

@ -24,6 +24,10 @@ declare(strict_types=1);
namespace pocketmine\crafting; namespace pocketmine\crafting;
use pocketmine\utils\EnumTrait; use pocketmine\utils\EnumTrait;
use pocketmine\world\sound\BlastFurnaceSound;
use pocketmine\world\sound\FurnaceSound;
use pocketmine\world\sound\SmokerSound;
use pocketmine\world\sound\Sound;
/** /**
* This doc-block is generated automatically, do not modify it manually. * This doc-block is generated automatically, do not modify it manually.
@ -42,15 +46,17 @@ final class FurnaceType{
protected static function setup() : void{ protected static function setup() : void{
self::registerAll( self::registerAll(
new self("furnace", 200), new self("furnace", 200, new FurnaceSound()),
new self("blast_furnace", 100), new self("blast_furnace", 100, new BlastFurnaceSound()),
new self("smoker", 100), new self("smoker", 100, new SmokerSound()),
); );
} }
private function __construct(string $enumName, private int $cookDurationTicks){ private function __construct(string $enumName, private int $cookDurationTicks, private Sound $cookSound){
$this->Enum___construct($enumName); $this->Enum___construct($enumName);
} }
public function getCookDurationTicks() : int{ return $this->cookDurationTicks; } public function getCookDurationTicks() : int{ return $this->cookDurationTicks; }
public function getCookSound() : Sound{ return $this->cookSound; }
} }