PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
CandleTrait.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\utils;
25
39
40trait CandleTrait{
41 use LightableTrait;
42
43 public function getLightLevel() : int{
44 return $this->lit ? 3 : 0;
45 }
46
52 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
53 if($item->getTypeId() === ItemTypeIds::FIRE_CHARGE || $item->getTypeId() === ItemTypeIds::FLINT_AND_STEEL || $item->hasEnchantment(VanillaEnchantments::FIRE_ASPECT())){
54 if($this->lit){
55 return true;
56 }
57 if($item instanceof Durable){
58 $item->applyDamage(1);
59 }elseif($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){
60 $item->pop();
61 //TODO: not sure if this is intentional, but it's what Bedrock currently does as of 1.20.10
62 $this->position->getWorld()->addSound($this->position, new BlazeShootSound());
63 }
64 $this->position->getWorld()->addSound($this->position, new FlintSteelSound());
65 $this->position->getWorld()->setBlock($this->position, $this->setLit(true));
66
67 return true;
68 }
69 if($item->isNull()){ //candle can only be extinguished with an empty hand
70 if(!$this->lit){
71 return true;
72 }
73 $this->position->getWorld()->addSound($this->position, new FireExtinguishSound());
74 $this->position->getWorld()->setBlock($this->position, $this->setLit(false));
75
76 return true;
77 }
78
79 //yes, this is intentional! in vanilla, if the candle is not interacted with, a block is placed.
80 return false;
81 }
82
84 public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{
85 if(!$this->lit && $projectile->isOnFire()){
86 $this->position->getWorld()->setBlock($this->position, $this->setLit(true));
87 }
88 }
89}