Improve documentation and add more proper checks to stack size and max damage item values

This commit is contained in:
Eclipse 2024-08-02 13:10:57 +00:00
parent 7d49af1653
commit 30df3349fd
No known key found for this signature in database
GPG key ID: 95E6998F82EC938A
2 changed files with 14 additions and 10 deletions

View file

@ -118,9 +118,9 @@ public interface CustomItemData {
/** /**
* Gets the stack size of the item. * Gets the stack size of the item.
* *
* 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. * <p>Returns 0 if not set. When not set (or 0), Geyser defaults to the stack count of the Java item when based on a vanilla item, or 64 when registering a non-vanilla item.</p>
* *
* 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. * <p>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.</p>
* *
* @return the stack size of the item * @return the stack size of the item
*/ */
@ -130,9 +130,9 @@ public interface CustomItemData {
/** /**
* Gets the max damage of the item. * Gets the max damage of the item.
* *
* 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. * <p>Returns -1 if not set. When not set (or below 0), Geyser defaults to the maximum damage of the Java item when based on a vanilla item, or uses 0 when registering a non-vanilla item.</p>
* *
* 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. * <p>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.</p>
* *
* @return the max damage of the item * @return the max damage of the item
*/ */
@ -142,7 +142,7 @@ public interface CustomItemData {
* Gets the attack damage of the item. * Gets the attack damage of the item.
* This is purely visual, and only applied to tools * This is purely visual, and only applied to tools
* *
* Returns 0 if not set. When 0, takes the Java item attack damage when based of a vanilla item, or uses 0 when porting a modded item. * <p>Returns 0 if not set. When 0, Geyser takes the Java item attack damage when based on a vanilla item, or uses 0 when porting a modded item.</p>
* *
* @return the attack damage of the item * @return the attack damage of the item
*/ */
@ -151,8 +151,8 @@ public interface CustomItemData {
/** /**
* Gets the armor type of the item. * Gets the armor type of the item.
* *
* This can be "boots", "leggings", "chestplate", or "helmet", and makes the item able to be equipped into its respective equipment slot. * <p>This can be "boots", "leggings", "chestplate", or "helmet", and makes the item able to be equipped into its respective equipment slot.
* This should only be set if the Java item can be placed into the specified equipment slot. * This should only be set if the Java item can be placed into the specified equipment slot.</p>
* *
* @return the armor type of the item * @return the armor type of the item
*/ */
@ -161,7 +161,7 @@ public interface CustomItemData {
/** /**
* Gets the armor protection value of the item. * Gets the armor protection value of the item.
* *
* Only has a function when {@link CustomItemData#armorType} is set. * <p>Only has a function when {@link CustomItemData#armorType} is set.</p>
* *
* @return the armor protection value of the item * @return the armor protection value of the item
*/ */

View file

@ -275,7 +275,9 @@ public class GeyserCustomItemData implements CustomItemData {
@Override @Override
public Builder stackSize(int stackSize) { public Builder stackSize(int stackSize) {
if (stackSize > 1) { if (stackSize < 1) {
throw new IllegalArgumentException("Stack size cannot be below 1");
} else if (stackSize > 1) {
if (this.maxDamage > 0) { if (this.maxDamage > 0) {
throw new IllegalStateException("Stack size cannot be above 1 when max damage is above 0"); throw new IllegalStateException("Stack size cannot be above 1 when max damage is above 0");
} }
@ -289,7 +291,9 @@ public class GeyserCustomItemData implements CustomItemData {
@Override @Override
public Builder maxDamage(int maxDamage) { public Builder maxDamage(int maxDamage) {
if (maxDamage > 0) { if (maxDamage < 0) {
throw new IllegalArgumentException("Max damage cannot be below 0");
} else if (maxDamage > 0) {
if (this.stackSize > 1) { if (this.stackSize > 1) {
throw new IllegalStateException("Max damage cannot be above 0 when stack size is above 1"); throw new IllegalStateException("Max damage cannot be above 0 when stack size is above 1");
} }