PocketMine-MP 5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
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
26use pocketmine\block\tile\Furnace as TileFurnace;
27use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
29use pocketmine\block\utils\LightableTrait;
30use pocketmine\crafting\FurnaceType;
35use function mt_rand;
36
37class Furnace extends Opaque implements Lightable{
38 use FacesOppositePlacingPlayerTrait;
39 use LightableTrait;
40
41 protected FurnaceType $furnaceType;
42
43 public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, FurnaceType $furnaceType){
44 $this->furnaceType = $furnaceType;
45 parent::__construct($idInfo, $name, $typeInfo);
46 }
47
48 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
49 $w->horizontalFacing($this->facing);
50 $w->bool($this->lit);
51 }
52
53 public function getFurnaceType() : FurnaceType{
54 return $this->furnaceType;
55 }
56
57 public function getLightLevel() : int{
58 return $this->lit ? 13 : 0;
59 }
60
61 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
62 if($player instanceof Player){
63 $furnace = $this->position->getWorld()->getTile($this->position);
64 if($furnace instanceof TileFurnace && $furnace->canOpenWith($item->getCustomName())){
65 $player->setCurrentWindow($furnace->getInventory());
66 }
67 }
68
69 return true;
70 }
71
72 public function onScheduledUpdate() : void{
73 $world = $this->position->getWorld();
74 $furnace = $world->getTile($this->position);
75 if($furnace instanceof TileFurnace && $furnace->onUpdate()){
76 if(mt_rand(1, 60) === 1){ //in vanilla this is between 1 and 5 seconds; try to average about 3
77 $world->addSound($this->position, $furnace->getFurnaceType()->getCookSound());
78 }
79 $world->scheduleDelayedBlockUpdate($this->position, 1); //TODO: check this
80 }
81 }
82}
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition Furnace.php:48
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Furnace.php:61