aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-06-26 22:01:52 -0500
committeringlettronald <inglettronald@gmail.com>2023-06-26 22:01:52 -0500
commitcacc7c10365c4ff9c20adde0f2bef7edd3c1cda0 (patch)
tree3dc4f9a05385d084cb0d4c9c43ead22503b57cd9
parent4e6af3727fc930d00a78fe91e19ba46f2dc63a28 (diff)
downloadDulkirMod-Fabric-cacc7c10365c4ff9c20adde0f2bef7edd3c1cda0.tar.gz
DulkirMod-Fabric-cacc7c10365c4ff9c20adde0f2bef7edd3c1cda0.tar.bz2
DulkirMod-Fabric-cacc7c10365c4ff9c20adde0f2bef7edd3c1cda0.zip
fixed inventory scaling
-rw-r--r--src/main/java/com/dulkirfabric/mixin/MouseMixin.java43
-rw-r--r--src/main/java/com/dulkirfabric/mixin/render/LoomScreenMixin.java25
-rw-r--r--src/main/java/com/dulkirfabric/mixin/render/MinecraftClientMixin.java9
-rw-r--r--src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt4
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/InventoryScale.kt17
-rw-r--r--src/main/resources/dulkirmod-fabric.mixins.json3
6 files changed, 99 insertions, 2 deletions
diff --git a/src/main/java/com/dulkirfabric/mixin/MouseMixin.java b/src/main/java/com/dulkirfabric/mixin/MouseMixin.java
new file mode 100644
index 0000000..d86985d
--- /dev/null
+++ b/src/main/java/com/dulkirfabric/mixin/MouseMixin.java
@@ -0,0 +1,43 @@
+package com.dulkirfabric.mixin;
+
+import com.dulkirfabric.features.InventoryScale;
+import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
+import net.minecraft.client.Mouse;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+
+@Mixin(Mouse.class)
+public class MouseMixin {
+
+ @ModifyExpressionValue(method = "onMouseButton", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;getScaledWidth()I"))
+ public int onMouseButtonWidth(int originalScaledWidth) {
+ return (int) (originalScaledWidth / InventoryScale.INSTANCE.getScale());
+ }
+
+ @ModifyExpressionValue(method = "onMouseButton", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;getScaledHeight()I"))
+ public int onMouseButtonHeight(int originalScaledHeight) {
+ return (int) (originalScaledHeight / InventoryScale.INSTANCE.getScale());
+ }
+
+ @ModifyExpressionValue(method = "onCursorPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;getScaledWidth()I"))
+ public int onCursorPosWidth(int originalScaledWidth) {
+ return (int) (originalScaledWidth / InventoryScale.INSTANCE.getScale());
+ }
+
+ @ModifyExpressionValue(method = "onCursorPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;getScaledHeight()I"))
+ public int onCursorPosHeight(int originalScaledHeight) {
+ return (int) (originalScaledHeight / InventoryScale.INSTANCE.getScale());
+ }
+
+ @ModifyExpressionValue(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;getScaledWidth()I"))
+ public int onMouseScrollWidth(int originalScaledWidth) {
+ return (int) (originalScaledWidth / InventoryScale.INSTANCE.getScale());
+ }
+
+ @ModifyExpressionValue(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;getScaledHeight()I"))
+ public int onMouseScrollHeight(int originalScaledHeight) {
+ return (int) (originalScaledHeight / InventoryScale.INSTANCE.getScale());
+ }
+
+}
+
diff --git a/src/main/java/com/dulkirfabric/mixin/render/LoomScreenMixin.java b/src/main/java/com/dulkirfabric/mixin/render/LoomScreenMixin.java
new file mode 100644
index 0000000..0270251
--- /dev/null
+++ b/src/main/java/com/dulkirfabric/mixin/render/LoomScreenMixin.java
@@ -0,0 +1,25 @@
+package com.dulkirfabric.mixin.render;
+
+import com.dulkirfabric.features.InventoryScale;
+import net.minecraft.block.entity.BannerPattern;
+import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.gui.screen.ingame.LoomScreen;
+import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NbtCompound;
+import net.minecraft.nbt.NbtList;
+import net.minecraft.registry.entry.RegistryEntry;
+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 org.spongepowered.asm.mixin.injection.callback.LocalCapture;
+
+@Mixin(LoomScreen.class)
+public class LoomScreenMixin {
+ @Inject(method = "drawBanner", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;push()V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
+ public void onCreateMatrix(DrawContext context, RegistryEntry<BannerPattern> pattern, int x, int y, CallbackInfo ci, NbtCompound nbtCompound, NbtList nbtList, ItemStack itemStack, MatrixStack matrixStack) {
+ matrixStack.scale(InventoryScale.INSTANCE.getScale(), InventoryScale.INSTANCE.getScale(), 1F);
+ }
+}
+
diff --git a/src/main/java/com/dulkirfabric/mixin/render/MinecraftClientMixin.java b/src/main/java/com/dulkirfabric/mixin/render/MinecraftClientMixin.java
new file mode 100644
index 0000000..9ab55ae
--- /dev/null
+++ b/src/main/java/com/dulkirfabric/mixin/render/MinecraftClientMixin.java
@@ -0,0 +1,9 @@
+package com.dulkirfabric.mixin.render;
+
+import net.minecraft.client.MinecraftClient;
+import org.spongepowered.asm.mixin.Mixin;
+
+@Mixin(MinecraftClient.class)
+public class MinecraftClientMixin {
+
+}
diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
index 7ebe742..da9f2d8 100644
--- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
+++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
@@ -55,7 +55,7 @@ class DulkirConfig {
Text.literal("This is a tooltip"))
)
general.addEntry(
- entryBuilder.startIntSlider(Text.literal("Inventory Scale"), configOptions.inventoryScale, 1, 5)
+ entryBuilder.startFloatField(Text.literal("Inventory Scale"), configOptions.inventoryScale)
.setTooltip(Text.literal("Size of GUI whenever you're in an inventory screen"))
.setSaveConsumer { newValue -> configOptions.inventoryScale = newValue }
.build()
@@ -109,7 +109,7 @@ class DulkirConfig {
@Serializable
data class ConfigOptions(
var invScaleBool: Boolean = false,
- var inventoryScale: Int = 3,
+ var inventoryScale: Float = 1f,
var macrosList: List<Macro> = listOf(Macro(UNKNOWN_KEY, "")),
var ignoreReverseThirdPerson: Boolean = false,
var dynamicKey: InputUtil.Key = UNKNOWN_KEY,
diff --git a/src/main/kotlin/com/dulkirfabric/features/InventoryScale.kt b/src/main/kotlin/com/dulkirfabric/features/InventoryScale.kt
new file mode 100644
index 0000000..0d2fc4a
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/features/InventoryScale.kt
@@ -0,0 +1,17 @@
+package com.dulkirfabric.features
+
+import com.dulkirfabric.DulkirModFabric.mc
+import com.dulkirfabric.config.DulkirConfig
+import net.minecraft.client.gui.screen.ingame.HandledScreen
+
+object InventoryScale {
+
+ /**
+ * Called every render frame, so don't put anything expensive in here.
+ */
+ fun getScale(): Float {
+ if (DulkirConfig.configOptions.invScaleBool && mc.currentScreen is HandledScreen<*>)
+ return DulkirConfig.configOptions.inventoryScale
+ return 1f
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/dulkirmod-fabric.mixins.json b/src/main/resources/dulkirmod-fabric.mixins.json
index e8ac46a..330c9ac 100644
--- a/src/main/resources/dulkirmod-fabric.mixins.json
+++ b/src/main/resources/dulkirmod-fabric.mixins.json
@@ -6,12 +6,15 @@
"defaultRequire": 1
},
"client": [
+ "MouseMixin",
"SoundSystemMixin",
"io.HandledScreenMixin",
"render.DrawContextMixin",
"render.GameMenuScreenMixin",
"render.GameRendererMixin",
"render.KeyboardMixin",
+ "render.LoomScreenMixin",
+ "render.MinecraftClientMixin",
"render.PerspectiveMixin",
"render.ScreenMixin"
],