From aced7535fc3bd4e03aac4a68933caed0b2ddf373 Mon Sep 17 00:00:00 2001 From: MicrocontrollersDev <66657148+MicrocontrollersDev@users.noreply.github.com> Date: Thu, 9 May 2024 11:58:59 -0500 Subject: [PATCH] scroll features and background opacity customization (#14) --- .../sk1er/patcher/config/PatcherConfig.java | 40 +++++++++++++++---- .../patcher/hooks/ContainerOpacityHook.java | 4 +- .../GuiScreenMixin_BackgroundRendering.java | 18 ++++++++- ...toryPlayerTransformer_HotbarScrolling.java | 31 +++++++++++++- 4 files changed, 81 insertions(+), 12 deletions(-) diff --git a/src/main/java/club/sk1er/patcher/config/PatcherConfig.java b/src/main/java/club/sk1er/patcher/config/PatcherConfig.java index 39e1507b8..cec4f8409 100644 --- a/src/main/java/club/sk1er/patcher/config/PatcherConfig.java +++ b/src/main/java/club/sk1er/patcher/config/PatcherConfig.java @@ -295,6 +295,20 @@ public class PatcherConfig extends Config { ) public static boolean disableHotbarScrolling; + @Switch( + name = "Invert Hotbar Scrolling", + description = "Changes the direction of scrolling in your hotbar.", + category = "Miscellaneous", subcategory = "General" + ) + public static boolean invertHotbarScrolling; + + @Switch( + name = "Prevent Overflow Hotbar Scrolling", + description = "Prevents from directly scrolling between the first and last hotbar slot.", + category = "Miscellaneous", subcategory = "General" + ) + public static boolean preventOverflowHotbarScrolling; + @Slider( name = "Unfocused Sounds", description = "Change the volume of sounds when you're not tabbed into the window.", @@ -969,20 +983,28 @@ public static int getInventoryScale() { return inventoryScale == 0 ? -1 : inventoryScale; } - @Switch( - name = "Remove Container Background", +// @Switch( +// name = "Remove Container Background", +// description = "Remove the dark background inside a container.", +// category = "Screens", subcategory = "General" +// ) + public static boolean removeContainerBackground = false; + + @Slider( + name = "Change Container Background Opacity (%)", description = "Remove the dark background inside a container.", - category = "Screens", subcategory = "General" + category = "Screens", subcategory = "General", + min = 0F, max = 100F ) - public static boolean removeContainerBackground = false; + public static float containerBackgroundOpacity = (208/255F) * 100F; @Slider( - name = "Container Opacity", + name = "Container Opacity (%)", description = "Change the opacity of supported containers.\nIncludes Chests & Survival Inventory.", category = "Screens", subcategory = "General", - min = 0, max = 1.0F + min = 0F, max = 100F ) - public static float containerOpacity = 1.0f; + public static float containerOpacity = 100F; @Info( text = "Supported servers for 1.11 chat length are servers that support 1.11 or above.", @@ -1419,6 +1441,10 @@ public PatcherConfig() { actionbarBackground = false; modified = true; } + if (removeContainerBackground) { + containerBackgroundOpacity = 0F; + modified = true; + } if (modified) { save(); diff --git a/src/main/java/club/sk1er/patcher/hooks/ContainerOpacityHook.java b/src/main/java/club/sk1er/patcher/hooks/ContainerOpacityHook.java index 82846c0bf..8fe3a0255 100644 --- a/src/main/java/club/sk1er/patcher/hooks/ContainerOpacityHook.java +++ b/src/main/java/club/sk1er/patcher/hooks/ContainerOpacityHook.java @@ -7,7 +7,7 @@ public class ContainerOpacityHook { public static void beginTransparency() { - float containerOpacity = PatcherConfig.containerOpacity; + float containerOpacity = PatcherConfig.containerOpacity / 100F; if (containerOpacity == 1.0f) return; GlStateManager.enableBlend(); @@ -18,7 +18,7 @@ public static void beginTransparency() { } public static void endTransparency() { - if (PatcherConfig.containerOpacity == 1.0f) return; + if (PatcherConfig.containerOpacity / 100F == 1.0F) return; GlStateManager.disableBlend(); GlStateManager.disableAlpha(); diff --git a/src/main/java/club/sk1er/patcher/mixins/features/GuiScreenMixin_BackgroundRendering.java b/src/main/java/club/sk1er/patcher/mixins/features/GuiScreenMixin_BackgroundRendering.java index ed25561f2..98a044e63 100644 --- a/src/main/java/club/sk1er/patcher/mixins/features/GuiScreenMixin_BackgroundRendering.java +++ b/src/main/java/club/sk1er/patcher/mixins/features/GuiScreenMixin_BackgroundRendering.java @@ -9,9 +9,12 @@ import net.minecraftforge.common.MinecraftForge; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(GuiScreen.class) public class GuiScreenMixin_BackgroundRendering { @@ -22,7 +25,7 @@ public class GuiScreenMixin_BackgroundRendering { @Inject(method = "drawDefaultBackground", at = @At("HEAD"), cancellable = true) private void patcher$cancelRendering(CallbackInfo ci) { - if (PatcherConfig.removeContainerBackground && this.mc.theWorld != null) { + if (PatcherConfig.containerBackgroundOpacity == 0 && this.mc.theWorld != null) { // Some guis (for example, the advancements gui) depend on the depth buffer having the rectangle from // the background in it. So, we draw a similar rectangle to only the depth buffer. GlStateManager.colorMask(false, false, false, false); @@ -33,4 +36,17 @@ public class GuiScreenMixin_BackgroundRendering { ci.cancel(); } } + + @ModifyArgs(method = "drawWorldBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiScreen;drawGradientRect(IIIIII)V")) + private void patcher$modifyColor(Args args) { + if (PatcherConfig.containerBackgroundOpacity != 0) { + args.set(4, patcher$getOpacity(args.get(4), Math.max(PatcherConfig.containerBackgroundOpacity / 100F - 16/255F, 0))); + args.set(5, patcher$getOpacity(args.get(4), Math.max(PatcherConfig.containerBackgroundOpacity / 100F, 0))); + } + } + + @Unique + private int patcher$getOpacity(int color, float opacity) { + return (int) (opacity * 255) << 24 | (color & 0xFFFFFF); + } } diff --git a/src/main/java/club/sk1er/patcher/mixins/features/InventoryPlayerTransformer_HotbarScrolling.java b/src/main/java/club/sk1er/patcher/mixins/features/InventoryPlayerTransformer_HotbarScrolling.java index 7f3032a93..5c42a8c41 100644 --- a/src/main/java/club/sk1er/patcher/mixins/features/InventoryPlayerTransformer_HotbarScrolling.java +++ b/src/main/java/club/sk1er/patcher/mixins/features/InventoryPlayerTransformer_HotbarScrolling.java @@ -3,17 +3,44 @@ import club.sk1er.patcher.config.PatcherConfig; import club.sk1er.patcher.hooks.ZoomHook; import net.minecraft.entity.player.InventoryPlayer; +import org.spongepowered.asm.mixin.Debug; 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.Shadow; +import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +@Debug(export = true) @Mixin(InventoryPlayer.class) public class InventoryPlayerTransformer_HotbarScrolling { + @Shadow + public int currentItem; + @Inject(method = "changeCurrentItem", at = @At("HEAD"), cancellable = true) private void patcher$cancelScrolling(int direction, CallbackInfo ci) { if (PatcherConfig.disableHotbarScrolling || (PatcherConfig.scrollToZoom && ZoomHook.zoomed)) { ci.cancel(); } } + + @Inject(method = "changeCurrentItem", at = @At(value = "HEAD", shift = At.Shift.AFTER)) + private void patcher$invertScrolling(int direction, CallbackInfo ci) { + if (PatcherConfig.invertHotbarScrolling) { + int dir; + if (direction < 0) { + dir = -2; + } else { + dir = 2; + } + this.currentItem += dir; + } + } + + @ModifyConstant(method = "changeCurrentItem", constant = {@Constant(intValue = 9, ordinal = 2), @Constant(intValue = 9, ordinal = 0)}) + private int patcher$preventOverflowScrolling(int constant) { + if (PatcherConfig.preventOverflowHotbarScrolling) { + return 1; + } + + return constant; + } }