Skip to content

Commit d902e8e

Browse files
committed
even more fixes
1 parent b493480 commit d902e8e

File tree

9 files changed

+75
-20
lines changed

9 files changed

+75
-20
lines changed

src/main/java/com/falsepattern/lib/config/ConfigurationManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import com.falsepattern.lib.DeprecationDetails;
2424
import com.falsepattern.lib.StableAPI;
2525
import com.falsepattern.lib.internal.FalsePatternLib;
26+
import com.falsepattern.lib.internal.ReflectionUtil;
2627
import com.falsepattern.lib.internal.impl.config.ConfigurationManagerImpl;
2728
import lombok.AccessLevel;
2829
import lombok.NoArgsConstructor;
30+
import lombok.SneakyThrows;
2931
import lombok.val;
3032

3133
import cpw.mods.fml.client.config.IConfigElement;
@@ -48,6 +50,15 @@ public static void initialize(Class<?>... configClasses) throws ConfigException
4850
initialize((a, b) -> {}, configClasses);
4951
}
5052

53+
/**
54+
* You can use this method in the static initializer of a config class to self-load it without extra effort.
55+
*/
56+
@StableAPI.Expose(since = "0.10.3")
57+
@SneakyThrows
58+
public static void selfInit() {
59+
initialize(ReflectionUtil.getCallerClass());
60+
}
61+
5162
@StableAPI.Expose(since = "0.10.0")
5263
public static void initialize(BiConsumer<Class<?>, Field> validatorErrorCallback, Class<?>... configClasses)
5364
throws ConfigException {

src/main/java/com/falsepattern/lib/internal/ReflectionUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ public static void jailBreak(Field field) {
4747
public static void jailBreak(Method method) {
4848
method.setAccessible(true);
4949
}
50+
51+
@SneakyThrows
52+
public static Class<?> getCallerClass() {
53+
return Class.forName(Thread.currentThread().getStackTrace()[3].getClassName());
54+
}
5055
}

src/main/java/com/falsepattern/lib/internal/asm/IMixinPluginTransformer.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import com.falsepattern.lib.mixin.MixinInfo;
2727
import lombok.val;
2828
import org.objectweb.asm.tree.ClassNode;
29+
import org.objectweb.asm.tree.MethodNode;
30+
31+
import java.util.ArrayList;
2932

3033
public class IMixinPluginTransformer implements IClassNodeTransformer {
3134
@Override
@@ -41,18 +44,21 @@ public boolean shouldTransform(ClassNode cn, String transformedName, boolean obf
4144
@Override
4245
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
4346
val methods = cn.methods;
47+
val remove = new ArrayList<MethodNode>();
48+
String name;
4449
if (!MixinInfo.isMixinBooterLegacy()) {
45-
FPTransformer.LOG.info("Could not detect MixinBooterLegacy. Converting IMixinPlugin to legacy compat mode.");
46-
for (val method : methods) {
47-
if (method.name.equals("preApply") || method.name.equals("postApply")) {
48-
method.desc = method.desc.replace("org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode",
49-
"org/spongepowered/asm/lib/tree/ClassNode");
50-
for (val local: method.localVariables) {
51-
local.desc = local.desc.replace("org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode",
52-
"org/spongepowered/asm/lib/tree/ClassNode");
53-
}
54-
}
50+
FPTransformer.LOG.info("Could not detect MixinBooterLegacy. Removing MBL compat code.");
51+
name = "org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode";
52+
} else {
53+
FPTransformer.LOG.info("Detected MixinBooterLegacy. Removing SpongeMixins compat code.");
54+
name = "org/spongepowered/asm/lib/tree/ClassNode";
55+
}
56+
for (val method: methods) {
57+
if ((method.name.equals("preApply") || method.name.equals("postApply")) &&
58+
method.desc.contains(name)) {
59+
remove.add(method);
5560
}
5661
}
62+
methods.removeAll(remove);
5763
}
5864
}

src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222

2323
import com.falsepattern.lib.StableAPI;
2424
import com.falsepattern.lib.config.Config;
25+
import com.falsepattern.lib.config.ConfigurationManager;
2526
import com.falsepattern.lib.internal.Tags;
2627

2728
@Config(modid = Tags.MODID)
2829
public class LibraryConfig {
30+
static {
31+
ConfigurationManager.selfInit();
32+
}
2933
@Config.Comment({"Used to control whether FalsePatternLib should check for outdated mods.",
3034
"If you're building a public modpack, you should turn this off so that your users don't " +
3135
"get nagged about outdated mods."})

src/main/java/com/falsepattern/lib/internal/config/ToastConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.falsepattern.lib.StableAPI;
2424
import com.falsepattern.lib.config.Config;
25+
import com.falsepattern.lib.config.ConfigurationManager;
2526
import com.falsepattern.lib.internal.Tags;
2627

2728
import cpw.mods.fml.relauncher.Side;
@@ -31,6 +32,9 @@
3132
@Config(modid = Tags.MODID,
3233
category = "toasts")
3334
public class ToastConfig {
35+
static {
36+
ConfigurationManager.selfInit();
37+
}
3438
@Config.Comment("The maximum amount of toasts to show on the screen")
3539
@Config.LangKey("config.falsepatternlib.maxtoasts")
3640
@Config.DefaultInt(5)

src/main/java/com/falsepattern/lib/internal/proxy/ClientProxy.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ public void construct(FMLConstructionEvent e) {
5858
@Override
5959
public void preInit(FMLPreInitializationEvent e) {
6060
super.preInit(e);
61-
try {
62-
ConfigurationManager.initialize(ToastConfig.class);
63-
} catch (ConfigException ex) {
64-
throw new RuntimeException(ex);
65-
}
6661
MinecraftForge.EVENT_BUS.register(this);
6762
}
6863

src/main/java/com/falsepattern/lib/internal/proxy/CommonProxy.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ public void construct(FMLConstructionEvent e) {
5757

5858
public void preInit(FMLPreInitializationEvent e) {
5959
ConfigurationManagerImpl.registerBus();
60-
try {
61-
ConfigurationManager.initialize(LibraryConfig.class);
62-
} catch (ConfigException ex) {
63-
throw new RuntimeException(ex);
64-
}
6560
if (LibraryConfig.ENABLE_UPDATE_CHECKER) {
6661
FalsePatternLib.getLog().info("Launching asynchronous update check.");
6762
updatesFuture = UpdateChecker.fetchUpdatesAsync(FalsePatternLib.UPDATE_URL).thenApplyAsync(updates -> {

src/main/java/com/falsepattern/lib/mixin/IMixinPlugin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,14 @@ default void preApply(String targetClassName, ClassNode targetClass, String mixi
157157
default void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
158158

159159
}
160+
161+
@StableAPI.Expose(since = "__INTERNAL__")
162+
default void preApply(String targetClassName, com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
163+
164+
}
165+
166+
@StableAPI.Expose(since = "__INTERNAL__")
167+
default void postApply(String targetClassName, com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
168+
169+
}
160170
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2022 FalsePattern
3+
* All Rights Reserved
4+
*
5+
* The above copyright notice, this permission notice and the word "SNEED"
6+
* shall be included in all copies or substantial portions of the Software.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
package com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.lib.tree;
23+
24+
public class ClassNode {
25+
}

0 commit comments

Comments
 (0)