3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

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

Dieser Commit ist enthalten in:
rtm516 2023-05-21 13:22:15 +01:00 committet von GitHub
Ursprung 551f159fc5
Commit 178fb2136f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 77 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -136,6 +136,27 @@ public interface NonVanillaCustomItemData extends CustomItemData {
*/ */
boolean isFoil(); 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. * @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. * 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 foil(boolean isFoil);
Builder edible(boolean isEdible);
Builder canAlwaysEat(boolean canAlwaysEat);
Builder chargeable(boolean isChargeable);
/** /**
* @deprecated Use {@link #displayHandheld(boolean)} instead. * @deprecated Use {@link #displayHandheld(boolean)} instead.
*/ */

Datei anzeigen

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

Datei anzeigen

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