diff --git a/src/main/java/xyz/bluspring/kilt/forgeinjects/server/ReloadableServerResourcesInject.java b/src/main/java/xyz/bluspring/kilt/forgeinjects/server/ReloadableServerResourcesInject.java index 084d3fc7..d490cb27 100644 --- a/src/main/java/xyz/bluspring/kilt/forgeinjects/server/ReloadableServerResourcesInject.java +++ b/src/main/java/xyz/bluspring/kilt/forgeinjects/server/ReloadableServerResourcesInject.java @@ -1,13 +1,18 @@ // TRACKED HASH: d24928420f3c1ebf622411bc07206c361aa737b9 package xyz.bluspring.kilt.forgeinjects.server; +import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.commands.Commands; import net.minecraft.core.RegistryAccess; import net.minecraft.server.ReloadableServerResources; +import net.minecraft.server.packs.resources.PreparableReloadListener; import net.minecraft.tags.TagManager; import net.minecraft.world.flag.FeatureFlagSet; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.crafting.conditions.ConditionContext; import net.minecraftforge.common.crafting.conditions.ICondition; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.event.TagsUpdatedEvent; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -15,9 +20,13 @@ import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xyz.bluspring.kilt.injections.ReloadableServerResourcesInjection; +import java.util.ArrayList; +import java.util.List; + @Mixin(ReloadableServerResources.class) public class ReloadableServerResourcesInject implements ReloadableServerResourcesInjection { @Shadow @Final private TagManager tagManager; @@ -34,4 +43,17 @@ public class ReloadableServerResourcesInject implements ReloadableServerResource public ICondition.IContext getConditionContext() { return kilt$context; } + + @ModifyArg(method = "loadResources", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/resources/SimpleReloadInstance;create(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/util/List;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Z)Lnet/minecraft/server/packs/resources/ReloadInstance;")) + private static List kilt$addForgeResourceReloadListener(List listeners, @Local ReloadableServerResources serverResources, @Local(argsOnly = true) RegistryAccess.Frozen registryAccess) { + var list = new ArrayList<>(listeners); + list.addAll(ForgeEventFactory.onResourceReload(serverResources, registryAccess)); + + return list; + } + + @Inject(method = "updateRegistryTags(Lnet/minecraft/core/RegistryAccess;)V", at = @At("TAIL")) + private void kilt$callTagUpdateEvent(RegistryAccess registryAccess, CallbackInfo ci) { + MinecraftForge.EVENT_BUS.post(new TagsUpdatedEvent(registryAccess, false, false)); + } } \ No newline at end of file