Skip to content

Commit bb91b30

Browse files
authored
Merge pull request #11 from KingContaria/1.16.1
5.0+1.16.1
2 parents af0ab22 + a913953 commit bb91b30

11 files changed

Lines changed: 144 additions & 103 deletions

build.gradle

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,76 @@
11
plugins {
2-
alias libs.plugins.fabric.loom
3-
id "maven-publish"
2+
id 'fabric-loom' version '1.4-SNAPSHOT'
3+
id 'maven-publish'
44
}
55

6-
version = "$mod_version+$target_version"
7-
group = maven_group
8-
9-
base {
10-
archivesName = archives_name
11-
}
6+
archivesBaseName = project.mod_id
7+
version = "${project.mod_version}+${project.supported_versions}"
8+
group = project.maven_group
129

1310
repositories {
14-
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots" }
15-
maven { url "https://jitpack.io" }
16-
}
17-
18-
loom {
19-
decompilers {
20-
vineflower {
21-
options.putAll(["mark-corresponding-synthetics": "1", "ind": " "])
22-
}
23-
}
24-
mixin {
25-
useLegacyMixinAp = false
26-
}
11+
maven { url 'https://jitpack.io' }
2712
}
2813

2914
dependencies {
30-
minecraft libs.minecraft
31-
mappings variantOf(libs.yarn.mappings) { classifier "v2" }
32-
modImplementation libs.fabric.loader
33-
vineflowerDecompilerClasspath libs.vineflower
15+
// To change the versions see the gradle.properties file
16+
minecraft "com.mojang:minecraft:${project.minecraft_version}"
17+
mappings "dev.tildejustin:yarn:${project.yarn_mappings}:v2"
18+
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
3419
}
3520

