diff options
author | inglettronald <inglettronald@gmail.com> | 2023-06-11 22:57:55 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-06-11 22:57:55 -0500 |
commit | 8ade4e173a03fcb3080025d11c6e51f5976f3ccc (patch) | |
tree | 2adce93925feb17af340dfb53bc79f6bd159a2ca /src/main | |
parent | a30fcadbeed2997ad1607d488ba7548c799a6033 (diff) | |
download | DulkirMod-Fabric-8ade4e173a03fcb3080025d11c6e51f5976f3ccc.tar.gz DulkirMod-Fabric-8ade4e173a03fcb3080025d11c6e51f5976f3ccc.tar.bz2 DulkirMod-Fabric-8ade4e173a03fcb3080025d11c6e51f5976f3ccc.zip |
wip
Diffstat (limited to 'src/main')
9 files changed, 118 insertions, 11 deletions
diff --git a/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java b/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java new file mode 100644 index 0000000..9b6cac3 --- /dev/null +++ b/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java @@ -0,0 +1,21 @@ +package com.dulkirfabric.mixin.render; + +import com.dulkirfabric.features.TooltipImpl; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.tooltip.TooltipPositioner; +import org.joml.Vector2ic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(DrawContext.class) +public class DrawContextMixin { + + @WrapOperation(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;)V", + at = @At(target = "Lnet/minecraft/client/gui/tooltip/TooltipPositioner;getPosition(IIIIII)Lorg/joml/Vector2ic;", value = "INVOKE")) + public Vector2ic drawTooltip(TooltipPositioner positionerInstance, int sw, int sh, int mx, int my, int tw, int th, Operation<Vector2ic> operation) { + Vector2ic v = operation.call(positionerInstance, sw, sh, mx, my, tw, th); + return TooltipImpl.INSTANCE.calculatePos(v); + } +} diff --git a/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt b/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt index 112bf2a..8748f20 100644 --- a/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt +++ b/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt @@ -14,6 +14,7 @@ package com.dulkirfabric import com.dulkirfabric.config.DulkirConfig +import com.llamalad7.mixinextras.MixinExtrasBootstrap import meteordevelopment.orbit.EventBus import net.fabricmc.api.ModInitializer import net.minecraft.client.MinecraftClient @@ -37,6 +38,9 @@ object DulkirModFabric : ModInitializer { lookupInMethod.invoke(null, klass, MethodHandles.lookup()) as MethodHandles.Lookup } + // Mixin Extras + MixinExtrasBootstrap.init() + Registrations.registerEventListeners() Registrations.registerCommands() Registrations.registerEvents() diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt index a3ab96d..4ef80e9 100644 --- a/src/main/kotlin/com/dulkirfabric/Registrations.kt +++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt @@ -4,16 +4,16 @@ import com.dulkirfabric.DulkirModFabric.EVENT_BUS import com.dulkirfabric.commands.ConfigCommand import com.dulkirfabric.commands.DynamicKeyCommand import com.dulkirfabric.commands.JoinDungeonCommands -import com.dulkirfabric.events.ChatReceivedEvent -import com.dulkirfabric.events.ClientTickEvent -import com.dulkirfabric.events.OverlayReceivedEvent -import com.dulkirfabric.events.WorldRenderLastEvent +import com.dulkirfabric.events.* import com.dulkirfabric.features.KeyShortCutImpl import com.dulkirfabric.features.RenderBoxTest +import com.dulkirfabric.features.TooltipImpl import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents +import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents +import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents /** @@ -46,6 +46,7 @@ object Registrations { EVENT_BUS.subscribe(DulkirModFabric) EVENT_BUS.subscribe(KeyShortCutImpl) EVENT_BUS.subscribe(RenderBoxTest) + EVENT_BUS.subscribe(TooltipImpl) } fun registerEvents() { @@ -62,5 +63,13 @@ object Registrations { WorldRenderEvents.END.register( WorldRenderEvents.End { context -> WorldRenderLastEvent(context).post()} ) + ScreenEvents.BEFORE_INIT.register( + ScreenEvents.BeforeInit { client, screen, scaledWidth, scaledHeight -> + ScreenMouseEvents.beforeMouseScroll(screen).register(ScreenMouseEvents.BeforeMouseScroll { + coolScreen, mouseX, mouseY, horizontalAmount, verticalAmount -> + MouseScrollEvent(coolScreen, mouseX, mouseY, horizontalAmount, verticalAmount).post() + }) + } + ) } }
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/events/MouseScrollEvent.kt b/src/main/kotlin/com/dulkirfabric/events/MouseScrollEvent.kt new file mode 100644 index 0000000..ebcbe69 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/events/MouseScrollEvent.kt @@ -0,0 +1,12 @@ +package com.dulkirfabric.events + +import com.dulkirfabric.events.base.Event +import net.minecraft.client.gui.screen.Screen + +data class MouseScrollEvent( + val screen: Screen, + val mouseX: Double, + val mouseY: Double, + val horizontalScrollAmount: Double, + val verticalScrollAmount: Double +): Event() diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt index 6a0c048..af76c44 100644 --- a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt +++ b/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt @@ -12,7 +12,7 @@ object RenderBoxTest { fun onRender(event: WorldRenderLastEvent) { WorldRenderUtils.drawBox( event.context, Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0), - Color(255, 255, 255, 255), 3f, true + Color(255, 255, 255, 255), 10f, true ) } }
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt b/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt new file mode 100644 index 0000000..100b880 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt @@ -0,0 +1,60 @@ +package com.dulkirfabric.features + +import com.dulkirfabric.DulkirModFabric.mc +import com.dulkirfabric.events.ClientTickEvent +import com.dulkirfabric.events.MouseScrollEvent +import meteordevelopment.orbit.EventHandler +import net.minecraft.client.MinecraftClient +import net.minecraft.client.util.InputUtil +import org.joml.Vector2i +import org.joml.Vector2ic +import org.lwjgl.glfw.GLFW + +object TooltipImpl { + + var scaleBuffer = 1f + var horizontalBuffer = 0.0 + var verticalBuffer = 0.0 + + var tickScale = 0f + var tickHorizontal = 0 + var tickVertical = 0 + + var prevTickX = 0 + var prevTickY = 0 + + fun calculatePos(v: Vector2ic): Vector2ic { + // calculate the position of the tooltip based on the scroll amount + val partialTicks = MinecraftClient.getInstance().tickDelta + val newVec = v.add(prevTickX + ((tickHorizontal - prevTickX) * partialTicks).toInt(), + prevTickY + ((tickVertical - prevTickY) * partialTicks).toInt(), Vector2i()) + return newVec + } + + fun applyScale() { + + } + + @EventHandler + fun onTick(event: ClientTickEvent) { + // flushes the buffer to a scroll amount this tick, will be interpolated in calculatePos + prevTickX = tickHorizontal + prevTickY = tickVertical + tickHorizontal = horizontalBuffer.toInt() + tickVertical = verticalBuffer.toInt() + tickScale = scaleBuffer + } + + @EventHandler + fun onScroll(event: MouseScrollEvent) { + if (event.verticalScrollAmount == 0.0) return + val handle = MinecraftClient.getInstance().window.handle + if (InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_SHIFT)) { + horizontalBuffer += (mc.window.width / 192) * event.verticalScrollAmount + } else if (InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_CONTROL)) { + scaleBuffer += .1f * event.verticalScrollAmount.toFloat() + } else { + verticalBuffer += (mc.window.height / 108) * event.verticalScrollAmount + } + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt index d5008ba..f5daccf 100644 --- a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt +++ b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt @@ -1,17 +1,14 @@ package com.dulkirfabric.util import com.mojang.blaze3d.platform.GlConst -import com.mojang.blaze3d.platform.GlStateManager import com.mojang.blaze3d.systems.RenderSystem import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext import net.minecraft.client.render.BufferBuilder import net.minecraft.client.render.GameRenderer -import net.minecraft.client.render.Tessellator import net.minecraft.client.render.VertexFormat import net.minecraft.client.render.VertexFormats import net.minecraft.client.util.math.MatrixStack import net.minecraft.util.math.Box -import net.minecraft.util.math.Direction.Axis import org.joml.Vector3f import java.awt.Color @@ -48,10 +45,11 @@ object WorldRenderUtils { ) { val matrices = context.matrixStack() matrices.push() + val prevShader = RenderSystem.getShader() RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram) RenderSystem.disableBlend() RenderSystem.disableCull() - RenderSystem.defaultBlendFunc() + // RenderSystem.defaultBlendFunc() RenderSystem.lineWidth(thickness) RenderSystem.setShaderColor(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f) if (!depthTest) { @@ -92,10 +90,12 @@ object WorldRenderUtils { RenderSystem.enableDepthTest() - RenderSystem.disableBlend() + RenderSystem.enableBlend() RenderSystem.setShaderColor( 1f, 1f, 1f, 1f ) + RenderSystem.setShader { prevShader } + RenderSystem.enableCull() matrices.pop() } }
\ No newline at end of file diff --git a/src/main/resources/1.0 TODO.txt b/src/main/resources/1.0 TODO.txt index d36d3fa..4fb9451 100644 --- a/src/main/resources/1.0 TODO.txt +++ b/src/main/resources/1.0 TODO.txt @@ -11,7 +11,7 @@ LIST OF EASY STUFF: - Secret Chime with a custom sound - Broken Hyp - Abiphone DND - - double hook noot noot + - double hook noot noota - JBR and hotswap plugin - Slot Binding (emulate keypress) --- APPROACH LAST diff --git a/src/main/resources/dulkirmod-fabric.mixins.json b/src/main/resources/dulkirmod-fabric.mixins.json index 2b28d67..ec83ba1 100644 --- a/src/main/resources/dulkirmod-fabric.mixins.json +++ b/src/main/resources/dulkirmod-fabric.mixins.json @@ -7,6 +7,7 @@ }, "client": [ "io.HandledScreenMixin", + "render.DrawContextMixin", "render.GameMenuScreenMixin", "render.GameRendererMixin", "render.KeyboardMixin", |