11package me .wurgo .antiresourcereload .mixin ;
22
33import com .google .common .collect .Lists ;
4+ import com .llamalad7 .mixinextras .injector .v2 .WrapWithCondition ;
5+ import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
6+ import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
47import me .wurgo .antiresourcereload .AntiResourceReload ;
58import net .minecraft .loot .LootManager ;
69import net .minecraft .loot .condition .LootConditionManager ;
710import net .minecraft .recipe .RecipeManager ;
8- import net .minecraft .resource .*;
11+ import net .minecraft .resource .ReloadableResourceManager ;
12+ import net .minecraft .resource .ResourcePackManager ;
13+ import net .minecraft .resource .ResourcePackProfile ;
914import net .minecraft .server .MinecraftServer ;
1015import net .minecraft .server .ServerAdvancementLoader ;
1116import net .minecraft .server .function .CommandFunctionManager ;
1722import org .spongepowered .asm .mixin .Mutable ;
1823import org .spongepowered .asm .mixin .Shadow ;
1924import org .spongepowered .asm .mixin .injection .At ;
20- import org .spongepowered .asm .mixin .injection .Redirect ;
2125
2226import java .util .List ;
2327
2428@ Mixin (MinecraftServer .class )
2529public abstract class MinecraftServerMixin {
26- @ Shadow protected abstract void reloadDataPacks (LevelProperties levelProperties );
27- @ Mutable @ Shadow @ Final private ReloadableResourceManager dataManager ;
28- @ Mutable @ Shadow @ Final private RegistryTagManager tagManager ;
29- @ Mutable @ Shadow @ Final private LootConditionManager predicateManager ;
30- @ Mutable @ Shadow @ Final private RecipeManager recipeManager ;
31- @ Mutable @ Shadow @ Final private LootManager lootManager ;
32- @ Mutable @ Shadow @ Final private CommandFunctionManager commandFunctionManager ;
33- @ Mutable @ Shadow @ Final private ServerAdvancementLoader advancementLoader ;
30+ @ Shadow
31+ @ Final
32+ private static Logger LOGGER ;
3433
35- @ Shadow @ Final private static Logger LOGGER ;
36- @ Shadow @ Final private ResourcePackManager <ResourcePackProfile > dataPackManager ;
34+ @ Shadow
35+ @ Final
36+ private ResourcePackManager <ResourcePackProfile > dataPackManager ;
3737
38- @ Redirect (
38+ @ Mutable
39+ @ Shadow
40+ @ Final
41+ private ReloadableResourceManager dataManager ;
42+ @ Mutable
43+ @ Shadow
44+ @ Final
45+ private RegistryTagManager tagManager ;
46+ @ Mutable
47+ @ Shadow
48+ @ Final
49+ private LootConditionManager predicateManager ;
50+ @ Mutable
51+ @ Shadow
52+ @ Final
53+ private RecipeManager recipeManager ;
54+ @ Mutable
55+ @ Shadow
56+ @ Final
57+ private LootManager lootManager ;
58+ @ Mutable
59+ @ Shadow
60+ @ Final
61+ private CommandFunctionManager commandFunctionManager ;
62+ @ Mutable
63+ @ Shadow
64+ @ Final
65+ private ServerAdvancementLoader advancementLoader ;
66+
67+ @ WrapOperation (
3968 method = "loadWorldDataPacks" ,
4069 at = @ At (
4170 value = "INVOKE" ,
4271 target = "Lnet/minecraft/server/MinecraftServer;reloadDataPacks(Lnet/minecraft/world/level/LevelProperties;)V"
4372 )
4473 )
45- private void antiresourcereload_cachedReload (MinecraftServer instance , LevelProperties levelProperties ) {
46- if (levelProperties .getEnabledDataPacks ().size () + levelProperties .getDisabledDataPacks ().size () != 0 ) {
74+ private void cachedReload (MinecraftServer server , LevelProperties properties , Operation < Void > original ) {
75+ if (! properties .getEnabledDataPacks ().isEmpty () || ! properties .getDisabledDataPacks ().isEmpty () ) {
4776 AntiResourceReload .log ("Using data-packs, reloading." );
48- this . reloadDataPacks ( levelProperties );
77+ original . call ( server , properties );
4978 return ;
5079 }
51-
80+
5281 if (AntiResourceReload .dataManager == null ) {
5382 AntiResourceReload .log ("Cached resources unavailable, reloading & caching." );
5483 AntiResourceReload .dataManager = this .dataManager ;
55- this . reloadDataPacks ( levelProperties );
84+ original . call ( server , properties );
5685 AntiResourceReload .tagManager = this .tagManager ;
5786 AntiResourceReload .predicateManager = this .predicateManager ;
5887 AntiResourceReload .recipeManager = this .recipeManager ;
@@ -68,21 +97,33 @@ private void antiresourcereload_cachedReload(MinecraftServer instance, LevelProp
6897 this .lootManager = AntiResourceReload .lootManager ;
6998 this .commandFunctionManager = AntiResourceReload .commandFunctionManager ;
7099 this .advancementLoader = AntiResourceReload .advancementLoader ;
71- if (AntiResourceReload .hasSeenRecipes ) {
72- ((RecipeManagerAccess ) this .recipeManager ).invokeApply (AntiResourceReload .recipes , null , null );
73- }
74100
75101 // should only be the vanilla pack
76102 // logic taken from MinecraftServer#reloadDataPacks
77103 List <ResourcePackProfile > list = Lists .newArrayList (this .dataPackManager .getEnabledProfiles ());
78104
79105 for (ResourcePackProfile resourcePackProfile : this .dataPackManager .getProfiles ()) {
80- if (!levelProperties .getDisabledDataPacks ().contains (resourcePackProfile .getName ()) && !list .contains (resourcePackProfile )) {
106+ if (!properties .getDisabledDataPacks ().contains (resourcePackProfile .getName ()) && !list .contains (resourcePackProfile )) {
81107 LOGGER .info ("Found new data pack {}, loading it automatically" , resourcePackProfile .getName ());
82108 resourcePackProfile .getInitialPosition ().insert (list , resourcePackProfile , profile -> profile , false );
83109 }
84110 }
85111 this .dataPackManager .setEnabledProfiles (list );
86112 }
87113 }
114+
115+ @ WrapWithCondition (
116+ method = "loadWorldDataPacks" ,
117+ at = @ At (
118+ value = "INVOKE" ,
119+ target = "Lnet/minecraft/server/MinecraftServer;method_24154()V"
120+ )
121+ )
122+ private boolean skipInitializingShapeCache (MinecraftServer server ) {
123+ if (!AntiResourceReload .hasInitializedShapeCache ) {
124+ AntiResourceReload .hasInitializedShapeCache = true ;
125+ return true ;
126+ }
127+ return false ;
128+ }
88129}
0 commit comments