Skip to content

Commit

Permalink
scroll features and background opacity customization (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
MicrocontrollersDev authored May 9, 2024
1 parent 1c12860 commit aced753
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 12 deletions.
40 changes: 33 additions & 7 deletions src/main/java/club/sk1er/patcher/config/PatcherConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -1419,6 +1441,10 @@ public PatcherConfig() {
actionbarBackground = false;
modified = true;
}
if (removeContainerBackground) {
containerBackgroundOpacity = 0F;
modified = true;
}

if (modified) {
save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit aced753

Please sign in to comment.