|
1 | 1 | package org.dimdev.vanillafix.bugs; |
2 | 2 |
|
3 | 3 | import java.util.List; |
| 4 | +import java.util.Optional; |
4 | 5 | import java.util.Set; |
5 | 6 |
|
| 7 | +import org.dimdev.vanillafix.VanillaFix; |
6 | 8 | import org.objectweb.asm.tree.ClassNode; |
7 | 9 | import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; |
8 | 10 | import org.spongepowered.asm.mixin.extensibility.IMixinInfo; |
9 | 11 |
|
10 | 12 | import static org.dimdev.vanillafix.VanillaFix.config; |
11 | 13 |
|
12 | 14 | public class BugFixMixinPlugin implements IMixinConfigPlugin { |
13 | | - |
14 | | - @Override |
15 | | - public void onLoad(String mixinPackage) { |
16 | | - } |
17 | | - |
18 | | - @Override |
19 | | - public String getRefMapperConfig() { |
20 | | - return null; |
21 | | - } |
22 | | - |
23 | | - // TODO: use asm |
24 | | - @Override |
25 | | - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { |
26 | | - System.out.println(mixinClassName); |
27 | | - |
28 | | - switch (mixinClassName) { |
29 | | - case "org.dimdev.vanillafix.bugs.mixins.step.ServerPlayerEntityMixin": |
30 | | - return config().antiCheat.fixStepHeight; |
31 | | - case "org.dimdev.vanillafix.bugs.mixins.EntityMixin": |
32 | | - return config().bugFixes.updateFallDistance; |
33 | | - case "org.dimdev.vanillafix.bugs.mixins.MinecraftServerMixin": |
34 | | - return config().bugFixes.disableInitialChunkLoad; |
35 | | - case "org.dimdev.vanillafix.bugs.mixins.PlayerInventoryMixin": |
36 | | - return config().bugFixes.fixRecipeBookIngredientsWithTags; |
37 | | - case "org.dimdev.vanillafix.bugs.mixins.invulnerable.ServerPlayerEntityMixin": |
38 | | - return config().antiCheat.noPlayerInvulnerabilityAfterTeleport; |
39 | | - case "org.dimdev.vanillafix.bugs.mixins.client.MinecraftClientMixin": |
40 | | - return config().clientOnly.splitScreenAndTextureProfiler; |
41 | | - case "org.dimdev.vanillafix.bugs.mixins.client.ClientPlayerEntityMixin": |
42 | | - return config().clientOnly.screenInNetherPortal; |
43 | | - case "org.dimdev.vanillafix.bugs.mixins.client.ClientPlayNetworkHandlerMixin": |
44 | | - return config().clientOnly.fastInterdimensionalTeleportation; |
45 | | - case "org.dimdev.vanillafix.bugs.mixins.BuiltinBiomesMixin": |
46 | | - return config().bugFixes.fixStoneShoreColors; |
47 | | - case "org.dimdev.vanillafix.bugs.mixins.SignBlockEntityMixin": |
48 | | - return config().bugFixes.fixSignCommands; |
49 | | - } |
50 | | - return true; |
51 | | - } |
52 | | - |
53 | | - @Override |
54 | | - public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { |
55 | | - } |
56 | | - |
57 | | - @Override |
58 | | - public List<String> getMixins() { |
59 | | - return null; |
60 | | - } |
61 | | - |
62 | | - @Override |
63 | | - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { |
64 | | - } |
65 | | - |
66 | | - @Override |
67 | | - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { |
68 | | - } |
| 15 | + @Override |
| 16 | + public void onLoad(String mixinPackage) { |
| 17 | + } |
| 18 | + |
| 19 | + @Override |
| 20 | + public String getRefMapperConfig() { |
| 21 | + return null; |
| 22 | + } |
| 23 | + |
| 24 | + @Override |
| 25 | + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { |
| 26 | + return Optional.ofNullable(VanillaFix.MIXIN_CONFIGS.get(targetClassName)).map(pair -> { |
| 27 | + try { |
| 28 | + Object e = VanillaFix.config() |
| 29 | + .getClass() |
| 30 | + .getField(pair.getCategory()) |
| 31 | + .get(VanillaFix.config()); |
| 32 | + return e.getClass().getField(pair.getValue()).getBoolean(e); |
| 33 | + } catch (IllegalAccessException | NoSuchFieldException ignored) { |
| 34 | + throw new AssertionError(); |
| 35 | + } |
| 36 | + }).orElse(Boolean.TRUE); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public List<String> getMixins() { |
| 45 | + return null; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { |
| 54 | + } |
69 | 55 | } |
0 commit comments