Skip to content

Commit

Permalink
Support MAX_STACK_SIZE for ItemStack
Browse files Browse the repository at this point in the history
Also fix incorrect supports condition for MAX_DURABILITY
  • Loading branch information
avaruus1 committed Jul 21, 2024
1 parent f25cc69 commit 655a4de
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,26 @@ public static void register(final DataProviderRegistrator registrator) {
.delete(h -> h.remove(DataComponents.LORE))
.create(Keys.MAX_DURABILITY)
.get(h -> h.getMaxDamage() != 0 ? h.getMaxDamage() : null)
.set((h, v) -> h.set(DataComponents.MAX_DAMAGE, v))
.supports(h -> h.getMaxDamage() != 0)
.setAnd((h, v) -> {
if (v <= 0) {
return false;
}

h.set(DataComponents.MAX_DAMAGE, v);
return true;
})
.supports(h -> h.getOrDefault(DataComponents.MAX_STACK_SIZE, 1) == 1)
.create(Keys.MAX_STACK_SIZE)
.get(ItemStack::getMaxStackSize)
.setAnd((h, v) -> {
if (v <= 0 || v > 99) {
return false;
}

h.set(DataComponents.MAX_STACK_SIZE, v);
return true;
})
.supports(h -> !h.has(DataComponents.MAX_DAMAGE))
.create(Keys.ITEM_DURABILITY)
.get(stack -> stack.getMaxDamage() - stack.getDamageValue())
.set((stack, durability) -> stack.setDamageValue(stack.getMaxDamage() - durability))
Expand Down

0 comments on commit 655a4de

Please sign in to comment.