diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-05 22:37:47 +0900 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-05 22:37:47 +0900 |
commit | 206063acf3a6e0edc0d16b07d206aa36207b42d4 (patch) | |
tree | 8d0f31d65cfa4b3f85a3d4f7f0844f6df65b2b7e /versions/src | |
parent | fecb67e07ded0d20b12d3bdb48fea3e2e50b7f88 (diff) | |
download | OneConfig-206063acf3a6e0edc0d16b07d206aa36207b42d4.tar.gz OneConfig-206063acf3a6e0edc0d16b07d206aa36207b42d4.tar.bz2 OneConfig-206063acf3a6e0edc0d16b07d206aa36207b42d4.zip |
a
Diffstat (limited to 'versions/src')
12 files changed, 427 insertions, 241 deletions
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java index 44a6611..4f73198 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java @@ -36,7 +36,6 @@ public class OneConfig { public static final Logger LOGGER = LogManager.getLogger("@NAME@"); private static boolean preLaunched = false; private static boolean initialized = false; - private static boolean isObfuscated = true; /** * Called before mods are loaded. @@ -44,12 +43,6 @@ public class OneConfig { */ public static void preLaunch() { if (preLaunched) return; - try { - Class.forName("net.minecraft.world.World"); - LOGGER.warn("OneConfig is NOT obfuscated!"); - isObfuscated = false; - } catch (Exception ignored) { - } oneConfigDir.mkdirs(); new File(oneConfigDir, "profiles").mkdirs(); if (OneConfigConfig.getInstance() == null) { @@ -83,12 +76,6 @@ public class OneConfig { initialized = true; } - /** Returns weather this is an obfuscated environment, using a check for obfuscated name of net.minecraft.world.World.class. - * @return true if this is an obfuscated environment, which is normal for Minecraft or false if not. */ - public static boolean isObfuscated() { - return isObfuscated; - } - @Subscribe private void onShutdown(ShutdownEvent event) { ConfigCore.saveAll(); diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java index 8d0d550..3424d2b 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java @@ -10,7 +10,6 @@ import cc.polyfrost.oneconfig.internal.mixin.ShaderGroupAccessor; import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; import cc.polyfrost.oneconfig.libs.universal.UMinecraft; import cc.polyfrost.oneconfig.libs.universal.UScreen; -import net.minecraft.client.Minecraft; import net.minecraft.client.shader.Shader; import net.minecraft.client.shader.ShaderUniform; import net.minecraft.util.ResourceLocation; @@ -55,7 +54,7 @@ public class BlurHandlerImpl implements BlurHandler { } // Only update the shader if one is active - if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive()) { + if (!isShaderActive()) { return; } if (progress >= 5) return; @@ -102,14 +101,14 @@ public class BlurHandlerImpl implements BlurHandler { // If a shader is not already active and the UI is // a one of ours, we should load our own blur! - if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive() && gui instanceof OneConfigGui && Preferences.enableBlur) { + if (!isShaderActive() && gui instanceof OneConfigGui && Preferences.enableBlur) { UMinecraft.getMinecraft().entityRenderer.loadShader(this.blurShader); this.start = System.currentTimeMillis(); this.progress = 0; // If a shader is active and the incoming UI is null or we have blur disabled, stop using the shader. - } else if (UMinecraft.getMinecraft().entityRenderer.isShaderActive() && (gui == null || !Preferences.enableBlur)) { + } else if (isShaderActive() && (gui == null || !Preferences.enableBlur)) { String name = UMinecraft.getMinecraft().entityRenderer.getShaderGroup().getShaderGroupName(); // Only stop our specific blur ;) @@ -129,4 +128,12 @@ public class BlurHandlerImpl implements BlurHandler { private float getBlurStrengthProgress() { return Math.min((System.currentTimeMillis() - this.start) / 50F, 5.0F); } + + private boolean isShaderActive() { + return UMinecraft.getMinecraft().entityRenderer.getShaderGroup() != null + //#if MC<=11202 + && net.minecraft.client.renderer.OpenGlHelper.shadersSupported + //#endif + ; + } } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java new file mode 100644 index 0000000..0063d1b --- /dev/null +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java @@ -0,0 +1,140 @@ +package cc.polyfrost.oneconfig.internal.plugin; + +import cc.polyfrost.oneconfig.platform.Platform; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class OneConfigMixinPlugin implements IMixinConfigPlugin { + private static boolean isVigilance = false; + + @Override + public void onLoad(String mixinPackage) { + try { + Class.forName("gg.essential.vigilance.Vigilant"); + isVigilance = true; + } catch (Exception e) { + isVigilance = false; + } + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return !targetClassName.contains("vigilance") || isVigilance; + } + + @Override + public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { + + } + + @Override + public List<String> getMixins() { + if (Platform.getInstance().getMinecraftVersion() >= 11600) { + ArrayList<String> mixins = new ArrayList<>(); + mixins.add("ClientModLoaderMixin"); + mixins.add("KeyboardListenerMixin"); + mixins.add("MouseHelperAccessor"); + mixins.add("MouseHelperMixin"); + mixins.add("TimeTrackerMixin"); + return mixins; + } else { + return null; + } + } + + @Override + public void preApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } + + @Override + public void postApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + if (mixinClassName.equals("cc.polyfrost.oneconfig.internal.mixin.VigilantMixin")) { + transform(targetClass); + } + } + + /** + * If anything here is changed, edit the corresponding method in OneConfigMixinPlugin! + */ + private void transform(org.spongepowered.asm.lib.tree.ClassNode node) { + if (!node.interfaces.contains("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor")) { + node.fields.add(new org.spongepowered.asm.lib.tree.FieldNode(Opcodes.ACC_PUBLIC, "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", null, null)); + node.fields.add(new org.spongepowered.asm.lib.tree.FieldNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "oneconfig$file", Type.getDescriptor(File.class), null, null)); + + node.interfaces.add("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor"); + org.spongepowered.asm.lib.tree.MethodNode methodNode = new org.spongepowered.asm.lib.tree.MethodNode(Opcodes.ACC_PUBLIC, "getPropertyCollector", "()Lgg/essential/vigilance/data/PropertyCollector;", null, null); + org.spongepowered.asm.lib.tree.LabelNode labelNode = new org.spongepowered.asm.lib.tree.LabelNode(); + methodNode.instructions.add(labelNode); + methodNode.instructions.add(new org.spongepowered.asm.lib.tree.LineNumberNode(421421, labelNode)); + methodNode.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0)); + methodNode.instructions.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "propertyCollector", "Lgg/essential/vigilance/data/PropertyCollector;")); + methodNode.instructions.add(new org.spongepowered.asm.lib.tree.InsnNode(Opcodes.ARETURN)); + node.methods.add(methodNode); + + org.spongepowered.asm.lib.tree.MethodNode methodNode2 = new org.spongepowered.asm.lib.tree.MethodNode(Opcodes.ACC_PUBLIC, "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", null, null); + org.spongepowered.asm.lib.tree.LabelNode labelNode2 = new org.spongepowered.asm.lib.tree.LabelNode(); + org.spongepowered.asm.lib.tree.LabelNode labelNode3 = new org.spongepowered.asm.lib.tree.LabelNode(); + org.spongepowered.asm.lib.tree.LabelNode labelNode4 = new org.spongepowered.asm.lib.tree.LabelNode(); + methodNode2.instructions.add(labelNode2); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.LineNumberNode(15636436, labelNode2)); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0)); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); + + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.JumpInsnNode(Opcodes.IFNULL, labelNode4)); + + methodNode2.instructions.add(labelNode3); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.LineNumberNode(15636437, labelNode3)); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0)); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 1)); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 2)); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.MethodInsnNode(Opcodes.INVOKEVIRTUAL, "cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig", "addDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); + + methodNode2.instructions.add(labelNode4); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.LineNumberNode(15636438, labelNode4)); + methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.InsnNode(Opcodes.RETURN)); + node.methods.add(methodNode2); + + for (org.spongepowered.asm.lib.tree.MethodNode method : node.methods) { + if (method.name.equals("initialize")) { + org.spongepowered.asm.lib.tree.InsnList list = new org.spongepowered.asm.lib.tree.InsnList(); + list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); + list.add(new org.spongepowered.asm.lib.tree.MethodInsnNode(Opcodes.INVOKESTATIC, "cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook", "returnNewConfig", "(Lgg/essential/vigilance/Vigilant;Ljava/io/File;)Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", false)); + list.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); + method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); + } else if (method.name.equals("addDependency") && method.desc.equals("(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V")) { + org.spongepowered.asm.lib.tree.InsnList list = new org.spongepowered.asm.lib.tree.InsnList(); + + list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 1)); + list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 2)); + list.add(new org.spongepowered.asm.lib.tree.MethodInsnNode(Opcodes.INVOKEVIRTUAL, "gg/essential/vigilance/Vigilant", "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); + + method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); + } else if (method.name.equals("<init>") && method.desc.equals("(Ljava/io/File;Ljava/lang/String;Lgg/essential/vigilance/data/PropertyCollector;Lgg/essential/vigilance/data/SortingBehavior;)V")) { + org.spongepowered.asm.lib.tree.InsnList list = new org.spongepowered.asm.lib.tree.InsnList(); + list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 1)); + list.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); + method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); + } + } + } + } +} diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java index dca53a1..bbd47ac 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java @@ -1,3 +1,4 @@ +//#if MC<=11202 package cc.polyfrost.oneconfig.internal.plugin.asm; import cc.polyfrost.oneconfig.internal.plugin.asm.tweakers.NanoVGGLConfigTransformer; @@ -98,4 +99,5 @@ public class ClassTransformer implements IClassTransformer { return cw.toByteArray(); } -}
\ No newline at end of file +} +//#endif
\ No newline at end of file diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java index d302b9d..b1f3eb2 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java @@ -1,3 +1,4 @@ +//#if MC<=11202 package cc.polyfrost.oneconfig.internal.plugin.asm; import cc.polyfrost.oneconfig.internal.init.OneConfigInit; @@ -114,4 +115,5 @@ public class OneConfigTweaker implements ITweaker { public String[] getLaunchArguments() { return new String[0]; } -}
\ No newline at end of file +} +//#endif
\ No newline at end of file diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java index 2755f7f..c984ac3 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java @@ -1,6 +1,9 @@ package cc.polyfrost.oneconfig.platform.impl; import cc.polyfrost.oneconfig.platform.LoaderPlatform; +//#if MC>=11600 +//$$ import net.minecraftforge.fml.ModList; +//#endif import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ModContainer; @@ -8,7 +11,11 @@ import net.minecraftforge.fml.common.ModContainer; public class LoaderPlatformImpl implements LoaderPlatform { @Override public boolean isModLoaded(String id) { + //#if MC>=11600 + //$$ return ModList.get().isLoaded(id); + //#else return Loader.isModLoaded(id); + //#endif } @Override @@ -19,9 +26,8 @@ public class LoaderPlatformImpl implements LoaderPlatform { @Override public ActiveMod getActiveModContainer() { ModContainer container = Loader.instance().activeModContainer(); - if (container == null) - return null; - //#if MC<=11202 + if (container == null) return null; + //#if MC==11202 return new ActiveMod(container.getName(), container.getModId(), container.getVersion()); //#else //$$ return new ActiveMod(container.getModInfo().getDisplayName(), container.getModId(), container.getModInfo().getVersion().getQualifier()); diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl.java index 1276000..e368a91 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl.java @@ -1,53 +1,84 @@ package cc.polyfrost.oneconfig.platform.impl; import cc.polyfrost.oneconfig.platform.MousePlatform; +//#if MC>=11600 +//$$ import cc.polyfrost.oneconfig.libs.universal.UMinecraft; +//$$ import cc.polyfrost.oneconfig.internal.mixin.MouseHelperAccessor; +//$$ import org.lwjgl.glfw.GLFW; +//#else import org.lwjgl.input.Mouse; +//#endif @SuppressWarnings("unused") public class MousePlatformImpl implements MousePlatform { + //#if MC>11600 + //$$ private double prevScroll = 0; + //#endif + @Override - public int getMouseX() { + public double getMouseX() { + //#if MC>=11600 + //$$ return UMinecraft.getMinecraft().mouseHelper.getMouseX(); + //#else return Mouse.getX(); + //#endif } @Override - public int getMouseY() { + public double getMouseY() { + //#if MC>=11600 + //$$ return UMinecraft.getMinecraft().mouseHelper.getMouseY(); + //#else return Mouse.getY(); + //#endif } @Override - public int getDWheel() { + public double getDWheel() { + //#if MC>=11600 + //$$ double scrollDelta = ((MouseHelperAccessor) UMinecraft.getMinecraft().mouseHelper).getAccumulatedScrollDelta(); + //$$ double amount = scrollDelta - prevScroll; + //$$ prevScroll = scrollDelta; + //$$ return amount; + //#else return Mouse.getDWheel(); + //#endif } @Override - public int getMouseDX() { + public double getMouseDX() { + //#if MC>=11600 + //$$ return UMinecraft.getMinecraft().mouseHelper.getXVelocity(); + //#else return Mouse.getDX(); + //#endif } @Override - public int getMouseDY() { + public double getMouseDY() { + //#if MC>=11600 + //$$ return UMinecraft.getMinecraft().mouseHelper.getYVelocity(); + //#else return Mouse.getDY(); + //#endif } @Override - public boolean next() { - return Mouse.next(); - } - - @Override - public boolean getEventButtonState() { - return Mouse.getEventButtonState(); - } - - @Override - public int getEventButton() { - return Mouse.getEventButton(); + public int getButtonState(int button) { + //#if MC>=11600 + //$$ return GLFW.glfwGetMouseButton(UMinecraft.getMinecraft().getMainWindow().getHandle(), button); + //#else + return Mouse.isButtonDown(button) ? 1 : 0; + //#endif } @Override public boolean isButtonDown(int button) { + //#if MC>=11600 + //$$ return GLFW.glfwGetMouseButton(UMinecraft.getMinecraft().getMainWindow().getHandle(), button) == GLFW.GLFW_PRESS; + //#else return Mouse.isButtonDown(button); + //#endif } } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java index 7ad639c..91edc53 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java @@ -9,4 +9,33 @@ public class PlatformImpl implements Platform { public boolean isCallingFromMinecraftThread() { return Minecraft.getMinecraft().isCallingFromMinecraftThread(); } + + @Override + public int getMinecraftVersion() { + //#if MC>=11900 + //$$ return 11900; + //#elseif MC>=11800 + //$$ return 11800; + //#elseif MC>=11700 + //$$ return 11700; + //#elseif MC>=11600 + //$$ return 11600; + //#elseif MC>=11500 + //$$ return 11500; + //#elseif MC>=11400 + //$$ return 11400; + //#elseif MC>=11300 + //$$ return 11300; + //#elseif MC>=11200 + //$$ return 11200; + //#elseif MC>=11100 + //$$ return 11100; + //#elseif MC>=11000 + //$$ return 11000; + //#elseif MC>=10900 + //$$ return 10900; + //#else + return 10800; + //#endif + } } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestMod_Test.java b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestMod_Test.java index f7672ff..0d2fb87 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestMod_Test.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestMod_Test.java @@ -1,20 +1,20 @@ package cc.polyfrost.oneconfig.test; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.InitializationEvent; +import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; //#if MC<=11202 @net.minecraftforge.fml.common.Mod(modid = "oneconfig-test-mod", name = "Test Mod", version = "0") -//#else -//$$ @Mod("oneconfig-test-mod") //#endif public class TestMod_Test { private TestConfig_Test config; + public TestMod_Test() { + EventManager.INSTANCE.register(this); + } - //#if MC<=11202 - @Mod.EventHandler - //#endif - public void init(FMLInitializationEvent event) { + @Subscribe + public void init(InitializationEvent e) { config = new TestConfig_Test(); } }
\ No newline at end of file diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java index c38fbff..a4cd9ae 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java @@ -1,11 +1,10 @@ +//#if MC>=11202 package cc.polyfrost.oneconfig.utils.commands; import cc.polyfrost.oneconfig.libs.universal.ChatColor; import cc.polyfrost.oneconfig.libs.universal.UChat; import cc.polyfrost.oneconfig.utils.commands.annotations.Command; import cc.polyfrost.oneconfig.utils.commands.annotations.Greedy; -import cc.polyfrost.oneconfig.utils.commands.annotations.Name; -import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; import cc.polyfrost.oneconfig.utils.commands.arguments.ArgumentParser; import cc.polyfrost.oneconfig.utils.commands.arguments.Arguments; import net.minecraft.command.CommandBase; @@ -22,8 +21,9 @@ import java.lang.reflect.Parameter; import java.util.*; import static cc.polyfrost.oneconfig.utils.commands.CommandManager.*; +import static cc.polyfrost.oneconfig.utils.commands.CommandManager.METHOD_RUN_ERROR; -public class PlatformCommandManagerImpl implements PlatformCommandManager { +public class PlatformCommandManagerImpl extends PlatformCommandManager { @Override public void createCommand(CommandManager.InternalCommand root, Command annotation) { @@ -47,7 +47,65 @@ public class PlatformCommandManagerImpl implements PlatformCommandManager { //$$ execute(net.minecraft.server.MinecraftServer server, ICommandSender sender, String[] args) //#endif { - handleCommand(root, annotation, args); + if (args.length == 0) { + if (!root.invokers.isEmpty()) { + try { + root.invokers.get(0).method.invoke(null); + } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException | + ExceptionInInitializerError e) { + e.printStackTrace(); + UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR); + } + } + } else { + if (annotation.helpCommand() && args[0].equalsIgnoreCase("help")) { + UChat.chat(sendHelpCommand(root)); + } else { + List<CommandManager.InternalCommand.InternalCommandInvoker> commands = new ArrayList<>(); + int depth = 0; + for (CommandManager.InternalCommand command : root.children) { + int newDepth = loopThroughCommands(commands, 0, command, args); + if (newDepth != -1) { + depth = newDepth; + break; + } + } + if (commands.isEmpty()) { + if (depth == -2) { + UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + TOO_MANY_PARAMETERS.replace("@ROOT_COMMAND@", annotation.value())); + } else { + UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + NOT_FOUND_TEXT.replace("@ROOT_COMMAND@", annotation.value())); + } + } else { + List<CommandManager.CustomError> errors = new ArrayList<>(); + for (CommandManager.InternalCommand.InternalCommandInvoker invoker : commands) { + try { + List<Object> params = getParametersForInvoker(invoker, depth, args); + if (params.size() == 1) { + Object first = params.get(0); + if (first instanceof CommandManager.CustomError) { + errors.add((CommandManager.CustomError) first); + continue; + } + } + invoker.method.invoke(null, params.toArray()); + return; + } catch (Exception e) { + e.printStackTrace(); + UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR); + return; + } + } + //noinspection ConstantConditions + if (!errors.isEmpty()) { + UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + "Multiple errors occurred:"); + for (CommandManager.CustomError error : errors) { + UChat.chat(" " + ChatColor.RED + ChatColor.BOLD + error.message); + } + } + } + } + } } @Override @@ -63,159 +121,93 @@ public class PlatformCommandManagerImpl implements PlatformCommandManager { //$$ getTabCompletions(net.minecraft.server.MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos) //#endif { - return handleTabCompletion(root, annotation, args); - } - }); - //#else - //#endif - } - - private void handleCommand(CommandManager.InternalCommand root, Command annotation, String[] args) { - if (args.length == 0) { - if (!root.invokers.isEmpty()) { try { - root.invokers.get(0).method.invoke(null); - } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException | - ExceptionInInitializerError e) { - e.printStackTrace(); - UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR); - } - } - } else { - if (annotation.helpCommand() && args[0].equalsIgnoreCase("help")) { - UChat.chat(sendHelpCommand(root)); - } else { - List<CommandManager.InternalCommand.InternalCommandInvoker> commands = new ArrayList<>(); - int depth = 0; - for (CommandManager.InternalCommand command : root.children) { - int newDepth = loopThroughCommands(commands, 0, command, args); - if (newDepth != -1) { - depth = newDepth; - break; - } - } - if (commands.isEmpty()) { - if (depth == -2) { - UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + TOO_MANY_PARAMETERS.replace("@ROOT_COMMAND@", annotation.value())); - } else { - UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + NOT_FOUND_TEXT.replace("@ROOT_COMMAND@", annotation.value())); + Set<Pair<InternalCommand.InternalCommandInvoker, Integer>> commands = new HashSet<>(); + for (CommandManager.InternalCommand command : root.children) { + loopThroughCommandsTab(commands, 0, command, args); } - } else { - List<CommandManager.CustomError> errors = new ArrayList<>(); - for (CommandManager.InternalCommand.InternalCommandInvoker invoker : commands) { - try { - List<Object> params = getParametersForInvoker(invoker, depth, args); - if (params.size() == 1) { - Object first = params.get(0); - if (first instanceof CommandManager.CustomError) { - errors.add((CommandManager.CustomError) first); - continue; + if (!commands.isEmpty() || annotation.helpCommand()) { + List<Triple<InternalCommand.InternalCommandInvoker, Integer, Integer>> validCommands = new ArrayList<>(); // command, depth, and all processed params + for (Pair<CommandManager.InternalCommand.InternalCommandInvoker, Integer> pair : commands) { + CommandManager.InternalCommand.InternalCommandInvoker invoker = pair.getLeft(); + int depth = pair.getRight(); + int currentParam = 0; + boolean failed = false; + while (args.length - depth > 1) { + Parameter param = invoker.method.getParameters()[currentParam]; + if (param.isAnnotationPresent(Greedy.class) && currentParam + 1 != invoker.parameterTypes.length) { + failed = true; + break; + } + ArgumentParser<?> parser = INSTANCE.parsers.get(param.getType()); + if (parser == null) { + failed = true; + break; + } + try { + Arguments arguments = new Arguments(Arrays.copyOfRange(args, depth, args.length), param.isAnnotationPresent(Greedy.class)); + if (parser.parse(arguments) != null) { + depth += arguments.getPosition(); + currentParam++; + } else { + failed = true; + break; + } + } catch (Exception e) { + failed = true; + break; } } - invoker.method.invoke(null, params.toArray()); - return; - } catch (Exception e) { - e.printStackTrace(); - UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR); - return; - } - } - //noinspection ConstantConditions - if (!errors.isEmpty()) { - UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + "Multiple errors occurred:"); - for (CommandManager.CustomError error : errors) { - UChat.chat(" " + ChatColor.RED + ChatColor.BOLD + error.message); + if (!failed) { + validCommands.add(new ImmutableTriple<>(pair.getLeft(), depth, currentParam)); + } } - } - } - } - } - } + if (!validCommands.isEmpty() || annotation.helpCommand()) { + Set<String> completions = new HashSet<>(); + for (Triple<CommandManager.InternalCommand.InternalCommandInvoker, Integer, Integer> valid : validCommands) { + if (valid.getMiddle() == args.length) { + completions.add(valid.getLeft().name); + completions.addAll(Arrays.asList(valid.getLeft().aliases)); + continue; + } + if (valid.getRight() + 1 > valid.getLeft().parameterTypes.length) continue; + Parameter param = valid.getLeft().method.getParameters()[valid.getRight()]; + if (param.isAnnotationPresent(Greedy.class) && valid.getRight() + 1 != valid.getLeft().parameterTypes.length) { + continue; + } + ArgumentParser<?> parser = INSTANCE.parsers.get(param.getType()); + if (parser == null) { + continue; + } + try { + Arguments arguments = new Arguments(Arrays.copyOfRange(args, valid.getMiddle(), args.length), param.isAnnotationPresent(Greedy.class)); + List<String> possibleCompletions = parser.complete(arguments, param); + if (possibleCompletions != null) { + completions.addAll(possibleCompletions); + } + } catch (Exception ignored) { - private List<String> handleTabCompletion(CommandManager.InternalCommand root, Command annotation, String[] args) { - try { - Set<Pair<CommandManager.InternalCommand.InternalCommandInvoker, Integer>> commands = new HashSet<>(); - for (CommandManager.InternalCommand command : root.children) { - loopThroughCommandsTab(commands, 0, command, args); - } - if (!commands.isEmpty() || annotation.helpCommand()) { - List<Triple<CommandManager.InternalCommand.InternalCommandInvoker, Integer, Integer>> validCommands = new ArrayList<>(); // command, depth, and all processed params - for (Pair<CommandManager.InternalCommand.InternalCommandInvoker, Integer> pair : commands) { - CommandManager.InternalCommand.InternalCommandInvoker invoker = pair.getLeft(); - int depth = pair.getRight(); - int currentParam = 0; - boolean failed = false; - while (args.length - depth > 1) { - Parameter param = invoker.method.getParameters()[currentParam]; - if (param.isAnnotationPresent(Greedy.class) && currentParam + 1 != invoker.parameterTypes.length) { - failed = true; - break; - } - ArgumentParser<?> parser = INSTANCE.parsers.get(param.getType()); - if (parser == null) { - failed = true; - break; - } - try { - Arguments arguments = new Arguments(Arrays.copyOfRange(args, depth, args.length), param.isAnnotationPresent(Greedy.class)); - if (parser.parse(arguments) != null) { - depth += arguments.getPosition(); - currentParam++; - } else { - failed = true; - break; + } } - } catch (Exception e) { - failed = true; - break; - } - } - if (!failed) { - validCommands.add(new ImmutableTriple<>(pair.getLeft(), depth, currentParam)); - } - } - if (!validCommands.isEmpty() || annotation.helpCommand()) { - Set<String> completions = new HashSet<>(); - for (Triple<CommandManager.InternalCommand.InternalCommandInvoker, Integer, Integer> valid : validCommands) { - if (valid.getMiddle() == args.length) { - completions.add(valid.getLeft().name); - completions.addAll(Arrays.asList(valid.getLeft().aliases)); - continue; - } - if (valid.getRight() + 1 > valid.getLeft().parameterTypes.length) continue; - Parameter param = valid.getLeft().method.getParameters()[valid.getRight()]; - if (param.isAnnotationPresent(Greedy.class) && valid.getRight() + 1 != valid.getLeft().parameterTypes.length) { - continue; - } - ArgumentParser<?> parser = INSTANCE.parsers.get(param.getType()); - if (parser == null) { - continue; - } - try { - Arguments arguments = new Arguments(Arrays.copyOfRange(args, valid.getMiddle(), args.length), param.isAnnotationPresent(Greedy.class)); - List<String> possibleCompletions = parser.complete(arguments, param); - if (possibleCompletions != null) { - completions.addAll(possibleCompletions); + if (args.length == 1 && annotation.helpCommand()) { + if ("help".startsWith(args[0].toLowerCase(Locale.ENGLISH))) { + completions.add("help"); + } } - } catch (Exception ignored) { - + return new ArrayList<>(completions); } } - if (args.length == 1 && annotation.helpCommand()) { - if ("help".startsWith(args[0].toLowerCase(Locale.ENGLISH))) { - completions.add("help"); - } - } - return new ArrayList<>(completions); + } catch (Exception ignored) { + } + return null; } - } catch (Exception ignored) { - - } - return null; + }); + //#else + //#endif } - private List<Object> getParametersForInvoker(CommandManager.InternalCommand.InternalCommandInvoker invoker, int depth, String[] args) { + protected List<Object> getParametersForInvoker(CommandManager.InternalCommand.InternalCommandInvoker invoker, int depth, String[] args) { List<Object> parameters = new ArrayList<>(); int processed = depth; int currentParam = 0; @@ -249,7 +241,7 @@ public class PlatformCommandManagerImpl implements PlatformCommandManager { return parameters; } - private int loopThroughCommands(List<CommandManager.InternalCommand.InternalCommandInvoker> commands, int depth, CommandManager.InternalCommand command, String[] args) { + protected int loopThroughCommands(List<CommandManager.InternalCommand.InternalCommandInvoker> commands, int depth, CommandManager.InternalCommand command, String[] args) { int nextDepth = depth + 1; boolean thatOneSpecialError = false; if (command.isValid(args[depth], false)) { @@ -279,7 +271,7 @@ public class PlatformCommandManagerImpl implements PlatformCommandManager { return thatOneSpecialError ? -2 : -1; } - private void loopThroughCommandsTab(Set<Pair<CommandManager.InternalCommand.InternalCommandInvoker, Integer>> commands, int depth, CommandManager.InternalCommand command, String[] args) { + protected void loopThroughCommandsTab(Set<Pair<CommandManager.InternalCommand.InternalCommandInvoker, Integer>> commands, int depth, CommandManager.InternalCommand command, String[] args) { int nextDepth = depth + 1; if (command.isValid(args[depth], args.length == nextDepth)) { if (args.length != nextDepth) { @@ -294,52 +286,5 @@ public class PlatformCommandManagerImpl implements PlatformCommandManager { } } } - - //TODO: someone make the help command actually look nice lmao - private String sendHelpCommand(CommandManager.InternalCommand root) { - StringBuilder builder = new StringBuilder(); - builder.append(ChatColor.GOLD).append("Help for ").append(ChatColor.BOLD).append(root.name).append(ChatColor.RESET).append(ChatColor.GOLD).append(":\n"); - if (!root.description.isEmpty()) { - builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(root.description); - } - for (CommandManager.InternalCommand command : root.children) { - runThroughCommandsHelp(root.name, command, builder); - } - builder.append("\n").append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.BOLD); - int index = 0; - for (String alias : root.aliases) { - ++index; - builder.append(alias).append(index < root.aliases.length ? ", " : ""); - } - builder.append("\n"); - return builder.toString(); - } - - private void runThroughCommandsHelp(String append, CommandManager.InternalCommand command, StringBuilder builder) { - if (!command.invokers.isEmpty()) { - Class<?> declaringClass = command.invokers.get(0).method.getDeclaringClass(); - if (declaringClass.isAnnotationPresent(SubCommand.class)) { - String description = declaringClass.getAnnotation(SubCommand.class).description(); - if (!description.isEmpty()) { - builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(description); - } - } - } - for (CommandManager.InternalCommand.InternalCommandInvoker invoker : command.invokers) { - builder.append("\n").append(ChatColor.GOLD).append("/").append(append).append(" ").append(command.name); - for (Parameter parameter : invoker.method.getParameters()) { - String name = parameter.getName(); - if (parameter.isAnnotationPresent(Name.class)) { - name = parameter.getAnnotation(Name.class).value(); - } - builder.append(" <").append(name).append(">"); - } - if (!command.description.trim().isEmpty()) { - builder.append(": ").append(ChatColor.BOLD).append(command.description); - } - } - for (CommandManager.InternalCommand subCommand : command.children) { - runThroughCommandsHelp(append + " " + command.name, subCommand, builder); - } - } -}
\ No newline at end of file +} +//#endif
\ No newline at end of file diff --git a/versions/src/main/resources/META-INF/mods.toml b/versions/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..8050cf5 --- /dev/null +++ b/versions/src/main/resources/META-INF/mods.toml @@ -0,0 +1,30 @@ +modLoader="javafml" +loaderVersion="[32,)" +license="https://www.gnu.org/licenses/lgpl-3.0.en.html" +[[mods]] +modId="${id}" +version="${version}" +displayName="${name}" +authors="Polyfrost" +description="OneConfig" + +# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. +[[dependencies.oneconfig]] #optional +# the modid of the dependency +modId="forge" #mandatory +# Does this dependency have to exist - if not, ordering below must be specified +mandatory=true #mandatory +# The version range of the dependency +versionRange="[32,)" #mandatory +# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory +ordering="NONE" +# Side this dependency is applied on - BOTH, CLIENT or SERVER +side="BOTH" +# Here's another dependency +[[dependencies.oneconfig]] +modId="minecraft" +mandatory=true +# This version range declares a minimum of the current minecraft version up to but not including the next major version +versionRange="[1.16,)" +ordering="NONE" +side="BOTH"
\ No newline at end of file diff --git a/versions/src/main/resources/pack.mcmeta b/versions/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..5d61962 --- /dev/null +++ b/versions/src/main/resources/pack.mcmeta @@ -0,0 +1,7 @@ +{ + "pack": { + "description": "oneconfig resources", + "pack_format": 6, + "_comment": "A pack_format of 5 requires json lang files and some texture changes from 1.15. Note: we require v5 pack meta for all mods." + } +} |