[Bug] Grindstone Recipe Traverses All Levels of Enchantments
Phoupraw opened this issue ยท 6 comments
EMI version: 1.0.15+1.20.1
Loader: Fabric
Though anvil enchant recipe no longer traverses all levels of enchantments, grindstone disenchant recipe still does so, causing #259.
I use this mixin to fix it, which only traverses enchanted books in the serach tab.
@Pseudo
@Mixin(targets = "dev/emi/emi/VanillaPlugin")
abstract class MVanillaPlugin {
@Shadow
private static void addRecipeSafe(EmiRegistry registry, Supplier<EmiRecipe> supplier) {
}
@Shadow
private static Identifier synthetic(String type, String name) {
throw new IllegalStateException();
}
@Inject(method = "addRepair", at = @At(value = "FIELD", target = "Ldev/emi/emi/recipe/special/EmiAnvilEnchantRecipe;ENCHANTMENTS:Ljava/util/List;", ordinal = 1))
private static void addGrindstoneRecipes(EmiRegistry registry, Set<Item> hiddenItems, CallbackInfo ci) {
for (ItemStack itemStack : ItemGroups.getSearchGroup().getDisplayStacks()) {
if (itemStack.isOf(Items.ENCHANTED_BOOK)) {
var entry = EnchantmentHelper.get(itemStack).entrySet().iterator().next();
addRecipeSafe(registry, () -> {
Enchantment enchantment = entry.getKey();
int level = entry.getValue();
//noinspection ConstantConditions
return new EmiGrindstoneDisenchantingBookRecipe(enchantment, level, synthetic("grindstone/disenchanting/book", EmiUtil.subId(EmiPort.getEnchantmentRegistry().getId(enchantment)) + "/" + level));
});
}
}
}
@Redirect(method = "addRepair", at = @At(value = "FIELD", target = "Ldev/emi/emi/recipe/special/EmiAnvilEnchantRecipe;ENCHANTMENTS:Ljava/util/List;", ordinal = 1))
private static List<Enchantment> emptyList() {
return List.of();
}
}
A fix will be released shortly, please don't use this mixin which can crash when I actually fix the issue.
How to reopen the issue?
for (Enchantment e : EmiAnvilEnchantRecipe.ENCHANTMENTS) {
if (!e.isCursed()) {
int max = Math.max(10, e.getMaxLevel());//<-------- should be Math.min
int min = e.getMinLevel();
while (min <= max) {
int level = min;
addRecipeSafe(registry, () -> new EmiGrindstoneDisenchantingBookRecipe(e, level,
synthetic("grindstone/disenchanting/book", EmiUtil.subId(EmiPort.getEnchantmentRegistry().getId(e)) + "/" + level)));
min++;
}
}
}