diff --git a/api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java b/api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java index 179ad1d34..a7f386b38 100644 --- a/api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java +++ b/api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java @@ -120,6 +120,8 @@ public interface CustomItemData { * * Returns 0 if not set. When not set (or 0), it defaults to the stack count of the Java item when based of a vanilla item, or 64 when registering a non-vanilla item. * + * Note that, to copy Java behaviour, setting the stack size of an item to a value above 1 will set the max damage to 0. If a max damage value above 0 was explicitly set, an exception will be thrown. + * * @return the stack size of the item */ @NonNegative @@ -130,6 +132,8 @@ public interface CustomItemData { * * Returns -1 if not set. When not set (or below 0), it defaults to the maximum damage of the Java item when based of a vanilla item, or uses 0 when registering a non-vanilla item. * + * Note that, to copy Java behaviour, setting the max damage value of an item to a value above 0 will set the stack size to 1. If a stack size above 1 was explicitly set, an exception will be thrown. + * * @return the max damage of the item */ int maxDamage(); diff --git a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java index 406dc3234..2bba27408 100644 --- a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java +++ b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java @@ -275,12 +275,28 @@ public class GeyserCustomItemData implements CustomItemData { @Override public Builder stackSize(int stackSize) { + if (stackSize > 1) { + if (this.maxDamage > 0) { + throw new IllegalStateException("Stack size cannot be above 1 when max damage is above 0"); + } + // Explicitly set max damage to 0 instead of falling back to the Java vanilla item value + this.maxDamage = 0; + } + this.stackSize = stackSize; return this; } @Override public Builder maxDamage(int maxDamage) { + if (maxDamage > 0) { + if (this.stackSize > 1) { + throw new IllegalStateException("Max damage cannot be above 0 when stack size is above 1"); + } + // Explicitly set stack size to 1 instead of falling back to the Java vanilla item value + this.stackSize = 1; + } + this.maxDamage = maxDamage; return this; } diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java index 509af0417..5560fdb6d 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java @@ -222,7 +222,7 @@ public class MappingsReader_v1 extends MappingsReader { } if (node.has("attack_damage")) { - customItemData.maxDamage(node.get("attack_damage").asInt()); + customItemData.attackDamage(node.get("attack_damage").asInt()); } if (node.has("armor_type")) {