Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx2G
org.gradle.parallel = true
org.gradle.caching = true

mod_version = 4.0.3
mod_version = 5.2.0
target_version = 1.15.2
archives_name = antiresourcereload
maven_group = me.wurgo
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[versions]
minecraft = "1.15.2"
yarn_mappings = "1.15.2+build.17"
fabric_loader = "0.15.7"
loom = "1.5-SNAPSHOT"
fabric_loader = "0.16.10"
loom = "1.9-SNAPSHOT"
vineflower = "1.10.0-SNAPSHOT"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package me.wurgo.antiresourcereload;

import com.google.gson.JsonElement;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.loot.LootManager;
import net.minecraft.loot.condition.LootConditionManager;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.resource.ReloadableResourceManager;
import net.minecraft.server.ServerAdvancementLoader;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.function.CommandFunctionManager;
import net.minecraft.structure.Structure;
import net.minecraft.tag.RegistryTagManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.UserCache;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class AntiResourceReload implements ModInitializer {
private static final Logger LOGGER = LogManager.getLogger(FabricLoader.getInstance().getModContainer("antiresourcereload").get().getMetadata().getName());
public class AntiResourceReload {
private static final Logger LOGGER = LogManager.getLogger();

public static ReloadableResourceManager dataManager;
public static RecipeManager recipeManager;
Expand All @@ -27,14 +30,17 @@ public class AntiResourceReload implements ModInitializer {
public static ServerAdvancementLoader advancementLoader;
public static CommandFunctionManager commandFunctionManager;
public static Map<Identifier, JsonElement> recipes;

public static CommandManager commandManager;

public static final Map<Identifier, Structure> structures = Collections.synchronizedMap(new HashMap<>());

public static UserCache userCache;

public static boolean hasInitializedShapeCache;
public static boolean hasSeenRecipes;

public static void log(String message) {
LOGGER.info("[" + LOGGER.getName() + "] " + message);
}

@Override
public void onInitialize() {
log("Initializing.");
public static void log(String message) {
LOGGER.info("[AntiResourceReload] {}", message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package me.wurgo.antiresourcereload.mixin;

import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import net.minecraft.resource.DefaultResourcePack;
import net.minecraft.resource.metadata.PackResourceMetadata;
import net.minecraft.resource.metadata.ResourceMetadataReader;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

@Mixin(DefaultResourcePack.class)
public abstract class DefaultResourcePackMixin {
@Nullable
@Unique
private static PackResourceMetadata METADATA;

@WrapMethod(method = "parseMetadata")
private Object cacheMetadata(ResourceMetadataReader<?> reader, Operation<?> original) {
if (reader != PackResourceMetadata.READER) {
return original.call(reader);
}
if (METADATA == null) {
METADATA = (PackResourceMetadata) original.call(reader);
}
return METADATA;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.wurgo.antiresourcereload.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import me.wurgo.antiresourcereload.AntiResourceReload;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.integrated.IntegratedServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(IntegratedServer.class)
public abstract class IntegratedServerMixin {

@WrapOperation(
method = "<init>",
at = @At(
value = "NEW",
target = "(Z)Lnet/minecraft/server/command/CommandManager;"
)
)
private static CommandManager cacheCommandManager(boolean isDedicatedServer, Operation<CommandManager> original) {
if (AntiResourceReload.commandManager == null) {
AntiResourceReload.commandManager = original.call(isDedicatedServer);
}
return AntiResourceReload.commandManager;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package me.wurgo.antiresourcereload.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.authlib.GameProfileRepository;
import me.wurgo.antiresourcereload.AntiResourceReload;
import net.minecraft.client.MinecraftClient;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.util.UserCache;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.io.File;

@Mixin(MinecraftClient.class)
public abstract class MinecraftClientMixin {

@Shadow
@Nullable
private IntegratedServer server;

@Inject(
method = "startIntegratedServer",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/ClientConnection;connectLocal(Ljava/net/SocketAddress;)Lnet/minecraft/network/ClientConnection;"
)
)
private void reloadRecipes(CallbackInfo ci) {
// reloading is done when actually joining the world instead of on world creation because of SeedQueue
if (this.server != null && this.server.getRecipeManager() == AntiResourceReload.recipeManager && AntiResourceReload.hasSeenRecipes) {
((RecipeManagerAccess) AntiResourceReload.recipeManager).antiresourcereload$apply(AntiResourceReload.recipes, null, null);
AntiResourceReload.hasSeenRecipes = false;
}
}

@WrapOperation(
method = {
"startIntegratedServer",
"joinWorld"
},
at = @At(
value = "NEW",
target = "(Lcom/mojang/authlib/GameProfileRepository;Ljava/io/File;)Lnet/minecraft/util/UserCache;"
),
require = 2
)
private UserCache cacheUserCache(GameProfileRepository profileRepository, File cacheFile, Operation<UserCache> original) {
if (AntiResourceReload.userCache == null) {
AntiResourceReload.userCache = original.call(profileRepository, cacheFile);
}
return AntiResourceReload.userCache;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package me.wurgo.antiresourcereload.mixin;

import com.google.common.collect.Lists;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import me.wurgo.antiresourcereload.AntiResourceReload;
import net.minecraft.loot.LootManager;
import net.minecraft.loot.condition.LootConditionManager;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.resource.*;
import net.minecraft.resource.ReloadableResourceManager;
import net.minecraft.resource.ResourcePackManager;
import net.minecraft.resource.ResourcePackProfile;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerAdvancementLoader;
import net.minecraft.server.function.CommandFunctionManager;
Expand All @@ -17,42 +22,66 @@
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.List;

@Mixin(MinecraftServer.class)
public abstract class MinecraftServerMixin {
@Shadow protected abstract void reloadDataPacks(LevelProperties levelProperties);
@Mutable @Shadow @Final private ReloadableResourceManager dataManager;
@Mutable @Shadow @Final private RegistryTagManager tagManager;
@Mutable @Shadow @Final private LootConditionManager predicateManager;
@Mutable @Shadow @Final private RecipeManager recipeManager;
@Mutable @Shadow @Final private LootManager lootManager;
@Mutable @Shadow @Final private CommandFunctionManager commandFunctionManager;
@Mutable @Shadow @Final private ServerAdvancementLoader advancementLoader;
@Shadow
@Final
private static Logger LOGGER;

@Shadow @Final private static Logger LOGGER;
@Shadow @Final private ResourcePackManager<ResourcePackProfile> dataPackManager;
@Shadow
@Final
private ResourcePackManager<ResourcePackProfile> dataPackManager;

@Redirect(
@Mutable
@Shadow
@Final
private ReloadableResourceManager dataManager;
@Mutable
@Shadow
@Final
private RegistryTagManager tagManager;
@Mutable
@Shadow
@Final
private LootConditionManager predicateManager;
@Mutable
@Shadow
@Final
private RecipeManager recipeManager;
@Mutable
@Shadow
@Final
private LootManager lootManager;
@Mutable
@Shadow
@Final
private CommandFunctionManager commandFunctionManager;
@Mutable
@Shadow
@Final
private ServerAdvancementLoader advancementLoader;

@WrapOperation(
method = "loadWorldDataPacks",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/MinecraftServer;reloadDataPacks(Lnet/minecraft/world/level/LevelProperties;)V"
)
)
private void antiresourcereload_cachedReload(MinecraftServer instance, LevelProperties levelProperties) {
if (levelProperties.getEnabledDataPacks().size() + levelProperties.getDisabledDataPacks().size() != 0) {
private void cachedReload(MinecraftServer server, LevelProperties properties, Operation<Void> original) {
if (!properties.getEnabledDataPacks().isEmpty() || !properties.getDisabledDataPacks().isEmpty()) {
AntiResourceReload.log("Using data-packs, reloading.");
this.reloadDataPacks(levelProperties);
original.call(server, properties);
return;
}

if (AntiResourceReload.dataManager == null) {
AntiResourceReload.log("Cached resources unavailable, reloading & caching.");
AntiResourceReload.dataManager = this.dataManager;
this.reloadDataPacks(levelProperties);
original.call(server, properties);
AntiResourceReload.tagManager = this.tagManager;
AntiResourceReload.predicateManager = this.predicateManager;
AntiResourceReload.recipeManager = this.recipeManager;
Expand All @@ -68,21 +97,33 @@ private void antiresourcereload_cachedReload(MinecraftServer instance, LevelProp
this.lootManager = AntiResourceReload.lootManager;
this.commandFunctionManager = AntiResourceReload.commandFunctionManager;
this.advancementLoader = AntiResourceReload.advancementLoader;
if (AntiResourceReload.hasSeenRecipes) {
((RecipeManagerAccess) this.recipeManager).invokeApply(AntiResourceReload.recipes, null, null);
}

// should only be the vanilla pack
// logic taken from MinecraftServer#reloadDataPacks
List<ResourcePackProfile> list = Lists.newArrayList(this.dataPackManager.getEnabledProfiles());

for (ResourcePackProfile resourcePackProfile : this.dataPackManager.getProfiles()) {
if (!levelProperties.getDisabledDataPacks().contains(resourcePackProfile.getName()) && !list.contains(resourcePackProfile)) {
if (!properties.getDisabledDataPacks().contains(resourcePackProfile.getName()) && !list.contains(resourcePackProfile)) {
LOGGER.info("Found new data pack {}, loading it automatically", resourcePackProfile.getName());
resourcePackProfile.getInitialPosition().insert(list, resourcePackProfile, profile -> profile, false);
}
}
this.dataPackManager.setEnabledProfiles(list);
}
}

@WrapWithCondition(
method = "loadWorldDataPacks",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/MinecraftServer;method_24154()V"
)
)
private boolean skipInitializingShapeCache(MinecraftServer server) {
if (!AntiResourceReload.hasInitializedShapeCache) {
AntiResourceReload.hasInitializedShapeCache = true;
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(RecipeBookWidget.class)
public class RecipeBookWidgetMixin {
@Inject(method = "initialize", at = @At("HEAD"))
public void antiresourcereload_updateHasSeenRecipes(CallbackInfo ci) {
public abstract class RecipeBookWidgetMixin {

@Inject(
method = "initialize",
at = @At("HEAD")
)
public void updateHasSeenRecipes(CallbackInfo ci) {
AntiResourceReload.hasSeenRecipes = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@

@Mixin(RecipeManager.class)
public interface RecipeManagerAccess {
@Invoker void invokeApply(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler);
@Invoker("apply")
void antiresourcereload$apply(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import java.util.Map;

@Mixin(RecipeManager.class)
public class RecipeManagerMixin {
public abstract class RecipeManagerMixin {

@Inject(
method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V",
at = @At("HEAD")
)
private void antiresourcereload_setRecipes(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci) {
private void setRecipes(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci) {
if (AntiResourceReload.dataManager != null && AntiResourceReload.recipeManager == null) {
AntiResourceReload.recipes = map;
}
Expand Down
Loading