Skip to content

Commit

Permalink
Item unbreakable changes (#2200)
Browse files Browse the repository at this point in the history
  • Loading branch information
krivey authored Sep 23, 2024
1 parent e7906b4 commit fb217e1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/main/java/cn/nukkit/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fb217e1

Please sign in to comment.