Skip to content

Commit

Permalink
Fix error from generated recycling recipes on reload, closes #5751
Browse files Browse the repository at this point in the history
  • Loading branch information
malte0811 committed Sep 16, 2023
1 parent 77cdf2e commit 645c5d1
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.world.item.crafting.Recipe;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.event.OnDatapackSyncEvent;
import net.minecraftforge.event.TickEvent.ServerTickEvent;
import net.minecraftforge.event.server.ServerStartedEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand Down Expand Up @@ -118,13 +119,19 @@ public void onServerTick(ServerTickEvent ev)
fillInRecipes(ServerLifecycleHooks.getCurrentServer());
}

@SubscribeEvent
public void onDatapackSync(OnDatapackSyncEvent ev)
{
fillInRecipes(ev.getPlayerList().getServer());
}

private void fillInRecipes(MinecraftServer server)
{
Preconditions.checkState(result.getValue()==null);
MinecraftForge.EVENT_BUS.unregister(eventListener.getValue());
Collection<Recipe<?>> recipes = server.getRecipeManager().getRecipes();
ArcRecyclingCalculator calculator = new ArcRecyclingCalculator(recipes, server.registryAccess());
result.setValue(calculator.run());
MinecraftForge.EVENT_BUS.unregister(eventListener.getValue());
}
});
MinecraftForge.EVENT_BUS.register(eventListener.getValue());
Expand Down

0 comments on commit 645c5d1

Please sign in to comment.