mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Make use of CompoundTag->hasTag()
This commit is contained in:
parent
292e462ea0
commit
28a840d161
@ -35,7 +35,7 @@ class Bed extends Spawnable{
|
||||
const TAG_COLOR = "color";
|
||||
|
||||
public function __construct(Level $level, CompoundTag $nbt){
|
||||
if(!($nbt->getTag(self::TAG_COLOR) instanceof ByteTag)){
|
||||
if(!$nbt->hasTag(self::TAG_COLOR, ByteTag::class)){
|
||||
$nbt->setTag(new ByteTag(self::TAG_COLOR, 14)); //default to old red
|
||||
}
|
||||
parent::__construct($level, $nbt);
|
||||
|
@ -51,7 +51,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
|
||||
parent::__construct($level, $nbt);
|
||||
$this->inventory = new ChestInventory($this);
|
||||
|
||||
if(!($this->namedtag->getTag("Items") instanceof ListTag)){
|
||||
if(!$this->namedtag->hasTag("Items", ListTag::class)){
|
||||
$this->namedtag->setTag(new ListTag("Items", [], NBT::TAG_Compound));
|
||||
}
|
||||
|
||||
|
@ -37,10 +37,10 @@ class FlowerPot extends Spawnable{
|
||||
const TAG_ITEM_DATA = "mData";
|
||||
|
||||
public function __construct(Level $level, CompoundTag $nbt){
|
||||
if(!($nbt->getTag(self::TAG_ITEM) instanceof ShortTag)){
|
||||
if(!$nbt->hasTag(self::TAG_ITEM, ShortTag::class)){
|
||||
$nbt->setTag(new ShortTag(self::TAG_ITEM, 0));
|
||||
}
|
||||
if(!($nbt->getTag(self::TAG_ITEM_DATA) instanceof IntTag)){
|
||||
if(!$nbt->hasTag(self::TAG_ITEM_DATA, IntTag::class)){
|
||||
$nbt->setTag(new IntTag(self::TAG_ITEM_DATA, 0));
|
||||
}
|
||||
parent::__construct($level, $nbt);
|
||||
|
@ -53,24 +53,24 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
||||
protected $inventory;
|
||||
|
||||
public function __construct(Level $level, CompoundTag $nbt){
|
||||
if(!($nbt->getTag(self::TAG_BURN_TIME) instanceof ShortTag) or $nbt->getShort(self::TAG_BURN_TIME) < 0){
|
||||
if(!$nbt->hasTag(self::TAG_BURN_TIME, ShortTag::class) or $nbt->getShort(self::TAG_BURN_TIME) < 0){
|
||||
$nbt->setTag(new ShortTag(self::TAG_BURN_TIME, 0));
|
||||
}
|
||||
|
||||
if(!
|
||||
($nbt->getTag(self::TAG_COOK_TIME) instanceof ShortTag) or
|
||||
if(
|
||||
!$nbt->hasTag(self::TAG_COOK_TIME, ShortTag::class) or
|
||||
$nbt->getShort(self::TAG_COOK_TIME) < 0 or
|
||||
($nbt->getShort(self::TAG_BURN_TIME) === 0 and $nbt->getShort(self::TAG_COOK_TIME) > 0)
|
||||
){
|
||||
$nbt->setTag(new ShortTag(self::TAG_COOK_TIME, 0));
|
||||
}
|
||||
|
||||
if(!($nbt->getTag(self::TAG_MAX_TIME) instanceof ShortTag)){
|
||||
if(!$nbt->hasTag(self::TAG_MAX_TIME, ShortTag::class)){
|
||||
$nbt->setTag(new ShortTag(self::TAG_MAX_TIME, $nbt->getShort(self::TAG_BURN_TIME)));
|
||||
$nbt->removeTag(self::TAG_BURN_TICKS);
|
||||
}
|
||||
|
||||
if(!($nbt->getTag(self::TAG_BURN_TICKS) instanceof ShortTag)){
|
||||
if(!$nbt->getTag(self::TAG_BURN_TICKS, ShortTag::class)){
|
||||
$nbt->setTag(new ShortTag(self::TAG_BURN_TICKS, 0));
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,11 @@ class ItemFrame extends Spawnable{
|
||||
const TAG_ITEM = "Item";
|
||||
|
||||
public function __construct(Level $level, CompoundTag $nbt){
|
||||
if(!($nbt->getTag(self::TAG_ITEM_ROTATION) instanceof ByteTag)){
|
||||
if(!$nbt->hasTag(self::TAG_ITEM_ROTATION, ByteTag::class)){
|
||||
$nbt->setTag(new ByteTag(self::TAG_ITEM_ROTATION, 0));
|
||||
}
|
||||
|
||||
if(!($nbt->getTag(self::TAG_ITEM_DROP_CHANCE) instanceof FloatTag)){
|
||||
if(!$nbt->hasTag(self::TAG_ITEM_DROP_CHANCE, FloatTag::class)){
|
||||
$nbt->setTag(new FloatTag(self::TAG_ITEM_DROP_CHANCE, 1.0));
|
||||
}
|
||||
|
||||
|
@ -41,14 +41,14 @@ class Sign extends Spawnable{
|
||||
protected $text = ["", "", "", ""];
|
||||
|
||||
public function __construct(Level $level, CompoundTag $nbt){
|
||||
if($nbt->getTag(self::TAG_TEXT_BLOB) instanceof StringTag){ //MCPE 1.2 save format
|
||||
if($nbt->hasTag(self::TAG_TEXT_BLOB, StringTag::class)){ //MCPE 1.2 save format
|
||||
$this->text = explode("\n", $nbt->getString(self::TAG_TEXT_BLOB));
|
||||
assert(count($this->text) === 4, "Too many lines!");
|
||||
$nbt->removeTag(self::TAG_TEXT_BLOB);
|
||||
}else{
|
||||
for($i = 1; $i <= 4; ++$i){
|
||||
$textKey = sprintf(self::TAG_TEXT_LINE, $i);
|
||||
if($nbt->getTag($textKey) instanceof StringTag){
|
||||
if($nbt->hasTag($textKey, StringTag::class)){
|
||||
$this->text[$i - 1] = $nbt->getString($textKey);
|
||||
$nbt->removeTag($textKey);
|
||||
}
|
||||
@ -140,8 +140,8 @@ class Sign extends Spawnable{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(($blob = $nbt->getString(self::TAG_TEXT_BLOB)) !== null){
|
||||
$lines = array_pad(explode("\n", $blob), 4, "");
|
||||
if($nbt->hasTag(self::TAG_TEXT_BLOB, StringTag::class)){
|
||||
$lines = array_pad(explode("\n", $nbt->getString(self::TAG_TEXT_BLOB)), 4, "");
|
||||
}else{
|
||||
$lines = [
|
||||
$nbt->getString(sprintf(self::TAG_TEXT_LINE, 1)),
|
||||
|
@ -42,10 +42,10 @@ class Skull extends Spawnable{
|
||||
const TAG_ROT = "Rot";
|
||||
|
||||
public function __construct(Level $level, CompoundTag $nbt){
|
||||
if(!($nbt->getTag(self::TAG_SKULL_TYPE) instanceof ByteTag)){
|
||||
if(!$nbt->hasTag(self::TAG_SKULL_TYPE, ByteTag::class)){
|
||||
$nbt->setTag(new ByteTag(self::TAG_SKULL_TYPE, 0));
|
||||
}
|
||||
if(!($nbt->getTag(self::TAG_ROT) instanceof ByteTag)){
|
||||
if(!$nbt->hasTag(self::TAG_ROT, ByteTag::class)){
|
||||
$nbt->setTag(new ByteTag(self::TAG_ROT, 0));
|
||||
}
|
||||
parent::__construct($level, $nbt);
|
||||
|
Loading…
x
Reference in New Issue
Block a user