PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
Furnace.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
27use pocketmine\block\tile\Furnace as TileFurnace;
29use pocketmine\block\utils\ContainerTrait;
30use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
33use pocketmine\block\utils\LightableTrait;
34use pocketmine\crafting\FurnaceType;
40use function mt_rand;
41
43 use ContainerTrait;
44 use FacesOppositePlacingPlayerTrait;
45 use LightableTrait;
46
47 protected FurnaceType $furnaceType;
48
49 public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, FurnaceType $furnaceType){
50 $this->furnaceType = $furnaceType;
51 parent::__construct($idInfo, $name, $typeInfo);
52 }
53
54 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
55 $w->enum($this->facing);
56 $w->bool($this->lit);
57 }
58
59 public function getFurnaceType() : FurnaceType{
60 return $this->furnaceType;
61 }
62
63 public function getLightLevel() : int{
64 return $this->lit ? 13 : 0;
65 }
66
67 protected function newMenu(Player $player, Inventory $inventory, Position $position) : InventoryWindow{
68 return new FurnaceInventoryWindow($player, $inventory, $position, $this->furnaceType);
69 }
70
71 public function onScheduledUpdate() : void{
72 $world = $this->position->getWorld();
73 $furnace = $world->getTile($this->position);
74 if($furnace instanceof TileFurnace && $furnace->onUpdate()){
75 if(mt_rand(1, 60) === 1){ //in vanilla this is between 1 and 5 seconds; try to average about 3
76 $world->addSound($this->position, $furnace->getFurnaceType()->getCookSound());
77 }
78 $world->scheduleDelayedBlockUpdate($this->position, 1); //TODO: check this
79 }
80 }
81}
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition Furnace.php:54