Use -1 for anydamage and empty string for null NBT, closes #146

This commit is contained in:
Dylan K. Taylor
2016-12-21 14:45:34 +00:00
parent 300a3d5ccd
commit 5443b10257
7 changed files with 40 additions and 36 deletions

View File

@ -339,7 +339,7 @@ class Item implements ItemIds, \JsonSerializable{
public function __construct(int $id, $meta = 0, int $count = 1, string $name = "Unknown"){
$this->id = $id & 0xffff;
$this->meta = $meta !== null ? $meta & 0xffff : null;
$this->meta = $meta !== -1 ? $meta & 0xffff : -1;
$this->count = $count;
$this->name = $name;
if(!isset($this->block) and $this->id <= 0xff and isset(Block::$list[$this->id])){
@ -352,7 +352,7 @@ class Item implements ItemIds, \JsonSerializable{
if($tags instanceof CompoundTag){
$this->setNamedTag($tags);
}else{
$this->tags = $tags;
$this->tags = (string) $tags;
$this->cachedNBT = null;
}
@ -362,12 +362,12 @@ class Item implements ItemIds, \JsonSerializable{
/**
* @return string
*/
public function getCompoundTag(){
public function getCompoundTag() : string{
return $this->tags;
}
public function hasCompoundTag() : bool{
return $this->tags !== "" and $this->tags !== null;
return $this->tags !== "";
}
public function hasCustomBlockData() : bool{
@ -672,12 +672,16 @@ class Item implements ItemIds, \JsonSerializable{
return $this->id;
}
final public function getDamage(){
final public function getDamage() : int{
return $this->meta;
}
public function setDamage($meta){
$this->meta = $meta !== null ? $meta & 0xFFFF : null;
public function setDamage(int $meta){
$this->meta = $meta !== -1 ? $meta & 0xFFFF : -1;
}
public function hasAnyDamageValue() : bool{
return $this->meta === -1;
}
public function getMaxStackSize(){
@ -757,7 +761,7 @@ class Item implements ItemIds, \JsonSerializable{
public final function deepEquals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{
if($this->equals($item, $checkDamage, $checkCompound)){
return true;
}elseif($item->hasCompoundTag() or $this->hasCompoundTag()){
}elseif($item->hasCompoundTag() and $this->hasCompoundTag()){
return NBT::matchTree($this->getNamedTag(), $item->getNamedTag());
}