3621
processResources {
37-
filesMatching "fabric.mod.json", {
38-
expand "version": version
22+
inputs.property "mod_id", project.mod_id
23+
inputs.property "version", project.version
24+
filteringCharset "UTF-8"
25+
26+
filesMatching("fabric.mod.json") {
27+
expand "mod_id": project.mod_id, "version": project.version
3928
}
4029
}
4130

4231
tasks.withType(JavaCompile).configureEach {
4332
it.options.encoding = "UTF-8"
44-
if (JavaVersion.current().isJava9Compatible()) it.options.release.set(8)
33+
34+
def targetVersion = 8
35+
if (JavaVersion.current().isJava9Compatible()) {
36+
it.options.release = targetVersion
37+
}
4538
}
4639

4740
java {
48-
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
41+
sourceCompatibility = JavaVersion.VERSION_1_8
42+
targetCompatibility = JavaVersion.VERSION_1_8
43+
44+
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
45+
// if it is present.
46+
// If you remove this line, sources will not be generated.
47+
withSourcesJar()
4948
}
5049

5150
jar {
52-
from "LICENSE"
51+
from("LICENSE") {
52+
rename { "${it}_${project.archivesBaseName}" }
53+
}
5354
}
5455

56+
// configure the maven publication
5557
publishing {
56-
publications.create("mavenJava", MavenPublication) {
57-
from components.java
58+
publications {
59+
mavenJava(MavenPublication) {
60+
artifact(remapJar) {
61+
builtBy remapJar
62+
}
63+
artifact(sourcesJar) {
64+
builtBy remapSourcesJar
65+
}
66+
}
67+
}
68+
69+
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
70+
repositories {
71+
// Add repositories to publish to here.
72+
// Notice: This block does NOT have the same function as the block in the top level.
73+
// The repositories here will be used for publishing your artifact, not for
74+
// retrieving dependencies.
5875
}
59-
repositories {}
6076
}

gradle.properties

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
org.gradle.jvmargs = -Xmx2G
2-
org.gradle.parallel = true
3-
org.gradle.caching = true
1+
# Done to increase the memory available to gradle.
2+
org.gradle.jvmargs=-Xmx2G
43

5-
mod_version = 4.0.1
6-
target_version = 1.16.1
7-
archives_name = antiresourcereload
8-
maven_group = me.wurgo
4+
# Fabric Properties
5+
# check these on https://fabricmc.net/develop
6+
minecraft_version=1.16.1
7+
yarn_mappings=1.16.1-build.24
8+
loader_version=0.15.0
9+
10+
# Mod Properties
11+
mod_version=5.0.0
12+
maven_group=me.wurgo
13+
archives_base_name=antiresourcereload
14+
15+
# MCSR
16+
mod_id=antiresourcereload
17+
supported_versions=1.16.1
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
4-
networkTimeout=10000
5-
validateDistributionUrl=true
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
64
zipStoreBase=GRADLE_USER_HOME
75
zipStorePath=wrapper/dists

jitpack.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
jdk:
2+
- openjdk17
3+
before_install:
4+
- sdk install java 17.0.1-open
5+
- sdk use java 17.0.1-open
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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.resource.ServerResourceManager;
75
import net.minecraft.util.Identifier;
86
import org.apache.logging.log4j.LogManager;
@@ -11,19 +9,14 @@
119
import java.util.Map;
1210
import java.util.concurrent.CompletableFuture;
1311

14-
public class AntiResourceReload implements ModInitializer {
15-
private static final Logger LOGGER = LogManager.getLogger(FabricLoader.getInstance().getModContainer("antiresourcereload").get().getMetadata().getName());
16-
17-
public static void log(String message) {
18-
LOGGER.info("[" + LOGGER.getName() + "] " + message);
19-
}
12+
public class AntiResourceReload {
13+
private static final Logger LOGGER = LogManager.getLogger();
2014

2115
public static CompletableFuture<ServerResourceManager> cache;
2216
public static Map<Identifier, JsonElement> recipes;
2317
public static boolean hasSeenRecipes;
2418

25-
@Override
26-
public void onInitialize() {
27-
log("Initializing.");
19+
public static void log(String message) {
20+
LOGGER.info("[AntiResourceReload] " + message);
2821
}
2922
}
Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,85 @@
11
package me.wurgo.antiresourcereload.mixin;
22

3+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
4+
import com.llamalad7.mixinextras.injector.WrapWithCondition;
5+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
6+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
7+
import com.llamalad7.mixinextras.sugar.Local;
38
import me.wurgo.antiresourcereload.AntiResourceReload;
49
import net.minecraft.client.MinecraftClient;
5-
import net.minecraft.resource.ResourcePack;
6-
import net.minecraft.resource.ServerResourceManager;
10+
import net.minecraft.resource.*;
711
import net.minecraft.server.command.CommandManager;
8-
import org.spongepowered.asm.mixin.*;
12+
import net.minecraft.tag.BlockTags;
13+
import net.minecraft.tag.EntityTypeTags;
14+
import net.minecraft.tag.FluidTags;
15+
import net.minecraft.tag.ItemTags;
16+
import org.spongepowered.asm.mixin.Mixin;
917
import org.spongepowered.asm.mixin.injection.At;
10-
import org.spongepowered.asm.mixin.injection.Redirect;
1118

1219
import java.util.List;
1320
import java.util.concurrent.CompletableFuture;
1421
import java.util.concurrent.ExecutionException;
1522
import java.util.concurrent.Executor;
23+
import java.util.stream.Collectors;
1624

1725
@Mixin(MinecraftClient.class)
18-
public class MinecraftClientMixin {
19-
@Unique
20-
private boolean hasLoadedTags;
26+
public abstract class MinecraftClientMixin {
2127

22-
@Redirect(
28+
@WrapOperation(
2329
method = "createIntegratedResourceManager",
2430
at = @At(
2531
value = "INVOKE",
2632
target = "Lnet/minecraft/resource/ServerResourceManager;reload(Ljava/util/List;Lnet/minecraft/server/command/CommandManager$RegistrationEnvironment;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"
2733
)
2834
)
29-
private CompletableFuture<ServerResourceManager> antiresourcereload_cachedReload(List<ResourcePack> dataPacks, CommandManager.RegistrationEnvironment registrationEnvironment, int i, Executor executor, Executor executor2) throws ExecutionException, InterruptedException {
30-
if (dataPacks.size() != 1) { AntiResourceReload.log("Using data-packs, reloading."); }
31-
else if (AntiResourceReload.cache == null) { AntiResourceReload.log("Cached resources unavailable, reloading & caching."); }
32-
else {
35+
private CompletableFuture<ServerResourceManager> cachedReload(List<ResourcePack> dataPacks, CommandManager.RegistrationEnvironment registrationEnvironment, int i, Executor executor, Executor executor2, Operation<CompletableFuture<ServerResourceManager>> original, @Local ResourcePackManager<ResourcePackProfile> resourcePackManager) {
36+
boolean usingDataPacks = !resourcePackManager.getEnabledProfiles().stream().map(ResourcePackProfile::getName).collect(Collectors.toList()).equals(DataPackSettings.SAFE_MODE.getEnabled());
37+
if (usingDataPacks) {
38+
AntiResourceReload.log("Using data-packs, reloading.");
39+
} else if (AntiResourceReload.cache == null) {
40+
AntiResourceReload.log("Cached resources unavailable, reloading & caching.");
41+
} else {
3342
AntiResourceReload.log("Using cached server resources.");
34-
if (AntiResourceReload.hasSeenRecipes) {
35-
((RecipeManagerAccess) AntiResourceReload.cache.get().getRecipeManager()).invokeApply(AntiResourceReload.recipes, null, null);
36-
}
37-
AntiResourceReload.hasSeenRecipes = false;
3843
return AntiResourceReload.cache;
3944
}
4045

41-
CompletableFuture<ServerResourceManager> reloaded = ServerResourceManager.reload(dataPacks, registrationEnvironment, i, executor, executor2);
46+
CompletableFuture<ServerResourceManager> reloaded = original.call(dataPacks, registrationEnvironment, i, executor, executor2);
4247

43-
if (dataPacks.size() == 1) { AntiResourceReload.cache = reloaded; }
44-
48+
if (!usingDataPacks) {
49+
AntiResourceReload.cache = reloaded;
50+
}
4551
return reloaded;
4652
}
4753

48-
@Redirect(
54+
@ModifyExpressionValue(
4955
method = "startIntegratedServer(Ljava/lang/String;Lnet/minecraft/util/registry/RegistryTracker$Modifiable;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/client/MinecraftClient$WorldLoadAction;)V",
5056
at = @At(
5157
value = "INVOKE",
52-
target = "Lnet/minecraft/resource/ServerResourceManager;loadRegistryTags()V"
58+
target = "Lnet/minecraft/client/MinecraftClient;createIntegratedResourceManager(Lnet/minecraft/util/registry/RegistryTracker$Modifiable;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/world/level/storage/LevelStorage$Session;)Lnet/minecraft/client/MinecraftClient$IntegratedResourceManager;"
5359
)
5460
)
55-
private void antiresourcereload_skipLoad(ServerResourceManager manager) throws ExecutionException, InterruptedException {
56-
if (AntiResourceReload.cache != null && manager == AntiResourceReload.cache.get()) {
57-
if (hasLoadedTags) return;
58-
hasLoadedTags = true;
61+
private MinecraftClient.IntegratedResourceManager reloadRecipes(MinecraftClient.IntegratedResourceManager integratedResourceManager) throws ExecutionException, InterruptedException {
62+
ServerResourceManager manager;
63+
// only reload recipes on the main thread
64+
// this is for compat with seedqueue creating servers in the background
65+
if (MinecraftClient.getInstance().isOnThread() && AntiResourceReload.hasSeenRecipes && AntiResourceReload.cache != null && (manager = AntiResourceReload.cache.get()) == integratedResourceManager.getServerResourceManager()) {
66+
((RecipeManagerAccess) manager.getRecipeManager()).invokeApply(AntiResourceReload.recipes, manager.getResourceManager(), MinecraftClient.getInstance().getProfiler());
67+
AntiResourceReload.hasSeenRecipes = false;
5968
}
60-
manager.loadRegistryTags();
69+
return integratedResourceManager;
70+
}
71+
72+
@WrapWithCondition(
73+
method = "startIntegratedServer(Ljava/lang/String;Lnet/minecraft/util/registry/RegistryTracker$Modifiable;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/client/MinecraftClient$WorldLoadAction;)V",
74+
at = @At(
75+
value = "INVOKE",
76+
target = "Lnet/minecraft/resource/ServerResourceManager;loadRegistryTags()V"
77+
)
78+
)
79+
private boolean skipReloadingRegistryTags(ServerResourceManager manager) {
80+
return manager.getRegistryTagManager().blocks() != BlockTags.getContainer() ||
81+
manager.getRegistryTagManager().items() != ItemTags.getContainer() ||
82+
manager.getRegistryTagManager().fluids() != FluidTags.getContainer() ||
83+
manager.getRegistryTagManager().entityTypes() != EntityTypeTags.getContainer();
6184
}
6285
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
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+
@Inject(
13+
method = "initialize",
14+
at = @At("HEAD")
15+
)
16+
private void updateHasSeenRecipes(CallbackInfo ci) {
1417
AntiResourceReload.hasSeenRecipes = true;
1518
}
1619
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
import java.util.Map;
1515

1616
@Mixin(RecipeManager.class)
17-
public class RecipeManagerMixin {
17+
public abstract class RecipeManagerMixin {
1818
@Inject(
1919
method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V",
2020
at = @At("HEAD")
2121
)
22-
private void antiresourcereload_setRecipes(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci) {
22+
private void setRecipes(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci) {
2323
if (AntiResourceReload.cache != null && !AntiResourceReload.cache.isDone()) {
2424
AntiResourceReload.recipes = map;
2525
}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
package me.wurgo.antiresourcereload.mixin;
22

33
import me.wurgo.antiresourcereload.AntiResourceReload;
4-
import net.minecraft.resource.ReloadableResourceManager;
54
import net.minecraft.resource.ServerResourceManager;
65
import org.spongepowered.asm.mixin.Mixin;
76
import org.spongepowered.asm.mixin.injection.At;
8-
import org.spongepowered.asm.mixin.injection.Redirect;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
99

1010
import java.util.concurrent.ExecutionException;
1111

1212
@Mixin(ServerResourceManager.class)
1313
public abstract class ServerResourceManagerMixin {
14-
@Redirect(
14+
@Inject(
1515
method = "close",
16-
at = @At(
17-
value = "INVOKE",
18-
target = "Lnet/minecraft/resource/ReloadableResourceManager;close()V"
19-
)
16+
at = @At("HEAD"),
17+
cancellable = true
2018
)
21-
private void antiresourcereload_keepOpened(ReloadableResourceManager instance) throws ExecutionException, InterruptedException {
19+
private void keepCachedResourcesOpen(CallbackInfo ci) throws ExecutionException, InterruptedException {
2220
// noinspection ConstantConditions - I think mixin is confusing for intellij here
23-
if (AntiResourceReload.cache == null || (Object) this != AntiResourceReload.cache.get()) {
24-
instance.close();
21+
if (AntiResourceReload.cache != null && (Object) this == AntiResourceReload.cache.get()) {
22+
ci.cancel();
2523
}
2624
}
2725
}

src/main/resources/antiresourcereload.mixins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"minVersion": "0.8",
44
"package": "me.wurgo.antiresourcereload.mixin",
55
"compatibilityLevel": "JAVA_8",
6-
"mixins": [
6+
"client": [
77
"MinecraftClientMixin",
88
"ServerResourceManagerMixin",
99
"RecipeManagerAccess",

0 commit comments

Comments
 (0)