Skip to content

Commit 98b9070

Browse files
authored
Convert to new IMixins and MixinsBuilder system (#13)
1 parent 8281149 commit 98b9070

30 files changed

+172
-357
lines changed

dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ dependencies {
55
transitive = false
66
}
77
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") { transitive = false }
8-
api("com.github.GTNewHorizons:NotEnoughItems:2.7.57-GTNH:dev")
8+
api("com.github.GTNewHorizons:NotEnoughItems:2.7.64-GTNH:dev")
99
}

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ separateMixinSourceSet =
9494
usesMixinDebug = true
9595

9696
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
97-
mixinPlugin = Mixins.RTMixinPlugin
97+
mixinPlugin =
9898

9999
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
100-
mixinsPackage = Mixins.Minecraft
100+
mixinsPackage = Mixins
101101

102102
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
103103
# This parameter is for legacy compatibility only
104104
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
105-
coreModClass =
105+
coreModClass = Mixins.RandomThingsLoadingPluing
106106

107107
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
108108
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
@@ -151,7 +151,7 @@ modrinthProjectId =
151151
# type can be one of [project, version],
152152
# and the name is the Modrinth project or version slug/id of the other mod.
153153
# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech
154-
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
154+
# Note: UniMixins is automatically set as a required dependency if usesMixins = true.
155155
modrinthRelations =
156156

157157
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pluginManagement {
1717
}
1818

1919
plugins {
20-
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.38'
20+
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.41'
2121
}
2222

2323

src/main/java/lumien/randomthings/Handler/BackgroundHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import lumien.randomthings.Configuration.Settings;
1010
import lumien.randomthings.Configuration.VanillaChanges;
11-
import lumien.randomthings.Mixins.Minecraft.GuiAccessor;
11+
import lumien.randomthings.Mixins.early.GuiAccessor;
1212

