PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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;
28use pocketmine\block\utils\LightableTrait;
29use pocketmine\crafting\FurnaceType;
34use function mt_rand;
35
36class Furnace extends Opaque{
37 use FacesOppositePlacingPlayerTrait;
38 use LightableTrait;
39
40 protected FurnaceType $furnaceType;
41
42 public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, FurnaceType $furnaceType){
43 $this->furnaceType = $furnaceType;
44 parent::__construct($idInfo, $name, $typeInfo);
45 }
46
47 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
48 $w->horizontalFacing($this->facing);
49 $w->bool($this->lit);
50 }
51
52 public function getFurnaceType() : FurnaceType{
53 return $this->furnaceType;
54 }
55
56 public function getLightLevel() : int{
57 return $this->lit ? 13 : 0;
58 }
59
60 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
61 if($player instanceof Player){
62 $furnace = $this->position->getWorld()->getTile($this->position);
63 if($furnace instanceof TileFurnace && $furnace->canOpenWith($item->getCustomName())){
64 $player->setCurrentWindow($furnace->getInventory());
65 }
66 }
67
68 return true;
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:47
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Furnace.php:60