mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Cleaned up tile NBT handling, use new CompoundTag API methods
This commit is contained in:
@ -33,14 +33,17 @@ use pocketmine\nbt\tag\FloatTag;
|
||||
use pocketmine\Player;
|
||||
|
||||
class ItemFrame extends Spawnable{
|
||||
const TAG_ITEM_ROTATION = "ItemRotation";
|
||||
const TAG_ITEM_DROP_CHANCE = "ItemDropChance";
|
||||
const TAG_ITEM = "Item";
|
||||
|
||||
public function __construct(Level $level, CompoundTag $nbt){
|
||||
if(!isset($nbt->ItemRotation)){
|
||||
$nbt->ItemRotation = new ByteTag("ItemRotation", 0);
|
||||
if(!($nbt->getTag(self::TAG_ITEM_ROTATION) instanceof ByteTag)){
|
||||
$nbt->setTag(new ByteTag(self::TAG_ITEM_ROTATION, 0));
|
||||
}
|
||||
|
||||
if(!isset($nbt->ItemDropChance)){
|
||||
$nbt->ItemDropChance = new FloatTag("ItemDropChance", 1.0);
|
||||
if(!($nbt->getTag(self::TAG_ITEM_DROP_CHANCE) instanceof FloatTag)){
|
||||
$nbt->setTag(new FloatTag(self::TAG_ITEM_DROP_CHANCE, 1.0));
|
||||
}
|
||||
|
||||
parent::__construct($level, $nbt);
|
||||
@ -51,52 +54,52 @@ class ItemFrame extends Spawnable{
|
||||
}
|
||||
|
||||
public function getItem() : Item{
|
||||
if(isset($this->namedtag->Item)){
|
||||
return Item::nbtDeserialize($this->namedtag->Item);
|
||||
}else{
|
||||
return ItemFactory::get(Item::AIR, 0, 0);
|
||||
$c = $this->namedtag->getCompoundTag(self::TAG_ITEM);
|
||||
if($c !== null){
|
||||
return Item::nbtDeserialize($c);
|
||||
}
|
||||
|
||||
return ItemFactory::get(Item::AIR, 0, 0);
|
||||
}
|
||||
|
||||
public function setItem(Item $item = null){
|
||||
if($item !== null and !$item->isNull()){
|
||||
$this->namedtag->Item = $item->nbtSerialize(-1, "Item");
|
||||
$this->namedtag->setTag($item->nbtSerialize(-1, self::TAG_ITEM));
|
||||
}else{
|
||||
unset($this->namedtag->Item);
|
||||
$this->namedtag->removeTag(self::TAG_ITEM);
|
||||
}
|
||||
$this->onChanged();
|
||||
}
|
||||
|
||||
public function getItemRotation() : int{
|
||||
return $this->namedtag->ItemRotation->getValue();
|
||||
return $this->namedtag->getByte(self::TAG_ITEM_ROTATION);
|
||||
}
|
||||
|
||||
public function setItemRotation(int $rotation){
|
||||
$this->namedtag->ItemRotation->setValue($rotation);
|
||||
$this->namedtag->setByte(self::TAG_ITEM_ROTATION, $rotation);
|
||||
$this->onChanged();
|
||||
}
|
||||
|
||||
public function getItemDropChance() : float{
|
||||
return $this->namedtag->ItemDropChance->getValue();
|
||||
return $this->namedtag->getFloat(self::TAG_ITEM_DROP_CHANCE);
|
||||
}
|
||||
|
||||
public function setItemDropChance(float $chance){
|
||||
$this->namedtag->ItemDropChance->setValue($chance);
|
||||
$this->namedtag->setFloat(self::TAG_ITEM_DROP_CHANCE, $chance);
|
||||
$this->onChanged();
|
||||
}
|
||||
|
||||
public function addAdditionalSpawnData(CompoundTag $nbt) : void{
|
||||
$nbt->ItemDropChance = $this->namedtag->ItemDropChance;
|
||||
$nbt->ItemRotation = $this->namedtag->ItemRotation;
|
||||
$nbt->setTag($this->namedtag->getTag(self::TAG_ITEM_DROP_CHANCE));
|
||||
$nbt->setTag($this->namedtag->getTag(self::TAG_ITEM_ROTATION));
|
||||
|
||||
if($this->hasItem()){
|
||||
$nbt->Item = $this->namedtag->Item;
|
||||
$nbt->setTag($this->namedtag->getTag(self::TAG_ITEM));
|
||||
}
|
||||
}
|
||||
|
||||
protected static function createAdditionalNBT(CompoundTag $nbt, Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : void{
|
||||
$nbt->ItemDropChance = new FloatTag("ItemDropChance", 1.0);
|
||||
$nbt->ItemRotation = new ByteTag("ItemRotation", 0);
|
||||
$nbt->setFloat(self::TAG_ITEM_DROP_CHANCE, 1.0);
|
||||
$nbt->setByte(self::TAG_ITEM_ROTATION, 0);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user