diff options
author | inglettronald <inglettronald@gmail.com> | 2023-06-30 03:58:25 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-06-30 03:58:25 -0500 |
commit | c43cbe3c2883a60e00533c5f32449f4a35f308b5 (patch) | |
tree | b6651729ba63b90653a48e173838123a216a9e80 /src/main | |
parent | e762856a7881d97fa862c093d84e8e7f673e7168 (diff) | |
download | DulkirMod-Fabric-c43cbe3c2883a60e00533c5f32449f4a35f308b5.tar.gz DulkirMod-Fabric-c43cbe3c2883a60e00533c5f32449f4a35f308b5.tar.bz2 DulkirMod-Fabric-c43cbe3c2883a60e00533c5f32449f4a35f308b5.zip |
Lots of rendering fixes and feature improvement
Diffstat (limited to 'src/main')
3 files changed, 47 insertions, 24 deletions
diff --git a/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java b/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java index 1bef0f5..79a71b2 100644 --- a/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java +++ b/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java @@ -1,12 +1,17 @@ package com.dulkirfabric.mixin.render; +import com.dulkirfabric.config.DulkirConfig; import com.dulkirfabric.events.TooltipRenderChangeEvent; +import com.dulkirfabric.features.InventoryScale; import com.dulkirfabric.features.TooltipImpl; import com.dulkirfabric.util.ItemChangeHandler; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.tooltip.TooltipComponent; import net.minecraft.client.gui.tooltip.TooltipPositioner; import net.minecraft.client.util.math.MatrixStack; @@ -23,18 +28,27 @@ import java.util.List; @Mixin(DrawContext.class) public class DrawContextMixin { @Shadow @Final private MatrixStack matrices; - List<TooltipComponent> prevComponents; @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); + Screen screen = MinecraftClient.getInstance().currentScreen; + if (!(screen instanceof HandledScreen)) { + return operation.call(positionerInstance, sw, sh, mx, my, tw, th); + } + float scale = InventoryScale.INSTANCE.getScale(); + float tooltipScale = DulkirConfig.ConfigVars.getConfigOptions().getTooltipScale(); + Vector2ic v = operation.call(positionerInstance, (int) (sw / scale), (int) (sh / scale), + mx , my, (int) (tw * tooltipScale), (int) (th * tooltipScale)); + return TooltipImpl.INSTANCE.calculatePos(v, (int) (tw * tooltipScale), + (int) (th * tooltipScale), (int) (sw / scale), (int) (sh / scale)); } @Inject(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;)V", at = @At(target = "Lnet/minecraft/client/util/math/MatrixStack;push()V", value = "INVOKE")) public void onPush(TextRenderer textRenderer, List<TooltipComponent> components, int x, int y, TooltipPositioner positioner, CallbackInfo ci) { - TooltipImpl.INSTANCE.applyScale(matrices); + if (MinecraftClient.getInstance().currentScreen instanceof HandledScreen) { + TooltipImpl.INSTANCE.applyScale(matrices); + } } } diff --git a/src/main/kotlin/com/dulkirfabric/features/InventoryScale.kt b/src/main/kotlin/com/dulkirfabric/features/InventoryScale.kt index eccfb2c..80442c3 100644 --- a/src/main/kotlin/com/dulkirfabric/features/InventoryScale.kt +++ b/src/main/kotlin/com/dulkirfabric/features/InventoryScale.kt @@ -9,12 +9,14 @@ import net.minecraft.client.MinecraftClient import net.minecraft.client.gui.screen.ingame.HandledScreen import net.minecraft.client.util.InputUtil import org.lwjgl.glfw.GLFW +import kotlin.math.max object InventoryScale { - private var scaleBuffer = DulkirConfig.configOptions.inventoryScale - private var prevTickScale = DulkirConfig.configOptions.inventoryScale - private var tickScale = DulkirConfig.configOptions.inventoryScale + var scaleBuffer = DulkirConfig.configOptions.inventoryScale + var prevTickScale = DulkirConfig.configOptions.inventoryScale + var tickScale = DulkirConfig.configOptions.inventoryScale + var frameScale = DulkirConfig.configOptions.inventoryScale /** @@ -35,7 +37,7 @@ object InventoryScale { if (event.verticalScrollAmount == 0.0) return val handle = MinecraftClient.getInstance().window.handle if (InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_CONTROL) && InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_ALT)) - scaleBuffer += (.05 * event.verticalScrollAmount).toFloat() + scaleBuffer = max(scaleBuffer + (.05 * event.verticalScrollAmount).toFloat(), .1f) } @EventHandler diff --git a/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt b/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt index 14bc6c5..4ab1e2d 100644 --- a/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt +++ b/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt @@ -1,6 +1,7 @@ package com.dulkirfabric.features import com.dulkirfabric.DulkirModFabric.mc +import com.dulkirfabric.config.DulkirConfig import com.dulkirfabric.events.ClientTickEvent import com.dulkirfabric.events.MouseScrollEvent import com.dulkirfabric.events.TooltipRenderChangeEvent @@ -11,10 +12,11 @@ import net.minecraft.client.util.math.MatrixStack import org.joml.Vector2i import org.joml.Vector2ic import org.lwjgl.glfw.GLFW +import kotlin.math.max object TooltipImpl { - private var scaleBuffer = 1f + private var scaleBuffer = DulkirConfig.configOptions.tooltipScale private var horizontalBuffer = 0.0 private var verticalBuffer = 0.0 private var tickScale = 0f @@ -22,26 +24,31 @@ object TooltipImpl { private var tickVertical = 0 private var prevTickX = 0 private var prevTickY = 0 - private var prevScale = 1f - private var frameScale = 1f + private var prevScale = DulkirConfig.configOptions.tooltipScale + private var frameScale = DulkirConfig.configOptions.tooltipScale private var frameX = 0 private var frameY = 0 - fun calculatePos(v: Vector2ic): Vector2ic { + fun calculatePos(v: Vector2ic, tw: Int, th: Int, sw: Int, sh: Int): Vector2ic { // calculate the position of the tooltip based on the scroll amount val partialTicks = MinecraftClient.getInstance().tickDelta - frameX = v.x() + prevTickX + ((tickHorizontal - prevTickX) * partialTicks).toInt() - frameY = v.y() + prevTickY + ((tickVertical - prevTickY) * partialTicks).toInt() - val newVec = v.add(-v.x() + frameX, -v.y() + frameY, Vector2i()) - return newVec + var newVec = v + frameX = newVec.x() + prevTickX + ((tickHorizontal - prevTickX) * partialTicks).toInt() + frameY = newVec.y() + prevTickY + ((tickVertical - prevTickY) * partialTicks).toInt() + frameScale = prevScale + (tickScale - prevScale) * partialTicks + // Check for tooltips that go off both sides of screen + if (tw > sw) { + frameX = frameX - v.x() + 4 + } + if (th > sh) { + frameY = frameY - v.y() + 4 + } + return Vector2i(0,0) } fun applyScale(matrices: MatrixStack) { - frameScale = prevScale + (tickScale - prevScale) * MinecraftClient.getInstance().tickDelta + matrices.translate(frameX.toFloat(), frameY.toFloat(), 0f) matrices.scale(frameScale, frameScale, 1f) - val newX = frameX / frameScale - val newY = frameY / frameScale - matrices.translate(newX - frameX, newY - frameY, 0f) } @EventHandler @@ -63,7 +70,7 @@ object TooltipImpl { 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() + scaleBuffer = max(.01f, scaleBuffer + .1f * event.verticalScrollAmount.toFloat()) } else { verticalBuffer += (mc.window.height / 108) * event.verticalScrollAmount } @@ -71,14 +78,14 @@ object TooltipImpl { @EventHandler fun onChange(event: TooltipRenderChangeEvent) { - scaleBuffer = 1f + scaleBuffer = DulkirConfig.configOptions.tooltipScale horizontalBuffer = 0.0 verticalBuffer = 0.0 - tickScale = 1f + tickScale = DulkirConfig.configOptions.tooltipScale tickHorizontal = 0 tickVertical = 0 prevTickX = 0 prevTickY = 0 - prevScale = 1f + prevScale = DulkirConfig.configOptions.tooltipScale } }
\ No newline at end of file |