Skip to content

Commit 1441934

Browse files
Merge pull request #2 from MalTeeez/master
Add patcher to disable specific mixins in Hodgepodge
2 parents e869687 + 62dd11a commit 1441934

File tree

4 files changed

+76
-12
lines changed

4 files changed

+76
-12
lines changed

dependencies.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
dependencies {
3535
// Hard deps begin
36-
api("com.github.GTNewHorizons:GTNHLib:0.6.39:dev")
36+
api("com.github.GTNewHorizons:GTNHLib:0.8.8:dev")
3737
// Hard deps end
3838

3939
// Indev stuff; only uncomment outside main!
@@ -53,7 +53,9 @@ dependencies {
5353
//implementation("maven.modrinth:archaicfix:0.7.7:dev")
5454

5555
// Compat begin
56-
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.78")
56+
devOnlyNonPublishable("com.github.GTNewHorizons:Hodgepodge:2.7.17")
57+
compileOnly("com.github.GTNewHorizons:Angelica:1.0.0-beta71-pre")
58+
5759
compileOnly("com.falsepattern:chunkapi-mc1.7.10:0.7.0")
5860
compileOnly("com.falsepattern:endlessids-mc1.7.10:1.6.12")
5961

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.gamma.spool.compat.hodgepodge;
2+
3+
import java.lang.reflect.Field;
4+
5+
import com.gtnewhorizon.gtnhmixins.builders.ITargetMod;
6+
import com.gtnewhorizon.gtnhmixins.builders.MixinBuilder;
7+
import com.gtnewhorizon.gtnhmixins.builders.TargetModBuilder;
8+
9+
public class MixinReflectionPatcher {
10+
11+
private static Class<?> mixinsClass;
12+
13+
public static void init() {
14+
try {
15+
Class.forName("com.mitchej123.hodgepodge.core.HodgepodgeCore");
16+
} catch (ClassNotFoundException ignored) {
17+
return;
18+
}
19+
try {
20+
initialize();
21+
applyPatches();
22+
} catch (Exception e) {
23+
System.out
24+
.println("Failed to patch hodgepodge mixins, will probably fail if config settings arent disabled.");
25+
}
26+
}
27+
28+
private static void initialize() throws Exception {
29+
ClassLoader loader = MixinReflectionPatcher.class.getClassLoader();
30+
// Initialize the Mixins enum (creates all constants)
31+
mixinsClass = Class.forName("com.mitchej123.hodgepodge.mixins.Mixins", true, loader);
32+
}
33+
34+
private static void applyPatches() throws Exception {
35+
// Create this mod as a ITargetMod via the TargetModBuilder from gtnhmixins
36+
TargetModBuilder targetedMod = new TargetModBuilder().setCoreModClass("com.gamma.spool.core.SpoolCoreMod")
37+
.setModId("spool");
38+
39+
addExcludedMod("TILE_ENTITY_RENDERER_PROFILER", targetedMod);
40+
addExcludedMod("ADD_SIMULATION_DISTANCE_OPTION", targetedMod);
41+
addExcludedMod("ADD_SIMULATION_DISTANCE_OPTION_THERMOS_FIX", targetedMod);
42+
addExcludedMod("OPTIMIZE_TILEENTITY_REMOVAL", targetedMod);
43+
addExcludedMod("SPEEDUP_NBT_COPY", targetedMod);
44+
}
45+
46+
@SuppressWarnings("unchecked")
47+
private static void addExcludedMod(String mixinName, Object targetedMod) throws Exception {
48+
// Get the enum entry for this mixin target
49+
Object mixin = Enum.valueOf((Class<Enum>) mixinsClass, mixinName);
50+
51+
// Allow accessing the builder field for the enum entries
52+
Field builderField = mixinsClass.getDeclaredField("builder");
53+
builderField.setAccessible(true);
54+
Object builder = builderField.get(mixin);
55+
56+
// Just use the existing MixinBuilder for the entry from <clinit> and modify the excludedMods in AbstractBuilder
57+
// via the usual method.
58+
// In this case we do not care about the return value (the same reference for chaining)
59+
((MixinBuilder) builder).addExcludedMod((ITargetMod) targetedMod);
60+
}
61+
}

src/main/java/com/gamma/spool/core/SpoolCoreMod.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import net.bytebuddy.agent.ByteBuddyAgent;
88

9+
import com.gamma.spool.compat.hodgepodge.MixinReflectionPatcher;
910
import com.gamma.spool.config.APIConfig;
1011
import com.gamma.spool.config.ConcurrentConfig;
1112
import com.gamma.spool.config.DebugConfig;
@@ -53,6 +54,8 @@ public static long getRecursiveObjectSize(Object o) {
5354

5455
static {
5556
try {
57+
MixinReflectionPatcher.init();
58+
5659
ConfigurationManager.registerConfig(DebugConfig.class);
5760

5861
SpoolCompat.earlyInitialization();

src/main/java/com/gamma/spool/unusedTemp/SimulationDistanceHelper.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import net.minecraftforge.common.ForgeChunkManager;
1818

1919
import com.gamma.spool.core.SpoolCompat;
20-
import com.mitchej123.hodgepodge.Compat;
21-
import com.mitchej123.hodgepodge.CoreTweaksCompat;
2220
import com.mitchej123.hodgepodge.config.FixesConfig;
2321
import com.mitchej123.hodgepodge.config.TweaksConfig;
2422
import com.mitchej123.hodgepodge.util.ChunkPosUtil;
@@ -41,15 +39,15 @@ public class SimulationDistanceHelper {
4139
* Mark a chunk as no to be simulated, or reset that state. Not thread safe!
4240
*/
4341
public static void preventChunkSimulation(World world, long packedChunkPos, boolean prevent) {
44-
if (!SpoolCompat.isModLoaded("hodgepodge") || !FixesConfig.addSimulationDistance) {
42+
if (!SpoolCompat.isModLoaded("hodgepodge") || !FixesConfig.addSimulationDistance_WIP) {
4543
return;
4644
}
4745
ISimulationDistanceWorld mixin = (ISimulationDistanceWorld) world;
4846
mixin.hodgepodge$preventChunkSimulation(packedChunkPos, prevent);
4947
}
5048

5149
public static int getSimulationDistance() {
52-
if (SpoolCompat.isModLoaded("hodgepodge") && FixesConfig.addSimulationDistance)
50+
if (SpoolCompat.isModLoaded("hodgepodge") && FixesConfig.addSimulationDistance_WIP)
5351
return TweaksConfig.simulationDistance;
5452
else return 0;
5553
}
@@ -307,9 +305,9 @@ public void chunkUnloaded(long chunk) {
307305
chunkTickMap.remove(chunk);
308306
for (NextTickListEntry entry : entries) {
309307
pendingTickListEntriesHashSet.remove(entry);
310-
if (Compat.isCoreTweaksPresent()) {
311-
CoreTweaksCompat.removeTickEntry(world, entry);
312-
}
308+
// if (Compat.isCoreTweaksPresent()) {
309+
// CoreTweaksCompat.removeTickEntry(world, entry);
310+
// }
313311
/*
314312
* Entries would get removed in tickUpdates eventually, but we risk reloading a chunk and having an
315313
* incompatible, similar entry in pendingTickListEntriesTreeSet/pendingTickListEntriesHashSet that can be
@@ -329,9 +327,9 @@ protected void removeTick(NextTickListEntry entry) {
329327
}
330328

331329
pendingTickListEntriesHashSet.remove(entry);
332-
if (Compat.isCoreTweaksPresent()) {
333-
CoreTweaksCompat.removeTickEntry(world, entry);
334-
}
330+
// if (Compat.isCoreTweaksPresent()) {
331+
// CoreTweaksCompat.removeTickEntry(world, entry);
332+
// }
335333
long key = ChunkCoordIntPair.chunkXZ2Int(entry.xCoord >> 4, entry.zCoord >> 4);
336334
HashSet<NextTickListEntry> entries = chunkTickMap.get(key);
337335
if (entries != null) {

0 commit comments

Comments
 (0)