Skip to content

Commit 1fa9ef1

Browse files
committed
fix vanilla pack showing up red in /datapack list and not being in enabled packs
1 parent 88a066d commit 1fa9ef1

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftServerMixin.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package me.wurgo.antiresourcereload.mixin;
22

3+
import com.google.common.collect.Lists;
34
import me.wurgo.antiresourcereload.AntiResourceReload;
45
import net.minecraft.loot.LootManager;
56
import net.minecraft.loot.condition.LootConditionManager;
67
import net.minecraft.recipe.RecipeManager;
7-
import net.minecraft.resource.ReloadableResourceManager;
8+
import net.minecraft.resource.*;
89
import net.minecraft.server.MinecraftServer;
910
import net.minecraft.server.ServerAdvancementLoader;
1011
import net.minecraft.server.function.CommandFunctionManager;
1112
import net.minecraft.tag.RegistryTagManager;
1213
import net.minecraft.world.level.LevelProperties;
14+
import org.apache.logging.log4j.core.Logger;
1315
import org.spongepowered.asm.mixin.Final;
1416
import org.spongepowered.asm.mixin.Mixin;
1517
import org.spongepowered.asm.mixin.Mutable;
1618
import org.spongepowered.asm.mixin.Shadow;
1719
import org.spongepowered.asm.mixin.injection.At;
1820
import org.spongepowered.asm.mixin.injection.Redirect;
1921

22+
import java.util.List;
23+
2024
@Mixin(MinecraftServer.class)
2125
public abstract class MinecraftServerMixin {
2226
@Shadow protected abstract void reloadDataPacks(LevelProperties levelProperties);
@@ -28,6 +32,9 @@ public abstract class MinecraftServerMixin {
2832
@Mutable @Shadow @Final private CommandFunctionManager commandFunctionManager;
2933
@Mutable @Shadow @Final private ServerAdvancementLoader advancementLoader;
3034

35+
@Shadow @Final private static Logger LOGGER;
36+
@Shadow @Final private ResourcePackManager<ResourcePackProfile> dataPackManager;
37+
3138
@Redirect(
3239
method = "loadWorldDataPacks",
3340
at = @At(
@@ -64,6 +71,18 @@ private void antiresourcereload_cachedReload(MinecraftServer instance, LevelProp
6471
if (AntiResourceReload.hasSeenRecipes) {
6572
((RecipeManagerAccess) this.recipeManager).invokeApply(AntiResourceReload.recipes, null, null);
6673
}
74+
75+
// should only be the vanilla pack
76+
// logic taken from MinecraftServer#reloadDataPacks
77+
List<ResourcePackProfile> list = Lists.newArrayList(this.dataPackManager.getEnabledProfiles());
78+
79+
for (ResourcePackProfile resourcePackProfile : this.dataPackManager.getProfiles()) {
80+
if (!levelProperties.getDisabledDataPacks().contains(resourcePackProfile.getName()) && !list.contains(resourcePackProfile)) {
81+
LOGGER.info("Found new data pack {}, loading it automatically", resourcePackProfile.getName());
82+
resourcePackProfile.getInitialPosition().insert(list, resourcePackProfile, profile -> profile, false);
83+
}
84+
}
85+
this.dataPackManager.setEnabledProfiles(list);
6786
}
6887
}
6988
}

0 commit comments

Comments
 (0)