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