From 0960bc9aa9faeb558124ee62b1c1e65983bbff69 Mon Sep 17 00:00:00 2001 From: nea Date: Wed, 15 Feb 2023 10:50:06 +0100 Subject: Use a new arraylist instead of modifying the old one (achievments) --- .../moulberry/notenoughupdates/TooltipTextScrolling.java | 14 ++++++++------ .../moulberry/notenoughupdates/mixins/MixinGuiUtils.java | 15 ++++----------- .../io/github/moulberry/notenoughupdates/util/Utils.java | 2 +- 3 files changed, 13 insertions(+), 18 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java b/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java index 21fa64b7..ccb28dd6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java @@ -35,20 +35,22 @@ public class TooltipTextScrolling { static int scrollOffset = 0; static boolean didRenderTooltip = false; - public static void handleTextLineRendering(List tooltip) { + public static List handleTextLineRendering(List tooltip) { didRenderTooltip = true; if (!Objects.equals(tooltip, lastRenderedTooltip)) { lastRenderedTooltip = new ArrayList<>(tooltip); scrollOffset = 0; - return; + return tooltip; } lastRenderedTooltip = new ArrayList<>(tooltip); - for (int i = 0; i < scrollOffset && tooltip.size() > 1; i++) { - tooltip.remove(0); + List modifiableTooltip = new ArrayList<>(tooltip); + for (int i = 0; i < scrollOffset && modifiableTooltip.size() > 1; i++) { + modifiableTooltip.remove(0); } - for (int i = 0; i < -scrollOffset && tooltip.size() > 1; i++) { - tooltip.remove(tooltip.size() - 1); + for (int i = 0; i < -scrollOffset && modifiableTooltip.size() > 1; i++) { + modifiableTooltip.remove(modifiableTooltip.size() - 1); } + return modifiableTooltip; } @SubscribeEvent diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiUtils.java index a3313090..a4e83a11 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiUtils.java @@ -74,17 +74,10 @@ public class MixinGuiUtils { List textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font, CallbackInfo ci) { Utils.resetGuiScale(); } - @Inject(at = @At("HEAD"), method = "drawHoveringText") - private static void onDrawHoveringText( - List textLines, - int mouseX, - int mouseY, - int screenWidth, - int screenHeight, - int maxTextWidth, - FontRenderer font, - CallbackInfo ci + @ModifyVariable(at = @At("HEAD"), method = "drawHoveringText") + private static List onDrawHoveringText( + List textLines ) { - TooltipTextScrolling.handleTextLineRendering(textLines); + return TooltipTextScrolling.handleTextLineRendering(textLines); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index bd3693a0..90e53097 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -1571,7 +1571,7 @@ public class Utils { ((NotEnoughUpdates.INSTANCE.config.tooltipTweaks.tooltipBorderOpacity) << 24); } } - TooltipTextScrolling.handleTextLineRendering(textLines); + textLines = TooltipTextScrolling.handleTextLineRendering(textLines); if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.guiScale != 0) { ScaledResolution scaledResolution = Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.tooltipTweaks.guiScale); mouseX = Mouse.getX() * scaledResolution.getScaledWidth() / Minecraft.getMinecraft().displayWidth; -- cgit