diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-02 07:38:22 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-02 07:38:22 +0700 |
commit | a81bc67e90df2fddb8e2b8ad5ac6e13cf7c81032 (patch) | |
tree | 939ef5ca9e1911d3fa9186d3c7b8f2f9472952a5 | |
parent | 511269ba2d250893481cb55f84ae22cba9ba0dc6 (diff) | |
download | OneConfig-a81bc67e90df2fddb8e2b8ad5ac6e13cf7c81032.tar.gz OneConfig-a81bc67e90df2fddb8e2b8ad5ac6e13cf7c81032.tar.bz2 OneConfig-a81bc67e90df2fddb8e2b8ad5ac6e13cf7c81032.zip |
pass a UMatrixStack in HUD API
From 1.17+, most matrix transformations can only be done with a MatrixStack instance, thus to prepare for a OneConfig 1.17+ port this has been done.
10 files changed, 135 insertions, 24 deletions
diff --git a/api/OneConfig.api b/api/OneConfig.api index a0a2e2f..fa4e477 100644 --- a/api/OneConfig.api +++ b/api/OneConfig.api @@ -390,7 +390,8 @@ public class cc/polyfrost/oneconfig/events/event/ChatReceiveEvent : cc/polyfrost public class cc/polyfrost/oneconfig/events/event/HudRenderEvent { public final field deltaTicks F - public fun <init> (F)V + public final field matrices Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack; + public fun <init> (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;F)V } public class cc/polyfrost/oneconfig/events/event/InitializationEvent { @@ -877,11 +878,11 @@ public abstract class cc/polyfrost/oneconfig/hud/Hud { public fun <init> (ZII)V public fun <init> (ZIIFZIIILcc/polyfrost/oneconfig/config/core/OneColor;ZFLcc/polyfrost/oneconfig/config/core/OneColor;)V public fun <init> (ZIII)V - public abstract fun draw (IIF)V - public fun drawAll (FFFZ)V + public abstract fun draw (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V + public fun drawAll (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;FFFZ)V public fun drawBackground ()Z - public fun drawExample (IIF)V - public fun drawExampleAll (FFFZ)V + public fun drawExample (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V + public fun drawExampleAll (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;FFFZ)V public fun getExampleHeight (F)I public fun getExampleWidth (F)I public abstract fun getHeight (F)I @@ -913,7 +914,7 @@ public abstract class cc/polyfrost/oneconfig/hud/TextHud : cc/polyfrost/oneconfi public field textType I public fun <init> (Z)V public fun <init> (ZII)V - public fun draw (IIF)V + public fun draw (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V protected fun getExampleLines (Ljava/util/List;)V protected fun getExampleLinesFrequent (Ljava/util/List;)V public fun getHeight (F)I diff --git a/gradle.properties b/gradle.properties index 47a5aee..de53850 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ mod_name = OneConfig mod_id = oneconfig -mod_version = 0.1.0-alpha42 +mod_version = 0.1.0-alpha43 essential.defaults.loom=0 diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/HudRenderEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/HudRenderEvent.java index 465a2f6..41011aa 100644 --- a/src/main/java/cc/polyfrost/oneconfig/events/event/HudRenderEvent.java +++ b/src/main/java/cc/polyfrost/oneconfig/events/event/HudRenderEvent.java @@ -1,5 +1,7 @@ package cc.polyfrost.oneconfig.events.event; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; + /** * Called when external HUDs can be rendered. */ @@ -8,8 +10,10 @@ public class HudRenderEvent { * How much time has elapsed since the last tick, in ticks. Used for animations. */ public final float deltaTicks; + public final UMatrixStack matrices; - public HudRenderEvent(float deltaTicks) { + public HudRenderEvent(UMatrixStack matrices, float deltaTicks) { + this.matrices = matrices; this.deltaTicks = deltaTicks; } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java index 2c3e681..b45a1d8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java @@ -37,11 +37,11 @@ public class HudGui extends UScreen implements GuiPause { } for (Hud hud : HudCore.huds) { - if (hud.enabled) processHud(hud, mouseX); + if (hud.enabled) processHud(matrixStack, hud, mouseX); } } - private void processHud(Hud hud, int mouseX) { + private void processHud(UMatrixStack matrixStack, Hud hud, int mouseX) { if (hud == editingHud && isScaling) { float xFloat = hud.getXScaled(UResolution.getScaledWidth()); float yFloat = hud.getYScaled(UResolution.getScaledHeight()); @@ -65,7 +65,7 @@ public class HudGui extends UScreen implements GuiPause { int x = (int) hud.getXScaled(UResolution.getScaledWidth()); int y = (int) hud.getYScaled(UResolution.getScaledHeight()); - hud.drawExampleAll(x, y, hud.scale, true); + hud.drawExampleAll(matrixStack, x, y, hud.scale, true); int color = new Color(215, 224, 235).getRGB(); if (editingHud == hud) { color = new Color(43, 159, 235).getRGB(); diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java index 9c9a005..982bee9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java @@ -4,6 +4,7 @@ import cc.polyfrost.oneconfig.config.Config; import cc.polyfrost.oneconfig.config.annotations.Switch; import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; @@ -14,7 +15,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; * If you simply want to display text, extend {@link TextHud} or {@link SingleTextHud}, * whichever applies to the use case. Then, override the required methods. * <p> - * If you want to display something else, extend this class and override {@link Hud#getWidth(float)}, {@link Hud#getHeight(float)}, and {@link Hud#draw(int, int, float)} with the width, height, and the drawing code respectively. + * If you want to display something else, extend this class and override {@link Hud#getWidth(float)}, {@link Hud#getHeight(float)}, and {@link Hud#draw(UMatrixStack, int, int, float)} with the width, height, and the drawing code respectively. * </p> * <p> * It should also be noted that additional options to the HUD can be added simply by declaring them. @@ -115,7 +116,7 @@ public abstract class Hud { * @param y Top left y-coordinate of the hud * @param scale Scale of the hud */ - public abstract void draw(int x, int y, float scale); + public abstract void draw(UMatrixStack matrices, int x, int y, float scale); /** * Function called when drawing the example version of the hud. @@ -125,8 +126,8 @@ public abstract class Hud { * @param y Top left y-coordinate of the hud * @param scale Scale of the hud */ - public void drawExample(int x, int y, float scale) { - draw(x, y, scale); + public void drawExample(UMatrixStack matrices, int x, int y, float scale) { + draw(matrices, x, y, scale); } /** @@ -172,12 +173,12 @@ public abstract class Hud { * @param scale Scale of the hud * @param background If background should be drawn or not */ - public void drawAll(float x, float y, float scale, boolean background) { + public void drawAll(UMatrixStack matrices, float x, float y, float scale, boolean background) { if (!showInGuis && Platform.getGuiPlatform().getCurrentScreen() != null && !(Platform.getGuiPlatform().getCurrentScreen() instanceof OneConfigGui)) return; if (!showInChat && Platform.getGuiPlatform().isInChat()) return; if (!showInDebug && Platform.getGuiPlatform().isInDebug()) return; if (background && drawBackground()) drawBackground(x, y, getWidth(scale), getHeight(scale), scale); - draw((int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); + draw(matrices, (int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); } /** @@ -188,9 +189,9 @@ public abstract class Hud { * @param scale Scale of the hud * @param background If background should be drawn or not */ - public void drawExampleAll(float x, float y, float scale, boolean background) { + public void drawExampleAll(UMatrixStack matrices, float x, float y, float scale, boolean background) { if (background) drawBackground(x, y, getWidth(scale), getHeight(scale), scale); - drawExample((int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); + drawExample(matrices, (int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); } /** diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java index 3b74c4c..381e0a8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java @@ -8,7 +8,7 @@ import cc.polyfrost.oneconfig.events.event.Stage; import cc.polyfrost.oneconfig.events.event.TickEvent; import cc.polyfrost.oneconfig.internal.hud.HudCore; import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; -import cc.polyfrost.oneconfig.libs.universal.UMinecraft; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; @@ -75,7 +75,7 @@ public abstract class TextHud extends Hud { } @Override - public void draw(int x, int y, float scale) { + public void draw(UMatrixStack matrices, int x, int y, float scale) { if (!HudCore.editing) getLinesFrequent(lines); else getExampleLinesFrequent(lines); if (lines == null) return; diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java index 7912ec5..2bbd3b7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java @@ -16,7 +16,7 @@ public class HudCore { if (editing) return; for (Hud hud : huds) { if (hud.enabled) - hud.drawAll(hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true); + hud.drawAll(event.matrices, hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true); } } } diff --git a/versions/1.12.2-forge/api/1.12.2-forge.api b/versions/1.12.2-forge/api/1.12.2-forge.api new file mode 100644 index 0000000..ff8ae9e --- /dev/null +++ b/versions/1.12.2-forge/api/1.12.2-forge.api @@ -0,0 +1,103 @@ +public class cc/polyfrost/oneconfig/events/event/ChatReceiveEvent : cc/polyfrost/oneconfig/events/event/CancellableEvent { + public final field message Lnet/minecraft/util/text/ITextComponent; + public fun <init> (Lnet/minecraft/util/text/ITextComponent;)V + public fun getFullyUnformattedMessage ()Ljava/lang/String; +} + +public class cc/polyfrost/oneconfig/events/event/ReceivePacketEvent : cc/polyfrost/oneconfig/events/event/CancellableEvent { + public final field packet Lnet/minecraft/network/Packet; + public fun <init> (Lnet/minecraft/network/Packet;)V +} + +public class cc/polyfrost/oneconfig/events/event/ScreenOpenEvent : cc/polyfrost/oneconfig/events/event/CancellableEvent { + public final field screen Lnet/minecraft/client/gui/GuiScreen; + public fun <init> (Lnet/minecraft/client/gui/GuiScreen;)V +} + +public class cc/polyfrost/oneconfig/events/event/SendPacketEvent : cc/polyfrost/oneconfig/events/event/CancellableEvent { + public final field packet Lnet/minecraft/network/Packet; + public fun <init> (Lnet/minecraft/network/Packet;)V +} + +public class cc/polyfrost/oneconfig/events/event/TimerUpdateEvent { + public final field timer Lnet/minecraft/util/Timer; + public final field updatedDeltaTicks Z + public fun <init> (Lnet/minecraft/util/Timer;Z)V +} + +public class cc/polyfrost/oneconfig/platform/impl/GLPlatformImpl : cc/polyfrost/oneconfig/platform/GLPlatform { + public fun <init> ()V + public fun drawRect (FFFFI)V + public fun drawText (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;Ljava/lang/String;FFIZ)F + public fun enableStencil ()V + public fun getStringWidth (Ljava/lang/String;)I +} + +public class cc/polyfrost/oneconfig/platform/impl/GuiPlatformImpl : cc/polyfrost/oneconfig/platform/GuiPlatform { + public fun <init> ()V + public fun getCurrentScreen ()Ljava/lang/Object; + public fun isInChat ()Z + public fun isInDebug ()Z + public fun setCurrentScreen (Ljava/lang/Object;)V +} + +public class cc/polyfrost/oneconfig/platform/impl/I18nPlatformImpl : cc/polyfrost/oneconfig/platform/I18nPlatform { + public fun <init> ()V + public fun format (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; +} + +public class cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl : cc/polyfrost/oneconfig/platform/LoaderPlatform { + public fun <init> ()V + public fun getActiveModContainer ()Lcc/polyfrost/oneconfig/platform/LoaderPlatform$ActiveMod; + public fun hasActiveModContainer ()Z + public fun isModLoaded (Ljava/lang/String;)Z +} + +public class cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl : cc/polyfrost/oneconfig/platform/MousePlatform { + public fun <init> ()V + public fun getDWheel ()I + public fun getEventButton ()I + public fun getEventButtonState ()Z + public fun getMouseDX ()I + public fun getMouseDY ()I + public fun getMouseX ()I + public fun getMouseY ()I + public fun isButtonDown (I)Z + public fun next ()Z +} + +public class cc/polyfrost/oneconfig/platform/impl/PlatformImpl : cc/polyfrost/oneconfig/platform/Platform { + public fun <init> ()V + public fun isCallingFromMinecraftThread ()Z +} + +public class cc/polyfrost/oneconfig/platform/impl/ServerPlatformImpl : cc/polyfrost/oneconfig/platform/ServerPlatform { + public fun <init> ()V + public fun getServerBrand ()Ljava/lang/String; + public fun inMultiplayer ()Z +} + +public class cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl : cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager { + public fun <init> ()V + public fun createCommand (Lcc/polyfrost/oneconfig/utils/commands/CommandManager$InternalCommand;Lcc/polyfrost/oneconfig/utils/commands/annotations/Command;)V +} + +public final class cc/polyfrost/oneconfig/utils/dsl/DSLsKt { + public static final fun getMc ()Lnet/minecraft/client/Minecraft; +} + +public final class cc/polyfrost/oneconfig/utils/dsl/GuiUtilsDSLKt { + public static final fun openScreen (Lnet/minecraft/client/gui/GuiScreen;I)V + public static synthetic fun openScreen$default (Lnet/minecraft/client/gui/GuiScreen;IILjava/lang/Object;)V +} + +public final class cc/polyfrost/oneconfig/utils/gui/GuiUtils { + public fun <init> ()V + public static fun closeScreen ()V + public static fun displayScreen (Ljava/lang/Object;)V + public static fun displayScreen (Lnet/minecraft/client/gui/GuiScreen;)V + public static fun displayScreen (Lnet/minecraft/client/gui/GuiScreen;I)V + public static fun getDeltaTime ()F + public static fun getScreenQueue ()Ljava/util/Deque; +} + diff --git a/versions/1.12.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java b/versions/1.12.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java index 6c615c8..775e055 100644 --- a/versions/1.12.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java +++ b/versions/1.12.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java @@ -2,6 +2,7 @@ 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 net.minecraftforge.client.GuiIngameForge; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,6 +13,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class GuiIngameForgeMixin { @Inject(method = "renderGameOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;)V", shift = At.Shift.AFTER, remap = false), remap = true) private void onRenderGameOverlay(float partialTicks, CallbackInfo ci) { - EventManager.INSTANCE.post(new HudRenderEvent(partialTicks)); + EventManager.INSTANCE.post(new HudRenderEvent(new UMatrixStack(), partialTicks)); } }
\ No newline at end of file diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java index 2a89972..ebf4f0a 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java @@ -3,6 +3,7 @@ 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 net.minecraftforge.client.GuiIngameForge; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -13,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class GuiIngameForgeMixin { @Inject(method = "renderGameOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;)V", shift = At.Shift.AFTER, remap = false), remap = true) private void onRenderGameOverlay(float partialTicks, CallbackInfo ci) { - EventManager.INSTANCE.post(new HudRenderEvent(partialTicks)); + EventManager.INSTANCE.post(new HudRenderEvent(new UMatrixStack(), partialTicks)); } } //#endif
\ No newline at end of file |