1313
public class BackgroundHandler {
1414

src/main/java/lumien/randomthings/Handler/Bloodmoon/ServerBloodmoonHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import net.minecraft.world.WorldServer;
1515

1616
import lumien.randomthings.Configuration.Settings;
17-
import lumien.randomthings.Mixins.Minecraft.WorldAccessor;
18-
import lumien.randomthings.Mixins.Minecraft.WorldServerAccessor;
1917
import lumien.randomthings.Mixins.ducks.SpawnerAnimalsExt;
18+
import lumien.randomthings.Mixins.early.WorldAccessor;
19+
import lumien.randomthings.Mixins.early.WorldServerAccessor;
2020
import lumien.randomthings.Network.Messages.MessageBloodmoon;
2121
import lumien.randomthings.Network.PacketHandler;
2222

src/main/java/lumien/randomthings/Handler/RTEventHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484
import lumien.randomthings.Library.DimensionCoordinate;
8585
import lumien.randomthings.Library.PotionEffects;
8686
import lumien.randomthings.Library.RandomThingsNBTKeys;
87-
import lumien.randomthings.Mixins.Minecraft.EntityAccessor;
88-
import lumien.randomthings.Mixins.Minecraft.EntityLivingAccessor;
87+
import lumien.randomthings.Mixins.early.EntityAccessor;
88+
import lumien.randomthings.Mixins.early.EntityLivingAccessor;
8989
import lumien.randomthings.Potions.ModPotions;
9090
import lumien.randomthings.RandomThings;
9191

src/main/java/lumien/randomthings/Handler/Spectre/SpectreHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import lumien.randomthings.Library.PotionEffects;
2525
import lumien.randomthings.Library.RandomThingsNBTKeys;
2626
import lumien.randomthings.Library.WorldUtils;
27-
import lumien.randomthings.Mixins.Minecraft.EntityAccessor;
27+
import lumien.randomthings.Mixins.early.EntityAccessor;
2828
import lumien.randomthings.Network.Messages.MessageSpectreData;
2929
import lumien.randomthings.Network.PacketHandler;
3030
import lumien.randomthings.RandomThings;

src/main/java/lumien/randomthings/Mixins/Mixin.java

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 55 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -1,188 +1,63 @@
11
package lumien.randomthings.Mixins;
22

3-
import java.util.ArrayList;
4-
import java.util.Arrays;
5-
import java.util.Collections;
6-
import java.util.List;
7-
import java.util.Set;
8-
import java.util.function.Supplier;
3+
import javax.annotation.Nonnull;
94

10-
import org.apache.logging.log4j.LogManager;
11-
import org.apache.logging.log4j.Logger;
5+
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
6+
import com.gtnewhorizon.gtnhmixins.builders.MixinBuilder;
127

13-
import cpw.mods.fml.relauncher.FMLLaunchHandler;
8+
import lumien.randomthings.Configuration.ConfigBlocks;
149
import lumien.randomthings.Configuration.VanillaChanges;
1510

16-
public enum Mixins {
17-
18-
BLOCK_MAGICAL_LEAVES(new Builder("Thaumcraft Fast Leaf Decay").setSide(Side.BOTH)
19-
.addTargetedMod(TargetedMod.THAUMCRAFT).setPhase(Phase.LATE)
20-
.setApplyIf(() -> VanillaChanges.FASTER_LEAVEDECAY).addMixinClasses("MixinBlockMagicalLeaves"));
21-
22-
private final List<String> mixinClasses;
23-
private final List<TargetedMod> targetedMods;
24-
private final List<TargetedMod> excludedMods;
25-
private final Supplier<Boolean> applyIf;
26-
private final Phase phase;
27-
private final Side side;
28-
public static final Logger LOGGER = LogManager.getLogger("RandomThings");
29-
30-
Mixins(Builder builder) {
31-
this.mixinClasses = builder.mixinClasses;
32-
this.targetedMods = builder.targetedMods;
33-
this.excludedMods = builder.excludedMods;
34-
this.applyIf = builder.applyIf;
35-
this.phase = builder.phase;
36-
this.side = builder.side;
37-
if (this.mixinClasses.isEmpty()) {
38-
throw new RuntimeException("No mixin class specified for Mixin : " + this.name());
39-
}
40-
if (this.targetedMods.isEmpty()) {
41-
throw new RuntimeException("No targeted mods specified for Mixin : " + this.name());
42-
}
43-
if (this.applyIf == null) {
44-
throw new RuntimeException("No ApplyIf function specified for Mixin : " + this.name());
45-
}
46-
if (this.phase == null) {
47-
throw new RuntimeException("No Phase specified for Mixin : " + this.name());
48-
}
49-
if (this.side == null) {
50-
throw new RuntimeException("No Side function specified for Mixin : " + this.name());
51-
}
52-
}
53-
54-
public static List<String> getEarlyMixins(Set<String> loadedCoreMods) {
55-
final List<String> mixins = new ArrayList<>();
56-
final List<String> notLoading = new ArrayList<>();
57-
for (Mixins mixin : Mixins.values()) {
58-
if (mixin.phase == Phase.EARLY) {
59-
if (mixin.shouldLoad(loadedCoreMods, Collections.emptySet())) {
60-
mixins.addAll(mixin.mixinClasses);
61-
} else {
62-
notLoading.addAll(mixin.mixinClasses);
63-
}
64-
}
65-
}
66-
LOGGER.info("Not loading the following EARLY mixins: {}", notLoading.toString());
67-
return mixins;
68-
}
69-
70-
public static List<String> getLateMixins(Set<String> loadedMods) {
71-
final List<String> mixins = new ArrayList<>();
72-
final List<String> notLoading = new ArrayList<>();
73-
for (Mixins mixin : Mixins.values()) {
74-
if (mixin.phase == Phase.LATE) {
75-
if (mixin.shouldLoad(Collections.emptySet(), loadedMods)) {
76-
mixins.addAll(mixin.mixinClasses);
77-
} else {
78-
notLoading.addAll(mixin.mixinClasses);
79-
}
80-
}
81-
}
82-
LOGGER.info("Not loading the following LATE mixins: {}", notLoading.toString());
83-
return mixins;
84-
}
85-
86-
private boolean shouldLoadSide() {
87-
return side == Side.BOTH || (side == Side.SERVER && FMLLaunchHandler.side().isServer())
88-
|| (side == Side.CLIENT && FMLLaunchHandler.side().isClient());
89-
}
90-
91-
private boolean allModsLoaded(List<TargetedMod> targetedMods, Set<String> loadedCoreMods, Set<String> loadedMods) {
92-
if (targetedMods.isEmpty()) return false;
93-
94-
for (TargetedMod target : targetedMods) {
95-
if (target == TargetedMod.VANILLA) continue;
96-
97-
if (!loadedCoreMods.isEmpty() && target.coreModClass != null
98-
&& !loadedCoreMods.contains(target.coreModClass))
99-
return false;
100-
else if (!loadedMods.isEmpty() && target.modId != null && !loadedMods.contains(target.modId)) return false;
101-
}
102-
103-
return true;
104-
}
105-
106-
private boolean noModsLoaded(List<TargetedMod> targetedMods, Set<String> loadedCoreMods, Set<String> loadedMods) {
107-
if (targetedMods.isEmpty()) return true;
108-
109-
for (TargetedMod target : targetedMods) {
110-
if (target == TargetedMod.VANILLA) continue;
111-
112-
if (!loadedCoreMods.isEmpty() && target.coreModClass != null
113-
&& loadedCoreMods.contains(target.coreModClass))
114-
return false;
115-
else if (!loadedMods.isEmpty() && target.modId != null && loadedMods.contains(target.modId)) return false;
116-
}
117-
118-
return true;
119-
}
120-
121-
private boolean shouldLoad(Set<String> loadedCoreMods, Set<String> loadedMods) {
122-
return (shouldLoadSide() && applyIf.get()
123-
&& allModsLoaded(targetedMods, loadedCoreMods, loadedMods)
124-
&& noModsLoaded(excludedMods, loadedCoreMods, loadedMods));
125-
}
126-
127-
private static class Builder {
128-
129-
private final String name;
130-
private final List<String> mixinClasses = new ArrayList<>();
131-
private final List<TargetedMod> targetedMods = new ArrayList<>();
132-
private final List<TargetedMod> excludedMods = new ArrayList<>();
133-
private Supplier<Boolean> applyIf = null;
134-
private Phase phase = null;
135-
private Side side = null;
136-
137-
public Builder(String name) {
138-
this.name = name;
139-
}
140-
141-
public Builder addMixinClasses(String... mixinClasses) {
142-
this.mixinClasses.addAll(Arrays.asList(mixinClasses));
143-
return this;
144-
}
145-
146-
public Builder setPhase(Phase phase) {
147-
if (this.phase != null) {
148-
throw new RuntimeException("Trying to define Phase twice for " + this.name);
149-
}
150-
this.phase = phase;
151-
return this;
152-
}
153-
154-
public Builder setSide(Side side) {
155-
if (this.side != null) {
156-
throw new RuntimeException("Trying to define Side twice for " + this.name);
157-
}
158-
this.side = side;
159-
return this;
160-
}
161-
162-
public Builder setApplyIf(Supplier<Boolean> applyIf) {
163-
this.applyIf = applyIf;
164-
return this;
165-
}
166-
167-
public Builder addTargetedMod(TargetedMod mod) {
168-
this.targetedMods.add(mod);
169-
return this;
170-
}
171-
172-
public Builder addExcludedMod(TargetedMod mod) {
173-
this.excludedMods.add(mod);
174-
return this;
175-
}
176-
}
177-
178-
private enum Side {
179-
BOTH,
180-
CLIENT,
181-
SERVER
182-
}
183-
184-
private enum Phase {
185-
EARLY,
186-
LATE,
11+
/**
12+
* IMPORTANT: Do not make any references to any mod from this file. This file is loaded quite early on and if you refer
13+
* to other mods you load them as well. The consequence is: You can't inject any previously loaded classes! Exception:
14+
* Reference.java, as long as it is used for Strings only!
15+
*/
16+
public enum Mixins implements IMixins {
17+
18+
// spotless:off
19+
MINECRAFT(new MixinBuilder()
20+
.addClientMixins(
21+
"MixinEntityRenderer",
22+
"GuiAccessor",
23+
"MixinItem",
24+
"MixinRenderGlobal")
25+
.addCommonMixins(
26+
"EntityAccessor",
27+
"EntityLivingAccessor",
28+
"PotionAccessor",
29+
"MixinSpawnerAnimals",
30+
"WorldServerAccessor",
31+
"WorldAccessor")
32+
.setPhase(Phase.EARLY)),
33+
BLOCK_LEAVES_BASE(new MixinBuilder()
34+
.addCommonMixins("MixinBlockLeavesBase")
35+
.setApplyIf(() -> VanillaChanges.FASTER_LEAVEDECAY)
36+
.setPhase(Phase.EARLY)),
37+
THAUMCRAFT_FAST_LEAVE_DECAY(new MixinBuilder()
38+
.addCommonMixins("MixinBlockMagicalLeaves")
39+
.addRequiredMod(TargetedMod.THAUMCRAFT)
40+
.setPhase(Phase.LATE)
41+
.setApplyIf(() -> VanillaChanges.FASTER_LEAVEDECAY)),
42+
GUIVIDEOSETTINGS(new MixinBuilder()
43+
.addClientMixins("MixinGuiVideoSettings")
44+
.setApplyIf(() -> VanillaChanges.LOCKED_GAMMA)
45+
.setPhase(Phase.EARLY)),
46+
WORLD(new MixinBuilder()
47+
.addCommonMixins("MixinWorld")
48+
.setApplyIf(() -> ConfigBlocks.wirelessLever)
49+
.setPhase(Phase.EARLY));
50+
// spotless:on
51+
52+
private final MixinBuilder builder;
53+
54+
Mixins(MixinBuilder builder) {
55+
this.builder = builder;
56+
}
57+
58+
@Nonnull
59+
@Override
60+
public MixinBuilder getBuilder() {
61+
return this.builder;
18762
}
18863
}

0 commit comments

Comments
 (0)