From fecb67e07ded0d20b12d3bdb48fea3e2e50b7f88 Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Sun, 3 Jul 2022 21:11:39 +0700 Subject: little trolling --- .../internal/mixin/ClientModLoaderMixin.java | 23 ++++++++ .../internal/mixin/GuiIngameForgeMixin.java | 19 +++++++ .../internal/mixin/KeyboardListenerMixin.java | 17 ++++++ .../oneconfig/internal/mixin/MinecraftMixin.java | 66 ++++++++++++++++++++++ .../oneconfig/internal/mixin/MouseHelperMixin.java | 17 ++++++ .../internal/mixin/NetHandlerPlayClientMixin.java | 25 ++++++++ .../internal/mixin/NetworkManagerMixin.java | 42 ++++++++++++++ .../oneconfig/internal/mixin/TimeTrackerMixin.java | 22 ++++++++ .../oneconfig/internal/mixin/WorldClientMixin.java | 25 ++++++++ 9 files changed, 256 insertions(+) create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java (limited to 'versions/1.16.2-forge/src/main/java/cc') diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java new file mode 100644 index 0000000..2bfbaef --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java @@ -0,0 +1,23 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.InitializationEvent; +import net.minecraftforge.fml.client.ClientModLoader; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = ClientModLoader.class, remap = false) +public class ClientModLoaderMixin { //todo + @Inject(method = "begin", at = @At("HEAD")) + private static void onBegin(CallbackInfo ci) { + OneConfig.preLaunch(); + } + + @Inject(method = "finishModLoading", at = @At("HEAD")) + private static void onFinishModLoading(CallbackInfo ci) { + EventManager.INSTANCE.post(new InitializationEvent()); + OneConfig.init(); + } +} diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java new file mode 100644 index 0000000..f4ea663 --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java @@ -0,0 +1,19 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.HudRenderEvent; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; +import com.mojang.blaze3d.matrix.MatrixStack; +import net.minecraftforge.client.gui.ForgeIngameGui; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = ForgeIngameGui.class, remap = false) +public class GuiIngameForgeMixin { + @Inject(method = "renderIngameGui", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/gui/ForgeIngameGui;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;Lcom/mojang/blaze3d/matrix/MatrixStack;)V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onRenderGameOverlay(MatrixStack matrixStack, float partialTicks, CallbackInfo ci) { + EventManager.INSTANCE.post(new HudRenderEvent(new UMatrixStack(), partialTicks)); + } +} \ No newline at end of file diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java new file mode 100644 index 0000000..5cd10cf --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java @@ -0,0 +1,17 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.KeyInputEvent; +import net.minecraft.client.KeyboardListener; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(KeyboardListener.class) +public class KeyboardListenerMixin { //todo + @Inject(method = "onKeyEvent", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;fireKeyInput(IIII)V")) + private void onKeyEvent(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo ci) { + EventManager.INSTANCE.post(new KeyInputEvent()); + } +} diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java new file mode 100644 index 0000000..26ede28 --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java @@ -0,0 +1,66 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.*; +import net.minecraft.client.Minecraft; +import net.minecraft.util.Timer; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.eventbus.api.Event; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Minecraft.class) +public class MinecraftMixin { + @Final + @Shadow + private Timer timer; + + @Inject(method = "shutdownMinecraftApplet", at = @At("HEAD")) + private void onShutdown(CallbackInfo ci) { + EventManager.INSTANCE.post(new PreShutdownEvent()); + } + + @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/hooks/BasicEventHooks;onRenderTickStart(F)V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onRenderTickStart(CallbackInfo ci) { + EventManager.INSTANCE.post(new RenderEvent(Stage.START, timer.renderPartialTicks)); + } + + @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/hooks/BasicEventHooks;onRenderTickEnd(F)V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onRenderTickEnd(CallbackInfo ci) { + EventManager.INSTANCE.post(new RenderEvent(Stage.END, timer.renderPartialTicks)); + } + + @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/hooks/BasicEventHooks;onPreClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onClientTickStart(CallbackInfo ci) { + EventManager.INSTANCE.post(new TickEvent(Stage.START)); + } + + @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/hooks/BasicEventHooks;onPostClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true) + private void onClientTickEnd(CallbackInfo ci) { + EventManager.INSTANCE.post(new TickEvent(Stage.END)); + } + + @ModifyArg(method = "displayGuiScreen", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/eventbus/api/IEventBus;post(Lnet/minecraftforge/eventbus/api/Event;)Z", remap = false), remap = true) + private Event onGuiOpenEvent(Event a) { + if (a instanceof GuiOpenEvent) { + GuiOpenEvent forgeEvent = (GuiOpenEvent) a; + ScreenOpenEvent event = new ScreenOpenEvent(forgeEvent.getGui()); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + forgeEvent.setCanceled(true); + } + return forgeEvent; + } + return a; + } + + @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Timer;getPartialTicks(J)I", shift = At.Shift.AFTER)) + private void onDeltaTickTimerUpdate(CallbackInfo ci) { + EventManager.INSTANCE.post(new TimerUpdateEvent(timer, true)); + } +} \ No newline at end of file diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java new file mode 100644 index 0000000..95a5b0c --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java @@ -0,0 +1,17 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.MouseInputEvent; +import net.minecraft.client.MouseHelper; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MouseHelper.class) +public class MouseHelperMixin { //todo + @Inject(method = "mouseButtonCallback", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;fireMouseInput(III)V")) + private void onMouse(long handle, int button, int action, int mods, CallbackInfo ci) { + EventManager.INSTANCE.post(new MouseInputEvent()); + } +} diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java new file mode 100644 index 0000000..dfee688 --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java @@ -0,0 +1,25 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.ChatReceiveEvent; +import net.minecraft.client.network.play.ClientPlayNetHandler; +import net.minecraft.network.play.server.SChatPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = ClientPlayNetHandler.class, priority = Integer.MAX_VALUE) +public class NetHandlerPlayClientMixin { + + @Inject(method = "handleChat", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;onClientChat(Lnet/minecraft/util/text/ChatType;Lnet/minecraft/util/text/ITextComponent;Ljava/util/UUID;)Lnet/minecraft/util/text/ITextComponent;", remap = false), cancellable = true, remap = true) + private void onClientChat(SChatPacket packetIn, CallbackInfo ci) { + if (packetIn.getType().getId() == 0) { + ChatReceiveEvent event = new ChatReceiveEvent(packetIn.getChatComponent()); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } + } +} \ No newline at end of file diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java new file mode 100644 index 0000000..35b987a --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java @@ -0,0 +1,42 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.ReceivePacketEvent; +import cc.polyfrost.oneconfig.events.event.SendPacketEvent; +import io.netty.channel.ChannelHandlerContext; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; +import net.minecraft.network.IPacket; +import net.minecraft.network.NetworkManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = NetworkManager.class, priority = Integer.MAX_VALUE) +public class NetworkManagerMixin { + + @Inject(method = "sendPacket(Lnet/minecraft/network/IPacket;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("HEAD"), cancellable = true) + private void onSendPacket(IPacket packetIn, GenericFutureListener> genericFutureListener, CallbackInfo ci) { + onSendPacket(packetIn, ci); + } + + @Inject(method = "sendPacket(Lnet/minecraft/network/IPacket;)V", at = @At("HEAD"), cancellable = true) + private void onSendPacket(IPacket packetIn, CallbackInfo ci) { + SendPacketEvent event = new SendPacketEvent(packetIn); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } + + + @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/IPacket;)V", at = @At("HEAD"), cancellable = true) + private void onReceivePacket(ChannelHandlerContext channelHandlerContext, IPacket arg, CallbackInfo ci) { + ReceivePacketEvent event = new ReceivePacketEvent(arg); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } +} \ No newline at end of file diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java new file mode 100644 index 0000000..e2d31fe --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java @@ -0,0 +1,22 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.ShutdownEvent; +import cc.polyfrost.oneconfig.events.event.StartEvent; +import net.minecraft.profiler.TimeTracker; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.IntSupplier; +import java.util.function.LongSupplier; + +@Mixin(TimeTracker.class) +public class TimeTrackerMixin { //todo + @Inject(method = "", at = @At("RETURN")) + private void onStart(LongSupplier longSupplier, IntSupplier intSupplier, CallbackInfo ci) { + EventManager.INSTANCE.post(new StartEvent()); + Runtime.getRuntime().addShutdownHook(new Thread(() -> EventManager.INSTANCE.post(new ShutdownEvent()))); + } +} diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java new file mode 100644 index 0000000..d98b0db --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java @@ -0,0 +1,25 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.WorldLoadEvent; +import net.minecraft.client.network.play.ClientPlayNetHandler; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.profiler.IProfiler; +import net.minecraft.util.RegistryKey; +import net.minecraft.world.DimensionType; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.Supplier; + +@Mixin(ClientWorld.class) +public class WorldClientMixin { + @Inject(method = "", at = @At("RETURN")) + private void onWorldLoad(ClientPlayNetHandler arg, ClientWorld.ClientWorldInfo arg2, RegistryKey arg3, DimensionType arg4, int i, Supplier supplier, WorldRenderer arg5, boolean bl, long l, CallbackInfo ci) { + EventManager.INSTANCE.post(new WorldLoadEvent()); + } +} \ No newline at end of file -- cgit From 206063acf3a6e0edc0d16b07d206aa36207b42d4 Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Tue, 5 Jul 2022 22:37:47 +0900 Subject: a --- build.gradle.kts | 6 - .../gui/elements/text/TextInputField.java | 44 ++- .../cc/polyfrost/oneconfig/gui/pages/Page.java | 2 +- .../internal/plugin/OneConfigMixinPlugin.java | 129 -------- .../oneconfig/platform/MousePlatform.java | 14 +- .../cc/polyfrost/oneconfig/platform/Platform.java | 2 + .../cc/polyfrost/oneconfig/utils/InputUtils.java | 4 +- .../utils/commands/PlatformCommandManager.java | 63 +++- versions/1.12.2-1.16.2.txt | 18 +- .../internal/mixin/ClientModLoaderMixin.java | 5 +- .../internal/mixin/KeyboardListenerMixin.java | 2 +- .../internal/mixin/MouseHelperAccessor.java | 11 + .../oneconfig/internal/mixin/MouseHelperMixin.java | 2 +- .../oneconfig/internal/mixin/TimeTrackerMixin.java | 2 +- .../utils/commands/PlatformCommandManagerImpl.java | 123 ++++++++ versions/build.gradle.kts | 61 ++-- .../cc/polyfrost/oneconfig/internal/OneConfig.java | 13 - .../internal/gui/impl/BlurHandlerImpl.java | 15 +- .../internal/plugin/OneConfigMixinPlugin.java | 140 +++++++++ .../internal/plugin/asm/ClassTransformer.java | 4 +- .../internal/plugin/asm/OneConfigTweaker.java | 4 +- .../platform/impl/LoaderPlatformImpl.java | 12 +- .../oneconfig/platform/impl/MousePlatformImpl.java | 65 ++-- .../oneconfig/platform/impl/PlatformImpl.java | 29 ++ .../cc/polyfrost/oneconfig/test/TestMod_Test.java | 16 +- .../utils/commands/PlatformCommandManagerImpl.java | 333 +++++++++------------ versions/src/main/resources/META-INF/mods.toml | 30 ++ versions/src/main/resources/pack.mcmeta | 7 + 28 files changed, 718 insertions(+), 438 deletions(-) delete mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperAccessor.java create mode 100644 versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java create mode 100644 versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java create mode 100644 versions/src/main/resources/META-INF/mods.toml create mode 100644 versions/src/main/resources/pack.mcmeta (limited to 'versions/1.16.2-forge/src/main/java/cc') diff --git a/build.gradle.kts b/build.gradle.kts index 8d888c4..3d48b72 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -59,12 +59,6 @@ val shade: Configuration by configurations.creating { val shadeNoPom: Configuration by configurations.creating -sourceSets { - main { - output.setResourcesDir(java.classesDirectory) - } -} - val common = registerStripReferencesAttribute("common") { excludes.add("net.minecraft") excludes.add("net.minecraftforge") diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java index 40463df..552051f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java @@ -143,32 +143,26 @@ public class TextInputField extends BasicElement { width = RenderManager.getTextWidth(vg, s.substring(0, caretPos), 14f, Fonts.REGULAR.font); } if (hovered) { - while (Platform.getMousePlatform().next()) { - if (Platform.getMousePlatform().getEventButtonState()) { - if (Platform.getMousePlatform().getEventButton() == 0) { - if (multiLine) { - int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f))); - caretPos = calculatePos(InputUtils.mouseX(), wrappedText.get(caretLine)); - } else prevCaret = calculatePos(InputUtils.mouseX(), input); - if (System.currentTimeMillis() - clickTimeD1 < 300) { - onDoubleClick(); - isDoubleClick = true; - } - clickTimeD1 = System.currentTimeMillis(); - } - } else { - if (Platform.getMousePlatform().getEventButton() == 0) { - long clickTimeU = System.currentTimeMillis(); - if (clickTimeU - clickTimeD1 < 200) { - if (!isDoubleClick) { - start = 0; - end = 0; - } - prevCaret = caretPos; - isDoubleClick = false; - } - + int state = Platform.getMousePlatform().getButtonState(0); //todo does this work + if (state == 1) { + if (multiLine) { + int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f))); + caretPos = calculatePos(InputUtils.mouseX(), wrappedText.get(caretLine)); + } else prevCaret = calculatePos(InputUtils.mouseX(), input); + if (System.currentTimeMillis() - clickTimeD1 < 300) { + onDoubleClick(); + isDoubleClick = true; + } + clickTimeD1 = System.currentTimeMillis(); + } else { + long clickTimeU = System.currentTimeMillis(); + if (clickTimeU - clickTimeD1 < 200) { + if (!isDoubleClick) { + start = 0; + end = 0; } + prevCaret = caretPos; + isDoubleClick = false; } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java index ddf6a3f..028f098 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -52,7 +52,7 @@ public abstract class Page { final float scrollBarLength = (728f / maxScroll) * 728f; Scissor scissor = ScissorManager.scissor(vg, x, y + scissorOffset, x + 1056, y + 728 - scissorOffset); Scissor inputScissor = InputUtils.blockInputArea(x, y,1056, scissorOffset); - int dWheel = Platform.getMousePlatform().getDWheel(); + int dWheel = (int) Platform.getMousePlatform().getDWheel(); if (dWheel != 0) { scrollTarget += dWheel; diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java deleted file mode 100644 index 0ef2c58..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java +++ /dev/null @@ -1,129 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin; - -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.spongepowered.asm.lib.tree.*; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import java.io.File; -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 myTargets, Set otherTargets) { - - } - - @Override - public List getMixins() { - return null; - } - - @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } - - @Override - public void postApply(String targetClassName, 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(ClassNode node) { - if (!node.interfaces.contains("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor")) { - node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC, "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", null, null)); - node.fields.add(new 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"); - MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "getPropertyCollector", "()Lgg/essential/vigilance/data/PropertyCollector;", null, null); - LabelNode labelNode = new LabelNode(); - methodNode.instructions.add(labelNode); - methodNode.instructions.add(new LineNumberNode(421421, labelNode)); - methodNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "propertyCollector", "Lgg/essential/vigilance/data/PropertyCollector;")); - methodNode.instructions.add(new InsnNode(Opcodes.ARETURN)); - node.methods.add(methodNode); - - MethodNode methodNode2 = new MethodNode(Opcodes.ACC_PUBLIC, "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", null, null); - LabelNode labelNode2 = new LabelNode(); - LabelNode labelNode3 = new LabelNode(); - LabelNode labelNode4 = new LabelNode(); - methodNode2.instructions.add(labelNode2); - methodNode2.instructions.add(new LineNumberNode(15636436, labelNode2)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); - - methodNode2.instructions.add(new JumpInsnNode(Opcodes.IFNULL, labelNode4)); - - methodNode2.instructions.add(labelNode3); - methodNode2.instructions.add(new LineNumberNode(15636437, labelNode3)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 2)); - methodNode2.instructions.add(new 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 LineNumberNode(15636438, labelNode4)); - methodNode2.instructions.add(new InsnNode(Opcodes.RETURN)); - node.methods.add(methodNode2); - - for (MethodNode method : node.methods) { - if (method.name.equals("initialize")) { - InsnList list = new InsnList(); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); - list.add(new 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 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")) { - InsnList list = new InsnList(); - - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 1)); - list.add(new VarInsnNode(Opcodes.ALOAD, 2)); - list.add(new 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("") && method.desc.equals("(Ljava/io/File;Ljava/lang/String;Lgg/essential/vigilance/data/PropertyCollector;Lgg/essential/vigilance/data/SortingBehavior;)V")) { - InsnList list = new InsnList(); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 1)); - list.add(new FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/platform/MousePlatform.java b/src/main/java/cc/polyfrost/oneconfig/platform/MousePlatform.java index add5f4f..3d7d735 100644 --- a/src/main/java/cc/polyfrost/oneconfig/platform/MousePlatform.java +++ b/src/main/java/cc/polyfrost/oneconfig/platform/MousePlatform.java @@ -1,15 +1,13 @@ package cc.polyfrost.oneconfig.platform; public interface MousePlatform { - int getMouseX(); - int getMouseY(); - int getDWheel(); - int getMouseDX(); - int getMouseDY(); + double getMouseX(); + double getMouseY(); + double getDWheel(); + double getMouseDX(); + double getMouseDY(); - boolean next(); - boolean getEventButtonState(); - int getEventButton(); + int getButtonState(int button); boolean isButtonDown(int button); } diff --git a/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java b/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java index 3eea049..62e9e2a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java +++ b/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java @@ -39,6 +39,8 @@ public interface Platform { boolean isCallingFromMinecraftThread(); + int getMinecraftVersion(); + class PlatformHolder { private PlatformHolder() { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java index a48d369..6582eaa 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java @@ -96,7 +96,7 @@ public final class InputUtils { * @return the current mouse X position */ public static int mouseX() { - if (OneConfigGui.INSTANCE == null) return Platform.getMousePlatform().getMouseX(); + if (OneConfigGui.INSTANCE == null) return (int) Platform.getMousePlatform().getMouseX(); //todo stop casting and actually use doubles return (int) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor()); } @@ -110,7 +110,7 @@ public final class InputUtils { * @return the current mouse Y position */ public static int mouseY() { - if (OneConfigGui.INSTANCE == null) return UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY()); + if (OneConfigGui.INSTANCE == null) return (int) (UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())); return (int) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor()); } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java index a02f4ff..1ab356c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java @@ -1,7 +1,66 @@ package cc.polyfrost.oneconfig.utils.commands; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; import cc.polyfrost.oneconfig.utils.commands.annotations.Command; +import cc.polyfrost.oneconfig.utils.commands.annotations.Name; +import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; +import cc.polyfrost.oneconfig.utils.commands.arguments.ArgumentParser; -public interface PlatformCommandManager { - void createCommand(CommandManager.InternalCommand root, Command annotation); +import java.lang.reflect.Parameter; + +public abstract class PlatformCommandManager { + + //TODO: someone make the help command actually look nice lmao + protected 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(); + } + + protected 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); + } + } + + abstract void createCommand(CommandManager.InternalCommand root, Command annotation); + + public void handleNewParser(ArgumentParser parser, Class clazz) { + + } } diff --git a/versions/1.12.2-1.16.2.txt b/versions/1.12.2-1.16.2.txt index 5171175..5d0f09b 100644 --- a/versions/1.12.2-1.16.2.txt +++ b/versions/1.12.2-1.16.2.txt @@ -9,8 +9,22 @@ net.minecraft.client.entity.EntityPlayerSP net.minecraft.client.entity.player.Cl net.minecraft.launchwrapper.IClassTransformer transform() transformClassBytes() net.minecraft.launchwrapper.IClassTransformer org.spongepowered.asm.service.ILegacyClassTransformer net.minecraft.client.Minecraft entityRenderer gameRenderer -net.minecraftforge.fml.common.event.FMLInitializationEvent net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent net.minecraft.client.shader.ShaderUniform net.minecraft.client.shader.ShaderDefault + +net.minecraftforge.fml.common.event.FMLInitializationEvent net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent net.minecraftforge.fml.common.Loader instance() get() +net.minecraftforge.fml.common.Loader activeModContainer() getActiveContainer() net.minecraftforge.fml.common.Loader net.minecraftforge.fml.ModLoadingContext -net.minecraftforge.fml.common.ModContainer net.minecraftforge.fml.ModContainer \ No newline at end of file +net.minecraftforge.fml.common.ModContainer net.minecraftforge.fml.ModContainer + +org.spongepowered.asm.lib.tree.ClassNode org.objectweb.asm.tree.ClassNode +org.spongepowered.asm.lib.tree.FieldNode org.objectweb.asm.tree.FieldNode +org.spongepowered.asm.lib.tree.MethodNode org.objectweb.asm.tree.MethodNode +org.spongepowered.asm.lib.tree.LabelNode org.objectweb.asm.tree.LabelNode +org.spongepowered.asm.lib.tree.LineNumberNode org.objectweb.asm.tree.LineNumberNode +org.spongepowered.asm.lib.tree.VarInsnNode org.objectweb.asm.tree.VarInsnNode +org.spongepowered.asm.lib.tree.FieldInsnNode org.objectweb.asm.tree.FieldInsnNode +org.spongepowered.asm.lib.tree.MethodInsnNode org.objectweb.asm.tree.MethodInsnNode +org.spongepowered.asm.lib.tree.InsnList org.objectweb.asm.tree.InsnList +org.spongepowered.asm.lib.tree.InsnNode org.objectweb.asm.tree.InsnNode +org.spongepowered.asm.lib.tree.JumpInsnNode org.objectweb.asm.tree.JumpInsnNode \ No newline at end of file diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java index 2bfbaef..b0caed6 100644 --- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java @@ -2,6 +2,7 @@ package cc.polyfrost.oneconfig.internal.mixin; import cc.polyfrost.oneconfig.events.EventManager; import cc.polyfrost.oneconfig.events.event.InitializationEvent; +import cc.polyfrost.oneconfig.internal.OneConfig; import net.minecraftforge.fml.client.ClientModLoader; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -9,13 +10,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = ClientModLoader.class, remap = false) -public class ClientModLoaderMixin { //todo +public class ClientModLoaderMixin { @Inject(method = "begin", at = @At("HEAD")) private static void onBegin(CallbackInfo ci) { OneConfig.preLaunch(); } - @Inject(method = "finishModLoading", at = @At("HEAD")) + @Inject(method = "lambda$finishModLoading$9", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/GameSettings;loadOptions()V")) private static void onFinishModLoading(CallbackInfo ci) { EventManager.INSTANCE.post(new InitializationEvent()); OneConfig.init(); diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java index 5cd10cf..c7e6327 100644 --- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(KeyboardListener.class) -public class KeyboardListenerMixin { //todo +public class KeyboardListenerMixin { @Inject(method = "onKeyEvent", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;fireKeyInput(IIII)V")) private void onKeyEvent(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo ci) { EventManager.INSTANCE.post(new KeyInputEvent()); diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperAccessor.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperAccessor.java new file mode 100644 index 0000000..d04ecb1 --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperAccessor.java @@ -0,0 +1,11 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import net.minecraft.client.MouseHelper; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(MouseHelper.class) +public interface MouseHelperAccessor { + @Accessor + double getAccumulatedScrollDelta(); +} diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java index 95a5b0c..42dd283 100644 --- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(MouseHelper.class) -public class MouseHelperMixin { //todo +public class MouseHelperMixin { @Inject(method = "mouseButtonCallback", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;fireMouseInput(III)V")) private void onMouse(long handle, int button, int action, int mods, CallbackInfo ci) { EventManager.INSTANCE.post(new MouseInputEvent()); diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java index e2d31fe..dd9920e 100644 --- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java @@ -13,7 +13,7 @@ import java.util.function.IntSupplier; import java.util.function.LongSupplier; @Mixin(TimeTracker.class) -public class TimeTrackerMixin { //todo +public class TimeTrackerMixin { @Inject(method = "", at = @At("RETURN")) private void onStart(LongSupplier longSupplier, IntSupplier intSupplier, CallbackInfo ci) { EventManager.INSTANCE.post(new StartEvent()); diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java new file mode 100644 index 0000000..81bc9b2 --- /dev/null +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java @@ -0,0 +1,123 @@ +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.arguments.ArgumentParser; +import cc.polyfrost.oneconfig.utils.commands.arguments.Arguments; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Parameter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.CompletableFuture; + +import static cc.polyfrost.oneconfig.utils.commands.CommandManager.METHOD_RUN_ERROR; + +public class PlatformCommandManagerImpl extends PlatformCommandManager { + + final HashMap, Pair, ArgumentType>> parsers = new HashMap<>(); // non-greedy, greedy + + @Override + void createCommand(CommandManager.InternalCommand root, Command annotation) { + LiteralArgumentBuilder builder = Commands.literal(annotation.value()); + if (!root.invokers.isEmpty()) { + builder.executes((context -> + { + try { + root.invokers.get(0).method.invoke(null); + return 1; + } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException | + ExceptionInInitializerError e) { + UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR); + return 0; + } + })); + } + if (annotation.helpCommand()) { + builder.then(Commands.literal("help").executes((context -> + { + UChat.chat(sendHelpCommand(root)); + return 1; + }))); + } + for (CommandManager.InternalCommand command : root.children) { + loopThroughChildren(command, builder, null); + } + } + + private void loopThroughChildren(CommandManager.InternalCommand command, LiteralArgumentBuilder root, LiteralArgumentBuilder builder) { + if (command.invokers.isEmpty() || command.children.isEmpty()) return; + if (builder == null) { + builder = root.then(Commands.literal(command.name)); + } else { + builder = builder.then(Commands.literal(command.name)); + } + for (CommandManager.InternalCommand.InternalCommandInvoker invoker : command.invokers) { + for (Parameter parameter : invoker.method.getParameters()) { + Pair, ArgumentType> pair = parsers.get(parameter.getType()); + builder.then(Commands.argument(parameter.getName(), parameter.isAnnotationPresent(Greedy.class) ? pair.getRight() : pair.getLeft())); + } + builder.executes((context -> + { + try { + ArrayList args = new ArrayList<>(invoker.method.getParameterCount()); + for (Parameter parameter: invoker.method.getParameters()) { + args.add(context.getArgument(parameter.getName(), Object.class)); + } + invoker.method.invoke(null, args); + return 1; + } catch (Exception e) { + e.printStackTrace(); + UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR); + return 0; + } + })); + } + for (CommandManager.InternalCommand child : command.children) { + loopThroughChildren(child, root, builder); + } + } + + @Override + public void handleNewParser(ArgumentParser parser, Class clazz) { + parsers.put(clazz, new ImmutablePair, ArgumentType>(new ArgumentType() { + + @Override + public Object parse(StringReader reader) { + final String text = reader.getRemaining(); + reader.setCursor(reader.getTotalLength()); + return parser.parse(new Arguments(text.split("\\s+"), false)); + } + + @Override + public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { + return ArgumentType.super.listSuggestions(context, builder); + } + }, new ArgumentType() { + + @Override + public Object parse(StringReader reader) { + final String text = reader.getRemaining(); + reader.setCursor(reader.getTotalLength()); + return parser.parse(new Arguments(text.split("\\s+"), true)); + } + + @Override + public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { + return ArgumentType.super.listSuggestions(context, builder); + } + })); + } +} diff --git a/versions/build.gradle.kts b/versions/build.gradle.kts index 1863fd4..b140fbd 100644 --- a/versions/build.gradle.kts +++ b/versions/build.gradle.kts @@ -2,6 +2,7 @@ import gg.essential.gradle.util.RelocationTransform.Companion.registerRelocation import gg.essential.gradle.util.noServerRunConfigs import gg.essential.gradle.util.prebundle import net.fabricmc.loom.task.RemapSourcesJarTask +import java.text.SimpleDateFormat plugins { @@ -47,11 +48,15 @@ base { } loom { noServerRunConfigs() - if (project.platform.isLegacyForge) { - launchConfigs.named("client") { + launchConfigs.named("client") { + if (project.platform.isLegacyForge) { arg("--tweakClass", "cc.polyfrost.oneconfig.internal.plugin.asm.OneConfigTweaker") - property("mixin.debug.export", "true") - property("debugBytecode", "true") + } + property("mixin.debug.export", "true") + property("debugBytecode", "true") + property("forge.logging.console.level", "debug") + if (org.gradle.internal.os.OperatingSystem.current().isMacOsX) { + property("fml.earlyprogresswindow", "false") } } if (project.platform.isForge) { @@ -59,6 +64,9 @@ loom { mixinConfig("mixins.${mod_id}.json") } } + log4jConfigs.asFileTree.files.forEach { + it.writeText(it.readText().replace("warn", "debug")) + } mixin.defaultRefmapName.set("mixins.${mod_id}.refmap.json") } @@ -85,10 +93,13 @@ val shade: Configuration by configurations.creating { } val shadeNoPom: Configuration by configurations.creating +val shadeNoPom2: Configuration by configurations.creating sourceSets { main { - output.setResourcesDir(java.classesDirectory) + if (project.platform.isForge) { + output.setResourcesDir(java.classesDirectory) + } } } @@ -105,8 +116,7 @@ dependencies { isTransitive = false } - @Suppress("GradlePackageUpdate") - shadeRelocated("com.github.ben-manes.caffeine:caffeine:2.9.3") + @Suppress("GradlePackageUpdate") shadeRelocated("com.github.ben-manes.caffeine:caffeine:2.9.3") // for other mods and universalcraft val kotlinVersion: String by project @@ -126,14 +136,19 @@ dependencies { shade("org.jetbrains.kotlinx:kotlinx-serialization-cbor-jvm:$serializationVersion") shade("org.jetbrains.kotlinx:atomicfu-jvm:$atomicfuVersion") - shade("org.spongepowered:mixin:0.7.11-SNAPSHOT") { - isTransitive = false + if (platform.isLegacyForge) { + shade("org.spongepowered:mixin:0.7.11-SNAPSHOT") { + isTransitive = false + } } shadeNoPom(project(":")) { isTransitive = false } shade("cc.polyfrost:lwjgl:1.0.0-alpha1") - shadeNoPom(prebundle(shadeRelocated)) + val prebundled = prebundle(shadeRelocated) + modCompileOnly(prebundled) + modRuntimeOnly(prebundled) + shadeNoPom2(prebundled) dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.6.21") @@ -155,7 +170,7 @@ tasks { inputs.property("java_level", compatLevel) inputs.property("version", mod_version) inputs.property("mcVersionStr", project.platform.mcVersionStr) - filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "mods.toml")) { + filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "**/mods.toml")) { expand( mapOf( "id" to mod_id, @@ -184,11 +199,11 @@ tasks { withType(Jar::class.java) { duplicatesStrategy = DuplicatesStrategy.EXCLUDE if (project.platform.isFabric) { - exclude("mcmod.info", "mods.toml") + exclude("mcmod.info", "META-INF/mods.toml") } else { exclude("fabric.mod.json") if (project.platform.isLegacyForge) { - exclude("mods.toml") + exclude("**/mods.toml") exclude("META-INF/versions/**") exclude("**/module-info.class") exclude("**/package-info.class") @@ -204,7 +219,7 @@ tasks { val shadowJar = named("shadowJar") { archiveClassifier.set("full-dev") - configurations = listOf(shade, shadeNoPom) + configurations = listOf(shade, shadeNoPom, shadeNoPom2) duplicatesStrategy = DuplicatesStrategy.EXCLUDE dependsOn(jar) } @@ -219,8 +234,9 @@ tasks { } jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE - dependsOn(shadeNoPom) - from(shadeNoPom.map { if (it.isDirectory) it else zipTree(it) }) + dependsOn(shadeNoPom, shadeNoPom2) + from(ArrayList().run { addAll(shadeNoPom); addAll(shadeNoPom2); this } + .map { if (it.isDirectory) it else zipTree(it) }) manifest { attributes( mapOf( @@ -228,10 +244,21 @@ tasks { "ForceLoadAsMod" to true, "TweakOrder" to "0", "MixinConfigs" to "mixins.oneconfig.json", - "TweakClass" to "cc.polyfrost.oneconfig.internal.plugin.asm.OneConfigTweaker" + "TweakClass" to "cc.polyfrost.oneconfig.internal.plugin.asm.OneConfigTweaker", + "FMLModType" to "LIBRARY", + "Specification-Title" to mod_id, + "Specification-Vendor" to mod_id, + "Specification-Version" to "1", // We are version 1 of ourselves, whatever the hell that means + "Implementation-Title" to mod_name, + "Implementation-Version" to mod_version, + "Implementation-Vendor" to mod_id, + "Implementation-Timestamp" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(`java.util`.Date()) ) ) } + /*/ + + */ excludeInternal() archiveClassifier.set("") } 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 myTargets, Set otherTargets) { + + } + + @Override + public List getMixins() { + if (Platform.getInstance().getMinecraftVersion() >= 11600) { + ArrayList 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("") && 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 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 errors = new ArrayList<>(); + for (CommandManager.InternalCommand.InternalCommandInvoker invoker : commands) { + try { + List 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 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> commands = new HashSet<>(); + for (CommandManager.InternalCommand command : root.children) { + loopThroughCommandsTab(commands, 0, command, args); } - } else { - List errors = new ArrayList<>(); - for (CommandManager.InternalCommand.InternalCommandInvoker invoker : commands) { - try { - List 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> validCommands = new ArrayList<>(); // command, depth, and all processed params + for (Pair 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 completions = new HashSet<>(); + for (Triple 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 possibleCompletions = parser.complete(arguments, param); + if (possibleCompletions != null) { + completions.addAll(possibleCompletions); + } + } catch (Exception ignored) { - private List handleTabCompletion(CommandManager.InternalCommand root, Command annotation, String[] args) { - try { - Set> commands = new HashSet<>(); - for (CommandManager.InternalCommand command : root.children) { - loopThroughCommandsTab(commands, 0, command, args); - } - if (!commands.isEmpty() || annotation.helpCommand()) { - List> validCommands = new ArrayList<>(); // command, depth, and all processed params - for (Pair 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 completions = new HashSet<>(); - for (Triple 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 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 getParametersForInvoker(CommandManager.InternalCommand.InternalCommandInvoker invoker, int depth, String[] args) { + protected List getParametersForInvoker(CommandManager.InternalCommand.InternalCommandInvoker invoker, int depth, String[] args) { List parameters = new ArrayList<>(); int processed = depth; int currentParam = 0; @@ -249,7 +241,7 @@ public class PlatformCommandManagerImpl implements PlatformCommandManager { return parameters; } - private int loopThroughCommands(List commands, int depth, CommandManager.InternalCommand command, String[] args) { + protected int loopThroughCommands(List 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> commands, int depth, CommandManager.InternalCommand command, String[] args) { + protected void loopThroughCommandsTab(Set> 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." + } +} -- cgit