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