mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 12:29:15 +00:00
配方替代原料
This commit is contained in:
@@ -63,6 +63,8 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
protected final List<Suggestion> cachedAllItemSuggestions = new ArrayList<>();
|
||||
protected final List<Suggestion> cachedVanillaItemSuggestions = new ArrayList<>();
|
||||
protected final List<Suggestion> cachedTotemSuggestions = new ArrayList<>();
|
||||
// 替代配方材料
|
||||
protected final Map<Key, List<UniqueKey>> ingredientSubstitutes = new HashMap<>();
|
||||
|
||||
protected AbstractItemManager(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
@@ -141,6 +143,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
this.equipments.clear();
|
||||
this.modernItemModels1_21_4.clear();
|
||||
this.modernItemModels1_21_2.clear();
|
||||
this.ingredientSubstitutes.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,6 +166,15 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
return Optional.ofNullable(this.customItemsByPath.get(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UniqueKey> getIngredientSubstitutes(Key item) {
|
||||
if (VANILLA_ITEMS.contains(item)) {
|
||||
return Optional.ofNullable(this.ingredientSubstitutes.get(item)).orElse(Collections.emptyList());
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUpdateResult updateItem(Item<I> item, Supplier<ItemBuildContext> contextSupplier) {
|
||||
Optional<CustomItem<I>> optionalCustomItem = item.getCustomItem();
|
||||
@@ -599,6 +611,17 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ========================
|
||||
*
|
||||
|
||||
@@ -124,5 +124,7 @@ public interface ItemManager<T> extends Manageable, ModelGenerator {
|
||||
|
||||
Item<T> build(DatapackRecipeResult result);
|
||||
|
||||
List<UniqueKey> getIngredientSubstitutes(Key item);
|
||||
|
||||
ItemUpdateResult updateItem(Item<T> item, Supplier<ItemBuildContext> contextSupplier);
|
||||
}
|
||||
@@ -144,13 +144,25 @@ public abstract class AbstractRecipeSerializer<T, R extends Recipe<T>> implement
|
||||
Set<UniqueKey> minecraftItemIds = new HashSet<>();
|
||||
ItemManager<T> itemManager = CraftEngine.instance().itemManager();
|
||||
for (String item : items) {
|
||||
if (item.charAt(0) == '#') itemIds.addAll(itemManager.itemIdsByTag(Key.of(item.substring(1))));
|
||||
else {
|
||||
if (item.charAt(0) == '#') {
|
||||
List<UniqueKey> uniqueKeys = itemManager.itemIdsByTag(Key.of(item.substring(1)));
|
||||
itemIds.addAll(uniqueKeys);
|
||||
for (UniqueKey uniqueKey : uniqueKeys) {
|
||||
List<UniqueKey> ingredientSubstitutes = itemManager.getIngredientSubstitutes(uniqueKey.key());
|
||||
if (!ingredientSubstitutes.isEmpty()) {
|
||||
itemIds.addAll(ingredientSubstitutes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Key itemId = Key.of(item);
|
||||
if (itemManager.getBuildableItem(itemId).isEmpty()) {
|
||||
throw new LocalizedResourceConfigException("warning.config.recipe.invalid_ingredient", item);
|
||||
}
|
||||
itemIds.add(UniqueKey.create(itemId));
|
||||
List<UniqueKey> ingredientSubstitutes = itemManager.getIngredientSubstitutes(itemId);
|
||||
if (!ingredientSubstitutes.isEmpty()) {
|
||||
itemIds.addAll(ingredientSubstitutes);
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean hasCustomItem = false;
|
||||
|
||||
@@ -21,10 +21,11 @@ public abstract class IdSectionConfigParser extends AbstractConfigParser {
|
||||
protected void parseSection(CachedConfigSection cached) {
|
||||
for (Map.Entry<String, Object> configEntry : cached.config().entrySet()) {
|
||||
String key = configEntry.getKey();
|
||||
Object value = configEntry.getValue();
|
||||
Key id = Key.withDefaultNamespace(key, cached.pack().namespace());
|
||||
if (!(configEntry.getValue() instanceof Map<?, ?> section)) {
|
||||
if (!(value instanceof Map<?, ?> section)) {
|
||||
TranslationManager.instance().log("warning.config.structure.not_section",
|
||||
cached.filePath().toString(), cached.prefix() + "." + key, configEntry.getValue().getClass().getSimpleName());
|
||||
cached.filePath().toString(), cached.prefix() + "." + key, value == null ? "null" : value.getClass().getSimpleName());
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> config = castToMap(section, false);
|
||||
|
||||
Reference in New Issue
Block a user