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

增强配方原料检测

This commit is contained in:
XiaoMoMi
2025-08-05 20:51:59 +08:00
parent afeec47672
commit 0d3f216bac
3 changed files with 21 additions and 12 deletions

View File

@@ -401,15 +401,13 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
for (Object item : (Iterable<?>) MBuiltInRegistries.ITEM) {
Object resourceLocation = FastNMS.INSTANCE.method$Registry$getKey(MBuiltInRegistries.ITEM, item);
Key itemKey = KeyUtils.resourceLocationToKey(resourceLocation);
if (itemKey.namespace().equals("minecraft")) {
VANILLA_ITEMS.add(itemKey);
UniqueKey uniqueKey = UniqueKey.create(itemKey);
Object mcHolder = FastNMS.INSTANCE.method$Registry$getHolderByResourceKey(MBuiltInRegistries.ITEM, FastNMS.INSTANCE.method$ResourceKey$create(MRegistries.ITEM, resourceLocation)).get();
Set<Object> tags = (Set<Object>) CoreReflections.field$Holder$Reference$tags.get(mcHolder);
for (Object tag : tags) {
Key tagId = Key.of(CoreReflections.field$TagKey$location.get(tag).toString());
VANILLA_ITEM_TAGS.computeIfAbsent(tagId, (key) -> new ArrayList<>()).add(uniqueKey);
}
VANILLA_ITEMS.add(itemKey);
UniqueKey uniqueKey = UniqueKey.create(itemKey);
Object mcHolder = FastNMS.INSTANCE.method$Registry$getHolderByResourceKey(MBuiltInRegistries.ITEM, FastNMS.INSTANCE.method$ResourceKey$create(MRegistries.ITEM, resourceLocation)).get();
Set<Object> tags = (Set<Object>) CoreReflections.field$Holder$Reference$tags.get(mcHolder);
for (Object tag : tags) {
Key tagId = Key.of(CoreReflections.field$TagKey$location.get(tag).toString());
VANILLA_ITEM_TAGS.computeIfAbsent(tagId, (key) -> new ArrayList<>()).add(uniqueKey);
}
}
} catch (ReflectiveOperationException e) {

View File

@@ -109,17 +109,26 @@ public abstract class AbstractRecipeSerializer<T, R extends Recipe<T>> implement
boolean hasCustomItem = false;
for (UniqueKey holder : itemIds) {
Optional<CustomItem<T>> optionalCustomItem = itemManager.getCustomItem(holder.key());
UniqueKey vanillaItem;
if (optionalCustomItem.isPresent()) {
CustomItem<T> customItem = optionalCustomItem.get();
if (customItem.isVanillaItem()) {
minecraftItemIds.add(holder);
vanillaItem = holder;
} else {
minecraftItemIds.add(UniqueKey.create(customItem.material()));
vanillaItem = UniqueKey.create(customItem.material());
hasCustomItem = true;
}
} else {
minecraftItemIds.add(holder);
if (itemManager.isVanillaItem(holder.key())) {
vanillaItem = holder;
} else {
throw new LocalizedResourceConfigException("warning.config.recipe.invalid_ingredient", holder.key().asString());
}
}
if (vanillaItem == UniqueKey.AIR) {
throw new LocalizedResourceConfigException("warning.config.recipe.invalid_ingredient", holder.key().asString());
}
minecraftItemIds.add(vanillaItem);
}
return itemIds.isEmpty() ? null : Ingredient.of(itemIds, minecraftItemIds, hasCustomItem);
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.util;
import net.momirealms.craftengine.core.item.ItemKeys;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
@@ -7,6 +8,7 @@ import java.util.Map;
public final class UniqueKey {
private static final Map<Key, UniqueKey> CACHE = new HashMap<>(4096, 0.5f);
public static final UniqueKey AIR = UniqueKey.create(ItemKeys.AIR);
private final Key key;