mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-17 04:06:54 +00:00
Added keep on death methods for items (#5395)
This commit is contained in:
@@ -65,6 +65,8 @@ class Item implements \JsonSerializable{
|
||||
public const TAG_DISPLAY_NAME = "Name";
|
||||
public const TAG_DISPLAY_LORE = "Lore";
|
||||
|
||||
public const TAG_KEEP_ON_DEATH = "minecraft:keep_on_death";
|
||||
|
||||
private ItemIdentifier $identifier;
|
||||
private CompoundTag $nbt;
|
||||
|
||||
@@ -96,6 +98,8 @@ class Item implements \JsonSerializable{
|
||||
*/
|
||||
protected $canDestroy;
|
||||
|
||||
protected bool $keepOnDeath = false;
|
||||
|
||||
/**
|
||||
* Constructs a new Item type. This constructor should ONLY be used when constructing a new item TYPE to register
|
||||
* into the index.
|
||||
@@ -222,6 +226,17 @@ class Item implements \JsonSerializable{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether players will retain this item on death. If a non-player dies it will be excluded from the drops.
|
||||
*/
|
||||
public function keepOnDeath() : bool{
|
||||
return $this->keepOnDeath;
|
||||
}
|
||||
|
||||
public function setKeepOnDeath(bool $keepOnDeath) : void{
|
||||
$this->keepOnDeath = $keepOnDeath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this Item has a non-empty NBT.
|
||||
*/
|
||||
@@ -320,6 +335,8 @@ class Item implements \JsonSerializable{
|
||||
$this->canDestroy[$entry->getValue()] = $entry->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
$this->keepOnDeath = $tag->getByte(self::TAG_KEEP_ON_DEATH, 0) !== 0;
|
||||
}
|
||||
|
||||
protected function serializeCompoundTag(CompoundTag $tag) : void{
|
||||
@@ -377,6 +394,12 @@ class Item implements \JsonSerializable{
|
||||
}else{
|
||||
$tag->removeTag("CanDestroy");
|
||||
}
|
||||
|
||||
if($this->keepOnDeath){
|
||||
$tag->setByte(self::TAG_KEEP_ON_DEATH, 1);
|
||||
}else{
|
||||
$tag->removeTag(self::TAG_KEEP_ON_DEATH);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCount() : int{
|
||||
|
Reference in New Issue
Block a user