Added keep on death methods for items (#5395)

This commit is contained in:
Javier León
2022-12-15 17:10:20 -03:00
committed by GitHub
parent 95d0a3bf41
commit c5d716dc9d
3 changed files with 29 additions and 4 deletions

View File

@@ -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{