From 7ef7a9ea3abaccbd44602eec66eac4a89f0da5fd Mon Sep 17 00:00:00 2001 From: Kriv <83916269+krivey@users.noreply.github.com> Date: Mon, 23 Sep 2024 00:44:06 +0700 Subject: [PATCH] Item unbreakable changes --- src/main/java/cn/nukkit/item/Item.java | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/cn/nukkit/item/Item.java b/src/main/java/cn/nukkit/item/Item.java index 4cff55d8563..d4968a333ba 100644 --- a/src/main/java/cn/nukkit/item/Item.java +++ b/src/main/java/cn/nukkit/item/Item.java @@ -12,6 +12,7 @@ import cn.nukkit.math.BlockFace; import cn.nukkit.math.Vector3; import cn.nukkit.nbt.NBTIO; +import cn.nukkit.nbt.tag.ByteTag; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.nbt.tag.IntTag; import cn.nukkit.nbt.tag.ListTag; @@ -1008,7 +1009,28 @@ public int getToughness() { } public boolean isUnbreakable() { - return false; + if (!(this instanceof ItemDurable)) { + return false; + } + + Tag tag = this.getNamedTagEntry("Unbreakable"); + return tag instanceof ByteTag && ((ByteTag) tag).data > 0; + } + + public Item setUnbreakable(boolean value) { + if (!(this instanceof ItemDurable)) { + return this; + } + + CompoundTag tag = this.getNamedTag(); + if (tag == null) tag = new CompoundTag(); + + this.setNamedTag(tag.putByte("Unbreakable", value ? 1 : 0)); + return this; + } + + public Item setUnbreakable() { + return this.setUnbreakable(true); } public boolean onUse(Player player, int ticksUsed) {