From c85c55e4c15715e7a4667cbacbdc5c953fdb3d7f Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Mon, 11 Dec 2023 14:35:49 -0800 Subject: Internal Change: Cleanup Position (#670) Remove Duplicate Code #670 --- .../skyhanni/config/core/config/Position.java | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java index d8b2a7a99..670ea573c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java @@ -115,27 +115,23 @@ public class Position { public int getAbsX0(int objWidth) { int width = new ScaledResolution(Minecraft.getMinecraft()).getScaledWidth(); - int ret = x; - if (x < 0) { - ret = width + x - objWidth; - } - - if (ret < 0) ret = 0; - if (ret > width - objWidth) ret = width - objWidth; - - return ret; + return calcAbs0(x, width, objWidth); } public int getAbsY0(int objHeight) { int height = new ScaledResolution(Minecraft.getMinecraft()).getScaledHeight(); - int ret = y; - if (y < 0) { - ret = height + y - objHeight; + return calcAbs0(y, height, objHeight); + } + + private int calcAbs0(int axis, int length, int objLength) { + int ret = axis; + if (axis < 0) { + ret = length + axis - objLength; } if (ret < 0) ret = 0; - if (ret > height - objHeight) ret = height - objHeight; + if (ret > length - objLength) ret = length - objLength; return ret; } -- cgit