mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
For blocks, we now use 'block-item state' and 'block-only state', which should be much clearer for people implementing custom stuff. 'block-item state', as the name suggests, sticks to the item when the block is acquired as an item. 'block-only state' applies only to the block and is discarded when the block is acquired as an item. 'type data' for items was also renamed, since 'type' is too ambiguous to be anything but super confusing.
93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\block\utils;
|
|
|
|
use pocketmine\block\Block;
|
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
|
use pocketmine\entity\projectile\Projectile;
|
|
use pocketmine\item\Durable;
|
|
use pocketmine\item\enchantment\VanillaEnchantments;
|
|
use pocketmine\item\Item;
|
|
use pocketmine\item\ItemTypeIds;
|
|
use pocketmine\math\RayTraceResult;
|
|
use pocketmine\math\Vector3;
|
|
use pocketmine\player\Player;
|
|
use pocketmine\world\sound\FireExtinguishSound;
|
|
use pocketmine\world\sound\FlintSteelSound;
|
|
|
|
trait CandleTrait{
|
|
private bool $lit = false;
|
|
|
|
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
|
$w->bool($this->lit);
|
|
}
|
|
|
|
public function getLightLevel() : int{
|
|
return $this->lit ? 3 : 0;
|
|
}
|
|
|
|
public function isLit() : bool{ return $this->lit; }
|
|
|
|
/** @return $this */
|
|
public function setLit(bool $lit) : self{
|
|
$this->lit = $lit;
|
|
return $this;
|
|
}
|
|
|
|
/** @see Block::onInteract() */
|
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
|
if($item->getTypeId() === ItemTypeIds::FLINT_AND_STEEL || $item->hasEnchantment(VanillaEnchantments::FIRE_ASPECT())){
|
|
if($this->lit){
|
|
return true;
|
|
}
|
|
if($item instanceof Durable){
|
|
$item->applyDamage(1);
|
|
}
|
|
$this->position->getWorld()->addSound($this->position, new FlintSteelSound());
|
|
$this->position->getWorld()->setBlock($this->position, $this->setLit(true));
|
|
|
|
return true;
|
|
}
|
|
if($item->isNull()){ //candle can only be extinguished with an empty hand
|
|
if(!$this->lit){
|
|
return true;
|
|
}
|
|
$this->position->getWorld()->addSound($this->position, new FireExtinguishSound());
|
|
$this->position->getWorld()->setBlock($this->position, $this->setLit(false));
|
|
|
|
return true;
|
|
}
|
|
|
|
//yes, this is intentional! in vanilla, if the candle is not interacted with, a block is placed.
|
|
return false;
|
|
}
|
|
|
|
/** @see Block::onProjectileHit() */
|
|
public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{
|
|
if(!$this->lit && $projectile->isOnFire()){
|
|
$this->position->getWorld()->setBlock($this->position, $this->setLit(true));
|
|
}
|
|
}
|
|
}
|