9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

修改替代配方的配置位置

This commit is contained in:
XiaoMoMi
2025-10-08 14:42:55 +08:00
parent b79d0c48f1
commit 00b95a8b43
2 changed files with 21 additions and 11 deletions

View File

@@ -208,6 +208,15 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
for (Key tag : tags) {
this.customItemTags.computeIfAbsent(tag, k -> new ArrayList<>()).add(customItem.uniqueId());
}
// ingredient substitutes
List<Key> substitutes = customItem.settings().ingredientSubstitutes();
if (!substitutes.isEmpty()) {
for (Key key : substitutes) {
if (VANILLA_ITEMS.contains(key)) {
AbstractItemManager.this.ingredientSubstitutes.computeIfAbsent(key, k -> new ArrayList<>()).add(customItem.uniqueId());
}
}
}
}
return true;
}
@@ -611,17 +620,6 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
AbstractItemManager.this.plugin.itemBrowserManager().addExternalCategoryMember(id, MiscUtils.getAsStringList(section.get("category")).stream().map(Key::of).toList());
}
// 替代配方材料
if (section.containsKey("ingredient-substitute")) {
List<String> substitutes = MiscUtils.getAsStringList(section.get("ingredient-substitute"));
for (String substitute : substitutes) {
Key key = Key.of(substitute);
if (VANILLA_ITEMS.contains(key)) {
AbstractItemManager.this.ingredientSubstitutes.computeIfAbsent(key, k -> new ArrayList<>()).add(uniqueId);
}
}
}
/*
* ========================
*

View File

@@ -38,6 +38,7 @@ public class ItemSettings {
boolean canEnchant = true;
float compostProbability= 0.5f;
boolean respectRepairableComponent = false;
List<Key> ingredientSubstitutes = List.of();
@Nullable
ItemEquipment equipment;
@Nullable
@@ -104,6 +105,7 @@ public class ItemSettings {
newSettings.respectRepairableComponent = settings.respectRepairableComponent;
newSettings.dyeColor = settings.dyeColor;
newSettings.fireworkColor = settings.fireworkColor;
newSettings.ingredientSubstitutes = settings.ingredientSubstitutes;
return newSettings;
}
@@ -159,6 +161,10 @@ public class ItemSettings {
return respectRepairableComponent;
}
public List<Key> ingredientSubstitutes() {
return ingredientSubstitutes;
}
@Nullable
public FoodData foodData() {
return foodData;
@@ -207,6 +213,11 @@ public class ItemSettings {
return this;
}
public ItemSettings ingredientSubstitutes(List<Key> substitutes) {
this.ingredientSubstitutes = substitutes;
return this;
}
public ItemSettings dyeColor(Color color) {
this.dyeColor = color;
return this;
@@ -458,6 +469,7 @@ public class ItemSettings {
}).toList();
return settings -> settings.invulnerable(list);
}));
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) {