Files
PocketMine-MP/src/block/Furnace.php
Dylan K. Taylor 496ab808a8 First step towards standardised opening logic for containers and menu blocks
we'll want to introduce interfaces for these, but getting the code deduplicated is enough to start with.
2025-08-30 21:35:42 +01:00

81 lines
2.6 KiB
PHP

<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\inventory\window\FurnaceInventoryWindow;
use pocketmine\block\tile\Furnace as TileFurnace;
use pocketmine\block\utils\ContainerTrait;
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
use pocketmine\block\utils\HorizontalFacing;
use pocketmine\block\utils\Lightable;
use pocketmine\block\utils\LightableTrait;
use pocketmine\crafting\FurnaceType;
use pocketmine\data\runtime\RuntimeDataDescriber;
use pocketmine\inventory\Inventory;
use pocketmine\player\InventoryWindow;
use pocketmine\player\Player;
use pocketmine\world\Position;
use function mt_rand;
class Furnace extends Opaque implements Lightable, HorizontalFacing{
use ContainerTrait;
use FacesOppositePlacingPlayerTrait;
use LightableTrait;
protected FurnaceType $furnaceType;
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, FurnaceType $furnaceType){
$this->furnaceType = $furnaceType;
parent::__construct($idInfo, $name, $typeInfo);
}
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
$w->enum($this->facing);
$w->bool($this->lit);
}
public function getFurnaceType() : FurnaceType{
return $this->furnaceType;
}
public function getLightLevel() : int{
return $this->lit ? 13 : 0;
}
protected function newWindow(Player $player, Inventory $inventory, Position $position) : InventoryWindow{
return new FurnaceInventoryWindow($player, $inventory, $position, $this->furnaceType);
}
public function onScheduledUpdate() : void{
$world = $this->position->getWorld();
$furnace = $world->getTile($this->position);
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
$world->addSound($this->position, $furnace->getFurnaceType()->getCookSound());
}
$world->scheduleDelayedBlockUpdate($this->position, 1); //TODO: check this
}
}
}