From 168a3bc6fcf37f0efe54f266ebc24b20062f217d Mon Sep 17 00:00:00 2001 From: Brennan Ward Date: Tue, 3 May 2022 13:25:42 -0400 Subject: [PATCH] Expose ICondition$IContext to modded reload listeners. (#8596) --- .../ReloadableServerResources.java.patch | 21 +++++++++++++++++-- .../event/AddReloadListenerEvent.java | 13 ++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/patches/minecraft/net/minecraft/server/ReloadableServerResources.java.patch b/patches/minecraft/net/minecraft/server/ReloadableServerResources.java.patch index 382dccdfdb..e705cc2aa7 100644 --- a/patches/minecraft/net/minecraft/server/ReloadableServerResources.java.patch +++ b/patches/minecraft/net/minecraft/server/ReloadableServerResources.java.patch @@ -18,8 +18,8 @@ this.f_206849_ = new TagManager(p_206857_); this.f_206847_ = new Commands(p_206858_); this.f_206854_ = new ServerFunctionLibrary(p_206859_, this.f_206847_.m_82094_()); -+ // Forge: pass condition context too -+ var context = new net.minecraftforge.common.crafting.conditions.ConditionContext(this.f_206849_); ++ // Forge: Create context object and pass it to the recipe manager. ++ this.context = new net.minecraftforge.common.crafting.conditions.ConditionContext(this.f_206849_); + this.f_206848_ = new RecipeManager(context); + this.f_206853_ = new ServerAdvancementManager(this.f_206850_, context); } @@ -44,3 +44,20 @@ } private static void m_206870_(RegistryAccess p_206871_, TagManager.LoadResult p_206872_) { +@@ -96,5 +_,16 @@ + return p_206874_.getValue().m_6497_(); + })); + p_206871_.m_175515_(resourcekey).m_203652_(map); ++ } ++ ++ private final net.minecraftforge.common.crafting.conditions.ICondition.IContext context; ++ ++ /** ++ * Exposes the current condition context for usage in other reload listeners.
++ * This is not useful outside the reloading stage. ++ * @return The condition context for the currently active reload. ++ */ ++ public net.minecraftforge.common.crafting.conditions.ICondition.IContext getConditionContext() { ++ return this.context; + } + } diff --git a/src/main/java/net/minecraftforge/event/AddReloadListenerEvent.java b/src/main/java/net/minecraftforge/event/AddReloadListenerEvent.java index 856ca5b864..2acb1d882a 100644 --- a/src/main/java/net/minecraftforge/event/AddReloadListenerEvent.java +++ b/src/main/java/net/minecraftforge/event/AddReloadListenerEvent.java @@ -11,6 +11,7 @@ import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.server.packs.resources.PreparableReloadListener; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.crafting.conditions.ICondition; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.fml.ModLoader; @@ -48,11 +49,23 @@ public class AddReloadListenerEvent extends Event return ImmutableList.copyOf(listeners); } + /** + * @return The ReloableServerResources being reloaded. + */ public ReloadableServerResources getServerResources() { return serverResources; } + /** + * This context object holds data relevant to the current reload, such as staged tags. + * @return The condition context for the currently active reload. + */ + public ICondition.IContext getConditionContext() + { + return serverResources.getConditionContext(); + } + private static class WrappedStateAwareListener implements PreparableReloadListener { private final PreparableReloadListener wrapped;