Skip to content

Commit

Permalink
fix: Skip smelting recipes that do not have valid result items.
Browse files Browse the repository at this point in the history
Writes a message to the log to help devs catch recipe problems.
  • Loading branch information
Rover656 committed Sep 28, 2024
1 parent 0d7db04 commit 3f1b6d0
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager;
Expand All @@ -21,6 +23,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;
import java.util.Optional;

@Mixin(RecipeManager.class)
public class RecipeManagerMixin {
Expand All @@ -29,21 +32,30 @@ public class RecipeManagerMixin {
private static void collectRecipe(ResourceLocation recipeId, ImmutableMultimap.Builder<RecipeType<?>, RecipeHolder<?>> byType,
ImmutableMap.Builder<ResourceLocation, RecipeHolder<?>> byName, WithConditions<Recipe<?>> recipeWithConditions, CallbackInfo ci) {
if (recipeWithConditions.carrier() instanceof SmeltingRecipe smeltingRecipe) {
RecipeHolder<AlloySmeltingRecipe> convertedHolder = enderio$convert(recipeId, smeltingRecipe);
byType.put(MachineRecipes.ALLOY_SMELTING.type().get(), convertedHolder);
byName.put(convertedHolder.id(), convertedHolder);
Optional<RecipeHolder<AlloySmeltingRecipe>> convertedHolder = enderio$convert(recipeId, smeltingRecipe);

convertedHolder.ifPresent(holder -> {
byType.put(MachineRecipes.ALLOY_SMELTING.type().get(), holder);
byName.put(holder.id(), holder);
});
}
}

@Unique
private static RecipeHolder<AlloySmeltingRecipe> enderio$convert(ResourceLocation originalId, SmeltingRecipe smeltingRecipe) {
private static Optional<RecipeHolder<AlloySmeltingRecipe>> enderio$convert(ResourceLocation originalId, SmeltingRecipe smeltingRecipe) {
AbstractCookingRecipeAccessor accessor = (AbstractCookingRecipeAccessor) smeltingRecipe;

if (accessor.getResult().isEmpty()) {
EnderIOBase.LOGGER.warn("Unable to inherit the cooking recipe with ID: {}. Reason: The result item is empty.", originalId);
return Optional.empty();
}

SizedIngredient input = new SizedIngredient(accessor.getIngredient(), 1);
int energy = MachinesConfig.COMMON.ENERGY.ALLOY_SMELTER_VANILLA_ITEM_ENERGY.get();
AlloySmeltingRecipe recipe = new AlloySmeltingRecipe(List.of(input), accessor.getResult(), energy, accessor.getExperience(), true);

String path = "smelting/" + originalId.getNamespace() + "/" + originalId.getPath();
ResourceLocation id = EnderIOBase.loc(path);
return new RecipeHolder<>(id, recipe);
return Optional.of(new RecipeHolder<>(id, recipe));
}
}

0 comments on commit 3f1b6d0

Please sign in to comment.