Files
MinecraftForge/patches/minecraft/net/minecraft/server/ReloadableServerResources.java.patch
T

63 lines
3.8 KiB
Diff

--- a/net/minecraft/server/ReloadableServerResources.java
+++ b/net/minecraft/server/ReloadableServerResources.java
@@ -29,10 +_,10 @@
private static final CompletableFuture<Unit> DATA_RELOAD_INITIAL_TASK = CompletableFuture.completedFuture(Unit.INSTANCE);
private final CommandBuildContext.Configurable commandBuildContext;
private final Commands commands;
- private final RecipeManager recipes = new RecipeManager();
+ private final RecipeManager recipes;
private final TagManager tagManager;
private final LootDataManager lootData = new LootDataManager();
- private final ServerAdvancementManager advancements = new ServerAdvancementManager(this.lootData);
+ private final ServerAdvancementManager advancements;
private final ServerFunctionLibrary functionLibrary;
public ReloadableServerResources(RegistryAccess.Frozen p_206857_, FeatureFlagSet p_250695_, Commands.CommandSelection p_206858_, int p_206859_) {
@@ -41,6 +_,10 @@
this.commands = new Commands(p_206858_, this.commandBuildContext);
this.commandBuildContext.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.CREATE_NEW);
this.functionLibrary = new ServerFunctionLibrary(p_206859_, this.commands.getDispatcher());
+ // Forge: Create context object and pass it to the recipe manager.
+ this.context = new net.minecraftforge.common.crafting.conditions.ConditionContext(this.tagManager);
+ this.recipes = new RecipeManager(context);
+ this.advancements = new ServerAdvancementManager(this.lootData, context);
}
public ServerFunctionLibrary getFunctionLibrary() {
@@ -69,7 +_,9 @@
public static CompletableFuture<ReloadableServerResources> loadResources(ResourceManager p_248588_, RegistryAccess.Frozen p_251163_, FeatureFlagSet p_250212_, Commands.CommandSelection p_249301_, int p_251126_, Executor p_249136_, Executor p_249601_) {
ReloadableServerResources reloadableserverresources = new ReloadableServerResources(p_251163_, p_250212_, p_249301_, p_251126_);
- return SimpleReloadInstance.create(p_248588_, reloadableserverresources.listeners(), p_249136_, p_249601_, DATA_RELOAD_INITIAL_TASK, LOGGER.isDebugEnabled()).done().whenComplete((p_255534_, p_255535_) -> {
+ List<PreparableReloadListener> listeners = new java.util.ArrayList<>(reloadableserverresources.listeners());
+ listeners.addAll(net.minecraftforge.event.ForgeEventFactory.onResourceReload(reloadableserverresources, p_251163_));
+ return SimpleReloadInstance.create(p_248588_, listeners, p_249136_, p_249601_, DATA_RELOAD_INITIAL_TASK, LOGGER.isDebugEnabled()).done().whenComplete((p_214309_, p_214310_) -> {
reloadableserverresources.commandBuildContext.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.FAIL);
}).thenApply((p_214306_) -> {
return reloadableserverresources;
@@ -81,6 +_,7 @@
updateRegistryTags(p_206869_, p_214315_);
});
Blocks.rebuildCache();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.TagsUpdatedEvent(p_206869_, false, false));
}
private static <T> void updateRegistryTags(RegistryAccess p_206871_, TagManager.LoadResult<T> p_206872_) {
@@ -91,5 +_,16 @@
return List.copyOf(p_214312_.getValue());
}));
p_206871_.registryOrThrow(resourcekey).bindTags(map);
+ }
+
+ private final net.minecraftforge.common.crafting.conditions.ICondition.IContext context;
+
+ /**
+ * Exposes the current condition context for usage in other reload listeners.<br>
+ * 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;
}
}