mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Use -1 for anydamage and empty string for null NBT, closes #146
This commit is contained in:
@ -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());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user