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