From 965d11c7a122f341a6f0c4fe9b234136f0371248 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Fri, 10 May 2024 21:23:46 +0000 Subject: [PATCH] Move armor type to super class and implement protection value and armor type in vanilla custom registry --- .../geyser/api/item/custom/CustomItemData.java | 9 +++++++++ .../item/custom/NonVanillaCustomItemData.java | 9 --------- .../geyser/item/GeyserCustomItemData.java | 16 ++++++++++++++-- .../item/GeyserNonVanillaCustomItemData.java | 14 -------------- .../populator/CustomItemRegistryPopulator.java | 12 +++++++++++- 5 files changed, 34 insertions(+), 26 deletions(-) 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 26a5adc8d..5bb469abc 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 @@ -165,6 +165,13 @@ public interface CustomItemData { */ @Nullable String translationString(); + /** + * 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. * @@ -244,6 +251,8 @@ public interface CustomItemData { Builder toolTier(@Nullable String toolTier); + Builder armorType(@Nullable String armorType); + Builder protectionValue(int protectionValue); Builder translationString(@Nullable String translationString); diff --git a/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java b/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java index 19703d21e..9a1a699c6 100644 --- a/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java +++ b/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java @@ -50,13 +50,6 @@ public interface NonVanillaCustomItemData extends CustomItemData { */ @NonNegative int javaId(); - /** - * Gets the armor type of the item. - * - * @return the armor type of the item - */ - @Nullable String armorType(); - /** * Gets the repair materials of the item. * @@ -98,8 +91,6 @@ public interface NonVanillaCustomItemData extends CustomItemData { Builder javaId(@NonNegative int javaId); - Builder armorType(@Nullable String armorType); - Builder repairMaterials(@Nullable Set repairMaterials); Builder hat(boolean isHat); 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 dd95e3dc8..f1cf50884 100644 --- a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java +++ b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java @@ -37,7 +37,6 @@ import java.util.HashSet; import java.util.Objects; import java.util.OptionalInt; import java.util.Set; -import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData; @EqualsAndHashCode @ToString @@ -59,6 +58,7 @@ public class GeyserCustomItemData implements CustomItemData { private final String toolType; private final String toolTier; private final String translationString; + private final String armorType; private final int protectionValue; private final boolean isFoil; private final boolean isEdible; @@ -82,6 +82,7 @@ public class GeyserCustomItemData implements CustomItemData { this.toolType = builder.toolType; this.toolTier = builder.toolTier; this.translationString = builder.translationString; + this.armorType = builder.armorType; this.protectionValue = builder.protectionValue; this.isFoil = builder.foil; this.isEdible = builder.edible; @@ -168,6 +169,11 @@ public class GeyserCustomItemData implements CustomItemData { return toolTier; } + @Override + public @Nullable String armorType() { + return armorType; + } + @Override public int protectionValue() { return protectionValue; @@ -210,10 +216,10 @@ public class GeyserCustomItemData implements CustomItemData { private int attackDamage = 0; private String toolType = null; private String toolTier = null; + private String armorType = null; private int protectionValue = 0; private String translationString; private boolean foil = false; - private boolean tool = false; private boolean edible = false; private boolean canAlwaysEat = false; @@ -313,6 +319,12 @@ public class GeyserCustomItemData implements CustomItemData { return this; } + @Override + public Builder armorType(@Nullable String armorType) { + this.armorType = armorType; + return this; + } + @Override public Builder protectionValue(int protectionValue) { this.protectionValue = protectionValue; diff --git a/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java b/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java index 160c74c10..d727401b2 100644 --- a/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java +++ b/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java @@ -40,7 +40,6 @@ import java.util.Set; public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData implements NonVanillaCustomItemData { private final String identifier; private final int javaId; - private final String armorType; private final Set repairMaterials; private final boolean isHat; private final boolean isChargeable; @@ -51,7 +50,6 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i this.identifier = builder.identifier; this.javaId = builder.javaId; - this.armorType = builder.armorType; this.repairMaterials = builder.repairMaterials; this.isHat = builder.hat; this.isChargeable = builder.chargeable; @@ -68,11 +66,6 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i return javaId; } - @Override - public @Nullable String armorType() { - return armorType; - } - @Override public Set repairMaterials() { return repairMaterials; @@ -96,7 +89,6 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i public static class Builder extends GeyserCustomItemData.Builder implements NonVanillaCustomItemData.Builder { private String identifier = null; private int javaId = -1; - private String armorType = null; private Set repairMaterials; private boolean hat = false; private boolean chargeable = false; @@ -160,12 +152,6 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i return this; } - @Override - public Builder armorType(@Nullable String armorType) { - this.armorType = armorType; - return this; - } - @Override public Builder repairMaterials(@Nullable Set repairMaterials) { this.repairMaterials = repairMaterials; diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java index 75d7fc2c6..141965cbd 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java @@ -188,8 +188,18 @@ public class CustomItemRegistryPopulator { itemProperties.putBoolean("can_destroy_in_creative", canDestroyInCreative); + String armorType = null; + int protectionValue = 0; if (mapping.getArmorType() != null) { - computeArmorProperties(mapping.getArmorType(), mapping.getProtectionValue(), itemProperties, componentBuilder); + armorType = mapping.getArmorType(); + protectionValue = mapping.getProtectionValue(); + } else if (customItemData.armorType() != null) { + armorType = customItemData.armorType(); + protectionValue = customItemData.protectionValue(); + } + + if (armorType != null) { + computeArmorProperties(armorType, protectionValue, itemProperties, componentBuilder); } if (mapping.getFirstBlockRuntimeId() != null) {