Skip to content

Commit fb217e1

Browse files
authored
Item unbreakable changes (#2200)
1 parent e7906b4 commit fb217e1

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/main/java/cn/nukkit/item/Item.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import cn.nukkit.math.BlockFace;
1313
import cn.nukkit.math.Vector3;
1414
import cn.nukkit.nbt.NBTIO;
15+
import cn.nukkit.nbt.tag.ByteTag;
1516
import cn.nukkit.nbt.tag.CompoundTag;
1617
import cn.nukkit.nbt.tag.IntTag;
1718
import cn.nukkit.nbt.tag.ListTag;
@@ -1008,7 +1009,28 @@ public int getToughness() {
10081009
}
10091010

10101011
public boolean isUnbreakable() {
1011-
return false;
1012+
if (!(this instanceof ItemDurable)) {
1013+
return false;
1014+
}
1015+
1016+
Tag tag = this.getNamedTagEntry("Unbreakable");
1017+
return tag instanceof ByteTag && ((ByteTag) tag).data > 0;
1018+
}
1019+
1020+
public Item setUnbreakable(boolean value) {
1021+
if (!(this instanceof ItemDurable)) {
1022+
return this;
1023+
}
1024+
1025+
CompoundTag tag = this.getNamedTag();
1026+
if (tag == null) tag = new CompoundTag();
1027+
1028+
this.setNamedTag(tag.putByte("Unbreakable", value ? 1 : 0));
1029+
return this;
1030+
}
1031+
1032+
public Item setUnbreakable() {
1033+
return this.setUnbreakable(true);
10121034
}
10131035

10141036
public boolean onUse(Player player, int ticksUsed) {

0 commit comments

Comments
 (0)