Skip to content

Commit b0f87c2

Browse files
authored
Merge pull request #14 from contariaa/1.15.2
Port 5.2.0 to MC 1.15.2
2 parents 790ddbf + d94e617 commit b0f87c2

14 files changed

Lines changed: 256 additions & 51 deletions

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx2G
22
org.gradle.parallel = true
33
org.gradle.caching = true
44

5-
mod_version = 4.0.3
5+
mod_version = 5.2.0
66
target_version = 1.15.2
77
archives_name = antiresourcereload
88
maven_group = me.wurgo

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[versions]
22
minecraft = "1.15.2"
33
yarn_mappings = "1.15.2+build.17"
4-
fabric_loader = "0.15.7"
5-
loom = "1.5-SNAPSHOT"
4+
fabric_loader = "0.16.10"
5+
loom = "1.9-SNAPSHOT"
66
vineflower = "1.10.0-SNAPSHOT"
77

88
[libraries]

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
package me.wurgo.antiresourcereload;
22

33
import com.google.gson.JsonElement;
4-
import net.fabricmc.api.ModInitializer;
5-
import net.fabricmc.loader.api.FabricLoader;
64
import net.minecraft.loot.LootManager;
75
import net.minecraft.loot.condition.LootConditionManager;
86
import net.minecraft.recipe.RecipeManager;
97
import net.minecraft.resource.ReloadableResourceManager;
108
import net.minecraft.server.ServerAdvancementLoader;
9+
import net.minecraft.server.command.CommandManager;
1110
import net.minecraft.server.function.CommandFunctionManager;
11+
import net.minecraft.structure.Structure;
1212
import net.minecraft.tag.RegistryTagManager;
1313
import net.minecraft.util.Identifier;
14+
import net.minecraft.util.UserCache;
1415
import org.apache.logging.log4j.LogManager;
1516
import org.apache.logging.log4j.Logger;
1617

18+
import java.util.Collections;
19+
import java.util.HashMap;
1720
import java.util.Map;
1821

