Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move various settings from NonVanillaCustomItemData to CustomItemData and allow use in JSON mappings #4655

Open
wants to merge 26 commits into
base: api/2.4.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e6c9c51
Move some functionality from non vanilla custom items to vanilla cust…
eclipseisoffline May 10, 2024
9cd847e
Update implementations
eclipseisoffline May 10, 2024
97e1beb
Implement logic for new vanilla custom item components in custom item…
eclipseisoffline May 10, 2024
965d11c
Move armor type to super class and implement protection value and arm…
eclipseisoffline May 10, 2024
72da5a5
Move translation string back to non vanilla and move hat to vanilla
eclipseisoffline May 11, 2024
86518d5
Merge remote-tracking branch 'upstream/master' into customitemapi
eclipseisoffline May 11, 2024
22f5ad1
Add overrides for backwards compatibility (testing needed) and reorde…
eclipseisoffline May 11, 2024
0a7a06a
Add new vanilla custom item properties to JSON reader, needs testing
eclipseisoffline May 11, 2024
d31e94a
Fix edible animation
eclipseisoffline May 11, 2024
e8266ff
Move tool property back to non vanilla custom item
eclipseisoffline May 11, 2024
17c3b78
Merge branch 'master' into customitemapi
eclipseisoffline May 17, 2024
ac4d543
Merge remote-tracking branch 'refs/remotes/upstream/master' into cust…
eclipseisoffline Jun 18, 2024
6819d2b
Update to recent Geyser
eclipseisoffline Jun 18, 2024
52b9921
Merge remote-tracking branch 'origin/customitemapi' into customitemapi
eclipseisoffline Jun 18, 2024
e5f037e
Move tool type and tool tier back to non vanilla items
eclipseisoffline Jul 21, 2024
9bdf05a
Adjust documentation
eclipseisoffline Jul 21, 2024
aa59f40
Whoops
eclipseisoffline Jul 21, 2024
e55eaa7
Simplify documentation of armor type property
eclipseisoffline Jul 21, 2024
7881c46
Merge remote-tracking branch 'refs/remotes/upstream/master' into cust…
eclipseisoffline Jul 23, 2024
7d49af1
Implement stack size and max damage restrictions
eclipseisoffline Aug 1, 2024
30df334
Improve documentation and add more proper checks to stack size and ma…
eclipseisoffline Aug 2, 2024
7394cf5
Improve documentation slightly again
eclipseisoffline Aug 2, 2024
7ebbf53
Improve exception messages for stackSize and maxDamage builder method…
eclipseisoffline Aug 11, 2024
c890f06
Add more annotations and proper validating of attack damage and prote…
eclipseisoffline Aug 13, 2024
db92184
Add validation for armor type
eclipseisoffline Aug 13, 2024
5b864ab
Return -1 if not set for attack damage and protection value and imple…
eclipseisoffline Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package org.geysermc.geyser.api.item.custom;

