Allow custom bows and food to be registered using the API (#3782)

This commit is contained in:
rtm516 2023-05-21 13:22:15 +01:00 committed by GitHub
parent 551f159fc5
commit 178fb2136f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 0 deletions

View file

@ -136,6 +136,27 @@ public interface NonVanillaCustomItemData extends CustomItemData {
*/
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();
/**
* Gets if the item is chargable, like a bow.
*
* @return if the item should act like a chargable item
*/
boolean isChargeable();
/**
* @deprecated Use {@link #displayHandheld()} instead.
* Gets if the item is a tool. This is used to set the render type of the item, if the item is handheld.
@ -183,6 +204,12 @@ public interface NonVanillaCustomItemData extends CustomItemData {
Builder foil(boolean isFoil);
Builder edible(boolean isEdible);
Builder canAlwaysEat(boolean canAlwaysEat);
Builder chargeable(boolean isChargeable);
/**
* @deprecated Use {@link #displayHandheld(boolean)} instead.
*/

View file

@ -55,6 +55,9 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
private final boolean isHat;
private final boolean isFoil;
private final boolean isTool;
private final boolean isEdible;
private final boolean canAlwaysEat;
private final boolean isChargeable;
public GeyserNonVanillaCustomItemData(NonVanillaCustomItemDataBuilder builder) {
super(builder.name, builder.customItemOptions, builder.displayName, builder.icon, builder.allowOffhand,
@ -75,6 +78,9 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
this.isHat = builder.hat;
this.isFoil = builder.foil;
this.isTool = builder.tool;
this.isEdible = builder.edible;
this.canAlwaysEat = builder.canAlwaysEat;
this.isChargeable = builder.chargeable;
}
@Override
@ -147,6 +153,21 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
return isFoil;
}
@Override
public boolean isEdible() {
return isEdible;
}
@Override
public boolean canAlwaysEat() {
return canAlwaysEat;
}
@Override
public boolean isChargeable() {
return isChargeable;
}
public static class NonVanillaCustomItemDataBuilder extends GeyserCustomItemData.CustomItemDataBuilder implements NonVanillaCustomItemData.Builder {
private String identifier = null;
private int javaId = -1;
@ -171,6 +192,9 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
private boolean hat = false;
private boolean foil = false;
private boolean tool = false;
private boolean edible = false;
private boolean canAlwaysEat = false;
private boolean chargeable = false;
@Override
public NonVanillaCustomItemData.Builder name(@NonNull String name) {
@ -297,6 +321,24 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
return this;
}
@Override
public NonVanillaCustomItemData.Builder edible(boolean isEdible) {
this.edible = isEdible;
return this;
}
@Override
public NonVanillaCustomItemData.Builder canAlwaysEat(boolean canAlwaysEat) {
this.canAlwaysEat = canAlwaysEat;
return this;
}
@Override
public NonVanillaCustomItemData.Builder chargeable(boolean isChargeable) {
this.chargeable = isChargeable;
return this;
}
@Override
public NonVanillaCustomItemData build() {
if (identifier == null || javaId == -1) {

View file

@ -238,6 +238,14 @@ public class CustomItemRegistryPopulator {
computeArmorProperties(armorType, customItemData.protectionValue(), componentBuilder);
}
if (customItemData.isEdible()) {
computeConsumableProperties(itemProperties, componentBuilder, 1, customItemData.canAlwaysEat());
}
if (customItemData.isChargeable()) {
computeChargeableProperties(itemProperties, componentBuilder);
}
computeRenderOffsets(isHat, customItemData, componentBuilder);
if (creativeGroup != null) {