19-
public class AntiResourceReload implements ModInitializer {
20-
private static final Logger LOGGER = LogManager.getLogger(FabricLoader.getInstance().getModContainer("antiresourcereload").get().getMetadata().getName());
22+
public class AntiResourceReload {
23+
private static final Logger LOGGER = LogManager.getLogger();
2124

2225
public static ReloadableResourceManager dataManager;
2326
public static RecipeManager recipeManager;
@@ -27,14 +30,17 @@ public class AntiResourceReload implements ModInitializer {
2730
public static ServerAdvancementLoader advancementLoader;
2831
public static CommandFunctionManager commandFunctionManager;
2932
public static Map<Identifier, JsonElement> recipes;
33+
34+
public static CommandManager commandManager;
35+
36+
public static final Map<Identifier, Structure> structures = Collections.synchronizedMap(new HashMap<>());
37+
38+
public static UserCache userCache;
39+
40+
public static boolean hasInitializedShapeCache;
3041
public static boolean hasSeenRecipes;
31-
32-
public static void log(String message) {
33-
LOGGER.info("[" + LOGGER.getName() + "] " + message);
34-
}
3542

36-
@Override
37-
public void onInitialize() {
38-
log("Initializing.");
43+
public static void log(String message) {
44+
LOGGER.info("[AntiResourceReload] {}", message);
3945
}
4046
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package me.wurgo.antiresourcereload.mixin;
2+
3+
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
5+
import net.minecraft.resource.DefaultResourcePack;
6+
import net.minecraft.resource.metadata.PackResourceMetadata;
7+
import net.minecraft.resource.metadata.ResourceMetadataReader;
8+
import org.jetbrains.annotations.Nullable;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.Unique;
11+
12+
@Mixin(DefaultResourcePack.class)
13+
public abstract class DefaultResourcePackMixin {
14+
@Nullable
15+
@Unique
16+
private static PackResourceMetadata METADATA;
17+
18+
@WrapMethod(method = "parseMetadata")
19+
private Object cacheMetadata(ResourceMetadataReader<?> reader, Operation<?> original) {
20+
if (reader != PackResourceMetadata.READER) {
21+
return original.call(reader);
22+
}
23+
if (METADATA == null) {
24+
METADATA = (PackResourceMetadata) original.call(reader);
25+
}
26+
return METADATA;
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.wurgo.antiresourcereload.mixin;
2+
3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import me.wurgo.antiresourcereload.AntiResourceReload;
6+
import net.minecraft.server.command.CommandManager;
7+
import net.minecraft.server.integrated.IntegratedServer;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
11+
@Mixin(IntegratedServer.class)
12+
public abstract class IntegratedServerMixin {
13+
14+
@WrapOperation(
15+
method = "<init>",
16+
at = @At(
17+
value = "NEW",
18+
target = "(Z)Lnet/minecraft/server/command/CommandManager;"
19+
)
20+
)
21+
private static CommandManager cacheCommandManager(boolean isDedicatedServer, Operation<CommandManager> original) {
22+
if (AntiResourceReload.commandManager == null) {
23+
AntiResourceReload.commandManager = original.call(isDedicatedServer);
24+
}
25+
return AntiResourceReload.commandManager;
26+
}
27+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package me.wurgo.antiresourcereload.mixin;
2+
3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import com.mojang.authlib.GameProfileRepository;
6+
import me.wurgo.antiresourcereload.AntiResourceReload;
7+
import net.minecraft.client.MinecraftClient;
8+
import net.minecraft.server.integrated.IntegratedServer;
9+
import net.minecraft.util.UserCache;
10+
import org.jetbrains.annotations.Nullable;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.Shadow;
13+
import org.spongepowered.asm.mixin.injection.At;
14+
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
16+
17+
import java.io.File;
18+
19+
@Mixin(MinecraftClient.class)
20+
public abstract class MinecraftClientMixin {
21+
22+
@Shadow
23+
@Nullable
24+
private IntegratedServer server;
25+
26+
@Inject(
27+
method = "startIntegratedServer",
28+
at = @At(
29+
value = "INVOKE",
30+
target = "Lnet/minecraft/network/ClientConnection;connectLocal(Ljava/net/SocketAddress;)Lnet/minecraft/network/ClientConnection;"
31+
)
32+
)
33+
private void reloadRecipes(CallbackInfo ci) {
34+
// reloading is done when actually joining the world instead of on world creation because of SeedQueue
35+
if (this.server != null && this.server.getRecipeManager() == AntiResourceReload.recipeManager && AntiResourceReload.hasSeenRecipes) {
36+
((RecipeManagerAccess) AntiResourceReload.recipeManager).antiresourcereload$apply(AntiResourceReload.recipes, null, null);
37+
AntiResourceReload.hasSeenRecipes = false;
38+
}
39+
}
40+
41+
@WrapOperation(
42+
method = {
43+
"startIntegratedServer",
44+
"joinWorld"
45+
},
46+
at = @At(
47+
value = "NEW",
48+
target = "(Lcom/mojang/authlib/GameProfileRepository;Ljava/io/File;)Lnet/minecraft/util/UserCache;"
49+
),
50+
require = 2
51+
)
52+
private UserCache cacheUserCache(GameProfileRepository profileRepository, File cacheFile, Operation<UserCache> original) {
53+
if (AntiResourceReload.userCache == null) {
54+
AntiResourceReload.userCache = original.call(profileRepository, cacheFile);
55+
}
56+
return AntiResourceReload.userCache;
57+
}
58+
}
Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package me.wurgo.antiresourcereload.mixin;
22

33
import 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;
47
import me.wurgo.antiresourcereload.AntiResourceReload;
58
import net.minecraft.loot.LootManager;
69
import net.minecraft.loot.condition.LootConditionManager;
710
import 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;
914
import net.minecraft.server.MinecraftServer;
1015
import net.minecraft.server.ServerAdvancementLoader;
1116
import net.minecraft.server.function.CommandFunctionManager;
@@ -17,42 +22,66 @@
1722
import org.spongepowered.asm.mixin.Mutable;
1823
import org.spongepowered.asm.mixin.Shadow;
1924
import org.spongepowered.asm.mixin.injection.At;
20-
import org.spongepowered.asm.mixin.injection.Redirect;
2125

2226
import java.util.List;
2327

2428
@Mixin(MinecraftServer.class)
2529
public 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
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
99

1010
@Mixin(RecipeBookWidget.class)
11-
public class RecipeBookWidgetMixin {
12-
@Inject(method = "initialize", at = @At("HEAD"))
13-
public void antiresourcereload_updateHasSeenRecipes(CallbackInfo ci) {
11+
public abstract class RecipeBookWidgetMixin {
12+
13+
@Inject(
14+
method = "initialize",
15+
at = @At("HEAD")
16+
)
17+
public void updateHasSeenRecipes(CallbackInfo ci) {
1418
AntiResourceReload.hasSeenRecipes = true;
1519
}
1620
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212

1313
@Mixin(RecipeManager.class)
1414
public interface RecipeManagerAccess {
15-
@Invoker void invokeApply(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler);
15+
@Invoker("apply")
16+
void antiresourcereload$apply(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler);
1617
}

0 commit comments

Comments
 (0)