Skip to content

Commit

Permalink
Use DRM when validating recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Seeker committed Jul 4, 2024
1 parent 9866934 commit ef4c4c7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/java/wraith/alloyforgery/AlloyForgery.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import wraith.alloyforgery.recipe.*;
import wraith.alloyforgery.utils.RecipeInjector;

import java.util.HashMap;

public class AlloyForgery implements ModInitializer {

public static final OwoNetChannel CHANNEL = OwoNetChannel.create(id("main"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.recipe.RecipeManager;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.ReloadableRegistries;
import net.minecraft.server.DataPackContents;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -16,9 +17,10 @@
import java.util.HashMap;

@Mixin(DataPackContents.class)
public class DataPackContentsMixin {
public abstract class DataPackContentsMixin {

@Shadow @Final private RecipeManager recipeManager;
@Shadow @Final private ReloadableRegistries.Lookup reloadableRegistries;

@Inject(method = "refresh", at = @At("TAIL"))
private void alloy_forgery$onRefresh(CallbackInfo ci) {
Expand All @@ -30,6 +32,6 @@ public class DataPackContentsMixin {
map.put(entry.value(), entry.id());
}

AlloyForgeRecipe.PENDING_RECIPES.forEach((recipe, pendingRecipeData) -> recipe.finishRecipe(pendingRecipeData, key -> map.getOrDefault(key, Identifier.of(AlloyForgery.MOD_ID, "unknown_recipe"))));
AlloyForgeRecipe.PENDING_RECIPES.forEach((recipe, pendingRecipeData) -> recipe.finishRecipe(this.reloadableRegistries.getRegistryManager(), pendingRecipeData, key -> map.getOrDefault(key, Identifier.of(AlloyForgery.MOD_ID, "unknown_recipe"))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.recipe.*;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -73,9 +74,9 @@ public Optional<Identifier> secondaryID() {
return this.secondaryID;
}

public void finishRecipe(PendingRecipeData pendingData, Function<AlloyForgeRecipe, Identifier> lookup) {
public void finishRecipe(DynamicRegistryManager drm, PendingRecipeData pendingData, Function<AlloyForgeRecipe, Identifier> lookup) {
if (pendingData.defaultTag() != null) {
final var itemEntryList = Registries.ITEM.getEntryList(pendingData.defaultTag().getLeft());
final var itemEntryList = drm.get(RegistryKeys.ITEM).getEntryList(pendingData.defaultTag().getLeft());

itemEntryList.ifPresentOrElse(registryEntries -> {
this.output = registryEntries.get(0).value().getDefaultStack();
Expand Down

0 comments on commit ef4c4c7

Please sign in to comment.