import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.index.qual.Positive;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
Expand Down Expand Up @@ -114,6 +116,88 @@ public interface CustomItemData {
*/
@NonNull Set<String> tags();

/**
* Gets the stack size of the item.
*
* <p>Returns 0 if not set. When not set, 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>
*
* <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
*/
@NonNegative int stackSize();

/**
* Gets the max damage of the item.
*
* <p>Returns -1 if not set. When not set, 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>
*
* <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
*/
int maxDamage();

/**
* Gets the attack damage of the item.
* This is purely visual, and only applied to tools
*
* <p>Returns -1 if not set. When not set, 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
*/
int attackDamage();

/**
* Gets the armor type of the item.
*
* <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.</p>
*
* @return the armor type of the item
*/
@Nullable String armorType();

/**
* Gets the armor protection value of the item.
*
* <p>Only has a function when {@link CustomItemData#armorType} is set, or when the Java item is an armor item (when based on a vanilla item).</p>
*
* <p>Returns -1 if not set. When not set, Geyser takes the Java item protection value when based on a vanilla item, or uses 0 when porting a modded item.</p>
*
* @return the armor protection value of the item
*/
int protectionValue();

/**
* Gets if the item is a hat. This is used to determine if the item should be rendered on the player's head, and
* normally allow the player to equip it. This is not meant for armor.
*
* @return if the item is a hat
*/
boolean isHat();
onebeastchris marked this conversation as resolved.
Show resolved Hide resolved

/**
* Gets if the item is a foil. This is used to determine if the item should be rendered with an enchantment glint effect.
*
* @return if the item is a foil
*/
boolean isFoil();

/**
* Gets if the item is edible.
*
* @return if the item is edible
*/
boolean isEdible();

/**
* Gets if the food item can always be eaten.
*
* @return if the item is allowed to be eaten all the time
*/
boolean canAlwaysEat();

static CustomItemData.Builder builder() {
return GeyserApi.api().provider(CustomItemData.Builder.class);
}
Expand Down Expand Up @@ -144,6 +228,24 @@ interface Builder {

Builder tags(@Nullable Set<String> tags);

Builder stackSize(@Positive int stackSize);

Builder maxDamage(@NonNegative int maxDamage);

Builder attackDamage(@NonNegative int attackDamage);

Builder armorType(@Nullable String armorType);

Builder protectionValue(@NonNegative int protectionValue);

Builder hat(boolean isHat);

Builder foil(boolean isFoil);

Builder edible(boolean isEdible);

Builder canAlwaysEat(boolean canAlwaysEat);

CustomItemData build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package org.geysermc.geyser.api.item.custom;

import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.index.qual.Positive;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
Expand All @@ -43,35 +44,6 @@ public interface NonVanillaCustomItemData extends CustomItemData {
*/
@NonNull String identifier();

/**
* Gets the java item id of the item.
*
* @return the java item id of the item
*/
@NonNegative int javaId();

/**
* Gets the stack size of the item.
*
* @return the stack size of the item
*/
@NonNegative int stackSize();

/**
* Gets the max damage of the item.
*
* @return the max damage of the item
*/
int maxDamage();

/**
* Gets the attack damage of the item.
* This is purely visual, and only applied to tools
*
* @return the attack damage of the item
*/
int attackDamage();

/**
* Gets the tool type of the item.
*
Expand All @@ -87,18 +59,11 @@ public interface NonVanillaCustomItemData extends CustomItemData {
@Nullable String toolTier();

/**
* Gets the armor type of the item.
*
* @return the armor type of the item
*/
@Nullable String armorType();

/**
* Gets the armor protection value of the item.
* Gets the java item id of the item.
*
* @return the armor protection value of the item
* @return the java item id of the item
*/
int protectionValue();
@NonNegative int javaId();

/**
* Gets the item's translation string.
Expand All @@ -115,40 +80,18 @@ public interface NonVanillaCustomItemData extends CustomItemData {
@Nullable Set<String> repairMaterials();

/**
* Gets if the item is a hat. This is used to determine if the item should be rendered on the player's head, and
* normally allow the player to equip it. This is not meant for armor.
*
* @return if the item is a hat
*/
boolean isHat();

/**
* Gets if the item is a foil. This is used to determine if the item should be rendered with an enchantment glint effect.
*
* @return if the item is a foil
*/
boolean isFoil();

/**
* Gets if the item is edible.
*
* @return if the item is edible
*/
boolean isEdible();

/**
* Gets if the food item can always be eaten.
* Gets if the item is chargable, like a bow.
*
* @return if the item is allowed to be eaten all the time
* @return if the item should act like a chargable item
*/
boolean canAlwaysEat();
boolean isChargeable();

/**
* Gets if the item is chargable, like a bow.
* Gets the block the item places.
*
* @return if the item should act like a chargable item
* @return the block the item places
*/
boolean isChargeable();
String block();

/**
* @deprecated Use {@link #displayHandheld()} instead.
Expand All @@ -161,13 +104,6 @@ default boolean isTool() {
return displayHandheld();
}

/**
* Gets the block the item places.
*
* @return the block the item places
*/
String block();

static NonVanillaCustomItemData.Builder builder() {
return GeyserApi.api().provider(NonVanillaCustomItemData.Builder.class);
}
Expand All @@ -176,40 +112,63 @@ interface Builder extends CustomItemData.Builder {
@Override
Builder name(@NonNull String name);

Builder identifier(@NonNull String identifier);
@Override
Builder customItemOptions(@NonNull CustomItemOptions customItemOptions);

Builder javaId(@NonNegative int javaId);
@Override
Builder displayName(@NonNull String displayName);

Builder stackSize(@NonNegative int stackSize);
@Override
Builder icon(@NonNull String icon);

Builder maxDamage(int maxDamage);
@Override
Builder allowOffhand(boolean allowOffhand);

Builder attackDamage(int attackDamage);
@Override
Builder displayHandheld(boolean displayHandheld);

Builder toolType(@Nullable String toolType);
@Override
Builder creativeCategory(int creativeCategory);

Builder toolTier(@Nullable String toolTier);
@Override
Builder creativeGroup(@Nullable String creativeGroup);

Builder armorType(@Nullable String armorType);
@Override
Builder textureSize(int textureSize);

Builder protectionValue(int protectionValue);
@Override
Builder renderOffsets(@Nullable CustomRenderOffsets renderOffsets);

Builder translationString(@Nullable String translationString);
@Override
Builder tags(@Nullable Set<String> tags);

Builder repairMaterials(@Nullable Set<String> repairMaterials);
@Override
Builder stackSize(@Positive int stackSize);

@Override
Builder maxDamage(@NonNegative int maxDamage);

@Override
Builder attackDamage(@NonNegative int attackDamage);

@Override
Builder armorType(@Nullable String armorType);

@Override
Builder protectionValue(@NonNegative int protectionValue);

@Override
Builder hat(boolean isHat);

@Override
Builder foil(boolean isFoil);

@Override
Builder edible(boolean isEdible);

@Override
Builder canAlwaysEat(boolean canAlwaysEat);

Builder chargeable(boolean isChargeable);

Builder block(String block);

/**
* @deprecated Use {@link #displayHandheld(boolean)} instead.
*/
Expand All @@ -218,35 +177,21 @@ default Builder tool(boolean isTool) {
return displayHandheld(isTool);
}

@Override
Builder creativeCategory(int creativeCategory);

@Override
Builder creativeGroup(@Nullable String creativeGroup);

@Override
Builder customItemOptions(@NonNull CustomItemOptions customItemOptions);
Builder identifier(@NonNull String identifier);

@Override
Builder displayName(@NonNull String displayName);
Builder javaId(@NonNegative int javaId);

@Override
Builder icon(@NonNull String icon);
Builder toolType(@Nullable String toolType);

@Override
Builder allowOffhand(boolean allowOffhand);
Builder toolTier(@Nullable String toolTier);

@Override
Builder displayHandheld(boolean displayHandheld);
Builder translationString(@Nullable String translationString);

@Override
Builder textureSize(int textureSize);
Builder repairMaterials(@Nullable Set<String> repairMaterials);

@Override
Builder renderOffsets(@Nullable CustomRenderOffsets renderOffsets);
Builder chargeable(boolean isChargeable);

@Override
Builder tags(@Nullable Set<String> tags);
Builder block(String block);

NonVanillaCustomItemData build();
}
Expand Down
Loading