From 6bc6c0afcd86739c02ca2e361cd07743f20d6d76 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Thu, 20 Nov 2025 01:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0custom=20data=E7=9A=84setting?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../craftengine/core/item/ItemSettings.java | 53 ++++++++++++------- .../craftengine/core/util/CustomDataType.java | 4 ++ 2 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/CustomDataType.java diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/ItemSettings.java b/core/src/main/java/net/momirealms/craftengine/core/item/ItemSettings.java index 96cead759..2800dcfc5 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/ItemSettings.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/ItemSettings.java @@ -47,6 +47,7 @@ public class ItemSettings { Color dyeColor; @Nullable Color fireworkColor; + Map, Object> customData = new IdentityHashMap<>(4); private ItemSettings() {} @@ -108,6 +109,7 @@ public class ItemSettings { newSettings.dyeColor = settings.dyeColor; newSettings.fireworkColor = settings.fireworkColor; newSettings.ingredientSubstitutes = settings.ingredientSubstitutes; + newSettings.customData = settings.customData; return newSettings; } @@ -123,73 +125,86 @@ public class ItemSettings { return settings; } + @SuppressWarnings("unchecked") + public T getCustomData(CustomDataType type) { + return (T) this.customData.get(type); + } + + public void clearCustomData() { + this.customData.clear(); + } + + public void addCustomData(CustomDataType key, T value) { + this.customData.put(key, value); + } + public ProjectileMeta projectileMeta() { - return projectileMeta; + return this.projectileMeta; } public boolean disableVanillaBehavior() { - return disableVanillaBehavior; + return this.disableVanillaBehavior; } public Repairable repairable() { - return repairable; + return this.repairable; } public int fuelTime() { - return fuelTime; + return this.fuelTime; } public boolean renameable() { - return renameable; + return this.renameable; } public Set tags() { - return tags; + return this.tags; } public Tristate dyeable() { - return dyeable; + return this.dyeable; } public boolean canEnchant() { - return canEnchant; + return this.canEnchant; } public List repairItems() { - return anvilRepairItems; + return this.anvilRepairItems; } public boolean respectRepairableComponent() { - return respectRepairableComponent; + return this.respectRepairableComponent; } public List ingredientSubstitutes() { - return ingredientSubstitutes; + return this.ingredientSubstitutes; } @Nullable public FoodData foodData() { - return foodData; + return this.foodData; } @Nullable public Key consumeReplacement() { - return consumeReplacement; + return this.consumeReplacement; } @Nullable public CraftRemainder craftRemainder() { - return craftRemainder; + return this.craftRemainder; } @Nullable public Helmet helmet() { - return helmet; + return this.helmet; } @Nullable public ItemEquipment equipment() { - return equipment; + return this.equipment; } @Nullable @@ -203,11 +218,11 @@ public class ItemSettings { } public List invulnerable() { - return invulnerable; + return this.invulnerable; } public float compostProbability() { - return compostProbability; + return this.compostProbability; } public ItemSettings fireworkColor(Color color) { @@ -482,7 +497,7 @@ public class ItemSettings { registerFactory("ingredient-substitute", (value -> settings -> settings.ingredientSubstitutes(MiscUtils.getAsStringList(value).stream().map(Key::of).toList()))); } - private static void registerFactory(String id, ItemSettings.Modifier.Factory factory) { + public static void registerFactory(String id, ItemSettings.Modifier.Factory factory) { FACTORIES.put(id, factory); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/CustomDataType.java b/core/src/main/java/net/momirealms/craftengine/core/util/CustomDataType.java new file mode 100644 index 000000000..48145fdd8 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/util/CustomDataType.java @@ -0,0 +1,4 @@ +package net.momirealms.craftengine.core.util; + +public class CustomDataType { +}