diff --git a/src/main/java/shit/zen/config/ModulesConfig.java b/src/main/java/shit/zen/config/ModulesConfig.java index 4ab64a8..cf3e9a5 100644 --- a/src/main/java/shit/zen/config/ModulesConfig.java +++ b/src/main/java/shit/zen/config/ModulesConfig.java @@ -22,23 +22,23 @@ extends Config { @Override public void read(BufferedReader bufferedReader) throws IOException { - String string; + String line; ModuleManager moduleManager = ZenClient.getInstance().getModuleManager(); - while ((string = bufferedReader.readLine()) != null) { - String[] stringArray = string.split(":", 3); - if (stringArray.length != 3) { - LOGGER.error("Failed to read line {}!", string); + while ((line = bufferedReader.readLine()) != null) { + String[] parts = line.split(":", 3); + if (parts.length != 3) { + LOGGER.error("Failed to read line {}!", line); continue; } - String string2 = stringArray[0]; - int n = Integer.parseInt(stringArray[1]); - boolean bl = Boolean.parseBoolean(stringArray[2]); + String moduleName = parts[0]; + int keyCode = Integer.parseInt(parts[1]); + boolean enabled = Boolean.parseBoolean(parts[2]); try { - Module module = moduleManager.getModule(string2); - module.setKey(n); - module.setEnabled(bl); - } catch (ModuleNotFoundException moduleNotFoundException) { - LOGGER.error("Failed to find module {}!", string2); + Module module = moduleManager.getModule(moduleName); + module.setKey(keyCode); + module.setEnabled(enabled); + } catch (ModuleNotFoundException ex) { + LOGGER.error("Failed to find module {}!", moduleName); } } } @@ -46,8 +46,8 @@ extends Config { @Override public void save(BufferedWriter bufferedWriter) throws IOException { ModuleManager moduleManager = ZenClient.getInstance().getModuleManager(); - ArrayList arrayList = new ArrayList<>(moduleManager.getModules()); - for (Module module : arrayList) { + ArrayList moduleList = new ArrayList<>(moduleManager.getModules()); + for (Module module : moduleList) { bufferedWriter.write(String.format((String)"%s:%d:%s\n", (Object[])new Object[]{module.getName(), module.getKey(), module.isEnabled()})); } } diff --git a/src/main/java/shit/zen/event/Event.java b/src/main/java/shit/zen/event/Event.java index acf8c16..2c4f702 100644 --- a/src/main/java/shit/zen/event/Event.java +++ b/src/main/java/shit/zen/event/Event.java @@ -17,7 +17,7 @@ EventMarker { } @Override - public void setCancelled(boolean bl) { - this.cancelled = bl; + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/CameraPitchEvent.java b/src/main/java/shit/zen/event/impl/CameraPitchEvent.java index a71cf61..b7300b5 100644 --- a/src/main/java/shit/zen/event/impl/CameraPitchEvent.java +++ b/src/main/java/shit/zen/event/impl/CameraPitchEvent.java @@ -11,12 +11,12 @@ implements EventMarker { return this.pitch; } - public void setPitch(float f) { - this.pitch = f; + public void setPitch(float pitch) { + this.pitch = pitch; } @Generated - public CameraPitchEvent(float f) { - this.pitch = f; + public CameraPitchEvent(float pitch) { + this.pitch = pitch; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/ChatEvent.java b/src/main/java/shit/zen/event/impl/ChatEvent.java index 351c0ae..c61ccf7 100644 --- a/src/main/java/shit/zen/event/impl/ChatEvent.java +++ b/src/main/java/shit/zen/event/impl/ChatEvent.java @@ -13,33 +13,33 @@ extends Event { private static final String TO_STRING_PREFIX = "ChatEvent(message="; @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof ChatEvent chatEvent)) { + if (!(other instanceof ChatEvent otherEvent)) { return false; } - if (!chatEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - String string = this.getMessage(); - String string2 = chatEvent.getMessage(); - return !(!Objects.equals(string, string2)); + String thisMessage = this.getMessage(); + String otherMessage = otherEvent.getMessage(); + return !(!Objects.equals(thisMessage, otherMessage)); } @Generated - protected boolean canEqual(Object object) { - return object instanceof ChatEvent; + protected boolean canEqual(Object other) { + return other instanceof ChatEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - String string = this.getMessage(); - n2 = n2 * 59 + (string == null ? 43 : string.hashCode()); - return n2; + int prime = 59; + int result = 1; + String msg = this.getMessage(); + result = result * 59 + (msg == null ? 43 : msg.hashCode()); + return result; } @Generated @@ -48,7 +48,7 @@ extends Event { } @Generated - public ChatEvent(String string) { - this.message = string; + public ChatEvent(String message) { + this.message = message; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/FallFlyingEvent.java b/src/main/java/shit/zen/event/impl/FallFlyingEvent.java index 514c6e3..cc1abb7 100644 --- a/src/main/java/shit/zen/event/impl/FallFlyingEvent.java +++ b/src/main/java/shit/zen/event/impl/FallFlyingEvent.java @@ -12,30 +12,30 @@ implements EventMarker { private static final String TO_STRING_PREFIX = "FallFlyingEvent(pitch="; @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof FallFlyingEvent fallFlyingEvent)) { + if (!(other instanceof FallFlyingEvent otherEvent)) { return false; } - if (!fallFlyingEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - return Float.compare(this.getSpeed(), fallFlyingEvent.getSpeed()) == 0; + return Float.compare(this.getSpeed(), otherEvent.getSpeed()) == 0; } @Generated - protected boolean canEqual(Object object) { - return object instanceof FallFlyingEvent; + protected boolean canEqual(Object other) { + return other instanceof FallFlyingEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - n2 = n2 * 59 + Float.floatToIntBits(this.getSpeed()); - return n2; + int prime = 59; + int result = 1; + result = result * 59 + Float.floatToIntBits(this.getSpeed()); + return result; } @Generated @@ -44,7 +44,7 @@ implements EventMarker { } @Generated - public FallFlyingEvent(float f) { - this.speed = f; + public FallFlyingEvent(float speed) { + this.speed = speed; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/GlRenderEvent.java b/src/main/java/shit/zen/event/impl/GlRenderEvent.java index cbf6cbe..6b8d86a 100644 --- a/src/main/java/shit/zen/event/impl/GlRenderEvent.java +++ b/src/main/java/shit/zen/event/impl/GlRenderEvent.java @@ -29,55 +29,55 @@ public record GlRenderEvent(GuiGraphics guiGraphics, PoseStack poseStack, DrawCo } @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof GlRenderEvent glRenderEvent)) { + if (!(other instanceof GlRenderEvent otherEvent)) { return false; } - if (!glRenderEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - GuiGraphics guiGraphics = this.guiGraphics(); - GuiGraphics guiGraphics2 = glRenderEvent.guiGraphics(); - if (!Objects.equals(guiGraphics, guiGraphics2)) { + GuiGraphics thisGui = this.guiGraphics(); + GuiGraphics otherGui = otherEvent.guiGraphics(); + if (!Objects.equals(thisGui, otherGui)) { return false; } - PoseStack poseStack = this.poseStack(); - PoseStack poseStack2 = glRenderEvent.poseStack(); - if (!Objects.equals(poseStack, poseStack2)) { + PoseStack thisPose = this.poseStack(); + PoseStack otherPose = otherEvent.poseStack(); + if (!Objects.equals(thisPose, otherPose)) { return false; } - DrawContext drawContext = this.drawContext(); - DrawContext drawContext2 = glRenderEvent.drawContext(); - return !(!Objects.equals(drawContext, drawContext2)); + DrawContext thisCtx = this.drawContext(); + DrawContext otherCtx = otherEvent.drawContext(); + return !(!Objects.equals(thisCtx, otherCtx)); } @Generated - protected boolean canEqual(Object object) { - return object instanceof GlRenderEvent; + protected boolean canEqual(Object other) { + return other instanceof GlRenderEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - GuiGraphics guiGraphics = this.guiGraphics(); - n2 = n2 * 59 + (guiGraphics == null ? 43 : guiGraphics.hashCode()); - PoseStack poseStack = this.poseStack(); - n2 = n2 * 59 + (poseStack == null ? 43 : poseStack.hashCode()); - DrawContext drawContext = this.drawContext(); - n2 = n2 * 59 + (drawContext == null ? 43 : drawContext.hashCode()); - return n2; + int prime = 59; + int result = 1; + GuiGraphics gui = this.guiGraphics(); + result = result * 59 + (gui == null ? 43 : gui.hashCode()); + PoseStack pose = this.poseStack(); + result = result * 59 + (pose == null ? 43 : pose.hashCode()); + DrawContext ctx = this.drawContext(); + result = result * 59 + (ctx == null ? 43 : ctx.hashCode()); + return result; } @Generated public String toString() { - String string = String.valueOf(this.drawContext()); - String string2 = String.valueOf(this.poseStack()); - String string3 = String.valueOf(this.guiGraphics()); - return "GlRenderEvent(guiGraphics=" + string3 + ", stack=" + string2 + ", context=" + string + ")"; + String ctxStr = String.valueOf(this.drawContext()); + String poseStr = String.valueOf(this.poseStack()); + String guiStr = String.valueOf(this.guiGraphics()); + return "GlRenderEvent(guiGraphics=" + guiStr + ", stack=" + poseStr + ", context=" + ctxStr + ")"; } @Generated diff --git a/src/main/java/shit/zen/event/impl/HeadTurnEvent.java b/src/main/java/shit/zen/event/impl/HeadTurnEvent.java index e6d6aa6..e16bf85 100644 --- a/src/main/java/shit/zen/event/impl/HeadTurnEvent.java +++ b/src/main/java/shit/zen/event/impl/HeadTurnEvent.java @@ -13,34 +13,34 @@ implements EventMarker { private float pitch; @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof HeadTurnEvent headTurnEvent)) { + if (!(other instanceof HeadTurnEvent otherEvent)) { return false; } - if (!headTurnEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - if (Float.compare(this.getYaw(), headTurnEvent.getYaw()) != 0) { + if (Float.compare(this.getYaw(), otherEvent.getYaw()) != 0) { return false; } - return Float.compare(this.getPitch(), headTurnEvent.getPitch()) == 0; + return Float.compare(this.getPitch(), otherEvent.getPitch()) == 0; } @Generated - protected boolean canEqual(Object object) { - return object instanceof HeadTurnEvent; + protected boolean canEqual(Object other) { + return other instanceof HeadTurnEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - n2 = n2 * 59 + Float.floatToIntBits(this.getYaw()); - n2 = n2 * 59 + Float.floatToIntBits(this.getPitch()); - return n2; + int prime = 59; + int result = 1; + result = result * 59 + Float.floatToIntBits(this.getYaw()); + result = result * 59 + Float.floatToIntBits(this.getPitch()); + return result; } @Generated @@ -49,8 +49,8 @@ implements EventMarker { } @Generated - public HeadTurnEvent(float f, float f2) { - this.yaw = f; - this.pitch = f2; + public HeadTurnEvent(float yaw, float pitch) { + this.yaw = yaw; + this.pitch = pitch; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/JumpMarkerEvent.java b/src/main/java/shit/zen/event/impl/JumpMarkerEvent.java index ec71c9a..a8b3173 100644 --- a/src/main/java/shit/zen/event/impl/JumpMarkerEvent.java +++ b/src/main/java/shit/zen/event/impl/JumpMarkerEvent.java @@ -12,30 +12,30 @@ implements EventMarker { private static final String TO_STRING_PREFIX = "JumpEvent(yaw="; @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof JumpMarkerEvent jumpMarkerEvent)) { + if (!(other instanceof JumpMarkerEvent otherEvent)) { return false; } - if (!jumpMarkerEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - return Float.compare(this.getJumpHeight(), jumpMarkerEvent.getJumpHeight()) == 0; + return Float.compare(this.getJumpHeight(), otherEvent.getJumpHeight()) == 0; } @Generated - protected boolean canEqual(Object object) { - return object instanceof JumpMarkerEvent; + protected boolean canEqual(Object other) { + return other instanceof JumpMarkerEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - n2 = n2 * 59 + Float.floatToIntBits(this.getJumpHeight()); - return n2; + int prime = 59; + int result = 1; + result = result * 59 + Float.floatToIntBits(this.getJumpHeight()); + return result; } @Generated @@ -44,7 +44,7 @@ implements EventMarker { } @Generated - public JumpMarkerEvent(float f) { - this.jumpHeight = f; + public JumpMarkerEvent(float jumpHeight) { + this.jumpHeight = jumpHeight; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/KeyEvent.java b/src/main/java/shit/zen/event/impl/KeyEvent.java index ca0b889..a72dbbe 100644 --- a/src/main/java/shit/zen/event/impl/KeyEvent.java +++ b/src/main/java/shit/zen/event/impl/KeyEvent.java @@ -12,34 +12,34 @@ extends Event { private final boolean pressed; @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof KeyEvent keyEvent)) { + if (!(other instanceof KeyEvent otherEvent)) { return false; } - if (!keyEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - if (this.getKeyCode() != keyEvent.getKeyCode()) { + if (this.getKeyCode() != otherEvent.getKeyCode()) { return false; } - return this.isPressed() == keyEvent.isPressed(); + return this.isPressed() == otherEvent.isPressed(); } @Generated - protected boolean canEqual(Object object) { - return object instanceof KeyEvent; + protected boolean canEqual(Object other) { + return other instanceof KeyEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - n2 = n2 * 59 + this.getKeyCode(); - n2 = n2 * 59 + (this.isPressed() ? 79 : 97); - return n2; + int prime = 59; + int result = 1; + result = result * 59 + this.getKeyCode(); + result = result * 59 + (this.isPressed() ? 79 : 97); + return result; } @Generated @@ -48,8 +48,8 @@ extends Event { } @Generated - public KeyEvent(int n, boolean bl) { - this.keyCode = n; - this.pressed = bl; + public KeyEvent(int keyCode, boolean pressed) { + this.keyCode = keyCode; + this.pressed = pressed; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/MotionEvent.java b/src/main/java/shit/zen/event/impl/MotionEvent.java index 3013856..b0df3e6 100644 --- a/src/main/java/shit/zen/event/impl/MotionEvent.java +++ b/src/main/java/shit/zen/event/impl/MotionEvent.java @@ -27,13 +27,13 @@ extends Event { } @Generated - public MotionEvent(boolean bl, double d, double d2, double d3, float f, float f2, boolean bl2) { - this.pre = bl; - this.x = d; - this.y = d2; - this.z = d3; - this.yaw = f; - this.pitch = f2; - this.onGround = bl2; + public MotionEvent(boolean pre, double x, double y, double z, float yaw, float pitch, boolean onGround) { + this.pre = pre; + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + this.onGround = onGround; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/PacketEvent.java b/src/main/java/shit/zen/event/impl/PacketEvent.java index 18e219e..4c34224 100644 --- a/src/main/java/shit/zen/event/impl/PacketEvent.java +++ b/src/main/java/shit/zen/event/impl/PacketEvent.java @@ -23,8 +23,8 @@ extends Event { } @Generated - public PacketEvent(Packet packet, boolean bl) { + public PacketEvent(Packet packet, boolean incoming) { this.packet = packet; - this.incoming = bl; + this.incoming = incoming; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/RayTraceEvent.java b/src/main/java/shit/zen/event/impl/RayTraceEvent.java index 0ba7c87..756f03a 100644 --- a/src/main/java/shit/zen/event/impl/RayTraceEvent.java +++ b/src/main/java/shit/zen/event/impl/RayTraceEvent.java @@ -18,55 +18,55 @@ implements EventMarker { public float blockRange; @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof RayTraceEvent rayTraceEvent)) { + if (!(other instanceof RayTraceEvent otherEvent)) { return false; } - if (!rayTraceEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - if (Float.compare(this.getRange(), rayTraceEvent.getRange()) != 0) { + if (Float.compare(this.getRange(), otherEvent.getRange()) != 0) { return false; } - if (Float.compare(this.getBlockRange(), rayTraceEvent.getBlockRange()) != 0) { + if (Float.compare(this.getBlockRange(), otherEvent.getBlockRange()) != 0) { return false; } - Entity entity = this.getEntity(); - Entity entity2 = rayTraceEvent.getEntity(); - return !(!Objects.equals(entity, entity2)); + Entity thisEntity = this.getEntity(); + Entity otherEntity = otherEvent.getEntity(); + return !(!Objects.equals(thisEntity, otherEntity)); } @Generated - protected boolean canEqual(Object object) { - return object instanceof RayTraceEvent; + protected boolean canEqual(Object other) { + return other instanceof RayTraceEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - n2 = n2 * 59 + Float.floatToIntBits(this.getRange()); - n2 = n2 * 59 + Float.floatToIntBits(this.getBlockRange()); + int prime = 59; + int result = 1; + result = result * 59 + Float.floatToIntBits(this.getRange()); + result = result * 59 + Float.floatToIntBits(this.getBlockRange()); Entity entity = this.getEntity(); - n2 = n2 * 59 + (entity == null ? 43 : entity.hashCode()); - return n2; + result = result * 59 + (entity == null ? 43 : entity.hashCode()); + return result; } @Generated public String toString() { - float f = this.getBlockRange(); - float f2 = this.getRange(); - String string = String.valueOf(this.getEntity()); - return "RayTraceEvent(entity=" + string + ", yaw=" + f2 + ", pitch=" + f + ")"; + float blockRange = this.getBlockRange(); + float range = this.getRange(); + String entityStr = String.valueOf(this.getEntity()); + return "RayTraceEvent(entity=" + entityStr + ", yaw=" + range + ", pitch=" + blockRange + ")"; } @Generated - public RayTraceEvent(Entity entity, float f, float f2) { + public RayTraceEvent(Entity entity, float range, float blockRange) { this.entity = entity; - this.range = f; - this.blockRange = f2; + this.range = range; + this.blockRange = blockRange; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/Render2DEvent.java b/src/main/java/shit/zen/event/impl/Render2DEvent.java index 1246aba..3f2bf8a 100644 --- a/src/main/java/shit/zen/event/impl/Render2DEvent.java +++ b/src/main/java/shit/zen/event/impl/Render2DEvent.java @@ -28,52 +28,52 @@ public record Render2DEvent(PoseStack poseStack, GuiGraphics guiGraphics, float } @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof Render2DEvent render2DEvent)) { + if (!(other instanceof Render2DEvent otherEvent)) { return false; } - if (!render2DEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - if (Float.compare(this.partialTick(), render2DEvent.partialTick()) != 0) { + if (Float.compare(this.partialTick(), otherEvent.partialTick()) != 0) { return false; } - PoseStack poseStack = this.poseStack(); - PoseStack poseStack2 = render2DEvent.poseStack(); - if (!Objects.equals(poseStack, poseStack2)) { + PoseStack thisPose = this.poseStack(); + PoseStack otherPose = otherEvent.poseStack(); + if (!Objects.equals(thisPose, otherPose)) { return false; } - GuiGraphics guiGraphics = this.guiGraphics(); - GuiGraphics guiGraphics2 = render2DEvent.guiGraphics(); - return !(!Objects.equals(guiGraphics, guiGraphics2)); + GuiGraphics thisGui = this.guiGraphics(); + GuiGraphics otherGui = otherEvent.guiGraphics(); + return !(!Objects.equals(thisGui, otherGui)); } @Generated - protected boolean canEqual(Object object) { - return object instanceof Render2DEvent; + protected boolean canEqual(Object other) { + return other instanceof Render2DEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - n2 = n2 * 59 + Float.floatToIntBits(this.partialTick()); - PoseStack poseStack = this.poseStack(); - n2 = n2 * 59 + (poseStack == null ? 43 : poseStack.hashCode()); - GuiGraphics guiGraphics = this.guiGraphics(); - n2 = n2 * 59 + (guiGraphics == null ? 43 : guiGraphics.hashCode()); - return n2; + int prime = 59; + int result = 1; + result = result * 59 + Float.floatToIntBits(this.partialTick()); + PoseStack pose = this.poseStack(); + result = result * 59 + (pose == null ? 43 : pose.hashCode()); + GuiGraphics gui = this.guiGraphics(); + result = result * 59 + (gui == null ? 43 : gui.hashCode()); + return result; } @Generated public String toString() { - float f = this.partialTick(); - String string = String.valueOf(this.guiGraphics()); - String string2 = String.valueOf(this.poseStack()); - return "Render2DEvent(stack=" + string2 + ", guiGraphics=" + string + ", partialTicks=" + f + ")"; + float partial = this.partialTick(); + String guiStr = String.valueOf(this.guiGraphics()); + String poseStr = String.valueOf(this.poseStack()); + return "Render2DEvent(stack=" + poseStr + ", guiGraphics=" + guiStr + ", partialTicks=" + partial + ")"; } @Generated diff --git a/src/main/java/shit/zen/event/impl/RenderEntityEvent.java b/src/main/java/shit/zen/event/impl/RenderEntityEvent.java index cd8e038..e188aa2 100644 --- a/src/main/java/shit/zen/event/impl/RenderEntityEvent.java +++ b/src/main/java/shit/zen/event/impl/RenderEntityEvent.java @@ -30,19 +30,19 @@ extends Event { } @Override - public void setCancelled(boolean bl) { - this.cancelled = bl; + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; } @Generated - public RenderEntityEvent(EntityRenderer entityRenderer, Entity entity, PoseStack poseStack, MultiBufferSource multiBufferSource, float f, int n, boolean bl) { + public RenderEntityEvent(EntityRenderer entityRenderer, Entity entity, PoseStack poseStack, MultiBufferSource bufferSource, float partialTick, int packedLight, boolean cancelled) { this.entityRenderer = entityRenderer; this.entity = entity; this.poseStack = poseStack; - this.bufferSource = multiBufferSource; - this.partialTick = f; - this.packedLight = n; - this.cancelled = bl; + this.bufferSource = bufferSource; + this.partialTick = partialTick; + this.packedLight = packedLight; + this.cancelled = cancelled; } public static class Pre extends RenderEntityEvent { diff --git a/src/main/java/shit/zen/event/impl/RotationEvent.java b/src/main/java/shit/zen/event/impl/RotationEvent.java index 36f51aa..de28039 100644 --- a/src/main/java/shit/zen/event/impl/RotationEvent.java +++ b/src/main/java/shit/zen/event/impl/RotationEvent.java @@ -13,8 +13,8 @@ implements EventMarker { private float pitch; @Generated - public RotationEvent(float f, float f2) { - this.yaw = f; - this.pitch = f2; + public RotationEvent(float yaw, float pitch) { + this.yaw = yaw; + this.pitch = pitch; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/SlowdownEvent.java b/src/main/java/shit/zen/event/impl/SlowdownEvent.java index 30d2f5b..3e70274 100644 --- a/src/main/java/shit/zen/event/impl/SlowdownEvent.java +++ b/src/main/java/shit/zen/event/impl/SlowdownEvent.java @@ -14,7 +14,7 @@ implements EventMarker { } @Generated - public SlowdownEvent(boolean bl) { - this.slowDown = bl; + public SlowdownEvent(boolean slowDown) { + this.slowDown = slowDown; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/StrafeEvent.java b/src/main/java/shit/zen/event/impl/StrafeEvent.java index 230e060..8159be7 100644 --- a/src/main/java/shit/zen/event/impl/StrafeEvent.java +++ b/src/main/java/shit/zen/event/impl/StrafeEvent.java @@ -15,9 +15,9 @@ implements EventMarker { private boolean sprinting; @Generated - public StrafeEvent(float f, float f2, boolean bl) { - this.forward = f; - this.strafe = f2; - this.sprinting = bl; + public StrafeEvent(float forward, float strafe, boolean sprinting) { + this.forward = forward; + this.strafe = strafe; + this.sprinting = sprinting; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/StuckInBlockEvent.java b/src/main/java/shit/zen/event/impl/StuckInBlockEvent.java index 868f052..d0c24c9 100644 --- a/src/main/java/shit/zen/event/impl/StuckInBlockEvent.java +++ b/src/main/java/shit/zen/event/impl/StuckInBlockEvent.java @@ -22,45 +22,45 @@ extends Event { } @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof StuckInBlockEvent stuckInBlockEvent)) { + if (!(other instanceof StuckInBlockEvent otherEvent)) { return false; } - if (!stuckInBlockEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - BlockState blockState = this.getBlockState(); - BlockState blockState2 = stuckInBlockEvent.getBlockState(); - if (!Objects.equals(blockState, blockState2)) { + BlockState thisState = this.getBlockState(); + BlockState otherState = otherEvent.getBlockState(); + if (!Objects.equals(thisState, otherState)) { return false; } - Vec3 vec3 = this.getMotion(); - Vec3 vec32 = stuckInBlockEvent.getMotion(); - return !(!Objects.equals(vec3, vec32)); + Vec3 thisMotion = this.getMotion(); + Vec3 otherMotion = otherEvent.getMotion(); + return !(!Objects.equals(thisMotion, otherMotion)); } @Generated - protected boolean canEqual(Object object) { - return object instanceof StuckInBlockEvent; + protected boolean canEqual(Object other) { + return other instanceof StuckInBlockEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - BlockState blockState = this.getBlockState(); - n2 = n2 * 59 + (blockState == null ? 43 : blockState.hashCode()); - Vec3 vec3 = this.getMotion(); - n2 = n2 * 59 + (vec3 == null ? 43 : vec3.hashCode()); - return n2; + int prime = 59; + int result = 1; + BlockState state = this.getBlockState(); + result = result * 59 + (state == null ? 43 : state.hashCode()); + Vec3 motion = this.getMotion(); + result = result * 59 + (motion == null ? 43 : motion.hashCode()); + return result; } @Generated - public StuckInBlockEvent(BlockState blockState, Vec3 vec3) { + public StuckInBlockEvent(BlockState blockState, Vec3 motion) { this.blockState = blockState; - this.motion = vec3; + this.motion = motion; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/event/impl/UpdateHeldItemEvent.java b/src/main/java/shit/zen/event/impl/UpdateHeldItemEvent.java index b94d82b..5462822 100644 --- a/src/main/java/shit/zen/event/impl/UpdateHeldItemEvent.java +++ b/src/main/java/shit/zen/event/impl/UpdateHeldItemEvent.java @@ -17,46 +17,46 @@ implements EventMarker { private ItemStack itemStack; @Generated - public UpdateHeldItemEvent(InteractionHand interactionHand, ItemStack itemStack) { - this.hand = interactionHand; + public UpdateHeldItemEvent(InteractionHand hand, ItemStack itemStack) { + this.hand = hand; this.itemStack = itemStack; } @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof UpdateHeldItemEvent updateHeldItemEvent)) { + if (!(other instanceof UpdateHeldItemEvent otherEvent)) { return false; } - if (!updateHeldItemEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - InteractionHand interactionHand = this.getHand(); - InteractionHand interactionHand2 = updateHeldItemEvent.getHand(); - if (!Objects.equals(interactionHand, interactionHand2)) { + InteractionHand thisHand = this.getHand(); + InteractionHand otherHand = otherEvent.getHand(); + if (!Objects.equals(thisHand, otherHand)) { return false; } - ItemStack itemStack = this.getItemStack(); - ItemStack itemStack2 = updateHeldItemEvent.getItemStack(); - return !(!Objects.equals(itemStack, itemStack2)); + ItemStack thisStack = this.getItemStack(); + ItemStack otherStack = otherEvent.getItemStack(); + return !(!Objects.equals(thisStack, otherStack)); } @Generated - protected boolean canEqual(Object object) { - return object instanceof UpdateHeldItemEvent; + protected boolean canEqual(Object other) { + return other instanceof UpdateHeldItemEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - InteractionHand interactionHand = this.getHand(); - n2 = n2 * 59 + (interactionHand == null ? 43 : interactionHand.hashCode()); - ItemStack itemStack = this.getItemStack(); - n2 = n2 * 59 + (itemStack == null ? 43 : itemStack.hashCode()); - return n2; + int prime = 59; + int result = 1; + InteractionHand hand = this.getHand(); + result = result * 59 + (hand == null ? 43 : hand.hashCode()); + ItemStack stack = this.getItemStack(); + result = result * 59 + (stack == null ? 43 : stack.hashCode()); + return result; } @Generated diff --git a/src/main/java/shit/zen/event/impl/UseItemRayTraceEvent.java b/src/main/java/shit/zen/event/impl/UseItemRayTraceEvent.java index b419c0f..09d68d5 100644 --- a/src/main/java/shit/zen/event/impl/UseItemRayTraceEvent.java +++ b/src/main/java/shit/zen/event/impl/UseItemRayTraceEvent.java @@ -13,34 +13,34 @@ implements EventMarker { private float blockRange; @Generated - public boolean equals(Object object) { - if (object == this) { + public boolean equals(Object other) { + if (other == this) { return true; } - if (!(object instanceof UseItemRayTraceEvent useItemRayTraceEvent)) { + if (!(other instanceof UseItemRayTraceEvent otherEvent)) { return false; } - if (!useItemRayTraceEvent.canEqual(this)) { + if (!otherEvent.canEqual(this)) { return false; } - if (Float.compare(this.getRange(), useItemRayTraceEvent.getRange()) != 0) { + if (Float.compare(this.getRange(), otherEvent.getRange()) != 0) { return false; } - return Float.compare(this.getBlockRange(), useItemRayTraceEvent.getBlockRange()) == 0; + return Float.compare(this.getBlockRange(), otherEvent.getBlockRange()) == 0; } @Generated - protected boolean canEqual(Object object) { - return object instanceof UseItemRayTraceEvent; + protected boolean canEqual(Object other) { + return other instanceof UseItemRayTraceEvent; } @Generated public int hashCode() { - int n = 59; - int n2 = 1; - n2 = n2 * 59 + Float.floatToIntBits(this.getRange()); - n2 = n2 * 59 + Float.floatToIntBits(this.getBlockRange()); - return n2; + int prime = 59; + int result = 1; + result = result * 59 + Float.floatToIntBits(this.getRange()); + result = result * 59 + Float.floatToIntBits(this.getBlockRange()); + return result; } @Generated @@ -49,8 +49,8 @@ implements EventMarker { } @Generated - public UseItemRayTraceEvent(float f, float f2) { - this.range = f; - this.blockRange = f2; + public UseItemRayTraceEvent(float range, float blockRange) { + this.range = range; + this.blockRange = blockRange; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/gui/IntroAnimation.java b/src/main/java/shit/zen/gui/IntroAnimation.java index 8d1d027..6fcbb0a 100644 --- a/src/main/java/shit/zen/gui/IntroAnimation.java +++ b/src/main/java/shit/zen/gui/IntroAnimation.java @@ -26,85 +26,85 @@ extends ClientBase { @EventTarget(value=4) public void onRender(GlRenderEvent glRenderEvent) { - float f; - float f2; - long l; + float fadeFactor; + float bgAlpha; + long elapsed; if (this.finished) { return; } if (this.startTime < 0L) { this.startTime = System.currentTimeMillis(); } - long l2 = l = System.currentTimeMillis() - this.startTime; - float f3 = mc.getWindow().getGuiScaledWidth(); - float f4 = mc.getWindow().getGuiScaledHeight(); - float f5 = f3 / 2.0f; - float f6 = f4 / 2.0f; - long l3 = 1100L; - long l4 = l3 + 900L + 700L + 500L + 300L + 500L + 1300L; - if (l2 <= 800L) { - float fadeIn = IntroAnimation.easeOutCubic(IntroAnimation.clamp01((float)l2 / 800.0f)); - f2 = 0.6f * fadeIn; - } else if (l2 <= l4) { - f2 = 0.6f; - } else if (l2 <= l4 + 700L) { - float fadeOut = 1.0f - IntroAnimation.easeInCubic(IntroAnimation.clamp01((float)(l2 - l4) / 700.0f)); - f2 = 0.6f * fadeOut; + long dup = elapsed = System.currentTimeMillis() - this.startTime; + float screenWidth = mc.getWindow().getGuiScaledWidth(); + float screenHeight = mc.getWindow().getGuiScaledHeight(); + float centerX = screenWidth / 2.0f; + float centerY = screenHeight / 2.0f; + long zAppearStart = 1100L; + long fadeOutStart = zAppearStart + 900L + 700L + 500L + 300L + 500L + 1300L; + if (elapsed <= 800L) { + float fadeIn = IntroAnimation.easeOutCubic(IntroAnimation.clamp01((float)elapsed / 800.0f)); + bgAlpha = 0.6f * fadeIn; + } else if (elapsed <= fadeOutStart) { + bgAlpha = 0.6f; + } else if (elapsed <= fadeOutStart + 700L) { + float fadeOut = 1.0f - IntroAnimation.easeInCubic(IntroAnimation.clamp01((float)(elapsed - fadeOutStart) / 700.0f)); + bgAlpha = 0.6f * fadeOut; } else { this.finish(); return; } - Paint paint = GlHelper.toPaint(new Color(0, 0, 0, (int)(f2 * 255.0f))); - GlHelper.drawRect(0.0f, 0.0f, f3, f4, paint); - float f7 = 1.0f; - float f8 = 0.0f; - if (l2 >= l3) { - long l5 = l2 - l3; - if (l5 <= 900L) { - float f9 = IntroAnimation.easeOutCubic(IntroAnimation.clamp01((float)l5 / 900.0f)); - f7 = IntroAnimation.lerp(2.0f, 1.0f, f9); - f8 = f9; + Paint paint = GlHelper.toPaint(new Color(0, 0, 0, (int)(bgAlpha * 255.0f))); + GlHelper.drawRect(0.0f, 0.0f, screenWidth, screenHeight, paint); + float zScale = 1.0f; + float zAlpha = 0.0f; + if (elapsed >= zAppearStart) { + long sinceZ = elapsed - zAppearStart; + if (sinceZ <= 900L) { + float zProgress = IntroAnimation.easeOutCubic(IntroAnimation.clamp01((float)sinceZ / 900.0f)); + zScale = IntroAnimation.lerp(2.0f, 1.0f, zProgress); + zAlpha = zProgress; } else { - f7 = 1.0f; - f8 = 1.0f; + zScale = 1.0f; + zAlpha = 1.0f; } } - float f10 = 0.0f; - long l6 = l3 + 900L + 700L; - if (l2 > l6 && l2 <= l6 + 500L) { - f10 = IntroAnimation.easeOutCubic((float)(l2 - l6) / 500.0f); - } else if (l2 > l6 + 500L) { - f10 = 1.0f; + float slideProgress = 0.0f; + long slideStart = zAppearStart + 900L + 700L; + if (elapsed > slideStart && elapsed <= slideStart + 500L) { + slideProgress = IntroAnimation.easeOutCubic((float)(elapsed - slideStart) / 500.0f); + } else if (elapsed > slideStart + 500L) { + slideProgress = 1.0f; } - FontRenderer fontRenderer = FontPresets.axiformaBold(64.0f * f7); - FontRenderer fontRenderer2 = FontPresets.axiformaBold(64.0f); - float f11 = GlHelper.getStringWidth("Z", fontRenderer); - float f12 = GlHelper.getStringWidth("EN", fontRenderer2); - float f13 = f5 - f11 / 2.0f; - float f14 = f5 - (f11 + 0.0f + f12) / 2.0f; - float f15 = IntroAnimation.lerp(f13, f14, f10); - float f16 = f6 - fontRenderer.getMetrics().capHeight() / 2.0f; - float f17 = 0.0f; - float f18 = 12.0f; - long l7 = l6 + 500L + 300L; - if (l2 > l7 && l2 <= l7 + 500L) { - f17 = f = IntroAnimation.easeOutCubic((float)(l2 - l7) / 500.0f); - f18 = (1.0f - f) * 12.0f; - } else if (l2 > l7 + 500L) { - f17 = 1.0f; - f18 = 0.0f; + FontRenderer scaledZFont = FontPresets.axiformaBold(64.0f * zScale); + FontRenderer baseFont = FontPresets.axiformaBold(64.0f); + float zWidth = GlHelper.getStringWidth("Z", scaledZFont); + float enWidth = GlHelper.getStringWidth("EN", baseFont); + float zCenterX = centerX - zWidth / 2.0f; + float zSlideX = centerX - (zWidth + 0.0f + enWidth) / 2.0f; + float zRenderX = IntroAnimation.lerp(zCenterX, zSlideX, slideProgress); + float zRenderY = centerY - scaledZFont.getMetrics().capHeight() / 2.0f; + float enAlpha = 0.0f; + float enOffsetY = 12.0f; + long enStart = slideStart + 500L + 300L; + if (elapsed > enStart && elapsed <= enStart + 500L) { + enAlpha = fadeFactor = IntroAnimation.easeOutCubic((float)(elapsed - enStart) / 500.0f); + enOffsetY = (1.0f - fadeFactor) * 12.0f; + } else if (elapsed > enStart + 500L) { + enAlpha = 1.0f; + enOffsetY = 0.0f; } - f = 1.0f; - if (l2 > l4) { - f = 1.0f - IntroAnimation.clamp01((float)(l2 - l4) / 700.0f); + fadeFactor = 1.0f; + if (elapsed > fadeOutStart) { + fadeFactor = 1.0f - IntroAnimation.clamp01((float)(elapsed - fadeOutStart) / 700.0f); } - int n = new Color(1.0f, 1.0f, 1.0f, IntroAnimation.clamp01(f8 * f)).getRGB(); - GlHelper.drawText("Z", f15, f16, fontRenderer, n); - if (f17 > 0.0f) { - float f19 = f15 + f11 + 0.0f; - float f20 = f6 - fontRenderer2.getMetrics().capHeight() / 2.0f + f18; - int n2 = new Color(1.0f, 1.0f, 1.0f, IntroAnimation.clamp01(f17 * f)).getRGB(); - GlHelper.drawText("EN", f19, f20, fontRenderer2, n2); + int zColor = new Color(1.0f, 1.0f, 1.0f, IntroAnimation.clamp01(zAlpha * fadeFactor)).getRGB(); + GlHelper.drawText("Z", zRenderX, zRenderY, scaledZFont, zColor); + if (enAlpha > 0.0f) { + float enX = zRenderX + zWidth + 0.0f; + float enY = centerY - baseFont.getMetrics().capHeight() / 2.0f + enOffsetY; + int enColor = new Color(1.0f, 1.0f, 1.0f, IntroAnimation.clamp01(enAlpha * fadeFactor)).getRGB(); + GlHelper.drawText("EN", enX, enY, baseFont, enColor); } } @@ -120,23 +120,23 @@ extends ClientBase { } } - private static float clamp01(float f) { - return f < 0.0f ? 0.0f : (f > 1.0f ? 1.0f : f); + private static float clamp01(float value) { + return value < 0.0f ? 0.0f : (value > 1.0f ? 1.0f : value); } - private static float lerp(float f, float f2, float f3) { - return f + (f2 - f) * f3; + private static float lerp(float from, float to, float t) { + return from + (to - from) * t; } - private static float easeOutCubic(float f) { - float f2 = IntroAnimation.clamp01(f); - f2 = (float)(1.0 - Math.pow(1.0f - f2, 3.0)); - return f2; + private static float easeOutCubic(float t) { + float clamped = IntroAnimation.clamp01(t); + clamped = (float)(1.0 - Math.pow(1.0f - clamped, 3.0)); + return clamped; } - private static float easeInCubic(float f) { - float f2 = IntroAnimation.clamp01(f); - f2 = f2 * f2 * f2; - return f2; + private static float easeInCubic(float t) { + float clamped = IntroAnimation.clamp01(t); + clamped = clamped * clamped * clamped; + return clamped; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/NewClickGui.java b/src/main/java/shit/zen/gui/NewClickGui.java index efa606e..98b7fa0 100644 --- a/src/main/java/shit/zen/gui/NewClickGui.java +++ b/src/main/java/shit/zen/gui/NewClickGui.java @@ -31,31 +31,31 @@ extends Screen { protected void init() { System.out.println("13"); focusedPanel = categoryPanels.get(0); - float f = (float)this.width / 2.0f - 380.0f; + float panelX = (float)this.width / 2.0f - 380.0f; for (CategoryPanel categoryPanel : categoryPanels) { - categoryPanel.setX(f); + categoryPanel.setX(panelX); categoryPanel.setY(36.0f); - f += 128.0f; + panelX += 128.0f; } initialized = true; System.out.println("14"); } - public void render(@NonNull GuiGraphics guiGraphics, int n, int n2, float f) { + public void render(@NonNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { if (guiGraphics == null) { throw new NullPointerException("graphics is marked non-null but is null"); } this.closeAnim.animate(this.closing ? 0.0 : 1.0, 0.2, Easings.EASE_OUT_POW2); this.closeAnim.tick(); - float f2 = this.closeAnim.getValueF(); - if (Mth.equal(f2, 0.0f) && this.closing) { + float closeProgress = this.closeAnim.getValueF(); + if (Mth.equal(closeProgress, 0.0f) && this.closing) { this.closing = false; super.onClose(); categoryPanels.forEach(CategoryPanel::reset); return; } for (CategoryPanel categoryPanel : categoryPanels) { - categoryPanel.render(this, guiGraphics, guiGraphics.pose(), n, n2, f2, f); + categoryPanel.render(this, guiGraphics, guiGraphics.pose(), mouseX, mouseY, closeProgress, partialTicks); } } @@ -63,18 +63,18 @@ extends Screen { this.closing = true; } - public boolean mouseClicked(double d, double d2, int n) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { for (CategoryPanel categoryPanel : categoryPanels) { - if (!categoryPanel.mouseClicked(d, d2, n)) continue; + if (!categoryPanel.mouseClicked(mouseX, mouseY, button)) continue; focusedPanel = categoryPanel; return true; } - return super.mouseClicked(d, d2, n); + return super.mouseClicked(mouseX, mouseY, button); } - public boolean mouseReleased(double d, double d2, int n) { + public boolean mouseReleased(double mouseX, double mouseY, int button) { for (CategoryPanel categoryPanel : categoryPanels) { - categoryPanel.mouseReleased(d, d2, n); + categoryPanel.mouseReleased(mouseX, mouseY, button); } return false; } @@ -83,9 +83,9 @@ extends Screen { return false; } - public boolean mouseScrolled(double d, double d2, double d3) { + public boolean mouseScrolled(double mouseX, double mouseY, double scrollDelta) { for (CategoryPanel categoryPanel : categoryPanels) { - if (!categoryPanel.mouseScrolled(d, d2, d3)) continue; + if (!categoryPanel.mouseScrolled(mouseX, mouseY, scrollDelta)) continue; return true; } return false; diff --git a/src/main/java/shit/zen/gui/OldClickGui.java b/src/main/java/shit/zen/gui/OldClickGui.java index 86ea2e3..8585787 100644 --- a/src/main/java/shit/zen/gui/OldClickGui.java +++ b/src/main/java/shit/zen/gui/OldClickGui.java @@ -17,10 +17,10 @@ extends Screen { public OldClickGui() { super(Component.nullToEmpty(TITLE)); - int n = 20; + int x = 20; for (Category category : Category.values()) { - this.categoryPanels.add(new CategoryPanel(n, 20, 140, 20, category)); - n += 160; + this.categoryPanels.add(new CategoryPanel(x, 20, 140, 20, category)); + x += 160; } } @@ -33,31 +33,31 @@ extends Screen { } } - public void render(GuiGraphics guiGraphics, int n, int n2, float f) { + public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { for (CategoryPanel categoryPanel : this.categoryPanels) { - categoryPanel.render(guiGraphics, n, n2, f); - categoryPanel.mouseDragged(n, n2); + categoryPanel.render(guiGraphics, mouseX, mouseY, partialTicks); + categoryPanel.mouseDragged(mouseX, mouseY); } - super.render(guiGraphics, n, n2, f); + super.render(guiGraphics, mouseX, mouseY, partialTicks); } - public boolean mouseReleased(double d, double d2, int n) { + public boolean mouseReleased(double mouseX, double mouseY, int button) { for (CategoryPanel categoryPanel : this.categoryPanels) { - categoryPanel.mouseReleased(d, d2, n); + categoryPanel.mouseReleased(mouseX, mouseY, button); } - return super.mouseReleased(d, d2, n); + return super.mouseReleased(mouseX, mouseY, button); } - public boolean mouseClicked(double d, double d2, int n) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { for (CategoryPanel categoryPanel : this.categoryPanels) { - categoryPanel.mouseClicked(d, d2, n); + categoryPanel.mouseClicked(mouseX, mouseY, button); } return true; } - public boolean mouseScrolled(double d, double d2, double d3) { + public boolean mouseScrolled(double mouseX, double mouseY, double scrollDelta) { for (CategoryPanel categoryPanel : this.categoryPanels) { - categoryPanel.mouseScrolled(d, d2, d3); + categoryPanel.mouseScrolled(mouseX, mouseY, scrollDelta); } return true; } diff --git a/src/main/java/shit/zen/gui/PanelClickGui.java b/src/main/java/shit/zen/gui/PanelClickGui.java index 233b1ae..d4ac778 100644 --- a/src/main/java/shit/zen/gui/PanelClickGui.java +++ b/src/main/java/shit/zen/gui/PanelClickGui.java @@ -81,11 +81,11 @@ extends Screen { this.settingsPanel = new SettingsPanel(); } - public void setScale(float f) { - if (this.currentOpenState == PanelClickGui.ScaleSwitchState.IDLE && f != this.currentScale) { - this.targetScale = f; + public void setScale(float newScale) { + if (this.currentOpenState == PanelClickGui.ScaleSwitchState.IDLE && newScale != this.currentScale) { + this.targetScale = newScale; this.currentOpenState = PanelClickGui.ScaleSwitchState.FADING_OUT; - this.scaleSwitchOverlay.show(this.currentScale, f); + this.scaleSwitchOverlay.show(this.currentScale, newScale); } } @@ -116,46 +116,46 @@ extends Screen { } } - private float easeOutCubic(float f) { - return (float)(1.0 - Math.pow(1.0f - f, 3.0)); + private float easeOutCubic(float t) { + return (float)(1.0 - Math.pow(1.0f - t, 3.0)); } - public void render(@Nonnull GuiGraphics guiGraphics, int n, int n2, float f) { - float f2; + public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { + float eased; LerpUtil.update(); this.updateOpenState(); if (this.currentScaleSwitchState == PanelClickGui.OpenState.CLOSED && this.openProgress <= 0.0f) { return; } - float f3 = f2 = this.easeOutCubic(this.openProgress); - float f4 = 0.98f + 0.02f * f2; - guiGraphics.fill(0, 0, this.width, this.height, new Color(0, 0, 0, (int)(80.0f * f3)).getRGB()); + float dup = eased = this.easeOutCubic(this.openProgress); + float scaleFactor = 0.98f + 0.02f * eased; + guiGraphics.fill(0, 0, this.width, this.height, new Color(0, 0, 0, (int)(80.0f * dup)).getRGB()); this.updateScaleSwitchState(); - int n3 = this.width / 2; - int n4 = this.height / 2; + int centerX = this.width / 2; + int centerY = this.height / 2; guiGraphics.pose().pushPose(); - guiGraphics.pose().translate((float)n3, (float)n4, 0.0f); - guiGraphics.pose().scale(f4, f4, 1.0f); - guiGraphics.pose().translate((float)(-n3), (float)(-n4), 0.0f); - float f5 = this.currentOpenState == PanelClickGui.ScaleSwitchState.FADING_OUT || this.currentOpenState == PanelClickGui.ScaleSwitchState.WAITING ? this.targetScale : this.currentScale; - int n5 = (int)(600.0f * this.currentScale); - int n6 = (int)(400.0f * this.currentScale); - int n7 = n3 - n5 / 2; - int n8 = n4 - n6 / 2; - float f6 = this.panelAlpha * f3; - if (f6 > 0.005f) { - this.drawPanelGlow(guiGraphics, n7, n8, f, f6); - this.categoryBar.render(guiGraphics, n7, n8, n, n2, this.currentScale, f6); - this.moduleListPanel.render(guiGraphics, n7, n8, n, n2, this.getSelectedCategory(), this.currentScale, f6); - this.settingsPanel.render(guiGraphics, n7, n8, n, n2, this.moduleListPanel.getHoveredModule(), this.currentScale, f6); - this.profileWidget.render(guiGraphics, n7, n8, n, n2, this.currentScale, f6); - this.drawSearchBar(guiGraphics, n7, n8, n, n2, f6); - this.drawToasts(guiGraphics, n7, n8, f6); + guiGraphics.pose().translate((float)centerX, (float)centerY, 0.0f); + guiGraphics.pose().scale(scaleFactor, scaleFactor, 1.0f); + guiGraphics.pose().translate((float)(-centerX), (float)(-centerY), 0.0f); + float overlayScale = this.currentOpenState == PanelClickGui.ScaleSwitchState.FADING_OUT || this.currentOpenState == PanelClickGui.ScaleSwitchState.WAITING ? this.targetScale : this.currentScale; + int panelWidth = (int)(600.0f * this.currentScale); + int panelHeight = (int)(400.0f * this.currentScale); + int panelX = centerX - panelWidth / 2; + int panelY = centerY - panelHeight / 2; + float effectiveAlpha = this.panelAlpha * dup; + if (effectiveAlpha > 0.005f) { + this.drawPanelGlow(guiGraphics, panelX, panelY, partialTicks, effectiveAlpha); + this.categoryBar.render(guiGraphics, panelX, panelY, mouseX, mouseY, this.currentScale, effectiveAlpha); + this.moduleListPanel.render(guiGraphics, panelX, panelY, mouseX, mouseY, this.getSelectedCategory(), this.currentScale, effectiveAlpha); + this.settingsPanel.render(guiGraphics, panelX, panelY, mouseX, mouseY, this.moduleListPanel.getHoveredModule(), this.currentScale, effectiveAlpha); + this.profileWidget.render(guiGraphics, panelX, panelY, mouseX, mouseY, this.currentScale, effectiveAlpha); + this.drawSearchBar(guiGraphics, panelX, panelY, mouseX, mouseY, effectiveAlpha); + this.drawToasts(guiGraphics, panelX, panelY, effectiveAlpha); } - super.render(guiGraphics, n, n2, f); + super.render(guiGraphics, mouseX, mouseY, partialTicks); guiGraphics.pose().popPose(); - this.keybindOverlay.render(guiGraphics, this.width, this.height, f5); - this.scaleSwitchOverlay.render(guiGraphics, this.width, this.height, f5); + this.keybindOverlay.render(guiGraphics, this.width, this.height, overlayScale); + this.scaleSwitchOverlay.render(guiGraphics, this.width, this.height, overlayScale); } private void updateScaleSwitchState() { @@ -182,38 +182,38 @@ extends Screen { } } - private void drawPanelGlow(GuiGraphics guiGraphics, int n, int n2, float f, float f2) { - int n3 = (int)(600.0f * this.currentScale); - int n4 = (int)(400.0f * this.currentScale); - TextGlow.drawBackground(guiGraphics.pose(), n, n2, n3, n4, 12.0f * this.currentScale, f2); + private void drawPanelGlow(GuiGraphics guiGraphics, int panelX, int panelY, float partialTicks, float alpha) { + int panelWidth = (int)(600.0f * this.currentScale); + int panelHeight = (int)(400.0f * this.currentScale); + TextGlow.drawBackground(guiGraphics.pose(), panelX, panelY, panelWidth, panelHeight, 12.0f * this.currentScale, alpha); } - public boolean mouseClicked(double d, double d2, int n) { - boolean bl; + public boolean mouseClicked(double mouseX, double mouseY, int button) { + boolean overSearch; if (this.openProgress < 1.0f) { return true; } if (this.keybindOverlay.isVisible()) { - if (n == 0) { + if (button == 0) { this.keybindOverlay.cancel(); } return true; } - int n2 = this.width / 2; - int n3 = this.height / 2; - int n4 = (int)(600.0f * this.currentScale); - int n5 = (int)(400.0f * this.currentScale); - int n6 = n2 - n4 / 2; - int n7 = n3 - n5 / 2; - if (this.profileWidget.isPopupOpen() && this.profileWidget.onMouseClick(n6, n7, (int)d, (int)d2, this.currentScale)) { + int centerX = this.width / 2; + int centerY = this.height / 2; + int panelWidth = (int)(600.0f * this.currentScale); + int panelHeight = (int)(400.0f * this.currentScale); + int panelX = centerX - panelWidth / 2; + int panelY = centerY - panelHeight / 2; + if (this.profileWidget.isPopupOpen() && this.profileWidget.onMouseClick(panelX, panelY, (int)mouseX, (int)mouseY, this.currentScale)) { return true; } - int n8 = (int)(200.0f * this.currentScale); - int n9 = (int)(20.0f * this.currentScale); - int n10 = n6 + (n4 - n8) / 2; - int n11 = n7 + n5 + (int)(15.0f * this.currentScale); - boolean bl2 = bl = d >= (double)n10 && d <= (double)(n10 + n8) && d2 >= (double)n11 && d2 <= (double)(n11 + n9); - if (bl) { + int searchWidth = (int)(200.0f * this.currentScale); + int searchHeight = (int)(20.0f * this.currentScale); + int searchX = panelX + (panelWidth - searchWidth) / 2; + int searchY = panelY + panelHeight + (int)(15.0f * this.currentScale); + boolean dup = overSearch = mouseX >= (double)searchX && mouseX <= (double)(searchX + searchWidth) && mouseY >= (double)searchY && mouseY <= (double)(searchY + searchHeight); + if (overSearch) { if (!this.searchActive) { this.searchActive = true; this.searchQuery = ""; @@ -224,78 +224,78 @@ extends Screen { return true; } this.searchFocused = false; - boolean bl3 = false; - if (n == 0 || n == 1 || n == 2) { - if (!bl3 && n == 0 && this.categoryBar.onMouseClick(n6, n7, (int)d, (int)d2, this.currentScale)) { + boolean handled = false; + if (button == 0 || button == 1 || button == 2) { + if (!handled && button == 0 && this.categoryBar.onMouseClick(panelX, panelY, (int)mouseX, (int)mouseY, this.currentScale)) { if (this.searchActive) { this.searchActive = false; this.searchFocused = false; this.searchQuery = ""; this.moduleListPanel.setSearchQuery(null); } - bl3 = true; + handled = true; } - if (!bl3 && this.moduleListPanel.onMouseClick(n6, n7, (int)d, (int)d2, this.getSelectedCategory(), n, this.currentScale)) { - bl3 = true; + if (!handled && this.moduleListPanel.onMouseClick(panelX, panelY, (int)mouseX, (int)mouseY, this.getSelectedCategory(), button, this.currentScale)) { + handled = true; } - if (!bl3 && this.profileWidget.onMouseClick(n6, n7, (int)d, (int)d2, this.currentScale)) { - bl3 = true; + if (!handled && this.profileWidget.onMouseClick(panelX, panelY, (int)mouseX, (int)mouseY, this.currentScale)) { + handled = true; } - if (!bl3 && (n == 0 || n == 1) && this.settingsPanel.onMouseClick(n6, n7, (int)d, (int)d2, n, this.currentScale)) { - bl3 = true; + if (!handled && (button == 0 || button == 1) && this.settingsPanel.onMouseClick(panelX, panelY, (int)mouseX, (int)mouseY, button, this.currentScale)) { + handled = true; } } - if (!bl3) { + if (!handled) { NumberSettingRenderer.clearEditing(); } - return bl3 || super.mouseClicked(d, d2, n); + return handled || super.mouseClicked(mouseX, mouseY, button); } - public boolean mouseReleased(double d, double d2, int n) { + public boolean mouseReleased(double mouseX, double mouseY, int button) { if (this.openProgress < 1.0f) { return true; } this.moduleListPanel.onMouseRelease(); - this.settingsPanel.onMouseRelease(d, d2, n); + this.settingsPanel.onMouseRelease(mouseX, mouseY, button); this.profileWidget.onMouseRelease(); - return super.mouseReleased(d, d2, n); + return super.mouseReleased(mouseX, mouseY, button); } - public boolean mouseScrolled(double d, double d2, double d3) { + public boolean mouseScrolled(double mouseX, double mouseY, double scrollDelta) { if (this.openProgress < 1.0f) { return true; } - int n = this.width / 2; - int n2 = n - (int)(600.0f * this.currentScale) / 2; - int n3 = this.height / 2; - int n4 = n3 - (int)(400.0f * this.currentScale) / 2; - if (this.moduleListPanel.isMouseOverPanel(n2, n4, (int)d, (int)d2, this.currentScale)) { - this.moduleListPanel.onScroll(d3, this.currentScale); + int centerX = this.width / 2; + int panelX = centerX - (int)(600.0f * this.currentScale) / 2; + int centerY = this.height / 2; + int panelY = centerY - (int)(400.0f * this.currentScale) / 2; + if (this.moduleListPanel.isMouseOverPanel(panelX, panelY, (int)mouseX, (int)mouseY, this.currentScale)) { + this.moduleListPanel.onScroll(scrollDelta, this.currentScale); return true; } - if (this.settingsPanel.isMouseOverPanel(n2, n4, (int)d, (int)d2, this.currentScale)) { - this.settingsPanel.onScroll(d3, this.currentScale); + if (this.settingsPanel.isMouseOverPanel(panelX, panelY, (int)mouseX, (int)mouseY, this.currentScale)) { + this.settingsPanel.onScroll(scrollDelta, this.currentScale); return true; } - return super.mouseScrolled(d, d2, d3); + return super.mouseScrolled(mouseX, mouseY, scrollDelta); } - public boolean mouseDragged(double d, double d2, int n, double d3, double d4) { + public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) { if (this.openProgress < 1.0f) { return true; } - this.moduleListPanel.onMouseDrag(d, d2, this.currentScale); - this.settingsPanel.onMouseDrag(d, d2, this.currentScale); - this.profileWidget.onMouseDrag((int)d, (int)d2); - return super.mouseDragged(d, d2, n, d3, d4); + this.moduleListPanel.onMouseDrag(mouseX, mouseY, this.currentScale); + this.settingsPanel.onMouseDrag(mouseX, mouseY, this.currentScale); + this.profileWidget.onMouseDrag((int)mouseX, (int)mouseY); + return super.mouseDragged(mouseX, mouseY, button, dragX, dragY); } - public boolean keyPressed(int n, int n2, int n3) { - if (this.keybindOverlay.onKeyPress(n, n2, n3)) { + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if (this.keybindOverlay.onKeyPress(keyCode, scanCode, modifiers)) { return true; } if (this.searchActive) { - if (n == 256) { + if (keyCode == 256) { this.searchActive = false; this.searchFocused = false; this.searchQuery = ""; @@ -304,7 +304,7 @@ extends Screen { } if (this.searchFocused) { this.searchCursorTime = System.currentTimeMillis(); - if (n == 259) { + if (keyCode == 259) { if (!this.searchQuery.isEmpty()) { this.searchQuery = this.searchQuery.substring(0, this.searchQuery.length() - 1); this.moduleListPanel.setSearchQuery(this.searchQuery); @@ -313,17 +313,17 @@ extends Screen { } } } - if (NumberSettingRenderer.onKeyPress(n, n2, n3)) { + if (NumberSettingRenderer.onKeyPress(keyCode, scanCode, modifiers)) { return true; } - if (n == 256 && !this.keybindOverlay.isVisible() && !this.searchActive) { + if (keyCode == 256 && !this.keybindOverlay.isVisible() && !this.searchActive) { this.onClose(); return true; } - return super.keyPressed(n, n2, n3); + return super.keyPressed(keyCode, scanCode, modifiers); } - public boolean charTyped(char c, int n) { + public boolean charTyped(char c, int modifiers) { if (this.searchActive && this.searchFocused) { this.searchCursorTime = System.currentTimeMillis(); this.searchQuery = this.searchQuery + c; @@ -333,7 +333,7 @@ extends Screen { if (NumberSettingRenderer.onCharTyped(c)) { return true; } - return super.charTyped(c, n); + return super.charTyped(c, modifiers); } public boolean isPauseScreen() { @@ -362,43 +362,43 @@ extends Screen { return this.settingsPanel; } - private void drawSearchBar(GuiGraphics guiGraphics, int n, int n2, int n3, int n4, float f) { + private void drawSearchBar(GuiGraphics guiGraphics, int panelX, int panelY, int mouseX, int mouseY, float alpha) { try { - int n5 = (int)(600.0f * this.currentScale); - int n6 = (int)(400.0f * this.currentScale); - int n7 = (int)(200.0f * this.currentScale); - int n8 = (int)(20.0f * this.currentScale); - int n9 = n + (n5 - n7) / 2; - int n10 = n2 + n6 + (int)(15.0f * this.currentScale); - TextGlow.drawBackground(guiGraphics.pose(), n9, n10, n7, n8, 8.0f * this.currentScale, f); + int panelWidth = (int)(600.0f * this.currentScale); + int panelHeight = (int)(400.0f * this.currentScale); + int searchWidth = (int)(200.0f * this.currentScale); + int searchHeight = (int)(20.0f * this.currentScale); + int searchX = panelX + (panelWidth - searchWidth) / 2; + int searchY = panelY + panelHeight + (int)(15.0f * this.currentScale); + TextGlow.drawBackground(guiGraphics.pose(), searchX, searchY, searchWidth, searchHeight, 8.0f * this.currentScale, alpha); Renderer.renderConsumer((drawContext -> { - FontRenderer fontRenderer = FontPresets.materialIcons(20.0f * this.currentScale); - String string = ""; - float f2 = (float)n9 + 12.0f * this.currentScale; - float f3 = (float)n10 + (float)n8 / 2.0f + fontRenderer.getMetrics().capHeight() / 2.0f - 12.0f * this.currentScale; - int iconColor = new Color(255, 255, 255, (int)(180.0f * f)).getRGB(); - TextGlow.drawGlowText(string, f2, f3, fontRenderer, -2236963, iconColor, 12.0f * this.currentScale); - FontRenderer fontRenderer2 = FontPresets.axiformaRegular(16.0f * this.currentScale); + FontRenderer iconFont = FontPresets.materialIcons(20.0f * this.currentScale); + String iconText = ""; + float iconX = (float)searchX + 12.0f * this.currentScale; + float iconY = (float)searchY + (float)searchHeight / 2.0f + iconFont.getMetrics().capHeight() / 2.0f - 12.0f * this.currentScale; + int iconColor = new Color(255, 255, 255, (int)(180.0f * alpha)).getRGB(); + TextGlow.drawGlowText(iconText, iconX, iconY, iconFont, -2236963, iconColor, 12.0f * this.currentScale); + FontRenderer queryFont = FontPresets.axiformaRegular(16.0f * this.currentScale); if (this.searchActive || !this.searchQuery.isEmpty()) { - float f4 = (float)n9 + 35.0f * this.currentScale; - float f5 = (float)n10 + (float)n8 / 2.0f + fontRenderer2.getMetrics().capHeight() / 2.0f - 9.0f * this.currentScale; - int queryColor = new Color(255, 255, 255, (int)(120.0f * f)).getRGB(); - TextGlow.drawGlowText(this.searchQuery, f4, f5, fontRenderer2, -1, queryColor, 8.0f * this.currentScale); + float queryX = (float)searchX + 35.0f * this.currentScale; + float queryY = (float)searchY + (float)searchHeight / 2.0f + queryFont.getMetrics().capHeight() / 2.0f - 9.0f * this.currentScale; + int queryColor = new Color(255, 255, 255, (int)(120.0f * alpha)).getRGB(); + TextGlow.drawGlowText(this.searchQuery, queryX, queryY, queryFont, -1, queryColor, 8.0f * this.currentScale); if (this.searchFocused) { - long l = System.currentTimeMillis() - this.searchCursorTime; - float f6 = (float)(Math.sin((double)l / 200.0) * 0.5 + 0.5); - int cursorColor = (int)(f6 * f * 255.0f) << 24 | 0xFFFFFF; - float f7 = f4 + GlHelper.getStringWidth(this.searchQuery, fontRenderer2) + 2.0f * this.currentScale; - float f8 = fontRenderer2.getMetrics().capHeight(); - RenderUtil.drawFilledRect(guiGraphics.pose(), f7, f5 - f8 + 11.0f * this.currentScale, this.currentScale, f8 - 3.0f * this.currentScale, cursorColor); + long sinceCursor = System.currentTimeMillis() - this.searchCursorTime; + float blinkAmount = (float)(Math.sin((double)sinceCursor / 200.0) * 0.5 + 0.5); + int cursorColor = (int)(blinkAmount * alpha * 255.0f) << 24 | 0xFFFFFF; + float cursorX = queryX + GlHelper.getStringWidth(this.searchQuery, queryFont) + 2.0f * this.currentScale; + float cursorHeight = queryFont.getMetrics().capHeight(); + RenderUtil.drawFilledRect(guiGraphics.pose(), cursorX, queryY - cursorHeight + 11.0f * this.currentScale, this.currentScale, cursorHeight - 3.0f * this.currentScale, cursorColor); } } else { - FontRenderer fontRenderer3 = FontPresets.axiformaBold(14.0f * this.currentScale); - String string2 = "search"; - float f9 = GlHelper.getStringWidth(string2, fontRenderer3); - float f10 = (float)n9 + ((float)n7 - f9) / 2.0f; - float f11 = (float)n10 + (float)n8 / 2.0f + fontRenderer3.getMetrics().capHeight() / 2.0f - 8.0f * this.currentScale; - TextGlow.drawGlowText(string2, f10, f11, fontRenderer3, -3355444, new Color(255, 255, 255, (int)(130.0f * f)).getRGB(), 10.0f * this.currentScale); + FontRenderer placeholderFont = FontPresets.axiformaBold(14.0f * this.currentScale); + String placeholder = "search"; + float placeholderWidth = GlHelper.getStringWidth(placeholder, placeholderFont); + float placeholderX = (float)searchX + ((float)searchWidth - placeholderWidth) / 2.0f; + float placeholderY = (float)searchY + (float)searchHeight / 2.0f + placeholderFont.getMetrics().capHeight() / 2.0f - 8.0f * this.currentScale; + TextGlow.drawGlowText(placeholder, placeholderX, placeholderY, placeholderFont, -3355444, new Color(255, 255, 255, (int)(130.0f * alpha)).getRGB(), 10.0f * this.currentScale); } })); } catch (Exception exception) { @@ -406,48 +406,48 @@ extends Screen { } } - public void addToast(String string) { - for (PanelClickGui.ToastEntry panelClickGui$ToastEntry : this.toasts) { - panelClickGui$ToastEntry.targetY -= 20.0f * this.currentScale; + public void addToast(String message) { + for (PanelClickGui.ToastEntry toast : this.toasts) { + toast.targetY -= 20.0f * this.currentScale; } - this.toasts.add(new PanelClickGui.ToastEntry(string)); + this.toasts.add(new PanelClickGui.ToastEntry(message)); } public void selectModule(Module module) { this.keybindOverlay.startBinding(module); } - private void drawToasts(GuiGraphics guiGraphics, int n, int n2, float f) { + private void drawToasts(GuiGraphics guiGraphics, int panelX, int panelY, float alpha) { if (this.toasts.isEmpty()) { return; } try { Renderer.renderConsumer((drawContext -> { - FontRenderer fontRenderer = FontPresets.axiformaBold(18.0f * this.currentScale); - for (PanelClickGui.ToastEntry panelClickGui$ToastEntry : this.toasts) { - long l = System.currentTimeMillis() - panelClickGui$ToastEntry.createdAt; - panelClickGui$ToastEntry.currentY = LerpUtil.smoothLerp(panelClickGui$ToastEntry.currentY, panelClickGui$ToastEntry.targetY, 0.2f); - float f2 = 0.0f; - if (l < 2000L) { - f2 = 1.0f; - } else if (l < 2500L) { - long l2 = l - 2000L; - f2 = 1.0f - (float)l2 / 500.0f; + FontRenderer toastFont = FontPresets.axiformaBold(18.0f * this.currentScale); + for (PanelClickGui.ToastEntry toast : this.toasts) { + long elapsed = System.currentTimeMillis() - toast.createdAt; + toast.currentY = LerpUtil.smoothLerp(toast.currentY, toast.targetY, 0.2f); + float targetAlpha = 0.0f; + if (elapsed < 2000L) { + targetAlpha = 1.0f; + } else if (elapsed < 2500L) { + long fadeMs = elapsed - 2000L; + targetAlpha = 1.0f - (float)fadeMs / 500.0f; } - panelClickGui$ToastEntry.alpha = LerpUtil.smoothLerp(panelClickGui$ToastEntry.alpha, f2, 0.25f); - if (panelClickGui$ToastEntry.alpha < 0.01f && l > 2000L) { - this.toasts.remove(panelClickGui$ToastEntry); + toast.alpha = LerpUtil.smoothLerp(toast.alpha, targetAlpha, 0.25f); + if (toast.alpha < 0.01f && elapsed > 2000L) { + this.toasts.remove(toast); continue; } - float f3 = GlHelper.getStringWidth(panelClickGui$ToastEntry.message, fontRenderer); - int n3 = (int)(600.0f * this.currentScale); - float f4 = (float)n + ((float)n3 - f3) / 2.0f; - float f5 = (float)(n2 - 25) + panelClickGui$ToastEntry.currentY; - int n4 = (int)(255.0f * panelClickGui$ToastEntry.alpha * f); - int n5 = n4 << 24 | 0xFFFFFF; - int n6 = (int)(120.0f * panelClickGui$ToastEntry.alpha * f); - int n7 = n6 << 24 | 0xFFFFFF; - TextGlow.drawGlowText(panelClickGui$ToastEntry.message, f4, f5 + 6.0f * this.currentScale, fontRenderer, n5, n7, 8.0f * this.currentScale); + float toastWidth = GlHelper.getStringWidth(toast.message, toastFont); + int panelWidth = (int)(600.0f * this.currentScale); + float toastX = (float)panelX + ((float)panelWidth - toastWidth) / 2.0f; + float toastY = (float)(panelY - 25) + toast.currentY; + int textAlpha = (int)(255.0f * toast.alpha * alpha); + int textColor = textAlpha << 24 | 0xFFFFFF; + int glowAlpha = (int)(120.0f * toast.alpha * alpha); + int glowColor = glowAlpha << 24 | 0xFFFFFF; + TextGlow.drawGlowText(toast.message, toastX, toastY + 6.0f * this.currentScale, toastFont, textColor, glowColor, 8.0f * this.currentScale); } })); } catch (Exception exception) { @@ -458,4 +458,4 @@ extends Screen { static { PanelClickGui panelClickGui = new PanelClickGui(); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/legacy/BooleanComponent.java b/src/main/java/shit/zen/gui/legacy/BooleanComponent.java index 2384b23..9bf176f 100644 --- a/src/main/java/shit/zen/gui/legacy/BooleanComponent.java +++ b/src/main/java/shit/zen/gui/legacy/BooleanComponent.java @@ -15,54 +15,54 @@ extends SettingComponent { private float toggleAnim = 0.0f; private final float animSpeed = 0.2f; - public BooleanComponent(Setting setting, ModuleButton moduleButton, int n) { - super(setting, moduleButton, n); + public BooleanComponent(Setting setting, ModuleButton moduleButton, int yOffset) { + super(setting, moduleButton, yOffset); this.booleanSetting = (BooleanSetting)setting; this.toggleAnim = this.booleanSetting.getValue() != false ? 1.0f : 0.0f; } @Override - public void renderWithAlpha(PoseStack poseStack, int n, int n2, float f, float f2) { - float f3; - float f4 = f3 = this.booleanSetting.getValue() != false ? 1.0f : 0.0f; - this.toggleAnim = Math.abs(this.toggleAnim - f3) > 0.01f ? (this.toggleAnim += (f3 - this.toggleAnim) * 0.2f) : f3; - int n3 = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; - int n4 = 4; - int n5 = this.parentButton.panel.rowHeight - n4 * 2; - int n6 = this.parentButton.panel.x; - int n7 = this.parentButton.panel.width; - int n8 = 8; - String string = this.booleanSetting.getName(); - float f5 = (float)(n3 + n4) + ((float)n5 - FontStore.OPENSANS_16.getFontHeight()) / 2.0f; - int n9 = new Color(255, 255, 255, (int)(255.0f * f2)).getRGB(); - FontStore.OPENSANS_16.drawStringWithShadow(poseStack, string, n6 + n8, f5, n9); - int n10 = 18; - int n11 = 8; - int n12 = n6 + n7 - n8 - n10; - int n13 = n3 + n4 + (n5 - n11) / 2 + 2; - Color color = this.booleanSetting.getValue() != false ? new Color(138, 180, 248, (int)(200.0f * f2)) : new Color(100, 100, 100, (int)(180.0f * f2)); - RenderUtil.drawFilledRect(poseStack, n12, n13, n10, n11, color.getRGB()); - float f6 = 7.0f; - float f7 = n11 + 4; - float f8 = (float)(n12 + 1) + ((float)n10 - f6 - 2.0f) * this.toggleAnim; - float f9 = n13 - 2; - RenderUtil.drawFilledRect(poseStack, f8, f9, f6, f7, new Color(160, 195, 255, (int)(255.0f * f2)).getRGB()); + public void renderWithAlpha(PoseStack poseStack, int mouseX, int mouseY, float partialTicks, float alpha) { + float target; + float dup = target = this.booleanSetting.getValue() != false ? 1.0f : 0.0f; + this.toggleAnim = Math.abs(this.toggleAnim - target) > 0.01f ? (this.toggleAnim += (target - this.toggleAnim) * 0.2f) : target; + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; + int verticalPadding = 4; + int contentHeight = this.parentButton.panel.rowHeight - verticalPadding * 2; + int panelX = this.parentButton.panel.x; + int panelWidth = this.parentButton.panel.width; + int textPadding = 8; + String name = this.booleanSetting.getName(); + float textY = (float)(rowY + verticalPadding) + ((float)contentHeight - FontStore.OPENSANS_16.getFontHeight()) / 2.0f; + int textColor = new Color(255, 255, 255, (int)(255.0f * alpha)).getRGB(); + FontStore.OPENSANS_16.drawStringWithShadow(poseStack, name, panelX + textPadding, textY, textColor); + int toggleWidth = 18; + int toggleHeight = 8; + int toggleX = panelX + panelWidth - textPadding - toggleWidth; + int toggleY = rowY + verticalPadding + (contentHeight - toggleHeight) / 2 + 2; + Color trackColor = this.booleanSetting.getValue() != false ? new Color(138, 180, 248, (int)(200.0f * alpha)) : new Color(100, 100, 100, (int)(180.0f * alpha)); + RenderUtil.drawFilledRect(poseStack, toggleX, toggleY, toggleWidth, toggleHeight, trackColor.getRGB()); + float knobWidth = 7.0f; + float knobHeight = toggleHeight + 4; + float knobX = (float)(toggleX + 1) + ((float)toggleWidth - knobWidth - 2.0f) * this.toggleAnim; + float knobY = toggleY - 2; + RenderUtil.drawFilledRect(poseStack, knobX, knobY, knobWidth, knobHeight, new Color(160, 195, 255, (int)(255.0f * alpha)).getRGB()); } @Override - public void mouseClicked(double d, double d2, int n) { - if (this.isHovered(d, d2) && n == 0) { - boolean bl = this.booleanSetting.getValue(); - this.booleanSetting.setValue(!bl); - if (bl != this.booleanSetting.getValue()) { + public void mouseClicked(double mouseX, double mouseY, int button) { + if (this.isHovered(mouseX, mouseY) && button == 0) { + boolean previous = this.booleanSetting.getValue(); + this.booleanSetting.setValue(!previous); + if (previous != this.booleanSetting.getValue()) { this.parentButton.panel.recalcLayout(); } } - super.mouseClicked(d, d2, n); + super.mouseClicked(mouseX, mouseY, button); } @Override - public void mouseReleased(double d, double d2, int n) { - super.mouseReleased(d, d2, n); + public void mouseReleased(double mouseX, double mouseY, int button) { + super.mouseReleased(mouseX, mouseY, button); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/legacy/CategoryPanel.java b/src/main/java/shit/zen/gui/legacy/CategoryPanel.java index 753dccf..41d462f 100644 --- a/src/main/java/shit/zen/gui/legacy/CategoryPanel.java +++ b/src/main/java/shit/zen/gui/legacy/CategoryPanel.java @@ -28,19 +28,19 @@ public class CategoryPanel { private long lastTime = System.currentTimeMillis(); private boolean needsLayout = false; - public CategoryPanel(int n, int n2, int n3, int n4, Category category) { - this.x = n; - this.y = n2; - this.width = n3; - this.rowHeight = n4; + public CategoryPanel(int x, int y, int width, int rowHeight, Category category) { + this.x = x; + this.y = y; + this.width = width; + this.rowHeight = rowHeight; this.category = category; this.dragging = false; this.expanded = false; this.moduleButtons = new ArrayList<>(); - int n5 = n4; + int buttonY = rowHeight; for (Module module : ZenClient.getInstance().getModuleManager().getModulesByCategory(category)) { - this.moduleButtons.add(new ModuleButton(module, this, n5)); - n5 += n4; + this.moduleButtons.add(new ModuleButton(module, this, buttonY)); + buttonY += rowHeight; } this.initOffsets(); } @@ -58,33 +58,33 @@ public class CategoryPanel { if (!this.needsLayout) { return; } - boolean bl = false; - long l = System.currentTimeMillis(); - float f = (float)(l - this.lastTime) / 1000.0f; - this.lastTime = l; + boolean stillAnimating = false; + long now = System.currentTimeMillis(); + float deltaSeconds = (float)(now - this.lastTime) / 1000.0f; + this.lastTime = now; for (ModuleButton moduleButton : this.moduleButtons) { if (!moduleButton.isAnimating()) continue; - bl = true; + stillAnimating = true; } for (int i = 0; i < this.moduleButtons.size(); ++i) { - float f2 = this.targetOffsets[i] - this.currentOffsets[i]; - if (Math.abs(f2) > 0.5f) { - int n = i; - this.currentOffsets[n] = this.currentOffsets[n] + f2 * 0.2f * (f * 60.0f); - bl = true; + float diff = this.targetOffsets[i] - this.currentOffsets[i]; + if (Math.abs(diff) > 0.5f) { + int idx = i; + this.currentOffsets[idx] = this.currentOffsets[idx] + diff * 0.2f * (deltaSeconds * 60.0f); + stillAnimating = true; this.moduleButtons.get(i).yOffset = (int)this.currentOffsets[i]; continue; } this.currentOffsets[i] = this.targetOffsets[i]; this.moduleButtons.get(i).yOffset = (int)this.targetOffsets[i]; } - this.needsLayout = bl; + this.needsLayout = stillAnimating; } - public void render(GuiGraphics guiGraphics, int n, int n2, float f) { + public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { this.tick(); RenderUtil.drawFilledRect(guiGraphics.pose(), this.x, this.y, this.width, this.rowHeight, new Color(16, 16, 20, 245).getRGB()); - String string = String.valueOf(switch (this.category) { + String iconChar = String.valueOf(switch (this.category) { case COMBAT -> 'a'; case MOVEMENT -> 'b'; case PLAYER -> 'c'; @@ -92,65 +92,65 @@ public class CategoryPanel { case EXPLOIT -> 'e'; default -> '?'; }); - float f2 = (float)this.y + ((float)this.rowHeight / 2.0f - FontStore.ICON_30.getFontHeight() / 2.0f) + 3.0f; - FontStore.ICON_30.drawStringWithShadow(guiGraphics.pose(), string, this.x + 4, f2, -1); - float f3 = (float)this.y + ((float)this.rowHeight / 2.0f - FontStore.OPENSANS_18.getFontHeight() / 2.0f) - 0.5f; - FontStore.OPENSANS_18.drawStringWithShadow(guiGraphics.pose(), this.category.displayName, this.x + this.rowHeight + 4, f3, -1); + float iconY = (float)this.y + ((float)this.rowHeight / 2.0f - FontStore.ICON_30.getFontHeight() / 2.0f) + 3.0f; + FontStore.ICON_30.drawStringWithShadow(guiGraphics.pose(), iconChar, this.x + 4, iconY, -1); + float labelY = (float)this.y + ((float)this.rowHeight / 2.0f - FontStore.OPENSANS_18.getFontHeight() / 2.0f) - 0.5f; + FontStore.OPENSANS_18.drawStringWithShadow(guiGraphics.pose(), this.category.displayName, this.x + this.rowHeight + 4, labelY, -1); for (ModuleButton moduleButton : this.moduleButtons) { - moduleButton.render(guiGraphics.pose(), n, n2, f); + moduleButton.render(guiGraphics.pose(), mouseX, mouseY, partialTicks); } } - public void mouseClicked(double d, double d2, int n) { - if (this.isHovered(d, d2)) { - if (n == 0) { + public void mouseClicked(double mouseX, double mouseY, int button) { + if (this.isHovered(mouseX, mouseY)) { + if (button == 0) { this.dragging = true; - this.dragOffsetX = (int)(d - (double)this.x); - this.dragOffsetY = (int)(d2 - (double)this.y); - } else if (n == 1) { + this.dragOffsetX = (int)(mouseX - (double)this.x); + this.dragOffsetY = (int)(mouseY - (double)this.y); + } else if (button == 1) { this.expanded = !this.expanded; this.recalcLayout(); } } for (ModuleButton moduleButton : this.moduleButtons) { - moduleButton.mouseClicked(d, d2, n); + moduleButton.mouseClicked(mouseX, mouseY, button); } } - public void mouseReleased(double d, double d2, int n) { + public void mouseReleased(double mouseX, double mouseY, int button) { for (ModuleButton moduleButton : this.moduleButtons) { - moduleButton.mouseReleased(d, d2, n); + moduleButton.mouseReleased(mouseX, mouseY, button); } - if (n == 0 && this.dragging) { + if (button == 0 && this.dragging) { this.dragging = false; } } - public void mouseScrolled(double d, double d2, double d3) { + public void mouseScrolled(double mouseX, double mouseY, double scrollDelta) { for (ModuleButton moduleButton : this.moduleButtons) { - moduleButton.mouseScrolled(d, d2, d3); + moduleButton.mouseScrolled(mouseX, mouseY, scrollDelta); } } - public boolean isHovered(double d, double d2) { - return d > (double)this.x && d < (double)(this.x + this.width) && d2 > (double)this.y && d2 < (double)(this.y + this.rowHeight); + public boolean isHovered(double mouseX, double mouseY) { + return mouseX > (double)this.x && mouseX < (double)(this.x + this.width) && mouseY > (double)this.y && mouseY < (double)(this.y + this.rowHeight); } - public void mouseDragged(double d, double d2) { + public void mouseDragged(double mouseX, double mouseY) { if (this.dragging) { - this.x = (int)(d - (double)this.dragOffsetX); - this.y = (int)(d2 - (double)this.dragOffsetY); + this.x = (int)(mouseX - (double)this.dragOffsetX); + this.y = (int)(mouseY - (double)this.dragOffsetY); } } public void recalcLayout() { - int n = this.rowHeight; + int currentY = this.rowHeight; for (int i = 0; i < this.moduleButtons.size(); ++i) { ModuleButton moduleButton = this.moduleButtons.get(i); - this.targetOffsets[i] = n; - n += moduleButton.getTotalHeight(); + this.targetOffsets[i] = currentY; + currentY += moduleButton.getTotalHeight(); } this.needsLayout = true; this.lastTime = System.currentTimeMillis(); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/legacy/ModeComponent.java b/src/main/java/shit/zen/gui/legacy/ModeComponent.java index 1fd23ae..ce8f9a7 100644 --- a/src/main/java/shit/zen/gui/legacy/ModeComponent.java +++ b/src/main/java/shit/zen/gui/legacy/ModeComponent.java @@ -16,124 +16,124 @@ extends SettingComponent { @Getter private boolean dropdownOpen = false; - public ModeComponent(Setting setting, ModuleButton moduleButton, int n) { - super(setting, moduleButton, n); + public ModeComponent(Setting setting, ModuleButton moduleButton, int yOffset) { + super(setting, moduleButton, yOffset); this.modeSetting = (ModeSetting)setting; } @Override - public void renderWithAlpha(PoseStack poseStack, int n, int n2, float f, float f2) { - int n3 = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset + 3; - int n4 = this.parentButton.panel.x; - int n5 = this.parentButton.panel.width; - int n6 = this.parentButton.panel.rowHeight; - int n7 = 4; - int n8 = n6 - n7 * 2; - int n9 = 8; - int n10 = 4; - int n11 = n4 + n9 + n10; - int n12 = n5 - (n9 + n10) * 2; - int n13 = new Color(255, 255, 255, (int)(255.0f * f2)).getRGB(); - boolean bl = n >= n11 && n <= n11 + n12 && n2 >= n3 + n7 && n2 <= n3 + n7 + n8; - Color color = bl && !this.dropdownOpen ? new Color(45, 45, 45, (int)(180.0f * f2)) : new Color(25, 25, 25, (int)(150.0f * f2)); - RenderUtil.drawFilledRect(poseStack, n11, n3 + n7, n12, n8, color.getRGB()); - Color color2 = new Color(100, 100, 100, (int)(180.0f * f2)); - RenderUtil.drawFilledRect(poseStack, n4 + n9 + 2, n3 + n7, n10 - 2, n8, color2.getRGB()); - RenderUtil.drawFilledRect(poseStack, n4 + n5 - n9 - n10, n3 + n7, n10 - 2, n8, color2.getRGB()); - String string = this.modeSetting.getName(); - float f3 = (float)(n3 + n7) + ((float)n8 - FontStore.OPENSANS_16.getFontHeight()) / 2.0f - 1.5f; - FontStore.OPENSANS_16.drawStringWithShadow(poseStack, string, n11 + n10, f3, n13); - String string2 = this.modeSetting.getValue(); - float f4 = (float)(n11 + n12) - FontStore.OPENSANS_16.getStringWidth(string2) - (float)n10; - FontStore.OPENSANS_16.drawStringWithShadow(poseStack, string2, f4, f3, new Color(138, 180, 248).getRGB()); + public void renderWithAlpha(PoseStack poseStack, int mouseX, int mouseY, float partialTicks, float alpha) { + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset + 3; + int panelX = this.parentButton.panel.x; + int panelWidth = this.parentButton.panel.width; + int rowHeight = this.parentButton.panel.rowHeight; + int verticalPadding = 4; + int contentHeight = rowHeight - verticalPadding * 2; + int outerPadding = 8; + int innerPadding = 4; + int boxX = panelX + outerPadding + innerPadding; + int boxWidth = panelWidth - (outerPadding + innerPadding) * 2; + int textColor = new Color(255, 255, 255, (int)(255.0f * alpha)).getRGB(); + boolean hovered = mouseX >= boxX && mouseX <= boxX + boxWidth && mouseY >= rowY + verticalPadding && mouseY <= rowY + verticalPadding + contentHeight; + Color boxColor = hovered && !this.dropdownOpen ? new Color(45, 45, 45, (int)(180.0f * alpha)) : new Color(25, 25, 25, (int)(150.0f * alpha)); + RenderUtil.drawFilledRect(poseStack, boxX, rowY + verticalPadding, boxWidth, contentHeight, boxColor.getRGB()); + Color edgeColor = new Color(100, 100, 100, (int)(180.0f * alpha)); + RenderUtil.drawFilledRect(poseStack, panelX + outerPadding + 2, rowY + verticalPadding, innerPadding - 2, contentHeight, edgeColor.getRGB()); + RenderUtil.drawFilledRect(poseStack, panelX + panelWidth - outerPadding - innerPadding, rowY + verticalPadding, innerPadding - 2, contentHeight, edgeColor.getRGB()); + String name = this.modeSetting.getName(); + float textY = (float)(rowY + verticalPadding) + ((float)contentHeight - FontStore.OPENSANS_16.getFontHeight()) / 2.0f - 1.5f; + FontStore.OPENSANS_16.drawStringWithShadow(poseStack, name, boxX + innerPadding, textY, textColor); + String selectedValue = this.modeSetting.getValue(); + float valueX = (float)(boxX + boxWidth) - FontStore.OPENSANS_16.getStringWidth(selectedValue) - (float)innerPadding; + FontStore.OPENSANS_16.drawStringWithShadow(poseStack, selectedValue, valueX, textY, new Color(138, 180, 248).getRGB()); if (this.dropdownOpen) { - int n14 = n3 + n7 + n8; - int n15 = this.getDropdownHeight(); - RenderUtil.drawFilledRect(poseStack, n11, n14, n12, n15, new Color(33, 33, 33, 150).getRGB()); - String[] stringArray = this.getModes(); - for (int i = 0; i < stringArray.length; ++i) { - boolean bl2; - String string3 = stringArray[i]; - float f5 = n14 + i * n8; - boolean bl3 = bl2 = n >= n11 && n <= n11 + n12 && (float)n2 >= f5 && (float)n2 < f5 + (float)n8; - if (bl2) { - RenderUtil.drawFilledRect(poseStack, n11, f5, n12, n8, new Color(0, 0, 0, 100).getRGB()); + int dropdownY = rowY + verticalPadding + contentHeight; + int dropdownHeight = this.getDropdownHeight(); + RenderUtil.drawFilledRect(poseStack, boxX, dropdownY, boxWidth, dropdownHeight, new Color(33, 33, 33, 150).getRGB()); + String[] modes = this.getModes(); + for (int i = 0; i < modes.length; ++i) { + boolean itemHovered; + String mode = modes[i]; + float itemY = dropdownY + i * contentHeight; + boolean dup = itemHovered = mouseX >= boxX && mouseX <= boxX + boxWidth && (float)mouseY >= itemY && (float)mouseY < itemY + (float)contentHeight; + if (itemHovered) { + RenderUtil.drawFilledRect(poseStack, boxX, itemY, boxWidth, contentHeight, new Color(0, 0, 0, 100).getRGB()); } - float f6 = FontStore.OPENSANS_16.getStringWidth(string3); - float f7 = (float)n11 + ((float)n12 - f6) / 2.0f; - float f8 = f5 + ((float)n8 - FontStore.OPENSANS_16.getFontHeight()) / 2.0f; - boolean bl4 = string3.equals(this.modeSetting.getValue()); - FontStore.OPENSANS_16.drawStringWithShadow(poseStack, string3, f7, f8, bl4 ? new Color(138, 180, 248).getRGB() : n13); + float modeTextWidth = FontStore.OPENSANS_16.getStringWidth(mode); + float modeTextX = (float)boxX + ((float)boxWidth - modeTextWidth) / 2.0f; + float modeTextY = itemY + ((float)contentHeight - FontStore.OPENSANS_16.getFontHeight()) / 2.0f; + boolean isSelected = mode.equals(this.modeSetting.getValue()); + FontStore.OPENSANS_16.drawStringWithShadow(poseStack, mode, modeTextX, modeTextY, isSelected ? new Color(138, 180, 248).getRGB() : textColor); } } } @Override - public void mouseClicked(double d, double d2, int n) { - int n2; - int n3 = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset + 3; - int n4 = this.parentButton.panel.rowHeight; - int n5 = 4; - int n6 = n4 - n5 * 2; - int n7 = this.parentButton.panel.x; - int n8 = this.parentButton.panel.width; - int n9 = 8; - int n10 = 4; - int n11 = n7 + n9 + n10; - int n12 = n8 - (n9 + n10) * 2; - String[] stringArray = this.modeSetting.getModes(); + public void mouseClicked(double mouseX, double mouseY, int button) { + int overHeader; + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset + 3; + int rowHeight = this.parentButton.panel.rowHeight; + int verticalPadding = 4; + int contentHeight = rowHeight - verticalPadding * 2; + int panelX = this.parentButton.panel.x; + int panelWidth = this.parentButton.panel.width; + int outerPadding = 8; + int innerPadding = 4; + int boxX = panelX + outerPadding + innerPadding; + int boxWidth = panelWidth - (outerPadding + innerPadding) * 2; + String[] modes = this.modeSetting.getModes(); if (this.dropdownOpen) { - n2 = n3 + n5 + n6; - int n13 = this.getDropdownHeight(); - if (d >= (double)n11 && d <= (double)(n11 + n12) && d2 >= (double)n2 && d2 < (double)(n2 + n13)) { - int n14 = (int)((d2 - (double)n2) / (double)n6); - if (n14 >= 0 && n14 < stringArray.length) { - this.modeSetting.setValue(stringArray[n14]); + overHeader = rowY + verticalPadding + contentHeight; + int dropdownHeight = this.getDropdownHeight(); + if (mouseX >= (double)boxX && mouseX <= (double)(boxX + boxWidth) && mouseY >= (double)overHeader && mouseY < (double)(overHeader + dropdownHeight)) { + int itemIndex = (int)((mouseY - (double)overHeader) / (double)contentHeight); + if (itemIndex >= 0 && itemIndex < modes.length) { + this.modeSetting.setValue(modes[itemIndex]); this.dropdownOpen = false; this.parentButton.panel.recalcLayout(); } return; } } - int n15 = n2 = d >= (double)n11 && d <= (double)(n11 + n12) && d2 >= (double)(n3 + n5) && d2 <= (double)(n3 + n5 + n6) ? 1 : 0; - if (n2 != 0 && (n == 0 || n == 1)) { + int headerHit = overHeader = mouseX >= (double)boxX && mouseX <= (double)(boxX + boxWidth) && mouseY >= (double)(rowY + verticalPadding) && mouseY <= (double)(rowY + verticalPadding + contentHeight) ? 1 : 0; + if (overHeader != 0 && (button == 0 || button == 1)) { this.dropdownOpen = !this.dropdownOpen; this.parentButton.panel.recalcLayout(); } } @Override - public boolean isHovered(double d, double d2) { - boolean bl; - int n = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; - int n2 = this.parentButton.panel.x; - int n3 = this.parentButton.panel.width; - int n4 = this.parentButton.panel.rowHeight; - boolean bl2 = bl = d >= (double)n2 && d <= (double)(n2 + n3) && d2 >= (double)n && d2 <= (double)(n + n4); - if (bl) { + public boolean isHovered(double mouseX, double mouseY) { + boolean overHeader; + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; + int panelX = this.parentButton.panel.x; + int panelWidth = this.parentButton.panel.width; + int rowHeight = this.parentButton.panel.rowHeight; + boolean dup = overHeader = mouseX >= (double)panelX && mouseX <= (double)(panelX + panelWidth) && mouseY >= (double)rowY && mouseY <= (double)(rowY + rowHeight); + if (overHeader) { return true; } if (this.dropdownOpen) { - int n5 = n + n4; - int n6 = this.getDropdownHeight(); - return d >= (double)n2 && d <= (double)(n2 + n3) && d2 >= (double)n5 && d2 <= (double)(n5 + n6); + int dropdownY = rowY + rowHeight; + int dropdownHeight = this.getDropdownHeight(); + return mouseX >= (double)panelX && mouseX <= (double)(panelX + panelWidth) && mouseY >= (double)dropdownY && mouseY <= (double)(dropdownY + dropdownHeight); } return false; } @Override - public void mouseReleased(double d, double d2, int n) { - super.mouseReleased(d, d2, n); + public void mouseReleased(double mouseX, double mouseY, int button) { + super.mouseReleased(mouseX, mouseY, button); } public int getDropdownHeight() { - int n = 4; - int n2 = this.parentButton.panel.rowHeight - n * 2; - return n2 * this.modeSetting.getModes().length; + int verticalPadding = 4; + int contentHeight = this.parentButton.panel.rowHeight - verticalPadding * 2; + return contentHeight * this.modeSetting.getModes().length; } public String[] getModes() { return this.modeSetting.getModes(); } - } \ No newline at end of file + } diff --git a/src/main/java/shit/zen/gui/legacy/ModuleButton.java b/src/main/java/shit/zen/gui/legacy/ModuleButton.java index 4bd1023..3a0a3fc 100644 --- a/src/main/java/shit/zen/gui/legacy/ModuleButton.java +++ b/src/main/java/shit/zen/gui/legacy/ModuleButton.java @@ -35,10 +35,10 @@ public class ModuleButton { private final float hoverSpeed = 4.0f; private long lastTime = System.currentTimeMillis(); - public ModuleButton(Module module, CategoryPanel categoryPanel, int n) { + public ModuleButton(Module module, CategoryPanel categoryPanel, int yOffset) { this.module = module; this.panel = categoryPanel; - this.yOffset = n; + this.yOffset = yOffset; this.expanded = false; this.settingComponents = new ArrayList<>(); for (Setting setting : module.getSettings()) { @@ -64,147 +64,147 @@ public class ModuleButton { if (!this.expanded) { return this.panel.rowHeight; } - int n = this.panel.rowHeight; - List list = this.settingComponents.stream().filter(settingComponent -> settingComponent.setting.getVisibility().displayable()).collect(Collectors.toList()); - for (SettingComponent settingComponent2 : list) { - n += this.panel.rowHeight; - if (settingComponent2 instanceof ModeComponent mode && mode.isDropdownOpen()) { - n += mode.getDropdownHeight(); + int total = this.panel.rowHeight; + List visibleComponents = this.settingComponents.stream().filter(settingComponent -> settingComponent.setting.getVisibility().displayable()).collect(Collectors.toList()); + for (SettingComponent settingComponent : visibleComponents) { + total += this.panel.rowHeight; + if (settingComponent instanceof ModeComponent mode && mode.isDropdownOpen()) { + total += mode.getDropdownHeight(); } - if (settingComponent2 instanceof MultiSelectComponent multi && multi.isDropdownOpen()) { - n += multi.getDropdownHeight(); + if (settingComponent instanceof MultiSelectComponent multi && multi.isDropdownOpen()) { + total += multi.getDropdownHeight(); } } - return n; + return total; } public int getExpandedHeight() { - int n = 0; - List list = this.settingComponents.stream().filter(settingComponent -> settingComponent.setting.getVisibility().displayable()).collect(Collectors.toList()); - for (SettingComponent settingComponent2 : list) { - n += this.panel.rowHeight; - if (settingComponent2 instanceof ModeComponent mode && mode.isDropdownOpen()) { - n += mode.getDropdownHeight(); + int total = 0; + List visibleComponents = this.settingComponents.stream().filter(settingComponent -> settingComponent.setting.getVisibility().displayable()).collect(Collectors.toList()); + for (SettingComponent settingComponent : visibleComponents) { + total += this.panel.rowHeight; + if (settingComponent instanceof ModeComponent mode && mode.isDropdownOpen()) { + total += mode.getDropdownHeight(); } - if (settingComponent2 instanceof MultiSelectComponent multi && multi.isDropdownOpen()) { - n += multi.getDropdownHeight(); + if (settingComponent instanceof MultiSelectComponent multi && multi.isDropdownOpen()) { + total += multi.getDropdownHeight(); } } - return n; + return total; } - public void render(PoseStack poseStack, int n, int n2, float f) { - float f2; + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) { + float expandedHeight; this.expandAnim.tick(); - long l = System.currentTimeMillis(); - float f3 = (float)(l - this.lastTime) / 1000.0f; - this.lastTime = l; - if (this.isHovered(n, n2)) { + long now = System.currentTimeMillis(); + float deltaSeconds = (float)(now - this.lastTime) / 1000.0f; + this.lastTime = now; + if (this.isHovered(mouseX, mouseY)) { if (this.hoverProgress < 1.0f) { - this.hoverProgress += f3 * 4.0f; + this.hoverProgress += deltaSeconds * 4.0f; } if (this.hoverProgress > 1.0f) { this.hoverProgress = 1.0f; } } else { if (this.hoverProgress > 0.0f) { - this.hoverProgress -= f3 * 4.0f; + this.hoverProgress -= deltaSeconds * 4.0f; } if (this.hoverProgress < 0.0f) { this.hoverProgress = 0.0f; } } - int n3 = (int)(160.0f + 40.0f * this.hoverProgress); - int n4 = this.panel.y + this.yOffset - (this.yOffset == 0 ? 0 : 1); - int n5 = this.panel.rowHeight + (this.yOffset == 0 ? 0 : 1); - RenderUtil.drawBlurredRect(poseStack, this.panel.x, n4, this.panel.width, n5, 4.0f, 6.0f, 0.9f, 0); - RenderUtil.drawFilledRect(poseStack, this.panel.x, n4, this.panel.width, n5, new Color(21, 21, 21, n3).getRGB()); - String string = this.module.getName(); - float f4 = FontStore.OPENSANS_16.getStringWidth(string); - float f5 = (float)this.panel.x + (float)this.panel.width / 2.0f - f4 / 2.0f; - float f6 = (float)(this.panel.y + this.yOffset) + (float)this.panel.rowHeight / 2.0f - FontStore.OPENSANS_16.getFontHeight() / 2.0f; - FontStore.OPENSANS_16.drawStringWithShadow(poseStack, string, f5, f6, this.module.isEnabled() ? ColorUtil.fromARGB(138, 180, 248, 255) : -1); + int bgAlpha = (int)(160.0f + 40.0f * this.hoverProgress); + int rowY = this.panel.y + this.yOffset - (this.yOffset == 0 ? 0 : 1); + int rowHeight = this.panel.rowHeight + (this.yOffset == 0 ? 0 : 1); + RenderUtil.drawBlurredRect(poseStack, this.panel.x, rowY, this.panel.width, rowHeight, 4.0f, 6.0f, 0.9f, 0); + RenderUtil.drawFilledRect(poseStack, this.panel.x, rowY, this.panel.width, rowHeight, new Color(21, 21, 21, bgAlpha).getRGB()); + String name = this.module.getName(); + float nameWidth = FontStore.OPENSANS_16.getStringWidth(name); + float nameX = (float)this.panel.x + (float)this.panel.width / 2.0f - nameWidth / 2.0f; + float nameY = (float)(this.panel.y + this.yOffset) + (float)this.panel.rowHeight / 2.0f - FontStore.OPENSANS_16.getFontHeight() / 2.0f; + FontStore.OPENSANS_16.drawStringWithShadow(poseStack, name, nameX, nameY, this.module.isEnabled() ? ColorUtil.fromARGB(138, 180, 248, 255) : -1); if (!this.module.getSettings().isEmpty()) { poseStack.pushPose(); - f2 = this.panel.x + this.panel.width - 15; - float f7 = (float)(this.panel.y + this.yOffset) + (float)this.panel.rowHeight / 2.0f; - float f8 = 180.0f * this.expandAnim.getValueF(); - poseStack.translate(f2, f7, 0.0f); - poseStack.mulPose(Axis.ZP.rotationDegrees(f8)); - poseStack.translate(-f2, -f7, 0.0f); - FontStore.MATERIAL_20.drawStringWithShadow(poseStack, "", f2 - FontStore.MATERIAL_20.getStringWidth("") / 2.0f, f7 - FontStore.MATERIAL_20.getFontHeight() / 2.0f, -1); + expandedHeight = this.panel.x + this.panel.width - 15; + float arrowY = (float)(this.panel.y + this.yOffset) + (float)this.panel.rowHeight / 2.0f; + float arrowAngle = 180.0f * this.expandAnim.getValueF(); + poseStack.translate(expandedHeight, arrowY, 0.0f); + poseStack.mulPose(Axis.ZP.rotationDegrees(arrowAngle)); + poseStack.translate(-expandedHeight, -arrowY, 0.0f); + FontStore.MATERIAL_20.drawStringWithShadow(poseStack, "", expandedHeight - FontStore.MATERIAL_20.getStringWidth("") / 2.0f, arrowY - FontStore.MATERIAL_20.getFontHeight() / 2.0f, -1); poseStack.popPose(); } - if ((f2 = (float)this.getExpandedHeight() * this.expandAnim.getValueF()) > 0.0f) { - int n6 = this.panel.y + this.yOffset + this.panel.rowHeight - 1; - RenderUtil.drawBlurredRect(poseStack, this.panel.x, n6, this.panel.width, (int)f2 + 1, 4.0f, 6.0f, 0.9f, 0); - RenderUtil.pushScissor(this.panel.x, n6, this.panel.width, (int)f2 + 1); - RenderUtil.drawFilledRect(poseStack, this.panel.x, n6, this.panel.width, (int)f2 + 1, new Color(11, 11, 11, 150).getRGB()); - List list = this.settingComponents.stream().filter(settingComponent -> settingComponent.setting.getVisibility().displayable()).collect(Collectors.toList()); - int n7 = 0; - for (SettingComponent settingComponent2 : list) { - SettingComponent settingComponent3; - settingComponent2.yOffset = n7; - settingComponent2.renderWithAlpha(poseStack, n, n2, f, 1.0f); - n7 += this.panel.rowHeight; - if (settingComponent2 instanceof ModeComponent && ((ModeComponent)(settingComponent3 = settingComponent2)).isDropdownOpen()) { - n7 += ((ModeComponent)settingComponent3).getDropdownHeight(); + if ((expandedHeight = (float)this.getExpandedHeight() * this.expandAnim.getValueF()) > 0.0f) { + int contentY = this.panel.y + this.yOffset + this.panel.rowHeight - 1; + RenderUtil.drawBlurredRect(poseStack, this.panel.x, contentY, this.panel.width, (int)expandedHeight + 1, 4.0f, 6.0f, 0.9f, 0); + RenderUtil.pushScissor(this.panel.x, contentY, this.panel.width, (int)expandedHeight + 1); + RenderUtil.drawFilledRect(poseStack, this.panel.x, contentY, this.panel.width, (int)expandedHeight + 1, new Color(11, 11, 11, 150).getRGB()); + List visibleComponents = this.settingComponents.stream().filter(settingComponent -> settingComponent.setting.getVisibility().displayable()).collect(Collectors.toList()); + int componentOffsetY = 0; + for (SettingComponent settingComponent : visibleComponents) { + SettingComponent ref; + settingComponent.yOffset = componentOffsetY; + settingComponent.renderWithAlpha(poseStack, mouseX, mouseY, partialTicks, 1.0f); + componentOffsetY += this.panel.rowHeight; + if (settingComponent instanceof ModeComponent && ((ModeComponent)(ref = settingComponent)).isDropdownOpen()) { + componentOffsetY += ((ModeComponent)ref).getDropdownHeight(); } - if (!(settingComponent2 instanceof MultiSelectComponent) || !((MultiSelectComponent)(settingComponent3 = settingComponent2)).isDropdownOpen()) continue; - n7 += ((MultiSelectComponent)settingComponent3).getDropdownHeight(); + if (!(settingComponent instanceof MultiSelectComponent) || !((MultiSelectComponent)(ref = settingComponent)).isDropdownOpen()) continue; + componentOffsetY += ((MultiSelectComponent)ref).getDropdownHeight(); } RenderUtil.popScissor(); } } - public void mouseClicked(double d, double d2, int n) { - if (this.isHovered(d, d2)) { - if (n == 0) { + public void mouseClicked(double mouseX, double mouseY, int button) { + if (this.isHovered(mouseX, mouseY)) { + if (button == 0) { this.module.setEnabled(!this.module.isEnabled()); - } else if (n == 1 && !this.module.getSettings().isEmpty()) { + } else if (button == 1 && !this.module.getSettings().isEmpty()) { this.expanded = !this.expanded; this.expandAnim.animate(this.expanded ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_QUAD); this.panel.recalcLayout(); } } if (this.expanded) { - List list = this.settingComponents.stream().filter(settingComponent -> settingComponent.setting.getVisibility().displayable()).collect(Collectors.toList()); - int n2 = 0; - for (SettingComponent settingComponent2 : list) { - SettingComponent settingComponent3; - settingComponent2.yOffset = n2; - if (settingComponent2.isHovered(d, d2)) { - settingComponent2.mouseClicked(d, d2, n); + List visibleComponents = this.settingComponents.stream().filter(settingComponent -> settingComponent.setting.getVisibility().displayable()).collect(Collectors.toList()); + int componentOffsetY = 0; + for (SettingComponent settingComponent : visibleComponents) { + SettingComponent ref; + settingComponent.yOffset = componentOffsetY; + if (settingComponent.isHovered(mouseX, mouseY)) { + settingComponent.mouseClicked(mouseX, mouseY, button); } - n2 += this.panel.rowHeight; - if (settingComponent2 instanceof ModeComponent && ((ModeComponent)(settingComponent3 = settingComponent2)).isDropdownOpen()) { - n2 += ((ModeComponent)settingComponent3).getDropdownHeight(); + componentOffsetY += this.panel.rowHeight; + if (settingComponent instanceof ModeComponent && ((ModeComponent)(ref = settingComponent)).isDropdownOpen()) { + componentOffsetY += ((ModeComponent)ref).getDropdownHeight(); } - if (!(settingComponent2 instanceof MultiSelectComponent) || !((MultiSelectComponent)(settingComponent3 = settingComponent2)).isDropdownOpen()) continue; - n2 += ((MultiSelectComponent)settingComponent3).getDropdownHeight(); + if (!(settingComponent instanceof MultiSelectComponent) || !((MultiSelectComponent)(ref = settingComponent)).isDropdownOpen()) continue; + componentOffsetY += ((MultiSelectComponent)ref).getDropdownHeight(); } } } - public void mouseReleased(double d, double d2, int n) { + public void mouseReleased(double mouseX, double mouseY, int button) { if (this.expanded) { for (SettingComponent settingComponent : this.settingComponents) { - settingComponent.mouseReleased(d, d2, n); + settingComponent.mouseReleased(mouseX, mouseY, button); } } } - public void mouseScrolled(double d, double d2, double d3) { + public void mouseScrolled(double mouseX, double mouseY, double scrollDelta) { } public void reset() { } - public boolean isHovered(double d, double d2) { - return d >= (double)this.panel.x && d <= (double)(this.panel.x + this.panel.width) && d2 >= (double)(this.panel.y + this.yOffset) && d2 <= (double)(this.panel.y + this.yOffset + this.panel.rowHeight); + public boolean isHovered(double mouseX, double mouseY) { + return mouseX >= (double)this.panel.x && mouseX <= (double)(this.panel.x + this.panel.width) && mouseY >= (double)(this.panel.y + this.yOffset) && mouseY <= (double)(this.panel.y + this.yOffset + this.panel.rowHeight); } public boolean isAnimating() { return !this.expandAnim.isDone(); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/legacy/MultiSelectComponent.java b/src/main/java/shit/zen/gui/legacy/MultiSelectComponent.java index 7bbf2c7..5e8cb97 100644 --- a/src/main/java/shit/zen/gui/legacy/MultiSelectComponent.java +++ b/src/main/java/shit/zen/gui/legacy/MultiSelectComponent.java @@ -17,88 +17,88 @@ extends SettingComponent { @Getter private boolean dropdownOpen; - public MultiSelectComponent(Setting setting, ModuleButton moduleButton, int n) { - super(setting, moduleButton, n); + public MultiSelectComponent(Setting setting, ModuleButton moduleButton, int yOffset) { + super(setting, moduleButton, yOffset); this.multiSelectSetting = (MultiSelectSetting)setting; } @Override - public void renderWithAlpha(PoseStack poseStack, int n, int n2, float f, float f2) { - int n3 = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; - int n4 = this.parentButton.panel.x; - int n5 = this.parentButton.panel.width; - int n6 = this.parentButton.panel.rowHeight; - int n7 = 4; - int n8 = n6 - n7 * 2; - int n9 = 8; - int n10 = 4; - int n11 = n4 + n9 + n10; - int n12 = n5 - (n9 + n10) * 2; - int n13 = new Color(255, 255, 255, (int)(255.0f * f2)).getRGB(); - int n14 = new Color(138, 180, 248, (int)(255.0f * f2)).getRGB(); - int n15 = n8; + public void renderWithAlpha(PoseStack poseStack, int mouseX, int mouseY, float partialTicks, float alpha) { + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; + int panelX = this.parentButton.panel.x; + int panelWidth = this.parentButton.panel.width; + int rowHeight = this.parentButton.panel.rowHeight; + int verticalPadding = 4; + int contentHeight = rowHeight - verticalPadding * 2; + int outerPadding = 8; + int innerPadding = 4; + int boxX = panelX + outerPadding + innerPadding; + int boxWidth = panelWidth - (outerPadding + innerPadding) * 2; + int textColor = new Color(255, 255, 255, (int)(255.0f * alpha)).getRGB(); + int selectedColor = new Color(138, 180, 248, (int)(255.0f * alpha)).getRGB(); + int boxHeight = contentHeight; if (this.dropdownOpen) { - n15 += this.getDropdownHeight(); + boxHeight += this.getDropdownHeight(); } - boolean bl = n >= n11 && n <= n11 + n12 && n2 >= n3 + n7 && n2 <= n3 + n7 + n8; - Color color = bl && !this.dropdownOpen ? new Color(40, 40, 40, (int)(180.0f * f2)) : new Color(15, 15, 15, (int)(220.0f * f2)); - RenderUtil.drawFilledRect(poseStack, n11, n3 + n7, n12, n15, color.getRGB()); - Color color2 = new Color(100, 100, 100, (int)(180.0f * f2)); - RenderUtil.drawFilledRect(poseStack, n4 + n9 + 2, n3 + n7, n10 - 2, n8, color2.getRGB()); - RenderUtil.drawFilledRect(poseStack, n4 + n5 - n9 - n10, n3 + n7, n10 - 2, n8, color2.getRGB()); - String string = this.multiSelectSetting.getName(); - float f3 = FontStore.OPENSANS_16.getStringWidth(string); - float f4 = (float)n11 + ((float)n12 - f3) / 2.0f; - float f5 = (float)(n3 + n7) + ((float)n8 - FontStore.OPENSANS_16.getFontHeight()) / 2.0f - 1.0f; - FontStore.OPENSANS_16.drawStringWithShadow(poseStack, string, f4, f5, n13); + boolean hovered = mouseX >= boxX && mouseX <= boxX + boxWidth && mouseY >= rowY + verticalPadding && mouseY <= rowY + verticalPadding + contentHeight; + Color boxColor = hovered && !this.dropdownOpen ? new Color(40, 40, 40, (int)(180.0f * alpha)) : new Color(15, 15, 15, (int)(220.0f * alpha)); + RenderUtil.drawFilledRect(poseStack, boxX, rowY + verticalPadding, boxWidth, boxHeight, boxColor.getRGB()); + Color edgeColor = new Color(100, 100, 100, (int)(180.0f * alpha)); + RenderUtil.drawFilledRect(poseStack, panelX + outerPadding + 2, rowY + verticalPadding, innerPadding - 2, contentHeight, edgeColor.getRGB()); + RenderUtil.drawFilledRect(poseStack, panelX + panelWidth - outerPadding - innerPadding, rowY + verticalPadding, innerPadding - 2, contentHeight, edgeColor.getRGB()); + String name = this.multiSelectSetting.getName(); + float nameWidth = FontStore.OPENSANS_16.getStringWidth(name); + float nameX = (float)boxX + ((float)boxWidth - nameWidth) / 2.0f; + float nameY = (float)(rowY + verticalPadding) + ((float)contentHeight - FontStore.OPENSANS_16.getFontHeight()) / 2.0f - 1.0f; + FontStore.OPENSANS_16.drawStringWithShadow(poseStack, name, nameX, nameY, textColor); if (this.dropdownOpen) { - int n16 = n3 + n7 + n8; - List list = this.multiSelectSetting.getOptions(); - for (int i = 0; i < list.size(); ++i) { - boolean bl2; - String string2 = list.get(i); - float f6 = n16 + i * n8; - boolean bl3 = bl2 = n >= n11 && n <= n11 + n12 && (float)n2 >= f6 && (float)n2 < f6 + (float)n8; - if (bl2) { - RenderUtil.drawFilledRect(poseStack, n11, f6, n12, n8, new Color(0, 0, 0, 100).getRGB()); + int dropdownY = rowY + verticalPadding + contentHeight; + List options = this.multiSelectSetting.getOptions(); + for (int i = 0; i < options.size(); ++i) { + boolean itemHovered; + String option = options.get(i); + float itemY = dropdownY + i * contentHeight; + boolean dup = itemHovered = mouseX >= boxX && mouseX <= boxX + boxWidth && (float)mouseY >= itemY && (float)mouseY < itemY + (float)contentHeight; + if (itemHovered) { + RenderUtil.drawFilledRect(poseStack, boxX, itemY, boxWidth, contentHeight, new Color(0, 0, 0, 100).getRGB()); } - float f7 = FontStore.OPENSANS_16.getStringWidth(string2); - float f8 = (float)n11 + ((float)n12 - f7) / 2.0f; - float f9 = f6 + ((float)n8 - FontStore.OPENSANS_16.getFontHeight()) / 2.0f; - boolean bl4 = this.multiSelectSetting.isSelected(string2); - FontStore.OPENSANS_16.drawStringWithShadow(poseStack, string2, f8, f9, bl4 ? n14 : n13); + float optionWidth = FontStore.OPENSANS_16.getStringWidth(option); + float optionX = (float)boxX + ((float)boxWidth - optionWidth) / 2.0f; + float optionY = itemY + ((float)contentHeight - FontStore.OPENSANS_16.getFontHeight()) / 2.0f; + boolean isSelected = this.multiSelectSetting.isSelected(option); + FontStore.OPENSANS_16.drawStringWithShadow(poseStack, option, optionX, optionY, isSelected ? selectedColor : textColor); } } } @Override - public void mouseClicked(double d, double d2, int n) { - if (this.isHeaderHovered(d, d2) && n == 1) { + public void mouseClicked(double mouseX, double mouseY, int button) { + if (this.isHeaderHovered(mouseX, mouseY) && button == 1) { this.dropdownOpen = !this.dropdownOpen; this.parentButton.panel.recalcLayout(); return; } if (this.dropdownOpen) { - int n2 = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; - int n3 = this.parentButton.panel.rowHeight; - int n4 = n2 + n3; - int n5 = 4; - int n6 = n3 - n5 * 2; - int n7 = this.parentButton.panel.x; - int n8 = this.parentButton.panel.width; - int n9 = 8; - int n10 = 4; - int n11 = n7 + n9 + n10; - int n12 = n8 - (n9 + n10) * 2; - if (d >= (double)n11 && d <= (double)(n11 + n12) && d2 >= (double)n4) { - int n13 = (int)((d2 - (double)n4) / (double)n6); - List list = this.multiSelectSetting.getOptions(); - if (n13 >= 0 && n13 < list.size()) { - String string = list.get(n13); - if (this.multiSelectSetting.isSelected(string)) { - this.multiSelectSetting.getValue().remove(string); + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; + int rowHeight = this.parentButton.panel.rowHeight; + int dropdownY = rowY + rowHeight; + int verticalPadding = 4; + int contentHeight = rowHeight - verticalPadding * 2; + int panelX = this.parentButton.panel.x; + int panelWidth = this.parentButton.panel.width; + int outerPadding = 8; + int innerPadding = 4; + int boxX = panelX + outerPadding + innerPadding; + int boxWidth = panelWidth - (outerPadding + innerPadding) * 2; + if (mouseX >= (double)boxX && mouseX <= (double)(boxX + boxWidth) && mouseY >= (double)dropdownY) { + int itemIndex = (int)((mouseY - (double)dropdownY) / (double)contentHeight); + List options = this.multiSelectSetting.getOptions(); + if (itemIndex >= 0 && itemIndex < options.size()) { + String option = options.get(itemIndex); + if (this.multiSelectSetting.isSelected(option)) { + this.multiSelectSetting.getValue().remove(option); } else { - this.multiSelectSetting.getValue().add(string); + this.multiSelectSetting.getValue().add(option); } } } @@ -109,34 +109,34 @@ extends SettingComponent { if (!this.dropdownOpen) { return 0; } - int n = 4; - int n2 = this.parentButton.panel.rowHeight - n * 2; - return n2 * this.multiSelectSetting.getOptions().size(); + int verticalPadding = 4; + int contentHeight = this.parentButton.panel.rowHeight - verticalPadding * 2; + return contentHeight * this.multiSelectSetting.getOptions().size(); } - private boolean isHeaderHovered(double d, double d2) { - int n = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; - return d >= (double)this.parentButton.panel.x && d <= (double)(this.parentButton.panel.x + this.parentButton.panel.width) && d2 >= (double)n && d2 <= (double)(n + this.parentButton.panel.rowHeight); + private boolean isHeaderHovered(double mouseX, double mouseY) { + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; + return mouseX >= (double)this.parentButton.panel.x && mouseX <= (double)(this.parentButton.panel.x + this.parentButton.panel.width) && mouseY >= (double)rowY && mouseY <= (double)(rowY + this.parentButton.panel.rowHeight); } @Override - public boolean isHovered(double d, double d2) { - if (this.isHeaderHovered(d, d2)) { + public boolean isHovered(double mouseX, double mouseY) { + if (this.isHeaderHovered(mouseX, mouseY)) { return true; } if (this.dropdownOpen) { - int n = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; - int n2 = n + this.parentButton.panel.rowHeight; - int n3 = this.getDropdownHeight(); - int n4 = this.parentButton.panel.x; - int n5 = this.parentButton.panel.width; - int n6 = 8; - int n7 = 4; - int n8 = n4 + n6 + n7; - int n9 = n5 - (n6 + n7) * 2; - return d >= (double)n8 && d <= (double)(n8 + n9) && d2 >= (double)n2 && d2 <= (double)(n2 + n3); + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; + int dropdownY = rowY + this.parentButton.panel.rowHeight; + int dropdownHeight = this.getDropdownHeight(); + int panelX = this.parentButton.panel.x; + int panelWidth = this.parentButton.panel.width; + int outerPadding = 8; + int innerPadding = 4; + int boxX = panelX + outerPadding + innerPadding; + int boxWidth = panelWidth - (outerPadding + innerPadding) * 2; + return mouseX >= (double)boxX && mouseX <= (double)(boxX + boxWidth) && mouseY >= (double)dropdownY && mouseY <= (double)(dropdownY + dropdownHeight); } return false; } - } \ No newline at end of file + } diff --git a/src/main/java/shit/zen/gui/legacy/NumberComponent.java b/src/main/java/shit/zen/gui/legacy/NumberComponent.java index e692c80..e913448 100644 --- a/src/main/java/shit/zen/gui/legacy/NumberComponent.java +++ b/src/main/java/shit/zen/gui/legacy/NumberComponent.java @@ -15,73 +15,73 @@ extends SettingComponent { private boolean dragging; private final NumberSetting numberSetting; - public NumberComponent(Setting setting, ModuleButton moduleButton, int n) { - super(setting, moduleButton, n); + public NumberComponent(Setting setting, ModuleButton moduleButton, int yOffset) { + super(setting, moduleButton, yOffset); this.numberSetting = (NumberSetting)setting; this.dragging = false; } @Override - public void renderWithAlpha(PoseStack poseStack, int n, int n2, float f, float f2) { - int n3 = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; - int n4 = this.parentButton.panel.x; - int n5 = this.parentButton.panel.width; - int n6 = this.parentButton.panel.rowHeight; - int n7 = new Color(255, 255, 255, (int)(255.0f * f2)).getRGB(); - int n8 = new Color(138, 180, 248, (int)(255.0f * f2)).getRGB(); - int n9 = 8; - int n10 = n4 + n9; - int n11 = (int)FontStore.OPENSANS_16.getStringWidth("00.00"); - int n12 = n5 - n9 * 2 - n11 + 20; + public void renderWithAlpha(PoseStack poseStack, int mouseX, int mouseY, float partialTicks, float alpha) { + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; + int panelX = this.parentButton.panel.x; + int panelWidth = this.parentButton.panel.width; + int rowHeight = this.parentButton.panel.rowHeight; + int textColor = new Color(255, 255, 255, (int)(255.0f * alpha)).getRGB(); + int sliderColor = new Color(138, 180, 248, (int)(255.0f * alpha)).getRGB(); + int textPadding = 8; + int sliderX = panelX + textPadding; + int valueTextWidth = (int)FontStore.OPENSANS_16.getStringWidth("00.00"); + int sliderWidth = panelWidth - textPadding * 2 - valueTextWidth + 20; if (this.dragging) { - this.updateSliderValue(n, n10, n12); + this.updateSliderValue(mouseX, sliderX, sliderWidth); } - String string = this.numberSetting.getName(); - String string2 = this.numberSetting.getStep().doubleValue() % 1.0 == 0.0 ? String.format("%d", new Object[]{this.numberSetting.getValue().intValue()}) : String.format("%.2f", new Object[]{Float.valueOf(this.numberSetting.getValue().floatValue())}); - float f3 = (float)n3 + ((float)n6 - FontStore.OPENSANS_16.getFontHeight()) / 2.0f; - FontStore.OPENSANS_16.drawStringWithShadow(poseStack, string, n10, f3, n7); - FontStore.OPENSANS_16.drawStringWithShadow(poseStack, string2, (float)(n4 + n5 - n9) - FontStore.OPENSANS_16.getStringWidth(string2), f3, n7); - float f4 = this.numberSetting.getMin().floatValue(); - float f5 = this.numberSetting.getMax().floatValue(); - float f6 = this.numberSetting.getValue().floatValue(); - float f7 = (f6 - f4) / (f5 - f4); - int n13 = n3 + n6 / 2 + 10; - int n14 = 2; - RenderUtil.drawFilledRect(poseStack, n10, n13, n12, n14, new Color(10, 10, 10, 200).getRGB()); - RenderUtil.drawFilledRect(poseStack, n10, n13, (int)((float)n12 * f7), n14, n8); + String name = this.numberSetting.getName(); + String valueText = this.numberSetting.getStep().doubleValue() % 1.0 == 0.0 ? String.format("%d", new Object[]{this.numberSetting.getValue().intValue()}) : String.format("%.2f", new Object[]{Float.valueOf(this.numberSetting.getValue().floatValue())}); + float textY = (float)rowY + ((float)rowHeight - FontStore.OPENSANS_16.getFontHeight()) / 2.0f; + FontStore.OPENSANS_16.drawStringWithShadow(poseStack, name, sliderX, textY, textColor); + FontStore.OPENSANS_16.drawStringWithShadow(poseStack, valueText, (float)(panelX + panelWidth - textPadding) - FontStore.OPENSANS_16.getStringWidth(valueText), textY, textColor); + float min = this.numberSetting.getMin().floatValue(); + float max = this.numberSetting.getMax().floatValue(); + float current = this.numberSetting.getValue().floatValue(); + float progress = (current - min) / (max - min); + int sliderY = rowY + rowHeight / 2 + 10; + int sliderHeight = 2; + RenderUtil.drawFilledRect(poseStack, sliderX, sliderY, sliderWidth, sliderHeight, new Color(10, 10, 10, 200).getRGB()); + RenderUtil.drawFilledRect(poseStack, sliderX, sliderY, (int)((float)sliderWidth * progress), sliderHeight, sliderColor); } - private void updateSliderValue(double d, int n, int n2) { - float f = this.numberSetting.getMin().floatValue(); - float f2 = this.numberSetting.getMax().floatValue(); - float f3 = f2 - f; - double d2 = Math.max(n, Math.min(d, n + n2)); - float f4 = f + f3 * (float)((d2 - (double)n) / (double)n2); - this.numberSetting.setValue(MathUtil.roundDecimal(f4, 2)); + private void updateSliderValue(double mouseX, int sliderX, int sliderWidth) { + float min = this.numberSetting.getMin().floatValue(); + float max = this.numberSetting.getMax().floatValue(); + float range = max - min; + double clampedX = Math.max(sliderX, Math.min(mouseX, sliderX + sliderWidth)); + float newValue = min + range * (float)((clampedX - (double)sliderX) / (double)sliderWidth); + this.numberSetting.setValue(MathUtil.roundDecimal(newValue, 2)); } @Override - public void mouseClicked(double d, double d2, int n) { - boolean bl; - int n2 = this.parentButton.panel.x; - int n3 = this.parentButton.panel.width; - int n4 = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; - int n5 = this.parentButton.panel.rowHeight; - int n6 = 8; - int n7 = n2 + n6; - int n8 = (int)FontStore.OPENSANS_16.getStringWidth("00.00"); - int n9 = n3 - n6 * 2 - n8 + 20; - boolean bl2 = bl = d >= (double)n7 && d <= (double)(n7 + n9) && d2 >= (double)n4 && d2 <= (double)(n4 + n5); - if (n == 0 && bl) { + public void mouseClicked(double mouseX, double mouseY, int button) { + boolean overSlider; + int panelX = this.parentButton.panel.x; + int panelWidth = this.parentButton.panel.width; + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; + int rowHeight = this.parentButton.panel.rowHeight; + int textPadding = 8; + int sliderX = panelX + textPadding; + int valueTextWidth = (int)FontStore.OPENSANS_16.getStringWidth("00.00"); + int sliderWidth = panelWidth - textPadding * 2 - valueTextWidth + 20; + boolean dup = overSlider = mouseX >= (double)sliderX && mouseX <= (double)(sliderX + sliderWidth) && mouseY >= (double)rowY && mouseY <= (double)(rowY + rowHeight); + if (button == 0 && overSlider) { this.dragging = true; - this.updateSliderValue(d, n7, n9); + this.updateSliderValue(mouseX, sliderX, sliderWidth); } } @Override - public void mouseReleased(double d, double d2, int n) { - if (n == 0) { + public void mouseReleased(double mouseX, double mouseY, int button) { + if (button == 0) { this.dragging = false; } } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/legacy/SettingComponent.java b/src/main/java/shit/zen/gui/legacy/SettingComponent.java index dab822e..ca51bbd 100644 --- a/src/main/java/shit/zen/gui/legacy/SettingComponent.java +++ b/src/main/java/shit/zen/gui/legacy/SettingComponent.java @@ -9,28 +9,28 @@ public class SettingComponent { public ModuleButton parentButton; public int yOffset; - public SettingComponent(Setting setting, ModuleButton moduleButton, int n) { + public SettingComponent(Setting setting, ModuleButton moduleButton, int yOffset) { this.setting = setting; this.parentButton = moduleButton; - this.yOffset = n; + this.yOffset = yOffset; } - public void render(PoseStack poseStack, int n, int n2, float f) { - this.renderWithAlpha(poseStack, n, n2, f, 1.0f); + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) { + this.renderWithAlpha(poseStack, mouseX, mouseY, partialTicks, 1.0f); } - public void renderWithAlpha(PoseStack poseStack, int n, int n2, float f, float f2) { + public void renderWithAlpha(PoseStack poseStack, int mouseX, int mouseY, float partialTicks, float alpha) { } - public void mouseClicked(double d, double d2, int n) { + public void mouseClicked(double mouseX, double mouseY, int button) { } - public void mouseReleased(double d, double d2, int n) { + public void mouseReleased(double mouseX, double mouseY, int button) { } - public boolean isHovered(double d, double d2) { - int n = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; - int n2 = this.parentButton.panel.rowHeight; - return d >= (double)this.parentButton.panel.x && d <= (double)(this.parentButton.panel.x + this.parentButton.panel.width) && d2 >= (double)n && d2 <= (double)(n + n2); + public boolean isHovered(double mouseX, double mouseY) { + int rowY = this.parentButton.panel.y + this.parentButton.yOffset + this.parentButton.panel.rowHeight + this.yOffset; + int rowHeight = this.parentButton.panel.rowHeight; + return mouseX >= (double)this.parentButton.panel.x && mouseX <= (double)(this.parentButton.panel.x + this.parentButton.panel.width) && mouseY >= (double)rowY && mouseY <= (double)(rowY + rowHeight); } } \ No newline at end of file diff --git a/src/main/java/shit/zen/gui/newclickgui/BooleanSettingElement.java b/src/main/java/shit/zen/gui/newclickgui/BooleanSettingElement.java index ae18e3b..ab6aa60 100644 --- a/src/main/java/shit/zen/gui/newclickgui/BooleanSettingElement.java +++ b/src/main/java/shit/zen/gui/newclickgui/BooleanSettingElement.java @@ -31,35 +31,35 @@ extends SettingElement { } @Override - public void render(NewClickGui newClickGui, GuiGraphics guiGraphics, PoseStack poseStack, int n, int n2, float f, float f2) { - this.isHovered = CursorUtil.isInBounds(n, n2, this.x, this.y, 120.0f, this.getHeight()); + public void render(NewClickGui clickGui, GuiGraphics guiGraphics, PoseStack poseStack, int mouseX, int mouseY, float alpha, float partialTicks) { + this.isHovered = CursorUtil.isInBounds(mouseX, mouseY, this.x, this.y, 120.0f, this.getHeight()); this.visibilityTimer.animate(this.setting.getVisibility().displayable() ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_POW2); this.visibilityTimer.tick(); - if (Mth.equal(f *= this.visibilityTimer.getValueF(), 0.0f)) { + if (Mth.equal(alpha *= this.visibilityTimer.getValueF(), 0.0f)) { return; } - String string = this.setting.getName(); - if (FontStore.AXIFORMA_REGULAR_14.getStringWidth(string) > 90.0f) { - string = string.substring(0, 10); - string = string + ELLIPSIS; + String name = this.setting.getName(); + if (FontStore.AXIFORMA_REGULAR_14.getStringWidth(name) > 90.0f) { + name = name.substring(0, 10); + name = name + ELLIPSIS; this.isTruncated = true; } this.toggleTimer.animate(this.setting.getValue() != false ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_POW2); this.toggleTimer.tick(); - if (Mth.equal(f, 0.0f)) { + if (Mth.equal(alpha, 0.0f)) { return; } poseStack.pushPose(); - FontStore.AXIFORMA_REGULAR_14.drawString(poseStack, string, this.x + 6.0f, this.y + (this.getHeight() - FontStore.AXIFORMA_REGULAR_14.getFontHeight()) / 2.0f, ColorUtil.withAlpha(-1, f * 0.8f)); - float f3 = this.toggleTimer.getValueF(); - if (f3 > 0.0f) { - RenderUtil.drawShadow(poseStack, this.x + 120.0f - 20.0f - 6.0f, this.y + (this.getHeight() - 10.0f) / 2.0f, 20.0f, 10.0f, 12, ColorUtil.withAlpha(-13768502, 0.36f * f * f3)); + FontStore.AXIFORMA_REGULAR_14.drawString(poseStack, name, this.x + 6.0f, this.y + (this.getHeight() - FontStore.AXIFORMA_REGULAR_14.getFontHeight()) / 2.0f, ColorUtil.withAlpha(-1, alpha * 0.8f)); + float toggleAmount = this.toggleTimer.getValueF(); + if (toggleAmount > 0.0f) { + RenderUtil.drawShadow(poseStack, this.x + 120.0f - 20.0f - 6.0f, this.y + (this.getHeight() - 10.0f) / 2.0f, 20.0f, 10.0f, 12, ColorUtil.withAlpha(-13768502, 0.36f * alpha * toggleAmount)); } - RenderUtil.drawRoundedRect(poseStack, this.x + 120.0f - 20.0f - 6.0f, this.y + (this.getHeight() - 10.0f) / 2.0f, 20.0f, 10.0f, 4.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(60, 60, 60), f)); - if (f3 > 0.0f) { - RenderUtil.drawRoundedRect(poseStack, this.x + 120.0f - 20.0f - 6.0f, this.y + (this.getHeight() - 10.0f) / 2.0f, 10.0f + 10.0f * f3, 10.0f, 4.0f, ColorUtil.withAlpha(CategoryPanel.ACCENT_COLOR, f * f3)); + RenderUtil.drawRoundedRect(poseStack, this.x + 120.0f - 20.0f - 6.0f, this.y + (this.getHeight() - 10.0f) / 2.0f, 20.0f, 10.0f, 4.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(60, 60, 60), alpha)); + if (toggleAmount > 0.0f) { + RenderUtil.drawRoundedRect(poseStack, this.x + 120.0f - 20.0f - 6.0f, this.y + (this.getHeight() - 10.0f) / 2.0f, 10.0f + 10.0f * toggleAmount, 10.0f, 4.0f, ColorUtil.withAlpha(CategoryPanel.ACCENT_COLOR, alpha * toggleAmount)); } - RenderUtil.drawRoundedRect(poseStack, this.x + 120.0f - 20.0f - 6.0f + 10.0f * f3, this.y + (this.getHeight() - 10.0f) / 2.0f, 10.0f, 10.0f, 4.8f, ColorUtil.withAlpha(-1, f)); + RenderUtil.drawRoundedRect(poseStack, this.x + 120.0f - 20.0f - 6.0f + 10.0f * toggleAmount, this.y + (this.getHeight() - 10.0f) / 2.0f, 10.0f, 10.0f, 4.8f, ColorUtil.withAlpha(-1, alpha)); poseStack.popPose(); if (this.isHovered && this.isTruncated) { this.parentPanel.setHoveredSettingElement(this); @@ -77,8 +77,8 @@ extends SettingElement { } @Override - public boolean mouseClicked(double d, double d2, int n) { - if (this.isHovered && CursorUtil.isInBounds((float)d, (float)d2, this.x + 120.0f - 20.0f - 6.0f, this.y + (this.getHeight() - 10.0f) / 2.0f, 20.0f, 10.0f)) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (this.isHovered && CursorUtil.isInBounds((float)mouseX, (float)mouseY, this.x + 120.0f - 20.0f - 6.0f, this.y + (this.getHeight() - 10.0f) / 2.0f, 20.0f, 10.0f)) { this.setting.setValue(this.setting.getValue() == false); return true; } diff --git a/src/main/java/shit/zen/gui/newclickgui/CategoryPanel.java b/src/main/java/shit/zen/gui/newclickgui/CategoryPanel.java index 70bfb51..77bf9f2 100644 --- a/src/main/java/shit/zen/gui/newclickgui/CategoryPanel.java +++ b/src/main/java/shit/zen/gui/newclickgui/CategoryPanel.java @@ -88,66 +88,66 @@ extends UIElement { } @Override - public void render(NewClickGui newClickGui, GuiGraphics guiGraphics, PoseStack poseStack, int n, int n2, float f, float f2) { - this.isHovered = CursorUtil.isInBounds(n, n2, this.posX, this.posY, 120.0f, this.panelHeight); + public void render(NewClickGui clickGui, GuiGraphics guiGraphics, PoseStack poseStack, int mouseX, int mouseY, float alpha, float partialTicks) { + this.isHovered = CursorUtil.isInBounds(mouseX, mouseY, this.posX, this.posY, 120.0f, this.panelHeight); if (this.isHovered) { NewClickGui.focusedPanel = this; } - this.scaleTimer.animate(newClickGui.isClosing() ? 0.0 : 1.0, newClickGui.isClosing() ? 0.22 : 0.32, Easings.BACK_OUT); + this.scaleTimer.animate(clickGui.isClosing() ? 0.0 : 1.0, clickGui.isClosing() ? 0.22 : 0.32, Easings.BACK_OUT); this.scaleTimer.tick(); - float f3 = 0.0f; + float totalContentHeight = 0.0f; for (ModuleElement moduleElement : this.moduleElements) { - f3 += moduleElement.getHeight(); + totalContentHeight += moduleElement.getHeight(); } if (this.moduleElements.size() < 10) { - this.panelHeight = Math.min(f3, 240.0f) + 20.0f; + this.panelHeight = Math.min(totalContentHeight, 240.0f) + 20.0f; } - this.scrollAmount = Mth.clamp(this.scrollAmount, 0.0f, f3 - this.panelHeight + 20.0f); + this.scrollAmount = Mth.clamp(this.scrollAmount, 0.0f, totalContentHeight - this.panelHeight + 20.0f); this.scrollTimer.animate(this.scrollAmount, 0.22, Easings.EASE_OUT_POW2); this.scrollTimer.tick(); this.tooltipTimer.animate(this.showTooltip ? 1.0 : 0.0, 0.3, Easings.EASE_OUT_POW2); this.tooltipTimer.tick(); if (this.isDragging) { - this.posX = (float)n + this.dragOffsetX; - this.posY = (float)n2 + this.dragOffsetY; + this.posX = (float)mouseX + this.dragOffsetX; + this.posY = (float)mouseY + this.dragOffsetY; } this.collapseTimer.animate(this.isCollapsed ? 0.0 : 1.0, 0.2, Easings.EASE_OUT_POW2); this.collapseTimer.tick(); - float f4 = this.collapseTimer.getValueF(); + float collapseAmount = this.collapseTimer.getValueF(); if (!this.isCollapsed) { this.prevHeight = this.panelHeight; } - float f5 = this.scaleTimer.getValueF(); - RenderHelper.pushScaleAround(poseStack, this.posX + 60.0f, this.posY + this.panelHeight / 2.0f, 0.4f + 0.6f * f5); - float f6 = 12.0f; - RenderUtil.drawRoundedRect(poseStack, this.posX - f6, this.posY - f6, 120.0f + f6 * 2.0f, this.panelHeight + f6 * 2.0f, 6.0f + f6 / 2.0f, f6, ColorUtil.fromARGB(0, 0, 0, (int)(80.0f * f * 1.0f))); - RenderUtil.drawRoundedRect(poseStack, this.posX, this.posY, 120.0f, this.panelHeight, 6.0f, ColorUtil.withAlpha(BG_COLOR, f)); + float scaleAmount = this.scaleTimer.getValueF(); + RenderHelper.pushScaleAround(poseStack, this.posX + 60.0f, this.posY + this.panelHeight / 2.0f, 0.4f + 0.6f * scaleAmount); + float shadowSize = 12.0f; + RenderUtil.drawRoundedRect(poseStack, this.posX - shadowSize, this.posY - shadowSize, 120.0f + shadowSize * 2.0f, this.panelHeight + shadowSize * 2.0f, 6.0f + shadowSize / 2.0f, shadowSize, ColorUtil.fromARGB(0, 0, 0, (int)(80.0f * alpha * 1.0f))); + RenderUtil.drawRoundedRect(poseStack, this.posX, this.posY, 120.0f, this.panelHeight, 6.0f, ColorUtil.withAlpha(BG_COLOR, alpha)); StencilHelper.beginWrite(false); RenderUtil.drawRoundedRect(poseStack, this.posX + 0.5f, this.posY, 118.0f, 20.0f, 6.0f, -1); StencilHelper.beginRead(true); - RenderUtil.drawGradientH(poseStack, this.posX, this.posY, 120.0f, 1.0f, ColorUtil.withAlpha(ColorUtil.animateColorOffset(-13768502, ACCENT_COLOR_DARK, 100L), f), ColorUtil.withAlpha(ColorUtil.animateColorOffset(-13768502, ACCENT_COLOR_DARK, 2000L), f)); + RenderUtil.drawGradientH(poseStack, this.posX, this.posY, 120.0f, 1.0f, ColorUtil.withAlpha(ColorUtil.animateColorOffset(-13768502, ACCENT_COLOR_DARK, 100L), alpha), ColorUtil.withAlpha(ColorUtil.animateColorOffset(-13768502, ACCENT_COLOR_DARK, 2000L), alpha)); StencilHelper.end(); - FontStore.AXIFORMA_EXTRABOLD_18.drawString(poseStack, this.category.displayName, this.posX + 8.0f, this.posY + (20.0f - FontStore.AXIFORMA_EXTRABOLD_18.getFontHeight()) / 2.0f + 3.0f, ColorUtil.withAlpha(-1, f)); - float f7 = this.scrollTimer.getValueF(); - float f8 = this.posY + 20.0f - f7; + FontStore.AXIFORMA_EXTRABOLD_18.drawString(poseStack, this.category.displayName, this.posX + 8.0f, this.posY + (20.0f - FontStore.AXIFORMA_EXTRABOLD_18.getFontHeight()) / 2.0f + 3.0f, ColorUtil.withAlpha(-1, alpha)); + float scrollOffset = this.scrollTimer.getValueF(); + float elementY = this.posY + 20.0f - scrollOffset; StencilHelper.beginWrite(false); RenderUtil.drawFilledRect(poseStack, this.posX + 0.5f, this.posY + 20.0f, 119.0f, 6.0f, -1); RenderUtil.drawRoundedRect(poseStack, this.posX, this.posY + 20.0f, 120.0f, this.panelHeight - 20.0f - 0.5f, 6.0f, -1); StencilHelper.beginRead(true); for (ModuleElement moduleElement : this.moduleElements) { moduleElement.setX(this.posX); - moduleElement.setY(f8); - moduleElement.render(newClickGui, guiGraphics, poseStack, n, n2, f, f2); - f8 += moduleElement.getHeight(); + moduleElement.setY(elementY); + moduleElement.render(clickGui, guiGraphics, poseStack, mouseX, mouseY, alpha, partialTicks); + elementY += moduleElement.getHeight(); } - RenderUtil.drawGradientV(poseStack, this.posX + 0.5f, this.posY + 20.0f - 0.5f, 119.0f, 6.0f, ColorUtil.withAlpha(-16777216, 0.36f * f), ColorUtil.withAlpha(-16777216, 0.0f)); + RenderUtil.drawGradientV(poseStack, this.posX + 0.5f, this.posY + 20.0f - 0.5f, 119.0f, 6.0f, ColorUtil.withAlpha(-16777216, 0.36f * alpha), ColorUtil.withAlpha(-16777216, 0.0f)); StencilHelper.end(); - float f9 = this.tooltipTimer.getValueF(); - if (f9 > 0.0f) { - float f10 = FontStore.AXIFORMA_REGULAR_16.getStringWidth(this.tooltipText); - RenderUtil.drawShadow(poseStack, n + 5, n2 + 5, f10 + 6.0f, FontStore.AXIFORMA_REGULAR_16.getFontHeight() + 4.0f, 12, ColorUtil.withAlpha(BG_COLOR, f * f9 * 0.66f)); - RenderUtil.drawRoundedRect(poseStack, n + 5, n2 + 5, f10 + 6.0f, FontStore.AXIFORMA_REGULAR_16.getFontHeight() + 4.0f, 3.0f, ColorUtil.withAlpha(BG_COLOR, f * f9)); - FontStore.AXIFORMA_REGULAR_16.drawString(poseStack, this.tooltipText, n + 5 + 3, n2 + 5 + 1, ColorUtil.withAlpha(-1, f * f9)); + float tooltipAmount = this.tooltipTimer.getValueF(); + if (tooltipAmount > 0.0f) { + float tooltipWidth = FontStore.AXIFORMA_REGULAR_16.getStringWidth(this.tooltipText); + RenderUtil.drawShadow(poseStack, mouseX + 5, mouseY + 5, tooltipWidth + 6.0f, FontStore.AXIFORMA_REGULAR_16.getFontHeight() + 4.0f, 12, ColorUtil.withAlpha(BG_COLOR, alpha * tooltipAmount * 0.66f)); + RenderUtil.drawRoundedRect(poseStack, mouseX + 5, mouseY + 5, tooltipWidth + 6.0f, FontStore.AXIFORMA_REGULAR_16.getFontHeight() + 4.0f, 3.0f, ColorUtil.withAlpha(BG_COLOR, alpha * tooltipAmount)); + FontStore.AXIFORMA_REGULAR_16.drawString(poseStack, this.tooltipText, mouseX + 5 + 3, mouseY + 5 + 1, ColorUtil.withAlpha(-1, alpha * tooltipAmount)); } RenderHelper.popPose(poseStack); } @@ -159,15 +159,15 @@ extends UIElement { } @Override - public boolean mouseClicked(double d, double d2, int n) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { if (this.isHovered) { - if (CursorUtil.isInBounds((float)d, (float)d2, this.posX, this.posY, 120.0f, 20.0f)) { + if (CursorUtil.isInBounds((float)mouseX, (float)mouseY, this.posX, this.posY, 120.0f, 20.0f)) { this.isDragging = true; - this.dragOffsetX = this.posX - (float)d; - this.dragOffsetY = this.posY - (float)d2; - } else if (CursorUtil.isInBounds((float)d, (float)d2, this.posX, this.posY + 20.0f, 120.0f, this.panelHeight - 20.0f)) { + this.dragOffsetX = this.posX - (float)mouseX; + this.dragOffsetY = this.posY - (float)mouseY; + } else if (CursorUtil.isInBounds((float)mouseX, (float)mouseY, this.posX, this.posY + 20.0f, 120.0f, this.panelHeight - 20.0f)) { for (ModuleElement moduleElement : this.moduleElements) { - if (!moduleElement.mouseClicked(d, d2, n)) continue; + if (!moduleElement.mouseClicked(mouseX, mouseY, button)) continue; return true; } } @@ -177,10 +177,10 @@ extends UIElement { } @Override - public boolean mouseReleased(double d, double d2, int n) { - if (CursorUtil.isInBounds((float)d, (float)d2, this.posX, this.posY + 20.0f, 120.0f, this.panelHeight - 20.0f)) { + public boolean mouseReleased(double mouseX, double mouseY, int button) { + if (CursorUtil.isInBounds((float)mouseX, (float)mouseY, this.posX, this.posY + 20.0f, 120.0f, this.panelHeight - 20.0f)) { for (ModuleElement moduleElement : this.moduleElements) { - if (!moduleElement.mouseReleased(d, d2, n)) continue; + if (!moduleElement.mouseReleased(mouseX, mouseY, button)) continue; return true; } } @@ -189,9 +189,9 @@ extends UIElement { } @Override - public boolean mouseScrolled(double d, double d2, double d3) { + public boolean mouseScrolled(double mouseX, double mouseY, double scrollDelta) { if (this.isHovered) { - this.scrollAmount -= (float)d3 * 50.0f; + this.scrollAmount -= (float)scrollDelta * 50.0f; return true; } return false; @@ -217,20 +217,20 @@ extends UIElement { @Override @Generated - public void setX(float f) { - this.posX = f; + public void setX(float x) { + this.posX = x; } @Override @Generated - public void setY(float f) { - this.posY = f; + public void setY(float y) { + this.posY = y; } @Override @Generated - public void setHeight(float f) { - this.panelHeight = f; + public void setHeight(float height) { + this.panelHeight = height; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/gui/newclickgui/ModeSettingElement.java b/src/main/java/shit/zen/gui/newclickgui/ModeSettingElement.java index 734f4d0..be5144e 100644 --- a/src/main/java/shit/zen/gui/newclickgui/ModeSettingElement.java +++ b/src/main/java/shit/zen/gui/newclickgui/ModeSettingElement.java @@ -29,55 +29,55 @@ extends SettingElement { } @Override - public void render(NewClickGui newClickGui, GuiGraphics guiGraphics, PoseStack poseStack, int n, int n2, float f, float f2) { - float f3; - float f4; - float f5 = 36.0f; - float f6 = this.y + f5 / 2.0f + 2.0f - 2.0f; - float f7 = 108.0f; - float f8 = 14.0f; + public void render(NewClickGui clickGui, GuiGraphics guiGraphics, PoseStack poseStack, int mouseX, int mouseY, float alpha, float partialTicks) { + float hoverAmount; + float dropdownHeight; + float totalHeight = 36.0f; + float dropdownY = this.y + totalHeight / 2.0f + 2.0f - 2.0f; + float dropdownWidth = 108.0f; + float itemHeight = 14.0f; this.hoveredMode = null; - this.isDropdownHovered = CursorUtil.isInBounds(n, n2, this.x + 6.0f, f6, f7, f8); + this.isDropdownHovered = CursorUtil.isInBounds(mouseX, mouseY, this.x + 6.0f, dropdownY, dropdownWidth, itemHeight); this.hoverTimer.animate(this.isDropdownHovered ? 1.0 : 0.0, 0.22, Easings.EASE_OUT_POW2); this.hoverTimer.tick(); this.visibilityTimer.animate(this.setting.getVisibility().displayable() ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_POW2); this.visibilityTimer.tick(); this.visTimer.animate(this.isOpen ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_POW2); this.visTimer.tick(); - if (Mth.equal(f *= this.visibilityTimer.getValueF(), 0.0f)) { + if (Mth.equal(alpha *= this.visibilityTimer.getValueF(), 0.0f)) { return; } - float f9 = this.y + (f5 / 2.0f - FontStore.AXIFORMA_REGULAR_14.getFontHeight()) / 2.0f + 1.0f; - FontStore.AXIFORMA_REGULAR_14.drawString(poseStack, this.setting.getName(), this.x + 6.0f, f9, ColorUtil.withAlpha(-1, f * 0.8f)); - float f10 = this.visTimer.getValueF(); - if (f10 > 0.0f) { - f4 = f8 + (float) this.setting.getModes().length * f8 * f10; - RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, f6, f7, f4, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(60, 60, 60), f * f10)); - f3 = (f8 - FontStore.AXIFORMA_BOLD_13.getFontHeight()) / 2.0f; - float f11 = f6 + f3 + f8; - for (String string : this.setting.getModes()) { - if (CursorUtil.isInBounds(n, n2, this.x + 6.0f, f11 - f3, f7, f8)) { - this.hoveredMode = string; - this.highlightYTimer.animate(f11 - f3, 0.2, Easings.EASE_OUT_POW2); + float nameY = this.y + (totalHeight / 2.0f - FontStore.AXIFORMA_REGULAR_14.getFontHeight()) / 2.0f + 1.0f; + FontStore.AXIFORMA_REGULAR_14.drawString(poseStack, this.setting.getName(), this.x + 6.0f, nameY, ColorUtil.withAlpha(-1, alpha * 0.8f)); + float openAmount = this.visTimer.getValueF(); + if (openAmount > 0.0f) { + dropdownHeight = itemHeight + (float) this.setting.getModes().length * itemHeight * openAmount; + RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, dropdownY, dropdownWidth, dropdownHeight, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(60, 60, 60), alpha * openAmount)); + hoverAmount = (itemHeight - FontStore.AXIFORMA_BOLD_13.getFontHeight()) / 2.0f; + float itemY = dropdownY + hoverAmount + itemHeight; + for (String mode : this.setting.getModes()) { + if (CursorUtil.isInBounds(mouseX, mouseY, this.x + 6.0f, itemY - hoverAmount, dropdownWidth, itemHeight)) { + this.hoveredMode = mode; + this.highlightYTimer.animate(itemY - hoverAmount, 0.2, Easings.EASE_OUT_POW2); } - if (f6 + f4 > f11 + FontStore.AXIFORMA_BOLD_13.getFontHeight()) { - FontStore.AXIFORMA_BOLD_13.drawStringCentered(poseStack, string, this.x + 60.0f, f11, ColorUtil.withAlpha(-1, f * 0.8f * f10)); + if (dropdownY + dropdownHeight > itemY + FontStore.AXIFORMA_BOLD_13.getFontHeight()) { + FontStore.AXIFORMA_BOLD_13.drawStringCentered(poseStack, mode, this.x + 60.0f, itemY, ColorUtil.withAlpha(-1, alpha * 0.8f * openAmount)); } - f11 += f8; + itemY += itemHeight; } } this.highlightTimer.animate(this.hoveredMode == null || !this.isOpen ? 0.0 : 1.0, 0.18, Easings.EASE_OUT_POW2); this.highlightTimer.tick(); this.highlightYTimer.tick(); - f4 = this.highlightTimer.getValueF(); - if (f4 > 0.0f) { - RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, this.highlightYTimer.getValueF(), f7, f8, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(255, 255, 255), f * f4 * 1.0f * 0.1f)); + dropdownHeight = this.highlightTimer.getValueF(); + if (dropdownHeight > 0.0f) { + RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, this.highlightYTimer.getValueF(), dropdownWidth, itemHeight, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(255, 255, 255), alpha * dropdownHeight * 1.0f * 0.1f)); } - f3 = this.hoverTimer.getValueF(); - RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, f6, f7, f8, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB((int)(60.0f + 30.0f * f3), (int)(60.0f + 30.0f * f3), (int)(60.0f + 30.0f * f3)), f)); - FontStore.AXIFORMA_BOLD_13.drawStringCentered(poseStack, this.setting.getValue(), this.x + 60.0f, f6 + (f8 - FontStore.AXIFORMA_BOLD_13.getFontHeight()) / 2.0f, ColorUtil.withAlpha(-1, f * 0.8f)); - String string = String.valueOf('\ueb5d'); - FontStore.MATERIAL_20.drawStringCentered(poseStack, string, this.x + 6.0f + f7 - FontStore.MATERIAL_20.getStringWidth(string) + 2.0f, f6 + (f8 - FontStore.MATERIAL_20.getFontHeight()) / 2.0f + 0.5f, ColorUtil.withAlpha(-1, f * 0.8f)); + hoverAmount = this.hoverTimer.getValueF(); + RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, dropdownY, dropdownWidth, itemHeight, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB((int)(60.0f + 30.0f * hoverAmount), (int)(60.0f + 30.0f * hoverAmount), (int)(60.0f + 30.0f * hoverAmount)), alpha)); + FontStore.AXIFORMA_BOLD_13.drawStringCentered(poseStack, this.setting.getValue(), this.x + 60.0f, dropdownY + (itemHeight - FontStore.AXIFORMA_BOLD_13.getFontHeight()) / 2.0f, ColorUtil.withAlpha(-1, alpha * 0.8f)); + String arrowIcon = String.valueOf('\ueb5d'); + FontStore.MATERIAL_20.drawStringCentered(poseStack, arrowIcon, this.x + 6.0f + dropdownWidth - FontStore.MATERIAL_20.getStringWidth(arrowIcon) + 2.0f, dropdownY + (itemHeight - FontStore.MATERIAL_20.getFontHeight()) / 2.0f + 0.5f, ColorUtil.withAlpha(-1, alpha * 0.8f)); } @Override @@ -91,7 +91,7 @@ extends SettingElement { } @Override - public boolean mouseClicked(double d, double d2, int n) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { if (this.isDropdownHovered) { this.isOpen = !this.isOpen; return true; diff --git a/src/main/java/shit/zen/gui/newclickgui/ModuleElement.java b/src/main/java/shit/zen/gui/newclickgui/ModuleElement.java index be76976..5318fe2 100644 --- a/src/main/java/shit/zen/gui/newclickgui/ModuleElement.java +++ b/src/main/java/shit/zen/gui/newclickgui/ModuleElement.java @@ -78,16 +78,16 @@ extends UIElement { } @Override - public void render(NewClickGui newClickGui, GuiGraphics guiGraphics, PoseStack poseStack, int n, int n2, float f, float f2) { - float f3; - float f4; - float f5; - float f6 = 0.0f; + public void render(NewClickGui clickGui, GuiGraphics guiGraphics, PoseStack poseStack, int mouseX, int mouseY, float alpha, float partialTicks) { + float titleY; + float titleWidth; + float enabledAmount; + float settingsTotalHeight = 0.0f; for (SettingElement settingElement : this.settingElements) { if (!settingElement.getSetting().getVisibility().displayable()) continue; - f6 += settingElement.getHeight(); + settingsTotalHeight += settingElement.getHeight(); } - this.settingsHeightTimer.animate(f6, 0.2, Easings.EASE_OUT_POW2); + this.settingsHeightTimer.animate(settingsTotalHeight, 0.2, Easings.EASE_OUT_POW2); this.settingsHeightTimer.tick(); this.parentPanel.setCollapsed(!this.settingsHeightTimer.isDone()); this.hoveredTimer.animate(this.isHovered ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_POW2); @@ -96,39 +96,39 @@ extends UIElement { this.enabledTimer.tick(); this.expandTimer.animate(this.isExpanded ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_POW3); this.expandTimer.tick(); - float f7 = this.expandTimer.getValueF(); - this.totalHeight = 20.0f + f7 * this.settingsHeightTimer.getValueF(); - this.isHovered = this.parentPanel.equals(NewClickGui.focusedPanel) && CursorUtil.isInBounds(n, n2, this.posX, this.posY, 120.0f, this.totalHeight); - RenderUtil.drawFilledRect(poseStack, this.posX + 1.0f, this.posY + 20.0f, 118.0f, this.totalHeight - 20.0f, ColorUtil.withAlpha(BG_COLOR, f7 * f)); - float f8 = this.hoveredTimer.getValueF(); - if (f8 > 0.0f) { - RenderUtil.drawFilledRect(poseStack, this.posX + 0.5f, this.posY, 119.0f, 20.0f, ColorUtil.withAlpha(-1, 0.1f * f * f8)); + float expandAmount = this.expandTimer.getValueF(); + this.totalHeight = 20.0f + expandAmount * this.settingsHeightTimer.getValueF(); + this.isHovered = this.parentPanel.equals(NewClickGui.focusedPanel) && CursorUtil.isInBounds(mouseX, mouseY, this.posX, this.posY, 120.0f, this.totalHeight); + RenderUtil.drawFilledRect(poseStack, this.posX + 1.0f, this.posY + 20.0f, 118.0f, this.totalHeight - 20.0f, ColorUtil.withAlpha(BG_COLOR, expandAmount * alpha)); + float hoverAmount = this.hoveredTimer.getValueF(); + if (hoverAmount > 0.0f) { + RenderUtil.drawFilledRect(poseStack, this.posX + 0.5f, this.posY, 119.0f, 20.0f, ColorUtil.withAlpha(-1, 0.1f * alpha * hoverAmount)); } - if (1.0f - (f5 = this.enabledTimer.getValueF()) > 0.0f) { - FontStore.AXIFORMA_REGULAR_16.drawStringCentered(poseStack, this.module.getName(), this.posX + 60.0f, this.posY + (20.0f - FontStore.AXIFORMA_REGULAR_16.getFontHeight()) / 2.0f, ColorUtil.withAlpha(-1, f * (1.0f - f5) * 0.6f)); + if (1.0f - (enabledAmount = this.enabledTimer.getValueF()) > 0.0f) { + FontStore.AXIFORMA_REGULAR_16.drawStringCentered(poseStack, this.module.getName(), this.posX + 60.0f, this.posY + (20.0f - FontStore.AXIFORMA_REGULAR_16.getFontHeight()) / 2.0f, ColorUtil.withAlpha(-1, alpha * (1.0f - enabledAmount) * 0.6f)); } - if (f5 > 0.0f) { - f4 = FontStore.AXIFORMA_BOLD_16.getStringWidth(this.module.getName()); - f3 = this.posY + (20.0f - FontStore.AXIFORMA_BOLD_16.getFontHeight()) / 2.0f; - RenderUtil.drawShadow(poseStack, this.posX + (120.0f - f4) / 2.0f, f3 + FontStore.AXIFORMA_BOLD_16.getFontHeight() / 4.0f, f4, FontStore.AXIFORMA_BOLD_16.getFontHeight() / 2.0f, 12, ColorUtil.withAlpha(-13768502, f * f5 * 0.36f)); - FontStore.AXIFORMA_BOLD_16.drawStringCentered(poseStack, this.module.getName(), this.posX + 60.0f, f3, ColorUtil.withAlpha(-13768502, f * f5)); + if (enabledAmount > 0.0f) { + titleWidth = FontStore.AXIFORMA_BOLD_16.getStringWidth(this.module.getName()); + titleY = this.posY + (20.0f - FontStore.AXIFORMA_BOLD_16.getFontHeight()) / 2.0f; + RenderUtil.drawShadow(poseStack, this.posX + (120.0f - titleWidth) / 2.0f, titleY + FontStore.AXIFORMA_BOLD_16.getFontHeight() / 4.0f, titleWidth, FontStore.AXIFORMA_BOLD_16.getFontHeight() / 2.0f, 12, ColorUtil.withAlpha(-13768502, alpha * enabledAmount * 0.36f)); + FontStore.AXIFORMA_BOLD_16.drawStringCentered(poseStack, this.module.getName(), this.posX + 60.0f, titleY, ColorUtil.withAlpha(-13768502, alpha * enabledAmount)); } if (!this.module.getSettings().isEmpty()) { - String string = String.valueOf('\ueb4e'); - f3 = FontStore.MATERIAL_20.getStringWidth(string); - float f9 = this.posX + 120.0f - f3 - 6.0f; - float f10 = this.posY + (20.0f - FontStore.MATERIAL_20.getFontHeight()) / 2.0f + 1.0f; - RenderHelper.pushRotateAround(poseStack, f9 + f3 / 2.0f, f10 + FontStore.MATERIAL_20.getFontHeight() / 2.0f - 1.0f, 180.0f * f7); - FontStore.MATERIAL_20.drawString(poseStack, string, f9, f10, ColorUtil.withAlpha(-1, (0.8f - 0.3f * f7) * f)); + String arrowIcon = String.valueOf('\ueb4e'); + titleY = FontStore.MATERIAL_20.getStringWidth(arrowIcon); + float arrowX = this.posX + 120.0f - titleY - 6.0f; + float arrowY = this.posY + (20.0f - FontStore.MATERIAL_20.getFontHeight()) / 2.0f + 1.0f; + RenderHelper.pushRotateAround(poseStack, arrowX + titleY / 2.0f, arrowY + FontStore.MATERIAL_20.getFontHeight() / 2.0f - 1.0f, 180.0f * expandAmount); + FontStore.MATERIAL_20.drawString(poseStack, arrowIcon, arrowX, arrowY, ColorUtil.withAlpha(-1, (0.8f - 0.3f * expandAmount) * alpha)); RenderHelper.popPose(poseStack); } if (this.isExpanded) { - f4 = this.posY + 20.0f; + titleWidth = this.posY + 20.0f; for (SettingElement settingElement : this.settingElements) { settingElement.setX(this.posX); - settingElement.setY(f4); - settingElement.render(newClickGui, guiGraphics, poseStack, n, n2, f * f7, f2); - f4 += settingElement.getAnimatedHeight() * settingElement.getVisibilityTimer().getValueF(); + settingElement.setY(titleWidth); + settingElement.render(clickGui, guiGraphics, poseStack, mouseX, mouseY, alpha * expandAmount, partialTicks); + titleWidth += settingElement.getAnimatedHeight() * settingElement.getVisibilityTimer().getValueF(); } } } @@ -200,20 +200,20 @@ extends UIElement { @Override @Generated - public void setX(float f) { - this.posX = f; + public void setX(float x) { + this.posX = x; } @Override @Generated - public void setY(float f) { - this.posY = f; + public void setY(float y) { + this.posY = y; } @Override @Generated - public void setHeight(float f) { - this.totalHeight = f; + public void setHeight(float height) { + this.totalHeight = height; } static { diff --git a/src/main/java/shit/zen/gui/newclickgui/MultiSelectSettingElement.java b/src/main/java/shit/zen/gui/newclickgui/MultiSelectSettingElement.java index 8a9c199..e8814e1 100644 --- a/src/main/java/shit/zen/gui/newclickgui/MultiSelectSettingElement.java +++ b/src/main/java/shit/zen/gui/newclickgui/MultiSelectSettingElement.java @@ -46,62 +46,62 @@ extends SettingElement { } @Override - public void render(NewClickGui newClickGui, GuiGraphics guiGraphics, PoseStack poseStack, int n, int n2, float f, float f2) { - float f3; - float f4; - float f5 = this.y + 18.0f + 2.0f; - float f6 = 108.0f; - float f7 = 14.0f; + public void render(NewClickGui clickGui, GuiGraphics guiGraphics, PoseStack poseStack, int mouseX, int mouseY, float alpha, float partialTicks) { + float hoverAmount; + float dropdownHeight; + float dropdownY = this.y + 18.0f + 2.0f; + float dropdownWidth = 108.0f; + float itemHeight = 14.0f; this.hoveredOption = null; - this.isDropdownHovered = CursorUtil.isInBounds(n, n2, this.x + 6.0f, f5, f6, f7); + this.isDropdownHovered = CursorUtil.isInBounds(mouseX, mouseY, this.x + 6.0f, dropdownY, dropdownWidth, itemHeight); this.hoverTimer.animate(this.isDropdownHovered ? 1.0 : 0.0, 0.22, Easings.EASE_OUT_POW2); this.hoverTimer.tick(); this.visibilityTimer.animate(this.setting.getVisibility().displayable() ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_POW2); this.visibilityTimer.tick(); this.visTimer.animate(this.isOpen ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_POW2); this.visTimer.tick(); - if (Mth.equal(f *= this.visibilityTimer.getValueF(), 0.0f)) { + if (Mth.equal(alpha *= this.visibilityTimer.getValueF(), 0.0f)) { return; } - float f8 = this.y + (18.0f - FontStore.AXIFORMA_REGULAR_14.getFontHeight()) / 2.0f + 1.0f; - FontStore.AXIFORMA_REGULAR_14.drawString(poseStack, this.setting.getName(), this.x + 6.0f, f8, ColorUtil.withAlpha(-1, f * 0.8f)); - float f9 = this.visTimer.getValueF(); - if (f9 > 0.0f) { - f4 = f7 + (float) this.setting.getOptions().size() * f7 * f9; - RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, f5, f6, f4, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(60, 60, 60), f * f9)); - f3 = (f7 - FontStore.AXIFORMA_BOLD_13.getFontHeight()) / 2.0f; - float f10 = f5 + f3 + f7; - for (String string : this.setting.getOptions()) { - if (CursorUtil.isInBounds(n, n2, this.x + 6.0f, f10 - f3, f6, f7)) { - this.hoveredOption = string; - this.highlightYTimer.animate(f10 - f3, 0.2, Easings.EASE_OUT_POW2); + float nameY = this.y + (18.0f - FontStore.AXIFORMA_REGULAR_14.getFontHeight()) / 2.0f + 1.0f; + FontStore.AXIFORMA_REGULAR_14.drawString(poseStack, this.setting.getName(), this.x + 6.0f, nameY, ColorUtil.withAlpha(-1, alpha * 0.8f)); + float openAmount = this.visTimer.getValueF(); + if (openAmount > 0.0f) { + dropdownHeight = itemHeight + (float) this.setting.getOptions().size() * itemHeight * openAmount; + RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, dropdownY, dropdownWidth, dropdownHeight, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(60, 60, 60), alpha * openAmount)); + hoverAmount = (itemHeight - FontStore.AXIFORMA_BOLD_13.getFontHeight()) / 2.0f; + float itemY = dropdownY + hoverAmount + itemHeight; + for (String option : this.setting.getOptions()) { + if (CursorUtil.isInBounds(mouseX, mouseY, this.x + 6.0f, itemY - hoverAmount, dropdownWidth, itemHeight)) { + this.hoveredOption = option; + this.highlightYTimer.animate(itemY - hoverAmount, 0.2, Easings.EASE_OUT_POW2); } - if (f5 + f4 > f10 + FontStore.AXIFORMA_BOLD_13.getFontHeight()) { - FontStore.AXIFORMA_BOLD_13.drawStringCentered(poseStack, string, this.x + 60.0f, f10, ColorUtil.withAlpha(-1, f * 0.8f * f9)); - if (this.setting.getValue().contains(string)) { - FontStore.MATERIAL_14.drawString(poseStack, "", this.x + 6.0f + f6 - FontStore.MATERIAL_14.getStringWidth("") - 4.0f, f10 - f3 + (f7 - FontStore.MATERIAL_14.getFontHeight()) / 2.0f + 0.5f, ColorUtil.withAlpha(-1, f * 0.56f * f9)); + if (dropdownY + dropdownHeight > itemY + FontStore.AXIFORMA_BOLD_13.getFontHeight()) { + FontStore.AXIFORMA_BOLD_13.drawStringCentered(poseStack, option, this.x + 60.0f, itemY, ColorUtil.withAlpha(-1, alpha * 0.8f * openAmount)); + if (this.setting.getValue().contains(option)) { + FontStore.MATERIAL_14.drawString(poseStack, "", this.x + 6.0f + dropdownWidth - FontStore.MATERIAL_14.getStringWidth("") - 4.0f, itemY - hoverAmount + (itemHeight - FontStore.MATERIAL_14.getFontHeight()) / 2.0f + 0.5f, ColorUtil.withAlpha(-1, alpha * 0.56f * openAmount)); } } - f10 += f7; + itemY += itemHeight; } } this.highlightTimer.animate(this.hoveredOption == null || !this.isOpen ? 0.0 : 1.0, 0.18, Easings.EASE_OUT_POW2); this.highlightTimer.tick(); this.highlightYTimer.tick(); - f4 = this.highlightTimer.getValueF(); - if (f4 > 0.0f) { - RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, this.highlightYTimer.getValueF(), f6, f7, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(255, 255, 255), f * f4 * 1.0f * 0.1f)); + dropdownHeight = this.highlightTimer.getValueF(); + if (dropdownHeight > 0.0f) { + RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, this.highlightYTimer.getValueF(), dropdownWidth, itemHeight, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(255, 255, 255), alpha * dropdownHeight * 1.0f * 0.1f)); } - f3 = this.hoverTimer.getValueF(); - RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, f5, f6, f7, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB((int)(60.0f + 30.0f * f3), (int)(60.0f + 30.0f * f3), (int)(60.0f + 30.0f * f3)), f)); - String string = this.setting.getValue().get(0); + hoverAmount = this.hoverTimer.getValueF(); + RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, dropdownY, dropdownWidth, itemHeight, 3.0f, ColorUtil.withAlpha(ColorUtil.fromRGB((int)(60.0f + 30.0f * hoverAmount), (int)(60.0f + 30.0f * hoverAmount), (int)(60.0f + 30.0f * hoverAmount)), alpha)); + String selectedLabel = this.setting.getValue().get(0); if (this.setting.getValue().size() > 1) { - string = string + ELLIPSIS; + selectedLabel = selectedLabel + ELLIPSIS; this.hasMultipleSelected = true; } - FontStore.AXIFORMA_BOLD_13.drawStringCentered(poseStack, string, this.x + 60.0f, f5 + (f7 - FontStore.AXIFORMA_BOLD_13.getFontHeight()) / 2.0f, ColorUtil.withAlpha(-1, f * 0.8f)); - Object object = String.valueOf('\ueb5d'); - FontStore.MATERIAL_20.drawString(poseStack, (String)object, this.x + 6.0f + f6 - FontStore.MATERIAL_20.getStringWidth((String)object) - 2.0f, f5 + (f7 - FontStore.MATERIAL_20.getFontHeight()) / 2.0f + 0.5f, ColorUtil.withAlpha(-1, f * 0.8f)); + FontStore.AXIFORMA_BOLD_13.drawStringCentered(poseStack, selectedLabel, this.x + 60.0f, dropdownY + (itemHeight - FontStore.AXIFORMA_BOLD_13.getFontHeight()) / 2.0f, ColorUtil.withAlpha(-1, alpha * 0.8f)); + Object arrowIcon = String.valueOf(''); + FontStore.MATERIAL_20.drawString(poseStack, (String)arrowIcon, this.x + 6.0f + dropdownWidth - FontStore.MATERIAL_20.getStringWidth((String)arrowIcon) - 2.0f, dropdownY + (itemHeight - FontStore.MATERIAL_20.getFontHeight()) / 2.0f + 0.5f, ColorUtil.withAlpha(-1, alpha * 0.8f)); if (this.isDropdownHovered && this.hasMultipleSelected) { this.parentPanel.setHoveredSettingElement(this); this.parentPanel.setTooltipText(this.setting.getValue().toString()); @@ -123,24 +123,24 @@ extends SettingElement { } @Override - public boolean mouseClicked(double d, double d2, int n) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { if (this.isDropdownHovered) { this.isOpen = !this.isOpen; return true; } if (this.hoveredOption != null && this.isOpen) { - ArrayList arrayList = new ArrayList<>(this.setting.getValue()); - if (arrayList.contains(this.hoveredOption)) { - if (arrayList.size() > 1) { - arrayList.remove(this.hoveredOption); + ArrayList selected = new ArrayList<>(this.setting.getValue()); + if (selected.contains(this.hoveredOption)) { + if (selected.size() > 1) { + selected.remove(this.hoveredOption); } } else { - arrayList.add(this.hoveredOption); + selected.add(this.hoveredOption); } - this.setting.setValue(arrayList); + this.setting.setValue(selected); return true; } return false; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/newclickgui/NumberSettingElement.java b/src/main/java/shit/zen/gui/newclickgui/NumberSettingElement.java index 2b8e1b2..4be2670 100644 --- a/src/main/java/shit/zen/gui/newclickgui/NumberSettingElement.java +++ b/src/main/java/shit/zen/gui/newclickgui/NumberSettingElement.java @@ -33,48 +33,48 @@ extends SettingElement { } @Override - public void render(NewClickGui newClickGui, GuiGraphics guiGraphics, PoseStack poseStack, int n, int n2, float f, float f2) { - float f3; - this.isHovered = CursorUtil.isInBounds(n, n2, this.x, this.y, 120.0f, this.getHeight()); - float f4 = 108.0f; - float f5 = 5.0f; - float f6 = this.y + this.getHeight() / 2.0f + (this.getHeight() / 2.0f - f5) / 2.0f; + public void render(NewClickGui clickGui, GuiGraphics guiGraphics, PoseStack poseStack, int mouseX, int mouseY, float alpha, float partialTicks) { + float dragRatio; + this.isHovered = CursorUtil.isInBounds(mouseX, mouseY, this.x, this.y, 120.0f, this.getHeight()); + float sliderWidth = 108.0f; + float sliderHeight = 5.0f; + float sliderY = this.y + this.getHeight() / 2.0f + (this.getHeight() / 2.0f - sliderHeight) / 2.0f; this.visibilityTimer.animate(this.setting.getVisibility().displayable() ? 1.0 : 0.0, 0.2, Easings.EASE_OUT_POW2); this.visibilityTimer.tick(); - if (Mth.equal(f *= this.visibilityTimer.getValueF(), 0.0f)) { + if (Mth.equal(alpha *= this.visibilityTimer.getValueF(), 0.0f)) { return; } - float f7 = this.y + (this.getHeight() / 2.0f - FontStore.AXIFORMA_REGULAR_14.getFontHeight()) / 2.0f + 1.0f; - String string = this.setting.getName(); - if (FontStore.AXIFORMA_REGULAR_14.getStringWidth(string) > 78.0f) { - string = string.substring(0, 10); - string = string + "..."; + float nameY = this.y + (this.getHeight() / 2.0f - FontStore.AXIFORMA_REGULAR_14.getFontHeight()) / 2.0f + 1.0f; + String name = this.setting.getName(); + if (FontStore.AXIFORMA_REGULAR_14.getStringWidth(name) > 78.0f) { + name = name.substring(0, 10); + name = name + "..."; this.isTruncated = true; } - FontStore.AXIFORMA_REGULAR_14.drawString(poseStack, string, this.x + 6.0f, f7, ColorUtil.withAlpha(-1, f * 0.8f)); - String string2 = String.format("%.2f", new Object[]{Float.valueOf(this.setting.getValue().floatValue())}); - FontStore.AXIFORMA_BOLD_13.drawString(poseStack, string2, this.x + 120.0f - FontStore.AXIFORMA_BOLD_13.getStringWidth(string2) - 6.0f, f7, ColorUtil.withAlpha(-1, f * 0.92f)); - float f8 = this.setting.getValue().floatValue() / this.setting.getMax().floatValue(); - f8 = Mth.clamp(f8, 0.0f, 1.0f); - this.sliderTimer.animate(f8, 0.2, Easings.EASE_OUT_POW2); + FontStore.AXIFORMA_REGULAR_14.drawString(poseStack, name, this.x + 6.0f, nameY, ColorUtil.withAlpha(-1, alpha * 0.8f)); + String valueText = String.format("%.2f", new Object[]{Float.valueOf(this.setting.getValue().floatValue())}); + FontStore.AXIFORMA_BOLD_13.drawString(poseStack, valueText, this.x + 120.0f - FontStore.AXIFORMA_BOLD_13.getStringWidth(valueText) - 6.0f, nameY, ColorUtil.withAlpha(-1, alpha * 0.92f)); + float progress = this.setting.getValue().floatValue() / this.setting.getMax().floatValue(); + progress = Mth.clamp(progress, 0.0f, 1.0f); + this.sliderTimer.animate(progress, 0.2, Easings.EASE_OUT_POW2); this.sliderTimer.tick(); if (this.isDragging) { NumberSetting numberSetting = this.setting; - f3 = ((float)n - (this.x + 6.0f)) / f4; - double d = numberSetting.getMin().floatValue() + (numberSetting.getMax().floatValue() - numberSetting.getMin().floatValue()) * f3; - double d2 = numberSetting.getStep().floatValue(); - double d3 = (double)Math.round(MathUtil.clamp(d, numberSetting.getMin().floatValue(), numberSetting.getMax().floatValue()) / d2) * d2; - numberSetting.setValue((double)Math.round(d3 * 1000.0) / 1000.0); + dragRatio = ((float)mouseX - (this.x + 6.0f)) / sliderWidth; + double rawValue = numberSetting.getMin().floatValue() + (numberSetting.getMax().floatValue() - numberSetting.getMin().floatValue()) * dragRatio; + double step = numberSetting.getStep().floatValue(); + double stepped = (double)Math.round(MathUtil.clamp(rawValue, numberSetting.getMin().floatValue(), numberSetting.getMax().floatValue()) / step) * step; + numberSetting.setValue((double)Math.round(stepped * 1000.0) / 1000.0); } - RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, f6, f4, 5.0f, 2.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(60, 60, 60), f)); - float f9 = this.sliderTimer.getValueF(); - f3 = 10.0f; - float f10 = 5.0f + f3 * 2.0f; - RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f - f3, f6 - f3, Math.max(f4 * f9 + f3 * 2.0f, f10), f10, 2.0f + f3 / 2.0f + 1.0f, f3, ColorUtil.withAlpha(-13768502, 0.26f * f)); - RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, f6, f4 * f9, 5.0f, 2.0f, ColorUtil.withAlpha(CategoryPanel.ACCENT_COLOR, f)); - float f11 = Math.max(this.x + 6.0f + this.sliderTimer.getValueF() * f4 - 5.0f - 0.5f, this.x + 6.0f - 0.5f); - RenderUtil.drawRoundedRect(poseStack, f11 - f3, f6 - 0.5f - f3, 6.0f + f3 * 2.0f, 6.0f + f3 * 2.0f, 2.0f + f3 / 2.0f + 1.0f, f3, ColorUtil.withAlpha(-1, 0.36f * f)); - RenderUtil.drawRoundedRect(poseStack, f11, f6 - 0.5f, 6.0f, 6.0f, 2.9f, ColorUtil.withAlpha(-1, f)); + RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, sliderY, sliderWidth, 5.0f, 2.0f, ColorUtil.withAlpha(ColorUtil.fromRGB(60, 60, 60), alpha)); + float fillAmount = this.sliderTimer.getValueF(); + dragRatio = 10.0f; + float glowSize = 5.0f + dragRatio * 2.0f; + RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f - dragRatio, sliderY - dragRatio, Math.max(sliderWidth * fillAmount + dragRatio * 2.0f, glowSize), glowSize, 2.0f + dragRatio / 2.0f + 1.0f, dragRatio, ColorUtil.withAlpha(-13768502, 0.26f * alpha)); + RenderUtil.drawRoundedRect(poseStack, this.x + 6.0f, sliderY, sliderWidth * fillAmount, 5.0f, 2.0f, ColorUtil.withAlpha(CategoryPanel.ACCENT_COLOR, alpha)); + float knobX = Math.max(this.x + 6.0f + this.sliderTimer.getValueF() * sliderWidth - 5.0f - 0.5f, this.x + 6.0f - 0.5f); + RenderUtil.drawRoundedRect(poseStack, knobX - dragRatio, sliderY - 0.5f - dragRatio, 6.0f + dragRatio * 2.0f, 6.0f + dragRatio * 2.0f, 2.0f + dragRatio / 2.0f + 1.0f, dragRatio, ColorUtil.withAlpha(-1, 0.36f * alpha)); + RenderUtil.drawRoundedRect(poseStack, knobX, sliderY - 0.5f, 6.0f, 6.0f, 2.9f, ColorUtil.withAlpha(-1, alpha)); if (this.isHovered && this.isTruncated) { this.parentPanel.setHoveredSettingElement(this); this.parentPanel.setTooltipText(this.setting.getName()); @@ -86,14 +86,14 @@ extends SettingElement { } @Override - public boolean mouseClicked(double d, double d2, int n) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { if (!this.setting.getVisibility().displayable()) { return false; } - float f = 108.0f; - float f2 = 5.0f; - float f3 = this.y + this.getHeight() / 2.0f + (this.getHeight() / 2.0f - f2) / 2.0f; - if (this.isHovered && CursorUtil.isInBounds((float)d, (float)d2, this.x + 6.0f, f3, f, 5.0f)) { + float sliderWidth = 108.0f; + float sliderHeight = 5.0f; + float sliderY = this.y + this.getHeight() / 2.0f + (this.getHeight() / 2.0f - sliderHeight) / 2.0f; + if (this.isHovered && CursorUtil.isInBounds((float)mouseX, (float)mouseY, this.x + 6.0f, sliderY, sliderWidth, 5.0f)) { this.isDragging = true; return true; } @@ -101,10 +101,10 @@ extends SettingElement { } @Override - public boolean mouseReleased(double d, double d2, int n) { - float f = 108.0f; - float f2 = 5.0f; - float f3 = this.y + this.getHeight() / 2.0f + (this.getHeight() / 2.0f - f2) / 2.0f; + public boolean mouseReleased(double mouseX, double mouseY, int button) { + float sliderWidth = 108.0f; + float sliderHeight = 5.0f; + float sliderY = this.y + this.getHeight() / 2.0f + (this.getHeight() / 2.0f - sliderHeight) / 2.0f; this.isDragging = false; return false; } diff --git a/src/main/java/shit/zen/gui/newclickgui/SettingElement.java b/src/main/java/shit/zen/gui/newclickgui/SettingElement.java index 6bd6491..b17d509 100644 --- a/src/main/java/shit/zen/gui/newclickgui/SettingElement.java +++ b/src/main/java/shit/zen/gui/newclickgui/SettingElement.java @@ -17,8 +17,8 @@ extends UIElement { protected final SmoothAnimationTimer visibilityTimer = new SmoothAnimationTimer(); @Generated - public SettingElement(CategoryPanel categoryPanel, T t) { + public SettingElement(CategoryPanel categoryPanel, T setting) { this.parentPanel = categoryPanel; - this.setting = t; + this.setting = setting; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/gui/newclickgui/UIElement.java b/src/main/java/shit/zen/gui/newclickgui/UIElement.java index 2f383bb..8bebd34 100644 --- a/src/main/java/shit/zen/gui/newclickgui/UIElement.java +++ b/src/main/java/shit/zen/gui/newclickgui/UIElement.java @@ -19,20 +19,20 @@ public abstract class UIElement { @Getter protected final SmoothAnimationTimer animTimer = new SmoothAnimationTimer(); - public abstract void render(NewClickGui var1, GuiGraphics var2, PoseStack var3, int var4, int var5, float var6, float var7); + public abstract void render(NewClickGui clickGui, GuiGraphics guiGraphics, PoseStack poseStack, int mouseX, int mouseY, float alpha, float partialTicks); public void reset() { } - public boolean mouseClicked(double d, double d2, int n) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { return false; } - public boolean mouseReleased(double d, double d2, int n) { + public boolean mouseReleased(double mouseX, double mouseY, int button) { return false; } - public boolean mouseScrolled(double d, double d2, double d3) { + public boolean mouseScrolled(double mouseX, double mouseY, double scrollDelta) { return false; } @@ -40,4 +40,4 @@ public abstract class UIElement { return this.getHeight(); } - } \ No newline at end of file + } diff --git a/src/main/java/shit/zen/gui/panel/CategoryBar.java b/src/main/java/shit/zen/gui/panel/CategoryBar.java index e948e00..5bb74c7 100644 --- a/src/main/java/shit/zen/gui/panel/CategoryBar.java +++ b/src/main/java/shit/zen/gui/panel/CategoryBar.java @@ -21,32 +21,32 @@ extends ClientBase { private final Map hoverAnimations = new HashMap<>(); private Category selectedCategory = Category.COMBAT; - public void render(GuiGraphics guiGraphics, int n, int n2, int n3, int n4, float f, float f2) { + public void render(GuiGraphics guiGraphics, int originX, int originY, int mouseX, int mouseY, float scale, float alpha) { try { - int n5 = (int)(20.0f * f); - int n6 = (int)(25.0f * f); - int n7 = (int)(80.0f * f); - float f3 = 24.0f * f; - int n8 = (int)(420.0f * f); - int n9 = n + n8; - int n10 = n2 + n7 - (int)(65.0f * f); - Category[] categoryArray = Category.values(); + int iconSize = (int)(20.0f * scale); + int iconSpacing = (int)(25.0f * scale); + int verticalOffset = (int)(80.0f * scale); + float iconFontSize = 24.0f * scale; + int horizontalOffset = (int)(420.0f * scale); + int baseX = originX + horizontalOffset; + int baseY = originY + verticalOffset - (int)(65.0f * scale); + Category[] categories = Category.values(); Renderer.renderConsumer(drawContext -> { - FontRenderer iconFont = FontPresets.materialIcons(f3); - for (int i = 0; i < categoryArray.length; ++i) { - Category category = categoryArray[i]; + FontRenderer iconFont = FontPresets.materialIcons(iconFontSize); + for (int i = 0; i < categories.length; ++i) { + Category category = categories[i]; String iconString = CATEGORY_ICONS.get(category); if (iconString == null) continue; - int iconX = n9 + i * n6; - int iconY = n10; - this.updateCategoryHover(category, iconX, iconY, n3, n4, n5); + int iconX = baseX + i * iconSpacing; + int iconY = baseY; + this.updateCategoryHover(category, iconX, iconY, mouseX, mouseY, iconSize); int categoryColor = this.getCategoryColor(category); if (category == this.selectedCategory) { - int glowColor = new Color(255, 255, 255, (int)(150.0f * f2)).getRGB(); - TextGlow.drawGlowText(iconString, iconX, iconY, iconFont, this.applyAlpha(categoryColor, f2), glowColor, 8.0f * f); + int glowColor = new Color(255, 255, 255, (int)(150.0f * alpha)).getRGB(); + TextGlow.drawGlowText(iconString, iconX, iconY, iconFont, this.applyAlpha(categoryColor, alpha), glowColor, 8.0f * scale); continue; } - GlHelper.drawText(iconString, iconX, iconY, iconFont, this.applyAlpha(categoryColor, f2)); + GlHelper.drawText(iconString, iconX, iconY, iconFont, this.applyAlpha(categoryColor, alpha)); } }); } catch (Exception exception) { @@ -54,61 +54,61 @@ extends ClientBase { } } - private int applyAlpha(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = (int)((float)n2 * f); - return n3 << 24 | n & 0xFFFFFF; + private int applyAlpha(int color, float alpha) { + int origAlpha = color >> 24 & 0xFF; + int newAlpha = (int)((float)origAlpha * alpha); + return newAlpha << 24 | color & 0xFFFFFF; } - private void updateCategoryHover(Category category, int n, int n2, int n3, int n4, int n5) { - float f = this.hoverAnimations.getOrDefault(category, Float.valueOf(0.0f)).floatValue(); - boolean bl = this.isMouseOverCategory(n, n2, n3, n4, n5); - this.hoverAnimations.put(category, Float.valueOf(LerpUtil.lerp(f, bl ? 1.0f : 0.0f, 0.12f))); + private void updateCategoryHover(Category category, int iconX, int iconY, int mouseX, int mouseY, int iconSize) { + float current = this.hoverAnimations.getOrDefault(category, Float.valueOf(0.0f)).floatValue(); + boolean hovered = this.isMouseOverCategory(iconX, iconY, mouseX, mouseY, iconSize); + this.hoverAnimations.put(category, Float.valueOf(LerpUtil.lerp(current, hovered ? 1.0f : 0.0f, 0.12f))); } private int getCategoryColor(Category category) { if (category == this.selectedCategory) { return -1; } - float f = this.hoverAnimations.getOrDefault(category, Float.valueOf(0.0f)).floatValue(); - return this.lerpColor(-7829368, -3355444, f); + float hoverAmount = this.hoverAnimations.getOrDefault(category, Float.valueOf(0.0f)).floatValue(); + return this.lerpColor(-7829368, -3355444, hoverAmount); } - private int lerpColor(int n, int n2, float f) { - float f2 = 1.0f - f; - int n3 = n >> 24 & 0xFF; - int n4 = n >> 16 & 0xFF; - int n5 = n >> 8 & 0xFF; - int n6 = n & 0xFF; - int n7 = n2 >> 24 & 0xFF; - int n8 = n2 >> 16 & 0xFF; - int n9 = n2 >> 8 & 0xFF; - int n10 = n2 & 0xFF; - int n11 = (int)((float)n3 * f2 + (float)n7 * f); - int n12 = (int)((float)n4 * f2 + (float)n8 * f); - int n13 = (int)((float)n5 * f2 + (float)n9 * f); - int n14 = (int)((float)n6 * f2 + (float)n10 * f); - return n11 << 24 | n12 << 16 | n13 << 8 | n14; + private int lerpColor(int fromColor, int toColor, float t) { + float inv = 1.0f - t; + int aFrom = fromColor >> 24 & 0xFF; + int rFrom = fromColor >> 16 & 0xFF; + int gFrom = fromColor >> 8 & 0xFF; + int bFrom = fromColor & 0xFF; + int aTo = toColor >> 24 & 0xFF; + int rTo = toColor >> 16 & 0xFF; + int gTo = toColor >> 8 & 0xFF; + int bTo = toColor & 0xFF; + int a = (int)((float)aFrom * inv + (float)aTo * t); + int r = (int)((float)rFrom * inv + (float)rTo * t); + int g = (int)((float)gFrom * inv + (float)gTo * t); + int b = (int)((float)bFrom * inv + (float)bTo * t); + return a << 24 | r << 16 | g << 8 | b; } - private boolean isMouseOverCategory(int n, int n2, int n3, int n4, int n5) { - int n6 = n5 / 2; - return n3 >= n && n3 <= n + n5 && n4 >= n2 - n6 && n4 <= n2 + n6; + private boolean isMouseOverCategory(int iconX, int iconY, int mouseX, int mouseY, int iconSize) { + int halfSize = iconSize / 2; + return mouseX >= iconX && mouseX <= iconX + iconSize && mouseY >= iconY - halfSize && mouseY <= iconY + halfSize; } - public boolean onMouseClick(int n, int n2, int n3, int n4, float f) { - int n5 = (int)(20.0f * f); - int n6 = (int)(25.0f * f); - int n7 = (int)(80.0f * f); - int n8 = (int)(420.0f * f); - int n9 = n + n8; - int n10 = n2 + n7 - (int)(65.0f * f); - Category[] categoryArray = Category.values(); - for (int i = 0; i < categoryArray.length; ++i) { - Category category = categoryArray[i]; - int n11 = n9 + i * n6; - int n12 = n10; - if (!this.isMouseOverCategory(n11, n12, n3, n4, n5)) continue; + public boolean onMouseClick(int originX, int originY, int mouseX, int mouseY, float scale) { + int iconSize = (int)(20.0f * scale); + int iconSpacing = (int)(25.0f * scale); + int verticalOffset = (int)(80.0f * scale); + int horizontalOffset = (int)(420.0f * scale); + int baseX = originX + horizontalOffset; + int baseY = originY + verticalOffset - (int)(65.0f * scale); + Category[] categories = Category.values(); + for (int i = 0; i < categories.length; ++i) { + Category category = categories[i]; + int iconX = baseX + i * iconSpacing; + int iconY = baseY; + if (!this.isMouseOverCategory(iconX, iconY, mouseX, mouseY, iconSize)) continue; this.selectedCategory = category; return true; } @@ -123,40 +123,40 @@ extends ClientBase { this.selectedCategory = category; } - public boolean isMouseOverAnyCategory(int n, int n2, int n3, int n4, float f) { - int n5 = (int)(20.0f * f); - int n6 = (int)(25.0f * f); - int n7 = (int)(80.0f * f); - int n8 = (int)(420.0f * f); - int n9 = n + n8; - int n10 = n2 + n7 - (int)(65.0f * f); - Category[] categoryArray = Category.values(); - for (int i = 0; i < categoryArray.length; ++i) { - int n11 = n9 + i * n6; - int n12 = n10; - if (!this.isMouseOverCategory(n11, n12, n3, n4, n5)) continue; + public boolean isMouseOverAnyCategory(int originX, int originY, int mouseX, int mouseY, float scale) { + int iconSize = (int)(20.0f * scale); + int iconSpacing = (int)(25.0f * scale); + int verticalOffset = (int)(80.0f * scale); + int horizontalOffset = (int)(420.0f * scale); + int baseX = originX + horizontalOffset; + int baseY = originY + verticalOffset - (int)(65.0f * scale); + Category[] categories = Category.values(); + for (int i = 0; i < categories.length; ++i) { + int iconX = baseX + i * iconSpacing; + int iconY = baseY; + if (!this.isMouseOverCategory(iconX, iconY, mouseX, mouseY, iconSize)) continue; return true; } return false; } - public int getTotalWidth(float f) { - int n = (int)(20.0f * f); - int n2 = (int)(25.0f * f); - return (Category.values().length - 1) * n2 + n; + public int getTotalWidth(float scale) { + int iconSize = (int)(20.0f * scale); + int iconSpacing = (int)(25.0f * scale); + return (Category.values().length - 1) * iconSpacing + iconSize; } - public int getCategoryHeight(float f) { - return (int)(20.0f * f); + public int getCategoryHeight(float scale) { + return (int)(20.0f * scale); } static { - CATEGORY_ICONS.put(Category.COMBAT, ""); - CATEGORY_ICONS.put(Category.MOVEMENT, ""); - CATEGORY_ICONS.put(Category.PLAYER, ""); - CATEGORY_ICONS.put(Category.RENDER, ""); - CATEGORY_ICONS.put(Category.EXPLOIT, ""); - CATEGORY_ICONS.put(Category.WORLD, ""); - CATEGORY_ICONS.put(Category.MISC, ""); + CATEGORY_ICONS.put(Category.COMBAT, ""); + CATEGORY_ICONS.put(Category.MOVEMENT, ""); + CATEGORY_ICONS.put(Category.PLAYER, ""); + CATEGORY_ICONS.put(Category.RENDER, ""); + CATEGORY_ICONS.put(Category.EXPLOIT, ""); + CATEGORY_ICONS.put(Category.WORLD, ""); + CATEGORY_ICONS.put(Category.MISC, ""); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/KeybindOverlay.java b/src/main/java/shit/zen/gui/panel/KeybindOverlay.java index f4fbc8a..c720fc3 100644 --- a/src/main/java/shit/zen/gui/panel/KeybindOverlay.java +++ b/src/main/java/shit/zen/gui/panel/KeybindOverlay.java @@ -39,7 +39,7 @@ extends ClientBase { return this.isActive && this.alpha > 0.01f; } - public void render(GuiGraphics guiGraphics, int n, int n2, float f) { + public void render(GuiGraphics guiGraphics, int screenWidth, int screenHeight, float scale) { if (!this.isActive && this.alpha <= 0.005f) { return; } @@ -48,23 +48,23 @@ extends ClientBase { return; } try { - this.drawBackground(guiGraphics, n, n2); - float f2 = 400.0f * f; - float f3 = 180.0f * f; - int n3 = (int)(((float)n - f2) / 2.0f); - int n4 = (int)(((float)n2 - f3) / 2.0f); - this.drawGlow(guiGraphics, n3, n4, f2, f3, f); - this.drawContent(guiGraphics, n3, n4, f2, f); + this.drawBackground(guiGraphics, screenWidth, screenHeight); + float boxWidth = 400.0f * scale; + float boxHeight = 180.0f * scale; + int boxX = (int)(((float)screenWidth - boxWidth) / 2.0f); + int boxY = (int)(((float)screenHeight - boxHeight) / 2.0f); + this.drawGlow(guiGraphics, boxX, boxY, boxWidth, boxHeight, scale); + this.drawContent(guiGraphics, boxX, boxY, boxWidth, scale); } catch (Exception exception) { // empty catch block } } - public boolean onKeyPress(int n, int n2, int n3) { + public boolean onKeyPress(int keyCode, int scanCode, int modifiers) { if (!this.isVisible()) { return false; } - if (n == 256) { + if (keyCode == 256) { if (this.targetModule != null) { this.targetModule.setKey(-1); if (ZenClient.isReady()) { @@ -75,14 +75,14 @@ extends ClientBase { this.cancel(); return true; } - if (this.targetModule != null && n != -1) { - this.targetModule.setKey(n); + if (this.targetModule != null && keyCode != -1) { + this.targetModule.setKey(keyCode); if (ZenClient.isReady()) { ZenClient.instance.getConfigManager().saveAll(); } - KeyBind keyBind = new KeyBind(n); - String string = keyBind.getName(); - PanelClickGui.panelClickGui.addToast(this.targetModule.getName() + " bound to " + string.toUpperCase()); + KeyBind keyBind = new KeyBind(keyCode); + String keyName = keyBind.getName(); + PanelClickGui.panelClickGui.addToast(this.targetModule.getName() + " bound to " + keyName.toUpperCase()); this.cancel(); return true; } @@ -96,82 +96,82 @@ extends ClientBase { private void onRenderExtra() { } - private void drawBackground(GuiGraphics guiGraphics, int n, int n2) { + private void drawBackground(GuiGraphics guiGraphics, int screenWidth, int screenHeight) { Color color = new Color(OVERLAY_BG_COLOR.getRed(), OVERLAY_BG_COLOR.getGreen(), OVERLAY_BG_COLOR.getBlue(), (int)((float)OVERLAY_BG_COLOR.getAlpha() * this.alpha)); - RenderUtil.drawRoundedRect(guiGraphics.pose(), 0.0f, 0.0f, n, n2, 0.0f, color.getRGB()); + RenderUtil.drawRoundedRect(guiGraphics.pose(), 0.0f, 0.0f, screenWidth, screenHeight, 0.0f, color.getRGB()); } - private void drawGlow(GuiGraphics guiGraphics, int n, int n2, float f, float f2, float f3) { - TextGlow.drawBackground(guiGraphics.pose(), n, n2, f, f2, 12.0f * f3, this.alpha); + private void drawGlow(GuiGraphics guiGraphics, int boxX, int boxY, float boxWidth, float boxHeight, float scale) { + TextGlow.drawBackground(guiGraphics.pose(), boxX, boxY, boxWidth, boxHeight, 12.0f * scale, this.alpha); } - private void drawContent(GuiGraphics guiGraphics, int n, int n2, float f, float f2) { + private void drawContent(GuiGraphics guiGraphics, int boxX, int boxY, float boxWidth, float scale) { Renderer.renderConsumer((drawContext -> { - int n3; - float f3; - float f4; - float f5; - String string; - FontRenderer fontRenderer; - int n4 = (int)(255.0f * this.alpha); - FontRenderer fontRenderer2 = FontPresets.axiformaBold(24.0f * f2); - String string2 = "KEYBIND"; - float f6 = GlHelper.getStringWidth(string2, fontRenderer2); - float f7 = (float)n + (f - f6) / 2.0f; - float f8 = (float)n2 + 45.0f * f2; - int n5 = n4 << 24 | 0xFFFFFF; - int n6 = n4 << 24 | 0xFFFFFF; - TextGlow.drawGlowText(string2, f7, f8, fontRenderer2, n5, n6, 10.0f * f2); + int textColor; + float textY; + float textX; + float textWidth; + String text; + FontRenderer textFont; + int alphaByte = (int)(255.0f * this.alpha); + FontRenderer titleFont = FontPresets.axiformaBold(24.0f * scale); + String title = "KEYBIND"; + float titleWidth = GlHelper.getStringWidth(title, titleFont); + float titleX = (float)boxX + (boxWidth - titleWidth) / 2.0f; + float titleY = (float)boxY + 45.0f * scale; + int titleColor = alphaByte << 24 | 0xFFFFFF; + int glowColor = alphaByte << 24 | 0xFFFFFF; + TextGlow.drawGlowText(title, titleX, titleY, titleFont, titleColor, glowColor, 10.0f * scale); if (this.targetModule != null) { - fontRenderer = FontPresets.axiformaRegular(18.0f * f2); - string = "Module: " + this.targetModule.getName(); - f5 = GlHelper.getStringWidth(string, fontRenderer); - f4 = (float)n + (f - f5) / 2.0f; - f3 = (float)n2 + 75.0f * f2; - n3 = n4 << 24 | 0xFFFFFF; - GlHelper.drawText(string, f4, f3, fontRenderer, n3); + textFont = FontPresets.axiformaRegular(18.0f * scale); + text = "Module: " + this.targetModule.getName(); + textWidth = GlHelper.getStringWidth(text, textFont); + textX = (float)boxX + (boxWidth - textWidth) / 2.0f; + textY = (float)boxY + 75.0f * scale; + textColor = alphaByte << 24 | 0xFFFFFF; + GlHelper.drawText(text, textX, textY, textFont, textColor); } - fontRenderer = FontPresets.axiformaRegular(16.0f * f2); - string = "Press any key to bind"; - f5 = GlHelper.getStringWidth(string, fontRenderer); - f4 = (float)n + (f - f5) / 2.0f; - f3 = (float)n2 + 105.0f * f2; - n3 = n4 << 24 | 0xCCCCCC; - GlHelper.drawText(string, f4, f3, fontRenderer, n3); - this.drawAnimatedDots(n, (int)((float)n2 + 125.0f * f2), (int)f, n4, f2); - FontRenderer fontRenderer3 = FontPresets.axiformaRegular(14.0f * f2); - String string3 = "Press ESC to cancel"; - float f9 = GlHelper.getStringWidth(string3, fontRenderer3); - float f10 = (float)n + (f - f9) / 2.0f; - float f11 = (float)n2 + 155.0f * f2; - int n7 = n4 << 24 | 0xCCCCCC; - GlHelper.drawText(string3, f10, f11, fontRenderer3, n7); + textFont = FontPresets.axiformaRegular(16.0f * scale); + text = "Press any key to bind"; + textWidth = GlHelper.getStringWidth(text, textFont); + textX = (float)boxX + (boxWidth - textWidth) / 2.0f; + textY = (float)boxY + 105.0f * scale; + textColor = alphaByte << 24 | 0xCCCCCC; + GlHelper.drawText(text, textX, textY, textFont, textColor); + this.drawAnimatedDots(boxX, (int)((float)boxY + 125.0f * scale), (int)boxWidth, alphaByte, scale); + FontRenderer cancelFont = FontPresets.axiformaRegular(14.0f * scale); + String cancelText = "Press ESC to cancel"; + float cancelWidth = GlHelper.getStringWidth(cancelText, cancelFont); + float cancelX = (float)boxX + (boxWidth - cancelWidth) / 2.0f; + float cancelY = (float)boxY + 155.0f * scale; + int cancelColor = alphaByte << 24 | 0xCCCCCC; + GlHelper.drawText(cancelText, cancelX, cancelY, cancelFont, cancelColor); })); } - private void drawAnimatedDots(int n, int n2, int n3, int n4, float f) { - FontRenderer fontRenderer = FontPresets.axiformaBold(20.0f * f); - String string = "•"; - float f2 = GlHelper.getStringWidth(string, fontRenderer); - float f3 = f2 * 3.0f + 20.0f * f; - float f4 = (float)n + ((float)n3 - f3) / 2.0f; - int n5 = n4 << 24 | 0xFFFFFF; - long l = System.currentTimeMillis(); - long l2 = l - this.startTime; - long l3 = l2 % 1400L; + private void drawAnimatedDots(int boxX, int dotsY, int boxWidth, int alphaByte, float scale) { + FontRenderer dotFont = FontPresets.axiformaBold(20.0f * scale); + String dot = "•"; + float dotWidth = GlHelper.getStringWidth(dot, dotFont); + float totalWidth = dotWidth * 3.0f + 20.0f * scale; + float startX = (float)boxX + ((float)boxWidth - totalWidth) / 2.0f; + int dotColor = alphaByte << 24 | 0xFFFFFF; + long now = System.currentTimeMillis(); + long elapsed = now - this.startTime; + long cycleTime = elapsed % 1400L; for (int i = 0; i < 3; ++i) { - float f5; - float f6 = f4 + (float)i * (f2 + 10.0f * f); - long l4 = (long)i * 150L; - long l5 = l4 + 300L; - float f7 = 0.0f; - if (l3 >= l4 && l3 <= l5) { - f5 = (float)(l3 - l4) / 300.0f; - float f8 = f5 * (float)Math.PI; - f7 = (float)(Math.sin(f8) * 6.0 * (double)f); + float drawY; + float dotX = startX + (float)i * (dotWidth + 10.0f * scale); + long dotStart = (long)i * 150L; + long dotEnd = dotStart + 300L; + float verticalOffset = 0.0f; + if (cycleTime >= dotStart && cycleTime <= dotEnd) { + drawY = (float)(cycleTime - dotStart) / 300.0f; + float angle = drawY * (float)Math.PI; + verticalOffset = (float)(Math.sin(angle) * 6.0 * (double)scale); } - f5 = (float)n2 - f7; - GlHelper.drawText(string, f6, f5, fontRenderer, n5); + drawY = (float)dotsY - verticalOffset; + GlHelper.drawText(dot, dotX, drawY, dotFont, dotColor); } } @@ -182,4 +182,4 @@ extends ClientBase { static { new Color(255, 255, 255, 40); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/ModuleListPanel.java b/src/main/java/shit/zen/gui/panel/ModuleListPanel.java index 4400e5a..9395a9d 100644 --- a/src/main/java/shit/zen/gui/panel/ModuleListPanel.java +++ b/src/main/java/shit/zen/gui/panel/ModuleListPanel.java @@ -47,28 +47,28 @@ extends ClientBase { private String searchQuery = ""; private List searchResults; - public void setSearchQuery(String string) { - if (string == null) { + public void setSearchQuery(String query) { + if (query == null) { this.searchQuery = ""; this.searchResults = null; return; } - this.searchQuery = string; - this.searchResults = !string.isEmpty() ? ZenClient.instance.getModuleManager().getModules().stream().filter(module -> module.getName().toLowerCase().contains(string.toLowerCase())).sorted(Comparator.comparing(Module::getName)).collect(Collectors.toList()) : ZenClient.instance.getModuleManager().getModules().stream().sorted(Comparator.comparing(Module::getName)).collect(Collectors.toList()); + this.searchQuery = query; + this.searchResults = !query.isEmpty() ? ZenClient.instance.getModuleManager().getModules().stream().filter(module -> module.getName().toLowerCase().contains(query.toLowerCase())).sorted(Comparator.comparing(Module::getName)).collect(Collectors.toList()) : ZenClient.instance.getModuleManager().getModules().stream().sorted(Comparator.comparing(Module::getName)).collect(Collectors.toList()); this.currentCategory = null; this.scrollOffset = 0.0f; this.scrollTarget = 0.0f; this.animationState = ModuleListPanel.AnimationState.NONE; } - public void render(GuiGraphics guiGraphics, int n, int n2, int n3, int n4, Category category, float f, float f2) { - if (Math.abs(f - this.lastScale) > 0.001f) { - this.rescaleScroll(f); - this.lastScale = f; + public void render(GuiGraphics guiGraphics, int originX, int originY, int mouseX, int mouseY, Category category, float scale, float alpha) { + if (Math.abs(scale - this.lastScale) > 0.001f) { + this.rescaleScroll(scale); + this.lastScale = scale; } this.scrollOffset = Math.abs(this.scrollOffset - this.scrollTarget) > 0.01f ? LerpUtil.smoothLerp(this.scrollOffset, this.scrollTarget, 0.35f) : this.scrollTarget; if (this.searchResults != null) { - this.renderSearchResults(guiGraphics, n, n2, n3, n4, f, f2); + this.renderSearchResults(guiGraphics, originX, originY, mouseX, mouseY, scale, alpha); return; } if (this.currentCategory != category) { @@ -84,7 +84,7 @@ extends ClientBase { this.animProgress = 0.0f; } this.currentCategory = category; - List list = this.currentModules = category == null ? null : ZenClient.instance.getModuleManager().getModules().stream().filter(module -> module.getCategory() == category).sorted(Comparator.comparing(Module::getName)).collect(Collectors.toList()); + List filtered = this.currentModules = category == null ? null : ZenClient.instance.getModuleManager().getModules().stream().filter(module -> module.getCategory() == category).sorted(Comparator.comparing(Module::getName)).collect(Collectors.toList()); } if (this.animationState != ModuleListPanel.AnimationState.NONE) { this.animProgress = LerpUtil.smoothLerp(this.animProgress, 1.0f, 0.18f); @@ -105,191 +105,191 @@ extends ClientBase { } } try { - int n5 = (int)(160.0f * f); - int n6 = (int)(20.0f * f); - int n7 = (int)(20.0f * f); - int n8 = (int)(400.0f * f); - int n9 = n + n6 - (int)(8.0f * f); - int n10 = n2 + n7 + (int)(23.0f * f); - int n11 = n8 - 2 * n6 - (int)(20.0f * f); - RenderUtil.drawRoundedRect(guiGraphics.pose(), n9, n10, n5, n11, 4.0f * f, this.applyAlpha(HOVER_BG_COLOR, f2)); + int panelWidth = (int)(160.0f * scale); + int marginX = (int)(20.0f * scale); + int marginY = (int)(20.0f * scale); + int baseSize = (int)(400.0f * scale); + int panelX = originX + marginX - (int)(8.0f * scale); + int panelY = originY + marginY + (int)(23.0f * scale); + int panelHeight = baseSize - 2 * marginX - (int)(20.0f * scale); + RenderUtil.drawRoundedRect(guiGraphics.pose(), panelX, panelY, panelWidth, panelHeight, 4.0f * scale, this.applyAlpha(HOVER_BG_COLOR, alpha)); Renderer.renderConsumer(drawContext -> { Category renderCategory = this.currentCategory; List renderList = this.currentModules; float slideOffset = 0.0f; - float renderAlpha = f2; + float renderAlpha = alpha; if (this.animationState == ModuleListPanel.AnimationState.FADE_OUT) { renderCategory = this.prevCategory; renderList = this.prevModules; - slideOffset = this.animProgress * 20.0f * f; - renderAlpha = (1.0f - this.animProgress) * f2; + slideOffset = this.animProgress * 20.0f * scale; + renderAlpha = (1.0f - this.animProgress) * alpha; } else if (this.animationState == ModuleListPanel.AnimationState.FADE_IN) { renderCategory = this.currentCategory; renderList = this.currentModules; - slideOffset = (1.0f - this.animProgress) * 20.0f * f; - renderAlpha = this.animProgress * f2; + slideOffset = (1.0f - this.animProgress) * 20.0f * scale; + renderAlpha = this.animProgress * alpha; } drawContext.save(); - drawContext.clip(Rectangle.ofXYWH(n9, n10, n5, n11)); + drawContext.clip(Rectangle.ofXYWH(panelX, panelY, panelWidth, panelHeight)); if (renderCategory != null) { drawContext.save(); drawContext.translate(0.0f, slideOffset); - this.renderModuleList(renderCategory, renderList, n9, n10, n11, n3, n4, renderAlpha, this.animationState != ModuleListPanel.AnimationState.NONE, f); + this.renderModuleList(renderCategory, renderList, panelX, panelY, panelHeight, mouseX, mouseY, renderAlpha, this.animationState != ModuleListPanel.AnimationState.NONE, scale); drawContext.restore(); } drawContext.restore(); }); if (this.animationState == ModuleListPanel.AnimationState.NONE) { - this.renderScrollbar(guiGraphics, n9, n10, n11, f, f2); + this.renderScrollbar(guiGraphics, panelX, panelY, panelHeight, scale, alpha); } } catch (Exception exception) { // empty catch block } } - private void renderSearchResults(GuiGraphics guiGraphics, int n, int n2, int n3, int n4, float f, float f2) { + private void renderSearchResults(GuiGraphics guiGraphics, int originX, int originY, int mouseX, int mouseY, float scale, float alpha) { try { - int n5 = (int)(160.0f * f); - int n6 = (int)(20.0f * f); - int n7 = (int)(20.0f * f); - int n8 = (int)(400.0f * f); - int n9 = n + n6 - (int)(8.0f * f); - int n10 = n2 + n7 + (int)(23.0f * f); - int n11 = n8 - 2 * n6 - (int)(20.0f * f); - RenderUtil.drawRoundedRect(guiGraphics.pose(), n9, n10, n5, n11, 4.0f * f, this.applyAlpha(HOVER_BG_COLOR, f2)); - Renderer.renderConsumer((drawContext -> this.renderModuleList(null, this.searchResults, n9, n10, n11, n3, n4, f2, false, f))); - this.renderScrollbar(guiGraphics, n9, n10, n11, f, f2); + int panelWidth = (int)(160.0f * scale); + int marginX = (int)(20.0f * scale); + int marginY = (int)(20.0f * scale); + int baseSize = (int)(400.0f * scale); + int panelX = originX + marginX - (int)(8.0f * scale); + int panelY = originY + marginY + (int)(23.0f * scale); + int panelHeight = baseSize - 2 * marginX - (int)(20.0f * scale); + RenderUtil.drawRoundedRect(guiGraphics.pose(), panelX, panelY, panelWidth, panelHeight, 4.0f * scale, this.applyAlpha(HOVER_BG_COLOR, alpha)); + Renderer.renderConsumer((drawContext -> this.renderModuleList(null, this.searchResults, panelX, panelY, panelHeight, mouseX, mouseY, alpha, false, scale))); + this.renderScrollbar(guiGraphics, panelX, panelY, panelHeight, scale, alpha); } catch (Exception exception) { // empty catch block } } - private void renderScrollbar(GuiGraphics guiGraphics, int n, int n2, int n3, float f, float f2) { - float f3; - float f4 = 30.0f * f; - float f5 = (float)n3 - f4; - if (this.totalContentHeight <= f5) { - f3 = 0.0f; + private void renderScrollbar(GuiGraphics guiGraphics, int panelX, int panelY, int panelHeight, float scale, float alpha) { + float targetAlpha; + float headerHeight = 30.0f * scale; + float visibleHeight = (float)panelHeight - headerHeight; + if (this.totalContentHeight <= visibleHeight) { + targetAlpha = 0.0f; } else { - long l = System.currentTimeMillis() - this.lastScrollTime; - if (this.isDraggingScrollbar || l < 500L) { - f3 = 1.0f; - } else if (l < 1000L) { - long l2 = l - 500L; - f3 = 1.0f - (float)l2 / 500.0f; + long sinceScroll = System.currentTimeMillis() - this.lastScrollTime; + if (this.isDraggingScrollbar || sinceScroll < 500L) { + targetAlpha = 1.0f; + } else if (sinceScroll < 1000L) { + long fadeMs = sinceScroll - 500L; + targetAlpha = 1.0f - (float)fadeMs / 500.0f; } else { - f3 = 0.0f; + targetAlpha = 0.0f; } } - this.scrollbarAlpha = Math.abs(this.scrollbarAlpha - f3) > 0.01f ? LerpUtil.smoothLerp(this.scrollbarAlpha, f3, 0.35f) : f3; + this.scrollbarAlpha = Math.abs(this.scrollbarAlpha - targetAlpha) > 0.01f ? LerpUtil.smoothLerp(this.scrollbarAlpha, targetAlpha, 0.35f) : targetAlpha; if (this.scrollbarAlpha <= 0.01f) { return; } - float f6 = this.totalContentHeight - f5; - if (f6 <= 0.0f) { + float maxScroll = this.totalContentHeight - visibleHeight; + if (maxScroll <= 0.0f) { return; } - float f7 = Math.max(20.0f * f, f5 / this.totalContentHeight * f5); - float f8 = (float)n2 + f4 + this.scrollOffset / f6 * (f5 - f7); - int n4 = n + (int)(160.0f * f) - (int)(4.0f * f) - 2; - float f9 = 4.0f * f; - int n5 = new Color(1.0f, 1.0f, 1.0f, this.scrollbarAlpha * f2).getRGB(); - RenderUtil.drawRoundedRect(guiGraphics.pose(), n4, f8, f9, f7, f9 / 2.0f, n5); + float thumbHeight = Math.max(20.0f * scale, visibleHeight / this.totalContentHeight * visibleHeight); + float thumbY = (float)panelY + headerHeight + this.scrollOffset / maxScroll * (visibleHeight - thumbHeight); + int thumbX = panelX + (int)(160.0f * scale) - (int)(4.0f * scale) - 2; + float thumbWidth = 4.0f * scale; + int thumbColor = new Color(1.0f, 1.0f, 1.0f, this.scrollbarAlpha * alpha).getRGB(); + RenderUtil.drawRoundedRect(guiGraphics.pose(), thumbX, thumbY, thumbWidth, thumbHeight, thumbWidth / 2.0f, thumbColor); } - private void updateModuleHover(Module module, int n, int n2, int n3, int n4, float f) { + private void updateModuleHover(Module module, int rowX, int rowY, int mouseX, int mouseY, float scale) { if (module.isEnabled()) { this.hoverAnimations.put(module, Float.valueOf(0.0f)); return; } - float f2 = this.hoverAnimations.getOrDefault(module, Float.valueOf(0.0f)).floatValue(); - boolean bl = this.isMouseOverModule(module, n, n2, n3, n4, f); - this.hoverAnimations.put(module, Float.valueOf(LerpUtil.lerp(f2, bl ? 1.0f : 0.0f, 0.12f))); + float current = this.hoverAnimations.getOrDefault(module, Float.valueOf(0.0f)).floatValue(); + boolean hovered = this.isMouseOverModule(module, rowX, rowY, mouseX, mouseY, scale); + this.hoverAnimations.put(module, Float.valueOf(LerpUtil.lerp(current, hovered ? 1.0f : 0.0f, 0.12f))); } - private int applyAlpha(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = (int)((float)n2 * f); - return n3 << 24 | n & 0xFFFFFF; + private int applyAlpha(int color, float alpha) { + int origAlpha = color >> 24 & 0xFF; + int newAlpha = (int)((float)origAlpha * alpha); + return newAlpha << 24 | color & 0xFFFFFF; } - private void renderModuleList(Category category, List list, int n, int n2, int n3, int n4, int n5, float f, boolean bl, float f2) { - float f3 = 30.0f * f2; - int n6 = (int)(160.0f * f2); - FontRenderer fontRenderer = FontPresets.axiformaBold(20.0f * f2); - String string = category == null ? "Search" : category.name().substring(0, 1).toUpperCase() + category.name().substring(1).toLowerCase(); - GlHelper.drawText(string, (float)n + 10.0f * f2, (float)n2 + 12.0f * f2, fontRenderer, this.applyAlpha(-1, f)); - FontRenderer fontRenderer2 = FontPresets.axiformaRegular(12.0f * f2); - String string2 = category == null ? list.size() + " Results" : "Sorting: A-Z"; - float f4 = GlHelper.getStringWidth(string2, fontRenderer2); - float f5 = (float)(n + n6) - f4 - 10.0f * f2; - GlHelper.drawText(string2, f5, (float)n2 + 14.0f * f2, fontRenderer2, this.applyAlpha(-5592406, f)); + private void renderModuleList(Category category, List modules, int panelX, int panelY, int panelHeight, int mouseX, int mouseY, float alpha, boolean animating, float scale) { + float headerHeight = 30.0f * scale; + int panelWidth = (int)(160.0f * scale); + FontRenderer titleFont = FontPresets.axiformaBold(20.0f * scale); + String titleText = category == null ? "Search" : category.name().substring(0, 1).toUpperCase() + category.name().substring(1).toLowerCase(); + GlHelper.drawText(titleText, (float)panelX + 10.0f * scale, (float)panelY + 12.0f * scale, titleFont, this.applyAlpha(-1, alpha)); + FontRenderer subtitleFont = FontPresets.axiformaRegular(12.0f * scale); + String subtitle = category == null ? modules.size() + " Results" : "Sorting: A-Z"; + float subtitleWidth = GlHelper.getStringWidth(subtitle, subtitleFont); + float subtitleX = (float)(panelX + panelWidth) - subtitleWidth - 10.0f * scale; + GlHelper.drawText(subtitle, subtitleX, (float)panelY + 14.0f * scale, subtitleFont, this.applyAlpha(-5592406, alpha)); DrawContext drawContext = GlHelper.getCanvas(); drawContext.save(); - drawContext.clip(Rectangle.ofXYWH(n, (float)n2 + f3, n6, (float)n3 - f3)); - int n7 = n2 + (int)f3 + (int)(2.0f * f2); - if (list != null) { - this.totalContentHeight = list.size() * Math.round(18.0f * f2); - for (Module module : list) { - float f6 = (float)n7 - this.scrollOffset; - if (!bl) { - this.updateModuleHover(module, n, (int)f6, n4, n5, f2); + drawContext.clip(Rectangle.ofXYWH(panelX, (float)panelY + headerHeight, panelWidth, (float)panelHeight - headerHeight)); + int rowY = panelY + (int)headerHeight + (int)(2.0f * scale); + if (modules != null) { + this.totalContentHeight = modules.size() * Math.round(18.0f * scale); + for (Module module : modules) { + float drawY = (float)rowY - this.scrollOffset; + if (!animating) { + this.updateModuleHover(module, panelX, (int)drawY, mouseX, mouseY, scale); } - FontRenderer fontRenderer3 = module.isEnabled() ? FontPresets.axiformaBold(16.0f * f2) : FontPresets.axiformaRegular(16.0f * f2); - String string3 = module.getName(); + FontRenderer moduleFont = module.isEnabled() ? FontPresets.axiformaBold(16.0f * scale) : FontPresets.axiformaRegular(16.0f * scale); + String moduleName = module.getName(); if (this.searchResults != null) { - String string4 = module.getCategory().name().substring(1).toLowerCase(); - char c = module.getCategory().name().charAt(0); - string3 = string3 + " (" + c + string4 + ")"; + String categorySuffix = module.getCategory().name().substring(1).toLowerCase(); + char categoryInitial = module.getCategory().name().charAt(0); + moduleName = moduleName + " (" + categoryInitial + categorySuffix + ")"; } if (module.isEnabled()) { - int n8 = this.applyAlpha(-1, f); - int glowColor = this.applyAlpha(new Color(255, 255, 255, 150).getRGB(), f); - TextGlow.drawGlowText(string3, (float)n + 10.0f * f2, f6, fontRenderer3, n8, glowColor, 8.0f * f2); - String string5 = module.getBind().getName(); - if (!string5.equalsIgnoreCase("None")) { - FontRenderer fontRenderer4 = FontPresets.materialIcons(16.0f * f2); - String string6 = ""; - FontRenderer fontRenderer5 = FontPresets.axiformaRegular(16.0f * f2); - float f7 = GlHelper.getStringWidth(string5, fontRenderer5); - float f8 = GlHelper.getStringWidth(string6, fontRenderer4); - float f9 = 2.0f * f2; - float f10 = f7 + f8 + f9; - float f11 = (float)(n + n6) - f10 - 10.0f * f2; - TextGlow.drawGlowText(string6, f11, f6 - (float)Math.round(f2), fontRenderer4, n8, glowColor, 8.0f * f2); - TextGlow.drawGlowText(string5, f11 + f8 + f9, f6 - 2.0f, fontRenderer3, n8, glowColor, 8.0f * f2); + int textColor = this.applyAlpha(-1, alpha); + int glowColor = this.applyAlpha(new Color(255, 255, 255, 150).getRGB(), alpha); + TextGlow.drawGlowText(moduleName, (float)panelX + 10.0f * scale, drawY, moduleFont, textColor, glowColor, 8.0f * scale); + String bindName = module.getBind().getName(); + if (!bindName.equalsIgnoreCase("None")) { + FontRenderer iconFont = FontPresets.materialIcons(16.0f * scale); + String iconText = ""; + FontRenderer bindFont = FontPresets.axiformaRegular(16.0f * scale); + float bindWidth = GlHelper.getStringWidth(bindName, bindFont); + float iconWidth = GlHelper.getStringWidth(iconText, iconFont); + float spacing = 2.0f * scale; + float totalWidth = bindWidth + iconWidth + spacing; + float bindX = (float)(panelX + panelWidth) - totalWidth - 10.0f * scale; + TextGlow.drawGlowText(iconText, bindX, drawY - (float)Math.round(scale), iconFont, textColor, glowColor, 8.0f * scale); + TextGlow.drawGlowText(bindName, bindX + iconWidth + spacing, drawY - 2.0f, moduleFont, textColor, glowColor, 8.0f * scale); } } else { - float f12 = this.hoverAnimations.getOrDefault(module, Float.valueOf(0.0f)).floatValue(); - int glowColor = 170; - int n9 = 170; - int n10 = 170; - int n11 = 204; - int n12 = 204; - int n13 = 204; - int n14 = (int)((float)glowColor + (float)(n11 - glowColor) * f12); - int n15 = (int)((float)n9 + (float)(n12 - n9) * f12); - int n16 = (int)((float)n10 + (float)(n13 - n10) * f12); - int n17 = 0xFF000000 | n14 << 16 | n15 << 8 | n16; - int n18 = this.applyAlpha(n17, f); - GlHelper.drawText(string3, (float)n + 10.0f * f2, f6, fontRenderer3, n18); - String string7 = module.getBind().getName(); - if (!string7.equalsIgnoreCase("None")) { - int n19 = (int)(f * 0.39215687f * f12); - int n20 = this.applyAlpha(-3355444, (float)n19 / 255.0f); - FontRenderer fontRenderer6 = FontPresets.materialIcons(16.0f * f2); - String string8 = ""; - FontRenderer fontRenderer7 = FontPresets.axiformaRegular(16.0f * f2); - float f13 = GlHelper.getStringWidth(string7, fontRenderer7); - float f14 = GlHelper.getStringWidth(string8, fontRenderer6); - float f15 = 2.0f * f2; - float f16 = f13 + f14 + f15; - float f17 = (float)(n + n6) - f16 - 10.0f * f2; - TextGlow.drawGlowText(string8, f17, f6 - (float)Math.round(f2), fontRenderer6, n18, n20, 5.0f * f2); - TextGlow.drawGlowText(string7, f17 + f14 + f15, f6 - 2.0f, fontRenderer3, n18, n20, 5.0f * f2); + float hoverAmount = this.hoverAnimations.getOrDefault(module, Float.valueOf(0.0f)).floatValue(); + int rFrom = 170; + int gFrom = 170; + int bFrom = 170; + int rTo = 204; + int gTo = 204; + int bTo = 204; + int r = (int)((float)rFrom + (float)(rTo - rFrom) * hoverAmount); + int g = (int)((float)gFrom + (float)(gTo - gFrom) * hoverAmount); + int b = (int)((float)bFrom + (float)(bTo - bFrom) * hoverAmount); + int rgbColor = 0xFF000000 | r << 16 | g << 8 | b; + int textColor = this.applyAlpha(rgbColor, alpha); + GlHelper.drawText(moduleName, (float)panelX + 10.0f * scale, drawY, moduleFont, textColor); + String bindName = module.getBind().getName(); + if (!bindName.equalsIgnoreCase("None")) { + int glowByte = (int)(alpha * 0.39215687f * hoverAmount); + int glowColor = this.applyAlpha(-3355444, (float)glowByte / 255.0f); + FontRenderer iconFont = FontPresets.materialIcons(16.0f * scale); + String iconText = ""; + FontRenderer bindFont = FontPresets.axiformaRegular(16.0f * scale); + float bindWidth = GlHelper.getStringWidth(bindName, bindFont); + float iconWidth = GlHelper.getStringWidth(iconText, iconFont); + float spacing = 2.0f * scale; + float totalWidth = bindWidth + iconWidth + spacing; + float bindX = (float)(panelX + panelWidth) - totalWidth - 10.0f * scale; + TextGlow.drawGlowText(iconText, bindX, drawY - (float)Math.round(scale), iconFont, textColor, glowColor, 5.0f * scale); + TextGlow.drawGlowText(bindName, bindX + iconWidth + spacing, drawY - 2.0f, moduleFont, textColor, glowColor, 5.0f * scale); } } - n7 += Math.round(18.0f * f2); + rowY += Math.round(18.0f * scale); } } else { this.totalContentHeight = 0.0f; @@ -297,90 +297,90 @@ extends ClientBase { drawContext.restore(); } - public boolean onMouseClick(int n, int n2, int n3, int n4, Category category, int n5, float f) { - List list; - List list2 = list = !this.searchQuery.isEmpty() ? this.searchResults : this.currentModules; - if (list == null || this.searchQuery.isEmpty() && this.animationState != ModuleListPanel.AnimationState.NONE) { + public boolean onMouseClick(int originX, int originY, int mouseX, int mouseY, Category category, int button, float scale) { + List modules; + List dup = modules = !this.searchQuery.isEmpty() ? this.searchResults : this.currentModules; + if (modules == null || this.searchQuery.isEmpty() && this.animationState != ModuleListPanel.AnimationState.NONE) { return false; } - int n6 = (int)(160.0f * f); - int n7 = (int)(20.0f * f); - int n8 = (int)(20.0f * f); - int n9 = (int)(400.0f * f); - int n10 = (int)(30.0f * f); - int n11 = n + n7 - (int)(8.0f * f); - int n12 = n2 + n8 + (int)(23.0f * f); - int n13 = n9 - 2 * n7 - (int)(20.0f * f); - float f2 = n13 - n10; - if (this.totalContentHeight > f2) { - float f3 = this.totalContentHeight - f2; - float f4 = Math.max(20.0f * f, f2 / this.totalContentHeight * f2); - float f5 = (float)(n12 + n10) + this.scrollOffset / f3 * (f2 - f4); - float f6 = 4.0f * f; - int n14 = n11 + n6 - (int)f6 - 2; - if (n3 >= n14 && (float)n3 <= (float)n14 + f6 && (float)n4 >= f5 && (float)n4 <= f5 + f4) { + int panelWidth = (int)(160.0f * scale); + int marginX = (int)(20.0f * scale); + int marginY = (int)(20.0f * scale); + int baseSize = (int)(400.0f * scale); + int headerHeight = (int)(30.0f * scale); + int panelX = originX + marginX - (int)(8.0f * scale); + int panelY = originY + marginY + (int)(23.0f * scale); + int panelHeight = baseSize - 2 * marginX - (int)(20.0f * scale); + float visibleHeight = panelHeight - headerHeight; + if (this.totalContentHeight > visibleHeight) { + float maxScroll = this.totalContentHeight - visibleHeight; + float thumbHeight = Math.max(20.0f * scale, visibleHeight / this.totalContentHeight * visibleHeight); + float thumbY = (float)(panelY + headerHeight) + this.scrollOffset / maxScroll * (visibleHeight - thumbHeight); + float thumbWidth = 4.0f * scale; + int thumbX = panelX + panelWidth - (int)thumbWidth - 2; + if (mouseX >= thumbX && (float)mouseX <= (float)thumbX + thumbWidth && (float)mouseY >= thumbY && (float)mouseY <= thumbY + thumbHeight) { this.isDraggingScrollbar = true; - this.scrollbarDragStartY = n4; + this.scrollbarDragStartY = mouseY; this.scrollOffsetAtDragStart = this.scrollOffset; this.lastScrollTime = System.currentTimeMillis(); return true; } } - if (!this.isMouseOverPanel(n, n2, n3, n4, f)) { + if (!this.isMouseOverPanel(originX, originY, mouseX, mouseY, scale)) { return false; } - int n15 = n12 + n10 + Math.round(2.0f * f); - for (Module module : list) { - int n16; - if (this.isMouseOverModule(module, n11, n16 = (int)((float)n15 - this.scrollOffset), n3, n4, f)) { - if (n5 == 0) { + int rowY = panelY + headerHeight + Math.round(2.0f * scale); + for (Module module : modules) { + int adjustedRowY; + if (this.isMouseOverModule(module, panelX, adjustedRowY = (int)((float)rowY - this.scrollOffset), mouseX, mouseY, scale)) { + if (button == 0) { module.toggle(); - String string = module.isEnabled() ? "On" : "Off"; - PanelClickGui.panelClickGui.addToast(module.getName() + " Module " + string); - } else if (n5 == 1) { + String stateLabel = module.isEnabled() ? "On" : "Off"; + PanelClickGui.panelClickGui.addToast(module.getName() + " Module " + stateLabel); + } else if (button == 1) { this.hoveredModule = module; - } else if (n5 == 2) { + } else if (button == 2) { PanelClickGui.panelClickGui.selectModule(module); } return true; } - n15 += Math.round(18.0f * f); + rowY += Math.round(18.0f * scale); } return false; } - private boolean isMouseOverModule(Module module, int n, int n2, int n3, int n4, float f) { - int n5 = Math.round(18.0f * f); - int n6 = (int)(160.0f * f); - boolean bl = n3 >= n && n3 <= n + n6; - boolean bl2 = n4 >= n2 - n5 / 2 && n4 <= n2 + n5 / 2; - return bl && bl2; + private boolean isMouseOverModule(Module module, int rowX, int rowY, int mouseX, int mouseY, float scale) { + int rowHeight = Math.round(18.0f * scale); + int panelWidth = (int)(160.0f * scale); + boolean withinX = mouseX >= rowX && mouseX <= rowX + panelWidth; + boolean withinY = mouseY >= rowY - rowHeight / 2 && mouseY <= rowY + rowHeight / 2; + return withinX && withinY; } - public void onScroll(double d, float f) { - int n = (int)(400.0f * f) - (int)(40.0f * f) - (int)(20.0f * f); - float f2 = 30.0f * f; - float f3 = (float)n - f2; - if (this.totalContentHeight > f3) { - float f4 = this.totalContentHeight - f3; - this.scrollTarget -= (float)d * 18.0f * f; - this.scrollTarget = Math.max(0.0f, Math.min(this.scrollTarget, f4)); + public void onScroll(double scrollDelta, float scale) { + int contentHeight = (int)(400.0f * scale) - (int)(40.0f * scale) - (int)(20.0f * scale); + float headerHeight = 30.0f * scale; + float visibleHeight = (float)contentHeight - headerHeight; + if (this.totalContentHeight > visibleHeight) { + float maxScroll = this.totalContentHeight - visibleHeight; + this.scrollTarget -= (float)scrollDelta * 18.0f * scale; + this.scrollTarget = Math.max(0.0f, Math.min(this.scrollTarget, maxScroll)); this.lastScrollTime = System.currentTimeMillis(); } } - public void onMouseDrag(double d, double d2, float f) { + public void onMouseDrag(double mouseX, double mouseY, float scale) { if (this.isDraggingScrollbar) { - int n = (int)(400.0f * f) - (int)(40.0f * f) - (int)(20.0f * f); - float f2 = (float)n - 30.0f * f; - float f3 = this.totalContentHeight - f2; - float f4 = Math.max(20.0f * f, f2 / this.totalContentHeight * f2); - float f5 = f2 - f4; - if (f5 > 0.0f) { - float f6 = (float)d2 - this.scrollbarDragStartY; - float f7 = f6 / f5 * f3; - this.scrollOffset = this.scrollOffsetAtDragStart + f7; - this.scrollTarget = this.scrollOffset = Math.max(0.0f, Math.min(this.scrollOffset, f3)); + int contentHeight = (int)(400.0f * scale) - (int)(40.0f * scale) - (int)(20.0f * scale); + float visibleHeight = (float)contentHeight - 30.0f * scale; + float maxScroll = this.totalContentHeight - visibleHeight; + float thumbHeight = Math.max(20.0f * scale, visibleHeight / this.totalContentHeight * visibleHeight); + float trackHeight = visibleHeight - thumbHeight; + if (trackHeight > 0.0f) { + float dragDeltaY = (float)mouseY - this.scrollbarDragStartY; + float scrollDelta = dragDeltaY / trackHeight * maxScroll; + this.scrollOffset = this.scrollOffsetAtDragStart + scrollDelta; + this.scrollTarget = this.scrollOffset = Math.max(0.0f, Math.min(this.scrollOffset, maxScroll)); } this.lastScrollTime = System.currentTimeMillis(); } @@ -391,16 +391,16 @@ extends ClientBase { this.lastScrollTime = System.currentTimeMillis(); } - public boolean isMouseOverPanel(int n, int n2, int n3, int n4, float f) { - int n5 = (int)(160.0f * f); - int n6 = (int)(20.0f * f); - int n7 = (int)(20.0f * f); - int n8 = (int)(400.0f * f); - int n9 = (int)(30.0f * f); - int n10 = n + n6 - (int)(8.0f * f); - int n11 = n2 + n7 + (int)(23.0f * f); - int n12 = n8 - 2 * n6 - (int)(20.0f * f); - return n3 >= n10 && n3 <= n10 + n5 && n4 >= n11 + n9 && n4 <= n11 + n12; + public boolean isMouseOverPanel(int originX, int originY, int mouseX, int mouseY, float scale) { + int panelWidth = (int)(160.0f * scale); + int marginX = (int)(20.0f * scale); + int marginY = (int)(20.0f * scale); + int baseSize = (int)(400.0f * scale); + int headerHeight = (int)(30.0f * scale); + int panelX = originX + marginX - (int)(8.0f * scale); + int panelY = originY + marginY + (int)(23.0f * scale); + int panelHeight = baseSize - 2 * marginX - (int)(20.0f * scale); + return mouseX >= panelX && mouseX <= panelX + panelWidth && mouseY >= panelY + headerHeight && mouseY <= panelY + panelHeight; } public Module getHoveredModule() { @@ -411,28 +411,28 @@ extends ClientBase { this.hoveredModule = module; } - private void rescaleScroll(float f) { - List list; + private void rescaleScroll(float scale) { + List modules; if (this.lastScale <= 0.0f) { return; } - float f2 = f / this.lastScale; - this.scrollOffset *= f2; - this.scrollTarget *= f2; - int n = (int)(400.0f * f) - (int)(40.0f * f) - (int)(20.0f * f); - float f3 = 30.0f * f; - float f4 = (float)n - f3; - List list2 = list = !this.searchQuery.isEmpty() ? this.searchResults : this.currentModules; - if (list != null) { - this.totalContentHeight = list.size() * Math.round(18.0f * f); + float scaleRatio = scale / this.lastScale; + this.scrollOffset *= scaleRatio; + this.scrollTarget *= scaleRatio; + int contentHeight = (int)(400.0f * scale) - (int)(40.0f * scale) - (int)(20.0f * scale); + float headerHeight = 30.0f * scale; + float visibleHeight = (float)contentHeight - headerHeight; + List dup = modules = !this.searchQuery.isEmpty() ? this.searchResults : this.currentModules; + if (modules != null) { + this.totalContentHeight = modules.size() * Math.round(18.0f * scale); } - if (this.totalContentHeight > f4) { - float f5 = this.totalContentHeight - f4; - this.scrollOffset = Math.max(0.0f, Math.min(this.scrollOffset, f5)); - this.scrollTarget = Math.max(0.0f, Math.min(this.scrollTarget, f5)); + if (this.totalContentHeight > visibleHeight) { + float maxScroll = this.totalContentHeight - visibleHeight; + this.scrollOffset = Math.max(0.0f, Math.min(this.scrollOffset, maxScroll)); + this.scrollTarget = Math.max(0.0f, Math.min(this.scrollTarget, maxScroll)); } else { this.scrollOffset = 0.0f; this.scrollTarget = 0.0f; } } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/ProfileWidget.java b/src/main/java/shit/zen/gui/panel/ProfileWidget.java index c5cf88e..518c3d5 100644 --- a/src/main/java/shit/zen/gui/panel/ProfileWidget.java +++ b/src/main/java/shit/zen/gui/panel/ProfileWidget.java @@ -24,65 +24,65 @@ extends ClientBase { private boolean isHovered = false; private final SettingsPopup settingsPopup; - public ProfileWidget(Consumer consumer) { - this.settingsPopup = new SettingsPopup(consumer); + public ProfileWidget(Consumer scaleChangeCallback) { + this.settingsPopup = new SettingsPopup(scaleChangeCallback); } - public void render(GuiGraphics guiGraphics, int n, int n2, int n3, int n4, float f, float f2) { + public void render(GuiGraphics guiGraphics, int originX, int originY, int mouseX, int mouseY, float scale, float alpha) { if (mc.player == null) { return; } try { - int n5 = (int)(20.0f * f); - int n6 = (int)(20.0f * f); - int n7 = (int)(10.0f * f); - int n8 = (int)(20.0f * f); - float f3 = 6.0f * f; - int n9 = n + n6; - int n10 = n2 + n8; - String string = this.getUserId(); - String string2 = this.getUserRole(); - int n11 = n9 + n5 + n7 - (int)(11.0f * f); - int n12 = n10 + n5 / 2 - (int)(10.0f * f); - int n13 = n11 - n5 - (int)(5.0f * f); - int n14 = n12 - (int)(8.0f * f); - this.checkHover(n13, n14, n3, n4, n5); + int avatarSize = (int)(20.0f * scale); + int marginX = (int)(20.0f * scale); + int textGap = (int)(10.0f * scale); + int marginY = (int)(20.0f * scale); + float cornerRadius = 6.0f * scale; + int baseX = originX + marginX; + int baseY = originY + marginY; + String userId = this.getUserId(); + String userRole = this.getUserRole(); + int textX = baseX + avatarSize + textGap - (int)(11.0f * scale); + int textY = baseY + avatarSize / 2 - (int)(10.0f * scale); + int avatarX = textX - avatarSize - (int)(5.0f * scale); + int avatarY = textY - (int)(8.0f * scale); + this.checkHover(avatarX, avatarY, mouseX, mouseY, avatarSize); this.updateHoverAlpha(); Renderer.renderConsumer(drawContext -> { if (this.hoverAlpha > 0.01f) { - int hoverColor = new Color(255, 255, 255, (int)(30.0f * this.hoverAlpha * f2)).getRGB(); - RenderUtil.drawRoundedRect(guiGraphics.pose(), n13 - 2, n14 - 2, n5 + 4, n5 + 4, f3 + 1.0f, hoverColor); + int hoverColor = new Color(255, 255, 255, (int)(30.0f * this.hoverAlpha * alpha)).getRGB(); + RenderUtil.drawRoundedRect(guiGraphics.pose(), avatarX - 2, avatarY - 2, avatarSize + 4, avatarSize + 4, cornerRadius + 1.0f, hoverColor); } if (mc.player instanceof AbstractClientPlayer) { - GlHelper.drawPlayerHeadRounded(mc.player, n13, n14, n5, n5, f2, f3); + GlHelper.drawPlayerHeadRounded(mc.player, avatarX, avatarY, avatarSize, avatarSize, alpha, cornerRadius); } - FontRenderer fontRenderer = FontPresets.axiformaRegular(14.0f * f); - int glowColor = new Color(255, 255, 255, (int)(100.0f * f2)).getRGB(); - TextGlow.drawGlowText(string, n11, n12, fontRenderer, this.applyAlpha(-1, f2), glowColor, 8.0f * f); - float roleWidth = GlHelper.getStringWidth(string, fontRenderer); - int roleBoxX = (int)((float)n11 + roleWidth + 8.0f * f); - int roleBoxY = n12 - (int)(6.0f * f); - Color color = this.getRoleColor(string2); - FontRenderer fontRenderer2 = FontPresets.axiformaBold(11.0f * f); - float roleStrWidth = GlHelper.getStringWidth(string2, fontRenderer2); - int roleBoxW = (int)(roleStrWidth + 8.0f * f); - int roleBoxH = (int)(10.0f * f); - int roleShadowColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)(180.0f * f2)).getRGB(); - RenderUtil.drawRoundedRect(guiGraphics.pose(), roleBoxX - 3, (float)roleBoxY + 2.5f * f - 2.0f, roleBoxW + 2, roleBoxH + 2, 5.0f * f, this.applyAlpha(roleShadowColor, f2 * 0.35f)); - RenderUtil.drawRoundedRect(guiGraphics.pose(), roleBoxX - 2, (float)roleBoxY + 3.5f * f - 2.0f, roleBoxW, roleBoxH, 4.0f * f, this.applyAlpha(color.getRGB(), f2)); - int roleTextGlow = new Color(255, 255, 255, (int)(120.0f * f2)).getRGB(); - TextGlow.drawGlowText(string2, (float)roleBoxX + 1.5f * f, (float)roleBoxY + 6.5f * f, fontRenderer2, this.applyAlpha(-1, f2), roleTextGlow, 5.0f * f); + FontRenderer nameFont = FontPresets.axiformaRegular(14.0f * scale); + int glowColor = new Color(255, 255, 255, (int)(100.0f * alpha)).getRGB(); + TextGlow.drawGlowText(userId, textX, textY, nameFont, this.applyAlpha(-1, alpha), glowColor, 8.0f * scale); + float nameWidth = GlHelper.getStringWidth(userId, nameFont); + int roleBoxX = (int)((float)textX + nameWidth + 8.0f * scale); + int roleBoxY = textY - (int)(6.0f * scale); + Color roleColor = this.getRoleColor(userRole); + FontRenderer roleFont = FontPresets.axiformaBold(11.0f * scale); + float roleStrWidth = GlHelper.getStringWidth(userRole, roleFont); + int roleBoxW = (int)(roleStrWidth + 8.0f * scale); + int roleBoxH = (int)(10.0f * scale); + int roleShadowColor = new Color(roleColor.getRed(), roleColor.getGreen(), roleColor.getBlue(), (int)(180.0f * alpha)).getRGB(); + RenderUtil.drawRoundedRect(guiGraphics.pose(), roleBoxX - 3, (float)roleBoxY + 2.5f * scale - 2.0f, roleBoxW + 2, roleBoxH + 2, 5.0f * scale, this.applyAlpha(roleShadowColor, alpha * 0.35f)); + RenderUtil.drawRoundedRect(guiGraphics.pose(), roleBoxX - 2, (float)roleBoxY + 3.5f * scale - 2.0f, roleBoxW, roleBoxH, 4.0f * scale, this.applyAlpha(roleColor.getRGB(), alpha)); + int roleTextGlow = new Color(255, 255, 255, (int)(120.0f * alpha)).getRGB(); + TextGlow.drawGlowText(userRole, (float)roleBoxX + 1.5f * scale, (float)roleBoxY + 6.5f * scale, roleFont, this.applyAlpha(-1, alpha), roleTextGlow, 5.0f * scale); }); - this.settingsPopup.render(guiGraphics, n3, n4, f, f2); + this.settingsPopup.render(guiGraphics, mouseX, mouseY, scale, alpha); } catch (Exception exception) { // empty catch block } } - private int applyAlpha(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = (int)((float)n2 * f); - return n3 << 24 | n & 0xFFFFFF; + private int applyAlpha(int color, float alpha) { + int origAlpha = color >> 24 & 0xFF; + int newAlpha = (int)((float)origAlpha * alpha); + return newAlpha << 24 | color & 0xFFFFFF; } private String getUserId() { @@ -92,11 +92,11 @@ extends ClientBase { private String getUserRole() { try { if (false) { - List list = new ArrayList<>(); - if (list.contains("ROLE_OWNER")) return "Premium"; - if (list.contains("ROLE_ADMIN")) return "Admin"; - if (list.contains("ROLE_BETA")) return "Beta"; - return list.get(0).replace("ROLE_", ""); + List roles = new ArrayList<>(); + if (roles.contains("ROLE_OWNER")) return "Premium"; + if (roles.contains("ROLE_ADMIN")) return "Admin"; + if (roles.contains("ROLE_BETA")) return "Beta"; + return roles.get(0).replace("ROLE_", ""); } } catch (Exception exception) { // empty catch block @@ -104,25 +104,25 @@ extends ClientBase { return "User"; } - public boolean isMouseOverAvatar(int n, int n2, int n3, int n4, float f) { - int n5 = (int)(20.0f * f); - int n6 = (int)(20.0f * f); - int n7 = (int)(10.0f * f); - int n8 = (int)(20.0f * f); - int n9 = n + n6; - int n10 = n2 + n8; - int n11 = n9 + n5 + n7 - (int)(11.0f * f); - int n12 = n10 + n5 / 2 - (int)(10.0f * f); - int n13 = n11 - n5 - (int)(5.0f * f); - int n14 = n12 - (int)(8.0f * f); - return n3 >= n13 && n3 <= n13 + n5 && n4 >= n14 && n4 <= n14 + n5; + public boolean isMouseOverAvatar(int originX, int originY, int mouseX, int mouseY, float scale) { + int avatarSize = (int)(20.0f * scale); + int marginX = (int)(20.0f * scale); + int textGap = (int)(10.0f * scale); + int marginY = (int)(20.0f * scale); + int baseX = originX + marginX; + int baseY = originY + marginY; + int textX = baseX + avatarSize + textGap - (int)(11.0f * scale); + int textY = baseY + avatarSize / 2 - (int)(10.0f * scale); + int avatarX = textX - avatarSize - (int)(5.0f * scale); + int avatarY = textY - (int)(8.0f * scale); + return mouseX >= avatarX && mouseX <= avatarX + avatarSize && mouseY >= avatarY && mouseY <= avatarY + avatarSize; } - public boolean onMouseClick(int n, int n2, int n3, int n4, float f) { - if (this.settingsPopup.isOpen() && this.settingsPopup.onMouseClick(n3, n4, f)) { + public boolean onMouseClick(int originX, int originY, int mouseX, int mouseY, float scale) { + if (this.settingsPopup.isOpen() && this.settingsPopup.onMouseClick(mouseX, mouseY, scale)) { return true; } - if (this.isMouseOverAvatar(n, n2, n3, n4, f)) { + if (this.isMouseOverAvatar(originX, originY, mouseX, mouseY, scale)) { this.settingsPopup.toggleOpen(); return true; } @@ -146,16 +146,16 @@ extends ClientBase { } } - private void checkHover(int n, int n2, int n3, int n4, int n5) { - this.isHovered = n3 >= n && n3 <= n + n5 && n4 >= n2 && n4 <= n2 + n5; + private void checkHover(int avatarX, int avatarY, int mouseX, int mouseY, int avatarSize) { + this.isHovered = mouseX >= avatarX && mouseX <= avatarX + avatarSize && mouseY >= avatarY && mouseY <= avatarY + avatarSize; } private void updateHoverAlpha() { this.hoverAlpha = this.isHovered ? LerpUtil.lerp(this.hoverAlpha, 1.0f, 0.12f) : LerpUtil.lerp(this.hoverAlpha, 0.0f, 0.12f); } - public void onMouseDrag(int n, int n2) { - this.settingsPopup.onMouseDrag(n, n2); + public void onMouseDrag(int mouseX, int mouseY) { + this.settingsPopup.onMouseDrag(mouseX, mouseY); } public void onMouseRelease() { @@ -165,4 +165,4 @@ extends ClientBase { public boolean isPopupOpen() { return this.settingsPopup.isOpen(); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/ScaleSwitchOverlay.java b/src/main/java/shit/zen/gui/panel/ScaleSwitchOverlay.java index 271a562..55974ab 100644 --- a/src/main/java/shit/zen/gui/panel/ScaleSwitchOverlay.java +++ b/src/main/java/shit/zen/gui/panel/ScaleSwitchOverlay.java @@ -23,9 +23,9 @@ extends ClientBase { private float fromScale = 1.0f; private float toScale = 1.0f; - public void show(float f, float f2) { - this.fromScale = f; - this.toScale = f2; + public void show(float fromScale, float toScale) { + this.fromScale = fromScale; + this.toScale = toScale; this.isActive = true; this.startTime = System.currentTimeMillis(); } @@ -46,7 +46,7 @@ extends ClientBase { return !this.isActive && this.alpha <= 0.0f; } - public void render(GuiGraphics guiGraphics, int n, int n2, float f) { + public void render(GuiGraphics guiGraphics, int screenWidth, int screenHeight, float scale) { if (!this.isActive && this.alpha <= 0.005f) { return; } @@ -55,13 +55,13 @@ extends ClientBase { return; } try { - this.drawBackground(guiGraphics, n, n2); - float f2 = 400.0f * f; - float f3 = 180.0f * f; - int n3 = (int)(((float)n - f2) / 2.0f); - int n4 = (int)(((float)n2 - f3) / 2.0f); - this.drawGlow(guiGraphics, n3, n4, f2, f3, f); - this.drawContent(guiGraphics, n3, n4, f2, f); + this.drawBackground(guiGraphics, screenWidth, screenHeight); + float boxWidth = 400.0f * scale; + float boxHeight = 180.0f * scale; + int boxX = (int)(((float)screenWidth - boxWidth) / 2.0f); + int boxY = (int)(((float)screenHeight - boxHeight) / 2.0f); + this.drawGlow(guiGraphics, boxX, boxY, boxWidth, boxHeight, scale); + this.drawContent(guiGraphics, boxX, boxY, boxWidth, scale); } catch (Exception exception) { // empty catch block } @@ -71,66 +71,66 @@ extends ClientBase { this.alpha = this.isActive ? LerpUtil.lerp(this.alpha, 1.0f, 0.08f) : LerpUtil.lerp(this.alpha, 0.0f, 0.08f); } - private void drawBackground(GuiGraphics guiGraphics, int n, int n2) { + private void drawBackground(GuiGraphics guiGraphics, int screenWidth, int screenHeight) { Color color = new Color(OVERLAY_BG_COLOR.getRed(), OVERLAY_BG_COLOR.getGreen(), OVERLAY_BG_COLOR.getBlue(), (int)((float)OVERLAY_BG_COLOR.getAlpha() * this.alpha)); - RenderUtil.drawRoundedRect(guiGraphics.pose(), 0.0f, 0.0f, n, n2, 0.0f, color.getRGB()); + RenderUtil.drawRoundedRect(guiGraphics.pose(), 0.0f, 0.0f, screenWidth, screenHeight, 0.0f, color.getRGB()); } - private void drawGlow(GuiGraphics guiGraphics, int n, int n2, float f, float f2, float f3) { - TextGlow.drawBackground(guiGraphics.pose(), n, n2, f, f2, 12.0f * f3, this.alpha); + private void drawGlow(GuiGraphics guiGraphics, int boxX, int boxY, float boxWidth, float boxHeight, float scale) { + TextGlow.drawBackground(guiGraphics.pose(), boxX, boxY, boxWidth, boxHeight, 12.0f * scale, this.alpha); } - private void drawContent(GuiGraphics guiGraphics, int n, int n2, float f, float f2) { + private void drawContent(GuiGraphics guiGraphics, int boxX, int boxY, float boxWidth, float scale) { Renderer.renderConsumer((drawContext -> { - int n3 = (int)(255.0f * this.alpha); - if (n3 <= 0) { + int alphaByte = (int)(255.0f * this.alpha); + if (alphaByte <= 0) { return; } - FontRenderer fontRenderer = FontPresets.axiformaBold(24.0f * f2); - String string = "Waiting"; - float f3 = GlHelper.getStringWidth(string, fontRenderer); - float f4 = (float)n + (f - f3) / 2.0f; - float f5 = (float)n2 + 45.0f * f2; - int n4 = n3 << 24 | 0xFFFFFF; - int n5 = n3 << 24 | 0xFFFFFF; - TextGlow.drawGlowText(string, f4, f5, fontRenderer, n4, n5, 10.0f * f2); - FontRenderer fontRenderer2 = FontPresets.axiformaRegular(18.0f * f2); - String string2 = String.format(Locale.US, "Switching scale from %.0f%% to %.0f%%", new Object[]{Float.valueOf(this.fromScale * 100.0f), Float.valueOf(this.toScale * 100.0f)}); - float f6 = GlHelper.getStringWidth(string2, fontRenderer2); - float f7 = (float)n + (f - f6) / 2.0f; - float f8 = (float)n2 + 75.0f * f2; - int n6 = n3 << 24 | 0xCCCCCC; - GlHelper.drawText(string2, f7, f8, fontRenderer2, n6); - this.drawAnimatedDots(n, (int)((float)n2 + 115.0f * f2), (int)f, n3, f2); + FontRenderer titleFont = FontPresets.axiformaBold(24.0f * scale); + String title = "Waiting"; + float titleWidth = GlHelper.getStringWidth(title, titleFont); + float titleX = (float)boxX + (boxWidth - titleWidth) / 2.0f; + float titleY = (float)boxY + 45.0f * scale; + int titleColor = alphaByte << 24 | 0xFFFFFF; + int glowColor = alphaByte << 24 | 0xFFFFFF; + TextGlow.drawGlowText(title, titleX, titleY, titleFont, titleColor, glowColor, 10.0f * scale); + FontRenderer descFont = FontPresets.axiformaRegular(18.0f * scale); + String description = String.format(Locale.US, "Switching scale from %.0f%% to %.0f%%", new Object[]{Float.valueOf(this.fromScale * 100.0f), Float.valueOf(this.toScale * 100.0f)}); + float descWidth = GlHelper.getStringWidth(description, descFont); + float descX = (float)boxX + (boxWidth - descWidth) / 2.0f; + float descY = (float)boxY + 75.0f * scale; + int descColor = alphaByte << 24 | 0xCCCCCC; + GlHelper.drawText(description, descX, descY, descFont, descColor); + this.drawAnimatedDots(boxX, (int)((float)boxY + 115.0f * scale), (int)boxWidth, alphaByte, scale); })); } - private void drawAnimatedDots(int n, int n2, int n3, int n4, float f) { - FontRenderer fontRenderer = FontPresets.axiformaBold(20.0f * f); - String string = "•"; - float f2 = GlHelper.getStringWidth(string, fontRenderer); - float f3 = f2 * 3.0f + 20.0f * f; - float f4 = (float)n + ((float)n3 - f3) / 2.0f; - int n5 = n4 << 24 | 0xFFFFFF; - long l = System.currentTimeMillis() - this.startTime; - long l2 = l % 1400L; + private void drawAnimatedDots(int boxX, int dotsY, int boxWidth, int alphaByte, float scale) { + FontRenderer dotFont = FontPresets.axiformaBold(20.0f * scale); + String dot = "•"; + float dotWidth = GlHelper.getStringWidth(dot, dotFont); + float totalWidth = dotWidth * 3.0f + 20.0f * scale; + float startX = (float)boxX + ((float)boxWidth - totalWidth) / 2.0f; + int dotColor = alphaByte << 24 | 0xFFFFFF; + long elapsed = System.currentTimeMillis() - this.startTime; + long cycleTime = elapsed % 1400L; for (int i = 0; i < 3; ++i) { - float f5; - float f6 = f4 + (float)i * (f2 + 10.0f * f); - long l3 = (long)i * 150L; - long l4 = l3 + 300L; - float f7 = 0.0f; - if (l2 >= l3 && l2 <= l4) { - f5 = (float)(l2 - l3) / 300.0f; - float f8 = f5 * (float)Math.PI; - f7 = (float)(Math.sin(f8) * 6.0 * (double)f); + float drawY; + float dotX = startX + (float)i * (dotWidth + 10.0f * scale); + long dotStart = (long)i * 150L; + long dotEnd = dotStart + 300L; + float verticalOffset = 0.0f; + if (cycleTime >= dotStart && cycleTime <= dotEnd) { + drawY = (float)(cycleTime - dotStart) / 300.0f; + float angle = drawY * (float)Math.PI; + verticalOffset = (float)(Math.sin(angle) * 6.0 * (double)scale); } - f5 = (float)n2 - f7; - GlHelper.drawText(string, f6, f5, fontRenderer, n5); + drawY = (float)dotsY - verticalOffset; + GlHelper.drawText(dot, dotX, drawY, dotFont, dotColor); } } static { new Color(255, 255, 255, 40); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/SettingsPanel.java b/src/main/java/shit/zen/gui/panel/SettingsPanel.java index 6defea7..bd294de 100644 --- a/src/main/java/shit/zen/gui/panel/SettingsPanel.java +++ b/src/main/java/shit/zen/gui/panel/SettingsPanel.java @@ -44,10 +44,10 @@ extends ClientBase { private float transitionProgress = 0.0f; private float lastScale = 1.0f; - public void render(GuiGraphics guiGraphics, int n, int n2, int n3, int n4, Module module, float f, float f2) { - if (Math.abs(f - this.lastScale) > 0.001f) { - this.rescaleScroll(f); - this.lastScale = f; + public void render(GuiGraphics guiGraphics, int originX, int originY, int mouseX, int mouseY, Module module, float scale, float alpha) { + if (Math.abs(scale - this.lastScale) > 0.001f) { + this.rescaleScroll(scale); + this.lastScale = scale; } if (this.currentModule != module) { if (this.currentModule != null) { @@ -84,64 +84,64 @@ extends ClientBase { return; } this.scrollOffset = Math.abs(this.scrollOffset - this.scrollTarget) > 0.01f ? LerpUtil.smoothLerp(this.scrollOffset, this.scrollTarget, 0.35f) : this.scrollTarget; - float f3 = this.currentModule != null && this.currentModule.isEnabled() ? 1.0f : 0.0f; - this.enabledAlpha = Math.abs(f3 - this.enabledAlpha) > 0.01f ? LerpUtil.smoothLerp(this.enabledAlpha, f3, 0.28f) : f3; + float enabledTarget = this.currentModule != null && this.currentModule.isEnabled() ? 1.0f : 0.0f; + this.enabledAlpha = Math.abs(enabledTarget - this.enabledAlpha) > 0.01f ? LerpUtil.smoothLerp(this.enabledAlpha, enabledTarget, 0.28f) : enabledTarget; try { - int n5 = (int)(405.0f * f); - int n6 = (int)(20.0f * f); - int n7 = (int)(20.0f * f); - int n8 = (int)(400.0f * f); - int n9 = (int)(30.0f * f); - int n10 = (int)(10.0f * f); - int n11 = n + (int)(600.0f * f) - n5 - n6 + (int)(8.0f * f); - int n12 = n2 + n7 + (int)(23.0f * f); - int n13 = n8 - 2 * n6 - (int)(20.0f * f); - int n14 = (int)(12.0f * f); - int n15 = (int)(15.0f * f); - int n16 = n11 + n5 - n14 * 2 - n15; - int n17 = n12 + (n9 - n14) / 2; - this.checkToggleHover(n16, n17, n3, n4, n14); - float f4 = this.isToggleHovered ? 1.0f : 0.0f; - this.toggleHoverAlpha = Math.abs(f4 - this.toggleHoverAlpha) > 0.01f ? LerpUtil.smoothLerp(this.toggleHoverAlpha, f4, 0.35f) : f4; - RenderUtil.drawRoundedRect(guiGraphics.pose(), n11, n12, n5, n13, 4.0f * f, this.applyAlpha(PANEL_BG_COLOR, f2)); - this.renderToggleButton(guiGraphics, n16, n17, this.enabledAlpha, this.toggleHoverAlpha, this.currentModule != null && this.currentModule.isEnabled(), f, f2); - int n18 = n11; - int n19 = n12 + n9; - int n20 = n5; - int n21 = n13 - n9; + int panelWidth = (int)(405.0f * scale); + int marginX = (int)(20.0f * scale); + int marginY = (int)(20.0f * scale); + int baseSize = (int)(400.0f * scale); + int headerHeight = (int)(30.0f * scale); + int bottomPadding = (int)(10.0f * scale); + int panelX = originX + (int)(600.0f * scale) - panelWidth - marginX + (int)(8.0f * scale); + int panelY = originY + marginY + (int)(23.0f * scale); + int panelHeight = baseSize - 2 * marginX - (int)(20.0f * scale); + int toggleHeight = (int)(12.0f * scale); + int toggleRightPadding = (int)(15.0f * scale); + int toggleX = panelX + panelWidth - toggleHeight * 2 - toggleRightPadding; + int toggleY = panelY + (headerHeight - toggleHeight) / 2; + this.checkToggleHover(toggleX, toggleY, mouseX, mouseY, toggleHeight); + float toggleHoverTarget = this.isToggleHovered ? 1.0f : 0.0f; + this.toggleHoverAlpha = Math.abs(toggleHoverTarget - this.toggleHoverAlpha) > 0.01f ? LerpUtil.smoothLerp(this.toggleHoverAlpha, toggleHoverTarget, 0.35f) : toggleHoverTarget; + RenderUtil.drawRoundedRect(guiGraphics.pose(), panelX, panelY, panelWidth, panelHeight, 4.0f * scale, this.applyAlpha(PANEL_BG_COLOR, alpha)); + this.renderToggleButton(guiGraphics, toggleX, toggleY, this.enabledAlpha, this.toggleHoverAlpha, this.currentModule != null && this.currentModule.isEnabled(), scale, alpha); + int stencilX = panelX; + int stencilY = panelY + headerHeight; + int stencilWidth = panelWidth; + int stencilHeight = panelHeight - headerHeight; StencilHelper.beginWrite(false); - RenderUtil.drawRoundedRect(guiGraphics.pose(), n18, n19, n20, n21, 4.0f * f, Color.WHITE.getRGB()); + RenderUtil.drawRoundedRect(guiGraphics.pose(), stencilX, stencilY, stencilWidth, stencilHeight, 4.0f * scale, Color.WHITE.getRGB()); StencilHelper.beginRead(true); Renderer.renderConsumer(drawContext -> { - this.calculateTotalHeight(this.currentModule, f); + this.calculateTotalHeight(this.currentModule, scale); drawContext.save(); - drawContext.clip(Rectangle.ofXYWH(n11, n12, n5, n13)); + drawContext.clip(Rectangle.ofXYWH(panelX, panelY, panelWidth, panelHeight)); Module renderModule = this.animationState == SettingsPanel.AnimationState.FADE_OUT ? this.prevModule : this.currentModule; - float titleAlpha = this.animationState == SettingsPanel.AnimationState.FADE_OUT ? (1.0f - this.transitionProgress) * f2 : f2; + float titleAlpha = this.animationState == SettingsPanel.AnimationState.FADE_OUT ? (1.0f - this.transitionProgress) * alpha : alpha; if (renderModule != null) { - FontRenderer titleFont = FontPresets.axiformaBold(20.0f * f); - String string = renderModule.getName(); + FontRenderer titleFont = FontPresets.axiformaBold(20.0f * scale); + String title = renderModule.getName(); if (renderModule.isEnabled()) { int glowColor = this.applyAlpha(new Color(255, 255, 255, 150).getRGB(), titleAlpha); - TextGlow.drawGlowText(string, (float)n11 + 10.0f * f, (float)n12 + 12.0f * f, titleFont, this.applyAlpha(-1, titleAlpha), glowColor, 12.0f * f); + TextGlow.drawGlowText(title, (float)panelX + 10.0f * scale, (float)panelY + 12.0f * scale, titleFont, this.applyAlpha(-1, titleAlpha), glowColor, 12.0f * scale); } else { - GlHelper.drawText(string, (float)n11 + 10.0f * f, (float)n12 + 12.0f * f, titleFont, this.applyAlpha(-1, titleAlpha)); + GlHelper.drawText(title, (float)panelX + 10.0f * scale, (float)panelY + 12.0f * scale, titleFont, this.applyAlpha(-1, titleAlpha)); } } drawContext.restore(); drawContext.save(); - drawContext.clip(Rectangle.ofXYWH(n11, n12 + n9, n5, n13 - n9)); + drawContext.clip(Rectangle.ofXYWH(panelX, panelY + headerHeight, panelWidth, panelHeight - headerHeight)); float slideY = 0.0f; - float bodyAlpha = f2; + float bodyAlpha = alpha; Module bodyModule; if (this.animationState == SettingsPanel.AnimationState.FADE_OUT && this.prevModule != null) { bodyModule = this.prevModule; - slideY = this.transitionProgress * 30.0f * f; - bodyAlpha = (1.0f - this.transitionProgress) * f2; + slideY = this.transitionProgress * 30.0f * scale; + bodyAlpha = (1.0f - this.transitionProgress) * alpha; } else if (this.animationState == SettingsPanel.AnimationState.FADE_IN && this.currentModule != null) { bodyModule = this.currentModule; - slideY = (1.0f - this.transitionProgress) * -30.0f * f; - bodyAlpha = this.transitionProgress * f2; + slideY = (1.0f - this.transitionProgress) * -30.0f * scale; + bodyAlpha = this.transitionProgress * alpha; } else { bodyModule = this.currentModule; } @@ -150,19 +150,19 @@ extends ClientBase { drawContext.translate(0.0f, slideY); guiGraphics.pose().pushPose(); guiGraphics.pose().translate(0.0f, slideY, 0.0f); - List> list = bodyModule.getSettings(); - if (list != null && !list.isEmpty()) { - int settingY = n12 + n9 - (int)this.scrollOffset; - for (Setting setting : list) { + List> settings = bodyModule.getSettings(); + if (settings != null && !settings.isEmpty()) { + int settingY = panelY + headerHeight - (int)this.scrollOffset; + for (Setting setting : settings) { if (setting.getVisibility() != null && !setting.getVisibility().displayable()) continue; - int dy = SettingRendererRegistry.getInstance().render(guiGraphics, setting, n11 + (int)(10.0f * f), settingY, n5 - (int)(20.0f * f), n3, n4, bodyAlpha, f); + int dy = SettingRendererRegistry.getInstance().render(guiGraphics, setting, panelX + (int)(10.0f * scale), settingY, panelWidth - (int)(20.0f * scale), mouseX, mouseY, bodyAlpha, scale); settingY += dy; } } else { - String string = this.getModuleDescription(bodyModule); - if (string != null && !string.isEmpty()) { - FontRenderer fontRenderer = FontPresets.axiformaRegular(12.0f * f); - this.renderWrappedText(string, n11 + (int)(10.0f * f), n12 + n9 + (int)(10.0f * f), n5 - (int)(20.0f * f), fontRenderer, -5592406, bodyAlpha, f); + String description = this.getModuleDescription(bodyModule); + if (description != null && !description.isEmpty()) { + FontRenderer descFont = FontPresets.axiformaRegular(12.0f * scale); + this.renderWrappedText(description, panelX + (int)(10.0f * scale), panelY + headerHeight + (int)(10.0f * scale), panelWidth - (int)(20.0f * scale), descFont, -5592406, bodyAlpha, scale); } } guiGraphics.pose().popPose(); @@ -171,116 +171,116 @@ extends ClientBase { drawContext.restore(); }); StencilHelper.end(); - int n22 = n8 - 2 * n6 - (int)(20.0f * f); - float f5 = n22 - n9 - n10; - if (this.totalContentHeight > f5) { - float f6 = this.totalContentHeight - f5; - if (this.scrollOffset > f6) { - this.scrollOffset = f6; - this.scrollTarget = f6; + int contentHeight = baseSize - 2 * marginX - (int)(20.0f * scale); + float visibleHeight = contentHeight - headerHeight - bottomPadding; + if (this.totalContentHeight > visibleHeight) { + float maxScroll = this.totalContentHeight - visibleHeight; + if (this.scrollOffset > maxScroll) { + this.scrollOffset = maxScroll; + this.scrollTarget = maxScroll; } - if (this.scrollTarget > f6) { - this.scrollTarget = f6; + if (this.scrollTarget > maxScroll) { + this.scrollTarget = maxScroll; } } else { this.scrollOffset = 0.0f; this.scrollTarget = 0.0f; } - this.renderScrollbar(guiGraphics, n11, n12, n13, f, f2); + this.renderScrollbar(guiGraphics, panelX, panelY, panelHeight, scale, alpha); } catch (Exception exception) { // empty catch block } } - private void renderScrollbar(GuiGraphics guiGraphics, int n, int n2, int n3, float f, float f2) { - float f3; - int n4 = (int)(30.0f * f); - int n5 = (int)(10.0f * f); - float f4 = n3 - n4 - n5; - if (this.totalContentHeight <= f4) { - f3 = 0.0f; + private void renderScrollbar(GuiGraphics guiGraphics, int panelX, int panelY, int panelHeight, float scale, float alpha) { + float targetAlpha; + int headerHeight = (int)(30.0f * scale); + int bottomPadding = (int)(10.0f * scale); + float visibleHeight = panelHeight - headerHeight - bottomPadding; + if (this.totalContentHeight <= visibleHeight) { + targetAlpha = 0.0f; } else { - long l = System.currentTimeMillis() - this.lastScrollTime; - if (this.isDraggingScrollbar || l < 500L) { - f3 = 1.0f; - } else if (l < 1000L) { - long l2 = l - 500L; - f3 = 1.0f - (float)l2 / 500.0f; + long sinceScroll = System.currentTimeMillis() - this.lastScrollTime; + if (this.isDraggingScrollbar || sinceScroll < 500L) { + targetAlpha = 1.0f; + } else if (sinceScroll < 1000L) { + long fadeMs = sinceScroll - 500L; + targetAlpha = 1.0f - (float)fadeMs / 500.0f; } else { - f3 = 0.0f; + targetAlpha = 0.0f; } } - this.scrollbarAlpha = Math.abs(this.scrollbarAlpha - f3) > 0.01f ? LerpUtil.smoothLerp(this.scrollbarAlpha, f3, 0.35f) : f3; + this.scrollbarAlpha = Math.abs(this.scrollbarAlpha - targetAlpha) > 0.01f ? LerpUtil.smoothLerp(this.scrollbarAlpha, targetAlpha, 0.35f) : targetAlpha; if (this.scrollbarAlpha <= 0.01f) { return; } - float f5 = this.totalContentHeight - f4; - if (f5 <= 0.0f) { + float maxScroll = this.totalContentHeight - visibleHeight; + if (maxScroll <= 0.0f) { return; } - float f6 = Math.max(20.0f * f, f4 / this.totalContentHeight * f4); - float f7 = (float)(n2 + n4) + this.scrollOffset / f5 * (f4 - f6); - int n6 = n + (int)(405.0f * f) - (int)(4.0f * f) - 2; - float f8 = 4.0f * f; - int n7 = new Color(1.0f, 1.0f, 1.0f, this.scrollbarAlpha * f2).getRGB(); - RenderUtil.drawRoundedRect(guiGraphics.pose(), n6, f7, f8, f6, f8 / 2.0f, n7); + float thumbHeight = Math.max(20.0f * scale, visibleHeight / this.totalContentHeight * visibleHeight); + float thumbY = (float)(panelY + headerHeight) + this.scrollOffset / maxScroll * (visibleHeight - thumbHeight); + int thumbX = panelX + (int)(405.0f * scale) - (int)(4.0f * scale) - 2; + float thumbWidth = 4.0f * scale; + int thumbColor = new Color(1.0f, 1.0f, 1.0f, this.scrollbarAlpha * alpha).getRGB(); + RenderUtil.drawRoundedRect(guiGraphics.pose(), thumbX, thumbY, thumbWidth, thumbHeight, thumbWidth / 2.0f, thumbColor); } - private void checkToggleHover(int n, int n2, int n3, int n4, int n5) { - this.isToggleHovered = n3 >= n && n3 <= n + n5 * 2 && n4 >= n2 && n4 <= n2 + n5; + private void checkToggleHover(int toggleX, int toggleY, int mouseX, int mouseY, int toggleHeight) { + this.isToggleHovered = mouseX >= toggleX && mouseX <= toggleX + toggleHeight * 2 && mouseY >= toggleY && mouseY <= toggleY + toggleHeight; } - private void renderToggleButton(GuiGraphics guiGraphics, int n, int n2, float f, float f2, boolean bl, float f3, float f4) { - int n3; - int n4 = (int)(12.0f * f3); - int n5 = n4 * 2; - int n6 = n4; - int n7 = this.lerpColor(TOGGLE_OFF_COLOR, TOGGLE_ON_COLOR, f); - if (f2 > 0.0f) { - float f5 = 1.0f + 0.3f * f2; - n7 = this.brightenColor(n7, f5); + private void renderToggleButton(GuiGraphics guiGraphics, int toggleX, int toggleY, float enabledFactor, float hoverFactor, boolean enabled, float scale, float alpha) { + int overlayColor; + int unit = (int)(12.0f * scale); + int toggleWidth = unit * 2; + int toggleHeight = unit; + int trackColor = this.lerpColor(TOGGLE_OFF_COLOR, TOGGLE_ON_COLOR, enabledFactor); + if (hoverFactor > 0.0f) { + float brightness = 1.0f + 0.3f * hoverFactor; + trackColor = this.brightenColor(trackColor, brightness); } - int n8 = this.applyAlpha(n7, f4); - if (bl) { - n3 = this.applyAlpha(new Color(76, 175, 80, 70).getRGB(), f4); - RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)n - f3, (float)n2 - f3, (float)n5 + 2.0f * f3, (float)n6 + 2.0f * f3, (float)n6 / 2.0f, n3); + int trackColorAlpha = this.applyAlpha(trackColor, alpha); + if (enabled) { + overlayColor = this.applyAlpha(new Color(76, 175, 80, 70).getRGB(), alpha); + RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)toggleX - scale, (float)toggleY - scale, (float)toggleWidth + 2.0f * scale, (float)toggleHeight + 2.0f * scale, (float)toggleHeight / 2.0f, overlayColor); } - RenderUtil.drawRoundedRect(guiGraphics.pose(), n, n2, n5, n6, (float)n6 / 2.0f, n8); - n3 = n4 - (int)(4.0f * f3); - int n9 = (n6 - n3) / 2; - int n10 = n + n9; - int n11 = n + n5 - n3 - n9; - int n12 = n10 + (int)((float)(n11 - n10) * f); - int n13 = n2 + n9; - if (f2 > 0.0f) { - int n14 = (int)(50.0f * f2); - int n15 = n14 << 24 | 0xFFFFFF; - float f6 = (float)n3 + 2.0f * f3; - RenderUtil.drawRoundedRect(guiGraphics.pose(), n12 - 1, n13 - 1, f6, f6, f6 / 2.0f, this.applyAlpha(n15, f4)); + RenderUtil.drawRoundedRect(guiGraphics.pose(), toggleX, toggleY, toggleWidth, toggleHeight, (float)toggleHeight / 2.0f, trackColorAlpha); + overlayColor = unit - (int)(4.0f * scale); + int knobInset = (toggleHeight - overlayColor) / 2; + int knobMinX = toggleX + knobInset; + int knobMaxX = toggleX + toggleWidth - overlayColor - knobInset; + int knobX = knobMinX + (int)((float)(knobMaxX - knobMinX) * enabledFactor); + int knobY = toggleY + knobInset; + if (hoverFactor > 0.0f) { + int highlightAlpha = (int)(50.0f * hoverFactor); + int highlightColor = highlightAlpha << 24 | 0xFFFFFF; + float highlightSize = (float)overlayColor + 2.0f * scale; + RenderUtil.drawRoundedRect(guiGraphics.pose(), knobX - 1, knobY - 1, highlightSize, highlightSize, highlightSize / 2.0f, this.applyAlpha(highlightColor, alpha)); } - RenderUtil.drawRoundedRect(guiGraphics.pose(), n12, n13, n3, n3, (float)n3 / 2.0f, this.applyAlpha(-1, f4)); + RenderUtil.drawRoundedRect(guiGraphics.pose(), knobX, knobY, overlayColor, overlayColor, (float)overlayColor / 2.0f, this.applyAlpha(-1, alpha)); } - private int renderWrappedText(String string, int n, int n2, int n3, FontRenderer fontRenderer, int n4, float f, float f2) { - String[] stringArray = string.split(" "); - StringBuilder stringBuilder = new StringBuilder(); - int n5 = n2; - int n6 = (int)(16.0f * f2); - for (String string2 : stringArray) { - String string3 = stringBuilder.length() == 0 ? string2 : stringBuilder + " " + string2; - float f3 = GlHelper.getStringWidth(string3, fontRenderer); - if (f3 > (float)n3 && stringBuilder.length() > 0) { - GlHelper.drawText(stringBuilder.toString(), n, n5, fontRenderer, this.applyAlpha(n4, f)); - stringBuilder = new StringBuilder(string2); - n5 += n6; + private int renderWrappedText(String text, int x, int y, int maxWidth, FontRenderer fontRenderer, int textColor, float alpha, float scale) { + String[] words = text.split(" "); + StringBuilder line = new StringBuilder(); + int currentY = y; + int lineHeight = (int)(16.0f * scale); + for (String word : words) { + String candidate = line.length() == 0 ? word : line + " " + word; + float candidateWidth = GlHelper.getStringWidth(candidate, fontRenderer); + if (candidateWidth > (float)maxWidth && line.length() > 0) { + GlHelper.drawText(line.toString(), x, currentY, fontRenderer, this.applyAlpha(textColor, alpha)); + line = new StringBuilder(word); + currentY += lineHeight; continue; } - stringBuilder = new StringBuilder(string3); + line = new StringBuilder(candidate); } - if (stringBuilder.length() > 0) { - GlHelper.drawText(stringBuilder.toString(), n, n5, fontRenderer, this.applyAlpha(n4, f)); + if (line.length() > 0) { + GlHelper.drawText(line.toString(), x, currentY, fontRenderer, this.applyAlpha(textColor, alpha)); } - return n5 - n2 + n6; + return currentY - y + lineHeight; } private String getModuleDescription(Module module) { @@ -291,162 +291,162 @@ extends ClientBase { } } - private void calculateTotalHeight(Module module, float f) { + private void calculateTotalHeight(Module module, float scale) { if (module == null) { this.totalContentHeight = 0.0f; return; } - List> list = module.getSettings(); - if (list != null && !list.isEmpty()) { - int n = 0; - for (Setting setting : list) { + List> settings = module.getSettings(); + if (settings != null && !settings.isEmpty()) { + int total = 0; + for (Setting setting : settings) { if (setting.getVisibility() != null && !setting.getVisibility().displayable()) continue; - n += SettingRendererRegistry.getInstance().getHeightForScroll(setting, f); + total += SettingRendererRegistry.getInstance().getHeightForScroll(setting, scale); } - this.totalContentHeight = n; + this.totalContentHeight = total; } else { - String string = this.getModuleDescription(module); - if (string != null && !string.isEmpty()) { - FontRenderer fontRenderer = FontPresets.axiformaRegular(12.0f * f); - this.totalContentHeight = this.calcWrappedTextHeight(string, (int)(385.0f * f), fontRenderer, f); + String description = this.getModuleDescription(module); + if (description != null && !description.isEmpty()) { + FontRenderer fontRenderer = FontPresets.axiformaRegular(12.0f * scale); + this.totalContentHeight = this.calcWrappedTextHeight(description, (int)(385.0f * scale), fontRenderer, scale); } else { this.totalContentHeight = 0.0f; } } } - private int calcWrappedTextHeight(String string, int n, FontRenderer fontRenderer, float f) { - if (string == null || string.isEmpty()) { + private int calcWrappedTextHeight(String text, int maxWidth, FontRenderer fontRenderer, float scale) { + if (text == null || text.isEmpty()) { return 0; } - String[] stringArray = string.split(" "); - StringBuilder stringBuilder = new StringBuilder(); - int n2 = 1; - int n3 = (int)(16.0f * f); - for (String string2 : stringArray) { - String string3; - String string4 = string3 = stringBuilder.length() == 0 ? string2 : stringBuilder + " " + string2; - if (GlHelper.getStringWidth(string3, fontRenderer) > (float)n && stringBuilder.length() > 0) { - ++n2; - stringBuilder = new StringBuilder(string2); + String[] words = text.split(" "); + StringBuilder line = new StringBuilder(); + int lines = 1; + int lineHeight = (int)(16.0f * scale); + for (String word : words) { + String candidate; + String dup = candidate = line.length() == 0 ? word : line + " " + word; + if (GlHelper.getStringWidth(candidate, fontRenderer) > (float)maxWidth && line.length() > 0) { + ++lines; + line = new StringBuilder(word); continue; } - stringBuilder = new StringBuilder(string3); + line = new StringBuilder(candidate); } - return n2 * n3; + return lines * lineHeight; } - private int applyAlpha(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = (int)((float)n2 * f); - return n3 << 24 | n & 0xFFFFFF; + private int applyAlpha(int color, float alpha) { + int origAlpha = color >> 24 & 0xFF; + int newAlpha = (int)((float)origAlpha * alpha); + return newAlpha << 24 | color & 0xFFFFFF; } - private int brightenColor(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = n >> 16 & 0xFF; - int n4 = n >> 8 & 0xFF; - int n5 = n & 0xFF; - n3 = Math.min(255, (int)((float)n3 * f)); - n4 = Math.min(255, (int)((float)n4 * f)); - n5 = Math.min(255, (int)((float)n5 * f)); - return n2 << 24 | n3 << 16 | n4 << 8 | n5; + private int brightenColor(int color, float factor) { + int a = color >> 24 & 0xFF; + int r = color >> 16 & 0xFF; + int g = color >> 8 & 0xFF; + int b = color & 0xFF; + r = Math.min(255, (int)((float)r * factor)); + g = Math.min(255, (int)((float)g * factor)); + b = Math.min(255, (int)((float)b * factor)); + return a << 24 | r << 16 | g << 8 | b; } - public boolean onMouseClick(int n, int n2, int n3, int n4, int n5, float f) { + public boolean onMouseClick(int originX, int originY, int mouseX, int mouseY, int button, float scale) { if (this.animationState != SettingsPanel.AnimationState.NONE) { return true; } if (this.currentModule == null) { return false; } - int n6 = (int)(405.0f * f); - int n7 = (int)(20.0f * f); - int n8 = (int)(20.0f * f); - int n9 = (int)(400.0f * f); - int n10 = (int)(30.0f * f); - int n11 = (int)(10.0f * f); - int n12 = n + (int)(600.0f * f) - n6 - n7 + (int)(8.0f * f); - int n13 = n2 + n8 + (int)(23.0f * f); - int n14 = n9 - 2 * n7 - (int)(20.0f * f); - float f2 = n14 - n10 - n11; - if (this.totalContentHeight > f2) { - float f3 = this.totalContentHeight - f2; - float f4 = Math.max(20.0f * f, f2 / this.totalContentHeight * f2); - float f5 = (float)(n13 + n10) + this.scrollOffset / f3 * (f2 - f4); - float f6 = 4.0f * f; - int n15 = n12 + n6 - (int)f6 - 2; - if (n3 >= n15 && (float)n3 <= (float)n15 + f6 && (float)n4 >= f5 && (float)n4 <= f5 + f4) { + int panelWidth = (int)(405.0f * scale); + int marginX = (int)(20.0f * scale); + int marginY = (int)(20.0f * scale); + int baseSize = (int)(400.0f * scale); + int headerHeight = (int)(30.0f * scale); + int bottomPadding = (int)(10.0f * scale); + int panelX = originX + (int)(600.0f * scale) - panelWidth - marginX + (int)(8.0f * scale); + int panelY = originY + marginY + (int)(23.0f * scale); + int panelHeight = baseSize - 2 * marginX - (int)(20.0f * scale); + float visibleHeight = panelHeight - headerHeight - bottomPadding; + if (this.totalContentHeight > visibleHeight) { + float maxScroll = this.totalContentHeight - visibleHeight; + float thumbHeight = Math.max(20.0f * scale, visibleHeight / this.totalContentHeight * visibleHeight); + float thumbY = (float)(panelY + headerHeight) + this.scrollOffset / maxScroll * (visibleHeight - thumbHeight); + float thumbWidth = 4.0f * scale; + int thumbX = panelX + panelWidth - (int)thumbWidth - 2; + if (mouseX >= thumbX && (float)mouseX <= (float)thumbX + thumbWidth && (float)mouseY >= thumbY && (float)mouseY <= thumbY + thumbHeight) { this.isDraggingScrollbar = true; - this.scrollbarDragStartY = n4; + this.scrollbarDragStartY = mouseY; this.scrollOffsetAtDragStart = this.scrollOffset; this.lastScrollTime = System.currentTimeMillis(); return true; } } - int n16 = (int)(12.0f * f); - int n17 = (int)(15.0f * f); - int n18 = n12 + n6 - n16 * 2 - n17; - int n19 = n13 + (n10 - n16) / 2; - if (n5 == 0 && n3 >= n18 && n3 <= n18 + n16 * 2 && n4 >= n19 && n4 <= n19 + n16) { + int toggleHeight = (int)(12.0f * scale); + int toggleRightPadding = (int)(15.0f * scale); + int toggleX = panelX + panelWidth - toggleHeight * 2 - toggleRightPadding; + int toggleY = panelY + (headerHeight - toggleHeight) / 2; + if (button == 0 && mouseX >= toggleX && mouseX <= toggleX + toggleHeight * 2 && mouseY >= toggleY && mouseY <= toggleY + toggleHeight) { this.currentModule.toggle(); - String string = this.currentModule.isEnabled() ? "On" : "Off"; - PanelClickGui.panelClickGui.addToast(this.currentModule.getName() + " Module " + string); + String stateLabel = this.currentModule.isEnabled() ? "On" : "Off"; + PanelClickGui.panelClickGui.addToast(this.currentModule.getName() + " Module " + stateLabel); return true; } - List> list = this.currentModule.getSettings(); - if (list != null && !list.isEmpty()) { - int n20 = n13 + n10; - int n21 = n4 + (int)this.scrollOffset; - for (Setting setting : list) { + List> settings = this.currentModule.getSettings(); + if (settings != null && !settings.isEmpty()) { + int settingY = panelY + headerHeight; + int adjustedMouseY = mouseY + (int)this.scrollOffset; + for (Setting setting : settings) { if (setting.getVisibility() != null && !setting.getVisibility().displayable()) continue; - int n22 = SettingRendererRegistry.getInstance().getHeightForScroll(setting, f); - if (n21 >= n20 && n21 <= n20 + n22 && SettingRendererRegistry.getInstance().onClick(setting, n12 + (int)(10.0f * f), n20 - (int)this.scrollOffset, n6 - (int)(20.0f * f), n3, n4, n5, f)) { + int settingHeight = SettingRendererRegistry.getInstance().getHeightForScroll(setting, scale); + if (adjustedMouseY >= settingY && adjustedMouseY <= settingY + settingHeight && SettingRendererRegistry.getInstance().onClick(setting, panelX + (int)(10.0f * scale), settingY - (int)this.scrollOffset, panelWidth - (int)(20.0f * scale), mouseX, mouseY, button, scale)) { return true; } - n20 += n22; + settingY += settingHeight; } } return false; } - public boolean isMouseOverPanel(int n, int n2, int n3, int n4, float f) { + public boolean isMouseOverPanel(int originX, int originY, int mouseX, int mouseY, float scale) { if (this.currentModule == null) { return false; } - int n5 = (int)(405.0f * f); - int n6 = (int)(20.0f * f); - int n7 = (int)(20.0f * f); - int n8 = (int)(400.0f * f); - int n9 = n + (int)(600.0f * f) - n5 - n6 + (int)(8.0f * f); - int n10 = n2 + n7 + (int)(23.0f * f); - int n11 = n8 - 2 * n6 - (int)(20.0f * f); - return n3 >= n9 && n3 <= n9 + n5 && n4 >= n10 && n4 <= n10 + n11; + int panelWidth = (int)(405.0f * scale); + int marginX = (int)(20.0f * scale); + int marginY = (int)(20.0f * scale); + int baseSize = (int)(400.0f * scale); + int panelX = originX + (int)(600.0f * scale) - panelWidth - marginX + (int)(8.0f * scale); + int panelY = originY + marginY + (int)(23.0f * scale); + int panelHeight = baseSize - 2 * marginX - (int)(20.0f * scale); + return mouseX >= panelX && mouseX <= panelX + panelWidth && mouseY >= panelY && mouseY <= panelY + panelHeight; } - public void onScroll(double d, float f) { - int n = (int)(400.0f * f) - (int)(40.0f * f) - (int)(20.0f * f); - float f2 = (float)n - 30.0f * f - 10.0f * f; - if (this.totalContentHeight > f2) { - float f3 = this.totalContentHeight - f2; - this.scrollTarget -= (float)d * 18.0f * f; - this.scrollTarget = Math.max(0.0f, Math.min(this.scrollTarget, f3)); + public void onScroll(double scrollDelta, float scale) { + int contentHeight = (int)(400.0f * scale) - (int)(40.0f * scale) - (int)(20.0f * scale); + float visibleHeight = (float)contentHeight - 30.0f * scale - 10.0f * scale; + if (this.totalContentHeight > visibleHeight) { + float maxScroll = this.totalContentHeight - visibleHeight; + this.scrollTarget -= (float)scrollDelta * 18.0f * scale; + this.scrollTarget = Math.max(0.0f, Math.min(this.scrollTarget, maxScroll)); this.lastScrollTime = System.currentTimeMillis(); } } - public void onMouseDrag(double d, double d2, float f) { + public void onMouseDrag(double mouseX, double mouseY, float scale) { if (this.isDraggingScrollbar) { - int n = (int)(400.0f * f) - (int)(40.0f * f) - (int)(20.0f * f); - float f2 = (float)n - 30.0f * f - 10.0f * f; - float f3 = this.totalContentHeight - f2; - float f4 = Math.max(20.0f * f, f2 / this.totalContentHeight * f2); - float f5 = f2 - f4; - if (f5 > 0.0f) { - float f6 = (float)d2 - this.scrollbarDragStartY; - float f7 = f6 / f5 * f3; - this.scrollOffset = this.scrollOffsetAtDragStart + f7; - this.scrollTarget = this.scrollOffset = Math.max(0.0f, Math.min(this.scrollOffset, f3)); + int contentHeight = (int)(400.0f * scale) - (int)(40.0f * scale) - (int)(20.0f * scale); + float visibleHeight = (float)contentHeight - 30.0f * scale - 10.0f * scale; + float maxScroll = this.totalContentHeight - visibleHeight; + float thumbHeight = Math.max(20.0f * scale, visibleHeight / this.totalContentHeight * visibleHeight); + float trackHeight = visibleHeight - thumbHeight; + if (trackHeight > 0.0f) { + float dragDeltaY = (float)mouseY - this.scrollbarDragStartY; + float scrollDelta = dragDeltaY / trackHeight * maxScroll; + this.scrollOffset = this.scrollOffsetAtDragStart + scrollDelta; + this.scrollTarget = this.scrollOffset = Math.max(0.0f, Math.min(this.scrollOffset, maxScroll)); } this.lastScrollTime = System.currentTimeMillis(); } @@ -454,19 +454,19 @@ extends ClientBase { for (Setting setting : this.currentModule.getSettings()) { SettingRenderer settingRenderer; if (setting.getVisibility() != null && !setting.getVisibility().displayable() || (settingRenderer = SettingRendererRegistry.getInstance().findRenderer(setting)) == null) continue; - settingRenderer.onMouseMove(d, d2); + settingRenderer.onMouseMove(mouseX, mouseY); } } } - public void onMouseRelease(double d, double d2, int n) { + public void onMouseRelease(double mouseX, double mouseY, int button) { this.isDraggingScrollbar = false; this.lastScrollTime = System.currentTimeMillis(); if (this.currentModule != null) { for (Setting setting : this.currentModule.getSettings()) { SettingRenderer settingRenderer; if (setting.getVisibility() != null && !setting.getVisibility().displayable() || (settingRenderer = SettingRendererRegistry.getInstance().findRenderer(setting)) == null) continue; - settingRenderer.onMouseRelease(d, d2, n); + settingRenderer.onMouseRelease(mouseX, mouseY, button); } } } @@ -479,40 +479,40 @@ extends ClientBase { this.currentModule = module; } - private int lerpColor(int n, int n2, float f) { - float f2 = 1.0f - f; - int n3 = n >> 24 & 0xFF; - int n4 = n >> 16 & 0xFF; - int n5 = n >> 8 & 0xFF; - int n6 = n & 0xFF; - int n7 = n2 >> 24 & 0xFF; - int n8 = n2 >> 16 & 0xFF; - int n9 = n2 >> 8 & 0xFF; - int n10 = n2 & 0xFF; - int n11 = (int)((float)n3 * f2 + (float)n7 * f); - int n12 = (int)((float)n4 * f2 + (float)n8 * f); - int n13 = (int)((float)n5 * f2 + (float)n9 * f); - int n14 = (int)((float)n6 * f2 + (float)n10 * f); - return n11 << 24 | n12 << 16 | n13 << 8 | n14; + private int lerpColor(int fromColor, int toColor, float t) { + float inv = 1.0f - t; + int aFrom = fromColor >> 24 & 0xFF; + int rFrom = fromColor >> 16 & 0xFF; + int gFrom = fromColor >> 8 & 0xFF; + int bFrom = fromColor & 0xFF; + int aTo = toColor >> 24 & 0xFF; + int rTo = toColor >> 16 & 0xFF; + int gTo = toColor >> 8 & 0xFF; + int bTo = toColor & 0xFF; + int a = (int)((float)aFrom * inv + (float)aTo * t); + int r = (int)((float)rFrom * inv + (float)rTo * t); + int g = (int)((float)gFrom * inv + (float)gTo * t); + int b = (int)((float)bFrom * inv + (float)bTo * t); + return a << 24 | r << 16 | g << 8 | b; } - private void rescaleScroll(float f) { - float f2; - int n; - float f3; + private void rescaleScroll(float scale) { + float headerHeight; + int contentHeight; + float visibleHeight; if (this.lastScale <= 0.0f) { return; } - float f4 = f / this.lastScale; - this.scrollOffset *= f4; - this.scrollTarget *= f4; + float scaleRatio = scale / this.lastScale; + this.scrollOffset *= scaleRatio; + this.scrollTarget *= scaleRatio; if (this.currentModule != null) { - this.calculateTotalHeight(this.currentModule, f); + this.calculateTotalHeight(this.currentModule, scale); } - if (this.totalContentHeight > (f3 = (float)(n = (int)(400.0f * f) - (int)(40.0f * f) - (int)(20.0f * f)) - (f2 = 30.0f * f))) { - float f5 = this.totalContentHeight - f3; - this.scrollOffset = Math.max(0.0f, Math.min(this.scrollOffset, f5)); - this.scrollTarget = Math.max(0.0f, Math.min(this.scrollTarget, f5)); + if (this.totalContentHeight > (visibleHeight = (float)(contentHeight = (int)(400.0f * scale) - (int)(40.0f * scale) - (int)(20.0f * scale)) - (headerHeight = 30.0f * scale))) { + float maxScroll = this.totalContentHeight - visibleHeight; + this.scrollOffset = Math.max(0.0f, Math.min(this.scrollOffset, maxScroll)); + this.scrollTarget = Math.max(0.0f, Math.min(this.scrollTarget, maxScroll)); } else { this.scrollOffset = 0.0f; this.scrollTarget = 0.0f; diff --git a/src/main/java/shit/zen/gui/panel/SettingsPopup.java b/src/main/java/shit/zen/gui/panel/SettingsPopup.java index 2ab85ca..3c3148e 100644 --- a/src/main/java/shit/zen/gui/panel/SettingsPopup.java +++ b/src/main/java/shit/zen/gui/panel/SettingsPopup.java @@ -40,8 +40,8 @@ extends ClientBase { private static final Color POPUP_BG_COLOR = new Color(20, 20, 24, 230); private final Consumer scaleChangeCallback; - public SettingsPopup(Consumer consumer) { - this.scaleChangeCallback = consumer; + public SettingsPopup(Consumer scaleChangeCallback) { + this.scaleChangeCallback = scaleChangeCallback; this.dropdownOpen.put("language", false); this.dropdownOpen.put("scale", false); this.dropdownAlpha.put("language", Float.valueOf(0.0f)); @@ -50,129 +50,129 @@ extends ClientBase { this.dropdownItemHover.put("scale", new HashMap<>()); } - public void render(GuiGraphics guiGraphics, int n, int n2, float f, float f2) { - this.updatePopupPosition(n, n2, f); + public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float scale, float alpha) { + this.updatePopupPosition(mouseX, mouseY, scale); this.updateOpenAlpha(); this.updateCloseButtonHover(); this.updateDropdownAlpha(); if (this.openAlpha > 0.01f) { - this.clampPopupPosition(f); - this.renderPopupContent(guiGraphics, n, n2, f, f2); + this.clampPopupPosition(scale); + this.renderPopupContent(guiGraphics, mouseX, mouseY, scale, alpha); } } - private void renderPopupContent(GuiGraphics guiGraphics, int n, int n2, float f, float f2) { - int n3 = (int)(220.0f * f); - int n4 = this.calculatePopupHeight(f); - int n5 = mc.getWindow().getGuiScaledWidth(); - int n6 = mc.getWindow().getGuiScaledHeight(); - int n7 = (n5 - n3) / 2 + this.offsetX; - int n8 = (n6 - (int)(200.0f * f)) / 2 + this.offsetY; - float f3 = this.openAlpha * f2; - int n9 = (int)(255.0f * f3); - TextGlow.drawBackground(guiGraphics.pose(), n7, n8, n3, n4, 12.0f * f, f3); - Renderer.renderConsumer((drawContext -> this.drawPopupBody(drawContext, guiGraphics, n7, n8, n, n2, n4, n9, f, n3))); + private void renderPopupContent(GuiGraphics guiGraphics, int mouseX, int mouseY, float scale, float alpha) { + int popupWidth = (int)(220.0f * scale); + int popupHeight = this.calculatePopupHeight(scale); + int screenWidth = mc.getWindow().getGuiScaledWidth(); + int screenHeight = mc.getWindow().getGuiScaledHeight(); + int popupX = (screenWidth - popupWidth) / 2 + this.offsetX; + int popupY = (screenHeight - (int)(200.0f * scale)) / 2 + this.offsetY; + float effectiveAlpha = this.openAlpha * alpha; + int alphaByte = (int)(255.0f * effectiveAlpha); + TextGlow.drawBackground(guiGraphics.pose(), popupX, popupY, popupWidth, popupHeight, 12.0f * scale, effectiveAlpha); + Renderer.renderConsumer((drawContext -> this.drawPopupBody(drawContext, guiGraphics, popupX, popupY, mouseX, mouseY, popupHeight, alphaByte, scale, popupWidth))); } - private void drawPopupBody(DrawContext drawContext, GuiGraphics guiGraphics, int n, int n2, int n3, int n4, int n5, int n6, float f, int n7) { - int n8 = n6 << 24 | 0xFFFFFF; - FontRenderer fontRenderer = FontPresets.materialIcons(18.0f * f); - GlHelper.drawText("", (float)n + 15.0f * f, (float)n2 + 16.0f * f, fontRenderer, n8); - FontRenderer fontRenderer2 = FontPresets.museoSans(22.0f * f); - String string = "ZENLESS.ZONE"; - float f2 = GlHelper.getStringWidth(string, fontRenderer2); - GlHelper.drawText(string, (float)n + ((float)n7 - f2) / 2.0f, (float)n2 + 35.0f * f, fontRenderer2, n8); - this.drawCloseButton(n, n2, fontRenderer, n6, f, n7); - FontRenderer fontRenderer3 = FontPresets.axiformaRegular(13.0f * f); - FontRenderer fontRenderer4 = FontPresets.axiformaRegular(13.0f * f); - int n9 = n6 << 24 | 0xAAAAAA; - int n10 = n6 << 24 | 0xFFFFFF; - int n11 = (int)(18.0f * f); - int n12 = (int)((float)n2 + 65.0f * f); - int n13 = (int)((float)(n + n7) - 15.0f * f); - GlHelper.drawText("Username:", (float)n + 15.0f * f, n12, fontRenderer3, n9); - String string2 = this.getUserId(); - float f3 = GlHelper.getStringWidth(string2, fontRenderer4); - GlHelper.drawText(string2, (float)n13 - f3, n12, fontRenderer4, n10); - GlHelper.drawText("Branch:", (float)n + 15.0f * f, n12 += n11, fontRenderer3, n9); - String string3 = this.getUserRole(); - float f4 = GlHelper.getStringWidth(string3, fontRenderer4); - GlHelper.drawText(string3, (float)n13 - f4, n12, fontRenderer4, n10); - GlHelper.drawText("Updated:", (float)n + 15.0f * f, n12 += n11, fontRenderer3, n9); - String string4 = "Aug 4 2025"; - float f5 = GlHelper.getStringWidth(string4, fontRenderer4); - GlHelper.drawText(string4, (float)n13 - f5, n12, fontRenderer4, n10); - n12 += n11; - n12 = (int)((float)n12 + 8.0f * f); - n12 += this.drawDropdown(drawContext, guiGraphics, "Language", this.selectedLanguage, LANGUAGES, "language", n, n12, n3, n4, this.openAlpha, f, n7); - n12 = (int)((float)n12 + 8.0f * f); - this.drawDropdown(drawContext, guiGraphics, "Menu Scale", this.selectedScale, SCALES, "scale", n, n12, n3, n4, this.openAlpha, f, n7); - FontRenderer fontRenderer5 = FontPresets.axiformaRegular(12.0f * f); - String string5 = "7unknown © 2024-2025"; - float f6 = GlHelper.getStringWidth(string5, fontRenderer5); - GlHelper.drawText(string5, (float)n + ((float)n7 - f6) / 2.0f, (float)(n2 + n5) - 15.0f * f, fontRenderer5, n9); + private void drawPopupBody(DrawContext drawContext, GuiGraphics guiGraphics, int popupX, int popupY, int mouseX, int mouseY, int popupHeight, int alphaByte, float scale, int popupWidth) { + int whiteColor = alphaByte << 24 | 0xFFFFFF; + FontRenderer iconFont = FontPresets.materialIcons(18.0f * scale); + GlHelper.drawText("", (float)popupX + 15.0f * scale, (float)popupY + 16.0f * scale, iconFont, whiteColor); + FontRenderer titleFont = FontPresets.museoSans(22.0f * scale); + String title = "ZENLESS.ZONE"; + float titleWidth = GlHelper.getStringWidth(title, titleFont); + GlHelper.drawText(title, (float)popupX + ((float)popupWidth - titleWidth) / 2.0f, (float)popupY + 35.0f * scale, titleFont, whiteColor); + this.drawCloseButton(popupX, popupY, iconFont, alphaByte, scale, popupWidth); + FontRenderer labelFont = FontPresets.axiformaRegular(13.0f * scale); + FontRenderer valueFont = FontPresets.axiformaRegular(13.0f * scale); + int labelColor = alphaByte << 24 | 0xAAAAAA; + int valueColor = alphaByte << 24 | 0xFFFFFF; + int rowHeight = (int)(18.0f * scale); + int rowY = (int)((float)popupY + 65.0f * scale); + int rightEdge = (int)((float)(popupX + popupWidth) - 15.0f * scale); + GlHelper.drawText("Username:", (float)popupX + 15.0f * scale, rowY, labelFont, labelColor); + String userId = this.getUserId(); + float userIdWidth = GlHelper.getStringWidth(userId, valueFont); + GlHelper.drawText(userId, (float)rightEdge - userIdWidth, rowY, valueFont, valueColor); + GlHelper.drawText("Branch:", (float)popupX + 15.0f * scale, rowY += rowHeight, labelFont, labelColor); + String userRole = this.getUserRole(); + float roleWidth = GlHelper.getStringWidth(userRole, valueFont); + GlHelper.drawText(userRole, (float)rightEdge - roleWidth, rowY, valueFont, valueColor); + GlHelper.drawText("Updated:", (float)popupX + 15.0f * scale, rowY += rowHeight, labelFont, labelColor); + String updatedDate = "Aug 4 2025"; + float dateWidth = GlHelper.getStringWidth(updatedDate, valueFont); + GlHelper.drawText(updatedDate, (float)rightEdge - dateWidth, rowY, valueFont, valueColor); + rowY += rowHeight; + rowY = (int)((float)rowY + 8.0f * scale); + rowY += this.drawDropdown(drawContext, guiGraphics, "Language", this.selectedLanguage, LANGUAGES, "language", popupX, rowY, mouseX, mouseY, this.openAlpha, scale, popupWidth); + rowY = (int)((float)rowY + 8.0f * scale); + this.drawDropdown(drawContext, guiGraphics, "Menu Scale", this.selectedScale, SCALES, "scale", popupX, rowY, mouseX, mouseY, this.openAlpha, scale, popupWidth); + FontRenderer footerFont = FontPresets.axiformaRegular(12.0f * scale); + String footer = "7unknown © 2024-2025"; + float footerWidth = GlHelper.getStringWidth(footer, footerFont); + GlHelper.drawText(footer, (float)popupX + ((float)popupWidth - footerWidth) / 2.0f, (float)(popupY + popupHeight) - 15.0f * scale, footerFont, labelColor); } - private void drawCloseButton(int n, int n2, FontRenderer fontRenderer, int n3, float f, int n4) { - float f2 = (float)(n + n4) - 25.0f * f; - float f3 = (float)n2 + 16.0f * f; - Color color = new Color(255, 255, 255); - Color color2 = new Color(255, 255, 255); - int n5 = (int)((float)color.getRed() + (float)(color2.getRed() - color.getRed()) * this.closeButtonHoverAlpha); - int n6 = (int)((float)color.getGreen() + (float)(color2.getGreen() - color.getGreen()) * this.closeButtonHoverAlpha); - int n7 = (int)((float)color.getBlue() + (float)(color2.getBlue() - color.getBlue()) * this.closeButtonHoverAlpha); - int n8 = n3 << 24 | n5 << 16 | n6 << 8 | n7; - int n9 = (int)(180.0f * this.closeButtonHoverAlpha * this.openAlpha); - int n10 = new Color(n5, n6, n7, n9).getRGB(); - TextGlow.drawGlowText("", f2, f3, fontRenderer, n8, n10, 10.0f * f); + private void drawCloseButton(int popupX, int popupY, FontRenderer iconFont, int alphaByte, float scale, int popupWidth) { + float btnX = (float)(popupX + popupWidth) - 25.0f * scale; + float btnY = (float)popupY + 16.0f * scale; + Color colorFrom = new Color(255, 255, 255); + Color colorTo = new Color(255, 255, 255); + int r = (int)((float)colorFrom.getRed() + (float)(colorTo.getRed() - colorFrom.getRed()) * this.closeButtonHoverAlpha); + int g = (int)((float)colorFrom.getGreen() + (float)(colorTo.getGreen() - colorFrom.getGreen()) * this.closeButtonHoverAlpha); + int b = (int)((float)colorFrom.getBlue() + (float)(colorTo.getBlue() - colorFrom.getBlue()) * this.closeButtonHoverAlpha); + int textColor = alphaByte << 24 | r << 16 | g << 8 | b; + int glowAlpha = (int)(180.0f * this.closeButtonHoverAlpha * this.openAlpha); + int glowColor = new Color(r, g, b, glowAlpha).getRGB(); + TextGlow.drawGlowText("", btnX, btnY, iconFont, textColor, glowColor, 10.0f * scale); } - private int drawDropdown(DrawContext drawContext, GuiGraphics guiGraphics, String string, String string2, String[] stringArray, String string3, int n, int n2, int n3, int n4, float f, float f2, int n5) { - FontRenderer fontRenderer = FontPresets.axiformaRegular(13.0f * f2); - FontRenderer fontRenderer2 = FontPresets.axiformaRegular(13.0f * f2); - int n6 = this.applyAlpha(new Color(0xAAAAAA).getRGB(), f); - int n7 = this.applyAlpha(new Color(0xFFFFFF).getRGB(), f); - GlHelper.drawText(string, (float)n + 15.0f * f2, (float)n2 + 6.0f * f2, fontRenderer, n6); - int n8 = (int)(90.0f * f2); - int n9 = (int)((float)(n + n5 - n8) - 15.0f * f2); - int n10 = (int)(20.0f * f2); - int n11 = (int)(18.0f * f2); - float f3 = this.dropdownAlpha.getOrDefault(string3, Float.valueOf(0.0f)).floatValue(); - String[] stringArray2 = this.filterDropdownItems(stringArray, string2); - int n12 = (int)((float)(stringArray2.length * n11) * f3); - RenderUtil.drawRoundedRect(guiGraphics.pose(), n9, n2, n8, n10 + n12, 4.0f * f2, this.applyAlpha(POPUP_BG_COLOR.getRGB(), f)); - float f4 = (float)n9 + 8.0f * f2; - float f5 = (float)n2 + (float)n10 / 2.0f - fontRenderer2.getMetrics().capHeight() / 2.0f + 3.0f * f2; - GlHelper.drawText(string2, f4, f5 - 2.0f, fontRenderer2, n7); - FontRenderer fontRenderer3 = FontPresets.materialIcons(18.0f * f2); - String string4 = ""; - float f6 = (float)(n9 + n8) - 18.0f * f2; - float f7 = (float)n2 + (float)n10 / 2.0f + fontRenderer3.getMetrics().capHeight() / 2.0f - 10.5f * f2 + 7.0f; - GlHelper.drawText(string4, f6, f7, fontRenderer3, n7); - if (f3 > 0.01f) { + private int drawDropdown(DrawContext drawContext, GuiGraphics guiGraphics, String label, String selectedValue, String[] items, String key, int popupX, int rowY, int mouseX, int mouseY, float openAlpha, float scale, int popupWidth) { + FontRenderer labelFont = FontPresets.axiformaRegular(13.0f * scale); + FontRenderer valueFont = FontPresets.axiformaRegular(13.0f * scale); + int labelColor = this.applyAlpha(new Color(0xAAAAAA).getRGB(), openAlpha); + int valueColor = this.applyAlpha(new Color(0xFFFFFF).getRGB(), openAlpha); + GlHelper.drawText(label, (float)popupX + 15.0f * scale, (float)rowY + 6.0f * scale, labelFont, labelColor); + int dropdownWidth = (int)(90.0f * scale); + int dropdownX = (int)((float)(popupX + popupWidth - dropdownWidth) - 15.0f * scale); + int dropdownHeaderHeight = (int)(20.0f * scale); + int itemHeight = (int)(18.0f * scale); + float openFactor = this.dropdownAlpha.getOrDefault(key, Float.valueOf(0.0f)).floatValue(); + String[] filteredItems = this.filterDropdownItems(items, selectedValue); + int expandedHeight = (int)((float)(filteredItems.length * itemHeight) * openFactor); + RenderUtil.drawRoundedRect(guiGraphics.pose(), dropdownX, rowY, dropdownWidth, dropdownHeaderHeight + expandedHeight, 4.0f * scale, this.applyAlpha(POPUP_BG_COLOR.getRGB(), openAlpha)); + float valueX = (float)dropdownX + 8.0f * scale; + float valueY = (float)rowY + (float)dropdownHeaderHeight / 2.0f - valueFont.getMetrics().capHeight() / 2.0f + 3.0f * scale; + GlHelper.drawText(selectedValue, valueX, valueY - 2.0f, valueFont, valueColor); + FontRenderer arrowFont = FontPresets.materialIcons(18.0f * scale); + String arrowIcon = ""; + float arrowX = (float)(dropdownX + dropdownWidth) - 18.0f * scale; + float arrowY = (float)rowY + (float)dropdownHeaderHeight / 2.0f + arrowFont.getMetrics().capHeight() / 2.0f - 10.5f * scale + 7.0f; + GlHelper.drawText(arrowIcon, arrowX, arrowY, arrowFont, valueColor); + if (openFactor > 0.01f) { drawContext.save(); - drawContext.clip(Rectangle.ofXYWH(n9, n2 + n10, n8, n12)); - Map map = this.dropdownItemHover.get(string3); - int n13 = n2 + n10; - for (String string5 : stringArray2) { - boolean bl = this.isPointInBounds(n3, n4, n9, n13, n8, n11); - this.updateItemHover(map, string5, bl); - float f8 = map.getOrDefault(string5, 0.0f); - float f9 = (float)n9 + 8.0f * f2; - float f10 = (float)n13 + (float)n11 / 2.0f - fontRenderer2.getMetrics().capHeight() / 2.0f + 3.0f * f2; - int n14 = this.applyAlpha(n7, f3); - float f11 = f8 * f3; - if (f11 > 0.01f) { - int n15 = new Color(1.0f, 1.0f, 1.0f, f11).getRGB(); - TextGlow.drawGlowText(string5, f9, f10, fontRenderer2, n14, n15, 8.0f * f2); + drawContext.clip(Rectangle.ofXYWH(dropdownX, rowY + dropdownHeaderHeight, dropdownWidth, expandedHeight)); + Map itemHovers = this.dropdownItemHover.get(key); + int itemY = rowY + dropdownHeaderHeight; + for (String item : filteredItems) { + boolean hovered = this.isPointInBounds(mouseX, mouseY, dropdownX, itemY, dropdownWidth, itemHeight); + this.updateItemHover(itemHovers, item, hovered); + float hoverAmount = itemHovers.getOrDefault(item, 0.0f); + float itemTextX = (float)dropdownX + 8.0f * scale; + float itemTextY = (float)itemY + (float)itemHeight / 2.0f - valueFont.getMetrics().capHeight() / 2.0f + 3.0f * scale; + int itemColor = this.applyAlpha(valueColor, openFactor); + float glowAmount = hoverAmount * openFactor; + if (glowAmount > 0.01f) { + int glowColor = new Color(1.0f, 1.0f, 1.0f, glowAmount).getRGB(); + TextGlow.drawGlowText(item, itemTextX, itemTextY, valueFont, itemColor, glowColor, 8.0f * scale); } else { - GlHelper.drawText(string5, f9, f10, fontRenderer2, n14); + GlHelper.drawText(item, itemTextX, itemTextY, valueFont, itemColor); } - n13 += n11; + itemY += itemHeight; } drawContext.restore(); } - return n10 + n12; + return dropdownHeaderHeight + expandedHeight; } private String getUserId() { @@ -183,33 +183,33 @@ extends ClientBase { return "User"; } - public boolean onMouseClick(int n, int n2, float f) { - int n3; - int n4; - int n5 = (int)(220.0f * f); - int n6 = this.calculatePopupHeight(f); - int n7 = mc.getWindow().getGuiScaledWidth(); - int n8 = (n7 - n5) / 2 + this.offsetX; - if (this.isMouseOverCloseButton(n, n2, n8, n4 = ((n3 = mc.getWindow().getGuiScaledHeight()) - (int)(200.0f * f)) / 2 + this.offsetY, f, n5)) { + public boolean onMouseClick(int mouseX, int mouseY, float scale) { + int screenHeight; + int popupY; + int popupWidth = (int)(220.0f * scale); + int popupHeight = this.calculatePopupHeight(scale); + int screenWidth = mc.getWindow().getGuiScaledWidth(); + int popupX = (screenWidth - popupWidth) / 2 + this.offsetX; + if (this.isMouseOverCloseButton(mouseX, mouseY, popupX, popupY = ((screenHeight = mc.getWindow().getGuiScaledHeight()) - (int)(200.0f * scale)) / 2 + this.offsetY, scale, popupWidth)) { this.toggleOpen(); return true; } if (this.isDragging) { return true; } - if (this.isMouseInRect(n, n2, n8, n4, f, n5)) { - this.beginDrag(n, n2); + if (this.isMouseInRect(mouseX, mouseY, popupX, popupY, scale, popupWidth)) { + this.beginDrag(mouseX, mouseY); return true; } - int n9 = (int)(90.0f * f); - int n10 = (int)((float)(n8 + n5 - n9) - 15.0f * f); - int n11 = (int)((float)n4 + 127.0f * f); - boolean bl = this.handleDropdownClick(n, n2, n10, n11, n9, LANGUAGES, this.selectedLanguage, "language", value -> { + int dropdownWidth = (int)(90.0f * scale); + int dropdownX = (int)((float)(popupX + popupWidth - dropdownWidth) - 15.0f * scale); + int langRowY = (int)((float)popupY + 127.0f * scale); + boolean langHandled = this.handleDropdownClick(mouseX, mouseY, dropdownX, langRowY, dropdownWidth, LANGUAGES, this.selectedLanguage, "language", value -> { this.selectedLanguage = value; - }, f); - float f2 = (float)this.filterDropdownItems(LANGUAGES, this.selectedLanguage).length * (18.0f * f) * this.dropdownAlpha.getOrDefault("language", 0.0f); - int n12 = (int)((float)n11 + 20.0f * f + f2 + 8.0f * f); - boolean bl2 = this.handleDropdownClick(n, n2, n10, n12, n9, SCALES, this.selectedScale, "scale", value -> { + }, scale); + float langExpanded = (float)this.filterDropdownItems(LANGUAGES, this.selectedLanguage).length * (18.0f * scale) * this.dropdownAlpha.getOrDefault("language", 0.0f); + int scaleRowY = (int)((float)langRowY + 20.0f * scale + langExpanded + 8.0f * scale); + boolean scaleHandled = this.handleDropdownClick(mouseX, mouseY, dropdownX, scaleRowY, dropdownWidth, SCALES, this.selectedScale, "scale", value -> { this.selectedScale = value; try { float parsed = Float.parseFloat(value.replace("%", "")) / 100.0f; @@ -217,12 +217,12 @@ extends ClientBase { } catch (NumberFormatException numberFormatException) { // empty catch block } - }, f); - boolean bl3 = this.isPointInBounds(n, n2, n8, n4, n5, n6); - if (bl || bl2) { + }, scale); + boolean withinPopup = this.isPointInBounds(mouseX, mouseY, popupX, popupY, popupWidth, popupHeight); + if (langHandled || scaleHandled) { return true; } - if (bl3) { + if (withinPopup) { this.dropdownOpen.put("language", false); this.dropdownOpen.put("scale", false); return true; @@ -230,51 +230,51 @@ extends ClientBase { return false; } - private boolean handleDropdownClick(int n, int n2, int n3, int n4, int n5, String[] stringArray, String string3, String string4, Consumer consumer, float f) { - boolean bl = this.dropdownOpen.getOrDefault(string4, false); - int n6 = (int)(18.0f * f); - int n7 = (int)(20.0f * f); - if (this.isPointInBounds(n, n2, n3, n4, n5, n7)) { - this.dropdownOpen.put(string4, !bl); - this.dropdownOpen.keySet().stream().filter(string2 -> !string2.equals(string4)).forEach(string -> this.dropdownOpen.put(string, false)); + private boolean handleDropdownClick(int mouseX, int mouseY, int dropdownX, int dropdownY, int dropdownWidth, String[] items, String selectedValue, String key, Consumer onSelect, float scale) { + boolean open = this.dropdownOpen.getOrDefault(key, false); + int itemHeight = (int)(18.0f * scale); + int headerHeight = (int)(20.0f * scale); + if (this.isPointInBounds(mouseX, mouseY, dropdownX, dropdownY, dropdownWidth, headerHeight)) { + this.dropdownOpen.put(key, !open); + this.dropdownOpen.keySet().stream().filter(otherKey -> !otherKey.equals(key)).forEach(otherKey -> this.dropdownOpen.put(otherKey, false)); return true; } - if (bl) { - String[] stringArray2 = this.filterDropdownItems(stringArray, string3); - for (int i = 0; i < stringArray2.length; ++i) { - if (!this.isPointInBounds(n, n2, n3, n4 + n7 + i * n6, n5, n6)) continue; - consumer.accept(stringArray2[i]); - this.dropdownOpen.put(string4, false); + if (open) { + String[] filtered = this.filterDropdownItems(items, selectedValue); + for (int i = 0; i < filtered.length; ++i) { + if (!this.isPointInBounds(mouseX, mouseY, dropdownX, dropdownY + headerHeight + i * itemHeight, dropdownWidth, itemHeight)) continue; + onSelect.accept(filtered[i]); + this.dropdownOpen.put(key, false); return true; } } return false; } - private boolean isMouseInRect(int n, int n2, int n3, int n4, float f, int n5) { - float f2 = (float)(n3 + n5) - 25.0f * f; - boolean bl = (float)n >= f2 - 10.0f * f && (float)n <= f2 + 15.0f * f; - return n >= n3 && n <= n3 + n5 && n2 >= n4 && (float)n2 <= (float)n4 + 30.0f * f && !bl; + private boolean isMouseInRect(int mouseX, int mouseY, int popupX, int popupY, float scale, int popupWidth) { + float closeBtnX = (float)(popupX + popupWidth) - 25.0f * scale; + boolean overCloseBtn = (float)mouseX >= closeBtnX - 10.0f * scale && (float)mouseX <= closeBtnX + 15.0f * scale; + return mouseX >= popupX && mouseX <= popupX + popupWidth && mouseY >= popupY && (float)mouseY <= (float)popupY + 30.0f * scale && !overCloseBtn; } - private boolean isMouseOverCloseButton(int n, int n2, int n3, int n4, float f, int n5) { - float f2 = (float)(n3 + n5) - 25.0f * f; - float f3 = (float)n4 + 16.0f * f; - return (float)n >= f2 - 10.0f * f && (float)n <= f2 + 15.0f * f && (float)n2 >= f3 - 10.0f * f && (float)n2 <= f3 + 10.0f * f; + private boolean isMouseOverCloseButton(int mouseX, int mouseY, int popupX, int popupY, float scale, int popupWidth) { + float closeBtnX = (float)(popupX + popupWidth) - 25.0f * scale; + float closeBtnY = (float)popupY + 16.0f * scale; + return (float)mouseX >= closeBtnX - 10.0f * scale && (float)mouseX <= closeBtnX + 15.0f * scale && (float)mouseY >= closeBtnY - 10.0f * scale && (float)mouseY <= closeBtnY + 10.0f * scale; } - private void beginDrag(int n, int n2) { + private void beginDrag(int mouseX, int mouseY) { this.isDragging = true; - this.lastDragX = n; - this.lastDragY = n2; + this.lastDragX = mouseX; + this.lastDragY = mouseY; } - public void onMouseDrag(int n, int n2) { + public void onMouseDrag(int mouseX, int mouseY) { if (this.isDragging) { - this.offsetX += n - this.lastDragX; - this.offsetY += n2 - this.lastDragY; - this.lastDragX = n; - this.lastDragY = n2; + this.offsetX += mouseX - this.lastDragX; + this.offsetY += mouseY - this.lastDragY; + this.lastDragX = mouseX; + this.lastDragY = mouseY; } } @@ -303,23 +303,23 @@ extends ClientBase { } private void updateDropdownAlpha() { - for (String string : this.dropdownOpen.keySet()) { - boolean bl = this.dropdownOpen.getOrDefault(string, false); - float f = this.dropdownAlpha.getOrDefault(string, Float.valueOf(0.0f)).floatValue(); - float f2 = bl ? 1.0f : 0.0f; - f = Math.abs(f - f2) > 0.01f ? LerpUtil.smoothLerp(f, f2, 0.22f) : f2; - this.dropdownAlpha.put(string, Float.valueOf(f)); + for (String key : this.dropdownOpen.keySet()) { + boolean open = this.dropdownOpen.getOrDefault(key, false); + float current = this.dropdownAlpha.getOrDefault(key, Float.valueOf(0.0f)).floatValue(); + float target = open ? 1.0f : 0.0f; + current = Math.abs(current - target) > 0.01f ? LerpUtil.smoothLerp(current, target, 0.22f) : target; + this.dropdownAlpha.put(key, Float.valueOf(current)); } } - private void updatePopupPosition(int n, int n2, float f) { + private void updatePopupPosition(int mouseX, int mouseY, float scale) { if (this.isOpen) { - int n3 = (int)(220.0f * f); - int n4 = mc.getWindow().getGuiScaledWidth(); - int n5 = mc.getWindow().getGuiScaledHeight(); - int n6 = (n4 - n3) / 2 + this.offsetX; - int n7 = (n5 - (int)(200.0f * f)) / 2 + this.offsetY; - this.isCloseButtonHovered = this.isMouseOverCloseButton(n, n2, n6, n7, f, n3); + int popupWidth = (int)(220.0f * scale); + int screenWidth = mc.getWindow().getGuiScaledWidth(); + int screenHeight = mc.getWindow().getGuiScaledHeight(); + int popupX = (screenWidth - popupWidth) / 2 + this.offsetX; + int popupY = (screenHeight - (int)(200.0f * scale)) / 2 + this.offsetY; + this.isCloseButtonHovered = this.isMouseOverCloseButton(mouseX, mouseY, popupX, popupY, scale, popupWidth); } else { this.isCloseButtonHovered = false; } @@ -329,45 +329,45 @@ extends ClientBase { this.closeButtonHoverAlpha = this.isCloseButtonHovered ? LerpUtil.lerp(this.closeButtonHoverAlpha, 1.0f, 0.16f) : LerpUtil.lerp(this.closeButtonHoverAlpha, 0.0f, 0.16f); } - private void updateItemHover(Map map, String string, boolean bl) { - float f = map.getOrDefault(string, Float.valueOf(0.0f)).floatValue(); - float f2 = bl ? 1.0f : 0.0f; - f = Math.abs(f - f2) > 0.01f ? LerpUtil.smoothLerp(f, f2, 0.28f) : f2; - map.put(string, Float.valueOf(f)); + private void updateItemHover(Map hoverMap, String key, boolean hovered) { + float current = hoverMap.getOrDefault(key, Float.valueOf(0.0f)).floatValue(); + float target = hovered ? 1.0f : 0.0f; + current = Math.abs(current - target) > 0.01f ? LerpUtil.smoothLerp(current, target, 0.28f) : target; + hoverMap.put(key, Float.valueOf(current)); } - private String[] filterDropdownItems(String[] stringArray, String string) { - return Stream.of((Object[])stringArray).filter(string2 -> !Objects.equals(string2, string)).toArray(String[]::new); + private String[] filterDropdownItems(String[] items, String selectedValue) { + return Stream.of((Object[])items).filter(item -> !Objects.equals(item, selectedValue)).toArray(String[]::new); } - private boolean isPointInBounds(int n, int n2, int n3, int n4, int n5, int n6) { - return n >= n3 && n <= n3 + n5 && n2 >= n4 && n2 <= n4 + n6; + private boolean isPointInBounds(int pointX, int pointY, int boxX, int boxY, int boxWidth, int boxHeight) { + return pointX >= boxX && pointX <= boxX + boxWidth && pointY >= boxY && pointY <= boxY + boxHeight; } - private int applyAlpha(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = (int)((float)n2 * f); - return n3 << 24 | n & 0xFFFFFF; + private int applyAlpha(int color, float alpha) { + int origAlpha = color >> 24 & 0xFF; + int newAlpha = (int)((float)origAlpha * alpha); + return newAlpha << 24 | color & 0xFFFFFF; } - private int calculatePopupHeight(float f) { - float f2 = 200.0f * f; - float f3 = 18.0f * f; - float f4 = (float)this.filterDropdownItems(LANGUAGES, this.selectedLanguage).length * f3 * this.dropdownAlpha.getOrDefault("language", Float.valueOf(0.0f)).floatValue(); - float f5 = (float)this.filterDropdownItems(SCALES, this.selectedScale).length * f3 * this.dropdownAlpha.getOrDefault("scale", Float.valueOf(0.0f)).floatValue(); - return (int)(f2 + f4 + f5); + private int calculatePopupHeight(float scale) { + float baseHeight = 200.0f * scale; + float itemHeight = 18.0f * scale; + float langExpanded = (float)this.filterDropdownItems(LANGUAGES, this.selectedLanguage).length * itemHeight * this.dropdownAlpha.getOrDefault("language", Float.valueOf(0.0f)).floatValue(); + float scaleExpanded = (float)this.filterDropdownItems(SCALES, this.selectedScale).length * itemHeight * this.dropdownAlpha.getOrDefault("scale", Float.valueOf(0.0f)).floatValue(); + return (int)(baseHeight + langExpanded + scaleExpanded); } - private void clampPopupPosition(float f) { - int n = mc.getWindow().getGuiScaledWidth(); - int n2 = mc.getWindow().getGuiScaledHeight(); - int n3 = this.calculatePopupHeight(f); - int n4 = (int)(220.0f * f); - int n5 = (n - n4) / 2; - int n6 = -(n - n4) / 2; - int n7 = (n2 - n3) / 2; - int n8 = -(n2 - (int)(200.0f * f)) / 2; - this.offsetX = Math.max(n6, Math.min(this.offsetX, n5)); - this.offsetY = Math.max(n8, Math.min(this.offsetY, n7)); + private void clampPopupPosition(float scale) { + int screenWidth = mc.getWindow().getGuiScaledWidth(); + int screenHeight = mc.getWindow().getGuiScaledHeight(); + int popupHeight = this.calculatePopupHeight(scale); + int popupWidth = (int)(220.0f * scale); + int maxOffsetX = (screenWidth - popupWidth) / 2; + int minOffsetX = -(screenWidth - popupWidth) / 2; + int maxOffsetY = (screenHeight - popupHeight) / 2; + int minOffsetY = -(screenHeight - (int)(200.0f * scale)) / 2; + this.offsetX = Math.max(minOffsetX, Math.min(this.offsetX, maxOffsetX)); + this.offsetY = Math.max(minOffsetY, Math.min(this.offsetY, maxOffsetY)); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/setting/BooleanSettingRenderer.java b/src/main/java/shit/zen/gui/panel/setting/BooleanSettingRenderer.java index 3cc9495..bc93f29 100644 --- a/src/main/java/shit/zen/gui/panel/setting/BooleanSettingRenderer.java +++ b/src/main/java/shit/zen/gui/panel/setting/BooleanSettingRenderer.java @@ -24,115 +24,115 @@ implements SettingRenderer { private final Map hoverAnimations = new HashMap<>(); @Override - public int render(GuiGraphics guiGraphics, Setting setting, int n, int n2, int n3, int n4, int n5, float f, float f2) { - int n6; + public int render(GuiGraphics guiGraphics, Setting setting, int x, int y, int width, int mouseX, int mouseY, float alpha, float scale) { + int toggleHeight; if (!(setting instanceof BooleanSetting booleanSetting)) { return 0; } - int n7 = Math.round(24.0f * f2); - int n8 = n6 = Math.round(10.0f * f2); - int n9 = Math.round(5.0f * f2); - float f3 = this.toggleAnimations.getOrDefault(booleanSetting, Float.valueOf(booleanSetting.getValue() != false ? 1.0f : 0.0f)).floatValue(); - float f4 = booleanSetting.getValue() != false ? 1.0f : 0.0f; - f3 = Math.abs(f4 - f3) > 0.01f ? LerpUtil.smoothLerp(f3, f4, 0.25f) : f4; - this.toggleAnimations.put(booleanSetting, Float.valueOf(f3)); - int n10 = n6 * 2; - int n11 = n + n3 - n10 - n9; - int n12 = n2 + (n7 - n8) / 2; - this.updateHoverState(booleanSetting, n11, n12, n4, n5, n6); - float f5 = this.hoverAnimations.getOrDefault(booleanSetting, Float.valueOf(0.0f)).floatValue(); - float f6 = this.hoverStates.getOrDefault(booleanSetting, false) != false ? 1.0f : 0.0f; - f5 = Math.abs(f6 - f5) > 0.01f ? LerpUtil.smoothLerp(f5, f6, 0.3f) : f6; - this.hoverAnimations.put(booleanSetting, Float.valueOf(f5)); - FontRenderer fontRenderer = FontPresets.axiformaRegular(14.0f * f2); - float f7 = (float)n2 + (float)n7 / 2.0f - fontRenderer.getMetrics().capHeight() / 2.0f; - TextGlow.drawGlowText(booleanSetting.getName(), n, f7, fontRenderer, this.applyAlpha(-1, f), this.applyAlpha(new Color(255, 255, 255, 120).getRGB(), f), 6.0f * f2); - this.drawToggle(guiGraphics, n11, n12, f3, f5, f, f2); - return n7; + int rowHeight = Math.round(24.0f * scale); + int toggleH = toggleHeight = Math.round(10.0f * scale); + int rightPadding = Math.round(5.0f * scale); + float toggleAnim = this.toggleAnimations.getOrDefault(booleanSetting, Float.valueOf(booleanSetting.getValue() != false ? 1.0f : 0.0f)).floatValue(); + float toggleTarget = booleanSetting.getValue() != false ? 1.0f : 0.0f; + toggleAnim = Math.abs(toggleTarget - toggleAnim) > 0.01f ? LerpUtil.smoothLerp(toggleAnim, toggleTarget, 0.25f) : toggleTarget; + this.toggleAnimations.put(booleanSetting, Float.valueOf(toggleAnim)); + int toggleWidth = toggleHeight * 2; + int toggleX = x + width - toggleWidth - rightPadding; + int toggleY = y + (rowHeight - toggleH) / 2; + this.updateHoverState(booleanSetting, toggleX, toggleY, mouseX, mouseY, toggleHeight); + float hoverAnim = this.hoverAnimations.getOrDefault(booleanSetting, Float.valueOf(0.0f)).floatValue(); + float hoverTarget = this.hoverStates.getOrDefault(booleanSetting, false) != false ? 1.0f : 0.0f; + hoverAnim = Math.abs(hoverTarget - hoverAnim) > 0.01f ? LerpUtil.smoothLerp(hoverAnim, hoverTarget, 0.3f) : hoverTarget; + this.hoverAnimations.put(booleanSetting, Float.valueOf(hoverAnim)); + FontRenderer nameFont = FontPresets.axiformaRegular(14.0f * scale); + float nameY = (float)y + (float)rowHeight / 2.0f - nameFont.getMetrics().capHeight() / 2.0f; + TextGlow.drawGlowText(booleanSetting.getName(), x, nameY, nameFont, this.applyAlpha(-1, alpha), this.applyAlpha(new Color(255, 255, 255, 120).getRGB(), alpha), 6.0f * scale); + this.drawToggle(guiGraphics, toggleX, toggleY, toggleAnim, hoverAnim, alpha, scale); + return rowHeight; } - private int applyAlpha(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = (int)((float)n2 * f); - return n3 << 24 | n & 0xFFFFFF; + private int applyAlpha(int color, float alpha) { + int origAlpha = color >> 24 & 0xFF; + int newAlpha = (int)((float)origAlpha * alpha); + return newAlpha << 24 | color & 0xFFFFFF; } - private void drawToggle(GuiGraphics guiGraphics, int n, int n2, float f, float f2, float f3, float f4) { - int n3 = Math.round(10.0f * f4); - int n4 = n3 * 2; - int n5 = n3; - int n6 = this.lerpColor(COLOR_OFF, COLOR_ON, f); - if (f2 > 0.0f) { - float f5 = 1.0f + 0.3f * f2; - n6 = this.brightenColor(n6, f5); + private void drawToggle(GuiGraphics guiGraphics, int toggleX, int toggleY, float onFactor, float hoverFactor, float alpha, float scale) { + int unit = Math.round(10.0f * scale); + int toggleWidth = unit * 2; + int toggleHeight = unit; + int trackColor = this.lerpColor(COLOR_OFF, COLOR_ON, onFactor); + if (hoverFactor > 0.0f) { + float brightness = 1.0f + 0.3f * hoverFactor; + trackColor = this.brightenColor(trackColor, brightness); } - if (f > 0.01f) { - int n7 = new Color(76, 175, 80, (int)(70.0f * f)).getRGB(); - RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)n - f4, (float)n2 - f4, (float)n4 + 2.0f * f4, (float)n5 + 2.0f * f4, (float)n5 / 2.0f, this.applyAlpha(n7, f3)); + if (onFactor > 0.01f) { + int overlayColor = new Color(76, 175, 80, (int)(70.0f * onFactor)).getRGB(); + RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)toggleX - scale, (float)toggleY - scale, (float)toggleWidth + 2.0f * scale, (float)toggleHeight + 2.0f * scale, (float)toggleHeight / 2.0f, this.applyAlpha(overlayColor, alpha)); } - RenderUtil.drawRoundedRect(guiGraphics.pose(), n, n2, n4, n5, (float)n5 / 2.0f, this.applyAlpha(n6, f3)); - int n8 = Math.round(2.0f * f4); - int n9 = n5 - n8 * 2; - int n10 = n + n8 + Math.round((float)(n4 - n9 - n8 * 2) * f); - int n11 = n2 + n8; - int n12 = -1; - if (f2 > 0.0f) { - int n13 = (int)(50.0f * f2); - int n14 = n13 << 24 | 0xFFFFFF; - RenderUtil.drawRoundedRect(guiGraphics.pose(), n10 - 1, n11 - 1, n9 + 2, n9 + 2, (float)(n9 + 2) / 2.0f, this.applyAlpha(n14, f3)); + RenderUtil.drawRoundedRect(guiGraphics.pose(), toggleX, toggleY, toggleWidth, toggleHeight, (float)toggleHeight / 2.0f, this.applyAlpha(trackColor, alpha)); + int knobInset = Math.round(2.0f * scale); + int knobSize = toggleHeight - knobInset * 2; + int knobX = toggleX + knobInset + Math.round((float)(toggleWidth - knobSize - knobInset * 2) * onFactor); + int knobY = toggleY + knobInset; + int knobColor = -1; + if (hoverFactor > 0.0f) { + int highlightAlpha = (int)(50.0f * hoverFactor); + int highlightColor = highlightAlpha << 24 | 0xFFFFFF; + RenderUtil.drawRoundedRect(guiGraphics.pose(), knobX - 1, knobY - 1, knobSize + 2, knobSize + 2, (float)(knobSize + 2) / 2.0f, this.applyAlpha(highlightColor, alpha)); } - RenderUtil.drawRoundedRect(guiGraphics.pose(), n10, n11, n9, n9, (float)n9 / 2.0f, this.applyAlpha(n12, f3)); + RenderUtil.drawRoundedRect(guiGraphics.pose(), knobX, knobY, knobSize, knobSize, (float)knobSize / 2.0f, this.applyAlpha(knobColor, alpha)); } - private void updateHoverState(BooleanSetting booleanSetting, int n, int n2, int n3, int n4, int n5) { - boolean bl = n3 >= n && n3 <= n + n5 * 2 && n4 >= n2 && n4 <= n2 + n5; - this.hoverStates.put(booleanSetting, bl); + private void updateHoverState(BooleanSetting booleanSetting, int toggleX, int toggleY, int mouseX, int mouseY, int toggleHeight) { + boolean hovered = mouseX >= toggleX && mouseX <= toggleX + toggleHeight * 2 && mouseY >= toggleY && mouseY <= toggleY + toggleHeight; + this.hoverStates.put(booleanSetting, hovered); } - private int brightenColor(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = n >> 16 & 0xFF; - int n4 = n >> 8 & 0xFF; - int n5 = n & 0xFF; - n3 = Math.min(255, (int)((float)n3 * f)); - n4 = Math.min(255, (int)((float)n4 * f)); - n5 = Math.min(255, (int)((float)n5 * f)); - return n2 << 24 | n3 << 16 | n4 << 8 | n5; + private int brightenColor(int color, float factor) { + int a = color >> 24 & 0xFF; + int r = color >> 16 & 0xFF; + int g = color >> 8 & 0xFF; + int b = color & 0xFF; + r = Math.min(255, (int)((float)r * factor)); + g = Math.min(255, (int)((float)g * factor)); + b = Math.min(255, (int)((float)b * factor)); + return a << 24 | r << 16 | g << 8 | b; } - private int lerpColor(int n, int n2, float f) { - int n3 = n >> 24 & 0xFF; - int n4 = n >> 16 & 0xFF; - int n5 = n >> 8 & 0xFF; - int n6 = n & 0xFF; - int n7 = n2 >> 24 & 0xFF; - int n8 = n2 >> 16 & 0xFF; - int n9 = n2 >> 8 & 0xFF; - int n10 = n2 & 0xFF; - int n11 = (int)((float)n3 + (float)(n7 - n3) * f); - int n12 = (int)((float)n4 + (float)(n8 - n4) * f); - int n13 = (int)((float)n5 + (float)(n9 - n5) * f); - int n14 = (int)((float)n6 + (float)(n10 - n6) * f); - return n11 << 24 | n12 << 16 | n13 << 8 | n14; + private int lerpColor(int fromColor, int toColor, float t) { + int aFrom = fromColor >> 24 & 0xFF; + int rFrom = fromColor >> 16 & 0xFF; + int gFrom = fromColor >> 8 & 0xFF; + int bFrom = fromColor & 0xFF; + int aTo = toColor >> 24 & 0xFF; + int rTo = toColor >> 16 & 0xFF; + int gTo = toColor >> 8 & 0xFF; + int bTo = toColor & 0xFF; + int a = (int)((float)aFrom + (float)(aTo - aFrom) * t); + int r = (int)((float)rFrom + (float)(rTo - rFrom) * t); + int g = (int)((float)gFrom + (float)(gTo - gFrom) * t); + int b = (int)((float)bFrom + (float)(bTo - bFrom) * t); + return a << 24 | r << 16 | g << 8 | b; } @Override - public boolean onClick(Setting setting, int n, int n2, int n3, int n4, int n5, int n6, float f) { - int n7; + public boolean onClick(Setting setting, int x, int y, int width, int mouseX, int mouseY, int button, float scale) { + int toggleHeight; if (!(setting instanceof BooleanSetting booleanSetting)) { return false; } - int n8 = Math.round(24.0f * f); - int n9 = n7 = Math.round(10.0f * f); - int n10 = Math.round(5.0f * f); - int n11 = n7 * 2; - int n12 = n + n3 - n11 - n10; - int n13 = n2 + (n8 - n9) / 2; - if (n6 == 0 && n4 >= n12 && n4 <= n12 + n11 && n5 >= n13 && n5 <= n13 + n9) { - boolean bl = booleanSetting.getValue() == false; - booleanSetting.setValue(bl); - String string = bl ? "On" : "Off"; - PanelClickGui.panelClickGui.addToast(booleanSetting.getName() + " is " + string); + int rowHeight = Math.round(24.0f * scale); + int toggleH = toggleHeight = Math.round(10.0f * scale); + int rightPadding = Math.round(5.0f * scale); + int toggleWidth = toggleHeight * 2; + int toggleX = x + width - toggleWidth - rightPadding; + int toggleY = y + (rowHeight - toggleH) / 2; + if (button == 0 && mouseX >= toggleX && mouseX <= toggleX + toggleWidth && mouseY >= toggleY && mouseY <= toggleY + toggleH) { + boolean newValue = booleanSetting.getValue() == false; + booleanSetting.setValue(newValue); + String stateLabel = newValue ? "On" : "Off"; + PanelClickGui.panelClickGui.addToast(booleanSetting.getName() + " is " + stateLabel); return true; } return false; @@ -144,11 +144,11 @@ implements SettingRenderer { } @Override - public int getHeight(Setting setting, float f) { - return Math.round(24.0f * f); + public int getHeight(Setting setting, float scale) { + return Math.round(24.0f * scale); } @Override - public void onMouseRelease(double d, double d2, int n) { + public void onMouseRelease(double mouseX, double mouseY, int button) { } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/setting/ModeSettingRenderer.java b/src/main/java/shit/zen/gui/panel/setting/ModeSettingRenderer.java index 7bd6a15..64b3f19 100644 --- a/src/main/java/shit/zen/gui/panel/setting/ModeSettingRenderer.java +++ b/src/main/java/shit/zen/gui/panel/setting/ModeSettingRenderer.java @@ -26,139 +26,139 @@ implements SettingRenderer { private final Map> itemHoverAnimations = new HashMap<>(); @Override - public int render(GuiGraphics guiGraphics, Setting setting, int n, int n2, int n3, int n4, int n5, float f, float f2) { + public int render(GuiGraphics guiGraphics, Setting setting, int x, int y, int width, int mouseX, int mouseY, float alpha, float scale) { if (!(setting instanceof ModeSetting modeSetting)) { return 0; } this.updateOpenAnimation(modeSetting); - String[] stringArray = Arrays.stream((Object[])modeSetting.getModes()).filter(string -> !Objects.equals(string, modeSetting.getValue())).toArray(String[]::new); - float f3 = this.openAnimations.getOrDefault(modeSetting, Float.valueOf(0.0f)).floatValue(); - int n6 = Math.round(16.0f * f2); - int n7 = Math.round((float)(stringArray.length * n6) * f3); - int n8 = Math.round(24.0f * f2); + String[] otherModes = Arrays.stream((Object[])modeSetting.getModes()).filter(mode -> !Objects.equals(mode, modeSetting.getValue())).toArray(String[]::new); + float openFactor = this.openAnimations.getOrDefault(modeSetting, Float.valueOf(0.0f)).floatValue(); + int itemHeight = Math.round(16.0f * scale); + int expandedHeight = Math.round((float)(otherModes.length * itemHeight) * openFactor); + int rowHeight = Math.round(24.0f * scale); try { - int n9 = Math.round(75.0f * f2); - int n10 = n + n3 - Math.round(80.0f * f2); - int n11 = n2 + 1; - RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)n10, (float)n11, (float)n9, (float)(n6 + n7), 4.0f * f2, this.applyAlpha(DROPDOWN_BG_COLOR, f)); - FontRenderer fontRenderer = FontPresets.axiformaRegular(14.0f * f2); - float f4 = (float)n2 + (float)n8 / 2.0f - fontRenderer.getMetrics().capHeight() / 2.0f; - int n12 = new Color(255, 255, 255, 100).getRGB(); - TextGlow.drawGlowText(modeSetting.getName(), n, f4, fontRenderer, this.applyAlpha(-1, f), this.applyAlpha(n12, f), 8.0f * f2); - FontRenderer fontRenderer2 = FontPresets.axiformaRegular(14.0f * f2); - String string2 = modeSetting.getValue() != null ? modeSetting.getValue() : "None"; - float f5 = GlHelper.getStringWidth(string2, fontRenderer2); - float f6 = (float)n10 + ((float)n9 - f5) / 2.0f; - float f7 = (float)n11 + (float)n6 / 2.0f - fontRenderer2.getMetrics().capHeight() / 2.0f + 2.0f * f2; - TextGlow.drawGlowText(string2, f6, f7, fontRenderer2, this.applyAlpha(-3355444, f), this.applyAlpha(new Color(255, 255, 255, 150).getRGB(), f), 10.0f * f2); - float f8 = this.openAnimations.getOrDefault(modeSetting, Float.valueOf(0.0f)).floatValue(); - if ((double)f8 > 0.01) { + int dropdownWidth = Math.round(75.0f * scale); + int dropdownX = x + width - Math.round(80.0f * scale); + int dropdownY = y + 1; + RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)dropdownX, (float)dropdownY, (float)dropdownWidth, (float)(itemHeight + expandedHeight), 4.0f * scale, this.applyAlpha(DROPDOWN_BG_COLOR, alpha)); + FontRenderer nameFont = FontPresets.axiformaRegular(14.0f * scale); + float nameY = (float)y + (float)rowHeight / 2.0f - nameFont.getMetrics().capHeight() / 2.0f; + int nameGlow = new Color(255, 255, 255, 100).getRGB(); + TextGlow.drawGlowText(modeSetting.getName(), x, nameY, nameFont, this.applyAlpha(-1, alpha), this.applyAlpha(nameGlow, alpha), 8.0f * scale); + FontRenderer valueFont = FontPresets.axiformaRegular(14.0f * scale); + String selectedValue = modeSetting.getValue() != null ? modeSetting.getValue() : "None"; + float selectedWidth = GlHelper.getStringWidth(selectedValue, valueFont); + float selectedX = (float)dropdownX + ((float)dropdownWidth - selectedWidth) / 2.0f; + float selectedY = (float)dropdownY + (float)itemHeight / 2.0f - valueFont.getMetrics().capHeight() / 2.0f + 2.0f * scale; + TextGlow.drawGlowText(selectedValue, selectedX, selectedY, valueFont, this.applyAlpha(-3355444, alpha), this.applyAlpha(new Color(255, 255, 255, 150).getRGB(), alpha), 10.0f * scale); + float openFactor2 = this.openAnimations.getOrDefault(modeSetting, Float.valueOf(0.0f)).floatValue(); + if ((double)openFactor2 > 0.01) { this.itemHoverAnimations.putIfAbsent(modeSetting, new HashMap<>()); - Map map = this.itemHoverAnimations.get(modeSetting); - for (int i = 0; i < stringArray.length; ++i) { - String string3 = stringArray[i]; - float f9 = GlHelper.getStringWidth(string3, fontRenderer2); - float f10 = (float)n10 + ((float)n9 - f9) / 2.0f; - int n13 = n11 + n6 + i * n6; - float f11 = (float)n13 + (float)n6 / 2.0f - fontRenderer2.getMetrics().capHeight() / 2.0f + 2.0f * f2; - boolean bl = this.isMouseInBounds(n4, n5, n10, n13, n9, n6); - this.updateItemHoverAnim(map, string3, bl); - float f12 = map.getOrDefault(string3, 0.0f); - float f13 = Math.min(1.0f, f8); - if (!(f13 > 0.01f)) continue; - int n14 = (int)(255.0f * f13 * f); - int n15 = this.lerpColor(-3355444, -1, f12); - int n16 = n14 << 24 | n15 & 0xFFFFFF; - int n17 = (int)this.lerpFloat(80.0f, 150.0f, f12); - int n18 = new Color(255, 255, 255, (int)((float)n17 * f13 * f)).getRGB(); - float f14 = this.lerpFloat(6.0f, 10.0f, f12); - TextGlow.drawGlowText(string3, f10, f11, fontRenderer2, n16, n18, f14 * f2); + Map hoverMap = this.itemHoverAnimations.get(modeSetting); + for (int i = 0; i < otherModes.length; ++i) { + String mode = otherModes[i]; + float modeWidth = GlHelper.getStringWidth(mode, valueFont); + float modeX = (float)dropdownX + ((float)dropdownWidth - modeWidth) / 2.0f; + int itemY = dropdownY + itemHeight + i * itemHeight; + float modeTextY = (float)itemY + (float)itemHeight / 2.0f - valueFont.getMetrics().capHeight() / 2.0f + 2.0f * scale; + boolean hovered = this.isMouseInBounds(mouseX, mouseY, dropdownX, itemY, dropdownWidth, itemHeight); + this.updateItemHoverAnim(hoverMap, mode, hovered); + float hoverAmount = hoverMap.getOrDefault(mode, 0.0f); + float clampedOpen = Math.min(1.0f, openFactor2); + if (!(clampedOpen > 0.01f)) continue; + int alphaByte = (int)(255.0f * clampedOpen * alpha); + int modeColor = this.lerpColor(-3355444, -1, hoverAmount); + int finalColor = alphaByte << 24 | modeColor & 0xFFFFFF; + int glowAlpha = (int)this.lerpFloat(80.0f, 150.0f, hoverAmount); + int glowColor = new Color(255, 255, 255, (int)((float)glowAlpha * clampedOpen * alpha)).getRGB(); + float glowRadius = this.lerpFloat(6.0f, 10.0f, hoverAmount); + TextGlow.drawGlowText(mode, modeX, modeTextY, valueFont, finalColor, glowColor, glowRadius * scale); } } } catch (Exception exception) { // empty catch block } - return n8 + n7; + return rowHeight + expandedHeight; } - private int applyAlpha(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = (int)((float)n2 * f); - return n3 << 24 | n & 0xFFFFFF; + private int applyAlpha(int color, float alpha) { + int origAlpha = color >> 24 & 0xFF; + int newAlpha = (int)((float)origAlpha * alpha); + return newAlpha << 24 | color & 0xFFFFFF; } - private void updateItemHoverAnim(Map map, String string, boolean bl) { - float f = map.getOrDefault(string, Float.valueOf(0.0f)).floatValue(); - float f2 = bl ? 1.0f : 0.0f; - f = Math.abs(f - f2) > 0.01f ? LerpUtil.smoothLerp(f, f2, 0.28f) : f2; - map.put(string, Float.valueOf(f)); + private void updateItemHoverAnim(Map hoverMap, String key, boolean hovered) { + float current = hoverMap.getOrDefault(key, Float.valueOf(0.0f)).floatValue(); + float target = hovered ? 1.0f : 0.0f; + current = Math.abs(current - target) > 0.01f ? LerpUtil.smoothLerp(current, target, 0.28f) : target; + hoverMap.put(key, Float.valueOf(current)); } - private float lerpFloat(float f, float f2, float f3) { - return f + (f2 - f) * f3; + private float lerpFloat(float from, float to, float t) { + return from + (to - from) * t; } - private int lerpColor(int n, int n2, float f) { - int n3 = n >> 24 & 0xFF; - int n4 = n >> 16 & 0xFF; - int n5 = n >> 8 & 0xFF; - int n6 = n & 0xFF; - int n7 = n2 >> 24 & 0xFF; - int n8 = n2 >> 16 & 0xFF; - int n9 = n2 >> 8 & 0xFF; - int n10 = n2 & 0xFF; - int n11 = (int)((float)n3 + (float)(n7 - n3) * f); - int n12 = (int)((float)n4 + (float)(n8 - n4) * f); - int n13 = (int)((float)n5 + (float)(n9 - n5) * f); - int n14 = (int)((float)n6 + (float)(n10 - n6) * f); - return n11 << 24 | n12 << 16 | n13 << 8 | n14; + private int lerpColor(int fromColor, int toColor, float t) { + int aFrom = fromColor >> 24 & 0xFF; + int rFrom = fromColor >> 16 & 0xFF; + int gFrom = fromColor >> 8 & 0xFF; + int bFrom = fromColor & 0xFF; + int aTo = toColor >> 24 & 0xFF; + int rTo = toColor >> 16 & 0xFF; + int gTo = toColor >> 8 & 0xFF; + int bTo = toColor & 0xFF; + int a = (int)((float)aFrom + (float)(aTo - aFrom) * t); + int r = (int)((float)rFrom + (float)(rTo - rFrom) * t); + int g = (int)((float)gFrom + (float)(gTo - gFrom) * t); + int b = (int)((float)bFrom + (float)(bTo - bFrom) * t); + return a << 24 | r << 16 | g << 8 | b; } private void updateOpenAnimation(ModeSetting modeSetting) { - boolean bl = this.openStates.getOrDefault(modeSetting, false); - float f = this.openAnimations.getOrDefault(modeSetting, Float.valueOf(0.0f)).floatValue(); - if (bl) { - this.openAnimations.put(modeSetting, Float.valueOf(LerpUtil.lerp(f, 1.0f, 0.08f))); + boolean open = this.openStates.getOrDefault(modeSetting, false); + float current = this.openAnimations.getOrDefault(modeSetting, Float.valueOf(0.0f)).floatValue(); + if (open) { + this.openAnimations.put(modeSetting, Float.valueOf(LerpUtil.lerp(current, 1.0f, 0.08f))); } else { - this.openAnimations.put(modeSetting, Float.valueOf(LerpUtil.lerp(f, 0.0f, 0.16f))); + this.openAnimations.put(modeSetting, Float.valueOf(LerpUtil.lerp(current, 0.0f, 0.16f))); } } @Override - public boolean onClick(Setting setting, int n, int n2, int n3, int n4, int n5, int n6, float f) { + public boolean onClick(Setting setting, int x, int y, int width, int mouseX, int mouseY, int button, float scale) { if (!(setting instanceof ModeSetting modeSetting)) { return false; } - int n7 = Math.round(16.0f * f); - int n8 = Math.round(75.0f * f); - int n9 = n + n3 - Math.round(80.0f * f); - int n10 = n2 - 2; - boolean bl = this.openStates.getOrDefault(modeSetting, false); - String[] stringArray = Arrays.stream((Object[])modeSetting.getModes()).filter(string -> !Objects.equals(string, modeSetting.getValue())).toArray(String[]::new); - boolean bl2 = this.isMouseInBounds(n4, n5, n9, n10, n8, n7); - if (bl2 && n6 == 1) { - this.openStates.put(modeSetting, !bl); + int itemHeight = Math.round(16.0f * scale); + int dropdownWidth = Math.round(75.0f * scale); + int dropdownX = x + width - Math.round(80.0f * scale); + int dropdownY = y - 2; + boolean open = this.openStates.getOrDefault(modeSetting, false); + String[] otherModes = Arrays.stream((Object[])modeSetting.getModes()).filter(mode -> !Objects.equals(mode, modeSetting.getValue())).toArray(String[]::new); + boolean overHeader = this.isMouseInBounds(mouseX, mouseY, dropdownX, dropdownY, dropdownWidth, itemHeight); + if (overHeader && button == 1) { + this.openStates.put(modeSetting, !open); return true; } - if (bl) { - int n11 = n10 + n7; - for (int i = 0; i < stringArray.length; ++i) { - if (!this.isMouseInBounds(n4, n5, n9, n11 + i * n7, n8, n7) || n6 != 0) continue; - String string2 = stringArray[i]; - modeSetting.setValue(string2); + if (open) { + int firstItemY = dropdownY + itemHeight; + for (int i = 0; i < otherModes.length; ++i) { + if (!this.isMouseInBounds(mouseX, mouseY, dropdownX, firstItemY + i * itemHeight, dropdownWidth, itemHeight) || button != 0) continue; + String chosen = otherModes[i]; + modeSetting.setValue(chosen); this.openStates.put(modeSetting, false); - PanelClickGui.panelClickGui.addToast(modeSetting.getName() + " set to " + string2); + PanelClickGui.panelClickGui.addToast(modeSetting.getName() + " set to " + chosen); return true; } - if (!bl2) { + if (!overHeader) { this.openStates.put(modeSetting, false); } } return false; } - private boolean isMouseInBounds(int n, int n2, int n3, int n4, int n5, int n6) { - return n >= n3 && n <= n3 + n5 && n2 >= n4 && n2 <= n4 + n6; + private boolean isMouseInBounds(int mouseX, int mouseY, int boxX, int boxY, int boxWidth, int boxHeight) { + return mouseX >= boxX && mouseX <= boxX + boxWidth && mouseY >= boxY && mouseY <= boxY + boxHeight; } @Override @@ -167,18 +167,18 @@ implements SettingRenderer { } @Override - public int getHeight(Setting setting, float f) { + public int getHeight(Setting setting, float scale) { if (!(setting instanceof ModeSetting modeSetting)) { - return Math.round(24.0f * f); + return Math.round(24.0f * scale); } - String[] stringArray = Arrays.stream((Object[])modeSetting.getModes()).filter(string -> !Objects.equals(string, modeSetting.getValue())).toArray(String[]::new); - float f2 = this.openAnimations.getOrDefault(modeSetting, Float.valueOf(0.0f)).floatValue(); - int n = Math.round(16.0f * f); - int n2 = Math.round((float)(stringArray.length * n) * f2); - return Math.round(24.0f * f) + n2; + String[] otherModes = Arrays.stream((Object[])modeSetting.getModes()).filter(mode -> !Objects.equals(mode, modeSetting.getValue())).toArray(String[]::new); + float openFactor = this.openAnimations.getOrDefault(modeSetting, Float.valueOf(0.0f)).floatValue(); + int itemHeight = Math.round(16.0f * scale); + int expandedHeight = Math.round((float)(otherModes.length * itemHeight) * openFactor); + return Math.round(24.0f * scale) + expandedHeight; } @Override - public void onMouseRelease(double d, double d2, int n) { + public void onMouseRelease(double mouseX, double mouseY, int button) { } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/setting/MultiSelectSettingRenderer.java b/src/main/java/shit/zen/gui/panel/setting/MultiSelectSettingRenderer.java index 1e776d0..d820cf8 100644 --- a/src/main/java/shit/zen/gui/panel/setting/MultiSelectSettingRenderer.java +++ b/src/main/java/shit/zen/gui/panel/setting/MultiSelectSettingRenderer.java @@ -24,77 +24,77 @@ implements SettingRenderer { private final Map selectedAnimations = new HashMap<>(); @Override - public int render(GuiGraphics guiGraphics, Setting setting, int n, int n2, int n3, int n4, int n5, float f, float f2) { + public int render(GuiGraphics guiGraphics, Setting setting, int x, int y, int width, int mouseX, int mouseY, float alpha, float scale) { if (!(setting instanceof MultiSelectSetting multiSelectSetting)) { return 0; } - FontRenderer fontRenderer = FontPresets.axiformaRegular(14.0f * f2); - float f3 = (float)n2 + 20.0f * f2 / 2.0f - fontRenderer.getMetrics().capHeight() / 2.0f; - TextGlow.drawGlowText(multiSelectSetting.getName(), n, f3, fontRenderer, this.applyAlpha(-1, f), this.applyAlpha(new Color(255, 255, 255, 120).getRGB(), f), 8.0f * f2); - int n6 = n2 + Math.round(20.0f * f2); - int n7 = Math.round(20.0f * f2); - int n8 = Math.round(10.0f * f2); - int n9 = Math.round(5.0f * f2); - for (String string : multiSelectSetting.getOptions()) { - int n10; - boolean bl = multiSelectSetting.isSelected(string); - boolean bl2 = n4 >= n && n4 <= n + n3 && n5 >= n6 && n5 <= n6 + n7; - this.updateAnimation(this.hoverAnimations, string, bl2, 0.28f); - this.updateAnimation(this.selectedAnimations, string, bl, 0.25f); - float f4 = this.hoverAnimations.getOrDefault(string, Float.valueOf(0.0f)).floatValue(); - float f5 = this.selectedAnimations.getOrDefault(string, Float.valueOf(0.0f)).floatValue(); - int n11 = n + n3 - n8 - n9; - int n12 = n6 + (n7 - n8) / 2; - if (f5 > 0.01f) { - n10 = this.applyAlpha(COLOR_SELECTED_GLOW, f * f5); - RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)n11 - f2, (float)n12 - f2, (float)n8 + 2.0f * f2, (float)n8 + 2.0f * f2, 2.0f * f2, n10); + FontRenderer nameFont = FontPresets.axiformaRegular(14.0f * scale); + float nameY = (float)y + 20.0f * scale / 2.0f - nameFont.getMetrics().capHeight() / 2.0f; + TextGlow.drawGlowText(multiSelectSetting.getName(), x, nameY, nameFont, this.applyAlpha(-1, alpha), this.applyAlpha(new Color(255, 255, 255, 120).getRGB(), alpha), 8.0f * scale); + int optionY = y + Math.round(20.0f * scale); + int rowHeight = Math.round(20.0f * scale); + int boxSize = Math.round(10.0f * scale); + int rightPadding = Math.round(5.0f * scale); + for (String option : multiSelectSetting.getOptions()) { + int color; + boolean selected = multiSelectSetting.isSelected(option); + boolean hovered = mouseX >= x && mouseX <= x + width && mouseY >= optionY && mouseY <= optionY + rowHeight; + this.updateAnimation(this.hoverAnimations, option, hovered, 0.28f); + this.updateAnimation(this.selectedAnimations, option, selected, 0.25f); + float hoverAmount = this.hoverAnimations.getOrDefault(option, Float.valueOf(0.0f)).floatValue(); + float selectedAmount = this.selectedAnimations.getOrDefault(option, Float.valueOf(0.0f)).floatValue(); + int boxX = x + width - boxSize - rightPadding; + int boxY = optionY + (rowHeight - boxSize) / 2; + if (selectedAmount > 0.01f) { + color = this.applyAlpha(COLOR_SELECTED_GLOW, alpha * selectedAmount); + RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)boxX - scale, (float)boxY - scale, (float)boxSize + 2.0f * scale, (float)boxSize + 2.0f * scale, 2.0f * scale, color); } - RenderUtil.drawRoundedRect(guiGraphics.pose(), n11, n12, n8, n8, 2.0f * f2, this.applyAlpha(-5592406, f)); - if ((double)f5 > 0.01) { - float f6 = (1.0f - f5) * ((float)n8 / 2.0f); - RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)n11 + f6, (float)n12 + f6, (float)n8 - f6 * 2.0f, (float)n8 - f6 * 2.0f, f2, this.applyAlpha(COLOR_SELECTED, f)); + RenderUtil.drawRoundedRect(guiGraphics.pose(), boxX, boxY, boxSize, boxSize, 2.0f * scale, this.applyAlpha(-5592406, alpha)); + if ((double)selectedAmount > 0.01) { + float inset = (1.0f - selectedAmount) * ((float)boxSize / 2.0f); + RenderUtil.drawRoundedRect(guiGraphics.pose(), (float)boxX + inset, (float)boxY + inset, (float)boxSize - inset * 2.0f, (float)boxSize - inset * 2.0f, scale, this.applyAlpha(COLOR_SELECTED, alpha)); } - n10 = bl ? -1 : -5592406; - int n13 = this.lerpColor(n10, -1, f4); - FontRenderer fontRenderer2 = FontPresets.axiformaRegular(13.0f * f2); - float f7 = (float)n6 + (float)n7 / 2.0f - fontRenderer2.getMetrics().capHeight() / 2.0f; - if (f5 > 0.01f) { - int n14 = this.applyAlpha(COLOR_SELECTED_GLOW, f * f5); - TextGlow.drawGlowText(string, n + n9, f7, fontRenderer2, this.applyAlpha(n13, f), n14, 8.0f * f2 * f5); + color = selected ? -1 : -5592406; + int labelColor = this.lerpColor(color, -1, hoverAmount); + FontRenderer labelFont = FontPresets.axiformaRegular(13.0f * scale); + float labelY = (float)optionY + (float)rowHeight / 2.0f - labelFont.getMetrics().capHeight() / 2.0f; + if (selectedAmount > 0.01f) { + int glowColor = this.applyAlpha(COLOR_SELECTED_GLOW, alpha * selectedAmount); + TextGlow.drawGlowText(option, x + rightPadding, labelY, labelFont, this.applyAlpha(labelColor, alpha), glowColor, 8.0f * scale * selectedAmount); } else { - GlHelper.drawText(string, n + n9, f7, fontRenderer2, this.applyAlpha(n13, f)); + GlHelper.drawText(option, x + rightPadding, labelY, labelFont, this.applyAlpha(labelColor, alpha)); } - n6 += n7; + optionY += rowHeight; } - return (multiSelectSetting.getOptions().size() + 1) * n7; + return (multiSelectSetting.getOptions().size() + 1) * rowHeight; } - private void updateAnimation(Map map, String string, boolean bl, float f) { - float f2 = map.getOrDefault(string, Float.valueOf(0.0f)).floatValue(); - float f3 = bl ? 1.0f : 0.0f; - f2 = Math.abs(f3 - f2) > 0.01f ? LerpUtil.smoothLerp(f2, f3, f) : f3; - map.put(string, Float.valueOf(f2)); + private void updateAnimation(Map map, String key, boolean target, float speed) { + float current = map.getOrDefault(key, Float.valueOf(0.0f)).floatValue(); + float targetValue = target ? 1.0f : 0.0f; + current = Math.abs(targetValue - current) > 0.01f ? LerpUtil.smoothLerp(current, targetValue, speed) : targetValue; + map.put(key, Float.valueOf(current)); } @Override - public boolean onClick(Setting setting, int n, int n2, int n3, int n4, int n5, int n6, float f) { - if (!(setting instanceof MultiSelectSetting multiSelectSetting) || n6 != 0) { + public boolean onClick(Setting setting, int x, int y, int width, int mouseX, int mouseY, int button, float scale) { + if (!(setting instanceof MultiSelectSetting multiSelectSetting) || button != 0) { return false; } - int n7 = n2 + Math.round(20.0f * f); - int n8 = Math.round(20.0f * f); - for (String string : multiSelectSetting.getOptions()) { - if (n4 >= n && n4 <= n + n3 && n5 >= n7 && n5 <= n7 + n8) { - if (multiSelectSetting.isSelected(string)) { - multiSelectSetting.getValue().remove(string); + int optionY = y + Math.round(20.0f * scale); + int rowHeight = Math.round(20.0f * scale); + for (String option : multiSelectSetting.getOptions()) { + if (mouseX >= x && mouseX <= x + width && mouseY >= optionY && mouseY <= optionY + rowHeight) { + if (multiSelectSetting.isSelected(option)) { + multiSelectSetting.getValue().remove(option); } else { - multiSelectSetting.getValue().add(string); + multiSelectSetting.getValue().add(option); } - boolean bl = multiSelectSetting.isSelected(string); - PanelClickGui.panelClickGui.addToast(string + (bl ? " enabled" : " disabled")); + boolean nowSelected = multiSelectSetting.isSelected(option); + PanelClickGui.panelClickGui.addToast(option + (nowSelected ? " enabled" : " disabled")); return true; } - n7 += n8; + optionY += rowHeight; } return false; } @@ -105,37 +105,37 @@ implements SettingRenderer { } @Override - public int getHeight(Setting setting, float f) { + public int getHeight(Setting setting, float scale) { if (!(setting instanceof MultiSelectSetting multiSelectSetting)) { return 0; } - return Math.round((float)((multiSelectSetting.getOptions().size() + 1) * 20) * f); + return Math.round((float)((multiSelectSetting.getOptions().size() + 1) * 20) * scale); } @Override - public void onMouseRelease(double d, double d2, int n) { + public void onMouseRelease(double mouseX, double mouseY, int button) { } - private int applyAlpha(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = (int)((float)n2 * f); - return n3 << 24 | n & 0xFFFFFF; + private int applyAlpha(int color, float alpha) { + int origAlpha = color >> 24 & 0xFF; + int newAlpha = (int)((float)origAlpha * alpha); + return newAlpha << 24 | color & 0xFFFFFF; } - private int lerpColor(int n, int n2, float f) { - float f2 = 1.0f - f; - int n3 = n >> 24 & 0xFF; - int n4 = n >> 16 & 0xFF; - int n5 = n >> 8 & 0xFF; - int n6 = n & 0xFF; - int n7 = n2 >> 24 & 0xFF; - int n8 = n2 >> 16 & 0xFF; - int n9 = n2 >> 8 & 0xFF; - int n10 = n2 & 0xFF; - int n11 = (int)((float)n3 * f2 + (float)n7 * f); - int n12 = (int)((float)n4 * f2 + (float)n8 * f); - int n13 = (int)((float)n5 * f2 + (float)n9 * f); - int n14 = (int)((float)n6 * f2 + (float)n10 * f); - return n11 << 24 | n12 << 16 | n13 << 8 | n14; + private int lerpColor(int fromColor, int toColor, float t) { + float inv = 1.0f - t; + int aFrom = fromColor >> 24 & 0xFF; + int rFrom = fromColor >> 16 & 0xFF; + int gFrom = fromColor >> 8 & 0xFF; + int bFrom = fromColor & 0xFF; + int aTo = toColor >> 24 & 0xFF; + int rTo = toColor >> 16 & 0xFF; + int gTo = toColor >> 8 & 0xFF; + int bTo = toColor & 0xFF; + int a = (int)((float)aFrom * inv + (float)aTo * t); + int r = (int)((float)rFrom * inv + (float)rTo * t); + int g = (int)((float)gFrom * inv + (float)gTo * t); + int b = (int)((float)bFrom * inv + (float)bTo * t); + return a << 24 | r << 16 | g << 8 | b; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/setting/NumberSettingRenderer.java b/src/main/java/shit/zen/gui/panel/setting/NumberSettingRenderer.java index 5a436b0..8001769 100644 --- a/src/main/java/shit/zen/gui/panel/setting/NumberSettingRenderer.java +++ b/src/main/java/shit/zen/gui/panel/setting/NumberSettingRenderer.java @@ -28,59 +28,59 @@ implements SettingRenderer { private final Map editIconHover = new HashMap<>(); @Override - public int render(GuiGraphics guiGraphics, Setting setting, int n, int n2, int n3, int n4, int n5, float f, float f2) { + public int render(GuiGraphics guiGraphics, Setting setting, int x, int y, int width, int mouseX, int mouseY, float alpha, float scale) { if (!(setting instanceof NumberSetting numberSetting)) { return 0; } - boolean bl = numberSetting.equals(editingNumberSetting); - int n6 = Math.round(24.0f * f2); - int n7 = Math.round(12.0f * f2); - int n8 = Math.round(8.0f * f2); - FontRenderer fontRenderer = FontPresets.axiformaBold(14.0f * f2); - String string = bl ? editingText : this.formatValue(numberSetting.getValue().doubleValue()); - float f3 = GlHelper.getStringWidth(string, fontRenderer); - int n9 = n7 * 2 + (int)f3 + n8 * 2 - Math.round(2.0f * f2); - int n10 = n + n3 - n9; - int n11 = n6 - Math.round(14.0f * f2); - float f4 = (float)n2 + (float)n6 / 2.0f; - int n12 = Math.round(f4 - (float)n11 / 2.0f); - int n13 = Math.round(16.0f * f2); - int n14 = Math.round(4.0f * f2); - int n15 = n10 - n13 - n14; - int n16 = Math.round(f4 - (float)n13 / 2.0f) + Math.round(3.0f * f2); - this.updateHoverStates(numberSetting, n4, n5, n10, n12, n9, n7, n11, n15, n16, n13); - this.drawNumberWidget(guiGraphics, numberSetting, n, n2, n3, n10, n12, n9, n11, n15, n16, bl, f, f2); - return n6; + boolean editing = numberSetting.equals(editingNumberSetting); + int rowHeight = Math.round(24.0f * scale); + int sidePadding = Math.round(12.0f * scale); + int innerPadding = Math.round(8.0f * scale); + FontRenderer valueFont = FontPresets.axiformaBold(14.0f * scale); + String valueText = editing ? editingText : this.formatValue(numberSetting.getValue().doubleValue()); + float valueWidth = GlHelper.getStringWidth(valueText, valueFont); + int widgetWidth = sidePadding * 2 + (int)valueWidth + innerPadding * 2 - Math.round(2.0f * scale); + int widgetX = x + width - widgetWidth; + int widgetHeight = rowHeight - Math.round(14.0f * scale); + float centerY = (float)y + (float)rowHeight / 2.0f; + int widgetY = Math.round(centerY - (float)widgetHeight / 2.0f); + int iconSize = Math.round(16.0f * scale); + int iconGap = Math.round(4.0f * scale); + int iconX = widgetX - iconSize - iconGap; + int iconY = Math.round(centerY - (float)iconSize / 2.0f) + Math.round(3.0f * scale); + this.updateHoverStates(numberSetting, mouseX, mouseY, widgetX, widgetY, widgetWidth, sidePadding, widgetHeight, iconX, iconY, iconSize); + this.drawNumberWidget(guiGraphics, numberSetting, x, y, width, widgetX, widgetY, widgetWidth, widgetHeight, iconX, iconY, editing, alpha, scale); + return rowHeight; } @Override - public boolean onClick(Setting setting, int n, int n2, int n3, int n4, int n5, int n6, float f) { - if (!(setting instanceof NumberSetting numberSetting) || n6 != 0) { + public boolean onClick(Setting setting, int x, int y, int width, int mouseX, int mouseY, int button, float scale) { + if (!(setting instanceof NumberSetting numberSetting) || button != 0) { return false; } - int n7 = Math.round(24.0f * f); - int n8 = Math.round(12.0f * f); - int n9 = Math.round(8.0f * f); - FontRenderer fontRenderer = FontPresets.axiformaBold(14.0f * f); - String string = this.formatValue(numberSetting.getValue().doubleValue()); - float f2 = GlHelper.getStringWidth(string, fontRenderer); - int n10 = n8 * 2 + (int)f2 + n9 * 2 - Math.round(2.0f * f); - int n11 = n + n3 - n10; - int n12 = n7 - Math.round(14.0f * f); - float f3 = (float)n2 + (float)n7 / 2.0f; - int n13 = Math.round(f3 - (float)n12 / 2.0f); - int n14 = Math.round(16.0f * f); - int n15 = Math.round(4.0f * f); - int n16 = n11 - n14 - n15; - int n17 = Math.round(f3 - (float)n14 / 2.0f); - if (n4 >= n16 && n4 <= n16 + n14 && n5 >= n17 && n5 <= n17 + n14) { + int rowHeight = Math.round(24.0f * scale); + int sidePadding = Math.round(12.0f * scale); + int innerPadding = Math.round(8.0f * scale); + FontRenderer valueFont = FontPresets.axiformaBold(14.0f * scale); + String valueText = this.formatValue(numberSetting.getValue().doubleValue()); + float valueWidth = GlHelper.getStringWidth(valueText, valueFont); + int widgetWidth = sidePadding * 2 + (int)valueWidth + innerPadding * 2 - Math.round(2.0f * scale); + int widgetX = x + width - widgetWidth; + int widgetHeight = rowHeight - Math.round(14.0f * scale); + float centerY = (float)y + (float)rowHeight / 2.0f; + int widgetY = Math.round(centerY - (float)widgetHeight / 2.0f); + int iconSize = Math.round(16.0f * scale); + int iconGap = Math.round(4.0f * scale); + int iconX = widgetX - iconSize - iconGap; + int iconY = Math.round(centerY - (float)iconSize / 2.0f); + if (mouseX >= iconX && mouseX <= iconX + iconSize && mouseY >= iconY && mouseY <= iconY + iconSize) { this.startEditing(numberSetting); return true; } - if (n4 >= n11 && n4 <= n11 + n10 && n5 >= n13 && n5 <= n13 + n12) { - if (n4 < n11 + n8) { + if (mouseX >= widgetX && mouseX <= widgetX + widgetWidth && mouseY >= widgetY && mouseY <= widgetY + widgetHeight) { + if (mouseX < widgetX + sidePadding) { this.decrementValue(numberSetting); - } else if (n4 > n11 + n10 - n8) { + } else if (mouseX > widgetX + widgetWidth - sidePadding) { this.incrementValue(numberSetting); } return true; @@ -92,19 +92,19 @@ implements SettingRenderer { NumberSettingRenderer.cancelEdit(); } - public static boolean onKeyPress(int n, int n2, int n3) { + public static boolean onKeyPress(int keyCode, int scanCode, int modifiers) { if (editingNumberSetting == null) { return false; } - if (n == 257 || n == 335) { + if (keyCode == 257 || keyCode == 335) { NumberSettingRenderer.commitEdit(); return true; } - if (n == 256) { + if (keyCode == 256) { NumberSettingRenderer.cancelEdit(); return true; } - if (n == 259 && !editingText.isEmpty()) { + if (keyCode == 259 && !editingText.isEmpty()) { editingText = editingText.substring(0, editingText.length() - 1); lastInputTime = System.currentTimeMillis(); return true; @@ -128,11 +128,11 @@ implements SettingRenderer { } @Override - public void onMouseMove(double d, double d2) { + public void onMouseMove(double mouseX, double mouseY) { } @Override - public void onMouseRelease(double d, double d2, int n) { + public void onMouseRelease(double mouseX, double mouseY, int button) { } private void startEditing(NumberSetting numberSetting) { @@ -147,12 +147,12 @@ implements SettingRenderer { return; } try { - double d = Double.parseDouble(editingText); - double d2 = editingNumberSetting.getMin().doubleValue(); - double d3 = editingNumberSetting.getMax().doubleValue(); - d = Math.max(d2, Math.min(d3, d)); - NumberSettingRenderer.applyValueStatic(editingNumberSetting, d); - PanelClickGui.panelClickGui.addToast(editingNumberSetting.getName() + " set to " + String.format(Locale.US, "%.1f", new Object[]{d})); + double parsed = Double.parseDouble(editingText); + double min = editingNumberSetting.getMin().doubleValue(); + double max = editingNumberSetting.getMax().doubleValue(); + parsed = Math.max(min, Math.min(max, parsed)); + NumberSettingRenderer.applyValueStatic(editingNumberSetting, parsed); + PanelClickGui.panelClickGui.addToast(editingNumberSetting.getName() + " set to " + String.format(Locale.US, "%.1f", new Object[]{parsed})); } catch (NumberFormatException numberFormatException) { PanelClickGui.panelClickGui.addToast("Invalid input, edit cancelled"); } @@ -164,139 +164,139 @@ implements SettingRenderer { editingText = ""; } - private int applyAlpha(int n, float f) { - int n2 = n >> 24 & 0xFF; - int n3 = (int)((float)n2 * f); - return n3 << 24 | n & 0xFFFFFF; + private int applyAlpha(int color, float alpha) { + int origAlpha = color >> 24 & 0xFF; + int newAlpha = (int)((float)origAlpha * alpha); + return newAlpha << 24 | color & 0xFFFFFF; } - private void drawNumberWidget(GuiGraphics guiGraphics, NumberSetting numberSetting, int n, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, boolean bl, float f, float f2) { - String string; - float f3 = 24.0f * f2; - float f4 = (float)n2 + f3 / 2.0f; - FontRenderer fontRenderer = FontPresets.axiformaRegular(14.0f * f2); - FontRenderer fontRenderer2 = FontPresets.axiformaBold(14.0f * f2); - FontRenderer fontRenderer3 = FontPresets.axiformaBold(12.0f * f2); - GlyphMetrics glyphMetrics = fontRenderer.getMetrics(); - float f5 = f4 - (glyphMetrics.ascent() + glyphMetrics.descent()) / 2.0f + glyphMetrics.ascent() + 6.0f * f2; - TextGlow.drawGlowText(numberSetting.getName(), n, f5, fontRenderer, this.applyAlpha(-1, f), this.applyAlpha(new Color(255, 255, 255, 120).getRGB(), f), 8.0f * f2); - this.drawEditIcon(guiGraphics, n8, n9, numberSetting, f, f2); - int n10 = Math.round(12.0f * f2); - RenderUtil.drawRoundedRect(guiGraphics.pose(), n4, n5, n6, n7, 5.0f * f2, this.applyAlpha(0x50F5F5F5, f)); - int n11 = n4 + n10; - int n12 = n6 - n10 * 2; - RenderUtil.drawRoundedRect(guiGraphics.pose(), n11, n5, n12, n7, 0.0f, this.applyAlpha(1086900424, f)); - GlyphMetrics glyphMetrics2 = fontRenderer3.getMetrics(); - float f6 = (float)n5 + (float)n7 / 2.0f; - float f7 = f6 - (glyphMetrics2.ascent() + glyphMetrics2.descent()) / 2.0f + glyphMetrics2.ascent() + 5.0f * f2 - 2.5f; - int n13 = this.minusButtonHover.getOrDefault(numberSetting, false) != false ? new Color(255, 255, 255).getRGB() : -1; - GlHelper.drawText("-", (float)n4 + (float)n10 / 2.0f - GlHelper.getStringWidth("-", fontRenderer3) / 2.0f, f7, fontRenderer3, this.applyAlpha(n13, f)); - int n14 = this.plusButtonHover.getOrDefault(numberSetting, false) != false ? new Color(255, 255, 255).getRGB() : -1; - GlHelper.drawText("+", (float)(n4 + n6 - n10) + ((float)n10 / 2.0f - GlHelper.getStringWidth("+", fontRenderer3) / 2.0f), f7, fontRenderer3, this.applyAlpha(n14, f)); - String string2 = string = bl ? editingText : this.formatValue(numberSetting.getValue().doubleValue()); - if (bl && string.isEmpty()) { - string = "0"; + private void drawNumberWidget(GuiGraphics guiGraphics, NumberSetting numberSetting, int x, int y, int width, int widgetX, int widgetY, int widgetWidth, int widgetHeight, int iconX, int iconY, boolean editing, float alpha, float scale) { + String displayText; + float rowHeight = 24.0f * scale; + float centerY = (float)y + rowHeight / 2.0f; + FontRenderer nameFont = FontPresets.axiformaRegular(14.0f * scale); + FontRenderer valueFont = FontPresets.axiformaBold(14.0f * scale); + FontRenderer signFont = FontPresets.axiformaBold(12.0f * scale); + GlyphMetrics nameMetrics = nameFont.getMetrics(); + float nameY = centerY - (nameMetrics.ascent() + nameMetrics.descent()) / 2.0f + nameMetrics.ascent() + 6.0f * scale; + TextGlow.drawGlowText(numberSetting.getName(), x, nameY, nameFont, this.applyAlpha(-1, alpha), this.applyAlpha(new Color(255, 255, 255, 120).getRGB(), alpha), 8.0f * scale); + this.drawEditIcon(guiGraphics, iconX, iconY, numberSetting, alpha, scale); + int sidePadding = Math.round(12.0f * scale); + RenderUtil.drawRoundedRect(guiGraphics.pose(), widgetX, widgetY, widgetWidth, widgetHeight, 5.0f * scale, this.applyAlpha(0x50F5F5F5, alpha)); + int middleX = widgetX + sidePadding; + int middleWidth = widgetWidth - sidePadding * 2; + RenderUtil.drawRoundedRect(guiGraphics.pose(), middleX, widgetY, middleWidth, widgetHeight, 0.0f, this.applyAlpha(1086900424, alpha)); + GlyphMetrics signMetrics = signFont.getMetrics(); + float widgetCenterY = (float)widgetY + (float)widgetHeight / 2.0f; + float signY = widgetCenterY - (signMetrics.ascent() + signMetrics.descent()) / 2.0f + signMetrics.ascent() + 5.0f * scale - 2.5f; + int minusColor = this.minusButtonHover.getOrDefault(numberSetting, false) != false ? new Color(255, 255, 255).getRGB() : -1; + GlHelper.drawText("-", (float)widgetX + (float)sidePadding / 2.0f - GlHelper.getStringWidth("-", signFont) / 2.0f, signY, signFont, this.applyAlpha(minusColor, alpha)); + int plusColor = this.plusButtonHover.getOrDefault(numberSetting, false) != false ? new Color(255, 255, 255).getRGB() : -1; + GlHelper.drawText("+", (float)(widgetX + widgetWidth - sidePadding) + ((float)sidePadding / 2.0f - GlHelper.getStringWidth("+", signFont) / 2.0f), signY, signFont, this.applyAlpha(plusColor, alpha)); + String dup = displayText = editing ? editingText : this.formatValue(numberSetting.getValue().doubleValue()); + if (editing && displayText.isEmpty()) { + displayText = "0"; } - float f8 = GlHelper.getStringWidth(string, fontRenderer2); - float f9 = (float)n4 + (float)n6 / 2.0f - f8 / 2.0f; - GlyphMetrics glyphMetrics3 = fontRenderer2.getMetrics(); - float f10 = f7 + f2 - 1.5f; - if (bl) { - long l = System.currentTimeMillis(); - float f11 = (float)(l % 1000L) / 1000.0f; - float f12 = (float)(Math.sin((double)f11 * Math.PI * 2.0) * 0.5 + 0.5); - int n15 = (int)(255.0f * (0.6f + f12 * 0.4f) * f); - int n16 = n15 << 24 | 0xFFFFFF; - GlHelper.drawText(string, f9, f10, fontRenderer2, n16); - float f13 = f9 + f8 + 2.0f * f2; - int n17 = (int)(255.0f * f12 * f); - int n18 = n17 << 24 | 0xFFFFFF; - float f14 = glyphMetrics3.capHeight(); - float f15 = f10 - glyphMetrics3.ascent() + (glyphMetrics3.ascent() - f14) / 2.0f; - RenderUtil.drawFilledRect(guiGraphics.pose(), f13, f15, Math.round(f2), Math.round(f14), n18); + float displayWidth = GlHelper.getStringWidth(displayText, valueFont); + float displayX = (float)widgetX + (float)widgetWidth / 2.0f - displayWidth / 2.0f; + GlyphMetrics valueMetrics = valueFont.getMetrics(); + float displayY = signY + scale - 1.5f; + if (editing) { + long now = System.currentTimeMillis(); + float cyclePos = (float)(now % 1000L) / 1000.0f; + float sineWave = (float)(Math.sin((double)cyclePos * Math.PI * 2.0) * 0.5 + 0.5); + int textAlpha = (int)(255.0f * (0.6f + sineWave * 0.4f) * alpha); + int textColor = textAlpha << 24 | 0xFFFFFF; + GlHelper.drawText(displayText, displayX, displayY, valueFont, textColor); + float caretX = displayX + displayWidth + 2.0f * scale; + int caretAlpha = (int)(255.0f * sineWave * alpha); + int caretColor = caretAlpha << 24 | 0xFFFFFF; + float caretHeight = valueMetrics.capHeight(); + float caretY = displayY - valueMetrics.ascent() + (valueMetrics.ascent() - caretHeight) / 2.0f; + RenderUtil.drawFilledRect(guiGraphics.pose(), caretX, caretY, Math.round(scale), Math.round(caretHeight), caretColor); } else { - int n19 = new Color(255, 255, 255, 120).getRGB(); - TextGlow.drawGlowText(string, f9, f10, fontRenderer2, this.applyAlpha(-1, f), this.applyAlpha(n19, f), 6.0f * f2); + int glowColor = new Color(255, 255, 255, 120).getRGB(); + TextGlow.drawGlowText(displayText, displayX, displayY, valueFont, this.applyAlpha(-1, alpha), this.applyAlpha(glowColor, alpha), 6.0f * scale); } } - private void drawEditIcon(GuiGraphics guiGraphics, int n, int n2, NumberSetting numberSetting, float f, float f2) { - boolean bl = this.editIconHover.getOrDefault(numberSetting, false); - long l = this.editIconTimers.getOrDefault(numberSetting, 0L); - long l2 = System.currentTimeMillis() - l; - int n3 = Math.round(16.0f * f2); - float f3 = Math.min(1.0f, (float)l2 / 200.0f); - if (!bl) { - f3 = 1.0f - f3; + private void drawEditIcon(GuiGraphics guiGraphics, int iconX, int iconY, NumberSetting numberSetting, float alpha, float scale) { + boolean hovered = this.editIconHover.getOrDefault(numberSetting, false); + long timerStart = this.editIconTimers.getOrDefault(numberSetting, 0L); + long sinceChange = System.currentTimeMillis() - timerStart; + int iconSize = Math.round(16.0f * scale); + float progress = Math.min(1.0f, (float)sinceChange / 200.0f); + if (!hovered) { + progress = 1.0f - progress; } - int n4 = -5197648; - int n5 = -1; - int n6 = RenderUtil.lerpColorHSB(n4, n5, f3); - FontRenderer fontRenderer = FontPresets.materialIcons(n3); - String string = ""; - float f4 = GlHelper.getStringWidth(string, fontRenderer); - GlyphMetrics glyphMetrics = fontRenderer.getMetrics(); - float f5 = (float)n + ((float)n3 - f4) / 2.0f; - float f6 = (float)n2 + (float)n3 / 2.0f - (glyphMetrics.ascent() + glyphMetrics.descent()) / 2.0f + glyphMetrics.ascent() + 1.0f; - GlHelper.drawText(string, f5, f6, fontRenderer, this.applyAlpha(n6, f)); + int colorFrom = -5197648; + int colorTo = -1; + int iconColor = RenderUtil.lerpColorHSB(colorFrom, colorTo, progress); + FontRenderer iconFont = FontPresets.materialIcons(iconSize); + String iconText = ""; + float iconTextWidth = GlHelper.getStringWidth(iconText, iconFont); + GlyphMetrics iconMetrics = iconFont.getMetrics(); + float drawX = (float)iconX + ((float)iconSize - iconTextWidth) / 2.0f; + float drawY = (float)iconY + (float)iconSize / 2.0f - (iconMetrics.ascent() + iconMetrics.descent()) / 2.0f + iconMetrics.ascent() + 1.0f; + GlHelper.drawText(iconText, drawX, drawY, iconFont, this.applyAlpha(iconColor, alpha)); } private void incrementValue(NumberSetting numberSetting) { - double d = numberSetting.getValue().doubleValue(); - double d2 = numberSetting.getStep().doubleValue(); - double d3 = numberSetting.getMax().doubleValue(); - double d4 = Math.min(d3, d + d2); - this.applyValue(numberSetting, d4); - PanelClickGui.panelClickGui.addToast(numberSetting.getName() + " set to " + this.formatValue(d4)); + double current = numberSetting.getValue().doubleValue(); + double step = numberSetting.getStep().doubleValue(); + double max = numberSetting.getMax().doubleValue(); + double newValue = Math.min(max, current + step); + this.applyValue(numberSetting, newValue); + PanelClickGui.panelClickGui.addToast(numberSetting.getName() + " set to " + this.formatValue(newValue)); } private void decrementValue(NumberSetting numberSetting) { - double d = numberSetting.getValue().doubleValue(); - double d2 = numberSetting.getStep().doubleValue(); - double d3 = numberSetting.getMin().doubleValue(); - double d4 = Math.max(d3, d - d2); - this.applyValue(numberSetting, d4); - PanelClickGui.panelClickGui.addToast(numberSetting.getName() + " set to " + this.formatValue(d4)); + double current = numberSetting.getValue().doubleValue(); + double step = numberSetting.getStep().doubleValue(); + double min = numberSetting.getMin().doubleValue(); + double newValue = Math.max(min, current - step); + this.applyValue(numberSetting, newValue); + PanelClickGui.panelClickGui.addToast(numberSetting.getName() + " set to " + this.formatValue(newValue)); } - private void applyValue(NumberSetting numberSetting, double d) { + private void applyValue(NumberSetting numberSetting, double value) { if (numberSetting.getValue() instanceof Integer) { - numberSetting.setValue((int)Math.round(d)); + numberSetting.setValue((int)Math.round(value)); } else if (numberSetting.getValue() instanceof Long) { - numberSetting.setValue(Math.round(d)); + numberSetting.setValue(Math.round(value)); } else if (numberSetting.getValue() instanceof Float) { - numberSetting.setValue(Float.valueOf((float)d)); + numberSetting.setValue(Float.valueOf((float)value)); } else { - numberSetting.setValue(d); + numberSetting.setValue(value); } } - private static void applyValueStatic(NumberSetting numberSetting, double d) { + private static void applyValueStatic(NumberSetting numberSetting, double value) { if (numberSetting.getValue() instanceof Integer) { - numberSetting.setValue((int)Math.round(d)); + numberSetting.setValue((int)Math.round(value)); } else if (numberSetting.getValue() instanceof Long) { - numberSetting.setValue(Math.round(d)); + numberSetting.setValue(Math.round(value)); } else if (numberSetting.getValue() instanceof Float) { - numberSetting.setValue(Float.valueOf((float)d)); + numberSetting.setValue(Float.valueOf((float)value)); } else { - numberSetting.setValue(d); + numberSetting.setValue(value); } } - private void updateHoverStates(NumberSetting numberSetting, int n, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, int n10) { - boolean bl; - boolean bl2 = n >= n3 && n <= n3 + n5 && n2 >= n4 && n2 <= n4 + n7; - this.minusButtonHover.put(numberSetting, bl2 && n < n3 + n6); - this.plusButtonHover.put(numberSetting, bl2 && n > n3 + n5 - n6); - boolean bl3 = bl = n >= n8 && n <= n8 + n10 && n2 >= n9 && n2 <= n9 + n10; - if (bl != this.editIconHover.getOrDefault(numberSetting, false)) { - this.editIconHover.put(numberSetting, bl); + private void updateHoverStates(NumberSetting numberSetting, int mouseX, int mouseY, int widgetX, int widgetY, int widgetWidth, int sidePadding, int widgetHeight, int iconX, int iconY, int iconSize) { + boolean iconHovered; + boolean overWidget = mouseX >= widgetX && mouseX <= widgetX + widgetWidth && mouseY >= widgetY && mouseY <= widgetY + widgetHeight; + this.minusButtonHover.put(numberSetting, overWidget && mouseX < widgetX + sidePadding); + this.plusButtonHover.put(numberSetting, overWidget && mouseX > widgetX + widgetWidth - sidePadding); + boolean dup = iconHovered = mouseX >= iconX && mouseX <= iconX + iconSize && mouseY >= iconY && mouseY <= iconY + iconSize; + if (iconHovered != this.editIconHover.getOrDefault(numberSetting, false)) { + this.editIconHover.put(numberSetting, iconHovered); this.editIconTimers.put(numberSetting, System.currentTimeMillis()); } } - private String formatValue(double d) { - return String.format(Locale.US, "%.1f", new Object[]{d}); + private String formatValue(double value) { + return String.format(Locale.US, "%.1f", new Object[]{value}); } @Override @@ -305,12 +305,12 @@ implements SettingRenderer { } @Override - public int getHeight(Setting setting, float f) { - return Math.round(24.0f * f); + public int getHeight(Setting setting, float scale) { + return Math.round(24.0f * scale); } static { editingText = ""; lastInputTime = 0L; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/gui/panel/setting/SettingRenderer.java b/src/main/java/shit/zen/gui/panel/setting/SettingRenderer.java index d9cc5bd..e3930cd 100644 --- a/src/main/java/shit/zen/gui/panel/setting/SettingRenderer.java +++ b/src/main/java/shit/zen/gui/panel/setting/SettingRenderer.java @@ -4,18 +4,18 @@ import net.minecraft.client.gui.GuiGraphics; import shit.zen.settings.Setting; public interface SettingRenderer { - int render(GuiGraphics var1, Setting var2, int var3, int var4, int var5, int var6, int var7, float var8, float var9); + int render(GuiGraphics guiGraphics, Setting setting, int x, int y, int width, int mouseX, int mouseY, float alpha, float scale); - boolean onClick(Setting var1, int var2, int var3, int var4, int var5, int var6, int var7, float var8); + boolean onClick(Setting setting, int x, int y, int width, int mouseX, int mouseY, int button, float scale); - boolean supports(Setting var1); + boolean supports(Setting setting); - default int getHeight(Setting setting, float f) { - return Math.round(20.0f * f); + default int getHeight(Setting setting, float scale) { + return Math.round(20.0f * scale); } - default void onMouseMove(double d, double d2) { + default void onMouseMove(double mouseX, double mouseY) { } - void onMouseRelease(double var1, double var3, int var5); -} \ No newline at end of file + void onMouseRelease(double mouseX, double mouseY, int button); +} diff --git a/src/main/java/shit/zen/gui/panel/setting/SettingRendererRegistry.java b/src/main/java/shit/zen/gui/panel/setting/SettingRendererRegistry.java index 53ac8ca..01293c6 100644 --- a/src/main/java/shit/zen/gui/panel/setting/SettingRendererRegistry.java +++ b/src/main/java/shit/zen/gui/panel/setting/SettingRendererRegistry.java @@ -39,37 +39,37 @@ public class SettingRendererRegistry { return null; } - public int render(GuiGraphics guiGraphics, Setting setting, int n, int n2, int n3, int n4, int n5, float f, float f2) { + public int render(GuiGraphics guiGraphics, Setting setting, int x, int y, int width, int mouseX, int mouseY, float alpha, float scale) { SettingRenderer settingRenderer = this.findRenderer(setting); if (!setting.getName().equals(versionString) || setting instanceof ModeSetting) { // empty if block } if (settingRenderer != null) { - return settingRenderer.render(guiGraphics, setting, n, n2, n3, n4, n5, f, f2); + return settingRenderer.render(guiGraphics, setting, x, y, width, mouseX, mouseY, alpha, scale); } return 0; } - public boolean onClick(Setting setting, int n, int n2, int n3, int n4, int n5, int n6, float f) { + public boolean onClick(Setting setting, int x, int y, int width, int mouseX, int mouseY, int button, float scale) { SettingRenderer settingRenderer = this.findRenderer(setting); if (settingRenderer != null) { - return settingRenderer.onClick(setting, n, n2, n3, n4, n5, n6, f); + return settingRenderer.onClick(setting, x, y, width, mouseX, mouseY, button, scale); } return false; } - public int getHeight(Setting setting, float f) { + public int getHeight(Setting setting, float scale) { SettingRenderer settingRenderer = this.findRenderer(setting); if (settingRenderer != null) { - return settingRenderer.getHeight(setting, f); + return settingRenderer.getHeight(setting, scale); } return 0; } - public int getHeightForScroll(Setting setting, float f) { + public int getHeightForScroll(Setting setting, float scale) { SettingRenderer settingRenderer = this.findRenderer(setting); if (settingRenderer != null) { - return settingRenderer.getHeight(setting, f); + return settingRenderer.getHeight(setting, scale); } return 0; } @@ -78,4 +78,4 @@ public class SettingRendererRegistry { versionString = "Mode"; INSTANCE = new SettingRendererRegistry(); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/hud/AutoPlayHud.java b/src/main/java/shit/zen/hud/AutoPlayHud.java index bfa242c..2417aec 100644 --- a/src/main/java/shit/zen/hud/AutoPlayHud.java +++ b/src/main/java/shit/zen/hud/AutoPlayHud.java @@ -28,15 +28,15 @@ implements IHudElement { if (AutoPlay.instance.pendingDisconnect) { return true; } - long l = AutoPlay.instance.disconnectTime; - if (l <= 0L) { + long disconnectTime = AutoPlay.instance.disconnectTime; + if (disconnectTime <= 0L) { return false; } - double d = AutoPlay.instance.getDelay().getValue().doubleValue() * 1000.0; - long l2 = System.currentTimeMillis() - l; - if ((double)l2 >= d) { - long l3 = l2 - (long)d; - return l3 < 500L; + double delayMs = AutoPlay.instance.getDelay().getValue().doubleValue() * 1000.0; + long elapsed = System.currentTimeMillis() - disconnectTime; + if ((double)elapsed >= delayMs) { + long afterDoneMs = elapsed - (long)delayMs; + return afterDoneMs < 500L; } return false; } @@ -46,25 +46,25 @@ implements IHudElement { if (!this.isVisible()) { return new IHudElement.Size(0.0f, 40.0f); } - long l = AutoPlay.instance.disconnectTime; - double d = AutoPlay.instance.getDelay().getValue().doubleValue() * 1000.0; - long l2 = System.currentTimeMillis() - l; - boolean bl = d <= 0.0 || (double)l2 >= d; - long l3 = bl ? l2 - (long)d : -1L; - String string = bl ? "Done!" : "Sending you to next game..."; - float f = font.getBounds(string).getWidth(); - float f2 = 28.0f; - float f3 = 18.0f + f2 + 8.0f + f + 18.0f; - float f4 = 30.0f; - float f5 = f3 - 30.0f; - float f6 = 60.0f; - f5 = Math.max(f5, f6); - float f7 = 40.0f; - if (bl) { - float f8 = Mth.clamp((float)l3 / 400.0f, 0.0f, 1.0f); - f7 = Mth.lerp(f8, 40.0f, 25.0f); + long disconnectTime = AutoPlay.instance.disconnectTime; + double delayMs = AutoPlay.instance.getDelay().getValue().doubleValue() * 1000.0; + long elapsed = System.currentTimeMillis() - disconnectTime; + boolean done = delayMs <= 0.0 || (double)elapsed >= delayMs; + long afterDoneMs = done ? elapsed - (long)delayMs : -1L; + String text = done ? "Done!" : "Sending you to next game..."; + float textWidth = font.getBounds(text).getWidth(); + float iconSize = 28.0f; + float totalWidth = 18.0f + iconSize + 8.0f + textWidth + 18.0f; + float padding = 30.0f; + float width = totalWidth - 30.0f; + float minWidth = 60.0f; + width = Math.max(width, minWidth); + float height = 40.0f; + if (done) { + float t = Mth.clamp((float)afterDoneMs / 400.0f, 0.0f, 1.0f); + height = Mth.lerp(t, 40.0f, 25.0f); } - return new IHudElement.Size(f5, f7); + return new IHudElement.Size(width, height); } @Override @@ -78,116 +78,116 @@ implements IHudElement { } @Override - public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float f, float f2, float f3, float f4, float f5) { + public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float x, float y, float width, float height, float alpha) { } @Override - public void render(DrawContext drawContext, float f, float f2, float f3, float f4, float f5) { - float f6; - float f7; - float f8; - float f9; - float f10; - float f11; - long l = 0L; - if (mc == null || mc.player == null || f5 <= 0.01f || AutoPlay.instance == null) { + public void render(DrawContext drawContext, float x, float y, float width, float height, float alpha) { + float checkEndY; + float checkEndX; + float checkMidY; + float checkMidX; + float arcBottom; + float arcProgress; + long afterDoneMs = 0L; + if (mc == null || mc.player == null || alpha <= 0.01f || AutoPlay.instance == null) { return; } - long l2 = System.currentTimeMillis(); + long now = System.currentTimeMillis(); if (!AutoPlay.instance.pendingDisconnect) { if (this.disableTime == -1L) { - this.disableTime = l2; + this.disableTime = now; } } else { this.disableTime = -1L; } if (this.lastUpdateTime == -1L) { - this.lastUpdateTime = l2; + this.lastUpdateTime = now; } - long l3 = l2 - this.lastUpdateTime; - this.lastUpdateTime = l2; - long l4 = AutoPlay.instance.disconnectTime; - double d = AutoPlay.instance.getDelay().getValue().doubleValue(); - double d2 = d * 1000.0; - long l5 = System.currentTimeMillis() - l4; - float f12 = d2 > 0.0 ? (float)((double)l5 / d2) : 1.0f; - f12 = Mth.clamp(f12, 0.0f, 1.0f); - float f13 = Mth.clamp((float)l3 / 200.0f, 0.0f, 1.0f); - this.animProgress = Mth.lerp(f13, this.animProgress, f12); - if (Math.abs(this.animProgress - f12) < 0.01f) { - this.animProgress = f12; + long deltaTime = now - this.lastUpdateTime; + this.lastUpdateTime = now; + long disconnectTime = AutoPlay.instance.disconnectTime; + double delaySec = AutoPlay.instance.getDelay().getValue().doubleValue(); + double delayMs = delaySec * 1000.0; + long elapsed = System.currentTimeMillis() - disconnectTime; + float targetProgress = delayMs > 0.0 ? (float)((double)elapsed / delayMs) : 1.0f; + targetProgress = Mth.clamp(targetProgress, 0.0f, 1.0f); + float lerpT = Mth.clamp((float)deltaTime / 200.0f, 0.0f, 1.0f); + this.animProgress = Mth.lerp(lerpT, this.animProgress, targetProgress); + if (Math.abs(this.animProgress - targetProgress) < 0.01f) { + this.animProgress = targetProgress; } - boolean bl = false; - if (l4 > 0L) { - long l6 = System.currentTimeMillis() - l4; - if (d2 <= 0.0 || (double)l6 >= d2) { - bl = true; - l = d2 > 0.0 ? l6 - (long)d2 : l6; + boolean done = false; + if (disconnectTime > 0L) { + long elapsed2 = System.currentTimeMillis() - disconnectTime; + if (delayMs <= 0.0 || (double)elapsed2 >= delayMs) { + done = true; + afterDoneMs = delayMs > 0.0 ? elapsed2 - (long)delayMs : elapsed2; } } - float f14 = f2 + f4 / 2.0f; - float f15 = f4 - 12.0f; - float f16 = f + 18.0f; - float f17 = f2 + 6.0f; - float f18 = f16 + f15 / 2.0f; - float f19 = f17 + f15 / 2.0f; - float f20 = f15 / 2.0f - 2.0f; - try (Paint object = new Paint(); + float centerY = y + height / 2.0f; + float iconSize = height - 12.0f; + float iconX = x + 18.0f; + float iconY = y + 6.0f; + float iconCx = iconX + iconSize / 2.0f; + float iconCy = iconY + iconSize / 2.0f; + float iconRadius = iconSize / 2.0f - 2.0f; + try (Paint paint = new Paint(); Path path = new Path()){ - float f21; - object.setStrokeWidth(2.0f); - object.setStrokeCap(Paint.StrokeCap.STROKE); - object.setStrokeJoin(Paint.StrokeJoin.ROUND); - object.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), f5)); + float arcLeft; + paint.setStrokeWidth(2.0f); + paint.setStrokeCap(Paint.StrokeCap.STROKE); + paint.setStrokeJoin(Paint.StrokeJoin.ROUND); + paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), alpha)); if (this.animProgress > 0.001f) { - f11 = 360.0f * this.animProgress; - f21 = f18 - f20; - f10 = f19 - f20; - f9 = f18 + f20; - f8 = f19 + f20; - drawContext.drawArc(f21, f10, f9, f8, -90.0f, f11, false, object); + arcProgress = 360.0f * this.animProgress; + arcLeft = iconCx - iconRadius; + arcBottom = iconCy - iconRadius; + checkMidX = iconCx + iconRadius; + checkMidY = iconCy + iconRadius; + drawContext.drawArc(arcLeft, arcBottom, checkMidX, checkMidY, -90.0f, arcProgress, false, paint); } - if (bl) { + if (done) { path.reset(); - f11 = Mth.clamp((float)l / 400.0f, 0.0f, 1.0f); - f21 = f18 - f20 * 0.4f; - f10 = f19; - f9 = f18 - f20 * 0.15f; - f8 = f19 + f20 * 0.3f; - f7 = f18 + f20 * 0.4f; - f6 = f19 - f20 * 0.3f; - float f22 = (float)Math.hypot(f9 - f21, f8 - f10); - float f23 = (float)Math.hypot(f7 - f9, f6 - f8); - float f24 = f22 + f23; - float f25 = f24 * f11; - path.moveTo(f21, f10); - if (f25 <= f22) { - float f26 = f25 / f22; - path.lineTo(Mth.lerp(f26, f21, f9), Mth.lerp(f26, f10, f8)); + arcProgress = Mth.clamp((float)afterDoneMs / 400.0f, 0.0f, 1.0f); + arcLeft = iconCx - iconRadius * 0.4f; + arcBottom = iconCy; + checkMidX = iconCx - iconRadius * 0.15f; + checkMidY = iconCy + iconRadius * 0.3f; + checkEndX = iconCx + iconRadius * 0.4f; + checkEndY = iconCy - iconRadius * 0.3f; + float seg1Len = (float)Math.hypot(checkMidX - arcLeft, checkMidY - arcBottom); + float seg2Len = (float)Math.hypot(checkEndX - checkMidX, checkEndY - checkMidY); + float totalLen = seg1Len + seg2Len; + float drawLen = totalLen * arcProgress; + path.moveTo(arcLeft, arcBottom); + if (drawLen <= seg1Len) { + float seg1T = drawLen / seg1Len; + path.lineTo(Mth.lerp(seg1T, arcLeft, checkMidX), Mth.lerp(seg1T, arcBottom, checkMidY)); } else { - path.lineTo(f9, f8); - float f27 = (f25 - f22) / f23; - path.lineTo(Mth.lerp(f27, f9, f7), Mth.lerp(f27, f8, f6)); + path.lineTo(checkMidX, checkMidY); + float seg2T = (drawLen - seg1Len) / seg2Len; + path.lineTo(Mth.lerp(seg2T, checkMidX, checkEndX), Mth.lerp(seg2T, checkMidY, checkEndY)); } - drawContext.drawPath(path, object); + drawContext.drawPath(path, paint); } } - String statusText = bl ? "Done!" : "Sending you to next game..."; - float f28 = f15; - f11 = f16 + f28 + 8.0f; + String statusText = done ? "Done!" : "Sending you to next game..."; + float textIconSize = iconSize; + arcProgress = iconX + textIconSize + 8.0f; try (Paint paint = new Paint()){ - paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), f5)); - f10 = f14 - font.getMetrics().capHeight() / 2.0f + 8.0f; - drawContext.drawString(statusText, f11, f10, font, paint); - f9 = 2.5f; - f8 = f10 + font.getMetrics().descent() + 8.0f; - f7 = f + f3 - f11 - 18.0f; + paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), alpha)); + arcBottom = centerY - font.getMetrics().capHeight() / 2.0f + 8.0f; + drawContext.drawString(statusText, arcProgress, arcBottom, font, paint); + checkMidX = 2.5f; + checkMidY = arcBottom + font.getMetrics().descent() + 8.0f; + checkEndX = x + width - arcProgress - 18.0f; paint.setStrokeCap(Paint.StrokeCap.FILL); - paint.setColor(this.colorWithAlpha(new Color(0, 0, 0, 40).getRGB(), f5)); + paint.setColor(this.colorWithAlpha(new Color(0, 0, 0, 40).getRGB(), alpha)); if (this.animProgress > 0.0f) { - paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), f5)); - f6 = f7 * this.animProgress; + paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), alpha)); + checkEndY = checkEndX * this.animProgress; } } } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/hud/DynamicIsland.java b/src/main/java/shit/zen/hud/DynamicIsland.java index ba87f63..80b6885 100644 --- a/src/main/java/shit/zen/hud/DynamicIsland.java +++ b/src/main/java/shit/zen/hud/DynamicIsland.java @@ -40,23 +40,23 @@ public class DynamicIsland { private long lastFrameTimestamp = 0L; public void onRender2D(Render2DEvent render2DEvent) { - float f; - float f2; + float islandY; + float outgoingY; IHudElement.Size size; if (ClientBase.mc.player == null) { return; } - long l = System.currentTimeMillis(); + long now = System.currentTimeMillis(); if (this.lastFrameTimestamp == 0L) { - this.lastFrameTimestamp = l; + this.lastFrameTimestamp = now; } - float f3 = (float)(l - this.lastFrameTimestamp) / 1000.0f; - this.lastFrameTimestamp = l; - f3 = Math.min(f3, 0.033333335f); - IHudElement iHudElement = this.activeElementSelector.visible(); - if (this.activeElement != iHudElement) { + float deltaSec = (float)(now - this.lastFrameTimestamp) / 1000.0f; + this.lastFrameTimestamp = now; + deltaSec = Math.min(deltaSec, 0.033333335f); + IHudElement visibleElement = this.activeElementSelector.visible(); + if (this.activeElement != visibleElement) { this.outgoingElement = this.activeElement; - this.activeElement = iHudElement; + this.activeElement = visibleElement; this.transitionAnim.reset(0.0f); this.transitionAnim.setTargetValue(1.0f); if (this.outgoingElement == null) { @@ -67,51 +67,51 @@ public class DynamicIsland { } } size = this.activeElement.getHudAlignment(); - float f4 = size.width(); - float f5 = size.height(); - float f6 = this.transitionAnim.getValue(); - if (this.outgoingElement != null && f6 < 1.0f) { - IHudElement.Size iHudElement$Size2 = this.outgoingElement.getHudAlignment(); - f4 = Mth.lerp(f6, iHudElement$Size2.width(), size.width()); - f5 = Mth.lerp(f6, iHudElement$Size2.height(), size.height()); + float targetWidth = size.width(); + float targetHeight = size.height(); + float progress = this.transitionAnim.getValue(); + if (this.outgoingElement != null && progress < 1.0f) { + IHudElement.Size outgoingSize = this.outgoingElement.getHudAlignment(); + targetWidth = Mth.lerp(progress, outgoingSize.width(), size.width()); + targetHeight = Mth.lerp(progress, outgoingSize.height(), size.height()); } - this.widthAnim.setTargetValue(f4); - this.heightAnim.setTargetValue(f5); - this.widthAnim.update(f3); - this.heightAnim.update(f3); - this.transitionAnim.update(f3); - float f7 = Math.max(0.0f, this.widthAnim.getValue() + 30.0f); - float f8 = Math.max(0.0f, this.heightAnim.getValue() + 3.0f); - float f9 = ((float)ClientBase.mc.getWindow().getGuiScaledWidth() - f7) / 2.0f; - float f10 = 25.0f; - float f11 = 25.0f; - float f12 = f11 + f10 / 2.0f; - float f13 = this.activeElement.getHudSize() == IHudElement.Alignment.CENTER ? f12 - f8 / 2.0f : f11; - if (this.outgoingElement != null && f6 < 1.0f) { - f2 = this.outgoingElement.getHudSize() == IHudElement.Alignment.CENTER ? f12 - f8 / 2.0f : f11; - f = Mth.lerp(f6, f2, f13); + this.widthAnim.setTargetValue(targetWidth); + this.heightAnim.setTargetValue(targetHeight); + this.widthAnim.update(deltaSec); + this.heightAnim.update(deltaSec); + this.transitionAnim.update(deltaSec); + float islandWidth = Math.max(0.0f, this.widthAnim.getValue() + 30.0f); + float islandHeight = Math.max(0.0f, this.heightAnim.getValue() + 3.0f); + float islandX = ((float)ClientBase.mc.getWindow().getGuiScaledWidth() - islandWidth) / 2.0f; + float anchorSize = 25.0f; + float topMargin = 25.0f; + float anchorCenterY = topMargin + anchorSize / 2.0f; + float activeY = this.activeElement.getHudSize() == IHudElement.Alignment.CENTER ? anchorCenterY - islandHeight / 2.0f : topMargin; + if (this.outgoingElement != null && progress < 1.0f) { + outgoingY = this.outgoingElement.getHudSize() == IHudElement.Alignment.CENTER ? anchorCenterY - islandHeight / 2.0f : topMargin; + islandY = Mth.lerp(progress, outgoingY, activeY); } else { - f = f13; + islandY = activeY; } - f2 = 12.0f; - final float finalF = f; - final float finalF2 = f2; + outgoingY = 12.0f; + final float finalY = islandY; + final float finalCornerRadius = outgoingY; if (this.activeElement.hasBackground()) { Renderer.renderConsumer((drawContext -> { try (Paint paint = new Paint()){ paint.setColor(new Color(0, 0, 0, 40).getRGB()); - drawContext.drawRoundedRect(RoundedRectangle.ofXYWHR(f9, finalF, f7, f8, finalF2), paint); + drawContext.drawRoundedRect(RoundedRectangle.ofXYWHR(islandX, finalY, islandWidth, islandHeight, finalCornerRadius), paint); } drawContext.save(); - drawContext.clipRoundedRect(RoundedRectangle.ofXYWHR(f9, finalF, f7, f8, finalF2), true); - this.activeElement.render(drawContext, f9, finalF, f7, f8, f6); + drawContext.clipRoundedRect(RoundedRectangle.ofXYWHR(islandX, finalY, islandWidth, islandHeight, finalCornerRadius), true); + this.activeElement.render(drawContext, islandX, finalY, islandWidth, islandHeight, progress); drawContext.restore(); })); } - RenderUtil.pushScissor((int)f9, (int)f, (int)f7, (int)f8); - this.activeElement.renderGui(render2DEvent.guiGraphics(), render2DEvent.poseStack(), f9, f, f7, f8, f6); + RenderUtil.pushScissor((int)islandX, (int)islandY, (int)islandWidth, (int)islandHeight); + this.activeElement.renderGui(render2DEvent.guiGraphics(), render2DEvent.poseStack(), islandX, islandY, islandWidth, islandHeight, progress); RenderUtil.popScissor(); - if (f6 >= 1.0f) { + if (progress >= 1.0f) { this.outgoingElement = null; } } diff --git a/src/main/java/shit/zen/hud/EventAlertHud.java b/src/main/java/shit/zen/hud/EventAlertHud.java index d40e52c..0ff7b3a 100644 --- a/src/main/java/shit/zen/hud/EventAlertHud.java +++ b/src/main/java/shit/zen/hud/EventAlertHud.java @@ -55,7 +55,7 @@ implements IHudElement { if (mc == null || mc.player == null || Projectiles.projectileMap.isEmpty()) { return Optional.empty(); } - Optional optional = Projectiles.projectileMap.entrySet().stream().filter(entry -> { + Optional nearest = Projectiles.projectileMap.entrySet().stream().filter(entry -> { if (mc.level == null) { return false; } @@ -66,19 +66,19 @@ implements IHudElement { if (!(entity instanceof ThrownEnderpearl)) { return false; } - Entity entity2 = ((ThrownEnderpearl)entity).getOwner(); - return entity2 != null && !entity2.equals(mc.player); + Entity owner = ((ThrownEnderpearl)entity).getOwner(); + return owner != null && !owner.equals(mc.player); }).map(java.util.Map.Entry::getValue).min(Comparator.comparingDouble(p -> p.getVelocity().distanceToSqr(mc.player.position()))); - return optional.map(e -> new EventAlertHud.AlertEntry(e.getVelocity(), e.getZ(), Optional.of((float)e.getX()), "Find an ender pearl!", "")); + return nearest.map(e -> new EventAlertHud.AlertEntry(e.getVelocity(), e.getZ(), Optional.of((float)e.getX()), "Find an ender pearl!", "")); } private Optional findEntityAlert() { if (mc == null || mc.player == null || mc.level == null) { return Optional.empty(); } - long l = System.currentTimeMillis(); - StreamSupport.stream(mc.level.entitiesForRendering().spliterator(), false).filter(entity -> entity instanceof LightningBolt && entity.isAlive()).forEach(entity -> this.activeAlerts.put(entity.position(), l)); - this.activeAlerts.entrySet().removeIf(entry -> l - entry.getValue() > 5000L); + long now = System.currentTimeMillis(); + StreamSupport.stream(mc.level.entitiesForRendering().spliterator(), false).filter(entity -> entity instanceof LightningBolt && entity.isAlive()).forEach(entity -> this.activeAlerts.put(entity.position(), now)); + this.activeAlerts.entrySet().removeIf(entry -> now - entry.getValue() > 5000L); if (this.activeAlerts.isEmpty()) { return Optional.empty(); } @@ -110,95 +110,95 @@ implements IHudElement { } @Override - public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float f, float f2, float f3, float f4, float f5) { + public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float x, float y, float width, float height, float alpha) { } @Override - public void render(DrawContext drawContext, float f, float f2, float f3, float f4, float f5) { - if (mc == null || mc.player == null || f5 <= 0.01f) { + public void render(DrawContext drawContext, float x, float y, float width, float height, float alpha) { + if (mc == null || mc.player == null || alpha <= 0.01f) { return; } - this.findBestAlert().ifPresent(eventAlertHud$AlertEntry -> { - float f6 = 12.0f; - float f7 = f + f6; - float f8 = f2 + f4 / 2.0f; - boolean bl = "".equals(eventAlertHud$AlertEntry.icon()); - if (bl) { - if (this.lastAlertPos == null || !this.lastAlertPos.equals(eventAlertHud$AlertEntry.pos())) { - this.lastAlertPos = eventAlertHud$AlertEntry.pos(); + this.findBestAlert().ifPresent(alert -> { + float padding = 12.0f; + float iconX = x + padding; + float centerY = y + height / 2.0f; + boolean hasPathIcon = "".equals(alert.icon()); + if (hasPathIcon) { + if (this.lastAlertPos == null || !this.lastAlertPos.equals(alert.pos())) { + this.lastAlertPos = alert.pos(); this.lastAlertTime = System.currentTimeMillis(); } } else { this.lastAlertPos = null; } try (Paint paint = new Paint()){ - Paint.LinearGradient paint$LinearGradient; - float f9; - paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), f5)); - float f10 = titleFont.getWidth(eventAlertHud$AlertEntry.icon()); - float f11 = f8 - (titleFont.getMetrics().ascent() + titleFont.getMetrics().descent()) / 2.0f - titleFont.getMetrics().descent(); - if (bl && iconPath != null) { - long l = System.currentTimeMillis() - this.lastAlertTime; - float f12 = Mth.clamp((float)l / 1000.0f, 0.0f, 1.0f); + Paint.LinearGradient gradient; + float descY; + paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), alpha)); + float iconWidth = titleFont.getWidth(alert.icon()); + float iconY = centerY - (titleFont.getMetrics().ascent() + titleFont.getMetrics().descent()) / 2.0f - titleFont.getMetrics().descent(); + if (hasPathIcon && iconPath != null) { + long elapsed = System.currentTimeMillis() - this.lastAlertTime; + float drawProgress = Mth.clamp((float)elapsed / 1000.0f, 0.0f, 1.0f); paint.setStrokeCap(Paint.StrokeCap.STROKE); paint.setStrokeWidth(1.5f); paint.setStrokeJoin(Paint.StrokeJoin.ROUND); - if (f12 < 1.0f) { - f9 = iconPathLength; - float f13 = f12 * f9; - paint$LinearGradient = GradientFactory.buildLinearGradient(new float[]{f13, f9}, 0.0f); + if (drawProgress < 1.0f) { + descY = iconPathLength; + float drawLen = drawProgress * descY; + gradient = GradientFactory.buildLinearGradient(new float[]{drawLen, descY}, 0.0f); try { - paint.setLinGradient(paint$LinearGradient); + paint.setLinGradient(gradient); } finally { - if (paint$LinearGradient != null) { - paint$LinearGradient.close(); + if (gradient != null) { + gradient.close(); } } } else { paint.setLinGradient(null); } drawContext.save(); - drawContext.translate(f7, f11); + drawContext.translate(iconX, iconY); drawContext.drawPath(iconPath, paint); drawContext.restore(); paint.setStrokeCap(Paint.StrokeCap.FILL); paint.setLinGradient(null); } else { - drawContext.drawString(eventAlertHud$AlertEntry.icon(), f7, f11, titleFont, paint); + drawContext.drawString(alert.icon(), iconX, iconY, titleFont, paint); } - float f14 = f7 + f10 + f6; - paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), f5)); - float f15 = f8 - iconFont.getMetrics().getLineHeight() / 2.0f + 2.0f; - drawContext.drawString(eventAlertHud$AlertEntry.title(), f14, f15, iconFont, paint); - String string = eventAlertHud$AlertEntry.getFormattedDescription(); - paint.setColor(this.colorWithAlpha(new Color(170, 170, 170).getRGB(), f5)); - f9 = f8 + timeFont.getMetrics().getLineHeight() / 2.0f + 6.0f; - drawContext.drawString(string, f14, f9, timeFont, paint); - paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), f5)); - Vec3 vec3 = mc.player.getEyePosition(); - Vec3 alertPos = eventAlertHud$AlertEntry.pos(); - double d = alertPos.x - vec3.x; - double d2 = alertPos.z - vec3.z; - if (Math.sqrt(d * d + d2 * d2) < 1.0) { - String string2 = alertPos.y > vec3.y ? "" : ""; - float f16 = subtitleFont.getWidth(string2); - float f17 = f + f3 - f6 - f16; - float f18 = f8 - (subtitleFont.getMetrics().ascent() + subtitleFont.getMetrics().descent()) / 2.0f - subtitleFont.getMetrics().descent(); - drawContext.drawString(string2, f17, f18, subtitleFont, paint); + float textX = iconX + iconWidth + padding; + paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), alpha)); + float titleY = centerY - iconFont.getMetrics().getLineHeight() / 2.0f + 2.0f; + drawContext.drawString(alert.title(), textX, titleY, iconFont, paint); + String desc = alert.getFormattedDescription(); + paint.setColor(this.colorWithAlpha(new Color(170, 170, 170).getRGB(), alpha)); + descY = centerY + timeFont.getMetrics().getLineHeight() / 2.0f + 6.0f; + drawContext.drawString(desc, textX, descY, timeFont, paint); + paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), alpha)); + Vec3 eyePos = mc.player.getEyePosition(); + Vec3 alertPos = alert.pos(); + double dx = alertPos.x - eyePos.x; + double dz = alertPos.z - eyePos.z; + if (Math.sqrt(dx * dx + dz * dz) < 1.0) { + String arrow = alertPos.y > eyePos.y ? "" : ""; + float arrowWidth = subtitleFont.getWidth(arrow); + float arrowX = x + width - padding - arrowWidth; + float arrowY = centerY - (subtitleFont.getMetrics().ascent() + subtitleFont.getMetrics().descent()) / 2.0f - subtitleFont.getMetrics().descent(); + drawContext.drawString(arrow, arrowX, arrowY, subtitleFont, paint); } else { - float f19 = subtitleFont.getWidth(""); - float f20 = f + f3 - f6 - f19; - float f21 = f8; + float arrowWidth = subtitleFont.getWidth(""); + float arrowX = x + width - padding - arrowWidth; + float arrowY = centerY; drawContext.save(); - drawContext.translate(f20 + f19 / 2.0f, f21); - float f22 = (float)(Mth.atan2(d2, d) * 57.29577951308232) - 90.0f; - float f23 = Mth.wrapDegrees(mc.player.getYRot()); - float f24 = Mth.wrapDegrees(f22 - f23); - drawContext.rotate(f24); - float f25 = subtitleFont.getMetrics().ascent(); - float f26 = subtitleFont.getMetrics().descent(); - float f27 = -(f25 + f26) / 2.0f; - drawContext.drawString("", -f19 / 2.0f, f27, subtitleFont, paint); + drawContext.translate(arrowX + arrowWidth / 2.0f, arrowY); + float targetAngle = (float)(Mth.atan2(dz, dx) * 57.29577951308232) - 90.0f; + float playerYaw = Mth.wrapDegrees(mc.player.getYRot()); + float rotation = Mth.wrapDegrees(targetAngle - playerYaw); + drawContext.rotate(rotation); + float ascent = subtitleFont.getMetrics().ascent(); + float descent = subtitleFont.getMetrics().descent(); + float baseOffsetY = -(ascent + descent) / 2.0f; + drawContext.drawString("", -arrowWidth / 2.0f, baseOffsetY, subtitleFont, paint); drawContext.restore(); } } @@ -213,7 +213,7 @@ implements IHudElement { Path path = null; float length = 0.0f; try { - short[] glyphCodes = titleFont.getGlyphCodes(""); + short[] glyphCodes = titleFont.getGlyphCodes(""); if (glyphCodes != null && glyphCodes.length > 0) { path = titleFont.getGlyphPath(glyphCodes[0]); if (path != null) { @@ -228,4 +228,4 @@ implements IHudElement { iconPath = path; iconPathLength = length; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/hud/HudElement.java b/src/main/java/shit/zen/hud/HudElement.java index 3ed4f8d..679babd 100644 --- a/src/main/java/shit/zen/hud/HudElement.java +++ b/src/main/java/shit/zen/hud/HudElement.java @@ -35,23 +35,23 @@ extends Module { public abstract void onSettings(); - public boolean mousePressed(int n, int n2, int n3) { - if (this.isHovered(n, n2) && n3 == 0) { + public boolean mousePressed(int mouseX, int mouseY, int button) { + if (this.isHovered(mouseX, mouseY) && button == 0) { this.visible = true; - this.dragOffsetX = (float)n - this.getX(); - this.dragOffsetY = (float)n2 - this.getY(); + this.dragOffsetX = (float)mouseX - this.getX(); + this.dragOffsetY = (float)mouseY - this.getY(); return true; } return false; } - public void mouseDragged(int n, int n2) { - this.x = (float)n - this.dragOffsetX; - this.y = (float)n2 - this.dragOffsetY; + public void mouseDragged(int mouseX, int mouseY) { + this.x = (float)mouseX - this.dragOffsetX; + this.y = (float)mouseY - this.dragOffsetY; } - public boolean isHovered(int n, int n2) { - return RenderUtil.isHovered(this.x, this.y, this.hudWidth, this.hudHeight, n, n2); + public boolean isHovered(int mouseX, int mouseY) { + return RenderUtil.isHovered(this.x, this.y, this.hudWidth, this.hudHeight, mouseX, mouseY); } public void stopDragging() { @@ -75,23 +75,23 @@ extends Module { } @Generated - public void setWidth(float f) { - this.hudWidth = f; + public void setWidth(float width) { + this.hudWidth = width; } @Generated - public void setHeight(float f) { - this.hudHeight = f; + public void setHeight(float height) { + this.hudHeight = height; } @Generated - protected void setDragging(boolean bl) { - this.dragging = bl; + protected void setDragging(boolean dragging) { + this.dragging = dragging; } @Override @Generated - public void setEnabled(boolean bl) { - this.visible = bl; + public void setEnabled(boolean enabled) { + this.visible = enabled; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/hud/IHudElement.java b/src/main/java/shit/zen/hud/IHudElement.java index 5fe11e8..f274ced 100644 --- a/src/main/java/shit/zen/hud/IHudElement.java +++ b/src/main/java/shit/zen/hud/IHudElement.java @@ -35,6 +35,6 @@ public interface IHudElement { return color & 0xFFFFFF | (int) (255.0f * clamped) << 24; } - default void render(DrawContext drawContext, float a, float b, float c, float d, float e) { + default void render(DrawContext drawContext, float x, float y, float width, float height, float alpha) { } } diff --git a/src/main/java/shit/zen/hud/KeyBindsHud.java b/src/main/java/shit/zen/hud/KeyBindsHud.java index d048f20..f4c95a3 100644 --- a/src/main/java/shit/zen/hud/KeyBindsHud.java +++ b/src/main/java/shit/zen/hud/KeyBindsHud.java @@ -152,9 +152,9 @@ extends HudElement { if (this.maxWidth >= 0.0f) { return; } - this.maxWidth = GlHelper.getStringWidth("", this.bindFont); + this.maxWidth = GlHelper.getStringWidth("", this.bindFont); this.totalHeight = GlHelper.getStringWidth("Hotkeys", this.nameFont); - this.visibleHeight = GlHelper.getStringWidth("", this.bindFont); + this.visibleHeight = GlHelper.getStringWidth("", this.bindFont); this.scrollOffset = GlHelper.getFontAscent(this.nameFont); this.alpha = GlHelper.getFontAscent(this.keyFont); this.rowHeight = GlHelper.getFontAscent(this.bindFont); @@ -162,7 +162,6 @@ extends HudElement { @EventTarget public void onTick(TickEvent tickEvent) { - Object object; if (mc.player == null) { this.rowList.clear(); this.rowMap.clear(); @@ -171,8 +170,8 @@ extends HudElement { } this.rowMap.clear(); this.removedRows.clear(); - List list = ZenClient.getInstance().getModuleManager().getModules(); - for (Module module : list) { + List moduleList = ZenClient.getInstance().getModuleManager().getModules(); + for (Module module : moduleList) { KeyBindsHud.KeyBindEntry entry = null; if (module instanceof TripleProvider tp) { Triple triple = (Triple) tp.getTriple(); @@ -194,7 +193,7 @@ extends HudElement { if (this.rowMap.containsKey(row.module)) continue; row.startRemove(); } - boolean bl = false; + boolean added = false; for (java.util.Map.Entry e : this.rowMap.entrySet()) { KeyBindsHud.KeyBindRow existing = this.removedRows.get(e.getKey()); if (existing != null) { @@ -203,21 +202,21 @@ extends HudElement { continue; } this.rowList.add(new KeyBindsHud.KeyBindRow(this, e.getKey(), e.getValue())); - bl = true; + added = true; } - if (bl) { + if (added) { this.rowList.sort((a, b) -> Double.compare(b.getNameWidth(), a.getNameWidth())); } } @Override - public void onRender2D(Render2DEvent render2DEvent, float f, float f2) { + public void onRender2D(Render2DEvent render2DEvent, float x, float y) { } @Override - public void onGlRender(GlRenderEvent glRenderEvent, float f, float f2) { - float f3; - boolean bl; + public void onGlRender(GlRenderEvent glRenderEvent, float x, float y) { + float panelWidth; + boolean rightAligned; this.initSettings(); this.rowList.removeIf(KeyBindsHud.KeyBindRow::isRemoveDone); this.rowList.forEach(KeyBindsHud.KeyBindRow::tick); @@ -226,82 +225,82 @@ extends HudElement { if (this.rowList.isEmpty() && this.scrollAnim.isDone() && this.fadeAnim.isDone()) { return; } - boolean bl2 = bl = f > (float)mc.getWindow().getGuiScaledWidth() / 2.0f; - if (this.isRightAligned != bl) { - this.isRightAligned = bl; + boolean rightSide = rightAligned = x > (float)mc.getWindow().getGuiScaledWidth() / 2.0f; + if (this.isRightAligned != rightAligned) { + this.isRightAligned = rightAligned; } - float f4 = this.scrollOffset + 10.0f; - float f5 = this.maxWidth + 3.0f + this.totalHeight + 10.0f; - float f6 = this.alpha + 10.0f; - float f7 = f5; + float headerHeight = this.scrollOffset + 10.0f; + float headerWidth = this.maxWidth + 3.0f + this.totalHeight + 10.0f; + float rowH = this.alpha + 10.0f; + float targetWidth = headerWidth; if (!this.rowList.isEmpty()) { - f3 = 0.0f; - for (KeyBindsHud.KeyBindRow keyBindsHud$KeyBindRow : this.rowList) { - float f8 = keyBindsHud$KeyBindRow.enabled ? f6 + 3.0f : 0.0f; - float f9 = f8 + (keyBindsHud$KeyBindRow.getNameWidth() + 10.0f); - if (!(f9 > f3)) continue; - f3 = f9; + panelWidth = 0.0f; + for (KeyBindsHud.KeyBindRow row : this.rowList) { + float keyBoxWidth = row.enabled ? rowH + 3.0f : 0.0f; + float rowWidth = keyBoxWidth + (row.getNameWidth() + 10.0f); + if (!(rowWidth > panelWidth)) continue; + panelWidth = rowWidth; } - f7 = Math.max(f5, f3); + targetWidth = Math.max(headerWidth, panelWidth); } if (this.scrollAnim.isDone() && this.rowList.isEmpty()) { - this.scrollAnim.setCurrentValue(f7); + this.scrollAnim.setCurrentValue(targetWidth); } - this.scrollAnim.animate(f7, 0.2, Easings.EASE_OUT_SINE); + this.scrollAnim.animate(targetWidth, 0.2, Easings.EASE_OUT_SINE); if (this.rowList.isEmpty()) { this.fadeAnim.animate(0.0, 0.2, Easings.EASE_IN_POW3); } else { this.fadeAnim.animate(1.0, 0.2, Easings.EASE_OUT_POW3); } - f3 = this.scrollAnim.getValueF(); - float f10 = this.fadeAnim.getValueF(); - float f11 = f2 + f4 + 3.0f; - for (KeyBindsHud.KeyBindRow keyBindsHud$KeyBindRow : this.rowList) { - if (keyBindsHud$KeyBindRow.visible) { - keyBindsHud$KeyBindRow.visible = false; - keyBindsHud$KeyBindRow.fadeAnim.setCurrentValue(f11); - keyBindsHud$KeyBindRow.slideAnim.setCurrentValue(keyBindsHud$KeyBindRow.rightAligned ? 20.0 : -20.0); - keyBindsHud$KeyBindRow.heightAnim.setCurrentValue(0.0); - keyBindsHud$KeyBindRow.alphaAnim.setCurrentValue(0.0); - keyBindsHud$KeyBindRow.slideAnim.animate(0.0, 0.2, Easings.EASE_OUT_POW3); - keyBindsHud$KeyBindRow.heightAnim.animate(1.0, 0.2, Easings.EASE_OUT_POW3); - keyBindsHud$KeyBindRow.alphaAnim.animate(f6 + 3.0f, 0.2, Easings.EASE_OUT_POW3); - } else if (keyBindsHud$KeyBindRow.animatingIn) { - keyBindsHud$KeyBindRow.animatingIn = false; - keyBindsHud$KeyBindRow.slideAnim.animate(0.0, 0.2, Easings.EASE_OUT_POW3); - keyBindsHud$KeyBindRow.heightAnim.animate(1.0, 0.2, Easings.EASE_OUT_POW3); - keyBindsHud$KeyBindRow.alphaAnim.animate(f6 + 3.0f, 0.2, Easings.EASE_OUT_POW3); + panelWidth = this.scrollAnim.getValueF(); + float globalAlpha = this.fadeAnim.getValueF(); + float rowY = y + headerHeight + 3.0f; + for (KeyBindsHud.KeyBindRow row : this.rowList) { + if (row.visible) { + row.visible = false; + row.fadeAnim.setCurrentValue(rowY); + row.slideAnim.setCurrentValue(row.rightAligned ? 20.0 : -20.0); + row.heightAnim.setCurrentValue(0.0); + row.alphaAnim.setCurrentValue(0.0); + row.slideAnim.animate(0.0, 0.2, Easings.EASE_OUT_POW3); + row.heightAnim.animate(1.0, 0.2, Easings.EASE_OUT_POW3); + row.alphaAnim.animate(rowH + 3.0f, 0.2, Easings.EASE_OUT_POW3); + } else if (row.animatingIn) { + row.animatingIn = false; + row.slideAnim.animate(0.0, 0.2, Easings.EASE_OUT_POW3); + row.heightAnim.animate(1.0, 0.2, Easings.EASE_OUT_POW3); + row.alphaAnim.animate(rowH + 3.0f, 0.2, Easings.EASE_OUT_POW3); } - keyBindsHud$KeyBindRow.fadeAnim.animate(f11, 0.15, Easings.EASE_OUT_SINE); - f11 += keyBindsHud$KeyBindRow.alphaAnim.getValueF(); + row.fadeAnim.animate(rowY, 0.15, Easings.EASE_OUT_SINE); + rowY += row.alphaAnim.getValueF(); } - Object object = glRenderEvent.drawContext(); - this.renderRows((DrawContext)object, f, f2, f3, this.isRightAligned, f10, f4, f6); - this.setWidth(f3); - this.setHeight(f11 - f2); + Object drawCtx = glRenderEvent.drawContext(); + this.renderRows((DrawContext)drawCtx, x, y, panelWidth, this.isRightAligned, globalAlpha, headerHeight, rowH); + this.setWidth(panelWidth); + this.setHeight(rowY - y); } - private void renderRows(DrawContext drawContext, float f, float f2, float f3, boolean bl, float f4, float f5, float f6) { - float f7; - float f8; - float f9; - float f10; - if (f4 <= 0.01f) { + private void renderRows(DrawContext drawContext, float x, float y, float width, boolean rightAligned, float alpha, float headerHeight, float rowH) { + float keyBoxLeft; + float boxWidth; + float rowAlpha; + float rowHeightFactor; + if (alpha <= 0.01f) { return; } - this.enabledPaint.setColor(ColorUtil.fromARGB(0, 0, 0, (int)(190.0f * f4))); - GlHelper.drawRoundedRect(f, f2, f3, f5, 4.5f, this.enabledPaint); - float f11 = f2 + 5.0f + (f5 - 10.0f - this.scrollOffset) / 2.0f + 1.0f; - int n = ColorUtil.fromARGB(255, 255, 255, (int)(255.0f * f4)); - this.disabledPaint.setColor(n); - if (bl) { - float f12 = f + f3 - 5.0f - this.maxWidth; - float f13 = f12 - 3.0f - this.totalHeight; - GlHelper.drawTextWithShadow("Hotkeys", f13, f11, this.nameFont, this.disabledPaint); - GlHelper.drawTextWithShadow("", f12, f11 + 1.0f, this.bindFont, this.disabledPaint); + this.enabledPaint.setColor(ColorUtil.fromARGB(0, 0, 0, (int)(190.0f * alpha))); + GlHelper.drawRoundedRect(x, y, width, headerHeight, 4.5f, this.enabledPaint); + float headerTextY = y + 5.0f + (headerHeight - 10.0f - this.scrollOffset) / 2.0f + 1.0f; + int whiteColor = ColorUtil.fromARGB(255, 255, 255, (int)(255.0f * alpha)); + this.disabledPaint.setColor(whiteColor); + if (rightAligned) { + float iconX = x + width - 5.0f - this.maxWidth; + float titleX = iconX - 3.0f - this.totalHeight; + GlHelper.drawTextWithShadow("Hotkeys", titleX, headerTextY, this.nameFont, this.disabledPaint); + GlHelper.drawTextWithShadow("", iconX, headerTextY + 1.0f, this.bindFont, this.disabledPaint); } else { - GlHelper.drawTextWithShadow("", f + 5.0f, f11 + 1.0f, this.bindFont, this.disabledPaint); - GlHelper.drawTextWithShadow("Hotkeys", f + 5.0f + this.maxWidth + 3.0f, f11, this.nameFont, this.disabledPaint); + GlHelper.drawTextWithShadow("", x + 5.0f, headerTextY + 1.0f, this.bindFont, this.disabledPaint); + GlHelper.drawTextWithShadow("Hotkeys", x + 5.0f + this.maxWidth + 3.0f, headerTextY, this.nameFont, this.disabledPaint); } if (this.rowList.isEmpty()) { return; @@ -311,89 +310,89 @@ extends HudElement { this.iconPaths[i].reset(); this.iconLoaded[i] = false; } - for (KeyBindsHud.KeyBindRow keyBindsHud$KeyBindRow : this.rowList) { - f10 = keyBindsHud$KeyBindRow.heightAnim.getValueF(); - if (f10 <= 0.0f) { - keyBindsHud$KeyBindRow.slideX = 0.0f; + for (KeyBindsHud.KeyBindRow row : this.rowList) { + rowHeightFactor = row.heightAnim.getValueF(); + if (rowHeightFactor <= 0.0f) { + row.slideX = 0.0f; continue; } - f9 = f4 * f10; - if (f9 <= 0.0f) { - keyBindsHud$KeyBindRow.slideX = 0.0f; + rowAlpha = alpha * rowHeightFactor; + if (rowAlpha <= 0.0f) { + row.slideX = 0.0f; continue; } - keyBindsHud$KeyBindRow.slideX = f9; - float f14 = f + keyBindsHud$KeyBindRow.slideAnim.getValueF(); - float f15 = keyBindsHud$KeyBindRow.fadeAnim.getValueF(); - f8 = keyBindsHud$KeyBindRow.getNameWidth() + 10.0f; - keyBindsHud$KeyBindRow.opacity = f15; - keyBindsHud$KeyBindRow.widthValue = f8; - int n2 = Math.max(0, Math.min(90, Math.round(90.0f * f9))); - Path path = this.iconPaths[n2]; + row.slideX = rowAlpha; + float rowX = x + row.slideAnim.getValueF(); + float rowFadeY = row.fadeAnim.getValueF(); + boxWidth = row.getNameWidth() + 10.0f; + row.opacity = rowFadeY; + row.widthValue = boxWidth; + int alphaBucket = Math.max(0, Math.min(90, Math.round(90.0f * rowAlpha))); + Path path = this.iconPaths[alphaBucket]; if (path == null) { - this.iconPaths[n2] = path = new Path(); + this.iconPaths[alphaBucket] = path = new Path(); } - this.iconLoaded[n2] = true; - if (keyBindsHud$KeyBindRow.enabled) { - if (bl) { - f7 = f14 + f3 - f6; - float f16 = f7 - 3.0f - f8; - keyBindsHud$KeyBindRow.rowHeightValue = f7; - keyBindsHud$KeyBindRow.alphaValue = f16; - path.addRoundedRect(RoundedRectangle.ofXYWHR(f16, f15, f8, f6, 4.5f)); - path.addRoundedRect(RoundedRectangle.ofXYWHR(f7, f15, f6, f6, 4.5f)); + this.iconLoaded[alphaBucket] = true; + if (row.enabled) { + if (rightAligned) { + keyBoxLeft = rowX + width - rowH; + float nameBoxLeft = keyBoxLeft - 3.0f - boxWidth; + row.rowHeightValue = keyBoxLeft; + row.alphaValue = nameBoxLeft; + path.addRoundedRect(RoundedRectangle.ofXYWHR(nameBoxLeft, rowFadeY, boxWidth, rowH, 4.5f)); + path.addRoundedRect(RoundedRectangle.ofXYWHR(keyBoxLeft, rowFadeY, rowH, rowH, 4.5f)); continue; } - keyBindsHud$KeyBindRow.rowHeightValue = f14; - keyBindsHud$KeyBindRow.alphaValue = f14 + f6 + 3.0f; - path.addRoundedRect(RoundedRectangle.ofXYWHR(f14, f15, f6, f6, 4.5f)); - path.addRoundedRect(RoundedRectangle.ofXYWHR(keyBindsHud$KeyBindRow.alphaValue, f15, f8, f6, 4.5f)); + row.rowHeightValue = rowX; + row.alphaValue = rowX + rowH + 3.0f; + path.addRoundedRect(RoundedRectangle.ofXYWHR(rowX, rowFadeY, rowH, rowH, 4.5f)); + path.addRoundedRect(RoundedRectangle.ofXYWHR(row.alphaValue, rowFadeY, boxWidth, rowH, 4.5f)); continue; } - keyBindsHud$KeyBindRow.alphaValue = f7 = bl ? f14 + f3 - f8 : f14; - keyBindsHud$KeyBindRow.rowHeightValue = f7; - path.addRoundedRect(RoundedRectangle.ofXYWHR(f7, f15, f8, f6, 4.5f)); + row.alphaValue = keyBoxLeft = rightAligned ? rowX + width - boxWidth : rowX; + row.rowHeightValue = keyBoxLeft; + path.addRoundedRect(RoundedRectangle.ofXYWHR(keyBoxLeft, rowFadeY, boxWidth, rowH, 4.5f)); } for (int i = 0; i < this.iconPaths.length; ++i) { if (!this.iconLoaded[i]) continue; this.backgroundPaint.setColor(ColorUtil.fromARGB(0, 0, 0, i)); drawContext.drawPath(this.iconPaths[i], this.backgroundPaint); } - for (KeyBindsHud.KeyBindRow keyBindsHud$KeyBindRow : this.rowList) { - if (keyBindsHud$KeyBindRow.slideX <= 0.0f) continue; - f10 = keyBindsHud$KeyBindRow.opacity; - f9 = keyBindsHud$KeyBindRow.widthValue; - int n3 = (int)(255.0f * keyBindsHud$KeyBindRow.slideX); - int n4 = ColorUtil.fromARGB(255, 255, 255, n3); - f8 = f10 + 5.0f + (f6 - 10.0f - this.alpha) / 2.0f; - float f17 = f10 + 5.0f + (f6 - 10.0f - this.rowHeight) / 2.0f + 2.5f; - this.disabledPaint.setColor(n4); - if (keyBindsHud$KeyBindRow.enabled) { - float f18 = keyBindsHud$KeyBindRow.rowHeightValue; - f7 = keyBindsHud$KeyBindRow.alphaValue; - if (bl) { - float f19 = f7 + f9 - 5.0f - keyBindsHud$KeyBindRow.getNameWidth(); - GlHelper.drawTextWithShadow(keyBindsHud$KeyBindRow.displayName, f19, f8, this.keyFont, this.disabledPaint); + for (KeyBindsHud.KeyBindRow row : this.rowList) { + if (row.slideX <= 0.0f) continue; + rowHeightFactor = row.opacity; + rowAlpha = row.widthValue; + int alphaInt = (int)(255.0f * row.slideX); + int rowColor = ColorUtil.fromARGB(255, 255, 255, alphaInt); + boxWidth = rowHeightFactor + 5.0f + (rowH - 10.0f - this.alpha) / 2.0f; + float keyTextY = rowHeightFactor + 5.0f + (rowH - 10.0f - this.rowHeight) / 2.0f + 2.5f; + this.disabledPaint.setColor(rowColor); + if (row.enabled) { + float keyBoxX = row.rowHeightValue; + keyBoxLeft = row.alphaValue; + if (rightAligned) { + float nameX = keyBoxLeft + rowAlpha - 5.0f - row.getNameWidth(); + GlHelper.drawTextWithShadow(row.displayName, nameX, boxWidth, this.keyFont, this.disabledPaint); } else { - GlHelper.drawTextWithShadow(keyBindsHud$KeyBindRow.displayName, f7 + 5.0f, f8, this.keyFont, this.disabledPaint); + GlHelper.drawTextWithShadow(row.displayName, keyBoxLeft + 5.0f, boxWidth, this.keyFont, this.disabledPaint); } - if (keyBindsHud$KeyBindRow.keyName == null) { - float f20 = f18 + (f6 - this.visibleHeight) / 2.0f; - GlHelper.drawTextWithShadow("", f20, f17, this.bindFont, this.disabledPaint); + if (row.keyName == null) { + float iconX = keyBoxX + (rowH - this.visibleHeight) / 2.0f; + GlHelper.drawTextWithShadow("", iconX, keyTextY, this.bindFont, this.disabledPaint); continue; } - FontRenderer fontRenderer = keyBindsHud$KeyBindRow.getFittingFont(this.keyFont, f6 - 5.0f); - float f21 = keyBindsHud$KeyBindRow.getKeyWidth(); - float f22 = f18 + (f6 - f21) / 2.0f; - float f23 = f10 + 5.0f + (f6 - 10.0f - (float)GlHelper.getFontAscent(fontRenderer)) / 2.0f; - GlHelper.drawTextWithShadow(keyBindsHud$KeyBindRow.keyName, f22, f23, fontRenderer, this.disabledPaint); + FontRenderer fontRenderer = row.getFittingFont(this.keyFont, rowH - 5.0f); + float keyWidth = row.getKeyWidth(); + float keyTextX = keyBoxX + (rowH - keyWidth) / 2.0f; + float keyDrawY = rowHeightFactor + 5.0f + (rowH - 10.0f - (float)GlHelper.getFontAscent(fontRenderer)) / 2.0f; + GlHelper.drawTextWithShadow(row.keyName, keyTextX, keyDrawY, fontRenderer, this.disabledPaint); continue; } - GlHelper.drawTextWithShadow(keyBindsHud$KeyBindRow.displayName, keyBindsHud$KeyBindRow.alphaValue + 5.0f, f8, this.keyFont, this.disabledPaint); + GlHelper.drawTextWithShadow(row.displayName, row.alphaValue + 5.0f, boxWidth, this.keyFont, this.disabledPaint); } } @Override public void onSettings() { } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/hud/LieDetector.java b/src/main/java/shit/zen/hud/LieDetector.java index 01a8e06..1f80072 100644 --- a/src/main/java/shit/zen/hud/LieDetector.java +++ b/src/main/java/shit/zen/hud/LieDetector.java @@ -34,23 +34,23 @@ extends HudElement { } @Override - public void onRender2D(Render2DEvent render2DEvent, float f, float f2) { + public void onRender2D(Render2DEvent render2DEvent, float x, float y) { } @Override - public void onGlRender(GlRenderEvent glRenderEvent, float f, float f2) { + public void onGlRender(GlRenderEvent glRenderEvent, float x, float y) { this.loadTextures(); this.needleAnim.animate(KillAura.aimingTarget == null ? 0.0 : (double)((LivingEntity)KillAura.aimingTarget).hurtTime, 0.32, Easings.BACK_OUT); this.needleAnim.tick(); PoseStack poseStack = glRenderEvent.poseStack(); RenderHelper.resetShaderColor(); - RenderUtil.drawTexture(this.panelTexture.getId(), poseStack, f, f2, this.panelDisplayWidth, this.panelDisplayHeight, 1.0f, -1); - RenderUtil.drawTexture(this.panelTexture.getId(), poseStack, f, f2, this.panelDisplayWidth, this.panelDisplayHeight, 1.0f, -1); - float f3 = f + (this.panelDisplayWidth - this.panelWidth / 2.0f) / 2.0f + 2.0f; - float f4 = f2 + this.panelDisplayHeight - this.pointerHeight; - RenderHelper.pushRotateAround(poseStack, f3 + 9.0f, f4 + 8.5f, this.needleAnim.getValueF() * -18.0f); - RenderUtil.drawTexture(this.pointerTexture.getId(), poseStack, f3, f4, this.panelWidth, this.pointerHeight, 1.0f, -1); - RenderUtil.drawTexture(this.pointerTexture.getId(), poseStack, f3, f4, this.panelWidth, this.pointerHeight, 1.0f, -1); + RenderUtil.drawTexture(this.panelTexture.getId(), poseStack, x, y, this.panelDisplayWidth, this.panelDisplayHeight, 1.0f, -1); + RenderUtil.drawTexture(this.panelTexture.getId(), poseStack, x, y, this.panelDisplayWidth, this.panelDisplayHeight, 1.0f, -1); + float pointerX = x + (this.panelDisplayWidth - this.panelWidth / 2.0f) / 2.0f + 2.0f; + float pointerY = y + this.panelDisplayHeight - this.pointerHeight; + RenderHelper.pushRotateAround(poseStack, pointerX + 9.0f, pointerY + 8.5f, this.needleAnim.getValueF() * -18.0f); + RenderUtil.drawTexture(this.pointerTexture.getId(), poseStack, pointerX, pointerY, this.panelWidth, this.pointerHeight, 1.0f, -1); + RenderUtil.drawTexture(this.pointerTexture.getId(), poseStack, pointerX, pointerY, this.panelWidth, this.pointerHeight, 1.0f, -1); RenderHelper.popPose(poseStack); this.setWidth(this.panelDisplayWidth); this.setHeight(this.panelDisplayHeight); diff --git a/src/main/java/shit/zen/hud/ModuleListHud.java b/src/main/java/shit/zen/hud/ModuleListHud.java index f2aa1fb..df5f966 100644 --- a/src/main/java/shit/zen/hud/ModuleListHud.java +++ b/src/main/java/shit/zen/hud/ModuleListHud.java @@ -22,11 +22,11 @@ extends HudElement { } private List getVisibleModules() { - return ZenClient.getInstance().getModuleManager().getModules().stream().filter(module -> !(module instanceof ModuleListHud) && !(module instanceof Interface)).filter(Module::isEnabled).filter(module -> !module.getName().isEmpty()).sorted((module, module2) -> Mth.ceil(GlHelper.getStringWidth(module2.getName(), FontPresets.pingfang(16.0f)) - GlHelper.getStringWidth(module.getName(), FontPresets.pingfang(16.0f)))).collect(Collectors.toList()); + return ZenClient.getInstance().getModuleManager().getModules().stream().filter(module -> !(module instanceof ModuleListHud) && !(module instanceof Interface)).filter(Module::isEnabled).filter(module -> !module.getName().isEmpty()).sorted((a, b) -> Mth.ceil(GlHelper.getStringWidth(b.getName(), FontPresets.pingfang(16.0f)) - GlHelper.getStringWidth(a.getName(), FontPresets.pingfang(16.0f)))).collect(Collectors.toList()); } @Override - public void onRender2D(Render2DEvent render2DEvent, float f, float f2) { + public void onRender2D(Render2DEvent render2DEvent, float x, float y) { } @EventTarget @@ -38,21 +38,21 @@ extends HudElement { return; } FontRenderer fontRenderer = FontPresets.pingfang(16.0f); - List list = this.getVisibleModules(); + List visibleModules = this.getVisibleModules(); GlHelper.drawTextShadowLegacy("Z", 4.0f, 4.0f, fontRenderer, ColorUtil.getRainbowColor(10, 1).getRGB()); GlHelper.drawTextShadowLegacy("en (" + mc.getFps() + "FPS)", 4.0f + GlHelper.getStringWidth("Z", fontRenderer), 4.0f, fontRenderer, -1); - if (!list.isEmpty()) { - float f = 0.0f; - for (Module module : list) { - GlHelper.drawTextShadowLegacy(module.getName(), 4.0f, 16.0f + f, fontRenderer, ColorUtil.getRainbowColor(10, list.indexOf(module) * 8).getRGB()); + if (!visibleModules.isEmpty()) { + float offsetY = 0.0f; + for (Module module : visibleModules) { + GlHelper.drawTextShadowLegacy(module.getName(), 4.0f, 16.0f + offsetY, fontRenderer, ColorUtil.getRainbowColor(10, visibleModules.indexOf(module) * 8).getRGB()); Objects.requireNonNull(mc.font); - f += (float)(9 + 2); + offsetY += (float)(9 + 2); } } } @Override - public void onGlRender(GlRenderEvent glRenderEvent, float f, float f2) { + public void onGlRender(GlRenderEvent glRenderEvent, float x, float y) { } @Override diff --git a/src/main/java/shit/zen/hud/NeverloseWatermark.java b/src/main/java/shit/zen/hud/NeverloseWatermark.java index 01a0874..3044255 100644 --- a/src/main/java/shit/zen/hud/NeverloseWatermark.java +++ b/src/main/java/shit/zen/hud/NeverloseWatermark.java @@ -30,90 +30,90 @@ public class NeverloseWatermark { if (ClientBase.mc.options.renderDebug) { return; } - float f = ClientBase.mc.getWindow().getGuiScaledWidth(); - float f2 = f / 2.0f - this.getTotalWidth() / 2.0f; - float f3 = 10.0f; - float f4 = 6.0f; - float f5 = 4.5f; - float f6 = 15.0f; - float f7 = this.measureText("ZEN", this.boldFont); - f2 += f7 + f4; - f2 = this.renderSectionLegacy(render2DEvent.poseStack(), f2, f3, this.getServerName(), this.smallFont, "", f5, f6, f4); - f2 = this.renderSectionLegacy(render2DEvent.poseStack(), f2, f3, this.getPingText(), this.regularFont, "", f5, f6, f4); - f2 = this.renderSectionLegacy(render2DEvent.poseStack(), f2, f3, this.getFpsText(), this.regularFont, "", f5, f6, f4); - f2 = this.renderSectionLegacy(render2DEvent.poseStack(), f2, f3, this.getTimeText(), this.regularFont, "", f5, f6, f4); - f2 = this.renderSectionLegacy(render2DEvent.poseStack(), f2, f3, this.getCpsText(), this.regularFont, "", f5, f6, f4); - this.renderSectionLegacy(render2DEvent.poseStack(), f2, f3, this.getCoordText(), this.regularFont, "", f5, f6, f4); + float screenWidth = ClientBase.mc.getWindow().getGuiScaledWidth(); + float currentX = screenWidth / 2.0f - this.getTotalWidth() / 2.0f; + float y = 10.0f; + float gap = 6.0f; + float cornerRadius = 4.5f; + float blurRadius = 15.0f; + float zenWidth = this.measureText("ZEN", this.boldFont); + currentX += zenWidth + gap; + currentX = this.renderSectionLegacy(render2DEvent.poseStack(), currentX, y, this.getServerName(), this.smallFont, "", cornerRadius, blurRadius, gap); + currentX = this.renderSectionLegacy(render2DEvent.poseStack(), currentX, y, this.getPingText(), this.regularFont, "", cornerRadius, blurRadius, gap); + currentX = this.renderSectionLegacy(render2DEvent.poseStack(), currentX, y, this.getFpsText(), this.regularFont, "", cornerRadius, blurRadius, gap); + currentX = this.renderSectionLegacy(render2DEvent.poseStack(), currentX, y, this.getTimeText(), this.regularFont, "", cornerRadius, blurRadius, gap); + currentX = this.renderSectionLegacy(render2DEvent.poseStack(), currentX, y, this.getCpsText(), this.regularFont, "", cornerRadius, blurRadius, gap); + this.renderSectionLegacy(render2DEvent.poseStack(), currentX, y, this.getCoordText(), this.regularFont, "", cornerRadius, blurRadius, gap); } - private float renderSectionLegacy(PoseStack poseStack, float f, float f2, String string, FontRenderer fontRenderer, String string2, float f3, float f4, float f5) { - float f6 = this.measureTextWithSub(string, fontRenderer, string2); - return f + f6 + f5; + private float renderSectionLegacy(PoseStack poseStack, float x, float y, String text, FontRenderer fontRenderer, String icon, float cornerRadius, float blurRadius, float gap) { + float sectionWidth = this.measureTextWithSub(text, fontRenderer, icon); + return x + sectionWidth + gap; } public void onGlRender(GlRenderEvent glRenderEvent) { if (ClientBase.mc.options.renderDebug) { return; } - float f = ClientBase.mc.getWindow().getGuiScaledWidth(); - float f2 = f / 2.0f - this.getTotalWidth() / 2.0f; - float f3 = 10.0f; - float f4 = 6.0f; - float f5 = 4.5f; - f2 = this.renderSection(glRenderEvent.drawContext(), f2, f3, "ZEN", this.boldFont, f5, f4); - f2 = this.renderSectionWithSub(glRenderEvent.drawContext(), f2, f3, this.getServerName(), this.smallFont, "", f5, f4); - f2 = this.renderSectionWithSub(glRenderEvent.drawContext(), f2, f3, this.getPingText(), this.regularFont, "", f5, f4); - f2 = this.renderSectionWithSub(glRenderEvent.drawContext(), f2, f3, this.getFpsText(), this.regularFont, "", f5, f4); - f2 = this.renderSectionWithSub(glRenderEvent.drawContext(), f2, f3, this.getTimeText(), this.regularFont, "", f5, f4); - f2 = this.renderSectionWithSub(glRenderEvent.drawContext(), f2, f3, this.getCpsText(), this.regularFont, "", f5, f4); - this.renderSectionWithSub(glRenderEvent.drawContext(), f2, f3, this.getCoordText(), this.regularFont, "", f5, f4); + float screenWidth = ClientBase.mc.getWindow().getGuiScaledWidth(); + float currentX = screenWidth / 2.0f - this.getTotalWidth() / 2.0f; + float y = 10.0f; + float gap = 6.0f; + float cornerRadius = 4.5f; + currentX = this.renderSection(glRenderEvent.drawContext(), currentX, y, "ZEN", this.boldFont, cornerRadius, gap); + currentX = this.renderSectionWithSub(glRenderEvent.drawContext(), currentX, y, this.getServerName(), this.smallFont, "", cornerRadius, gap); + currentX = this.renderSectionWithSub(glRenderEvent.drawContext(), currentX, y, this.getPingText(), this.regularFont, "", cornerRadius, gap); + currentX = this.renderSectionWithSub(glRenderEvent.drawContext(), currentX, y, this.getFpsText(), this.regularFont, "", cornerRadius, gap); + currentX = this.renderSectionWithSub(glRenderEvent.drawContext(), currentX, y, this.getTimeText(), this.regularFont, "", cornerRadius, gap); + currentX = this.renderSectionWithSub(glRenderEvent.drawContext(), currentX, y, this.getCpsText(), this.regularFont, "", cornerRadius, gap); + this.renderSectionWithSub(glRenderEvent.drawContext(), currentX, y, this.getCoordText(), this.regularFont, "", cornerRadius, gap); } - private float renderSection(DrawContext drawContext, float f, float f2, String string, FontRenderer fontRenderer, float f3, float f4) { - float f5 = 8.0f; - float f6 = (float)GlHelper.getFontAscent(this.boldFont) + 12.0f - 2.0f; - float f7 = GlHelper.getStringWidth(string, fontRenderer); - float f8 = f5 + f7 + f5 - 5.0f; - GlHelper.drawRoundedRect(f, f2, f8, f6, f3, this.backgroundPaint); - float f9 = f2 + (f6 - (float)GlHelper.getFontAscent(fontRenderer)) / 2.0f + 3.5f; - GlHelper.drawTextShadowLegacy(string, f + f5 - 2.0f, f9, fontRenderer, this.textPaint.getColor()); - return f + f8 + f4; + private float renderSection(DrawContext drawContext, float x, float y, String text, FontRenderer fontRenderer, float cornerRadius, float gap) { + float padding = 8.0f; + float boxHeight = (float)GlHelper.getFontAscent(this.boldFont) + 12.0f - 2.0f; + float textWidth = GlHelper.getStringWidth(text, fontRenderer); + float boxWidth = padding + textWidth + padding - 5.0f; + GlHelper.drawRoundedRect(x, y, boxWidth, boxHeight, cornerRadius, this.backgroundPaint); + float textY = y + (boxHeight - (float)GlHelper.getFontAscent(fontRenderer)) / 2.0f + 3.5f; + GlHelper.drawTextShadowLegacy(text, x + padding - 2.0f, textY, fontRenderer, this.textPaint.getColor()); + return x + boxWidth + gap; } - private float renderSectionWithSub(DrawContext drawContext, float f, float f2, String string, FontRenderer fontRenderer, String string2, float f3, float f4) { - float f5 = 8.0f; - float f6 = (float)GlHelper.getFontAscent(fontRenderer) + 12.0f; - float f7 = GlHelper.getStringWidth(string, fontRenderer); - float f8 = GlHelper.getStringWidth(string2, this.tinyFont); - float f9 = f5 + f8 + 5.0f + f7 + f5 - 4.0f; - GlHelper.drawRoundedRect(f, f2, f9, f6, f3, this.backgroundPaint); - float f10 = f2 + (f6 - (float)GlHelper.getFontAscent(this.tinyFont)) / 2.0f + 3.0f; - GlHelper.drawTextShadowLegacy(string2, f + f5 - 1.0f, f10, this.tinyFont, this.accentPaint.getColor()); - float f11 = f2 + (f6 - (float)GlHelper.getFontAscent(fontRenderer)) / 2.0f + 1.0f; - GlHelper.drawTextShadowLegacy(string, f + f5 + f8 + 5.0f - 3.0f, f11, fontRenderer, this.textPaint.getColor()); - return f + f9 + f4; + private float renderSectionWithSub(DrawContext drawContext, float x, float y, String text, FontRenderer fontRenderer, String icon, float cornerRadius, float gap) { + float padding = 8.0f; + float boxHeight = (float)GlHelper.getFontAscent(fontRenderer) + 12.0f; + float textWidth = GlHelper.getStringWidth(text, fontRenderer); + float iconWidth = GlHelper.getStringWidth(icon, this.tinyFont); + float boxWidth = padding + iconWidth + 5.0f + textWidth + padding - 4.0f; + GlHelper.drawRoundedRect(x, y, boxWidth, boxHeight, cornerRadius, this.backgroundPaint); + float iconY = y + (boxHeight - (float)GlHelper.getFontAscent(this.tinyFont)) / 2.0f + 3.0f; + GlHelper.drawTextShadowLegacy(icon, x + padding - 1.0f, iconY, this.tinyFont, this.accentPaint.getColor()); + float textY = y + (boxHeight - (float)GlHelper.getFontAscent(fontRenderer)) / 2.0f + 1.0f; + GlHelper.drawTextShadowLegacy(text, x + padding + iconWidth + 5.0f - 3.0f, textY, fontRenderer, this.textPaint.getColor()); + return x + boxWidth + gap; } - private float measureText(String string, FontRenderer fontRenderer) { - float f = 8.0f; - return f + GlHelper.getStringWidth(string, fontRenderer) + f - 5.0f; + private float measureText(String text, FontRenderer fontRenderer) { + float padding = 8.0f; + return padding + GlHelper.getStringWidth(text, fontRenderer) + padding - 5.0f; } private float getTotalWidth() { - float f = 0.0f; - float f2 = 6.0f; - f += this.measureText("ZEN", this.boldFont) + f2; - f += this.measureTextWithSub(this.getServerName(), this.smallFont, "") + f2; - f += this.measureTextWithSub(this.getPingText(), this.regularFont, "") + f2; - f += this.measureTextWithSub(this.getFpsText(), this.regularFont, "") + f2; - f += this.measureTextWithSub(this.getTimeText(), this.regularFont, "") + f2; - f += this.measureTextWithSub(this.getCpsText(), this.regularFont, "") + f2; - return f += this.measureTextWithSub(this.getCoordText(), this.regularFont, ""); + float total = 0.0f; + float gap = 6.0f; + total += this.measureText("ZEN", this.boldFont) + gap; + total += this.measureTextWithSub(this.getServerName(), this.smallFont, "") + gap; + total += this.measureTextWithSub(this.getPingText(), this.regularFont, "") + gap; + total += this.measureTextWithSub(this.getFpsText(), this.regularFont, "") + gap; + total += this.measureTextWithSub(this.getTimeText(), this.regularFont, "") + gap; + total += this.measureTextWithSub(this.getCpsText(), this.regularFont, "") + gap; + return total += this.measureTextWithSub(this.getCoordText(), this.regularFont, ""); } - private float measureTextWithSub(String string, FontRenderer fontRenderer, String string2) { - float f = 8.0f; - return f + GlHelper.getStringWidth(string2, this.tinyFont) + 5.0f + GlHelper.getStringWidth(string, fontRenderer) + f - 4.0f; + private float measureTextWithSub(String text, FontRenderer fontRenderer, String icon) { + float padding = 8.0f; + return padding + GlHelper.getStringWidth(icon, this.tinyFont) + 5.0f + GlHelper.getStringWidth(text, fontRenderer) + padding - 4.0f; } private String getServerName() { @@ -147,4 +147,4 @@ public class NeverloseWatermark { private String getCoordText() { return this.timeFormat.format(new Date()); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/hud/PlayerListHud.java b/src/main/java/shit/zen/hud/PlayerListHud.java index 5a6aec1..e9d313b 100644 --- a/src/main/java/shit/zen/hud/PlayerListHud.java +++ b/src/main/java/shit/zen/hud/PlayerListHud.java @@ -67,8 +67,8 @@ extends HudElement { this.player = player; this.items = items; this.displayName = player.getName().getString(); - for (ItemStack s : items) { - this.itemStacks.put(s.getItem(), s); + for (ItemStack stack : items) { + this.itemStacks.put(stack.getItem(), stack); } } @@ -144,8 +144,8 @@ extends HudElement { } return; } - List list = mc.level.players(); - ArrayList playerList = new ArrayList<>(list); + List levelPlayers = mc.level.players(); + ArrayList playerList = new ArrayList<>(levelPlayers); for (PlayerListHud.PlayerEntry entry : this.playerEntryList) { if (!playerList.stream().noneMatch(p -> p.getUUID().equals(entry.player.getUUID()))) continue; entry.startRemove(); @@ -181,13 +181,13 @@ extends HudElement { } }); } - this.removedEntries.removeIf(uUID -> { - Player player = mc.level.getPlayerByUUID(uUID); + this.removedEntries.removeIf(uuid -> { + Player player = mc.level.getPlayerByUUID(uuid); if (player == null) { return true; } - MobEffectInstance mobEffectInstance = player.getEffect(MobEffects.ABSORPTION); - return mobEffectInstance == null || mobEffectInstance.getAmplifier() < 3; + MobEffectInstance absorption = player.getEffect(MobEffects.ABSORPTION); + return absorption == null || absorption.getAmplifier() < 3; }); } @@ -200,23 +200,23 @@ extends HudElement { @EventTarget public void onPacket(PacketEvent packetEvent) { - MobEffectInstance mobEffectInstance; + MobEffectInstance absorption; Player player; Entity entity; - ClientboundEntityEventPacket clientboundEntityEventPacket; + ClientboundEntityEventPacket entityEventPacket; if (mc.level == null) { return; } Packet packet = packetEvent.getPacket(); - if (packet instanceof ClientboundEntityEventPacket && (clientboundEntityEventPacket = (ClientboundEntityEventPacket)packet).getEventId() == 35 && (entity = clientboundEntityEventPacket.getEntity(mc.level)) instanceof Player) { + if (packet instanceof ClientboundEntityEventPacket && (entityEventPacket = (ClientboundEntityEventPacket)packet).getEventId() == 35 && (entity = entityEventPacket.getEntity(mc.level)) instanceof Player) { player = (Player)entity; ChatUtil.print("§e[提示] §f" + player.getName().getString() + " 触发了不死图腾!"); this.updatePlayerItem(player, Items.TOTEM_OF_UNDYING); } if (packet instanceof ClientboundSetEntityDataPacket dataPacket && (entity = mc.level.getEntity(dataPacket.id())) instanceof Player - && (mobEffectInstance = (player = (Player)entity).getEffect(MobEffects.ABSORPTION)) != null - && mobEffectInstance.getAmplifier() >= 3 + && (absorption = (player = (Player)entity).getEffect(MobEffects.ABSORPTION)) != null + && absorption.getAmplifier() >= 3 && player.hasEffect(MobEffects.REGENERATION) && !this.removedEntries.contains(player.getUUID())) { ChatUtil.print("§6[提示] §f" + player.getName().getString() + " 吃下了附魔金苹果!"); @@ -226,23 +226,23 @@ extends HudElement { } private void updatePlayerItem(Player player, Item item) { - this.playerEntryList.stream().filter(playerListHud$PlayerEntry -> playerListHud$PlayerEntry.player.getUUID().equals(player.getUUID())).findFirst().ifPresent(playerListHud$PlayerEntry -> { - playerListHud$PlayerEntry.flaggedItems.add(item); - playerListHud$PlayerEntry.itemStacks.remove(item); + this.playerEntryList.stream().filter(entry -> entry.player.getUUID().equals(player.getUUID())).findFirst().ifPresent(entry -> { + entry.flaggedItems.add(item); + entry.itemStacks.remove(item); }); } @Override - public void onRender2D(Render2DEvent render2DEvent, float f, float f2) { + public void onRender2D(Render2DEvent render2DEvent, float x, float y) { } @Override - public void onGlRender(GlRenderEvent glRenderEvent, float f, float f2) { - float f3; - float f4; - float f5; - float f6; - boolean bl; + public void onGlRender(GlRenderEvent glRenderEvent, float x, float y) { + float rightFade; + float leftFade; + float entryY; + float panelWidth; + boolean isRightAligned; this.playerEntryList.removeIf(PlayerListHud.PlayerEntry::isRemoveDone); this.playerEntryList.forEach(PlayerListHud.PlayerEntry::tick); this.slideAnim.tick(); @@ -251,218 +251,218 @@ extends HudElement { if (this.playerEntryList.isEmpty() && this.slideAnim.isDone() && this.fadeAnim.isDone()) { return; } - boolean bl2 = bl = f + this.getWidth() / 2.0f > (float)mc.getWindow().getGuiScaledWidth() / 2.0f; - if (this.wasRightAligned != bl && this.rightAlignAnim.isDone()) { + boolean rightSide = isRightAligned = x + this.getWidth() / 2.0f > (float)mc.getWindow().getGuiScaledWidth() / 2.0f; + if (this.wasRightAligned != isRightAligned && this.rightAlignAnim.isDone()) { this.rightAlign = this.wasRightAligned; - this.wasRightAligned = bl; + this.wasRightAligned = isRightAligned; this.rightAlignAnim.setCurrentValue(0.0); this.rightAlignAnim.animate(1.0, 0.3, Easings.EASE_OUT_SINE); } - float f7 = 5.0f; - float f8 = 3.0f; - float f9 = 4.5f; - float f10 = 15.0f; - float f11 = 0.7f; - String string = ""; - String string2 = "Playerlist"; - float f12 = GlHelper.getStringWidth(string, this.subFont); - float f13 = GlHelper.getStringWidth(string2, this.nameFont); - float f14 = (float)GlHelper.getFontAscent(this.nameFont) + f7 * 2.0f; - float f15 = f12 + f8 + f13 + f7 * 2.0f; - float f16 = 20.0f; - float f17 = 16.0f; - float f18 = f16 + f7 * 2.0f; - float f19 = f15; + float padding = 5.0f; + float gap = 3.0f; + float spacing = 4.5f; + float cornerRadius = 15.0f; + float blurStrength = 0.7f; + String iconText = ""; + String titleText = "Playerlist"; + float iconWidth = GlHelper.getStringWidth(iconText, this.subFont); + float titleWidth = GlHelper.getStringWidth(titleText, this.nameFont); + float headerHeight = (float)GlHelper.getFontAscent(this.nameFont) + padding * 2.0f; + float headerWidth = iconWidth + gap + titleWidth + padding * 2.0f; + float headSize = 20.0f; + float itemSize = 16.0f; + float entryHeight = headSize + padding * 2.0f; + float targetWidth = headerWidth; if (!this.playerEntryList.isEmpty()) { - f6 = 0.0f; - for (PlayerListHud.PlayerEntry playerListHud$PlayerEntry : this.playerEntryList) { - float f20; - f5 = GlHelper.getStringWidth(playerListHud$PlayerEntry.displayName, this.headerFont); - float f21 = f16 + f8 + f5 + f8 + (f20 = (float)playerListHud$PlayerEntry.items.size() * (f17 + f8)) + f7 * 2.0f; - if (!(f21 > f6)) continue; - f6 = f21; + panelWidth = 0.0f; + for (PlayerListHud.PlayerEntry entry : this.playerEntryList) { + float itemsWidth; + entryY = GlHelper.getStringWidth(entry.displayName, this.headerFont); + float rowWidth = headSize + gap + entryY + gap + (itemsWidth = (float)entry.items.size() * (itemSize + gap)) + padding * 2.0f; + if (!(rowWidth > panelWidth)) continue; + panelWidth = rowWidth; } - f19 = Math.max(f15, f6); + targetWidth = Math.max(headerWidth, panelWidth); } if (this.slideAnim.isDone() && this.playerEntryList.isEmpty()) { - this.slideAnim.setCurrentValue(f19); + this.slideAnim.setCurrentValue(targetWidth); } - this.slideAnim.animate(f19, 0.2, Easings.EASE_OUT_SINE); + this.slideAnim.animate(targetWidth, 0.2, Easings.EASE_OUT_SINE); if (this.playerEntryList.isEmpty()) { this.fadeAnim.animate(0.0, 0.2, Easings.EASE_IN_POW3); } else { this.fadeAnim.animate(1.0, 0.2, Easings.EASE_OUT_POW3); } - f6 = this.slideAnim.getValueF(); - float f22 = f; + panelWidth = this.slideAnim.getValueF(); + float drawX = x; if (this.wasRightAligned) { - f22 = f + this.getWidth() - f6; + drawX = x + this.getWidth() - panelWidth; } - float f23 = f22; - f5 = f2 + f14 + f8; - for (PlayerListHud.PlayerEntry playerListHud$PlayerEntry : this.playerEntryList) { - if (playerListHud$PlayerEntry.visible) { - playerListHud$PlayerEntry.visible = false; - playerListHud$PlayerEntry.fadeAnim.setCurrentValue(f5); - playerListHud$PlayerEntry.slideAnim.setCurrentValue(playerListHud$PlayerEntry.rightAligned ? 20.0 : -20.0); - playerListHud$PlayerEntry.heightAnim.setCurrentValue(0.0); - playerListHud$PlayerEntry.alphaAnim.setCurrentValue(0.0); - playerListHud$PlayerEntry.slideAnim.animate(0.0, 0.2, Easings.EASE_OUT_POW3); - playerListHud$PlayerEntry.heightAnim.animate(1.0, 0.2, Easings.EASE_OUT_POW3); - playerListHud$PlayerEntry.alphaAnim.animate(f18 + f8, 0.2, Easings.EASE_OUT_POW3); + float finalX = drawX; + entryY = y + headerHeight + gap; + for (PlayerListHud.PlayerEntry entry : this.playerEntryList) { + if (entry.visible) { + entry.visible = false; + entry.fadeAnim.setCurrentValue(entryY); + entry.slideAnim.setCurrentValue(entry.rightAligned ? 20.0 : -20.0); + entry.heightAnim.setCurrentValue(0.0); + entry.alphaAnim.setCurrentValue(0.0); + entry.slideAnim.animate(0.0, 0.2, Easings.EASE_OUT_POW3); + entry.heightAnim.animate(1.0, 0.2, Easings.EASE_OUT_POW3); + entry.alphaAnim.animate(entryHeight + gap, 0.2, Easings.EASE_OUT_POW3); } - playerListHud$PlayerEntry.fadeAnim.animate(f5, 0.15, Easings.EASE_OUT_SINE); - f5 += playerListHud$PlayerEntry.alphaAnim.getValueF(); + entry.fadeAnim.animate(entryY, 0.15, Easings.EASE_OUT_SINE); + entryY += entry.alphaAnim.getValueF(); } - GuiGraphics iterator = new GuiGraphics(mc, mc.renderBuffers().bufferSource()); - float f24 = this.fadeAnim.getValueF(); + GuiGraphics guiGraphics = new GuiGraphics(mc, mc.renderBuffers().bufferSource()); + float globalAlpha = this.fadeAnim.getValueF(); if (!this.rightAlignAnim.isDone()) { - float f25 = 1.0f - this.rightAlignAnim.getValueF(); - f4 = this.rightAlignAnim.getValueF(); - this.renderLegacy(iterator.pose(), f23, f2, f6, this.rightAlign, f24 * f25, f18, f9, f10, f11, f7); - this.renderLegacy(iterator.pose(), f23, f2, f6, this.wasRightAligned, f24 * f4, f18, f9, f10, f11, f7); + float prevSideFade = 1.0f - this.rightAlignAnim.getValueF(); + leftFade = this.rightAlignAnim.getValueF(); + this.renderLegacy(guiGraphics.pose(), finalX, y, panelWidth, this.rightAlign, globalAlpha * prevSideFade, entryHeight, spacing, cornerRadius, blurStrength, padding); + this.renderLegacy(guiGraphics.pose(), finalX, y, panelWidth, this.wasRightAligned, globalAlpha * leftFade, entryHeight, spacing, cornerRadius, blurStrength, padding); } else { - this.renderLegacy(iterator.pose(), f23, f2, f6, this.wasRightAligned, f24, f18, f9, f10, f11, f7); + this.renderLegacy(guiGraphics.pose(), finalX, y, panelWidth, this.wasRightAligned, globalAlpha, entryHeight, spacing, cornerRadius, blurStrength, padding); } DrawContext drawContext = glRenderEvent.drawContext(); if (!this.rightAlignAnim.isDone()) { - f4 = 1.0f - this.rightAlignAnim.getValueF(); - f3 = this.rightAlignAnim.getValueF(); - this.renderEntry(drawContext, f23, f2, f6, this.rightAlign, f24 * f4, string, string2, f12, f13, f14, f7, f8, f9, f16); - this.renderEntry(drawContext, f23, f2, f6, this.wasRightAligned, f24 * f3, string, string2, f12, f13, f14, f7, f8, f9, f16); + leftFade = 1.0f - this.rightAlignAnim.getValueF(); + rightFade = this.rightAlignAnim.getValueF(); + this.renderEntry(drawContext, finalX, y, panelWidth, this.rightAlign, globalAlpha * leftFade, iconText, titleText, iconWidth, titleWidth, headerHeight, padding, gap, spacing, headSize); + this.renderEntry(drawContext, finalX, y, panelWidth, this.wasRightAligned, globalAlpha * rightFade, iconText, titleText, iconWidth, titleWidth, headerHeight, padding, gap, spacing, headSize); } else { - this.renderEntry(drawContext, f23, f2, f6, this.wasRightAligned, f24, string, string2, f12, f13, f14, f7, f8, f9, f16); + this.renderEntry(drawContext, finalX, y, panelWidth, this.wasRightAligned, globalAlpha, iconText, titleText, iconWidth, titleWidth, headerHeight, padding, gap, spacing, headSize); } if (!this.rightAlignAnim.isDone()) { - f4 = 1.0f - this.rightAlignAnim.getValueF(); - f3 = this.rightAlignAnim.getValueF(); - this.renderEntryGui(iterator, f23, f2, f6, this.rightAlign, f24 * f4, f16, f17, f7, f8); - this.renderEntryGui(iterator, f23, f2, f6, this.wasRightAligned, f24 * f3, f16, f17, f7, f8); + leftFade = 1.0f - this.rightAlignAnim.getValueF(); + rightFade = this.rightAlignAnim.getValueF(); + this.renderEntryGui(guiGraphics, finalX, y, panelWidth, this.rightAlign, globalAlpha * leftFade, headSize, itemSize, padding, gap); + this.renderEntryGui(guiGraphics, finalX, y, panelWidth, this.wasRightAligned, globalAlpha * rightFade, headSize, itemSize, padding, gap); } else { - this.renderEntryGui(iterator, f23, f2, f6, this.wasRightAligned, f24, f16, f17, f7, f8); + this.renderEntryGui(guiGraphics, finalX, y, panelWidth, this.wasRightAligned, globalAlpha, headSize, itemSize, padding, gap); } - iterator.flush(); + guiGraphics.flush(); if (this.wasRightAligned) { - this.setX(f22); + this.setX(drawX); } - this.setWidth(f6); - this.setHeight(f5 - f2); + this.setWidth(panelWidth); + this.setHeight(entryY - y); } - private void renderLegacy(PoseStack poseStack, float f, float f2, float f3, boolean bl, float f4, float f5, float f6, float f7, float f8, float f9) { - if (f4 <= 0.01f) { + private void renderLegacy(PoseStack poseStack, float x, float y, float width, boolean rightAligned, float alpha, float entryHeight, float spacing, float cornerRadius, float blurStrength, float padding) { + if (alpha <= 0.01f) { return; } - for (PlayerListHud.PlayerEntry playerListHud$PlayerEntry : this.playerEntryList) { - float f10 = playerListHud$PlayerEntry.heightAnim.getValueF(); - if (f10 <= 0.0f) continue; - float f11 = bl ? f + f3 - playerListHud$PlayerEntry.widthAnim.getValueF() : f; - float f12 = f11 + playerListHud$PlayerEntry.slideAnim.getValueF(); - float f13 = playerListHud$PlayerEntry.fadeAnim.getValueF(); - float f14 = f8 * f4 * f10; - float f15 = playerListHud$PlayerEntry.widthAnim.getValueF(); - float f16 = f12; - RenderUtil.drawBlurredRect(poseStack, f16, f13, f15, f5, f6, f7, f14, 0); + for (PlayerListHud.PlayerEntry entry : this.playerEntryList) { + float heightFactor = entry.heightAnim.getValueF(); + if (heightFactor <= 0.0f) continue; + float baseX = rightAligned ? x + width - entry.widthAnim.getValueF() : x; + float entryX = baseX + entry.slideAnim.getValueF(); + float entryY = entry.fadeAnim.getValueF(); + float entryAlpha = blurStrength * alpha * heightFactor; + float entryWidth = entry.widthAnim.getValueF(); + float drawX = entryX; + RenderUtil.drawBlurredRect(poseStack, drawX, entryY, entryWidth, entryHeight, spacing, cornerRadius, entryAlpha, 0); } } - private void renderEntry(DrawContext drawContext, float f, float f2, float f3, boolean bl, float f4, String string, String string2, float f5, float f6, float f7, float f8, float f9, float f10, float f11) { - if (f4 <= 0.01f) { + private void renderEntry(DrawContext drawContext, float x, float y, float width, boolean rightAligned, float alpha, String iconText, String titleText, float iconWidth, float titleWidth, float headerHeight, float padding, float gap, float spacing, float headSize) { + if (alpha <= 0.01f) { return; } - float f12 = f2 + f8 + (f7 - f8 * 2.0f - (float)GlHelper.getFontAscent(this.nameFont)) / 2.0f + 1.0f; - int n = ColorUtil.fromARGB(255, 255, 255, (int)(255.0f * f4)); - Paint paint = GlHelper.toPaint(n); - try (Paint paint2 = new Paint()){ - paint2.setColor(ColorUtil.fromARGB(0, 0, 0, (int)(190.0f * f4))); - GlHelper.drawRoundedRect(f, f2, f3, f7, f10, paint2); + float headerTextY = y + padding + (headerHeight - padding * 2.0f - (float)GlHelper.getFontAscent(this.nameFont)) / 2.0f + 1.0f; + int textColor = ColorUtil.fromARGB(255, 255, 255, (int)(255.0f * alpha)); + Paint textPaint = GlHelper.toPaint(textColor); + try (Paint bgPaint = new Paint()){ + bgPaint.setColor(ColorUtil.fromARGB(0, 0, 0, (int)(190.0f * alpha))); + GlHelper.drawRoundedRect(x, y, width, headerHeight, spacing, bgPaint); } - if (bl) { - float f13 = f + f3 - f8 - f5; - float f14 = f13 - f9 - f6; - GlHelper.drawTextWithShadow(string2, f14, f12, this.nameFont, paint); - GlHelper.drawTextWithShadow(string, f13, f12 + 1.0f, this.subFont, paint); + if (rightAligned) { + float iconX = x + width - padding - iconWidth; + float titleX = iconX - gap - titleWidth; + GlHelper.drawTextWithShadow(titleText, titleX, headerTextY, this.nameFont, textPaint); + GlHelper.drawTextWithShadow(iconText, iconX, headerTextY + 1.0f, this.subFont, textPaint); } else { - GlHelper.drawTextWithShadow(string, f + f8, f12 + 1.0f, this.subFont, paint); - GlHelper.drawTextWithShadow(string2, f + f8 + f5 + f9, f12, this.nameFont, paint); + GlHelper.drawTextWithShadow(iconText, x + padding, headerTextY + 1.0f, this.subFont, textPaint); + GlHelper.drawTextWithShadow(titleText, x + padding + iconWidth + gap, headerTextY, this.nameFont, textPaint); } - for (PlayerListHud.PlayerEntry playerListHud$PlayerEntry : this.playerEntryList) { - float f15; - float f16; - float f17 = playerListHud$PlayerEntry.heightAnim.getValueF(); - if (f17 <= 0.0f || (f16 = f4 * f17) <= 0.0f) continue; - float f18 = bl ? f + f3 - playerListHud$PlayerEntry.widthAnim.getValueF() : f; - float f19 = f18 + playerListHud$PlayerEntry.slideAnim.getValueF(); - float f20 = playerListHud$PlayerEntry.fadeAnim.getValueF(); - float f21 = f11 + f8 * 2.0f; - try (Paint paint3 = new Paint()){ - paint3.setColor(ColorUtil.fromARGB(0, 0, 0, (int)(90.0f * f16))); - float f22 = playerListHud$PlayerEntry.widthAnim.getValueF(); - float f23 = f19; - GlHelper.drawRoundedRect(f23, f20, f22, f21, f10, paint3); + for (PlayerListHud.PlayerEntry entry : this.playerEntryList) { + float headX; + float entryAlpha; + float heightFactor = entry.heightAnim.getValueF(); + if (heightFactor <= 0.0f || (entryAlpha = alpha * heightFactor) <= 0.0f) continue; + float baseX = rightAligned ? x + width - entry.widthAnim.getValueF() : x; + float entryX = baseX + entry.slideAnim.getValueF(); + float entryY = entry.fadeAnim.getValueF(); + float entryHeight = headSize + padding * 2.0f; + try (Paint entryBgPaint = new Paint()){ + entryBgPaint.setColor(ColorUtil.fromARGB(0, 0, 0, (int)(90.0f * entryAlpha))); + float entryWidth = entry.widthAnim.getValueF(); + float entryDrawX = entryX; + GlHelper.drawRoundedRect(entryDrawX, entryY, entryWidth, entryHeight, spacing, entryBgPaint); } - float f24 = f20 + f8; - int n2 = playerListHud$PlayerEntry.player == mc.player ? ColorUtil.fromRGB(100, 150, 255) : -1; - int n3 = ColorUtil.withAlpha(n2, (int)f16); - float f25 = f20 + f8 + (f21 - f8 * 2.0f - (float)GlHelper.getFontAscent(this.headerFont)) / 2.0f; - if (bl) { - f15 = f19 + playerListHud$PlayerEntry.widthAnim.getValueF(); - float f26 = f15 - f8 - f11; - if (playerListHud$PlayerEntry.player instanceof AbstractClientPlayer) { - GlHelper.drawPlayerHeadRounded((AbstractClientPlayer)playerListHud$PlayerEntry.player, f26, f24, f11, f11, f16, f10); + float contentY = entryY + padding; + int nameColor = entry.player == mc.player ? ColorUtil.fromRGB(100, 150, 255) : -1; + int nameAlpha = ColorUtil.withAlpha(nameColor, (int)entryAlpha); + float nameY = entryY + padding + (entryHeight - padding * 2.0f - (float)GlHelper.getFontAscent(this.headerFont)) / 2.0f; + if (rightAligned) { + headX = entryX + entry.widthAnim.getValueF(); + float headDrawX = headX - padding - headSize; + if (entry.player instanceof AbstractClientPlayer) { + GlHelper.drawPlayerHeadRounded((AbstractClientPlayer)entry.player, headDrawX, contentY, headSize, headSize, entryAlpha, spacing); } - float f27 = f26 - f9 - playerListHud$PlayerEntry.nameWidth; - GlHelper.drawTextShadowLegacy(playerListHud$PlayerEntry.displayName, f27, f25, this.headerFont, n3); + float nameX = headDrawX - spacing - entry.nameWidth; + GlHelper.drawTextShadowLegacy(entry.displayName, nameX, nameY, this.headerFont, nameAlpha); continue; } - if (playerListHud$PlayerEntry.player instanceof AbstractClientPlayer) { - f15 = f19 + f8; - GlHelper.drawPlayerHeadRounded((AbstractClientPlayer)playerListHud$PlayerEntry.player, f15, f24, f11, f11, f16, f10); + if (entry.player instanceof AbstractClientPlayer) { + headX = entryX + padding; + GlHelper.drawPlayerHeadRounded((AbstractClientPlayer)entry.player, headX, contentY, headSize, headSize, entryAlpha, spacing); } - f15 = f19 + f8 + f11 + f9; - GlHelper.drawTextShadowLegacy(playerListHud$PlayerEntry.displayName, f15, f25, this.headerFont, n3); + headX = entryX + padding + headSize + spacing; + GlHelper.drawTextShadowLegacy(entry.displayName, headX, nameY, this.headerFont, nameAlpha); } } - private void renderEntryGui(GuiGraphics guiGraphics, float f, float f2, float f3, boolean bl, float f4, float f5, float f6, float f7, float f8) { - if (f4 <= 0.01f) { + private void renderEntryGui(GuiGraphics guiGraphics, float x, float y, float width, boolean rightAligned, float alpha, float headSize, float itemSize, float padding, float gap) { + if (alpha <= 0.01f) { return; } - for (PlayerListHud.PlayerEntry playerListHud$PlayerEntry : this.playerEntryList) { - float f9; - float f10 = playerListHud$PlayerEntry.heightAnim.getValueF(); - if (f10 <= 0.0f || (f9 = f4 * f10) <= 0.01f) continue; - float f11 = bl ? f + f3 - playerListHud$PlayerEntry.widthAnim.getValueF() : f; - float f12 = f11 + playerListHud$PlayerEntry.slideAnim.getValueF(); - float f13 = playerListHud$PlayerEntry.fadeAnim.getValueF(); - float f14 = f13 + f7 + (f5 - f6) / 2.0f; + for (PlayerListHud.PlayerEntry entry : this.playerEntryList) { + float entryAlpha; + float heightFactor = entry.heightAnim.getValueF(); + if (heightFactor <= 0.0f || (entryAlpha = alpha * heightFactor) <= 0.01f) continue; + float baseX = rightAligned ? x + width - entry.widthAnim.getValueF() : x; + float entryX = baseX + entry.slideAnim.getValueF(); + float entryY = entry.fadeAnim.getValueF(); + float itemY = entryY + padding + (headSize - itemSize) / 2.0f; RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, f9); + RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, entryAlpha); float rightEdge; - if (bl) { - rightEdge = f12 + playerListHud$PlayerEntry.widthAnim.getValueF(); - float f15 = rightEdge - f7 - f5; - float f16 = f15 - f8 - playerListHud$PlayerEntry.nameWidth; - float f17 = (float)playerListHud$PlayerEntry.items.size() * (f6 + f8); - float f18 = f16 - f8 - f17; - for (ItemStack itemStack : playerListHud$PlayerEntry.items) { + if (rightAligned) { + rightEdge = entryX + entry.widthAnim.getValueF(); + float headRight = rightEdge - padding - headSize; + float nameRight = headRight - gap - entry.nameWidth; + float itemsTotal = (float)entry.items.size() * (itemSize + gap); + float itemX = nameRight - gap - itemsTotal; + for (ItemStack itemStack : entry.items) { PoseStack poseStack = guiGraphics.pose(); poseStack.pushPose(); - poseStack.translate(f18, f14, 0.0f); + poseStack.translate(itemX, itemY, 0.0f); guiGraphics.renderItem(itemStack, 0, 0); poseStack.popPose(); - f18 += f6 + f8; + itemX += itemSize + gap; } } else { - rightEdge = f12 + f7 + f5 + f8 + playerListHud$PlayerEntry.nameWidth + f8; - for (ItemStack itemStack : playerListHud$PlayerEntry.items) { + rightEdge = entryX + padding + headSize + gap + entry.nameWidth + gap; + for (ItemStack itemStack : entry.items) { PoseStack poseStack = guiGraphics.pose(); poseStack.pushPose(); - poseStack.translate(rightEdge, f14, 0.0f); + poseStack.translate(rightEdge, itemY, 0.0f); guiGraphics.renderItem(itemStack, 0, 0); poseStack.popPose(); - rightEdge += f6 + f8; + rightEdge += itemSize + gap; } } RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); @@ -474,4 +474,4 @@ extends HudElement { @Override public void onSettings() { } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/hud/PotionEffectsHud.java b/src/main/java/shit/zen/hud/PotionEffectsHud.java index cf08f2a..923bc5d 100644 --- a/src/main/java/shit/zen/hud/PotionEffectsHud.java +++ b/src/main/java/shit/zen/hud/PotionEffectsHud.java @@ -126,26 +126,26 @@ extends HudElement { Collection collection = mc.player.getActiveEffects(); this.effectEntryList.stream().filter(e -> collection.stream().noneMatch(eff -> eff.getEffect() == e.getEffect())).forEach(PotionEffectsHud.EffectEntry::startRemove); for (MobEffectInstance mobEffectInstance : collection) { - Optional optional = this.effectEntryList.stream().filter(e -> !e.removing && e.getEffect() == mobEffectInstance.getEffect()).findFirst(); - if (optional.isEmpty()) { - PotionEffectsHud.EffectEntry potionEffectsHud$EffectEntry3 = new PotionEffectsHud.EffectEntry(this, mobEffectInstance); - this.effectEntryList.add(potionEffectsHud$EffectEntry3); + Optional existing = this.effectEntryList.stream().filter(e -> !e.removing && e.getEffect() == mobEffectInstance.getEffect()).findFirst(); + if (existing.isEmpty()) { + PotionEffectsHud.EffectEntry newEntry = new PotionEffectsHud.EffectEntry(this, mobEffectInstance); + this.effectEntryList.add(newEntry); continue; } - optional.get().updateEffect(mobEffectInstance); + existing.get().updateEffect(mobEffectInstance); } - this.effectEntryList.sort((potionEffectsHud$EffectEntry, potionEffectsHud$EffectEntry2) -> Float.compare(potionEffectsHud$EffectEntry2.getTotalWidth(), potionEffectsHud$EffectEntry.getTotalWidth())); + this.effectEntryList.sort((a, b) -> Float.compare(b.getTotalWidth(), a.getTotalWidth())); } @Override - public void onGlRender(GlRenderEvent glRenderEvent, float f, float f2) { + public void onGlRender(GlRenderEvent glRenderEvent, float x, float y) { if (!this.isEnabled()) { return; } - this.renderEffects(glRenderEvent.drawContext(), f, f2); + this.renderEffects(glRenderEvent.drawContext(), x, y); } - private void renderEffects(DrawContext drawContext, float f, float f2) { + private void renderEffects(DrawContext drawContext, float x, float y) { if (drawContext == null) { return; } @@ -155,76 +155,76 @@ extends HudElement { this.setHeight(0.0f); return; } - float f3 = 2.0f; - float f4 = 18.0f; - float f5 = 4.5f; - float f6 = 100.0f; - float f7 = f2; - float f8 = 0.0f; - for (PotionEffectsHud.EffectEntry potionEffectsHud$EffectEntry : this.effectEntryList) { - potionEffectsHud$EffectEntry.tick(); - float f9 = 20.0f; - float f10 = 5.0f; - float f11 = GlHelper.getStringWidth(potionEffectsHud$EffectEntry.effectName, this.effectNameFont); - float f12 = GlHelper.getStringWidth(potionEffectsHud$EffectEntry.durationText, this.amplifierFont); - float f13 = Math.max(f6, f9 + f11 + f12 + f10 * 3.0f); - if (potionEffectsHud$EffectEntry.visible) { - potionEffectsHud$EffectEntry.visible = false; - potionEffectsHud$EffectEntry.fadeAnim.setCurrentValue(f7); - potionEffectsHud$EffectEntry.show(f4); + float spacing = 2.0f; + float entryHeight = 18.0f; + float cornerRadius = 4.5f; + float minWidth = 100.0f; + float currentY = y; + float maxWidth = 0.0f; + for (PotionEffectsHud.EffectEntry entry : this.effectEntryList) { + entry.tick(); + float iconBoxWidth = 20.0f; + float padding = 5.0f; + float nameWidth = GlHelper.getStringWidth(entry.effectName, this.effectNameFont); + float durationWidth = GlHelper.getStringWidth(entry.durationText, this.amplifierFont); + float totalWidth = Math.max(minWidth, iconBoxWidth + nameWidth + durationWidth + padding * 3.0f); + if (entry.visible) { + entry.visible = false; + entry.fadeAnim.setCurrentValue(currentY); + entry.show(entryHeight); } - potionEffectsHud$EffectEntry.fadeAnim.animate(f7, 0.15, Easings.EASE_OUT_SINE); - float f14 = potionEffectsHud$EffectEntry.heightAnim.getValueF(); - float f15 = potionEffectsHud$EffectEntry.fadeAnim.getValueF(); - float f16 = potionEffectsHud$EffectEntry.widthAnim.getValueF(); - if (f13 > f8) { - f8 = f13; + entry.fadeAnim.animate(currentY, 0.15, Easings.EASE_OUT_SINE); + float animHeight = entry.heightAnim.getValueF(); + float entryY = entry.fadeAnim.getValueF(); + float animWidth = entry.widthAnim.getValueF(); + if (totalWidth > maxWidth) { + maxWidth = totalWidth; } - if (f14 <= 0.01f) { - f7 += f16 + (f16 > 0.0f ? f3 : 0.0f); + if (animHeight <= 0.01f) { + currentY += animWidth + (animWidth > 0.0f ? spacing : 0.0f); continue; } - int n = this.getEffectColor(potionEffectsHud$EffectEntry.instance.getEffect()); - float f17 = f13 - f9; - float f18 = f + f9; - this.iconBgPaint.setColor(ColorUtil.fromARGB(30, 30, 35, (int)(80.0f * f14))); - drawContext.drawRoundedRect(RoundedRectangle.ofXYWHRadii(f18, f15, f17, f16, new float[]{0.0f, 0.0f, 4.5f, 4.5f, 4.5f, 4.5f, 0.0f, 0.0f}), this.iconBgPaint); - float f19 = potionEffectsHud$EffectEntry.instance.isInfiniteDuration() ? 1.0f : (float)potionEffectsHud$EffectEntry.instance.getDuration() / (float)potionEffectsHud$EffectEntry.originalDuration; - this.effectIconPaint.setColor(ColorUtil.fromARGB(n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF, (int)(140.0f * f14))); - if (f19 > 0.0f) { - drawContext.drawRoundedRect(RoundedRectangle.ofXYWHRadii(f18, f15, f17 * f19, f16, new float[]{0.0f, 0.0f, f5 * f19, f5 * f19, f5 * f19, f5 * f19, 0.0f, 0.0f}), this.effectIconPaint); + int effectColor = this.getEffectColor(entry.instance.getEffect()); + float barWidth = totalWidth - iconBoxWidth; + float barX = x + iconBoxWidth; + this.iconBgPaint.setColor(ColorUtil.fromARGB(30, 30, 35, (int)(80.0f * animHeight))); + drawContext.drawRoundedRect(RoundedRectangle.ofXYWHRadii(barX, entryY, barWidth, animWidth, new float[]{0.0f, 0.0f, 4.5f, 4.5f, 4.5f, 4.5f, 0.0f, 0.0f}), this.iconBgPaint); + float durationPct = entry.instance.isInfiniteDuration() ? 1.0f : (float)entry.instance.getDuration() / (float)entry.originalDuration; + this.effectIconPaint.setColor(ColorUtil.fromARGB(effectColor >> 16 & 0xFF, effectColor >> 8 & 0xFF, effectColor & 0xFF, (int)(140.0f * animHeight))); + if (durationPct > 0.0f) { + drawContext.drawRoundedRect(RoundedRectangle.ofXYWHRadii(barX, entryY, barWidth * durationPct, animWidth, new float[]{0.0f, 0.0f, cornerRadius * durationPct, cornerRadius * durationPct, cornerRadius * durationPct, cornerRadius * durationPct, 0.0f, 0.0f}), this.effectIconPaint); } - int n2 = n >> 16 & 0xFF; - int n3 = n >> 8 & 0xFF; - int n4 = n & 0xFF; - this.backgroundPaint.setColor(ColorUtil.fromARGB((int)((float)n2 * 0.7f + 76.5f), (int)((float)n3 * 0.7f + 76.5f), (int)((float)n4 * 0.7f + 76.5f), (int)(160.0f * f14))); - drawContext.drawRoundedRect(RoundedRectangle.ofXYWHRadii(f, f15, f9, f16, new float[]{4.5f, 4.5f, 0.0f, 0.0f, 0.0f, 0.0f, 4.5f, 4.5f}), this.backgroundPaint); - this.timerBarPaint.setColor(ColorUtil.fromARGB(255, 255, 255, (int)(185.0f * f14))); - float f20 = f15 + (f16 - (float)GlHelper.getFontAscent(this.effectNameFont)) / 2.0f; - float f21 = GlHelper.getStringWidth(potionEffectsHud$EffectEntry.amplifierText, this.timerFont); - GlHelper.drawTextFormatted(potionEffectsHud$EffectEntry.amplifierText, f + (f9 - f21) / 2.0f, f20, this.timerFont, this.timerBarPaint, false); - GlHelper.drawTextFormatted(potionEffectsHud$EffectEntry.effectName, f18 + f10, f20, this.effectNameFont, this.timerBarPaint, false); - f12 = GlHelper.getStringWidth(potionEffectsHud$EffectEntry.durationText, this.amplifierFont); - GlHelper.drawTextFormatted(potionEffectsHud$EffectEntry.durationText, f + f13 - f12 - f10, f20 + 1.0f, this.amplifierFont, this.timerBarPaint, false); - f7 += f16 + (f16 > 0.0f ? f3 : 0.0f); + int r = effectColor >> 16 & 0xFF; + int g = effectColor >> 8 & 0xFF; + int b = effectColor & 0xFF; + this.backgroundPaint.setColor(ColorUtil.fromARGB((int)((float)r * 0.7f + 76.5f), (int)((float)g * 0.7f + 76.5f), (int)((float)b * 0.7f + 76.5f), (int)(160.0f * animHeight))); + drawContext.drawRoundedRect(RoundedRectangle.ofXYWHRadii(x, entryY, iconBoxWidth, animWidth, new float[]{4.5f, 4.5f, 0.0f, 0.0f, 0.0f, 0.0f, 4.5f, 4.5f}), this.backgroundPaint); + this.timerBarPaint.setColor(ColorUtil.fromARGB(255, 255, 255, (int)(185.0f * animHeight))); + float textY = entryY + (animWidth - (float)GlHelper.getFontAscent(this.effectNameFont)) / 2.0f; + float ampWidth = GlHelper.getStringWidth(entry.amplifierText, this.timerFont); + GlHelper.drawTextFormatted(entry.amplifierText, x + (iconBoxWidth - ampWidth) / 2.0f, textY, this.timerFont, this.timerBarPaint, false); + GlHelper.drawTextFormatted(entry.effectName, barX + padding, textY, this.effectNameFont, this.timerBarPaint, false); + durationWidth = GlHelper.getStringWidth(entry.durationText, this.amplifierFont); + GlHelper.drawTextFormatted(entry.durationText, x + totalWidth - durationWidth - padding, textY + 1.0f, this.amplifierFont, this.timerBarPaint, false); + currentY += animWidth + (animWidth > 0.0f ? spacing : 0.0f); } - this.setWidth(f8); - this.setHeight(Math.max(0.0f, f7 - f2 - f3)); + this.setWidth(maxWidth); + this.setHeight(Math.max(0.0f, currentY - y - spacing)); } private int getEffectColor(MobEffect mobEffect) { - int n = mobEffect.getColor(); - return n != 0 ? n : 3376639; + int color = mobEffect.getColor(); + return color != 0 ? color : 3376639; } - String formatAmplifier(int n) { - return switch (n) { + String formatAmplifier(int amplifier) { + return switch (amplifier) { case 1 -> "I"; case 2 -> "II"; case 3 -> "III"; case 4 -> "IV"; case 5 -> "V"; - default -> String.valueOf(n); + default -> String.valueOf(amplifier); }; } @@ -236,7 +236,7 @@ extends HudElement { } @Override - public void onRender2D(Render2DEvent render2DEvent, float f, float f2) { + public void onRender2D(Render2DEvent render2DEvent, float x, float y) { } @Override diff --git a/src/main/java/shit/zen/hud/ScaffoldHud.java b/src/main/java/shit/zen/hud/ScaffoldHud.java index 94f1296..dcd23ad 100644 --- a/src/main/java/shit/zen/hud/ScaffoldHud.java +++ b/src/main/java/shit/zen/hud/ScaffoldHud.java @@ -34,62 +34,62 @@ implements IHudElement { } @Override - public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float f, float f2, float f3, float f4, float f5) { - if (mc == null || mc.player == null || f5 <= 0.01f) { + public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float x, float y, float width, float height, float alpha) { + if (mc == null || mc.player == null || alpha <= 0.01f) { return; } - ItemStack itemStack = this.getBlockItem(); - if (itemStack.isEmpty()) { + ItemStack blockItem = this.getBlockItem(); + if (blockItem.isEmpty()) { return; } - float f6 = f4 - 16.0f; - float f7 = f + 8.0f; - float f8 = f2 + 8.0f; - if (f5 > 0.1f && f6 - 4.0f > 0.0f) { - guiGraphics.renderItem(itemStack, (int)f7 + 2, (int)f8 + 2, 0, (int)f6 - 4); + float iconSize = height - 16.0f; + float iconX = x + 8.0f; + float iconY = y + 8.0f; + if (alpha > 0.1f && iconSize - 4.0f > 0.0f) { + guiGraphics.renderItem(blockItem, (int)iconX + 2, (int)iconY + 2, 0, (int)iconSize - 4); } } @Override - public void render(DrawContext drawContext, float f, float f2, float f3, float f4, float f5) { - if (mc == null || mc.player == null || f5 <= 0.01f) { + public void render(DrawContext drawContext, float x, float y, float width, float height, float alpha) { + if (mc == null || mc.player == null || alpha <= 0.01f) { return; } - ItemStack itemStack = this.getBlockItem(); - if (itemStack.isEmpty()) { + ItemStack blockItem = this.getBlockItem(); + if (blockItem.isEmpty()) { return; } - float f6 = f4 - 16.0f; - int n = itemStack.getCount(); - String string = n + " blocks"; - double d = MovementUtil.getSpeedBps(); - String string2 = String.format("%.2fb/s", new Object[]{d}); - float f7 = blockCountFont.getWidth(string); - float f8 = speedFont.getWidth(string2); - float f9 = Math.max(f7, f8); - float f10 = f3 - f6 - f9 - 32.0f; - float f11 = 6.0f; - float f12 = f + 8.0f + f6 + 8.0f; - float f13 = f2 + f4 / 2.0f - f11 / 2.0f; - float f14 = Math.min(1.0f, (float)n / 64.0f); - this.setX(f14); + float iconSize = height - 16.0f; + int blockCount = blockItem.getCount(); + String countText = blockCount + " blocks"; + double speedBps = MovementUtil.getSpeedBps(); + String speedText = String.format("%.2fb/s", new Object[]{speedBps}); + float countWidth = blockCountFont.getWidth(countText); + float speedWidth = speedFont.getWidth(speedText); + float maxTextWidth = Math.max(countWidth, speedWidth); + float barWidth = width - iconSize - maxTextWidth - 32.0f; + float barHeight = 6.0f; + float barX = x + 8.0f + iconSize + 8.0f; + float barY = y + height / 2.0f - barHeight / 2.0f; + float progressPct = Math.min(1.0f, (float)blockCount / 64.0f); + this.setX(progressPct); try (Paint paint = new Paint()){ - paint.setColor(this.colorWithAlpha(new Color(30, 30, 30).getRGB(), f5)); - drawContext.drawRoundedRect(RoundedRectangle.ofXYWHR(f12, f13, f10, f11, f11 / 2.0f), paint); + paint.setColor(this.colorWithAlpha(new Color(30, 30, 30).getRGB(), alpha)); + drawContext.drawRoundedRect(RoundedRectangle.ofXYWHR(barX, barY, barWidth, barHeight, barHeight / 2.0f), paint); if (this.progressAnim.getValue() > 0.0f) { - paint.setColor(this.colorWithAlpha(new Color(153, 0, 255).getRGB(), f5)); - drawContext.drawRoundedRect(RoundedRectangle.ofXYWHR(f12, f13, f10 * this.progressAnim.getValue(), f11, f11 / 2.0f), paint); + paint.setColor(this.colorWithAlpha(new Color(153, 0, 255).getRGB(), alpha)); + drawContext.drawRoundedRect(RoundedRectangle.ofXYWHR(barX, barY, barWidth * this.progressAnim.getValue(), barHeight, barHeight / 2.0f), paint); } } - float f15 = f12 + f10 + 8.0f; - float f16 = f2 + f4 / 2.0f; - float f17 = f15 + (f9 - f7) / 2.0f; - float f18 = f15 + (f9 - f8) / 2.0f; + float textX = barX + barWidth + 8.0f; + float centerY = y + height / 2.0f; + float countX = textX + (maxTextWidth - countWidth) / 2.0f; + float speedX = textX + (maxTextWidth - speedWidth) / 2.0f; try (Paint paint = new Paint()){ - paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), f5)); - drawContext.drawString(string, f17, f16 - blockCountFont.getMetrics().capHeight() / 2.0f + 2.0f, blockCountFont, paint); - paint.setColor(this.colorWithAlpha(Color.GRAY.getRGB(), f5)); - drawContext.drawString(string2, f18, f16 + speedFont.getMetrics().capHeight() / 2.0f + 8.0f, speedFont, paint); + paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), alpha)); + drawContext.drawString(countText, countX, centerY - blockCountFont.getMetrics().capHeight() / 2.0f + 2.0f, blockCountFont, paint); + paint.setColor(this.colorWithAlpha(Color.GRAY.getRGB(), alpha)); + drawContext.drawString(speedText, speedX, centerY + speedFont.getMetrics().capHeight() / 2.0f + 8.0f, speedFont, paint); } } @@ -97,33 +97,33 @@ implements IHudElement { if (mc.player == null) { return ItemStack.EMPTY; } - ItemStack itemStack = mc.player.getMainHandItem(); - if (itemStack.getItem() instanceof BlockItem) { - return itemStack; + ItemStack mainHand = mc.player.getMainHandItem(); + if (mainHand.getItem() instanceof BlockItem) { + return mainHand; } for (int i = 0; i < 9; ++i) { - ItemStack itemStack2 = mc.player.getInventory().getItem(i); - if (!(itemStack2.getItem() instanceof BlockItem)) continue; - return itemStack2; + ItemStack slotItem = mc.player.getInventory().getItem(i); + if (!(slotItem.getItem() instanceof BlockItem)) continue; + return slotItem; } return ItemStack.EMPTY; } - private void setX(float f) { - long l = System.currentTimeMillis(); - if (this.lastUpdateTime == 0L || l - this.lastUpdateTime > 1000L) { - this.lastUpdateTime = l; - this.progressAnim.setValue(f); - this.progressAnim.setTargetValue(f); + private void setX(float progressPct) { + long now = System.currentTimeMillis(); + if (this.lastUpdateTime == 0L || now - this.lastUpdateTime > 1000L) { + this.lastUpdateTime = now; + this.progressAnim.setValue(progressPct); + this.progressAnim.setTargetValue(progressPct); return; } - float f2 = (float)(l - this.lastUpdateTime) / 1000.0f; - if (f2 <= 0.0f) { + float deltaSec = (float)(now - this.lastUpdateTime) / 1000.0f; + if (deltaSec <= 0.0f) { return; } - this.lastUpdateTime = l; - this.progressAnim.setTargetValue(f); - this.progressAnim.update(f2); + this.lastUpdateTime = now; + this.progressAnim.setTargetValue(progressPct); + this.progressAnim.update(deltaSec); } @Override diff --git a/src/main/java/shit/zen/hud/TabListHud.java b/src/main/java/shit/zen/hud/TabListHud.java index 9fa773b..245f842 100644 --- a/src/main/java/shit/zen/hud/TabListHud.java +++ b/src/main/java/shit/zen/hud/TabListHud.java @@ -31,151 +31,151 @@ implements IHudElement { } @Override - public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float f, float f2, float f3, float f4, float f5) { - float f6; - float f7; - if (mc == null || mc.player == null || mc.getConnection() == null || f5 <= 0.01f) { + public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float x, float y, float width, float height, float alpha) { + float rowWidth; + float maxRowWidth; + if (mc == null || mc.player == null || mc.getConnection() == null || alpha <= 0.01f) { return; } - ArrayList arrayList = new ArrayList<>(mc.getConnection().getOnlinePlayers()); - arrayList.sort(Comparator.comparing(p -> p.getProfile().getName())); - Component component = TabListInfo.header; - float f8 = component != null && !component.getString().isEmpty() ? (float)component.getString().split("\n").length * 11.0f : 20.0f; - int n = 20; - int n2 = Math.max(1, (int)Math.ceil((double)arrayList.size() / (double)n)); - float f9 = 0.0f; - if (n2 == 1) { - float f10; - f7 = 0.0f; - if (!arrayList.isEmpty()) { - for (PlayerInfo playerInfo2 : arrayList) { - String string = playerInfo2.getProfile().getName(); - String string2 = playerInfo2.getLatency() + "ms"; - f6 = 12.0f + nameFont.getWidth(string) + 5.0f + nameFont.getWidth(string2); - f7 = Math.max(f7, f6); + ArrayList players = new ArrayList<>(mc.getConnection().getOnlinePlayers()); + players.sort(Comparator.comparing(p -> p.getProfile().getName())); + Component header = TabListInfo.header; + float headerHeight = header != null && !header.getString().isEmpty() ? (float)header.getString().split("\n").length * 11.0f : 20.0f; + int rowsPerColumn = 20; + int columnCount = Math.max(1, (int)Math.ceil((double)players.size() / (double)rowsPerColumn)); + float centerOffset = 0.0f; + if (columnCount == 1) { + float available; + maxRowWidth = 0.0f; + if (!players.isEmpty()) { + for (PlayerInfo player : players) { + String name = player.getProfile().getName(); + String ping = player.getLatency() + "ms"; + rowWidth = 12.0f + nameFont.getWidth(name) + 5.0f + nameFont.getWidth(ping); + maxRowWidth = Math.max(maxRowWidth, rowWidth); } } - if (f7 < (f10 = f3 - 20.0f)) { - f9 = (f10 - f7) / 2.0f; + if (maxRowWidth < (available = width - 20.0f)) { + centerOffset = (available - maxRowWidth) / 2.0f; } } - f7 = f2 + 10.0f + f8 + 10.0f; - for (int i = 0; i < arrayList.size(); ++i) { - int n3 = i / n; - int n4 = i % n; - float f11 = f + 10.0f + (float)n3 * 150.0f; - if (n2 == 1) { - f11 += f9; + maxRowWidth = y + 10.0f + headerHeight + 10.0f; + for (int i = 0; i < players.size(); ++i) { + int column = i / rowsPerColumn; + int row = i % rowsPerColumn; + float entryX = x + 10.0f + (float)column * 150.0f; + if (columnCount == 1) { + entryX += centerOffset; } - f6 = f7 + (float)n4 * 11.0f; - PlayerInfo playerInfo3 = arrayList.get(i); + rowWidth = maxRowWidth + (float)row * 11.0f; + PlayerInfo player = players.get(i); poseStack.pushPose(); - poseStack.translate(f11, f6, 0.0f); - guiGraphics.blit(playerInfo3.getSkinLocation(), 0, 0, 8, 8, 8.0f, 8.0f, 8, 8, 64, 64); - guiGraphics.blit(playerInfo3.getSkinLocation(), 0, 0, 8, 8, 40.0f, 8.0f, 8, 8, 64, 64); + poseStack.translate(entryX, rowWidth, 0.0f); + guiGraphics.blit(player.getSkinLocation(), 0, 0, 8, 8, 8.0f, 8.0f, 8, 8, 64, 64); + guiGraphics.blit(player.getSkinLocation(), 0, 0, 8, 8, 40.0f, 8.0f, 8, 8, 64, 64); poseStack.popPose(); } } @Override - public void render(DrawContext drawContext, float f, float f2, float f3, float f4, float f5) { - if (mc == null || mc.player == null || mc.getConnection() == null || f5 <= 0.01f) { + public void render(DrawContext drawContext, float x, float y, float width, float height, float alpha) { + if (mc == null || mc.player == null || mc.getConnection() == null || alpha <= 0.01f) { return; } - ArrayList arrayList = new ArrayList<>(mc.getConnection().getOnlinePlayers()); - arrayList.sort(Comparator.comparing(p -> p.getProfile().getName())); - Component component = TabListInfo.header; - Component component2 = TabListInfo.footer; + ArrayList players = new ArrayList<>(mc.getConnection().getOnlinePlayers()); + players.sort(Comparator.comparing(p -> p.getProfile().getName())); + Component header = TabListInfo.header; + Component footer = TabListInfo.footer; try (Paint paint = new Paint()){ - int n; - float f6; - float f7; - float f8; - paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), f5)); - if (component != null && !component.getString().isEmpty()) { - f8 = (float)component.getString().split("\n").length * 11.0f; - float f9 = f2 + 10.0f; - for (String string : component.getString().split("\n")) { - f7 = f + f3 / 2.0f; - this.drawFormattedComponent(drawContext, Component.literal(string), f7, f9 + titleFont.getMetrics().ascent() / 2.0f + 9.0f, titleFont, paint, f5); - f9 += 11.0f; + int i; + float rowWidth; + float maxRowWidth; + float headerHeight; + paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), alpha)); + if (header != null && !header.getString().isEmpty()) { + headerHeight = (float)header.getString().split("\n").length * 11.0f; + float lineY = y + 10.0f; + for (String line : header.getString().split("\n")) { + maxRowWidth = x + width / 2.0f; + this.drawFormattedComponent(drawContext, Component.literal(line), maxRowWidth, lineY + titleFont.getMetrics().ascent() / 2.0f + 9.0f, titleFont, paint, alpha); + lineY += 11.0f; } } else { - f8 = 20.0f; - String string = "Player List (" + arrayList.size() + ")"; - float f10 = f + (f3 - headerFont.getWidth(string)) / 2.0f; - GlHelper.drawTextShadowLegacy(string, f10, f2 + 10.0f + headerFont.getMetrics().ascent() + 15.0f, headerFont, -1); + headerHeight = 20.0f; + String title = "Player List (" + players.size() + ")"; + float titleX = x + (width - headerFont.getWidth(title)) / 2.0f; + GlHelper.drawTextShadowLegacy(title, titleX, y + 10.0f + headerFont.getMetrics().ascent() + 15.0f, headerFont, -1); } - if (arrayList.isEmpty() && (component2 == null || component2.getString().isEmpty())) { + if (players.isEmpty() && (footer == null || footer.getString().isEmpty())) { return; } - int n2 = arrayList.size(); - int n3 = 20; - int n4 = Math.max(1, (int)Math.ceil((double)n2 / (double)n3)); - float f11 = f2 + 10.0f + f8 + 10.0f; - float f12 = 0.0f; - f7 = 0.0f; - if (n4 == 1) { - float f13; - if (!arrayList.isEmpty()) { - for (PlayerInfo playerInfo2 : arrayList) { - String string = playerInfo2.getProfile().getName(); - String string2 = playerInfo2.getLatency() + "ms"; - f6 = 12.0f + nameFont.getWidth(string) + 5.0f + nameFont.getWidth(string2); - f7 = Math.max(f7, f6); + int playerCount = players.size(); + int rowsPerColumn = 20; + int columnCount = Math.max(1, (int)Math.ceil((double)playerCount / (double)rowsPerColumn)); + float rowsStartY = y + 10.0f + headerHeight + 10.0f; + float centerOffset = 0.0f; + maxRowWidth = 0.0f; + if (columnCount == 1) { + float available; + if (!players.isEmpty()) { + for (PlayerInfo player : players) { + String name = player.getProfile().getName(); + String ping = player.getLatency() + "ms"; + rowWidth = 12.0f + nameFont.getWidth(name) + 5.0f + nameFont.getWidth(ping); + maxRowWidth = Math.max(maxRowWidth, rowWidth); } } - if (f7 < (f13 = f3 - 20.0f)) { - f12 = (f13 - f7) / 2.0f; + if (maxRowWidth < (available = width - 20.0f)) { + centerOffset = (available - maxRowWidth) / 2.0f; } } - for (n = 0; n < arrayList.size(); ++n) { - int n5 = n / n3; - int n6 = n % n3; - float f14 = f + 10.0f + (float)n5 * 150.0f; - if (n4 == 1) { - f14 += f12; + for (i = 0; i < players.size(); ++i) { + int column = i / rowsPerColumn; + int row = i % rowsPerColumn; + float entryX = x + 10.0f + (float)column * 150.0f; + if (columnCount == 1) { + entryX += centerOffset; } - f6 = f11 + (float)n6 * 11.0f; - PlayerInfo object = arrayList.get(n); - paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), f5)); - String f19 = object.getProfile().getName(); - String string = object.getLatency() + "ms"; - float f9 = nameFont.getWidth(string); - float f10 = n4 > 1 ? 128.0f - f9 - 5.0f : f7 - 8.0f - 4.0f - f9 - 5.0f; - if (nameFont.getWidth(f19) > f10 && f10 > 0.0f) { - while (nameFont.getWidth(f19) > f10 && !f19.isEmpty()) { - f19 = f19.substring(0, f19.length() - 1); + rowWidth = rowsStartY + (float)row * 11.0f; + PlayerInfo player = players.get(i); + paint.setColor(this.colorWithAlpha(Color.WHITE.getRGB(), alpha)); + String displayName = player.getProfile().getName(); + String ping = player.getLatency() + "ms"; + float pingWidth = nameFont.getWidth(ping); + float nameMaxWidth = columnCount > 1 ? 128.0f - pingWidth - 5.0f : maxRowWidth - 8.0f - 4.0f - pingWidth - 5.0f; + if (nameFont.getWidth(displayName) > nameMaxWidth && nameMaxWidth > 0.0f) { + while (nameFont.getWidth(displayName) > nameMaxWidth && !displayName.isEmpty()) { + displayName = displayName.substring(0, displayName.length() - 1); } } - drawContext.drawString(f19, f14 + 8.0f + 4.0f + 0.5f, f6 + nameFont.getMetrics().ascent() / 2.0f + 11.0f + 0.5f, nameFont, paint.setColor(ColorUtil.fromARGB(0, 0, 0, (int)(f5 * 0.65f * 255.0f)))); - drawContext.drawString(f19, f14 + 8.0f + 4.0f, f6 + nameFont.getMetrics().ascent() / 2.0f + 11.0f, nameFont, paint.setColor(-1)); - paint.setColor(this.colorWithAlpha(Color.GRAY.getRGB(), f5)); - float f13 = n4 > 1 ? f14 + 140.0f - f9 : f14 + f7 - f9; - drawContext.drawString(string, f13, f6 + nameFont.getMetrics().ascent() / 2.0f + 11.0f, nameFont, paint); + drawContext.drawString(displayName, entryX + 8.0f + 4.0f + 0.5f, rowWidth + nameFont.getMetrics().ascent() / 2.0f + 11.0f + 0.5f, nameFont, paint.setColor(ColorUtil.fromARGB(0, 0, 0, (int)(alpha * 0.65f * 255.0f)))); + drawContext.drawString(displayName, entryX + 8.0f + 4.0f, rowWidth + nameFont.getMetrics().ascent() / 2.0f + 11.0f, nameFont, paint.setColor(-1)); + paint.setColor(this.colorWithAlpha(Color.GRAY.getRGB(), alpha)); + float pingX = columnCount > 1 ? entryX + 140.0f - pingWidth : entryX + maxRowWidth - pingWidth; + drawContext.drawString(ping, pingX, rowWidth + nameFont.getMetrics().ascent() / 2.0f + 11.0f, nameFont, paint); } - if (component2 != null && !component2.getString().isEmpty()) { - n = arrayList.isEmpty() ? 0 : Math.min(arrayList.size(), n3); - float f18 = f11 + (float)n * 11.0f + 10.0f; - for (String string : component2.getString().split("\n")) { - float f14 = f + f3 / 2.0f; - this.drawFormattedComponent(drawContext, Component.literal(string), f14, f18, titleFont, paint, f5); - f18 += 11.0f; + if (footer != null && !footer.getString().isEmpty()) { + i = players.isEmpty() ? 0 : Math.min(players.size(), rowsPerColumn); + float footerY = rowsStartY + (float)i * 11.0f + 10.0f; + for (String line : footer.getString().split("\n")) { + float centerX = x + width / 2.0f; + this.drawFormattedComponent(drawContext, Component.literal(line), centerX, footerY, titleFont, paint, alpha); + footerY += 11.0f; } } } } - private void drawFormattedComponent(DrawContext drawContext, Component component, float f, float f2, FontRenderer fontRenderer, Paint paint, float f3) { - float f4 = f2; - for (String string : component.getString().split("\n")) { - float f5 = f; - ArrayList arrayList = new ArrayList<>(); - String[] stringArray = ("§r" + string).split("§"); + private void drawFormattedComponent(DrawContext drawContext, Component component, float centerX, float startY, FontRenderer fontRenderer, Paint paint, float alpha) { + float lineY = startY; + for (String line : component.getString().split("\n")) { + float drawX = centerX; + ArrayList segments = new ArrayList<>(); + String[] parts = ("§r" + line).split("§"); Style style = Style.EMPTY; - for (int i = 0; i < stringArray.length; ++i) { - if (stringArray[i].isEmpty()) continue; - String segment = stringArray[i]; + for (int i = 0; i < parts.length; ++i) { + if (parts[i].isEmpty()) continue; + String segment = parts[i]; if (i > 0) { char c = segment.charAt(0); ChatFormatting fmt = ChatFormatting.getByCode(c); @@ -185,34 +185,34 @@ implements IHudElement { segment = segment.substring(1); } if (segment.isEmpty()) continue; - arrayList.add(Component.literal(segment).withStyle(style)); + segments.add(Component.literal(segment).withStyle(style)); } - float f6 = 0.0f; - for (Component component2 : arrayList) { - f6 += fontRenderer.getWidth(component2.getString()); + float totalWidth = 0.0f; + for (Component seg : segments) { + totalWidth += fontRenderer.getWidth(seg.getString()); } - f5 = f - f6 / 2.0f; - for (Component component3 : arrayList) { - String text = component3.getString(); - Style style2 = component3.getStyle(); - TextColor textColor = style2.getColor(); - int n = textColor != null ? textColor.getValue() : Color.WHITE.getRGB(); - paint.setColor(this.colorWithAlpha(n, f3)); - drawContext.drawString(text, f5, f4, fontRenderer, paint); - f5 += fontRenderer.getWidth(text); + drawX = centerX - totalWidth / 2.0f; + for (Component seg : segments) { + String text = seg.getString(); + Style segStyle = seg.getStyle(); + TextColor textColor = segStyle.getColor(); + int color = textColor != null ? textColor.getValue() : Color.WHITE.getRGB(); + paint.setColor(this.colorWithAlpha(color, alpha)); + drawContext.drawString(text, drawX, lineY, fontRenderer, paint); + drawX += fontRenderer.getWidth(text); } - f4 += 11.0f; + lineY += 11.0f; } } private float getComponentWidth(Component component, FontRenderer fontRenderer) { - float f = 0.0f; - for (String string : component.getString().split("\n")) { - String string2 = ChatFormatting.stripFormatting(string); - if (string2 == null) continue; - f = Math.max(f, fontRenderer.getWidth(string2)); + float maxWidth = 0.0f; + for (String line : component.getString().split("\n")) { + String stripped = ChatFormatting.stripFormatting(line); + if (stripped == null) continue; + maxWidth = Math.max(maxWidth, fontRenderer.getWidth(stripped)); } - return f; + return maxWidth; } @Override @@ -222,59 +222,60 @@ implements IHudElement { @Override public IHudElement.Size getHudAlignment() { - float f; - float f2; - float f3; - int n; + float screenHeight; + float rowWidth; + float maxRowWidth; + float listWidth; + int visibleRows; if (mc == null || mc.getConnection() == null) { return new IHudElement.Size(200.0f, 30.0f); } - int n2 = mc.getConnection().getOnlinePlayers().size(); - Component component = TabListInfo.header; - Component component2 = TabListInfo.footer; - float f4 = 0.0f; - f4 = component != null && !component.getString().isEmpty() ? (float)component.getString().split("\n").length * 11.0f : 20.0f; - float f5 = 0.0f; - if (component2 != null && !component2.getString().isEmpty()) { - f5 = (float)component2.getString().split("\n").length * 11.0f + 10.0f; + int playerCount = mc.getConnection().getOnlinePlayers().size(); + Component header = TabListInfo.header; + Component footer = TabListInfo.footer; + float headerHeight = 0.0f; + headerHeight = header != null && !header.getString().isEmpty() ? (float)header.getString().split("\n").length * 11.0f : 20.0f; + float footerHeight = 0.0f; + if (footer != null && !footer.getString().isEmpty()) { + footerHeight = (float)footer.getString().split("\n").length * 11.0f + 10.0f; } - int n3 = 20; - int n4 = Math.max(1, (int)Math.ceil((double)n2 / (double)n3)); - int n5 = n = n2 > 0 ? Math.min(n2, n3) : 0; - if (n4 > 1) { - f3 = (float)n4 * 140.0f + (float)(n4 - 1) * 10.0f; + int rowsPerColumn = 20; + int columnCount = Math.max(1, (int)Math.ceil((double)playerCount / (double)rowsPerColumn)); + int rowsShown = visibleRows = playerCount > 0 ? Math.min(playerCount, rowsPerColumn) : 0; + if (columnCount > 1) { + listWidth = (float)columnCount * 140.0f + (float)(columnCount - 1) * 10.0f; } else { - f2 = 0.0f; + maxRowWidth = 0.0f; if (mc.getConnection() != null) { - for (PlayerInfo playerInfo : mc.getConnection().getOnlinePlayers()) { - String string = playerInfo.getProfile().getName(); - String string2 = playerInfo.getLatency() + "ms"; - f = 12.0f + nameFont.getWidth(string) + 5.0f + nameFont.getWidth(string2); - f2 = Math.max(f2, f); + for (PlayerInfo player : mc.getConnection().getOnlinePlayers()) { + String name = player.getProfile().getName(); + String ping = player.getLatency() + "ms"; + rowWidth = 12.0f + nameFont.getWidth(name) + 5.0f + nameFont.getWidth(ping); + maxRowWidth = Math.max(maxRowWidth, rowWidth); } } - f3 = f2; + listWidth = maxRowWidth; } - f2 = 0.0f; - if (component != null) { - f2 = this.getComponentWidth(component, titleFont); + maxRowWidth = 0.0f; + if (header != null) { + maxRowWidth = this.getComponentWidth(header, titleFont); } - float f6 = 0.0f; - if (component2 != null) { - f6 = this.getComponentWidth(component2, titleFont); + float footerWidth = 0.0f; + if (footer != null) { + footerWidth = this.getComponentWidth(footer, titleFont); } - float f7 = Math.max(f3, Math.max(f2, f6)) + 20.0f; - float f8 = f4 + (float)n * 11.0f + f5 + 20.0f; - if (n2 == 0 && component2 == null) { - f8 += 10.0f; + float totalWidth = Math.max(listWidth, Math.max(maxRowWidth, footerWidth)) + 20.0f; + float totalHeight = headerHeight + (float)visibleRows * 11.0f + footerHeight + 20.0f; + if (playerCount == 0 && footer == null) { + totalHeight += 10.0f; } - if (n2 > 0 && component != null) { - f8 += 10.0f; + if (playerCount > 0 && header != null) { + totalHeight += 10.0f; } - float f9 = mc.getWindow().getGuiScaledWidth(); - f = mc.getWindow().getGuiScaledHeight(); - f7 = Math.min(f7, f9 * 0.9f); - f8 = Math.min(f8, f * 0.9f); - return new IHudElement.Size(f7, f8); + float screenWidth = mc.getWindow().getGuiScaledWidth(); + screenHeight = mc.getWindow().getGuiScaledHeight(); + totalWidth = Math.min(totalWidth, screenWidth * 0.9f); + totalHeight = Math.min(totalHeight, screenHeight * 0.9f); + return new IHudElement.Size(totalWidth, totalHeight); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/hud/TargetHud.java b/src/main/java/shit/zen/hud/TargetHud.java index 255f624..c203653 100644 --- a/src/main/java/shit/zen/hud/TargetHud.java +++ b/src/main/java/shit/zen/hud/TargetHud.java @@ -52,18 +52,18 @@ extends HudElement { } @Override - public void onGlRender(GlRenderEvent glRenderEvent, float f, float f2) { + public void onGlRender(GlRenderEvent glRenderEvent, float x, float y) { } @Override - public void onRender2D(Render2DEvent render2DEvent, float f, float f2) { + public void onRender2D(Render2DEvent render2DEvent, float x, float y) { if (mc.level == null || mc.player == null) { return; } - float f3; - for (AbstractClientPlayer abstractClientPlayer : mc.level.players()) { - if (abstractClientPlayer == mc.player || !playerHealthMap.containsKey(abstractClientPlayer.getName().getString())) continue; - abstractClientPlayer.setHealth((float)Math.max(1, playerHealthMap.get(abstractClientPlayer.getName().getString()).get())); + float maxHealth; + for (AbstractClientPlayer player : mc.level.players()) { + if (player == mc.player || !playerHealthMap.containsKey(player.getName().getString())) continue; + player.setHealth((float)Math.max(1, playerHealthMap.get(player.getName().getString()).get())); } LivingEntity target = null; if (mc.screen instanceof ChatScreen) { @@ -77,8 +77,8 @@ extends HudElement { this.lastHealth = target.getHealth(); } float currentHealth = Math.min(target.getHealth(), 20.0f); - f3 = Math.min(target.getMaxHealth(), 20.0f); - float ratio = f3 > 0.0f ? currentHealth / f3 : 0.0f; + maxHealth = Math.min(target.getMaxHealth(), 20.0f); + float ratio = maxHealth > 0.0f ? currentHealth / maxHealth : 0.0f; this.healthAnim.animate(ratio, 0.5, Easings.EASE_OUT_POW4); this.healthLagAnim.animate(ratio, 1.5, Easings.EASE_OUT_POW5); } else { @@ -88,8 +88,8 @@ extends HudElement { this.healthLagAnim.tick(); TargetStyle targetStyle = TargetStyle.getByName(this.styleMode.getValue()); if (targetStyle != null) { - f3 = target != null ? (target.getMaxHealth() > 0.0f ? Math.min(target.getHealth(), 20.0f) / Math.min(target.getMaxHealth(), 20.0f) : 0.0f) : 0.0f; - targetStyle.render(render2DEvent, target, this.healthAnim, this.healthLagAnim, f3, f, f2); + maxHealth = target != null ? (target.getMaxHealth() > 0.0f ? Math.min(target.getHealth(), 20.0f) / Math.min(target.getMaxHealth(), 20.0f) : 0.0f) : 0.0f; + targetStyle.render(render2DEvent, target, this.healthAnim, this.healthLagAnim, maxHealth, x, y); if (targetStyle instanceof RoundTargetStyle) { this.setWidth(120.0f); this.setHeight(38.0f); diff --git a/src/main/java/shit/zen/hud/WatermarkHud.java b/src/main/java/shit/zen/hud/WatermarkHud.java index 48b3213..e35cbdf 100644 --- a/src/main/java/shit/zen/hud/WatermarkHud.java +++ b/src/main/java/shit/zen/hud/WatermarkHud.java @@ -54,47 +54,47 @@ implements IHudElement { } @Override - public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float f, float f2, float f3, float f4, float f5) { + public void renderGui(GuiGraphics guiGraphics, PoseStack poseStack, float x, float y, float width, float height, float alpha) { } @Override - public void render(DrawContext drawContext, float f, float f2, float f3, float f4, float f5) { - if (mc == null || mc.player == null || f5 <= 0.01f) { + public void render(DrawContext drawContext, float x, float y, float width, float height, float alpha) { + if (mc == null || mc.player == null || alpha <= 0.01f) { return; } this.updateCache(); - float f6 = betaWidth + this.maxSubWidth; - float f7 = f + (f3 - f6) / 2.0f - 1.0f; - float f8 = f2 + f4 / 2.0f + 1.0f; - int n = this.colorWithAlpha(Color.WHITE.getRGB(), f5); - int n2 = this.colorWithAlpha(primaryColor, f5); - int n3 = this.colorWithAlpha(shadowColor, f5); + float totalWidth = betaWidth + this.maxSubWidth; + float drawX = x + (width - totalWidth) / 2.0f - 1.0f; + float centerY = y + height / 2.0f + 1.0f; + int textColor = this.colorWithAlpha(Color.WHITE.getRGB(), alpha); + int subColor = this.colorWithAlpha(primaryColor, alpha); + int shadow = this.colorWithAlpha(shadowColor, alpha); try (Paint paint = new Paint()){ - this.drawText(drawContext, paint, "Z", f7, f8 + 4.0f, logoFont, b1Width, n, n3, true); - f7 += logoCharWidth + 12.0f; - this.drawText(drawContext, paint, "|", (f7 += 12.0f) - 13.0f, f8, subFont, subLineHeight, n2, n3, true); - float f9 = (f7 += separatorCharWidth + 12.0f) + (sep1Width - betaRawWidth) / 2.0f - 13.0f; - float f10 = f7 + (sep1Width - b1RawWidth) / 2.0f - 13.0f; - this.drawText(drawContext, paint, "beta", f9, f8 - 2.0f, subFont, 0.0f, n, n3, false); - this.drawText(drawContext, paint, "b1", f10, f8 + 7.0f, subFont, 0.0f, n2, n3, false); - f7 += sep1Width; - this.drawText(drawContext, paint, "|", (f7 += 12.0f) - 13.0f, f8, subFont, subLineHeight, n2, n3, true); - float f11 = (f7 += separatorCharWidth + 12.0f) + (this.maxSubWidth - this.line1Width) / 2.0f - 13.0f; - float f12 = f7 + (this.maxSubWidth - this.line2Width) / 2.0f - 13.0f; - this.drawText(drawContext, paint, this.line1Text, f11, f8 - 2.0f, subFont, 0.0f, n, n3, false); - this.drawText(drawContext, paint, this.line2Text, f12, f8 + 7.0f, subFont, 0.0f, n2, n3, false); + this.drawText(drawContext, paint, "Z", drawX, centerY + 4.0f, logoFont, b1Width, textColor, shadow, true); + drawX += logoCharWidth + 12.0f; + this.drawText(drawContext, paint, "|", (drawX += 12.0f) - 13.0f, centerY, subFont, subLineHeight, subColor, shadow, true); + float betaX = (drawX += separatorCharWidth + 12.0f) + (sep1Width - betaRawWidth) / 2.0f - 13.0f; + float b1X = drawX + (sep1Width - b1RawWidth) / 2.0f - 13.0f; + this.drawText(drawContext, paint, "beta", betaX, centerY - 2.0f, subFont, 0.0f, textColor, shadow, false); + this.drawText(drawContext, paint, "b1", b1X, centerY + 7.0f, subFont, 0.0f, subColor, shadow, false); + drawX += sep1Width; + this.drawText(drawContext, paint, "|", (drawX += 12.0f) - 13.0f, centerY, subFont, subLineHeight, subColor, shadow, true); + float line1X = (drawX += separatorCharWidth + 12.0f) + (this.maxSubWidth - this.line1Width) / 2.0f - 13.0f; + float line2X = drawX + (this.maxSubWidth - this.line2Width) / 2.0f - 13.0f; + this.drawText(drawContext, paint, this.line1Text, line1X, centerY - 2.0f, subFont, 0.0f, textColor, shadow, false); + this.drawText(drawContext, paint, this.line2Text, line2X, centerY + 7.0f, subFont, 0.0f, subColor, shadow, false); } } - private void drawText(DrawContext drawContext, Paint paint, String string, float f, float f2, FontRenderer fontRenderer, float f3, int n, int n2, boolean bl) { - float f4 = f2; - if (bl) { - f4 = f2 + f3 / 2.0f; + private void drawText(DrawContext drawContext, Paint paint, String text, float x, float y, FontRenderer fontRenderer, float lineHeight, int color, int shadowColor, boolean centerVertical) { + float drawY = y; + if (centerVertical) { + drawY = y + lineHeight / 2.0f; } - paint.setColor(n2); - drawContext.drawString(string, f + 0.5f, f4 + 0.5f, fontRenderer, paint); - paint.setColor(n); - drawContext.drawString(string, f, f4, fontRenderer, paint); + paint.setColor(shadowColor); + drawContext.drawString(text, x + 0.5f, drawY + 0.5f, fontRenderer, paint); + paint.setColor(color); + drawContext.drawString(text, x, drawY, fontRenderer, paint); } private float getX() { @@ -113,13 +113,13 @@ implements IHudElement { return new String[]{"Singleplayer", "1ms"}; } ServerData serverData = mc.getCurrentServer(); - String string = serverData != null ? serverData.ip : "Multiplayer"; - int n = 0; + String serverIp = serverData != null ? serverData.ip : "Multiplayer"; + int ping = 0; if (mc.getConnection() != null && mc.player != null && (playerInfo = mc.getConnection().getPlayerInfo(mc.player.getUUID())) != null) { - n = playerInfo.getLatency(); + ping = playerInfo.getLatency(); } - n = Mth.clamp(n, 0, 9999); - return new String[]{string, n + "ms"}; + ping = Mth.clamp(ping, 0, 9999); + return new String[]{serverIp, ping + "ms"}; } @Override diff --git a/src/main/java/shit/zen/hud/target/RoundTargetStyle.java b/src/main/java/shit/zen/hud/target/RoundTargetStyle.java index 3c8119e..b5ba174 100644 --- a/src/main/java/shit/zen/hud/target/RoundTargetStyle.java +++ b/src/main/java/shit/zen/hud/target/RoundTargetStyle.java @@ -57,30 +57,30 @@ extends TargetStyle { } @Override - public void render(Render2DEvent render2DEvent, LivingEntity livingEntity, SmoothAnimationTimer smoothAnimationTimer, SmoothAnimationTimer smoothAnimationTimer2, float f, float f2, float f3) { - float f4; - boolean bl; + public void render(Render2DEvent render2DEvent, LivingEntity livingEntity, SmoothAnimationTimer healthAnim, SmoothAnimationTimer healthLagAnim, float healthPct, float x, float y) { + float fade; + boolean shouldShow; for (int i = 0; i < this.equipmentSlots.length; ++i) { this.equipmentSlots[i] = ItemStack.EMPTY; } - float f5 = 120.0f; - float f6 = 38.0f; - float f7 = 3.0f; - float f8 = 5.0f; - boolean bl2 = livingEntity != null; - long l = System.currentTimeMillis(); - boolean bl3 = false; - if (bl2) { - this.lastActiveTime = l; + float panelWidth = 120.0f; + float panelHeight = 38.0f; + float healthBarRadius = 3.0f; + float panelRadius = 5.0f; + boolean hasTarget = livingEntity != null; + long now = System.currentTimeMillis(); + boolean targetChanged = false; + if (hasTarget) { + this.lastActiveTime = now; if (this.currentTarget != livingEntity) { this.currentTarget = livingEntity; this.lastTarget = livingEntity; - bl3 = true; + targetChanged = true; } } - boolean bl4 = bl = bl2 || l - this.lastActiveTime < 300L; - if (bl != this.visible) { - this.visible = bl; + boolean visibleNow = shouldShow = hasTarget || now - this.lastActiveTime < 300L; + if (shouldShow != this.visible) { + this.visible = shouldShow; if (this.visible) { this.fadeAnim.animate(1.0, 0.35, Easings.EASE_OUT_POW3); this.slideAnim.setCurrentValue(5.0); @@ -94,7 +94,7 @@ extends TargetStyle { this.slideAnim.animate(5.0, 0.15, Easings.EASE_IN_POW3); this.contentAnim.animate(0.0, 0.15, Easings.EASE_IN_POW3); } - } else if (bl3 && this.visible) { + } else if (targetChanged && this.visible) { this.fadeAnim.animate(1.0, 0.35, Easings.EASE_OUT_POW3); this.slideAnim.setCurrentValue(5.0); this.slideAnim.setStartTime(0L); @@ -118,84 +118,84 @@ extends TargetStyle { if (this.contentAnim.getStartTime() != 0L) { this.contentAnim.tick(); } - if ((f4 = this.fadeAnim.getValueF()) <= 0.01f) { + if ((fade = this.fadeAnim.getValueF()) <= 0.01f) { return; } - LivingEntity livingEntity2 = this.currentTarget; - if (livingEntity2 == null) { + LivingEntity target = this.currentTarget; + if (target == null) { return; } - float f9 = 30.0f; - float f10 = 4.0f; - float f11 = f2 + 4.0f + 30.0f + 4.0f; - float f12 = 120.0f - (f11 - f2) - 3.0f; - float f13 = f3 + 3.0f + 2.0f; - float f14 = GlHelper.getFontAscent(this.nameFont); - float f15 = f13 + f14 + 4.0f; + float headBoxSize = 30.0f; + float headPadding = 4.0f; + float contentX = x + 4.0f + 30.0f + 4.0f; + float contentWidth = 120.0f - (contentX - x) - 3.0f; + float nameY = y + 3.0f + 2.0f; + float nameAscent = GlHelper.getFontAscent(this.nameFont); + float belowNameY = nameY + nameAscent + 4.0f; PoseStack poseStack = render2DEvent.guiGraphics().pose(); poseStack.pushPose(); - RenderUtil.drawBlurredRect(poseStack, f2, f3, 120.0f, 38.0f, 5.0f, 15.0f, 0.95f * f4, 0); + RenderUtil.drawBlurredRect(poseStack, x, y, 120.0f, 38.0f, 5.0f, 15.0f, 0.95f * fade, 0); poseStack.popPose(); Renderer.renderConsumer((drawContext -> { - this.panelPaint.setColor(new Color(0, 0, 0, (int)((float)COLOR_PANEL_BG.getAlpha() * f4)).getRGB()); - GlHelper.drawRoundedRect(f2, f3, 120.0f, 38.0f, 5.0f, this.panelPaint); - if (bl2 && livingEntity.hurtTime > this.lastHurtTime) { + this.panelPaint.setColor(new Color(0, 0, 0, (int)((float)COLOR_PANEL_BG.getAlpha() * fade)).getRGB()); + GlHelper.drawRoundedRect(x, y, 120.0f, 38.0f, 5.0f, this.panelPaint); + if (hasTarget && livingEntity.hurtTime > this.lastHurtTime) { this.scaleAnim.setCurrentValue(0.7f); this.scaleAnim.animate(1.0, 1.5, Easings.EASE_OUT_ELASTIC); } - if (bl2) { + if (hasTarget) { this.lastHurtTime = livingEntity.hurtTime; } this.scaleAnim.tick(); float scaleValue = this.scaleAnim.getValueF(); - float minScale = (float)Math.max(0.7, f4); + float minScale = (float)Math.max(0.7, fade); float combinedScale = scaleValue * minScale; float headSize = 30.0f * combinedScale; - float headX = f2 + 4.0f + (30.0f - headSize) / 2.0f; - float headY = f3 + (38.0f - headSize) / 2.0f; - if (livingEntity2 instanceof AbstractClientPlayer abstractClientPlayer) { - GlHelper.drawPlayerHeadRounded(abstractClientPlayer, headX, headY, headSize, headSize, f4, 5.0f * combinedScale); + float headX = x + 4.0f + (30.0f - headSize) / 2.0f; + float headY = y + (38.0f - headSize) / 2.0f; + if (target instanceof AbstractClientPlayer abstractClientPlayer) { + GlHelper.drawPlayerHeadRounded(abstractClientPlayer, headX, headY, headSize, headSize, fade, 5.0f * combinedScale); } float slideOff = this.slideAnim.getValueF(); - String string = livingEntity2 == mc.player ? NameProtect.getProtectedName() : livingEntity2.getName().getString(); - GlHelper.drawTextShadowLegacy(string, f11, f13 + 1.0f + slideOff, this.nameFont, new Color(1.0f, 1.0f, 1.0f, f4).getRGB()); - float healthY = f15 + 16.0f; + String displayName = target == mc.player ? NameProtect.getProtectedName() : target.getName().getString(); + GlHelper.drawTextShadowLegacy(displayName, contentX, nameY + 1.0f + slideOff, this.nameFont, new Color(1.0f, 1.0f, 1.0f, fade).getRGB()); + float healthY = belowNameY + 16.0f; float healthH = 4.0f; - float healthW = f12 - 2.0f; - this.healthBgPaint.setColor(new Color(0, 0, 0, (int)((float)COLOR_HEALTH_BG.getAlpha() * f4)).getRGB()); - GlHelper.drawRoundedRect(f11, healthY, healthW, healthH, 3.0f, this.healthBgPaint); - this.healthLagPaint.setColor(new Color(99, 99, 99, (int)((float)COLOR_HEALTH_LAG.getAlpha() * f4)).getRGB()); - float lagWidth = smoothAnimationTimer2.getValueF() * healthW; - GlHelper.drawRoundedRect(f11, healthY, lagWidth, healthH, 3.0f, this.healthLagPaint); + float healthW = contentWidth - 2.0f; + this.healthBgPaint.setColor(new Color(0, 0, 0, (int)((float)COLOR_HEALTH_BG.getAlpha() * fade)).getRGB()); + GlHelper.drawRoundedRect(contentX, healthY, healthW, healthH, 3.0f, this.healthBgPaint); + this.healthLagPaint.setColor(new Color(99, 99, 99, (int)((float)COLOR_HEALTH_LAG.getAlpha() * fade)).getRGB()); + float lagWidth = healthLagAnim.getValueF() * healthW; + GlHelper.drawRoundedRect(contentX, healthY, lagWidth, healthH, 3.0f, this.healthLagPaint); float contentVal = this.contentAnim.getValueF(); - float barWidth = smoothAnimationTimer.getValueF() * healthW * contentVal; - Color color = new Color(COLOR_HEALTH_BAR.getRed(), COLOR_HEALTH_BAR.getGreen(), COLOR_HEALTH_BAR.getBlue(), (int)(255.0f * f4)); - Color color2 = new Color(COLOR_HEALTH_BAR2.getRed(), COLOR_HEALTH_BAR2.getGreen(), COLOR_HEALTH_BAR2.getBlue(), (int)(255.0f * f4)); - GlHelper.drawGradientRoundedRect(f11, healthY, barWidth, healthH, 3.0f, color, color2); + float barWidth = healthAnim.getValueF() * healthW * contentVal; + Color barColor1 = new Color(COLOR_HEALTH_BAR.getRed(), COLOR_HEALTH_BAR.getGreen(), COLOR_HEALTH_BAR.getBlue(), (int)(255.0f * fade)); + Color barColor2 = new Color(COLOR_HEALTH_BAR2.getRed(), COLOR_HEALTH_BAR2.getGreen(), COLOR_HEALTH_BAR2.getBlue(), (int)(255.0f * fade)); + GlHelper.drawGradientRoundedRect(contentX, healthY, barWidth, healthH, 3.0f, barColor1, barColor2); })); - if (livingEntity2 != null) { - this.equipmentSlots[0] = livingEntity2.getItemBySlot(EquipmentSlot.HEAD); - this.equipmentSlots[1] = livingEntity2.getItemBySlot(EquipmentSlot.CHEST); - this.equipmentSlots[2] = livingEntity2.getItemBySlot(EquipmentSlot.LEGS); - this.equipmentSlots[3] = livingEntity2.getItemBySlot(EquipmentSlot.FEET); + if (target != null) { + this.equipmentSlots[0] = target.getItemBySlot(EquipmentSlot.HEAD); + this.equipmentSlots[1] = target.getItemBySlot(EquipmentSlot.CHEST); + this.equipmentSlots[2] = target.getItemBySlot(EquipmentSlot.LEGS); + this.equipmentSlots[3] = target.getItemBySlot(EquipmentSlot.FEET); } - float f16 = f11; - float f17 = 0.8f; - float f18 = 16.0f * f17; - float f19 = 2.0f; + float itemX = contentX; + float itemScale = 0.8f; + float itemSize = 16.0f * itemScale; + float itemGap = 2.0f; RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); for (ItemStack itemStack : this.equipmentSlots) { if (itemStack != null && !itemStack.isEmpty()) { - PoseStack poseStack2 = render2DEvent.guiGraphics().pose(); - poseStack2.pushPose(); - poseStack2.translate(f16, f15, 0.0f); - poseStack2.scale(f17, f17, 1.0f); - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, f4); + PoseStack itemPose = render2DEvent.guiGraphics().pose(); + itemPose.pushPose(); + itemPose.translate(itemX, belowNameY, 0.0f); + itemPose.scale(itemScale, itemScale, 1.0f); + RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, fade); render2DEvent.guiGraphics().renderItem(itemStack, 0, 0); - poseStack2.popPose(); + itemPose.popPose(); } - f16 += f18 + f19; + itemX += itemSize + itemGap; } RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); RenderSystem.disableBlend(); diff --git a/src/main/java/shit/zen/manager/LagManager.java b/src/main/java/shit/zen/manager/LagManager.java index 5a065f0..95f8afd 100644 --- a/src/main/java/shit/zen/manager/LagManager.java +++ b/src/main/java/shit/zen/manager/LagManager.java @@ -25,17 +25,17 @@ public class LagManager { INSTANCE = this; } - public void setBlink(boolean bl) { - if (bl) { + public void setBlink(boolean enable) { + if (enable) { ++this.blinkCount; } else if (this.blinkCount > 0) { --this.blinkCount; } - boolean bl2 = this.blinkCount > 0; - if (this.blinking == bl2) { + boolean shouldBlink = this.blinkCount > 0; + if (this.blinking == shouldBlink) { return; } - this.blinking = bl2; + this.blinking = shouldBlink; if (this.blinking) { this.packetQueue.clear(); } else { @@ -69,8 +69,8 @@ public class LagManager { if (!this.blinking || ClientBase.mc.getConnection() == null) { return; } - long l = System.currentTimeMillis(); - while (!this.packetQueue.isEmpty() && l - this.packetQueue.peek().getRight() >= this.lagTime) { + long now = System.currentTimeMillis(); + while (!this.packetQueue.isEmpty() && now - this.packetQueue.peek().getRight() >= this.lagTime) { ClientBase.mc.getConnection().send(this.packetQueue.poll().getLeft()); } } diff --git a/src/main/java/shit/zen/manager/TargetManager.java b/src/main/java/shit/zen/manager/TargetManager.java index c837ef8..c42acbf 100644 --- a/src/main/java/shit/zen/manager/TargetManager.java +++ b/src/main/java/shit/zen/manager/TargetManager.java @@ -42,18 +42,18 @@ extends ClientBase { } } - public Stream getTargetsStream(float f) { + public Stream getTargetsStream(float range) { if (mc.player == null) { return Stream.empty(); } return new ArrayList<>(this.targets).stream().filter(livingEntity -> { - Vec3 vec3 = RotationUtil.closestPoint(mc.player.getEyePosition(), livingEntity.getBoundingBox()); - return vec3.distanceTo(mc.player.getEyePosition()) <= (double)f; + Vec3 closest = RotationUtil.closestPoint(mc.player.getEyePosition(), livingEntity.getBoundingBox()); + return closest.distanceTo(mc.player.getEyePosition()) <= (double)range; }); } - public List getTargets(float f) { - return this.getTargetsStream(f).toList(); + public List getTargets(float range) { + return this.getTargetsStream(range).toList(); } @Generated diff --git a/src/main/java/shit/zen/modules/KeyBind.java b/src/main/java/shit/zen/modules/KeyBind.java index 3c794d7..957a150 100644 --- a/src/main/java/shit/zen/modules/KeyBind.java +++ b/src/main/java/shit/zen/modules/KeyBind.java @@ -7,8 +7,8 @@ public class KeyBind { private int keyCode; private static final Map bindings = new HashMap<>(); - public KeyBind(int n) { - this.keyCode = n; + public KeyBind(int keyCode) { + this.keyCode = keyCode; } public String getName() { @@ -18,8 +18,8 @@ public class KeyBind { return bindings.getOrDefault(this.keyCode, "Unknown"); } - public void setKey(int n) { - this.keyCode = n; + public void setKey(int keyCode) { + this.keyCode = keyCode; } public int getKey() { diff --git a/src/main/java/shit/zen/modules/Module.java b/src/main/java/shit/zen/modules/Module.java index 6b62e95..df574a1 100644 --- a/src/main/java/shit/zen/modules/Module.java +++ b/src/main/java/shit/zen/modules/Module.java @@ -25,25 +25,25 @@ extends ClientBase { private final List> settings; private static final String REGISTER_FAIL_MSG = "Failed to register value for module "; - protected Module(String string, Category category) { - this.name = string; + protected Module(String name, Category category) { + this.name = name; this.category = category; this.keyCode = 0; this.bind = new KeyBind(this.keyCode); this.settings = new ArrayList<>(); } - protected Module(String string, Category category, int n) { - this.name = string; + protected Module(String name, Category category, int keyCode) { + this.name = name; this.category = category; - this.keyCode = n; + this.keyCode = keyCode; this.bind = new KeyBind(this.keyCode); this.settings = new ArrayList<>(); } - public void setKey(int n) { - this.keyCode = n; - this.bind.setKey(n); + public void setKey(int keyCode) { + this.keyCode = keyCode; + this.bind.setKey(keyCode); } public KeyBind getBind() { @@ -57,21 +57,21 @@ extends ClientBase { public void registerSettings() { for (Field field : this.getClass().getDeclaredFields()) { try { - Object object; + Object value; if (!field.isAccessible()) { field.setAccessible(true); } - if (!((object = field.get(this)) instanceof Setting)) continue; - this.addSetting((Setting)object); - } catch (IllegalAccessException illegalAccessException) { + if (!((value = field.get(this)) instanceof Setting)) continue; + this.addSetting((Setting)value); + } catch (IllegalAccessException ex) { System.out.println(REGISTER_FAIL_MSG + this.getName() + "!"); } } } - public void setEnabled(boolean bl) { - this.enabled = bl; - if (bl) { + public void setEnabled(boolean enabled) { + this.enabled = enabled; + if (enabled) { ZenClient.getInstance().getEventBus().register(this); this.onEnable(); } else { diff --git a/src/main/java/shit/zen/modules/impl/combat/AutoOffHand.java b/src/main/java/shit/zen/modules/impl/combat/AutoOffHand.java index f2e4983..bc1e483 100644 --- a/src/main/java/shit/zen/modules/impl/combat/AutoOffHand.java +++ b/src/main/java/shit/zen/modules/impl/combat/AutoOffHand.java @@ -78,11 +78,11 @@ public class AutoOffHand extends Module { private boolean isNearEnemy() { if (mc.level == null || mc.player == null) return false; - double d = this.range.getValue().doubleValue(); + double rangeValue = this.range.getValue().doubleValue(); return mc.level.players().stream().anyMatch( p -> !p.equals(mc.player) && !p.isRemoved() - && mc.player.distanceToSqr(p) <= d * d + && mc.player.distanceToSqr(p) <= rangeValue * rangeValue && this.hasLineOfSight(p)); } diff --git a/src/main/java/shit/zen/modules/impl/combat/AutoSoup.java b/src/main/java/shit/zen/modules/impl/combat/AutoSoup.java index b8c06a5..83ffcfa 100644 --- a/src/main/java/shit/zen/modules/impl/combat/AutoSoup.java +++ b/src/main/java/shit/zen/modules/impl/combat/AutoSoup.java @@ -49,13 +49,12 @@ extends Module { if (!this.delayTimer.hasPassed(this.delay.getValue().longValue())) { return; } - int n = ItemUtil.findItemInRange(0, 9, Items.MUSHROOM_STEW); - if (mc.player.getHealth() <= this.health.getValue().floatValue() && n != -1) { - boolean bl; - boolean bl2 = bl = mc.player.getInventory().selected == n; - if (!bl) { + int soupSlot = ItemUtil.findItemInRange(0, 9, Items.MUSHROOM_STEW); + if (mc.player.getHealth() <= this.health.getValue().floatValue() && soupSlot != -1) { + boolean alreadySelected = mc.player.getInventory().selected == soupSlot; + if (!alreadySelected) { this.prevSelectedSlot = mc.player.getInventory().selected; - mc.player.getInventory().selected = n; + mc.player.getInventory().selected = soupSlot; PlayerUtil.sendCarriedItem(); this.switchDelayTimer.reset(); } diff --git a/src/main/java/shit/zen/modules/impl/combat/AutoThrow.java b/src/main/java/shit/zen/modules/impl/combat/AutoThrow.java index e830e49..0436829 100644 --- a/src/main/java/shit/zen/modules/impl/combat/AutoThrow.java +++ b/src/main/java/shit/zen/modules/impl/combat/AutoThrow.java @@ -67,7 +67,7 @@ extends Module { */ @EventTarget public void onSprint(SprintEvent sprintEvent) { - int n; + int slot; if (mc.player == null || mc.level == null || mc.gameMode == null || mc.getConnection() == null) { return; } @@ -79,28 +79,27 @@ extends Module { if (this.ticksUntilThrow <= 0) { this.targetRotation = null; } - int n2 = -1; - for (n = 0; n < 9; ++n) { - ItemStack itemStack = mc.player.getInventory().getItem(n); + int projectileSlot = -1; + for (slot = 0; slot < 9; ++slot) { + ItemStack itemStack = mc.player.getInventory().getItem(slot); if (itemStack.isEmpty() || !(itemStack.getItem() instanceof EggItem) && !(itemStack.getItem() instanceof SnowballItem)) continue; - n2 = n; + projectileSlot = slot; break; } if (mc.player.isUsingItem() || mc.player.getMainHandItem().getItem() instanceof BowItem || mc.player.getMainHandItem().getItem() instanceof CrossbowItem) { return; } - if (n2 == -1) return; + if (projectileSlot == -1) return; if (--this.ticksUntilThrow == 0) { - boolean bl; - n = mc.player.getInventory().selected; - boolean bl2 = bl = n != n2; - if (bl) { - mc.player.getInventory().selected = n2; + slot = mc.player.getInventory().selected; + boolean shouldSwap = slot != projectileSlot; + if (shouldSwap) { + mc.player.getInventory().selected = projectileSlot; PlayerUtil.sendCarriedItem(); - this.savedSlot = n; + this.savedSlot = slot; } - float f = mc.player.getYRot(); - float f2 = mc.player.getXRot(); + float prevYaw = mc.player.getYRot(); + float prevPitch = mc.player.getXRot(); if (RotationHandler.targetRotation != null && RotationHandler.isRotating) { mc.player.setYRot(RotationHandler.targetRotation.getYaw()); mc.player.setXRot(RotationHandler.targetRotation.getPitch()); @@ -109,8 +108,8 @@ extends Module { if (!(mc.player.getMainHandItem().getItem() instanceof EggItem) && !(mc.player.getMainHandItem().getItem() instanceof SnowballItem)) return; mc.gameMode.useItem(mc.player, InteractionHand.MAIN_HAND); } finally { - mc.player.setYRot(f); - mc.player.setXRot(f2); + mc.player.setYRot(prevYaw); + mc.player.setXRot(prevPitch); } } else { if (!this.findTarget().isPresent() || !this.throwTimer.hasPassed((float)((long) this.throwDelay.getValue().doubleValue())) || Stuck.INSTANCE != null && Stuck.INSTANCE.isEnabled()) return; @@ -137,58 +136,58 @@ extends Module { } private Rotation calculateThrowRotation(Entity entity) { - float f; - float f2 = 1.5f; - float f3 = 0.03f; - double d = entity.getX(); - double d2 = entity.getY() + (double)entity.getBbHeight() * 0.8; - double d3 = entity.getZ(); - double d4 = entity.getX() - entity.xOld; - double d5 = entity.getY() - entity.yOld; - double d6 = entity.getZ() - entity.zOld; + float pitch; + float projectileSpeed = 1.5f; + float gravity = 0.03f; + double predictX = entity.getX(); + double predictY = entity.getY() + (double)entity.getBbHeight() * 0.8; + double predictZ = entity.getZ(); + double velX = entity.getX() - entity.xOld; + double velY = entity.getY() - entity.yOld; + double velZ = entity.getZ() - entity.zOld; for (int i = 0; i < 3; ++i) { - double d7 = d - mc.player.getX(); - double d8 = d2 - (mc.player.getY() + (double)mc.player.getEyeHeight(mc.player.getPose())); - double d9 = d3 - mc.player.getZ(); - double d10 = Math.sqrt(d7 * d7 + d9 * d9); - f = (float)(d10 / (double)(f2 * 0.4f)); - d = entity.getX() + d4 * (double)f; - d2 = entity.getY() + (double)entity.getBbHeight() * 0.8 + d5 * (double)f; - d3 = entity.getZ() + d6 * (double)f; + double dx = predictX - mc.player.getX(); + double dy = predictY - (mc.player.getY() + (double)mc.player.getEyeHeight(mc.player.getPose())); + double dz = predictZ - mc.player.getZ(); + double horizDist = Math.sqrt(dx * dx + dz * dz); + float travelTicks = (float)(horizDist / (double)(projectileSpeed * 0.4f)); + predictX = entity.getX() + velX * (double)travelTicks; + predictY = entity.getY() + (double)entity.getBbHeight() * 0.8 + velY * (double)travelTicks; + predictZ = entity.getZ() + velZ * (double)travelTicks; } - double d11 = d - mc.player.getX(); - double d12 = d2 - (mc.player.getY() + (double)mc.player.getEyeHeight(mc.player.getPose())); - double d13 = d3 - mc.player.getZ(); - double d14 = Math.sqrt(d11 * d11 + d13 * d13); - float f4 = (float)(Math.atan2(d13, d11) * 180.0 / Math.PI) - 90.0f; - f = -RotationUtil.ballisticPitch((float)d14, (float)d12, f2, f3); - return new Rotation(f4, f); + double dx = predictX - mc.player.getX(); + double dy = predictY - (mc.player.getY() + (double)mc.player.getEyeHeight(mc.player.getPose())); + double dz = predictZ - mc.player.getZ(); + double horizDist = Math.sqrt(dx * dx + dz * dz); + float yaw = (float)(Math.atan2(dz, dx) * 180.0 / Math.PI) - 90.0f; + pitch = -RotationUtil.ballisticPitch((float)horizDist, (float)dy, projectileSpeed, gravity); + return new Rotation(yaw, pitch); } private Optional findTarget() { if (mc.player == null || mc.level == null) { return Optional.empty(); } - return mc.level.players().stream().filter(abstractClientPlayer -> abstractClientPlayer != mc.player).filter(abstractClientPlayer -> KillAura.INSTANCE.isValidTarget(abstractClientPlayer)).filter(abstractClientPlayer -> { - double d = this.getDistanceTo(abstractClientPlayer); - return d >= this.minDistance.getValue().doubleValue() && d <= this.maxDistance.getValue().doubleValue(); - }).filter(this::hasLineOfSight).filter(abstractClientPlayer -> !this.isInvisibleAlly(abstractClientPlayer)).min(Comparator.comparingDouble(abstractClientPlayer -> mc.player.distanceTo(abstractClientPlayer))); + return mc.level.players().stream().filter(player -> player != mc.player).filter(player -> KillAura.INSTANCE.isValidTarget(player)).filter(player -> { + double dist = this.getDistanceTo(player); + return dist >= this.minDistance.getValue().doubleValue() && dist <= this.maxDistance.getValue().doubleValue(); + }).filter(this::hasLineOfSight).filter(player -> !this.isInvisibleAlly(player)).min(Comparator.comparingDouble(player -> mc.player.distanceTo(player))); } private double getDistanceTo(Entity entity) { - double d = mc.player.getX() - entity.getX(); - double d2 = mc.player.getZ() - entity.getZ(); - return Math.sqrt(d * d + d2 * d2); + double dx = mc.player.getX() - entity.getX(); + double dz = mc.player.getZ() - entity.getZ(); + return Math.sqrt(dx * dx + dz * dz); } private boolean hasLineOfSight(Entity entity) { - Vec3 vec3; + Vec3 targetPos; if (mc.player == null || mc.level == null) { return false; } - Vec3 vec32 = new Vec3(mc.player.getX(), mc.player.getY() + (double)mc.player.getEyeHeight(), mc.player.getZ()); - BlockHitResult blockHitResult = mc.level.clip(new ClipContext(vec32, vec3 = new Vec3(entity.getX(), entity.getY() + (double)entity.getEyeHeight(), entity.getZ()), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); - return blockHitResult.getType() == HitResult.Type.MISS; + Vec3 eyePos = new Vec3(mc.player.getX(), mc.player.getY() + (double)mc.player.getEyeHeight(), mc.player.getZ()); + BlockHitResult hit = mc.level.clip(new ClipContext(eyePos, targetPos = new Vec3(entity.getX(), entity.getY() + (double)entity.getEyeHeight(), entity.getZ()), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); + return hit.getType() == HitResult.Type.MISS; } private boolean isInvisibleAlly(Entity entity) { diff --git a/src/main/java/shit/zen/modules/impl/combat/Critical.java b/src/main/java/shit/zen/modules/impl/combat/Critical.java index 8b12e31..0da1851 100644 --- a/src/main/java/shit/zen/modules/impl/combat/Critical.java +++ b/src/main/java/shit/zen/modules/impl/combat/Critical.java @@ -20,12 +20,12 @@ extends Module { if (mc.player == null) { return; } - boolean bl = mc.player.fallDistance > 0.0f && !mc.player.onGround() && !mc.player.onClimbable() && !mc.player.isInWater() && !mc.player.hasEffect(MobEffects.BLINDNESS) && !mc.player.isPassenger() && entityRemoveEvent.entity() instanceof LivingEntity; - boolean bl2 = mc.player.isSprinting(); - if (bl && !entityRemoveEvent.dead()) { + boolean canCrit = mc.player.fallDistance > 0.0f && !mc.player.onGround() && !mc.player.onClimbable() && !mc.player.isInWater() && !mc.player.hasEffect(MobEffects.BLINDNESS) && !mc.player.isPassenger() && entityRemoveEvent.entity() instanceof LivingEntity; + boolean wasSprinting = mc.player.isSprinting(); + if (canCrit && !entityRemoveEvent.dead()) { mc.player.resetAttackStrengthTicker(); } - if (bl && bl2 && entityRemoveEvent.dead()) { + if (canCrit && wasSprinting && entityRemoveEvent.dead()) { mc.options.keySprint.setDown(false); } } diff --git a/src/main/java/shit/zen/modules/impl/combat/CrystalAura.java b/src/main/java/shit/zen/modules/impl/combat/CrystalAura.java index 5b7aa6e..7feaf18 100644 --- a/src/main/java/shit/zen/modules/impl/combat/CrystalAura.java +++ b/src/main/java/shit/zen/modules/impl/combat/CrystalAura.java @@ -41,22 +41,22 @@ extends Module { return; } Object rawPacket = packetEvent.getPacket(); - if (rawPacket instanceof ClientboundAddEntityPacket clientboundAddEntityPacket) { - if (this.attackOnPacket.getValue() && clientboundAddEntityPacket.getType() == EntityType.END_CRYSTAL) { - EndCrystal endCrystal = new EndCrystal(mc.level, clientboundAddEntityPacket.getX(), clientboundAddEntityPacket.getY(), clientboundAddEntityPacket.getZ()); - endCrystal.setId(clientboundAddEntityPacket.getId()); + if (rawPacket instanceof ClientboundAddEntityPacket addEntityPacket) { + if (this.attackOnPacket.getValue() && addEntityPacket.getType() == EntityType.END_CRYSTAL) { + EndCrystal endCrystal = new EndCrystal(mc.level, addEntityPacket.getX(), addEntityPacket.getY(), addEntityPacket.getZ()); + endCrystal.setId(addEntityPacket.getId()); if (mc.player.distanceTo(endCrystal) <= 4.0f) { Rotation rotation = RotationUtil.entityRotation(endCrystal); mc.getConnection().send(new ServerboundMovePlayerPacket.PosRot(mc.player.getX(), mc.player.getY(), mc.player.getZ(), rotation.getYaw(), rotation.getPitch(), mc.player.onGround())); - PacketUtil.sendPredictive(n -> new ServerboundUseItemPacket(InteractionHand.MAIN_HAND, n)); - float f = mc.player.getYRot(); - float f2 = mc.player.getXRot(); + PacketUtil.sendPredictive(seq -> new ServerboundUseItemPacket(InteractionHand.MAIN_HAND, seq)); + float prevYaw = mc.player.getYRot(); + float prevPitch = mc.player.getXRot(); mc.player.setYRot(RotationHandler.targetRotation.getYaw()); mc.player.setXRot(RotationHandler.targetRotation.getPitch()); mc.getConnection().send(ServerboundInteractPacket.createAttackPacket(endCrystal, false)); mc.player.swing(InteractionHand.MAIN_HAND); - mc.player.setYRot(f); - mc.player.setXRot(f2); + mc.player.setYRot(prevYaw); + mc.player.setXRot(prevPitch); } } } @@ -66,13 +66,13 @@ extends Module { public void onTick(TickEvent tickEvent) { if (mc.player != null && mc.level != null) { Rotation rotation; - Entity entity2; - double d; - Optional optional = StreamSupport.stream(mc.level.entitiesForRendering().spliterator(), true).filter(entity -> entity instanceof EndCrystal).findAny(); + Entity crystalEntity; + double hitDistance; + Optional crystalOpt = StreamSupport.stream(mc.level.entitiesForRendering().spliterator(), true).filter(entity -> entity instanceof EndCrystal).findAny(); aimRotation = null; - if (optional.isPresent() && (d = RotationUtil.getMinHitDistance(entity2 = optional.get(), rotation = RotationUtil.entityRotation(entity2))) <= 3.0) { + if (crystalOpt.isPresent() && (hitDistance = RotationUtil.getMinHitDistance(crystalEntity = crystalOpt.get(), rotation = RotationUtil.entityRotation(crystalEntity))) <= 3.0) { aimRotation = rotation; - this.crystalTarget = entity2; + this.crystalTarget = crystalEntity; } } } @@ -80,14 +80,14 @@ extends Module { @EventTarget public void onPreMotion(PreMotionEvent preMotionEvent) { if (this.crystalTarget != null && aimRotation != null && mc.player != null && mc.getConnection() != null) { - float f = mc.player.getYRot(); - float f2 = mc.player.getXRot(); + float prevYaw = mc.player.getYRot(); + float prevPitch = mc.player.getXRot(); mc.player.setYRot(aimRotation.getYaw()); mc.player.setXRot(aimRotation.getPitch()); mc.getConnection().send(ServerboundInteractPacket.createAttackPacket(this.crystalTarget, false)); mc.player.swing(InteractionHand.MAIN_HAND); - mc.player.setYRot(f); - mc.player.setXRot(f2); + mc.player.setYRot(prevYaw); + mc.player.setXRot(prevPitch); this.crystalTarget = null; } } diff --git a/src/main/java/shit/zen/modules/impl/combat/antikb/MixMode.java b/src/main/java/shit/zen/modules/impl/combat/antikb/MixMode.java index ff27ec2..b77154b 100644 --- a/src/main/java/shit/zen/modules/impl/combat/antikb/MixMode.java +++ b/src/main/java/shit/zen/modules/impl/combat/antikb/MixMode.java @@ -100,27 +100,27 @@ extends AntiKBMode { } Packet packet = receivePacketEvent.getPacket(); if (this.webHitCount <= 0 || mc.player.isInWater() || mc.player.isUnderWater()) { - if (packet instanceof ClientboundSetEntityMotionPacket clientboundSetEntityMotionPacket) { - if (clientboundSetEntityMotionPacket.getId() != localPlayer.getId()) { + if (packet instanceof ClientboundSetEntityMotionPacket motionPacket) { + if (motionPacket.getId() != localPlayer.getId()) { return; } AntiKB.rotation = null; this.knockbackPacket = null; - if (clientboundSetEntityMotionPacket.getYa() > 0) { + if (motionPacket.getYa() > 0) { this.sprintTick = 0; if (KillAura.INSTANCE.isEnabled() && KillAura.target != null && AntiKB.INSTANCE.tryAttack.getValue()) { this.shouldAttack = true; this.wasSprinting = mc.player.isSprinting(); } else if (AntiKB.INSTANCE.rotate.getValue()) { - float f = (float)((double)clientboundSetEntityMotionPacket.getXa() / 8000.0); - float f2 = (float)((double)clientboundSetEntityMotionPacket.getZa() / 8000.0); - float f3 = (float)Math.toDegrees(Math.atan2(f, -f2)); - AntiKB.rotation = new Rotation(f3, localPlayer.getXRot()); + float dx = (float)((double)motionPacket.getXa() / 8000.0); + float dz = (float)((double)motionPacket.getZa() / 8000.0); + float kbYaw = (float)Math.toDegrees(Math.atan2(dx, -dz)); + AntiKB.rotation = new Rotation(kbYaw, localPlayer.getXRot()); } receivePacketEvent.setCancelled(true); this.packetQueue.add(receivePacketEvent.getPacket()); this.isSuspending = true; - this.knockbackPacket = clientboundSetEntityMotionPacket; + this.knockbackPacket = motionPacket; } } if (this.isSuspending) { @@ -196,22 +196,22 @@ extends AntiKBMode { } private void applyKBDirection() { - float f = (float)((double)this.knockbackPacket.getXa() / 8000.0); - float f2 = (float)((double)this.knockbackPacket.getZa() / 8000.0); - float f3 = (float)Math.toDegrees(Math.atan2(f, -f2)); - float f4 = Mth.wrapDegrees(f3 - mc.player.getYRot()); + float dx = (float)((double)this.knockbackPacket.getXa() / 8000.0); + float dz = (float)((double)this.knockbackPacket.getZa() / 8000.0); + float kbYaw = (float)Math.toDegrees(Math.atan2(dx, -dz)); + float yawDelta = Mth.wrapDegrees(kbYaw - mc.player.getYRot()); this.restoreMovementKeys(); - double d = Math.toRadians(f4); - double d2 = Math.sin(d); - double d3 = Math.cos(d); - if (d3 > 0.5) { + double yawRad = Math.toRadians(yawDelta); + double sinYaw = Math.sin(yawRad); + double cosYaw = Math.cos(yawRad); + if (cosYaw > 0.5) { mc.options.keyUp.setDown(true); - } else if (d3 < -0.5) { + } else if (cosYaw < -0.5) { mc.options.keyDown.setDown(true); } - if (d2 > 0.5) { + if (sinYaw > 0.5) { mc.options.keyRight.setDown(true); - } else if (d2 < -0.5) { + } else if (sinYaw < -0.5) { mc.options.keyLeft.setDown(true); } } @@ -229,8 +229,8 @@ extends AntiKBMode { if (mc.player.hurtTime > 6 && !mc.options.keyJump.isDown()) { mc.options.keyJump.setDown(true); } else if (!Scaffold.INSTANCE.isEnabled()) { - boolean bl = InputConstants.isKeyDown(mc.getWindow().getWindow(), mc.options.keyJump.getKey().getValue()); - mc.options.keyJump.setDown(bl); + boolean jumpKeyDown = InputConstants.isKeyDown(mc.getWindow().getWindow(), mc.options.keyJump.getKey().getValue()); + mc.options.keyJump.setDown(jumpKeyDown); } } } diff --git a/src/main/java/shit/zen/modules/impl/combat/antikb/NoXZMode.java b/src/main/java/shit/zen/modules/impl/combat/antikb/NoXZMode.java index c423cd2..6a6cecc 100644 --- a/src/main/java/shit/zen/modules/impl/combat/antikb/NoXZMode.java +++ b/src/main/java/shit/zen/modules/impl/combat/antikb/NoXZMode.java @@ -146,35 +146,34 @@ extends AntiKBMode { } return; } - if (packet instanceof ClientboundSetEntityMotionPacket clientboundSetEntityMotionPacket) { - if (clientboundSetEntityMotionPacket.getId() != mc.player.getId()) { + if (packet instanceof ClientboundSetEntityMotionPacket motionPacket) { + if (motionPacket.getId() != mc.player.getId()) { return; } - double d = -clientboundSetEntityMotionPacket.getXa(); - double d2 = -clientboundSetEntityMotionPacket.getZa(); - if (Math.abs(d) > 0.01 || Math.abs(d2) > 0.01) { + double dx = -motionPacket.getXa(); + double dz = -motionPacket.getZa(); + if (Math.abs(dx) > 0.01 || Math.abs(dz) > 0.01) { this.hitCounter = 1; } - if (clientboundSetEntityMotionPacket.getYa() > 0) { - Entity entity; - boolean bl; + if (motionPacket.getYa() > 0) { + Entity target; this.sprintBoostCounter = this.sprintBoostCounter % 100 + 100; if (this.sprintBoostCounter >= 100) { this.shouldJump = true; } - boolean bl2 = bl = this.isValidTarget(entity = this.getAttackTarget()) && mc.player.isSprinting(); + boolean canAttack = this.isValidTarget(target = this.getAttackTarget()) && mc.player.isSprinting(); if (!mc.player.onGround()) { this.isSuspending = true; this.suspendTicks = 0; - this.knockbackPacket = clientboundSetEntityMotionPacket; + this.knockbackPacket = motionPacket; receivePacketEvent.setCancelled(true); - } else if (bl) { - this.attackTarget = entity; + } else if (canAttack) { + this.attackTarget = target; this.attacksRemaining = AntiKB.INSTANCE.attackAmount.getValue().intValue(); } else { this.isSuspending = true; this.suspendTicks = 0; - this.knockbackPacket = clientboundSetEntityMotionPacket; + this.knockbackPacket = motionPacket; receivePacketEvent.setCancelled(true); ChatUtil.print("Alink Wait"); } @@ -249,18 +248,18 @@ extends AntiKBMode { if (mc.player == null) { return Double.MAX_VALUE; } - Vec3 vec3 = mc.player.getEyePosition(1.0f); - AABB aABB = entity.getBoundingBox(); - double d = Math.max(aABB.minX, Math.min(vec3.x, aABB.maxX)); - double d2 = Math.max(aABB.minY, Math.min(vec3.y, aABB.maxY)); - double d3 = Math.max(aABB.minZ, Math.min(vec3.z, aABB.maxZ)); - return vec3.distanceTo(new Vec3(d, d2, d3)); + Vec3 eyePos = mc.player.getEyePosition(1.0f); + AABB box = entity.getBoundingBox(); + double clampedX = Math.max(box.minX, Math.min(eyePos.x, box.maxX)); + double clampedY = Math.max(box.minY, Math.min(eyePos.y, box.maxY)); + double clampedZ = Math.max(box.minZ, Math.min(eyePos.z, box.maxZ)); + return eyePos.distanceTo(new Vec3(clampedX, clampedY, clampedZ)); } private Entity getHitResultEntity() { - Entity entity; - if (mc.hitResult != null && mc.hitResult.getType() == HitResult.Type.ENTITY && (entity = ((EntityHitResult)mc.hitResult).getEntity()) instanceof LivingEntity && entity != mc.player && entity.isAlive() && !entity.isSpectator()) { - return entity; + Entity hitEntity; + if (mc.hitResult != null && mc.hitResult.getType() == HitResult.Type.ENTITY && (hitEntity = ((EntityHitResult)mc.hitResult).getEntity()) instanceof LivingEntity && hitEntity != mc.player && hitEntity.isAlive() && !hitEntity.isSpectator()) { + return hitEntity; } return null; } @@ -280,8 +279,8 @@ extends AntiKBMode { if (entity instanceof LivingEntity && ((livingEntity = (LivingEntity)entity).isDeadOrDying() || livingEntity.getHealth() <= 0.0f)) { return false; } - double d = 3.7f; - return !(this.getAABBDistance(entity) > d); + double maxReach = 3.7f; + return !(this.getAABBDistance(entity) > maxReach); } @Override @@ -319,32 +318,31 @@ extends AntiKBMode { this.clearTarget(); } if (this.isSuspending) { - boolean bl; ++this.suspendTicks; - boolean bl2 = AntiKB.INSTANCE.instantAttack.getValue(); - if (bl2 && this.instantAttackProgress < 3.0f) { - float f; - ZenClient.serverTickRate = f = 0.5f; - this.instantAttackProgress += 1.0f - f; + boolean instantAttackEnabled = AntiKB.INSTANCE.instantAttack.getValue(); + if (instantAttackEnabled && this.instantAttackProgress < 3.0f) { + float tickRate; + ZenClient.serverTickRate = tickRate = 0.5f; + this.instantAttackProgress += 1.0f - tickRate; this.instantAttackProgress = Math.min(this.instantAttackProgress, 3.0f); } - boolean bl3 = mc.player.onGround(); - boolean bl4 = bl = this.suspendTicks >= 12; - if (bl3 || bl) { - ChatUtil.print(bl ? "Alink Timeout" : "ground"); - if (bl2) { + boolean onGround = mc.player.onGround(); + boolean isTimeout = this.suspendTicks >= 12; + if (onGround || isTimeout) { + ChatUtil.print(isTimeout ? "Alink Timeout" : "ground"); + if (instantAttackEnabled) { ZenClient.serverTickRate = 1.0f; } - Entity entity = this.getAttackTarget(); - boolean bl5 = this.isValidTarget(entity); - boolean bl6 = mc.player.isSprinting(); - if (bl3 && bl5 && bl6) { + Entity target = this.getAttackTarget(); + boolean canAttack = this.isValidTarget(target); + boolean sprinting = mc.player.isSprinting(); + if (onGround && canAttack && sprinting) { this.isFlushing = true; - this.attackTarget = entity; + this.attackTarget = target; this.attacksRemaining = AntiKB.INSTANCE.attackAmount.getValue().intValue(); this.sendMovePackets(); this.applyKnockbackPacket(); - if (bl2 && this.instantAttackProgress > 0.0f) { + if (instantAttackEnabled && this.instantAttackProgress > 0.0f) { this.attacksRemaining = (int)this.instantAttackProgress; this.scheduleMotionFlush(); this.isSuspending = false; @@ -361,10 +359,10 @@ extends AntiKBMode { } } else { this.release(); - if (bl2) { + if (instantAttackEnabled) { this.instantAttackProgress = 0.0f; } - if (bl3 && mc.player.isSprinting()) { + if (onGround && mc.player.isSprinting()) { mc.player.setSprinting(false); } } @@ -407,8 +405,8 @@ extends AntiKBMode { this.clearTarget(); return; } - double d = 3.7f; - if (this.getAABBDistance(this.attackTarget) > d) { + double maxReach = 3.7f; + if (this.getAABBDistance(this.attackTarget) > maxReach) { this.clearTarget(); return; } @@ -432,15 +430,15 @@ extends AntiKBMode { ChatUtil.print("not sprinting"); return false; } - boolean bl = mc.player.isSprinting(); - if (bl) { + boolean wasSprinting = mc.player.isSprinting(); + if (wasSprinting) { mc.player.setSprinting(false); } mc.gameMode.attack(mc.player, entity); mc.player.swing(InteractionHand.MAIN_HAND); - if (bl) { - Vec3 vec3 = mc.player.getDeltaMovement(); - mc.player.setDeltaMovement(vec3.x * 0.6, vec3.y, vec3.z * 0.6); + if (wasSprinting) { + Vec3 velocity = mc.player.getDeltaMovement(); + mc.player.setDeltaMovement(velocity.x * 0.6, velocity.y, velocity.z * 0.6); } if (!AntiKB.INSTANCE.instantAttack.getValue()) { ChatUtil.print("Attack (" + this.attacksRemaining + ")"); diff --git a/src/main/java/shit/zen/modules/impl/exploit/Disabler.java b/src/main/java/shit/zen/modules/impl/exploit/Disabler.java index 93c68b3..e358ebd 100644 --- a/src/main/java/shit/zen/modules/impl/exploit/Disabler.java +++ b/src/main/java/shit/zen/modules/impl/exploit/Disabler.java @@ -97,8 +97,7 @@ extends Module { @EventTarget(value=0) public void onPacket(PacketEvent packetEvent) { - float f; - ServerboundSetCarriedItemPacket serverboundSetCarriedItemPacket; + ServerboundSetCarriedItemPacket carriedItemPacket; if (mc.player == null || mc.isSingleplayer() && this.onlyRemoteServer.getValue()) { return; } @@ -122,34 +121,34 @@ extends Module { this.log("Inventory opened at: " + this.inventoryOpenTime); } if (packet instanceof ServerboundSetCarriedItemPacket) { - serverboundSetCarriedItemPacket = (ServerboundSetCarriedItemPacket)packet; - int n = serverboundSetCarriedItemPacket.getSlot(); - if (this.badPacketsA.getValue() && n == this.lastSentSlot && n != -1) { + carriedItemPacket = (ServerboundSetCarriedItemPacket)packet; + int slot = carriedItemPacket.getSlot(); + if (this.badPacketsA.getValue() && slot == this.lastSentSlot && slot != -1) { packetEvent.setCancelled(true); - this.log("BadPacketsA: Cancelled duplicate slot packet: " + n); + this.log("BadPacketsA: Cancelled duplicate slot packet: " + slot); return; } - if (this.acaFastSwitch.getValue() && this.lastSentSlot != -1 && n != this.lastSentSlot) { - this.sendIntermediateSlots(this.lastSentSlot, n); + if (this.acaFastSwitch.getValue() && this.lastSentSlot != -1 && slot != this.lastSentSlot) { + this.sendIntermediateSlots(this.lastSentSlot, slot); } - this.lastSentSlot = n; - this.log("Processed slot switch: " + this.lastSentSlot + " -> " + n); + this.lastSentSlot = slot; + this.log("Processed slot switch: " + this.lastSentSlot + " -> " + slot); } if (this.acaInventoryFrequency.getValue() && packet instanceof ServerboundContainerClosePacket closePacket) { if (this.inventoryOpen) { - long l = System.currentTimeMillis(); - long l2 = l - this.inventoryOpenTime; - if (l2 <= 150L) { + long now = System.currentTimeMillis(); + long openDuration = now - this.inventoryOpenTime; + if (openDuration <= 150L) { packetEvent.setCancelled(true); this.storedClosePacket = closePacket; - this.inventoryCloseDelay = 151L - l2; + this.inventoryCloseDelay = 151L - openDuration; this.inventoryTimer.reset(); this.log("InventoryFrequency: Storing close packet, will send after " + this.inventoryCloseDelay + "ms"); this.inventoryOpen = false; return; } this.inventoryOpen = false; - this.log("InventoryFrequency: Allowed close packet after " + l2 + "ms"); + this.log("InventoryFrequency: Allowed close packet after " + openDuration + "ms"); } } if (this.themisBlink.getValue()) { @@ -221,101 +220,101 @@ extends Module { } } - private boolean isAimStepRotation(float f, float f2) { + private boolean isAimStepRotation(float yaw, float pitch) { if (this.lastYaw == 0.0f && this.lastPitch == 0.0f) { return false; } - double d = Math.abs(this.wrapDegrees(f - this.lastYaw)); - double d2 = Math.abs(f2 - this.lastPitch); - boolean bl = d < 1.0E-5 && d2 > 1.0; - boolean bl2 = d2 < 1.0E-5 && d > 1.0; - return bl || bl2; + double yawDelta = Math.abs(this.wrapDegrees(yaw - this.lastYaw)); + double pitchDelta = Math.abs(pitch - this.lastPitch); + boolean yawStuck = yawDelta < 1.0E-5 && pitchDelta > 1.0; + boolean pitchStuck = pitchDelta < 1.0E-5 && yawDelta > 1.0; + return yawStuck || pitchStuck; } - private float[] applyAimStep(float f, float f2) { - double d = Math.abs(this.wrapDegrees(f - this.lastYaw)); - double d2 = Math.abs(f2 - this.lastPitch); - float f3 = f; - float f4 = f2; - if (d < 1.0E-5 && d2 > 1.0) { - f3 = this.lastYaw + (float)(this.random.nextGaussian() * 0.001); + private float[] applyAimStep(float yaw, float pitch) { + double yawDelta = Math.abs(this.wrapDegrees(yaw - this.lastYaw)); + double pitchDelta = Math.abs(pitch - this.lastPitch); + float newYaw = yaw; + float newPitch = pitch; + if (yawDelta < 1.0E-5 && pitchDelta > 1.0) { + newYaw = this.lastYaw + (float)(this.random.nextGaussian() * 0.001); } - if (d2 < 1.0E-5 && d > 1.0) { - f4 = this.lastPitch + (float)(this.random.nextGaussian() * 0.001); + if (pitchDelta < 1.0E-5 && yawDelta > 1.0) { + newPitch = this.lastPitch + (float)(this.random.nextGaussian() * 0.001); } - return new float[]{f3, f4}; + return new float[]{newYaw, newPitch}; } - private float[] applyPerfectRotation(float f, float f2) { - double d; + private float[] applyPerfectRotation(float yaw, float pitch) { + double jitter; if (this.lastYaw == 0.0f && this.lastPitch == 0.0f) { - return new float[]{f, f2}; + return new float[]{yaw, pitch}; } - double d2 = Math.abs(this.wrapDegrees(f - this.lastYaw)); - double d3 = Math.abs(f2 - this.lastPitch); - float f3 = f; - float f4 = f2; - if (!this.isNearZeroOrMultiple(d2) && this.isKnownRotationStep(d2)) { - d = this.random.nextGaussian() * 0.005; - f3 = f + (float)d; + double yawDelta = Math.abs(this.wrapDegrees(yaw - this.lastYaw)); + double pitchDelta = Math.abs(pitch - this.lastPitch); + float newYaw = yaw; + float newPitch = pitch; + if (!this.isNearZeroOrMultiple(yawDelta) && this.isKnownRotationStep(yawDelta)) { + jitter = this.random.nextGaussian() * 0.005; + newYaw = yaw + (float)jitter; } - if (!this.isNearZeroOrMultiple(d3) && this.isKnownRotationStep(d3)) { - d = this.random.nextGaussian() * 0.005; - f4 = f2 + (float)d; + if (!this.isNearZeroOrMultiple(pitchDelta) && this.isKnownRotationStep(pitchDelta)) { + jitter = this.random.nextGaussian() * 0.005; + newPitch = pitch + (float)jitter; } - return new float[]{f3, f4}; + return new float[]{newYaw, newPitch}; } private boolean isMoving() { return mc.player != null && mc.player.getDeltaMovement().lengthSqr() > 0.001; } - private boolean isNearZeroOrMultiple(double d) { - return Math.abs(d) <= 1.0E-10 || this.isMultipleOf(360.0, d); + private boolean isNearZeroOrMultiple(double value) { + return Math.abs(value) <= 1.0E-10 || this.isMultipleOf(360.0, value); } - private boolean isKnownRotationStep(double d) { - if (Double.isInfinite(d) || Double.isNaN(d)) { + private boolean isKnownRotationStep(double value) { + if (Double.isInfinite(value) || Double.isNaN(value)) { return false; } - for (double d2 : perfectRotSteps) { - if (!this.isMultipleOf(d2, d)) continue; + for (double step : perfectRotSteps) { + if (!this.isMultipleOf(step, value)) continue; return true; } return false; } - private boolean isMultipleOf(double d, double d2) { - if (d == 0.0) { - return Math.abs(d2) <= 1.0E-10; + private boolean isMultipleOf(double base, double value) { + if (base == 0.0) { + return Math.abs(value) <= 1.0E-10; } - double d3 = d2 / d; - return Math.abs(d3 - (double)Math.round(d3)) <= 1.0E-10; + double ratio = value / base; + return Math.abs(ratio - (double)Math.round(ratio)) <= 1.0E-10; } - private float wrapDegrees(float f) { - while (f > 180.0f) { - f -= 360.0f; + private float wrapDegrees(float degrees) { + while (degrees > 180.0f) { + degrees -= 360.0f; } - while (f < -180.0f) { - f += 360.0f; + while (degrees < -180.0f) { + degrees += 360.0f; } - return f; + return degrees; } - private void sendIntermediateSlots(int n, int n2) { - int n3 = Math.abs(n - n2); - if (n3 > 1 && !this.isWrapAroundSlot(n, n2)) { - int n4 = n > n2 ? -1 : 1; - for (int i = n + n4; i != n2; i += n4) { - if (i < 0 || i > 8) continue; - PacketUtil.sendQueued(new ServerboundSetCarriedItemPacket(i)); - this.log("Sent intermediate slot: " + i); + private void sendIntermediateSlots(int fromSlot, int toSlot) { + int distance = Math.abs(fromSlot - toSlot); + if (distance > 1 && !this.isWrapAroundSlot(fromSlot, toSlot)) { + int step = fromSlot > toSlot ? -1 : 1; + for (int slot = fromSlot + step; slot != toSlot; slot += step) { + if (slot < 0 || slot > 8) continue; + PacketUtil.sendQueued(new ServerboundSetCarriedItemPacket(slot)); + this.log("Sent intermediate slot: " + slot); } } } - private boolean isWrapAroundSlot(int n, int n2) { - return n == 0 && n2 == 8 || n == 8 && n2 == 0; + private boolean isWrapAroundSlot(int fromSlot, int toSlot) { + return fromSlot == 0 && toSlot == 8 || fromSlot == 8 && toSlot == 0; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/modules/impl/exploit/FastPlace.java b/src/main/java/shit/zen/modules/impl/exploit/FastPlace.java index 15c1119..653b852 100644 --- a/src/main/java/shit/zen/modules/impl/exploit/FastPlace.java +++ b/src/main/java/shit/zen/modules/impl/exploit/FastPlace.java @@ -42,11 +42,11 @@ extends Module { return; } Item item = localPlayer.getMainHandItem().getItem(); - boolean bl = this.itemTypes.isSelected("Blocks") && item instanceof BlockItem; + boolean shouldFastPlace = this.itemTypes.isSelected("Blocks") && item instanceof BlockItem; if (this.itemTypes.isSelected("Throwables") && this.isThrowable(item)) { - bl = true; + shouldFastPlace = true; } - if (bl) { + if (shouldFastPlace) { try { ReflectionUtil.setRightClickDelay(0); this.placeTimer.reset(); diff --git a/src/main/java/shit/zen/modules/impl/misc/AimAssist.java b/src/main/java/shit/zen/modules/impl/misc/AimAssist.java index 0151645..0638e97 100644 --- a/src/main/java/shit/zen/modules/impl/misc/AimAssist.java +++ b/src/main/java/shit/zen/modules/impl/misc/AimAssist.java @@ -130,13 +130,13 @@ extends Module { private void applyRotation(Rotation rotation) { rotation.snapToSensitivity(Float.valueOf((float) mc.options.sensitivity().get().doubleValue())); - float f = rotation.getYaw(); - float f2 = rotation.getPitch(); - mc.player.setXRot(f2); - mc.player.setYRot(f); + float yaw = rotation.getYaw(); + float pitch = rotation.getPitch(); + mc.player.setXRot(pitch); + mc.player.setYRot(yaw); mc.player.setXRot(Mth.clamp(mc.player.getXRot(), -90.0f, 90.0f)); - mc.player.xRotO = f2; - mc.player.yRotO = f; + mc.player.xRotO = pitch; + mc.player.yRotO = yaw; mc.player.xRotO = Mth.clamp(mc.player.xRotO, -90.0f, 90.0f); } @@ -154,12 +154,12 @@ extends Module { return new Rotation(mc.player.getRotationVector().y, mc.player.getRotationVector().x); } - public static float getAngleDifference(double d, double d2) { - return Float.parseFloat(Double.valueOf(Mth.wrapDegrees(d - d2)).toString()); + public static float getAngleDifference(double a, double b) { + return Float.parseFloat(Double.valueOf(Mth.wrapDegrees(a - b)).toString()); } private boolean isInFov(Rotation rotation, Entity entity) { - float f = AimAssist.getAngleDifference(entity.getYRot(), rotation.getYaw()); - return (double)Math.abs(f) <= this.fov.getValue().doubleValue() / 2.0; + float diff = AimAssist.getAngleDifference(entity.getYRot(), rotation.getYaw()); + return (double)Math.abs(diff) <= this.fov.getValue().doubleValue() / 2.0; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/modules/impl/misc/AutoRod.java b/src/main/java/shit/zen/modules/impl/misc/AutoRod.java index b3c337b..75d250a 100644 --- a/src/main/java/shit/zen/modules/impl/misc/AutoRod.java +++ b/src/main/java/shit/zen/modules/impl/misc/AutoRod.java @@ -53,8 +53,8 @@ extends Module { } return; } - boolean bl = this.isMouseButtonDown(); - if (!bl) { + boolean mouseDown = this.isMouseButtonDown(); + if (!mouseDown) { this.isActive = false; return; } @@ -62,34 +62,34 @@ extends Module { return; } this.isActive = true; - int n = this.findUsableItemSlot(); - if (n == -1) { + int slot = this.findUsableItemSlot(); + if (slot == -1) { return; } this.previousSlot = mc.player.getInventory().selected; - boolean bl2 = mc.player.getInventory().getItem(n).getItem() == Items.FISHING_ROD; + boolean isFishingRod = mc.player.getInventory().getItem(slot).getItem() == Items.FISHING_ROD; this.slotSwitched = true; - this.selectHotbarSlot(n); + this.selectHotbarSlot(slot); this.useItem(); - if (bl2) { + if (isFishingRod) { this.tickDelay = this.delay.getValue().intValue(); } - if (!bl2 || this.tickDelay <= 0) { + if (!isFishingRod || this.tickDelay <= 0) { this.restoreSlot(); this.slotSwitched = false; } } - public boolean isCurrentMouseButton(int n) { - return this.getMouseButtonCode() == n; + public boolean isCurrentMouseButton(int button) { + return this.getMouseButtonCode() == button; } public boolean isActiveOrPending() { return this.slotSwitched || this.tickDelay > 0; } - public boolean shouldInterceptButton(int n) { - return this.isCurrentMouseButton(n) && (this.isActiveOrPending() || this.findUsableItemSlot() != -1); + public boolean shouldInterceptButton(int button) { + return this.isCurrentMouseButton(button) && (this.isActiveOrPending() || this.findUsableItemSlot() != -1); } private boolean isMidPearlBlocking() { @@ -110,16 +110,16 @@ extends Module { } private int findUsableItemSlot() { - int n = this.findItemInHotbar(Items.FISHING_ROD); - return n != -1 ? n : this.findThrowableSlot(); + int rodSlot = this.findItemInHotbar(Items.FISHING_ROD); + return rodSlot != -1 ? rodSlot : this.findThrowableSlot(); } private int findItemInHotbar(Item item) { if (mc.player == null) { return -1; } - int n = Math.min(9, mc.player.getInventory().items.size()); - for (int i = 0; i < n; ++i) { + int hotbarSize = Math.min(9, mc.player.getInventory().items.size()); + for (int i = 0; i < hotbarSize; ++i) { if (mc.player.getInventory().getItem(i).getItem() != item) continue; return i; } @@ -130,16 +130,16 @@ extends Module { if (mc.player == null) { return -1; } - int n = Math.min(9, mc.player.getInventory().items.size()); - for (int i = 0; i < n; ++i) { + int hotbarSize = Math.min(9, mc.player.getInventory().items.size()); + for (int i = 0; i < hotbarSize; ++i) { if (!this.isThrowable(mc.player.getInventory().getItem(i).getItem())) continue; return i; } return -1; } - private void selectHotbarSlot(int n) { - mc.player.getInventory().selected = n; + private void selectHotbarSlot(int slot) { + mc.player.getInventory().selected = slot; PlayerUtil.sendCarriedItem(); } diff --git a/src/main/java/shit/zen/modules/impl/misc/SafeWalk.java b/src/main/java/shit/zen/modules/impl/misc/SafeWalk.java index cf25d08..4a4e3c8 100644 --- a/src/main/java/shit/zen/modules/impl/misc/SafeWalk.java +++ b/src/main/java/shit/zen/modules/impl/misc/SafeWalk.java @@ -12,8 +12,8 @@ extends Module { super("SafeWalk", Category.MISC); } - public static boolean isOnBlockEdge(float f) { - return !mc.level.getCollisions(mc.player, mc.player.getBoundingBox().move(0.0, -0.5, 0.0).inflate(-f, 0.0, -f)).iterator().hasNext(); + public static boolean isOnBlockEdge(float inset) { + return !mc.level.getCollisions(mc.player, mc.player.getBoundingBox().move(0.0, -0.5, 0.0).inflate(-inset, 0.0, -inset)).iterator().hasNext(); } @EventTarget @@ -25,7 +25,7 @@ extends Module { @Override public void onDisable() { - boolean bl = InputConstants.isKeyDown(mc.getWindow().getWindow(), mc.options.keyShift.getKey().getValue()); - mc.options.keyShift.setDown(bl); + boolean keyDown = InputConstants.isKeyDown(mc.getWindow().getWindow(), mc.options.keyShift.getKey().getValue()); + mc.options.keyShift.setDown(keyDown); } } \ No newline at end of file diff --git a/src/main/java/shit/zen/modules/impl/movement/CollisionSpeed.java b/src/main/java/shit/zen/modules/impl/movement/CollisionSpeed.java index 792ec23..57c7fab 100644 --- a/src/main/java/shit/zen/modules/impl/movement/CollisionSpeed.java +++ b/src/main/java/shit/zen/modules/impl/movement/CollisionSpeed.java @@ -26,43 +26,43 @@ extends Module { @EventTarget public void onMotion(MotionEvent motionEvent) { if (motionEvent.isPost() && MovementUtil.isInputActive() && mc.player != null && mc.level != null) { - AABB aABB = mc.player.getBoundingBox().expandTowards(0.25, 0.25, 0.25); - int n = 0; + AABB playerBox = mc.player.getBoundingBox().expandTowards(0.25, 0.25, 0.25); + int collisionCount = 0; for (Entity entity : mc.level.entitiesForRendering()) { - if (!(entity instanceof LivingEntity) && !(entity instanceof Boat) && !(entity instanceof Minecart) && !(entity instanceof FishingHook) || entity instanceof ArmorStand || entity.getId() == mc.player.getId() || !entity.isAlive() || !aABB.intersects(entity.getBoundingBox()) || entity.getId() == -8 || entity.getId() == -1337 || mc.player.getTeam() != null && entity.getTeam() != null && !entity.getTeam().getCollisionRule().equals(Team.CollisionRule.ALWAYS) && (mc.player.getTeam().isAlliedTo(entity.getTeam()) ? !entity.getTeam().getCollisionRule().equals(Team.CollisionRule.PUSH_OWN_TEAM) : !entity.getTeam().getCollisionRule().equals(Team.CollisionRule.PUSH_OTHER_TEAMS))) continue; - ++n; + if (!(entity instanceof LivingEntity) && !(entity instanceof Boat) && !(entity instanceof Minecart) && !(entity instanceof FishingHook) || entity instanceof ArmorStand || entity.getId() == mc.player.getId() || !entity.isAlive() || !playerBox.intersects(entity.getBoundingBox()) || entity.getId() == -8 || entity.getId() == -1337 || mc.player.getTeam() != null && entity.getTeam() != null && !entity.getTeam().getCollisionRule().equals(Team.CollisionRule.ALWAYS) && (mc.player.getTeam().isAlliedTo(entity.getTeam()) ? !entity.getTeam().getCollisionRule().equals(Team.CollisionRule.PUSH_OWN_TEAM) : !entity.getTeam().getCollisionRule().equals(Team.CollisionRule.PUSH_OTHER_TEAMS))) continue; + ++collisionCount; } - float f = mc.player.getYRot(); + float moveYaw = mc.player.getYRot(); if (mc.options.keyDown.isDown()) { - f += 180.0f; + moveYaw += 180.0f; if (mc.options.keyLeft.isDown()) { - f += 45.0f; + moveYaw += 45.0f; } else if (mc.options.keyRight.isDown()) { - f -= 45.0f; + moveYaw -= 45.0f; } } else if (mc.options.keyUp.isDown()) { if (mc.options.keyLeft.isDown()) { - f -= 45.0f; + moveYaw -= 45.0f; } else if (mc.options.keyRight.isDown()) { - f += 45.0f; + moveYaw += 45.0f; } } else if (mc.options.keyRight.isDown()) { - f += 90.0f; + moveYaw += 90.0f; } else if (mc.options.keyLeft.isDown()) { - f -= 90.0f; + moveYaw -= 90.0f; } - double d = Math.toRadians(f); - double d2 = 0.065f * (float)Math.min(4, n); + double moveYawRad = Math.toRadians(moveYaw); + double speedBoost = 0.065f * (float)Math.min(4, collisionCount); if (TargetStrafe.strafeTarget != null && TargetStrafe.INSTANCE.isEnabled() && (!TargetStrafe.isSmartStrafe() || mc.options.keyJump.isDown())) { - float f2 = (float)(d2 / ((double)TargetStrafe.getRange() * Math.PI * 2.0) * 360.0) * (float)TargetStrafe.strafeDirectionSign; + float angleStep = (float)(speedBoost / ((double)TargetStrafe.getRange() * Math.PI * 2.0) * 360.0) * (float)TargetStrafe.strafeDirectionSign; Rotation rotation = RotationUtil.rotationToForBow(new Vec3(TargetStrafe.strafeTarget.getX(), TargetStrafe.strafeTarget.getY(), TargetStrafe.strafeTarget.getZ()), new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ())); - rotation.setYaw(rotation.getYaw() + f2); - float f3 = rotation.getYaw() * ((float)Math.PI / 180); - double d3 = TargetStrafe.strafeTarget.getX() - Math.sin(f3) * (double)TargetStrafe.getRange(); - double d4 = TargetStrafe.strafeTarget.getZ() + Math.cos(f3) * (double)TargetStrafe.getRange(); - d = RotationUtil.rotationToForBow(new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ()), new Vec3(d3, TargetStrafe.strafeTarget.getY(), d4)).getYaw() * ((float)Math.PI / 180); + rotation.setYaw(rotation.getYaw() + angleStep); + float strafeYawRad = rotation.getYaw() * ((float)Math.PI / 180); + double strafeX = TargetStrafe.strafeTarget.getX() - Math.sin(strafeYawRad) * (double)TargetStrafe.getRange(); + double strafeZ = TargetStrafe.strafeTarget.getZ() + Math.cos(strafeYawRad) * (double)TargetStrafe.getRange(); + moveYawRad = RotationUtil.rotationToForBow(new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ()), new Vec3(strafeX, TargetStrafe.strafeTarget.getY(), strafeZ)).getYaw() * ((float)Math.PI / 180); } - MovementUtil.strafeWithYaw(d, d2); + MovementUtil.strafeWithYaw(moveYawRad, speedBoost); MovementUtil.strafeForward(1.0E-4f); } } diff --git a/src/main/java/shit/zen/modules/impl/movement/FastUse.java b/src/main/java/shit/zen/modules/impl/movement/FastUse.java index 08664f8..82d2dde 100644 --- a/src/main/java/shit/zen/modules/impl/movement/FastUse.java +++ b/src/main/java/shit/zen/modules/impl/movement/FastUse.java @@ -598,7 +598,7 @@ public class FastUse extends Module implements TripleProvider { return "NoSlow".equals(this.mode.getValue()); } - private Packet createUseItemPacket(int n) { - return new ServerboundUseItemPacket(this.useHand, n); + private Packet createUseItemPacket(int sequence) { + return new ServerboundUseItemPacket(this.useHand, sequence); } } diff --git a/src/main/java/shit/zen/modules/impl/movement/GuiMove.java b/src/main/java/shit/zen/modules/impl/movement/GuiMove.java index 1a1dc1d..51aac59 100644 --- a/src/main/java/shit/zen/modules/impl/movement/GuiMove.java +++ b/src/main/java/shit/zen/modules/impl/movement/GuiMove.java @@ -50,10 +50,10 @@ extends Module { return InputConstants.isKeyDown(mc.getWindow().getWindow(), keyMapping.getDefaultKey().getValue()); } - private static float getMovementSpeed(boolean bl, boolean bl2) { - if (bl == bl2) { + private static float getMovementSpeed(boolean forward, boolean back) { + if (forward == back) { return 0.0f; } - return bl ? 1.0f : -1.0f; + return forward ? 1.0f : -1.0f; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/modules/impl/movement/TargetStrafe.java b/src/main/java/shit/zen/modules/impl/movement/TargetStrafe.java index 39d445d..e1083c9 100644 --- a/src/main/java/shit/zen/modules/impl/movement/TargetStrafe.java +++ b/src/main/java/shit/zen/modules/impl/movement/TargetStrafe.java @@ -41,25 +41,25 @@ extends Module { @EventTarget public void onMotion(MotionEvent motionEvent) { if (motionEvent.isPost() && mc.player != null) { - boolean bl; - AABB aABB; + boolean aboveVoid; + AABB playerBox; if (KillAura.target == null) { strafeTarget = null; } else if (this.switchTimer.hasPassed(this.switchDelay.getValue().intValue()) || strafeTarget == null) { ArrayList sortedTargets = new ArrayList<>(KillAura.targetList); - sortedTargets.sort((entity, entity2) -> { - float f = mc.player.distanceTo(entity); - float f2 = mc.player.distanceTo(entity2); - return Float.compare(f, f2); + sortedTargets.sort((a, b) -> { + float distA = mc.player.distanceTo(a); + float distB = mc.player.distanceTo(b); + return Float.compare(distA, distB); }); if (!sortedTargets.isEmpty()) { strafeTarget = sortedTargets.get(0); this.switchTimer.reset(); } } - aABB = mc.player.getBoundingBox(); - boolean bl2 = bl = MovementUtil.isAboveVoid(aABB.minX, aABB.minY, aABB.minZ) || MovementUtil.isAboveVoid(aABB.minX, aABB.minY, aABB.maxZ) || MovementUtil.isAboveVoid(aABB.maxX, aABB.minY, aABB.minZ) || MovementUtil.isAboveVoid(aABB.maxX, aABB.minY, aABB.maxZ); - if ((bl || mc.player.horizontalCollision) && this.collisionTimer.hasPassedDouble(500.0, true)) { + playerBox = mc.player.getBoundingBox(); + aboveVoid = MovementUtil.isAboveVoid(playerBox.minX, playerBox.minY, playerBox.minZ) || MovementUtil.isAboveVoid(playerBox.minX, playerBox.minY, playerBox.maxZ) || MovementUtil.isAboveVoid(playerBox.maxX, playerBox.minY, playerBox.minZ) || MovementUtil.isAboveVoid(playerBox.maxX, playerBox.minY, playerBox.maxZ); + if ((aboveVoid || mc.player.horizontalCollision) && this.collisionTimer.hasPassedDouble(500.0, true)) { strafeDirectionSign *= -1; } } diff --git a/src/main/java/shit/zen/modules/impl/player/AntiTNT.java b/src/main/java/shit/zen/modules/impl/player/AntiTNT.java index 7d80438..2313449 100644 --- a/src/main/java/shit/zen/modules/impl/player/AntiTNT.java +++ b/src/main/java/shit/zen/modules/impl/player/AntiTNT.java @@ -113,16 +113,16 @@ extends Module { RenderUtil.drawSolidBox(aABB, poseStack); RenderSystem.setShaderColor(1.0f, 0.0f, 0.0f, 0.8f); RenderUtil.drawOutlineBox(aABB, poseStack); - float f = (float)this.targetTnt.getFuse() / 20.0f; - if (f > 0.0f) { - String string = String.format("%.1fs", new Object[]{Float.valueOf(f)}); - BlockPos blockPos = this.targetTnt.blockPosition(); + float fuseSeconds = (float)this.targetTnt.getFuse() / 20.0f; + if (fuseSeconds > 0.0f) { + String fuseLabel = String.format("%.1fs", new Object[]{Float.valueOf(fuseSeconds)}); + BlockPos tntPos = this.targetTnt.blockPosition(); poseStack.pushPose(); - poseStack.translate((double)blockPos.getX() + 0.5 - vec3.x, (double)blockPos.getY() + 1.1 - vec3.y, (double)blockPos.getZ() + 0.5 - vec3.z); + poseStack.translate((double)tntPos.getX() + 0.5 - vec3.x, (double)tntPos.getY() + 1.1 - vec3.y, (double)tntPos.getZ() + 0.5 - vec3.z); poseStack.mulPose(mc.gameRenderer.getMainCamera().rotation()); poseStack.scale(-0.025f, -0.025f, 0.025f); - float f2 = mc.font.width(string); - mc.font.drawInBatch(string, -f2 / 2.0f, 0.0f, -1, false, poseStack.last().pose(), mc.renderBuffers().bufferSource(), Font.DisplayMode.NORMAL, 0, 0xF000F0); + float textWidth = mc.font.width(fuseLabel); + mc.font.drawInBatch(fuseLabel, -textWidth / 2.0f, 0.0f, -1, false, poseStack.last().pose(), mc.renderBuffers().bufferSource(), Font.DisplayMode.NORMAL, 0, 0xF000F0); poseStack.popPose(); } } @@ -145,26 +145,26 @@ extends Module { } private boolean hasLineOfSight(PrimedTnt primedTnt) { - Vec3 vec3; + Vec3 eyePos; if (mc.player == null || mc.level == null) { return false; } - float f = 8.0f; + float maxRange = 8.0f; if (primedTnt.distanceToSqr(mc.player) > 64.0) { return false; } - Vec3 vec32 = primedTnt.position(); - BlockHitResult blockHitResult = mc.level.clip(new ClipContext(vec32, vec3 = mc.player.getEyePosition(), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); - return blockHitResult.getType() == HitResult.Type.MISS; + Vec3 tntPos = primedTnt.position(); + BlockHitResult hit = mc.level.clip(new ClipContext(tntPos, eyePos = mc.player.getEyePosition(), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); + return hit.getType() == HitResult.Type.MISS; } private boolean isMovingTowardsPlayer(PrimedTnt primedTnt) { - Vec3 vec3 = mc.player.position().subtract(primedTnt.position()).normalize(); - return primedTnt.getDeltaMovement().dot(vec3) > 0.05; + Vec3 toPlayer = mc.player.position().subtract(primedTnt.position()).normalize(); + return primedTnt.getDeltaMovement().dot(toPlayer) > 0.05; } private void collectBlockPositions() { - BlockPos blockPos; + BlockPos sidePos; if (!this.blockPositionQueue.isEmpty()) { return; } @@ -172,18 +172,18 @@ extends Module { mc.player.closeContainer(); mc.setScreen(null); } - BlockPos blockPos2 = mc.player.blockPosition(); + BlockPos playerPos = mc.player.blockPosition(); for (Direction direction : Direction.Plane.HORIZONTAL) { - blockPos = blockPos2.relative(direction); - if (!this.canPlaceAt(blockPos)) continue; - this.blockPositionQueue.add(blockPos); + sidePos = playerPos.relative(direction); + if (!this.canPlaceAt(sidePos)) continue; + this.blockPositionQueue.add(sidePos); } for (Direction direction : Direction.Plane.HORIZONTAL) { - blockPos = blockPos2.above().relative(direction); - if (!this.canPlaceAt(blockPos)) continue; - this.blockPositionQueue.add(blockPos); + sidePos = playerPos.above().relative(direction); + if (!this.canPlaceAt(sidePos)) continue; + this.blockPositionQueue.add(sidePos); } - BlockPos abovePos = blockPos2.above(2); + BlockPos abovePos = playerPos.above(2); if (this.canPlaceAt(abovePos)) { this.blockPositionQueue.add(abovePos); } @@ -197,14 +197,14 @@ extends Module { if (this.blockPositionQueue.isEmpty()) { return; } - BlockPos blockPos = this.blockPositionQueue.get(0); - BlockHitResult blockHitResult = this.getPlacementHitResult(blockPos); - if (blockHitResult == null) { + BlockPos placePos = this.blockPositionQueue.get(0); + BlockHitResult hit = this.getPlacementHitResult(placePos); + if (hit == null) { this.blockPositionQueue.remove(0); return; } - int n = this.findBlockSlot(); - if (n == -1) { + int blockSlot = this.findBlockSlot(); + if (blockSlot == -1) { this.blockPositionQueue.clear(); this.restoreSlot(); return; @@ -212,13 +212,13 @@ extends Module { if (this.savedHotbarSlot == -1) { this.savedHotbarSlot = mc.player.getInventory().selected; } - mc.player.getInventory().selected = n; - targetRotation = RotationUtil.rotationToBlock(blockHitResult.getBlockPos(), 0.0f); - InteractionResult interactionResult = mc.gameMode.useItemOn(mc.player, InteractionHand.MAIN_HAND, blockHitResult); + mc.player.getInventory().selected = blockSlot; + targetRotation = RotationUtil.rotationToBlock(hit.getBlockPos(), 0.0f); + InteractionResult interactionResult = mc.gameMode.useItemOn(mc.player, InteractionHand.MAIN_HAND, hit); if (interactionResult.consumesAction()) { mc.player.swing(InteractionHand.MAIN_HAND); } - this.lastPlacedPos = blockPos; + this.lastPlacedPos = placePos; this.blockPositionQueue.remove(0); this.placementTimer.reset(); if (this.blockPositionQueue.isEmpty()) { @@ -239,10 +239,10 @@ extends Module { } private int findBlockSlot() { - for (int i = 0; i < 9; ++i) { - ItemStack itemStack = mc.player.getInventory().getItem(i); + for (int slot = 0; slot < 9; ++slot) { + ItemStack itemStack = mc.player.getInventory().getItem(slot); if (itemStack.isEmpty() || !(itemStack.getItem() instanceof BlockItem) || !BlockUtil.isPlaceable(itemStack)) continue; - return i; + return slot; } return -1; } @@ -251,40 +251,40 @@ extends Module { return mc.level.getBlockState(blockPos).isSolidRender(mc.level, blockPos); } - private BlockHitResult getPlacementHitResult(BlockPos blockPos) { - BlockPos blockPos2 = blockPos.below(); - if (this.isSolidBlock(blockPos2)) { - return new BlockHitResult(this.getHitVec(blockPos2, Direction.UP), Direction.UP, blockPos2, false); + private BlockHitResult getPlacementHitResult(BlockPos placePos) { + BlockPos belowPos = placePos.below(); + if (this.isSolidBlock(belowPos)) { + return new BlockHitResult(this.getHitVec(belowPos, Direction.UP), Direction.UP, belowPos, false); } for (Direction direction : Direction.Plane.HORIZONTAL) { - BlockPos blockPos3 = blockPos.relative(direction); - if (!this.isSolidBlock(blockPos3)) continue; - Direction direction2 = direction.getOpposite(); - return new BlockHitResult(this.getHitVec(blockPos3, direction2), direction2, blockPos3, false); + BlockPos sidePos = placePos.relative(direction); + if (!this.isSolidBlock(sidePos)) continue; + Direction hitFace = direction.getOpposite(); + return new BlockHitResult(this.getHitVec(sidePos, hitFace), hitFace, sidePos, false); } return null; } private Vec3 getHitVec(BlockPos blockPos, Direction direction) { - double d = (double)blockPos.getX() + 0.5; - double d2 = (double)blockPos.getY() + 0.5; - double d3 = (double)blockPos.getZ() + 0.5; + double hitX = (double)blockPos.getX() + 0.5; + double hitY = (double)blockPos.getY() + 0.5; + double hitZ = (double)blockPos.getZ() + 0.5; if (direction == Direction.UP || direction == Direction.DOWN) { - d += MathUtil.randomDouble(-0.3, 0.3); - d3 += MathUtil.randomDouble(-0.3, 0.3); + hitX += MathUtil.randomDouble(-0.3, 0.3); + hitZ += MathUtil.randomDouble(-0.3, 0.3); } else { - d2 += MathUtil.randomDouble(-0.25, 0.25); + hitY += MathUtil.randomDouble(-0.25, 0.25); } if (direction == Direction.WEST || direction == Direction.EAST) { - d3 += MathUtil.randomDouble(-0.3, 0.3); + hitZ += MathUtil.randomDouble(-0.3, 0.3); } if (direction == Direction.SOUTH || direction == Direction.NORTH) { - d += MathUtil.randomDouble(-0.3, 0.3); + hitX += MathUtil.randomDouble(-0.3, 0.3); } - double d4 = Math.max(blockPos.getX(), Math.min(blockPos.getX() + 1, d)); - double d5 = Math.max(blockPos.getY(), Math.min(blockPos.getY() + 1, d2)); - double d6 = Math.max(blockPos.getZ(), Math.min(blockPos.getZ() + 1, d3)); - return new Vec3(d4, d5, d6); + double clampedX = Math.max(blockPos.getX(), Math.min(blockPos.getX() + 1, hitX)); + double clampedY = Math.max(blockPos.getY(), Math.min(blockPos.getY() + 1, hitY)); + double clampedZ = Math.max(blockPos.getZ(), Math.min(blockPos.getZ() + 1, hitZ)); + return new Vec3(clampedX, clampedY, clampedZ); } static { diff --git a/src/main/java/shit/zen/modules/impl/player/AntiVoid.java b/src/main/java/shit/zen/modules/impl/player/AntiVoid.java index 64a9adc..1e08948 100644 --- a/src/main/java/shit/zen/modules/impl/player/AntiVoid.java +++ b/src/main/java/shit/zen/modules/impl/player/AntiVoid.java @@ -85,9 +85,8 @@ extends Module { return; } if (!this.bufferingPackets && !this.sentFlyPacket && !mc.player.onGround() && mc.player.getDeltaMovement().y < 0.0) { - boolean bl; - boolean bl2 = bl = mc.player.getDeltaMovement().y < 0.1 && this.isVoidBelow() && !PlayerUtil.isSafe(mc.player.getY() + (double)mc.player.getEyeHeight()); - if (bl) { + boolean shouldBuffer = mc.player.getDeltaMovement().y < 0.1 && this.isVoidBelow() && !PlayerUtil.isSafe(mc.player.getY() + (double)mc.player.getEyeHeight()); + if (shouldBuffer) { this.scaffoldWasActive = Scaffold.INSTANCE.isEnabled(); this.bufferingPackets = true; this.bufferedPackets.clear(); @@ -153,11 +152,11 @@ extends Module { } private boolean isVoidBelow() { - BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); - int n = 30; - for (int i = 0; i < n; ++i) { - mutableBlockPos.set(mc.player.getX(), mc.player.getY() - (double)i, mc.player.getZ()); - if (mc.level.getBlockState(mutableBlockPos).getBlock() == Blocks.AIR) continue; + BlockPos.MutableBlockPos cursor = new BlockPos.MutableBlockPos(); + int scanDepth = 30; + for (int dy = 0; dy < scanDepth; ++dy) { + cursor.set(mc.player.getX(), mc.player.getY() - (double)dy, mc.player.getZ()); + if (mc.level.getBlockState(cursor).getBlock() == Blocks.AIR) continue; return false; } return true; diff --git a/src/main/java/shit/zen/modules/impl/player/AutoMLG.java b/src/main/java/shit/zen/modules/impl/player/AutoMLG.java index 4d87bce..48334c4 100644 --- a/src/main/java/shit/zen/modules/impl/player/AutoMLG.java +++ b/src/main/java/shit/zen/modules/impl/player/AutoMLG.java @@ -89,10 +89,10 @@ extends Module { @EventTarget public void onTick(TickEvent tickEvent) { Rotation rotation; - BlockHitResult blockHitResult; - BlockPos blockPos; - int n; - double d; + BlockHitResult hit; + BlockPos bucketPos; + int slot; + double deltaY; if (mc.player == null || mc.level == null) { return; } @@ -102,9 +102,9 @@ extends Module { if (mc.player.onGround() || mc.player.getAbilities().flying || mc.player.isInWaterRainOrBubble() || mc.player.isInLava()) { this.accumulatedFall = 0.0f; } else { - d = mc.player.getY() - this.lastY; - if (d < 0.0) { - this.accumulatedFall -= (float)d; + deltaY = mc.player.getY() - this.lastY; + if (deltaY < 0.0) { + this.accumulatedFall -= (float)deltaY; } } this.lastY = mc.player.getY(); @@ -154,28 +154,28 @@ extends Module { this.placedWaterPos = null; return; } - Rotation rotation2 = RotationUtil.rotationToBlock(this.placedWaterPos, 0.0f); - BlockHitResult blockHitResult2 = this.raycastFluid(rotation2, 4.5); - if (blockHitResult2.getType() == HitResult.Type.MISS || !blockHitResult2.getBlockPos().equals(this.placedWaterPos)) { + Rotation recoveryRotation = RotationUtil.rotationToBlock(this.placedWaterPos, 0.0f); + BlockHitResult recoveryHit = this.raycastFluid(recoveryRotation, 4.5); + if (recoveryHit.getType() == HitResult.Type.MISS || !recoveryHit.getBlockPos().equals(this.placedWaterPos)) { this.recoveryActive = false; this.waterBucketSlot = null; this.placedWaterPos = null; return; } - this.setTargetRotation(rotation2); + this.setTargetRotation(recoveryRotation); this.selectSlot(this.waterBucketSlot); - this.useItem(rotation2); + this.useItem(recoveryRotation); return; } - if (!this.waterPlaced && !this.recoveryActive && this.placedWaterPos == null && this.postPlaceCooldown == 0 && this.postActionCooldown == 0 && this.accumulatedFall <= 0.5f && ItemUtil.findItemInRange(0, 9, Items.WATER_BUCKET) < 0 && (n = ItemUtil.findItemInRange(0, 9, Items.BUCKET)) >= 0 && (blockPos = this.findBucketPos()) != null && (blockHitResult = this.raycastFluid(rotation = RotationUtil.rotationToBlock(blockPos, 0.0f), 4.5)).getType() != HitResult.Type.MISS && blockHitResult.getBlockPos().equals(blockPos)) { + if (!this.waterPlaced && !this.recoveryActive && this.placedWaterPos == null && this.postPlaceCooldown == 0 && this.postActionCooldown == 0 && this.accumulatedFall <= 0.5f && ItemUtil.findItemInRange(0, 9, Items.WATER_BUCKET) < 0 && (slot = ItemUtil.findItemInRange(0, 9, Items.BUCKET)) >= 0 && (bucketPos = this.findBucketPos()) != null && (hit = this.raycastFluid(rotation = RotationUtil.rotationToBlock(bucketPos, 0.0f), 4.5)).getType() != HitResult.Type.MISS && hit.getBlockPos().equals(bucketPos)) { this.setTargetRotation(rotation); - this.selectSlot(n); + this.selectSlot(slot); this.useItem(rotation); this.postActionCooldown = 8; this.postPlaceCooldown = Math.max(this.postPlaceCooldown, 1); return; } - if (this.waterPlaced && !this.readyToPlace && mc.player.getDeltaMovement().y < 0.0 && (d = this.distanceToGround(2.5)) > 0.0 && d <= 1.05) { + if (this.waterPlaced && !this.readyToPlace && mc.player.getDeltaMovement().y < 0.0 && (deltaY = this.distanceToGround(2.5)) > 0.0 && deltaY <= 1.05) { this.readyToPlace = true; } if (this.waterPlaced) { @@ -184,21 +184,21 @@ extends Module { if (this.accumulatedFall < this.triggerDistanceSetting.getValue().floatValue()) { return; } - n = ItemUtil.findItemInRange(0, 9, Items.WATER_BUCKET); - if (n < 0) { + slot = ItemUtil.findItemInRange(0, 9, Items.WATER_BUCKET); + if (slot < 0) { return; } - int n2 = this.ticksUntilGround(); - if (n2 <= this.predictTicksSetting.getValue().intValue()) { + int ticksLeft = this.ticksUntilGround(); + if (ticksLeft <= this.predictTicksSetting.getValue().intValue()) { if (this.solidCheckSetting.getValue() && !this.hasSolidBelow(BlockPos.containing(mc.player.getX(), mc.player.getY(), mc.player.getZ()))) { return; } rotation = new Rotation(mc.player.getYRot(), 90.0f); - blockHitResult = this.raycastSolid(rotation, 5.0); - if (blockHitResult.getType() == HitResult.Type.MISS) { + hit = this.raycastSolid(rotation, 5.0); + if (hit.getType() == HitResult.Type.MISS) { return; } - this.placeWaterBucket(n, true); + this.placeWaterBucket(slot, true); } } @@ -206,16 +206,16 @@ extends Module { if (mc.player.getDeltaMovement().y >= 0.0) { return 999; } - double d = this.distanceToGround(30.0); - if (d == Double.POSITIVE_INFINITY) { + double distance = this.distanceToGround(30.0); + if (distance == Double.POSITIVE_INFINITY) { return 999; } - double d2 = 0.0; - double d3 = mc.player.getDeltaMovement().y; + double simulatedDrop = 0.0; + double simulatedVelocity = mc.player.getDeltaMovement().y; for (int i = 1; i <= 20; ++i) { - d2 += d3; - d3 = (d3 - 0.08) * 0.98; - if (!(Math.abs(d2) >= d)) continue; + simulatedDrop += simulatedVelocity; + simulatedVelocity = (simulatedVelocity - 0.08) * 0.98; + if (!(Math.abs(simulatedDrop) >= distance)) continue; return i; } return 999; @@ -223,8 +223,8 @@ extends Module { private void useItem(Rotation rotation) { if (mc.gameMode != null && mc.player != null) { - float f = mc.player.getXRot(); - float f2 = mc.player.getYRot(); + float originalPitch = mc.player.getXRot(); + float originalYaw = mc.player.getYRot(); if (rotation != null) { mc.player.setXRot(rotation.getPitch()); mc.player.setYRot(rotation.getYaw()); @@ -232,48 +232,48 @@ extends Module { mc.gameMode.useItem(mc.player, InteractionHand.MAIN_HAND); mc.player.swing(InteractionHand.MAIN_HAND); if (rotation != null) { - mc.player.setXRot(f); - mc.player.setYRot(f2); + mc.player.setXRot(originalPitch); + mc.player.setYRot(originalYaw); } } } private BlockPos findBucketPos() { - BlockPos blockPos = BlockPos.containing(mc.player.getX(), mc.player.getY(), mc.player.getZ()); - BlockPos blockPos2 = null; - double d = Double.POSITIVE_INFINITY; - int n = 4; - for (int i = -1; i <= 1; ++i) { - for (int j = -n; j <= n; ++j) { - for (int k = -n; k <= n; ++k) { + BlockPos playerPos = BlockPos.containing(mc.player.getX(), mc.player.getY(), mc.player.getZ()); + BlockPos closestPos = null; + double closestDistSq = Double.POSITIVE_INFINITY; + int radius = 4; + for (int dy = -1; dy <= 1; ++dy) { + for (int dx = -radius; dx <= radius; ++dx) { + for (int dz = -radius; dz <= radius; ++dz) { Rotation rotation; - BlockHitResult blockHitResult; - double d2; - BlockPos blockPos3 = blockPos.offset(j, i, k); - if (!this.isWaterSource(blockPos3) || (d2 = mc.player.position().distanceToSqr((double)blockPos3.getX() + 0.5, (double)blockPos3.getY() + 0.5, (double)blockPos3.getZ() + 0.5)) >= d || (blockHitResult = this.raycastFluid(rotation = RotationUtil.rotationToBlock(blockPos3, 0.0f), 4.5)).getType() == HitResult.Type.MISS || !blockHitResult.getBlockPos().equals(blockPos3)) continue; - blockPos2 = blockPos3; - d = d2; + BlockHitResult hit; + double distSq; + BlockPos candidatePos = playerPos.offset(dx, dy, dz); + if (!this.isWaterSource(candidatePos) || (distSq = mc.player.position().distanceToSqr((double)candidatePos.getX() + 0.5, (double)candidatePos.getY() + 0.5, (double)candidatePos.getZ() + 0.5)) >= closestDistSq || (hit = this.raycastFluid(rotation = RotationUtil.rotationToBlock(candidatePos, 0.0f), 4.5)).getType() == HitResult.Type.MISS || !hit.getBlockPos().equals(candidatePos)) continue; + closestPos = candidatePos; + closestDistSq = distSq; } } } - return blockPos2; + return closestPos; } private void setTargetRotation(Rotation rotation) { this.targetRotation = rotation; } - private void selectSlot(int n) { + private void selectSlot(int slot) { this.slotToRestore = mc.player.getInventory().selected; - mc.player.getInventory().selected = n; + mc.player.getInventory().selected = slot; } - private void placeWaterBucket(int n, boolean bl) { + private void placeWaterBucket(int slot, boolean markPlaced) { Rotation rotation = new Rotation(mc.player.getYRot(), 90.0f); this.setTargetRotation(rotation); - this.selectSlot(n); + this.selectSlot(slot); this.useItem(rotation); - if (bl) { + if (markPlaced) { this.waterPlaced = true; } this.recoveryActive = this.recoverySetting.getValue(); @@ -284,25 +284,25 @@ extends Module { } private BlockPos getPlacementBlockPos(Rotation rotation) { - BlockHitResult blockHitResult = this.raycastSolid(rotation, 4.5); - if (blockHitResult.getType() == HitResult.Type.MISS) { + BlockHitResult hit = this.raycastSolid(rotation, 4.5); + if (hit.getType() == HitResult.Type.MISS) { return null; } - return blockHitResult.getBlockPos().relative(blockHitResult.getDirection()); + return hit.getBlockPos().relative(hit.getDirection()); } - private BlockHitResult raycastSolid(Rotation rotation, double d) { - Vec3 vec3 = mc.player.getEyePosition(1.0f); - Vec3 vec32 = Vec3.directionFromRotation(rotation.getPitch(), rotation.getYaw()); - Vec3 vec33 = vec3.add(vec32.scale(d)); - return mc.level.clip(new ClipContext(vec3, vec33, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); + private BlockHitResult raycastSolid(Rotation rotation, double range) { + Vec3 eyePos = mc.player.getEyePosition(1.0f); + Vec3 direction = Vec3.directionFromRotation(rotation.getPitch(), rotation.getYaw()); + Vec3 endPos = eyePos.add(direction.scale(range)); + return mc.level.clip(new ClipContext(eyePos, endPos, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); } - private BlockHitResult raycastFluid(Rotation rotation, double d) { - Vec3 vec3 = mc.player.getEyePosition(1.0f); - Vec3 vec32 = Vec3.directionFromRotation(rotation.getPitch(), rotation.getYaw()); - Vec3 vec33 = vec3.add(vec32.scale(d)); - return mc.level.clip(new ClipContext(vec3, vec33, ClipContext.Block.OUTLINE, ClipContext.Fluid.SOURCE_ONLY, mc.player)); + private BlockHitResult raycastFluid(Rotation rotation, double range) { + Vec3 eyePos = mc.player.getEyePosition(1.0f); + Vec3 direction = Vec3.directionFromRotation(rotation.getPitch(), rotation.getYaw()); + Vec3 endPos = eyePos.add(direction.scale(range)); + return mc.level.clip(new ClipContext(eyePos, endPos, ClipContext.Block.OUTLINE, ClipContext.Fluid.SOURCE_ONLY, mc.player)); } private boolean isWaterSource(BlockPos blockPos) { @@ -316,18 +316,18 @@ extends Module { private boolean isSolidNonMenu(BlockPos blockPos) { BlockState blockState = mc.level.getBlockState(blockPos); - boolean bl = !blockState.getCollisionShape(mc.level, blockPos).isEmpty(); - boolean bl2 = blockState.getMenuProvider(mc.level, blockPos) == null; - return bl && bl2; + boolean hasCollision = !blockState.getCollisionShape(mc.level, blockPos).isEmpty(); + boolean noMenu = blockState.getMenuProvider(mc.level, blockPos) == null; + return hasCollision && noMenu; } - private double distanceToGround(double d) { - Vec3 vec3; - Vec3 vec32 = new Vec3(mc.player.getX(), mc.player.getBoundingBox().minY, mc.player.getZ()); - BlockHitResult blockHitResult = mc.level.clip(new ClipContext(vec32, vec3 = vec32.add(0.0, -d, 0.0), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); - if (blockHitResult.getType() == HitResult.Type.MISS) { + private double distanceToGround(double maxDist) { + Vec3 endPos; + Vec3 startPos = new Vec3(mc.player.getX(), mc.player.getBoundingBox().minY, mc.player.getZ()); + BlockHitResult hit = mc.level.clip(new ClipContext(startPos, endPos = startPos.add(0.0, -maxDist, 0.0), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); + if (hit.getType() == HitResult.Type.MISS) { return Double.POSITIVE_INFINITY; } - return vec32.y - blockHitResult.getLocation().y; + return startPos.y - hit.getLocation().y; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/modules/impl/player/ChestStealer.java b/src/main/java/shit/zen/modules/impl/player/ChestStealer.java index f306968..a064ea6 100644 --- a/src/main/java/shit/zen/modules/impl/player/ChestStealer.java +++ b/src/main/java/shit/zen/modules/impl/player/ChestStealer.java @@ -123,7 +123,7 @@ extends Module { return; } Screen screen = mc.screen; - AbstractContainerMenu abstractContainerMenu = mc.player.containerMenu; + AbstractContainerMenu containerMenu = mc.player.containerMenu; this.countBlocks(); if (screen instanceof ContainerScreen containerScreen) { if (screen != this.lastScreen) { @@ -137,16 +137,16 @@ extends Module { if (this.openDelayTicks < this.openDelaySetting.getValue().intValue()) { return; } - String string = containerScreen.getTitle().getString(); - String string2 = Component.translatable("container.chest").getString(); - String string3 = Component.translatable("container.chestDouble").getString(); - String string4 = Component.translatable("container.enderchest").getString(); + String title = containerScreen.getTitle().getString(); + String chestTitle = Component.translatable("container.chest").getString(); + String doubleChestTitle = Component.translatable("container.chestDouble").getString(); + String enderChestTitle = Component.translatable("container.enderchest").getString(); ChestMenu chestMenu = containerScreen.getMenu(); - if (this.chestSetting.getValue() && (string.equals(string2) || string.equals(string3) || string.equals("Chest"))) { + if (this.chestSetting.getValue() && (title.equals(chestTitle) || title.equals(doubleChestTitle) || title.equals("Chest"))) { if (this.shouldCloseChest(chestMenu)) { this.stealFromChest(chestMenu); } - } else if (this.enderChestSetting.getValue() && string.equals(string4) && this.shouldCloseChest(chestMenu)) { + } else if (this.enderChestSetting.getValue() && title.equals(enderChestTitle) && this.shouldCloseChest(chestMenu)) { this.stealFromChest(chestMenu); } } @@ -156,12 +156,12 @@ extends Module { this.stealTargetQueue.clear(); this.stealIndex = 0; } - if (abstractContainerMenu instanceof FurnaceMenu furnaceMenu) { + if (containerMenu instanceof FurnaceMenu furnaceMenu) { if (this.furnaceSetting.getValue()) { this.stealFromFurnace(furnaceMenu); } } - if (abstractContainerMenu instanceof BrewingStandMenu brewingMenu) { + if (containerMenu instanceof BrewingStandMenu brewingMenu) { if (this.brewingStandSetting.getValue()) { this.stealFromBrewing(brewingMenu); } @@ -193,9 +193,9 @@ extends Module { this.stealIndex = 0; } if (this.stealIndex < this.stealTargetQueue.size()) { - ChestStealer.StealTarget chestStealer$StealTarget = this.stealTargetQueue.get(this.stealIndex); - if (!chestMenu.getSlot(chestStealer$StealTarget.slotIndex).getItem().isEmpty()) { - this.schedulePendingClick(chestMenu, chestStealer$StealTarget.slotIndex); + ChestStealer.StealTarget target = this.stealTargetQueue.get(this.stealIndex); + if (!chestMenu.getSlot(target.slotIndex).getItem().isEmpty()) { + this.schedulePendingClick(chestMenu, target.slotIndex); ++this.stealIndex; } else { ++this.stealIndex; @@ -206,39 +206,39 @@ extends Module { } private void buildStealQueue(ChestMenu chestMenu) { - ArrayList arrayList = new ArrayList<>(); - for (int i = 0; i < chestMenu.getRowCount() * 9; ++i) { - ItemStack itemStack = chestMenu.getSlot(i).getItem(); + ArrayList candidates = new ArrayList<>(); + for (int slot = 0; slot < chestMenu.getRowCount() * 9; ++slot) { + ItemStack itemStack = chestMenu.getSlot(slot).getItem(); if (itemStack.isEmpty() || !this.shouldStealItem(itemStack)) continue; - int n = this.getItemPriority(itemStack); - double d = this.getItemScore(itemStack); - arrayList.add(new ChestStealer.StealTarget(i, itemStack, n, d)); + int priority = this.getItemPriority(itemStack); + double score = this.getItemScore(itemStack); + candidates.add(new ChestStealer.StealTarget(slot, itemStack, priority, score)); } - Map> map = this.categorizeItems(arrayList); + Map> categoryMap = this.categorizeItems(candidates); this.stealTargetQueue.clear(); List categories = Arrays.asList("god", "helmet", "chestplate", "leggings", "boots", "sword", "bow", "crossbow", "golden_apple", "pickaxe", "axe", "shovel", "special", "utility", "other"); - for (String string : categories) { - if (!map.containsKey(string)) continue; - List list = map.get(string); - boolean bl = string.equals("god") || string.equals("helmet") || string.equals("chestplate") || string.equals("leggings") || string.equals("boots") || string.equals("sword") || string.equals("bow") || string.equals("crossbow") || string.equals("pickaxe") || string.equals("axe") || string.equals("shovel"); - if (this.onlyBestSetting.getValue() && bl) { - ChestStealer.StealTarget best = list.stream().max(Comparator.comparingDouble(t -> t.score)).orElse(null); + for (String category : categories) { + if (!categoryMap.containsKey(category)) continue; + List categoryItems = categoryMap.get(category); + boolean isBestOnlyCategory = category.equals("god") || category.equals("helmet") || category.equals("chestplate") || category.equals("leggings") || category.equals("boots") || category.equals("sword") || category.equals("bow") || category.equals("crossbow") || category.equals("pickaxe") || category.equals("axe") || category.equals("shovel"); + if (this.onlyBestSetting.getValue() && isBestOnlyCategory) { + ChestStealer.StealTarget best = categoryItems.stream().max(Comparator.comparingDouble(t -> t.score)).orElse(null); if (best == null) continue; this.stealTargetQueue.add(best); continue; } - list.sort((a, b) -> Double.compare(b.score, a.score)); - this.stealTargetQueue.addAll(list); + categoryItems.sort((a, b) -> Double.compare(b.score, a.score)); + this.stealTargetQueue.addAll(categoryItems); } } - private Map> categorizeItems(List list) { - HashMap> hashMap = new HashMap<>(); - for (ChestStealer.StealTarget chestStealer$StealTarget : list) { - String string2 = this.getItemCategory(chestStealer$StealTarget.itemStack); - hashMap.computeIfAbsent(string2, string -> new ArrayList<>()).add(chestStealer$StealTarget); + private Map> categorizeItems(List targets) { + HashMap> categoryMap = new HashMap<>(); + for (ChestStealer.StealTarget target : targets) { + String category = this.getItemCategory(target.itemStack); + categoryMap.computeIfAbsent(category, key -> new ArrayList<>()).add(target); } - return hashMap; + return categoryMap; } private String getItemCategory(ItemStack itemStack) { @@ -410,14 +410,14 @@ extends Module { } private void stealRandomMode(ChestMenu chestMenu) { - List list = this.getStealableChestSlots(chestMenu); - if (this.randomClickSetting.getValue() && !list.isEmpty() && this.accessCount > 1) { - int n = list.get(this.random.nextInt(list.size())); - this.schedulePendingClick(chestMenu, n); + List stealableSlots = this.getStealableChestSlots(chestMenu); + if (this.randomClickSetting.getValue() && !stealableSlots.isEmpty() && this.accessCount > 1) { + int randomSlot = stealableSlots.get(this.random.nextInt(stealableSlots.size())); + this.schedulePendingClick(chestMenu, randomSlot); } else { - for (int i = 0; i < chestMenu.getRowCount() * 9; ++i) { - ItemStack itemStack = chestMenu.getSlot(i).getItem(); - if (itemStack.isEmpty() || this.accessCount <= 1 || !this.tryStealSlot(chestMenu, i)) continue; + for (int slot = 0; slot < chestMenu.getRowCount() * 9; ++slot) { + ItemStack itemStack = chestMenu.getSlot(slot).getItem(); + if (itemStack.isEmpty() || this.accessCount <= 1 || !this.tryStealSlot(chestMenu, slot)) continue; return; } } @@ -434,15 +434,15 @@ extends Module { mc.player.closeContainer(); return; } - List list = this.getStealableContainerSlots(container); - if (this.randomClickSetting.getValue() && !list.isEmpty() && this.accessCount > 1) { - int n = list.get(this.random.nextInt(list.size())); - this.schedulePendingClick(furnaceMenu, n); + List stealableSlots = this.getStealableContainerSlots(container); + if (this.randomClickSetting.getValue() && !stealableSlots.isEmpty() && this.accessCount > 1) { + int randomSlot = stealableSlots.get(this.random.nextInt(stealableSlots.size())); + this.schedulePendingClick(furnaceMenu, randomSlot); } else { - for (int i = 0; i < container.getContainerSize(); ++i) { - ItemStack itemStack = container.getItem(i); + for (int slot = 0; slot < container.getContainerSize(); ++slot) { + ItemStack itemStack = container.getItem(slot); if (itemStack.isEmpty() || this.accessCount <= 1 || !this.shouldStealItem(itemStack)) continue; - this.schedulePendingClick(furnaceMenu, i); + this.schedulePendingClick(furnaceMenu, slot); return; } } @@ -461,54 +461,54 @@ extends Module { mc.player.closeContainer(); return; } - List list = this.getStealableContainerSlots(container); - if (this.randomClickSetting.getValue() && !list.isEmpty() && this.accessCount > 1) { - int n = list.get(this.random.nextInt(list.size())); - this.schedulePendingClick(brewingStandMenu, n); + List stealableSlots = this.getStealableContainerSlots(container); + if (this.randomClickSetting.getValue() && !stealableSlots.isEmpty() && this.accessCount > 1) { + int randomSlot = stealableSlots.get(this.random.nextInt(stealableSlots.size())); + this.schedulePendingClick(brewingStandMenu, randomSlot); } else { - for (int i = 0; i < container.getContainerSize(); ++i) { - ItemStack itemStack = container.getItem(i); + for (int slot = 0; slot < container.getContainerSize(); ++slot) { + ItemStack itemStack = container.getItem(slot); if (itemStack.isEmpty() || this.accessCount <= 1 || !this.shouldStealItem(itemStack)) continue; - this.schedulePendingClick(brewingStandMenu, i); + this.schedulePendingClick(brewingStandMenu, slot); return; } } } private List getStealableChestSlots(ChestMenu chestMenu) { - ArrayList arrayList = new ArrayList<>(); - for (int i = 0; i < chestMenu.getRowCount() * 9; ++i) { - ItemStack itemStack = chestMenu.getSlot(i).getItem(); + ArrayList stealableSlots = new ArrayList<>(); + for (int slot = 0; slot < chestMenu.getRowCount() * 9; ++slot) { + ItemStack itemStack = chestMenu.getSlot(slot).getItem(); if (itemStack.isEmpty() || !ChestStealer.isWorthStealing(itemStack) && !this.pickTrashSetting.getValue() || !this.shouldStealItem(itemStack)) continue; - arrayList.add(i); + stealableSlots.add(slot); } - return arrayList; + return stealableSlots; } private List getStealableContainerSlots(Container container) { - ArrayList arrayList = new ArrayList<>(); - for (int i = 0; i < container.getContainerSize(); ++i) { - ItemStack itemStack = container.getItem(i); + ArrayList stealableSlots = new ArrayList<>(); + for (int slot = 0; slot < container.getContainerSize(); ++slot) { + ItemStack itemStack = container.getItem(slot); if (itemStack.isEmpty() || !this.shouldStealItem(itemStack)) continue; - arrayList.add(i); + stealableSlots.add(slot); } - return arrayList; + return stealableSlots; } - private Container getFurnaceContainer(AbstractFurnaceMenu abstractFurnaceMenu) throws Exception { - Field[] fieldArray; - for (Field field : fieldArray = AbstractFurnaceMenu.class.getDeclaredFields()) { + private Container getFurnaceContainer(AbstractFurnaceMenu furnaceMenu) throws Exception { + Field[] fields; + for (Field field : fields = AbstractFurnaceMenu.class.getDeclaredFields()) { if (!Container.class.isAssignableFrom(field.getType())) continue; field.setAccessible(true); - return (Container)field.get(abstractFurnaceMenu); + return (Container)field.get(furnaceMenu); } return null; } - private void schedulePendingClick(AbstractContainerMenu abstractContainerMenu, int n) { + private void schedulePendingClick(AbstractContainerMenu menu, int slot) { if (!this.hasPendingClick) { - this.pendingMenu = abstractContainerMenu; - this.pendingSlot = n; + this.pendingMenu = menu; + this.pendingSlot = slot; this.hasPendingClick = true; this.ticksSinceMenu = 0; } @@ -524,10 +524,10 @@ extends Module { } } - private boolean tryStealSlot(ChestMenu chestMenu, int n) { - ItemStack itemStack = chestMenu.getSlot(n).getItem(); + private boolean tryStealSlot(ChestMenu chestMenu, int slot) { + ItemStack itemStack = chestMenu.getSlot(slot).getItem(); if ((ChestStealer.isWorthStealing(itemStack) || this.pickTrashSetting.getValue()) && this.shouldStealItem(itemStack)) { - this.schedulePendingClick(chestMenu, n); + this.schedulePendingClick(chestMenu, slot); return true; } return false; @@ -547,22 +547,22 @@ extends Module { private void countBlocks() { this.totalBlockCount = 0; - for (int i = 0; i < mc.player.getInventory().getContainerSize(); ++i) { - ItemStack itemStack = mc.player.getInventory().getItem(i); + for (int slot = 0; slot < mc.player.getInventory().getContainerSize(); ++slot) { + ItemStack itemStack = mc.player.getInventory().getItem(slot); if (itemStack.isEmpty() || !(itemStack.getItem() instanceof BlockItem)) continue; this.totalBlockCount += itemStack.getCount(); } } private boolean shouldStealItem(ItemStack itemStack) { - int n; + int count; Item item = itemStack.getItem(); - if (item instanceof FishingRodItem && (n = ItemUtil.countItem(Items.FISHING_ROD)) > 0) { + if (item instanceof FishingRodItem && (count = ItemUtil.countItem(Items.FISHING_ROD)) > 0) { return false; } if (item instanceof BlockItem && item != Items.COBWEB) { - n = InventoryManager.getMaxBlockSize(); - if (this.totalBlockCount + itemStack.getCount() > n) { + count = InventoryManager.getMaxBlockSize(); + if (this.totalBlockCount + itemStack.getCount() > count) { return false; } } @@ -594,62 +594,62 @@ extends Module { private boolean isBetterThanCurrent(ItemStack itemStack) { if (itemStack.getItem() instanceof SwordItem) { - float f; - float f2 = ItemUtil.getSwordDamage(itemStack); - return f2 > (f = ItemUtil.getBestSwordDamage()); + float candidateDamage = ItemUtil.getSwordDamage(itemStack); + float bestDamage = ItemUtil.getBestSwordDamage(); + return candidateDamage > bestDamage; } if (itemStack.getItem() instanceof DiggerItem) { if (itemStack.getItem() instanceof PickaxeItem) { - float f; - float f3 = ItemUtil.getDigSpeed(itemStack); - return f3 > (f = ItemUtil.getBestPickaxeScore()); + float candidateSpeed = ItemUtil.getDigSpeed(itemStack); + float bestSpeed = ItemUtil.getBestPickaxeScore(); + return candidateSpeed > bestSpeed; } if (itemStack.getItem() instanceof AxeItem) { - float f; if (ItemUtil.isLegitAxe(itemStack)) { - float f4 = ItemUtil.getAxeDamage(itemStack); - ItemStack itemStack2 = ItemUtil.getBestSharpAxe(); - float f5 = itemStack2 != null ? ItemUtil.getAxeDamage(itemStack2) : 0.0f; - return f4 > f5; + float candidateDamage = ItemUtil.getAxeDamage(itemStack); + ItemStack bestAxeStack = ItemUtil.getBestSharpAxe(); + float bestDamage = bestAxeStack != null ? ItemUtil.getAxeDamage(bestAxeStack) : 0.0f; + return candidateDamage > bestDamage; } - float f6 = ItemUtil.getDigSpeed(itemStack); - return f6 > (f = ItemUtil.getBestAxeScore()); + float candidateSpeed = ItemUtil.getDigSpeed(itemStack); + float bestSpeed = ItemUtil.getBestAxeScore(); + return candidateSpeed > bestSpeed; } if (itemStack.getItem() instanceof ShovelItem) { - float f; - float f7 = ItemUtil.getDigSpeed(itemStack); - return f7 > (f = ItemUtil.getBestShovelScore()); + float candidateSpeed = ItemUtil.getDigSpeed(itemStack); + float bestSpeed = ItemUtil.getBestShovelScore(); + return candidateSpeed > bestSpeed; } } else { Item item = itemStack.getItem(); if (item instanceof ArmorItem armorItem) { - float f; - float f8 = ItemUtil.getArmorScore(itemStack); - return f8 > (f = ItemUtil.getEquippedArmorScore(armorItem.getEquipmentSlot())) + 0.1f; + float candidateScore = ItemUtil.getArmorScore(itemStack); + float equippedScore = ItemUtil.getEquippedArmorScore(armorItem.getEquipmentSlot()); + return candidateScore > equippedScore + 0.1f; } if (itemStack.getItem() instanceof BowItem) { if (ItemUtil.isGoodBow(itemStack)) { - float f; - float f9 = ItemUtil.getBowScore(itemStack); - return f9 > (f = ItemUtil.getBestBowScore()); + float candidateScore = ItemUtil.getBowScore(itemStack); + float bestScore = ItemUtil.getBestBowScore(); + return candidateScore > bestScore; } if (ItemUtil.isGoodBowAlt(itemStack)) { - float f; - float f10 = ItemUtil.getBowScoreAlt(itemStack); - return f10 > (f = ItemUtil.getBestBowScoreAlt()); + float candidateScore = ItemUtil.getBowScoreAlt(itemStack); + float bestScore = ItemUtil.getBestBowScoreAlt(); + return candidateScore > bestScore; } } else if (itemStack.getItem() instanceof CrossbowItem) { - float f; - float f11 = ItemUtil.getCrossbowScore(itemStack); - return f11 > (f = ItemUtil.getBestCrossbowScore()); + float candidateScore = ItemUtil.getCrossbowScore(itemStack); + float bestScore = ItemUtil.getBestCrossbowScore(); + return candidateScore > bestScore; } } return true; } private boolean isChestDone(ChestMenu chestMenu) { - for (int i = 0; i < chestMenu.getRowCount() * 9; ++i) { - ItemStack itemStack = chestMenu.getSlot(i).getItem(); + for (int slot = 0; slot < chestMenu.getRowCount() * 9; ++slot) { + ItemStack itemStack = chestMenu.getSlot(slot).getItem(); if (itemStack.isEmpty() || !ChestStealer.isWorthStealing(itemStack) && !this.pickTrashSetting.getValue() || !this.shouldStealItem(itemStack)) continue; return false; } @@ -657,8 +657,8 @@ extends Module { } private boolean isChestComplete(ChestMenu chestMenu) { - for (int i = 0; i < chestMenu.getRowCount() * 9; ++i) { - ItemStack itemStack = chestMenu.getSlot(i).getItem(); + for (int slot = 0; slot < chestMenu.getRowCount() * 9; ++slot) { + ItemStack itemStack = chestMenu.getSlot(slot).getItem(); if (itemStack.isEmpty() || !ChestStealer.isWorthStealing(itemStack) && !this.pickTrashSetting.getValue() || !this.shouldStealItem(itemStack)) continue; return false; } @@ -671,8 +671,8 @@ extends Module { if (container == null) { return false; } - for (int i = 0; i < container.getContainerSize(); ++i) { - ItemStack itemStack = container.getItem(i); + for (int slot = 0; slot < container.getContainerSize(); ++slot) { + ItemStack itemStack = container.getItem(slot); if (itemStack.isEmpty() || !this.shouldStealItem(itemStack)) continue; return false; } @@ -688,8 +688,8 @@ extends Module { if (container == null) { return true; } - for (int i = 0; i < container.getContainerSize(); ++i) { - ItemStack itemStack = container.getItem(i); + for (int slot = 0; slot < container.getContainerSize(); ++slot) { + ItemStack itemStack = container.getItem(slot); if (itemStack.isEmpty() || !this.shouldStealItem(itemStack)) continue; return false; } @@ -705,44 +705,44 @@ extends Module { } Item item = itemStack.getItem(); if (item instanceof ArmorItem armorItem) { - float f; - float f2 = ItemUtil.getArmorScore(itemStack); - return !(f2 <= (f = ItemUtil.getBestArmorScore(armorItem.getEquipmentSlot()))); + float candidateScore = ItemUtil.getArmorScore(itemStack); + float bestScore = ItemUtil.getBestArmorScore(armorItem.getEquipmentSlot()); + return !(candidateScore <= bestScore); } if (itemStack.getItem() instanceof SwordItem) { - float f; - float f3 = ItemUtil.getSwordDamage(itemStack); - return !(f3 <= (f = ItemUtil.getBestSwordDamage())); + float candidateDamage = ItemUtil.getSwordDamage(itemStack); + float bestDamage = ItemUtil.getBestSwordDamage(); + return !(candidateDamage <= bestDamage); } if (itemStack.getItem() instanceof PickaxeItem) { - float f; - float f4 = ItemUtil.getDigSpeed(itemStack); - return !(f4 <= (f = ItemUtil.getBestPickaxeScore())); + float candidateSpeed = ItemUtil.getDigSpeed(itemStack); + float bestSpeed = ItemUtil.getBestPickaxeScore(); + return !(candidateSpeed <= bestSpeed); } if (itemStack.getItem() instanceof AxeItem) { - float f; - float f5 = ItemUtil.getDigSpeed(itemStack); - return !(f5 <= (f = ItemUtil.getBestAxeScore())); + float candidateSpeed = ItemUtil.getDigSpeed(itemStack); + float bestSpeed = ItemUtil.getBestAxeScore(); + return !(candidateSpeed <= bestSpeed); } if (itemStack.getItem() instanceof ShovelItem) { - float f; - float f6 = ItemUtil.getDigSpeed(itemStack); - return !(f6 <= (f = ItemUtil.getBestShovelScore())); + float candidateSpeed = ItemUtil.getDigSpeed(itemStack); + float bestSpeed = ItemUtil.getBestShovelScore(); + return !(candidateSpeed <= bestSpeed); } if (itemStack.getItem() instanceof CrossbowItem) { - float f; - float f7 = ItemUtil.getCrossbowScore(itemStack); - return !(f7 <= (f = ItemUtil.getBestCrossbowScore())); + float candidateScore = ItemUtil.getCrossbowScore(itemStack); + float bestScore = ItemUtil.getBestCrossbowScore(); + return !(candidateScore <= bestScore); } if (itemStack.getItem() instanceof BowItem && ItemUtil.isGoodBow(itemStack)) { - float f; - float f8 = ItemUtil.getBowScore(itemStack); - return !(f8 <= (f = ItemUtil.getBestBowScore())); + float candidateScore = ItemUtil.getBowScore(itemStack); + float bestScore = ItemUtil.getBestBowScore(); + return !(candidateScore <= bestScore); } if (itemStack.getItem() instanceof BowItem && ItemUtil.isGoodBowAlt(itemStack)) { - float f; - float f9 = ItemUtil.getBowScoreAlt(itemStack); - return !(f9 <= (f = ItemUtil.getBestBowScoreAlt())); + float candidateScore = ItemUtil.getBowScoreAlt(itemStack); + float bestScore = ItemUtil.getBestBowScoreAlt(); + return !(candidateScore <= bestScore); } if (itemStack.getItem() == Items.GOLDEN_APPLE || itemStack.getItem() == Items.ENCHANTED_GOLDEN_APPLE) { return true; diff --git a/src/main/java/shit/zen/modules/impl/player/GhostHand.java b/src/main/java/shit/zen/modules/impl/player/GhostHand.java index f961d73..89128b6 100644 --- a/src/main/java/shit/zen/modules/impl/player/GhostHand.java +++ b/src/main/java/shit/zen/modules/impl/player/GhostHand.java @@ -40,25 +40,25 @@ extends Module { if (mc.player == null || mc.level == null) { return false; } - Vec3 vec3 = mc.player.getEyePosition(1.0f); - Vec3 vec32 = mc.player.getViewVector(1.0f); - Vec3 vec33 = vec3.add(vec32.scale(4.5)); - ChestBlockEntity chestBlockEntity = null; - BlockHitResult blockHitResult = null; - double d = Double.MAX_VALUE; - ArrayList arrayList = ChunkUtil.getLoadedBlockEntities().collect(Collectors.toCollection(ArrayList::new)); - for (BlockEntity blockEntity : arrayList) { - double d2; - Optional optional; - ChestBlockEntity chestBlockEntity2; - AABB aABB; - if (!(blockEntity instanceof ChestBlockEntity) || (aABB = this.getChestAABB(chestBlockEntity2 = (ChestBlockEntity)blockEntity)) == null || !(optional = aABB.clip(vec3, vec33)).isPresent() || !((d2 = optional.get().distanceTo(vec3)) < d)) continue; - d = d2; - chestBlockEntity = chestBlockEntity2; - blockHitResult = new BlockHitResult(optional.get(), Direction.UP, chestBlockEntity2.getBlockPos(), false); + Vec3 eyePos = mc.player.getEyePosition(1.0f); + Vec3 lookVec = mc.player.getViewVector(1.0f); + Vec3 endPos = eyePos.add(lookVec.scale(4.5)); + ChestBlockEntity targetChest = null; + BlockHitResult chestHit = null; + double closestDist = Double.MAX_VALUE; + ArrayList blockEntities = ChunkUtil.getLoadedBlockEntities().collect(Collectors.toCollection(ArrayList::new)); + for (BlockEntity blockEntity : blockEntities) { + double dist; + Optional clipResult; + ChestBlockEntity candidateChest; + AABB chestBox; + if (!(blockEntity instanceof ChestBlockEntity) || (chestBox = this.getChestAABB(candidateChest = (ChestBlockEntity)blockEntity)) == null || !(clipResult = chestBox.clip(eyePos, endPos)).isPresent() || !((dist = clipResult.get().distanceTo(eyePos)) < closestDist)) continue; + closestDist = dist; + targetChest = candidateChest; + chestHit = new BlockHitResult(clipResult.get(), Direction.UP, candidateChest.getBlockPos(), false); } - if (chestBlockEntity != null && blockHitResult != null) { - mc.gameMode.useItemOn(mc.player, InteractionHand.MAIN_HAND, blockHitResult); + if (targetChest != null && chestHit != null) { + mc.gameMode.useItemOn(mc.player, InteractionHand.MAIN_HAND, chestHit); mc.player.swing(InteractionHand.MAIN_HAND); return true; } @@ -66,7 +66,7 @@ extends Module { } private AABB getChestAABB(ChestBlockEntity chestBlockEntity) { - BlockPos blockPos; + BlockPos pairedPos; BlockState blockState = chestBlockEntity.getBlockState(); if (!blockState.hasProperty((Property)ChestBlock.TYPE)) { return null; @@ -75,13 +75,13 @@ extends Module { if (chestType == ChestType.LEFT) { return null; } - BlockPos blockPos2 = chestBlockEntity.getBlockPos(); - AABB aABB = BlockUtil.getBoundingBox(blockPos2); - if (chestType != ChestType.SINGLE && BlockUtil.canBeClicked(blockPos = blockPos2.relative(ChestBlock.getConnectedDirection(blockState)))) { - AABB aABB2 = BlockUtil.getBoundingBox(blockPos); - aABB = aABB.minmax(aABB2); + BlockPos chestPos = chestBlockEntity.getBlockPos(); + AABB chestBox = BlockUtil.getBoundingBox(chestPos); + if (chestType != ChestType.SINGLE && BlockUtil.canBeClicked(pairedPos = chestPos.relative(ChestBlock.getConnectedDirection(blockState)))) { + AABB pairedBox = BlockUtil.getBoundingBox(pairedPos); + chestBox = chestBox.minmax(pairedBox); } - return aABB; + return chestBox; } static { diff --git a/src/main/java/shit/zen/modules/impl/player/InventoryManager.java b/src/main/java/shit/zen/modules/impl/player/InventoryManager.java index 6ca45e6..e46e7d8 100644 --- a/src/main/java/shit/zen/modules/impl/player/InventoryManager.java +++ b/src/main/java/shit/zen/modules/impl/player/InventoryManager.java @@ -151,15 +151,14 @@ extends Module { } } else { Screen screen; - AbstractContainerScreen abstractContainerScreen; - ServerboundPlayerCommandPacket serverboundPlayerCommandPacket; - boolean bl; - boolean bl2 = bl = !this.pendingPackets.isEmpty(); + AbstractContainerScreen containerScreen; + ServerboundPlayerCommandPacket commandPacket; + boolean hasPendingPackets = !this.pendingPackets.isEmpty(); if (packet instanceof ServerboundPlayerCommandPacket) { - serverboundPlayerCommandPacket = (ServerboundPlayerCommandPacket)packet; - if (serverboundPlayerCommandPacket.getAction() == ServerboundPlayerCommandPacket.Action.START_SPRINTING) { + commandPacket = (ServerboundPlayerCommandPacket)packet; + if (commandPacket.getAction() == ServerboundPlayerCommandPacket.Action.START_SPRINTING) { this.wasSprinting = true; - } else if (serverboundPlayerCommandPacket.getAction() == ServerboundPlayerCommandPacket.Action.STOP_SPRINTING) { + } else if (commandPacket.getAction() == ServerboundPlayerCommandPacket.Action.STOP_SPRINTING) { this.wasSprinting = false; } } @@ -172,14 +171,13 @@ extends Module { } } if ((screen = mc.screen) instanceof AbstractContainerScreen) { - abstractContainerScreen = (AbstractContainerScreen)screen; - if (abstractContainerScreen.getMenu().containerId != mc.player.inventoryMenu.containerId) { + containerScreen = (AbstractContainerScreen)screen; + if (containerScreen.getMenu().containerId != mc.player.inventoryMenu.containerId) { return; } } - boolean bl3 = false; - boolean bl4 = bl3; - if (bl4) return; + boolean shouldSkip = false; + if (shouldSkip) return; if (!(packet instanceof ServerboundContainerClickPacket)) { if (!(packet instanceof ServerboundContainerClosePacket)) return; } @@ -191,9 +189,8 @@ extends Module { @EventTarget public void onMotion(MotionEvent motionEvent) { if (motionEvent.isPost() && !this.inventoryOnlySetting.getValue() && GuiMove.INSTANCE.isEnabled() && mc.player != null) { - boolean bl; - boolean bl2 = bl = !this.pendingPackets.isEmpty(); - if (bl) { + boolean hasPendingPackets = !this.pendingPackets.isEmpty(); + if (hasPendingPackets) { if (this.wasSprinting || mc.player.isSprinting()) { this.skipNextTick = true; this.sprintDelayTicks = 2 + this.sprintDelayTicksSetting.getValue().intValue(); @@ -207,14 +204,14 @@ extends Module { PacketUtil.sendQueued((Packet) this.pendingPackets.poll()); } PacketUtil.sendQueued(new ServerboundContainerClosePacket(mc.player.inventoryMenu.containerId)); - boolean bl3 = mc.options.keyJump.isDown(); - boolean bl4 = mc.options.keyShift.isDown(); + boolean jumpDown = mc.options.keyJump.isDown(); + boolean shiftDown = mc.options.keyShift.isDown(); this.justClosedInventory = true; } else { this.sprintDelayTicks = 0; if (this.justClosedInventory) { - boolean bl5 = mc.options.keyJump.isDown(); - boolean bl6 = mc.options.keyShift.isDown(); + boolean jumpDown = mc.options.keyJump.isDown(); + boolean shiftDown = mc.options.keyShift.isDown(); this.justClosedInventory = false; } } @@ -222,28 +219,28 @@ extends Module { } private boolean validateSlotConfig() { - ArrayList> arrayList = new ArrayList<>(); - arrayList.add(Pair.of(this.swordSlotSetting.getValue().intValue() != 0, this.swordSlotSetting)); - arrayList.add(Pair.of(this.axeSlotSetting.getValue().intValue() != 0, this.axeSlotSetting)); - arrayList.add(Pair.of(this.pickaxeSlotSetting.getValue().intValue() != 0, this.pickaxeSlotSetting)); - arrayList.add(Pair.of(this.bowSlotSetting.getValue().intValue() != 0, this.bowSlotSetting)); - arrayList.add(Pair.of(this.waterBucketSlotSetting.getValue().intValue() != 0, this.waterBucketSlotSetting)); - arrayList.add(Pair.of(this.pearlSlotSetting.getValue().intValue() != 0, this.pearlSlotSetting)); - arrayList.add(Pair.of(this.slimeBallSlotSetting.getValue().intValue() != 0, this.slimeBallSlotSetting)); - arrayList.add(Pair.of(this.crystalSlotSetting.getValue().intValue() != 0, this.crystalSlotSetting)); - arrayList.add(Pair.of(this.eggsSnowballsSlotSetting.getValue().intValue() != 0, this.eggsSnowballsSlotSetting)); + ArrayList> slotEntries = new ArrayList<>(); + slotEntries.add(Pair.of(this.swordSlotSetting.getValue().intValue() != 0, this.swordSlotSetting)); + slotEntries.add(Pair.of(this.axeSlotSetting.getValue().intValue() != 0, this.axeSlotSetting)); + slotEntries.add(Pair.of(this.pickaxeSlotSetting.getValue().intValue() != 0, this.pickaxeSlotSetting)); + slotEntries.add(Pair.of(this.bowSlotSetting.getValue().intValue() != 0, this.bowSlotSetting)); + slotEntries.add(Pair.of(this.waterBucketSlotSetting.getValue().intValue() != 0, this.waterBucketSlotSetting)); + slotEntries.add(Pair.of(this.pearlSlotSetting.getValue().intValue() != 0, this.pearlSlotSetting)); + slotEntries.add(Pair.of(this.slimeBallSlotSetting.getValue().intValue() != 0, this.slimeBallSlotSetting)); + slotEntries.add(Pair.of(this.crystalSlotSetting.getValue().intValue() != 0, this.crystalSlotSetting)); + slotEntries.add(Pair.of(this.eggsSnowballsSlotSetting.getValue().intValue() != 0, this.eggsSnowballsSlotSetting)); if (!"Golden Apple".equals(this.offhandItemSetting.getValue())) { - arrayList.add(Pair.of(this.goldenAppleSlotSetting.getValue().intValue() != 0, this.goldenAppleSlotSetting)); + slotEntries.add(Pair.of(this.goldenAppleSlotSetting.getValue().intValue() != 0, this.goldenAppleSlotSetting)); } if (!"Block".equals(this.offhandItemSetting.getValue())) { - arrayList.add(Pair.of(this.blockSlotSetting.getValue().intValue() != 0, this.blockSlotSetting)); + slotEntries.add(Pair.of(this.blockSlotSetting.getValue().intValue() != 0, this.blockSlotSetting)); } - HashSet hashSet = new HashSet<>(); - for (Pair pair : arrayList) { - if (!pair.getKey()) continue; - int n = pair.getValue().getValue().intValue() - 1; - if (!hashSet.contains(n)) { - hashSet.add(n); + HashSet usedSlots = new HashSet<>(); + for (Pair entry : slotEntries) { + if (!entry.getKey()) continue; + int slot = entry.getValue().getValue().intValue() - 1; + if (!usedSlots.contains(slot)) { + usedSlots.add(slot); continue; } return false; @@ -267,32 +264,32 @@ extends Module { return; } this.idleTicks = MovementUtil.isInputActive() ? 0 : ++this.idleTicks; - boolean bl = false; - AbstractContainerMenu abstractContainerMenu = mc.player.containerMenu; - Object object = mc.screen; - if (object instanceof ContainerScreen) { - containerScreen = (ContainerScreen)object; - object = containerScreen.getTitle().getString(); - String string = Component.translatable("container.chest").getString(); - String string2 = Component.translatable("container.chestDouble").getString(); - String string3 = Component.translatable("container.enderchest").getString(); + boolean isContainerOpen = false; + AbstractContainerMenu containerMenu = mc.player.containerMenu; + Object screen = mc.screen; + if (screen instanceof ContainerScreen) { + containerScreen = (ContainerScreen)screen; + String title = containerScreen.getTitle().getString(); + String chestTitle = Component.translatable("container.chest").getString(); + String doubleChestTitle = Component.translatable("container.chestDouble").getString(); + String enderChestTitle = Component.translatable("container.enderchest").getString(); ChestMenu chestMenu = containerScreen.getMenu(); - if (object.equals(string) || object.equals(string2) || object.equals("Chest")) { - bl = true; + if (title.equals(chestTitle) || title.equals(doubleChestTitle) || title.equals("Chest")) { + isContainerOpen = true; } } - if (abstractContainerMenu instanceof FurnaceMenu || abstractContainerMenu instanceof BrewingStandMenu) { - bl = true; + if (containerMenu instanceof FurnaceMenu || containerMenu instanceof BrewingStandMenu) { + isContainerOpen = true; } - if (bl || ChestStealer.isRateLimited() || Scaffold.INSTANCE.isEnabled() || (this.inventoryOnlySetting.getValue() != false ? !(mc.screen instanceof InventoryScreen) : !GuiMove.INSTANCE.isEnabled() && this.idleTicks <= 1)) { + if (isContainerOpen || ChestStealer.isRateLimited() || Scaffold.INSTANCE.isEnabled() || (this.inventoryOnlySetting.getValue() != false ? !(mc.screen instanceof InventoryScreen) : !GuiMove.INSTANCE.isEnabled() && this.idleTicks <= 1)) { this.pendingOffhandPlace = false; this.sprintWaitTicks = 0; isPerformingAction = false; this.skipNextTick = true; return; } - object = mc.screen; - if (object instanceof AbstractContainerScreen acs) { + screen = mc.screen; + if (screen instanceof AbstractContainerScreen acs) { if (acs.getMenu().containerId != mc.player.inventoryMenu.containerId) { return; } @@ -316,12 +313,12 @@ extends Module { * Enabled aggressive block sorting */ private boolean performInventoryAction() { - Integer n; - ItemStack itemStack; - ItemStack itemStack2; - ItemStack itemStack3; - ItemStack itemStack4; - ItemStack itemStack5; + Integer dropSlot; + ItemStack dropStack; + ItemStack worstProjectile; + ItemStack fishingRodStack; + ItemStack bestFoodStack; + ItemStack worstBlock; if (this.handleAutoArmor()) { return true; } @@ -353,95 +350,94 @@ extends Module { this.swapItemToSlot(this.goldenAppleSlotSetting.getValue().intValue() - 1, Items.GOLDEN_APPLE); } if (this.blockSlotSetting.getValue().intValue() != 0) { - int n7 = this.blockSlotSetting.getValue().intValue() - 1; - ItemStack itemStack11 = mc.player.getInventory().items.get(n7); - ItemStack itemStack12 = ItemUtil.getBestBlock(); - if (!(itemStack12 == null || itemStack12.getCount() <= itemStack11.getCount() && BlockUtil.isPlaceable(itemStack11) || this.offhandItemSetting.getValue().equals("Block") || !this.swapToSlot(n7, itemStack12))) { + int blockSlot = this.blockSlotSetting.getValue().intValue() - 1; + ItemStack currentBlock = mc.player.getInventory().items.get(blockSlot); + ItemStack bestBlock = ItemUtil.getBestBlock(); + if (!(bestBlock == null || bestBlock.getCount() <= currentBlock.getCount() && BlockUtil.isPlaceable(currentBlock) || this.offhandItemSetting.getValue().equals("Block") || !this.swapToSlot(blockSlot, bestBlock))) { return true; } } - if (ItemUtil.countBlocks() > this.maxBlockSizeSetting.getValue().intValue() && this.throwItem(itemStack5 = ItemUtil.getWorstBlock())) { + if (ItemUtil.countBlocks() > this.maxBlockSizeSetting.getValue().intValue() && this.throwItem(worstBlock = ItemUtil.getWorstBlock())) { return true; } - if (ItemUtil.countFood() > this.maxFoodSizeSetting.getValue().intValue() && this.throwItem(itemStack4 = ItemUtil.getBestFoodStack())) { + if (ItemUtil.countFood() > this.maxFoodSizeSetting.getValue().intValue() && this.throwItem(bestFoodStack = ItemUtil.getBestFoodStack())) { return true; } - if (ItemUtil.countFishingRods() > this.maxRodSizeSetting.getValue().intValue() && this.throwItem(itemStack3 = ItemUtil.getFishingRodStack())) { + if (ItemUtil.countFishingRods() > this.maxRodSizeSetting.getValue().intValue() && this.throwItem(fishingRodStack = ItemUtil.getFishingRodStack())) { return true; } - if (ItemUtil.countItem(Items.EGG) + ItemUtil.countItem(Items.SNOWBALL) > this.maxEggsSnowballsSetting.getValue().intValue() && this.throwItem(itemStack2 = ItemUtil.getWorstProjectile())) { + if (ItemUtil.countItem(Items.EGG) + ItemUtil.countItem(Items.SNOWBALL) > this.maxEggsSnowballsSetting.getValue().intValue() && this.throwItem(worstProjectile = ItemUtil.getWorstProjectile())) { return true; } if (this.swordSlotSetting.getValue().intValue() != 0) { - ItemStack itemStack13 = ItemUtil.getBestSword(); - int n8 = this.swordSlotSetting.getValue().intValue() - 1; - ItemStack itemStack14 = mc.player.getInventory().items.get(n8); - ItemStack itemStack15 = ItemUtil.getBestSharpAxe(); - if (ItemUtil.getAxeDamage(itemStack15) > ItemUtil.getSwordDamage(itemStack13)) { - itemStack13 = itemStack15; + ItemStack bestSword = ItemUtil.getBestSword(); + int swordSlot = this.swordSlotSetting.getValue().intValue() - 1; + ItemStack currentSword = mc.player.getInventory().items.get(swordSlot); + ItemStack bestSharpAxe = ItemUtil.getBestSharpAxe(); + if (ItemUtil.getAxeDamage(bestSharpAxe) > ItemUtil.getSwordDamage(bestSword)) { + bestSword = bestSharpAxe; } - if (itemStack13 != null) { - float f; - float f2 = itemStack14.getItem() instanceof SwordItem ? ItemUtil.getSwordDamage(itemStack14) : ItemUtil.getAxeDamage(itemStack14); - float f3 = f = itemStack13.getItem() instanceof SwordItem ? ItemUtil.getSwordDamage(itemStack13) : ItemUtil.getAxeDamage(itemStack13); - if (f > f2 && this.swapToSlot(n8, itemStack13)) { + if (bestSword != null) { + float currentDamage = currentSword.getItem() instanceof SwordItem ? ItemUtil.getSwordDamage(currentSword) : ItemUtil.getAxeDamage(currentSword); + float candidateDamage = bestSword.getItem() instanceof SwordItem ? ItemUtil.getSwordDamage(bestSword) : ItemUtil.getAxeDamage(bestSword); + if (candidateDamage > currentDamage && this.swapToSlot(swordSlot, bestSword)) { return true; } } } if (this.pickaxeSlotSetting.getValue().intValue() != 0) { - int n9 = this.pickaxeSlotSetting.getValue().intValue() - 1; - ItemStack itemStack16 = ItemUtil.getBestPickaxe(); - ItemStack itemStack17 = mc.player.getInventory().items.get(n9); - if (itemStack16 != null && itemStack16.getItem() instanceof PickaxeItem && (ItemUtil.getDigSpeed(itemStack16) > ItemUtil.getDigSpeed(itemStack17) || !(itemStack17.getItem() instanceof PickaxeItem)) && this.swapToSlot(n9, itemStack16)) { + int pickaxeSlot = this.pickaxeSlotSetting.getValue().intValue() - 1; + ItemStack bestPickaxe = ItemUtil.getBestPickaxe(); + ItemStack currentPickaxe = mc.player.getInventory().items.get(pickaxeSlot); + if (bestPickaxe != null && bestPickaxe.getItem() instanceof PickaxeItem && (ItemUtil.getDigSpeed(bestPickaxe) > ItemUtil.getDigSpeed(currentPickaxe) || !(currentPickaxe.getItem() instanceof PickaxeItem)) && this.swapToSlot(pickaxeSlot, bestPickaxe)) { return true; } } if (this.bowSlotSetting.getValue().intValue() != 0) { - ItemStack itemStack18; - float f; - float f4; - ItemStack itemStack19; - int n10 = this.bowSlotSetting.getValue().intValue() - 1; - ItemStack itemStack20 = mc.player.getInventory().items.get(n10); + ItemStack arrowStack; + float currentScore; + float bestScore; + ItemStack bestBow; + int bowSlot = this.bowSlotSetting.getValue().intValue() - 1; + ItemStack currentBow = mc.player.getInventory().items.get(bowSlot); if (this.bowPrioritySetting.getValue().equals("Crossbow")) { - itemStack19 = ItemUtil.getBestCrossbow(); - f4 = ItemUtil.getCrossbowScore(itemStack19); - f = ItemUtil.getCrossbowScore(itemStack20); + bestBow = ItemUtil.getBestCrossbow(); + bestScore = ItemUtil.getCrossbowScore(bestBow); + currentScore = ItemUtil.getCrossbowScore(currentBow); } else if (this.bowPrioritySetting.getValue().equals("Power Bow")) { - itemStack19 = ItemUtil.getBestBowAlt(); - f4 = ItemUtil.getBowScoreAlt(itemStack19); - f = ItemUtil.getBowScoreAlt(itemStack20); + bestBow = ItemUtil.getBestBowAlt(); + bestScore = ItemUtil.getBowScoreAlt(bestBow); + currentScore = ItemUtil.getBowScoreAlt(currentBow); } else { - itemStack19 = ItemUtil.getBestBow(); - f4 = ItemUtil.getBowScore(itemStack19); - f = ItemUtil.getBowScore(itemStack20); + bestBow = ItemUtil.getBestBow(); + bestScore = ItemUtil.getBowScore(bestBow); + currentScore = ItemUtil.getBowScore(currentBow); } - if (itemStack19 == null) { - itemStack19 = ItemUtil.getBestCrossbow(); - f4 = ItemUtil.getCrossbowScore(itemStack19); - f = ItemUtil.getCrossbowScore(itemStack20); + if (bestBow == null) { + bestBow = ItemUtil.getBestCrossbow(); + bestScore = ItemUtil.getCrossbowScore(bestBow); + currentScore = ItemUtil.getCrossbowScore(currentBow); } - if (itemStack19 == null) { - itemStack19 = ItemUtil.getBestBowAlt(); - f4 = ItemUtil.getBowScoreAlt(itemStack19); - f = ItemUtil.getBowScoreAlt(itemStack20); + if (bestBow == null) { + bestBow = ItemUtil.getBestBowAlt(); + bestScore = ItemUtil.getBowScoreAlt(bestBow); + currentScore = ItemUtil.getBowScoreAlt(currentBow); } - if (itemStack19 == null) { - itemStack19 = ItemUtil.getBestBow(); - f4 = ItemUtil.getBowScore(itemStack19); - f = ItemUtil.getBowScore(itemStack20); + if (bestBow == null) { + bestBow = ItemUtil.getBestBow(); + bestScore = ItemUtil.getBowScore(bestBow); + currentScore = ItemUtil.getBowScore(currentBow); } - if (itemStack19 != null && f4 > f && this.swapToSlot(n10, itemStack19)) { + if (bestBow != null && bestScore > currentScore && this.swapToSlot(bowSlot, bestBow)) { return true; } - if (ItemUtil.countItem(Items.ARROW) > 256 && this.throwItem(itemStack18 = ItemUtil.getArrowStack())) { + if (ItemUtil.countItem(Items.ARROW) > 256 && this.throwItem(arrowStack = ItemUtil.getArrowStack())) { return true; } } if (this.axeSlotSetting.getValue().intValue() != 0) { - ItemStack itemStack21 = ItemUtil.getBestAxe(); - if (this.swapToSlot(this.axeSlotSetting.getValue().intValue() - 1, itemStack21)) { + ItemStack bestAxe = ItemUtil.getBestAxe(); + if (this.swapToSlot(this.axeSlotSetting.getValue().intValue() - 1, bestAxe)) { return true; } } @@ -460,14 +456,14 @@ extends Module { if (this.crystalSlotSetting.getValue().intValue() != 0 && this.swapItemToSlot(this.crystalSlotSetting.getValue().intValue() - 1, Items.END_CRYSTAL)) { return true; } - List list = IntStream.range(0, mc.player.getInventory().items.size()).boxed().collect(Collectors.toList()); - Collections.shuffle(list); - Iterator iterator = list.iterator(); + List slotIndices = IntStream.range(0, mc.player.getInventory().items.size()).boxed().collect(Collectors.toList()); + Collections.shuffle(slotIndices); + Iterator slotIterator = slotIndices.iterator(); do { - if (iterator.hasNext()) continue; + if (slotIterator.hasNext()) continue; return false; - } while ((itemStack = mc.player.getInventory().items.get((n = iterator.next()).intValue())).isEmpty() || this.isUsefulItem(itemStack)); - this.throwItem(itemStack); + } while ((dropStack = mc.player.getInventory().items.get((dropSlot = slotIterator.next()).intValue())).isEmpty() || this.isUsefulItem(dropStack)); + this.throwItem(dropStack); return true; } @@ -580,29 +576,29 @@ extends Module { return true; } - private void moveToOffhand(int n) { + private void moveToOffhand(int slot) { if (mc.gameMode == null || mc.player == null) { return; } - if (n < 9) { - mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, n + 36, 40, ClickType.SWAP, mc.player); + if (slot < 9) { + mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, slot + 36, 40, ClickType.SWAP, mc.player); } else { - mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, n, 40, ClickType.SWAP, mc.player); + mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, slot, 40, ClickType.SWAP, mc.player); } this.didInventoryAction = true; actionTimer.reset(); } private boolean throwItem(ItemStack itemStack) { - int n; + int slot; if (mc.gameMode == null || mc.player == null) { return false; } - if (this.throwItemsSetting.getValue() && ItemUtil.isUsable(itemStack) && (actionTimer.hasPassed(this.dropDelaySetting.getValue().intValue()) || this.fastThrowSetting.getValue()) && (n = ItemUtil.getSlot(itemStack)) != -1) { - if (n < 9) { - mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, n + 36, 1, ClickType.THROW, mc.player); + if (this.throwItemsSetting.getValue() && ItemUtil.isUsable(itemStack) && (actionTimer.hasPassed(this.dropDelaySetting.getValue().intValue()) || this.fastThrowSetting.getValue()) && (slot = ItemUtil.getSlot(itemStack)) != -1) { + if (slot < 9) { + mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, slot + 36, 1, ClickType.THROW, mc.player); } else { - mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, n, 1, ClickType.THROW, mc.player); + mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, slot, 1, ClickType.THROW, mc.player); } this.didInventoryAction = true; actionTimer.reset(); @@ -611,17 +607,17 @@ extends Module { return false; } - private boolean swapToSlot(int n, ItemStack itemStack) { - int n2; + private boolean swapToSlot(int targetSlot, ItemStack itemStack) { + int sourceSlot; if (mc.gameMode == null || mc.player == null) { return false; } - ItemStack itemStack2 = mc.player.getInventory().items.get(n); - if (ItemUtil.isUsable(itemStack2) && itemStack != itemStack2 && actionTimer.hasPassed(this.actionDelaySetting.getValue().intValue()) && (n2 = ItemUtil.getSlot(itemStack)) != -1) { - if (n2 < 9) { - mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, n2 + 36, n, ClickType.SWAP, mc.player); + ItemStack currentStack = mc.player.getInventory().items.get(targetSlot); + if (ItemUtil.isUsable(currentStack) && itemStack != currentStack && actionTimer.hasPassed(this.actionDelaySetting.getValue().intValue()) && (sourceSlot = ItemUtil.getSlot(itemStack)) != -1) { + if (sourceSlot < 9) { + mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, sourceSlot + 36, targetSlot, ClickType.SWAP, mc.player); } else { - mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, n2, n, ClickType.SWAP, mc.player); + mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, sourceSlot, targetSlot, ClickType.SWAP, mc.player); } this.didInventoryAction = true; actionTimer.reset(); @@ -630,19 +626,19 @@ extends Module { return false; } - private boolean swapItemToSlot(int n, Item item) { - int n2; + private boolean swapItemToSlot(int targetSlot, Item item) { + int sourceSlot; if (mc.gameMode == null || mc.player == null) { return false; } - ItemStack itemStack = mc.player.getInventory().items.get(n); - if (ItemUtil.isUsable(itemStack) && actionTimer.hasPassed(this.actionDelaySetting.getValue().intValue()) && (n2 = ItemUtil.getSlot(item)) != -1) { - ItemStack itemStack2 = mc.player.getInventory().items.get(n2); - if (itemStack.getItem() != item || itemStack.getItem() == item && itemStack.getCount() < itemStack2.getCount()) { - if (n2 < 9) { - mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, n2 + 36, n, ClickType.SWAP, mc.player); + ItemStack currentStack = mc.player.getInventory().items.get(targetSlot); + if (ItemUtil.isUsable(currentStack) && actionTimer.hasPassed(this.actionDelaySetting.getValue().intValue()) && (sourceSlot = ItemUtil.getSlot(item)) != -1) { + ItemStack sourceStack = mc.player.getInventory().items.get(sourceSlot); + if (currentStack.getItem() != item || currentStack.getItem() == item && currentStack.getCount() < sourceStack.getCount()) { + if (sourceSlot < 9) { + mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, sourceSlot + 36, targetSlot, ClickType.SWAP, mc.player); } else { - mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, n2, n, ClickType.SWAP, mc.player); + mc.gameMode.handleInventoryMouseClick(mc.player.inventoryMenu.containerId, sourceSlot, targetSlot, ClickType.SWAP, mc.player); } this.didInventoryAction = true; actionTimer.reset(); @@ -687,12 +683,12 @@ extends Module { } Item item = itemStack.getItem(); if (item instanceof ArmorItem armorItem) { - float f = ItemUtil.getArmorScore(itemStack); - if (ItemUtil.getEquippedArmorScore(armorItem.getEquipmentSlot()) >= f) { + float candidateScore = ItemUtil.getArmorScore(itemStack); + if (ItemUtil.getEquippedArmorScore(armorItem.getEquipmentSlot()) >= candidateScore) { return false; } - float f2 = ItemUtil.getBestArmorScore(armorItem.getEquipmentSlot()); - return !(f < f2); + float bestScore = ItemUtil.getBestArmorScore(armorItem.getEquipmentSlot()); + return !(candidateScore < bestScore); } if (itemStack.getItem() instanceof SwordItem) { return ItemUtil.getBestSword() == itemStack; diff --git a/src/main/java/shit/zen/modules/impl/player/Stuck.java b/src/main/java/shit/zen/modules/impl/player/Stuck.java index a44dc33..969e891 100644 --- a/src/main/java/shit/zen/modules/impl/player/Stuck.java +++ b/src/main/java/shit/zen/modules/impl/player/Stuck.java @@ -56,11 +56,11 @@ extends Module { } @Override - public void setEnabled(boolean bl) { + public void setEnabled(boolean enable) { if (mc.player == null) { return; } - if (bl) { + if (enable) { super.setEnabled(true); } else if (this.modeSetting.is("Delay")) { if (this.stuckState == 3) { @@ -114,15 +114,15 @@ extends Module { mc.player.setDeltaMovement(0.0, 0.0, 0.0); if (this.stuckState == 1) { this.stuckState = 2; - float f = mc.player.getYRot(); - float f2 = mc.player.getXRot(); - if (this.shouldSendCapturedPacket() && (this.savedYaw != f || this.savedPitch != f2)) { - PacketUtil.sendQueued(new ServerboundMovePlayerPacket.Rot(f, f2, mc.player.onGround())); + float currentYaw = mc.player.getYRot(); + float currentPitch = mc.player.getXRot(); + if (this.shouldSendCapturedPacket() && (this.savedYaw != currentYaw || this.savedPitch != currentPitch)) { + PacketUtil.sendQueued(new ServerboundMovePlayerPacket.Rot(currentYaw, currentPitch, mc.player.onGround())); while (!this.pongQueue.isEmpty()) { PacketUtil.sendQueued((Packet) this.pongQueue.poll()); } - this.savedYaw = f; - this.savedPitch = f2; + this.savedYaw = currentYaw; + this.savedPitch = currentPitch; } PacketUtil.sendQueued((Packet) this.capturedPacket); } else if (!this.isAntiVoidActive() && this.modeSetting.is("Packet") && mc.player.tickCount % 10 == 0) { @@ -151,12 +151,12 @@ extends Module { } private boolean shouldSendCapturedPacket() { - if (this.capturedPacket instanceof ServerboundUseItemPacket serverboundUseItemPacket) { - ItemStack itemStack = mc.player.getItemInHand(serverboundUseItemPacket.getHand()); - return !(itemStack.getItem() instanceof BowlFoodItem) && !(itemStack.getItem() instanceof BowItem); + if (this.capturedPacket instanceof ServerboundUseItemPacket useItemPacket) { + ItemStack heldStack = mc.player.getItemInHand(useItemPacket.getHand()); + return !(heldStack.getItem() instanceof BowlFoodItem) && !(heldStack.getItem() instanceof BowItem); } - if (this.capturedPacket instanceof ServerboundPlayerActionPacket serverboundPlayerActionPacket) { - return serverboundPlayerActionPacket.getAction() == ServerboundPlayerActionPacket.Action.RELEASE_USE_ITEM && mc.player.getUseItem().getItem() instanceof BowItem; + if (this.capturedPacket instanceof ServerboundPlayerActionPacket actionPacket) { + return actionPacket.getAction() == ServerboundPlayerActionPacket.Action.RELEASE_USE_ITEM && mc.player.getUseItem().getItem() instanceof BowItem; } return false; } @@ -180,12 +180,12 @@ extends Module { if (mc.player == null) { return; } - Object object = packetEvent.getPacket(); - if (object instanceof ServerboundMovePlayerPacket serverboundMovePlayerPacket) { + Object rawPacket = packetEvent.getPacket(); + if (rawPacket instanceof ServerboundMovePlayerPacket movePacket) { if (this.stuckState != 1 && this.modeSetting.is("Packet")) { - object = new Rotation(mc.player.getYRot() + (float)(Math.random() - 0.5), mc.player.getXRot()); - ReflectionUtil.setXRot(serverboundMovePlayerPacket, ((Rotation)object).getPitch()); - ReflectionUtil.setYRot(serverboundMovePlayerPacket, ((Rotation)object).getYaw()); + Rotation jitterRotation = new Rotation(mc.player.getYRot() + (float)(Math.random() - 0.5), mc.player.getXRot()); + ReflectionUtil.setXRot(movePacket, jitterRotation.getPitch()); + ReflectionUtil.setYRot(movePacket, jitterRotation.getYaw()); } packetEvent.setCancelled(true); } else if (packetEvent.getPacket() instanceof ServerboundPongPacket) { diff --git a/src/main/java/shit/zen/modules/impl/player/helper/impl/BlockLava.java b/src/main/java/shit/zen/modules/impl/player/helper/impl/BlockLava.java index 875b057..cf867b9 100644 --- a/src/main/java/shit/zen/modules/impl/player/helper/impl/BlockLava.java +++ b/src/main/java/shit/zen/modules/impl/player/helper/impl/BlockLava.java @@ -121,9 +121,9 @@ extends HelperBase { this.tryFindPlacement(); return; } - this.findSuitableFace(blockPos).ifPresentOrElse(blockLava$PlacementData -> { - this.targetRotation = RotationUtil.exactRotation(mc.player.getEyePosition(), blockLava$PlacementData.hitVec()); - this.currentState = blockLava$PlacementData; + this.findSuitableFace(blockPos).ifPresentOrElse(placementData -> { + this.targetRotation = RotationUtil.exactRotation(mc.player.getEyePosition(), placementData.hitVec()); + this.currentState = placementData; }, () -> this.reset()); break; } @@ -137,11 +137,11 @@ extends HelperBase { } private boolean tryFindPlacement() { - Optional optional = this.findSuitableFace(this.targetPos); - if (optional.isPresent()) { - BlockLava.PlacementData blockLava$PlacementData = optional.get(); - this.targetRotation = RotationUtil.exactRotation(mc.player.getEyePosition(), blockLava$PlacementData.hitVec()); - this.currentState = blockLava$PlacementData; + Optional placementOpt = this.findSuitableFace(this.targetPos); + if (placementOpt.isPresent()) { + BlockLava.PlacementData placementData = placementOpt.get(); + this.targetRotation = RotationUtil.exactRotation(mc.player.getEyePosition(), placementData.hitVec()); + this.currentState = placementData; return true; } return false; @@ -196,63 +196,63 @@ extends HelperBase { this.targetPos = null; return; } - BlockPos blockPos2 = mc.player.blockPosition(); - ArrayList arrayList = new ArrayList<>(); - for (int i = -3; i <= 3; ++i) { - for (int j = -2; j <= 2; ++j) { - for (int k = -3; k <= 3; ++k) { - BlockPos blockPos3 = blockPos2.offset(i, j, k); - if (Helper.hasLavaPlacement(blockPos3) || !mc.level.getBlockState(blockPos3).is(Blocks.LAVA) || !mc.level.getFluidState(blockPos3).isSource() || !Helper.isPositionInFov(Vec3.atCenterOf(blockPos3))) continue; - arrayList.add(blockPos3); + BlockPos playerPos = mc.player.blockPosition(); + ArrayList candidates = new ArrayList<>(); + for (int dx = -3; dx <= 3; ++dx) { + for (int dy = -2; dy <= 2; ++dy) { + for (int dz = -3; dz <= 3; ++dz) { + BlockPos candidatePos = playerPos.offset(dx, dy, dz); + if (Helper.hasLavaPlacement(candidatePos) || !mc.level.getBlockState(candidatePos).is(Blocks.LAVA) || !mc.level.getFluidState(candidatePos).isSource() || !Helper.isPositionInFov(Vec3.atCenterOf(candidatePos))) continue; + candidates.add(candidatePos); } } } - Vec3 vec3 = mc.player.getEyePosition(); - this.targetPos = (BlockPos)arrayList.stream().min(Comparator.comparingDouble(blockPos -> Vec3.atCenterOf((Vec3i)blockPos).distanceToSqr(vec3))).orElse(null); + Vec3 eyePos = mc.player.getEyePosition(); + this.targetPos = (BlockPos)candidates.stream().min(Comparator.comparingDouble(blockPos -> Vec3.atCenterOf((Vec3i)blockPos).distanceToSqr(eyePos))).orElse(null); } private int findBlockSlot() { - int n = ItemUtil.getSlot(Items.COBBLESTONE); - if (n != -1 && n < 9) { - return n; + int cobblestoneSlot = ItemUtil.getSlot(Items.COBBLESTONE); + if (cobblestoneSlot != -1 && cobblestoneSlot < 9) { + return cobblestoneSlot; } - for (int i = 0; i < 9; ++i) { + for (int slot = 0; slot < 9; ++slot) { Block block; - ItemStack itemStack = mc.player.getInventory().getItem(i); + ItemStack itemStack = mc.player.getInventory().getItem(slot); if (!(itemStack.getItem() instanceof BlockItem) || !(block = ((BlockItem)itemStack.getItem()).getBlock()).defaultBlockState().isSolid() || block.getSoundType(block.defaultBlockState()).equals(SoundEvents.WOOD_PLACE)) continue; - return i; + return slot; } return -1; } private Optional findSuitableFace(BlockPos blockPos) { for (Direction direction : Direction.values()) { - BlockPos blockPos3 = blockPos.relative(direction); - if (mc.level.getBlockState(blockPos3).isSolid() && !mc.level.getBlockState(blockPos3).is(Blocks.LAVA)) { - Vec3 hitVec = Vec3.atCenterOf(blockPos3).add(direction.getOpposite().getStepX() * 0.5, direction.getOpposite().getStepY() * 0.5, direction.getOpposite().getStepZ() * 0.5); - if (mc.player.getEyePosition().distanceToSqr(hitVec) <= 25.0 && this.canSeeBlockFace(blockPos3, direction.getOpposite())) { - return Optional.of(new BlockLava.PlacementData(blockPos3, direction.getOpposite(), hitVec)); + BlockPos neighborPos = blockPos.relative(direction); + if (mc.level.getBlockState(neighborPos).isSolid() && !mc.level.getBlockState(neighborPos).is(Blocks.LAVA)) { + Vec3 hitVec = Vec3.atCenterOf(neighborPos).add(direction.getOpposite().getStepX() * 0.5, direction.getOpposite().getStepY() * 0.5, direction.getOpposite().getStepZ() * 0.5); + if (mc.player.getEyePosition().distanceToSqr(hitVec) <= 25.0 && this.canSeeBlockFace(neighborPos, direction.getOpposite())) { + return Optional.of(new BlockLava.PlacementData(neighborPos, direction.getOpposite(), hitVec)); } } if (direction != Direction.DOWN) continue; - BlockPos blockPos2 = blockPos3; - for (int i = 0; i < 3 && mc.level.getBlockState(blockPos2).is(Blocks.LAVA); ++i) { - blockPos2 = blockPos2.below(); + BlockPos belowPos = neighborPos; + for (int i = 0; i < 3 && mc.level.getBlockState(belowPos).is(Blocks.LAVA); ++i) { + belowPos = belowPos.below(); } - if (!mc.level.getBlockState(blockPos2).isSolid() || mc.level.getBlockState(blockPos2).is(Blocks.LAVA)) continue; - Vec3 vec3 = Vec3.atCenterOf(blockPos2).add(new Vec3((double)Direction.UP.getStepX() * 0.5, (double)Direction.UP.getStepY() * 0.5, (double)Direction.UP.getStepZ() * 0.5)); - if (!(mc.player.getEyePosition().distanceToSqr(vec3) <= 25.0) || !this.canSeeBlockFace(blockPos2, Direction.UP)) continue; - return Optional.of(new BlockLava.PlacementData(blockPos2, Direction.UP, vec3)); + if (!mc.level.getBlockState(belowPos).isSolid() || mc.level.getBlockState(belowPos).is(Blocks.LAVA)) continue; + Vec3 topHitVec = Vec3.atCenterOf(belowPos).add(new Vec3((double)Direction.UP.getStepX() * 0.5, (double)Direction.UP.getStepY() * 0.5, (double)Direction.UP.getStepZ() * 0.5)); + if (!(mc.player.getEyePosition().distanceToSqr(topHitVec) <= 25.0) || !this.canSeeBlockFace(belowPos, Direction.UP)) continue; + return Optional.of(new BlockLava.PlacementData(belowPos, Direction.UP, topHitVec)); } return Optional.empty(); } - private boolean hasLineOfSight(Vec3 vec3) { + private boolean hasLineOfSight(Vec3 targetVec) { if (mc.player == null || mc.level == null) { return false; } - Vec3 vec32 = mc.player.getEyePosition(); - return mc.level.clip(new ClipContext(vec32, vec3, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)).getType() == HitResult.Type.MISS; + Vec3 eyePos = mc.player.getEyePosition(); + return mc.level.clip(new ClipContext(eyePos, targetVec, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)).getType() == HitResult.Type.MISS; } @Override @@ -266,19 +266,18 @@ extends HelperBase { } private boolean canSeeBlockFace(BlockPos blockPos, Direction direction) { - Vec3 vec3; + Vec3 targetVec; if (mc.player == null || mc.level == null) { return false; } - Vec3 vec32 = mc.player.getEyePosition(); - BlockHitResult blockHitResult = mc.level.clip(new ClipContext(vec32, vec3 = Vec3.atCenterOf(blockPos).add(new Vec3((double)direction.getStepX() * 0.49, (double)direction.getStepY() * 0.49, (double)direction.getStepZ() * 0.49)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); - if (blockHitResult.getType() != HitResult.Type.BLOCK) { + Vec3 eyePos = mc.player.getEyePosition(); + BlockHitResult hit = mc.level.clip(new ClipContext(eyePos, targetVec = Vec3.atCenterOf(blockPos).add(new Vec3((double)direction.getStepX() * 0.49, (double)direction.getStepY() * 0.49, (double)direction.getStepZ() * 0.49)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); + if (hit.getType() != HitResult.Type.BLOCK) { return false; } - BlockHitResult blockHitResult2 = blockHitResult; - if (!blockHitResult2.getBlockPos().equals(blockPos)) { + if (!hit.getBlockPos().equals(blockPos)) { return false; } - return blockHitResult2.getLocation().distanceToSqr(vec3) < 0.25; + return hit.getLocation().distanceToSqr(targetVec) < 0.25; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/modules/impl/player/helper/impl/BlockWater.java b/src/main/java/shit/zen/modules/impl/player/helper/impl/BlockWater.java index 36ed371..6bbf0d5 100644 --- a/src/main/java/shit/zen/modules/impl/player/helper/impl/BlockWater.java +++ b/src/main/java/shit/zen/modules/impl/player/helper/impl/BlockWater.java @@ -116,9 +116,9 @@ extends HelperBase { this.tryFindPlacement(); return; } - this.findSuitableFace(blockPos).ifPresentOrElse(blockWater$PlacementData -> { - this.targetRotation = RotationUtil.exactRotation(mc.player.getEyePosition(), blockWater$PlacementData.hitVec()); - this.currentPlacement = blockWater$PlacementData; + this.findSuitableFace(blockPos).ifPresentOrElse(placementData -> { + this.targetRotation = RotationUtil.exactRotation(mc.player.getEyePosition(), placementData.hitVec()); + this.currentPlacement = placementData; }, () -> this.reset()); break; } @@ -132,11 +132,11 @@ extends HelperBase { } private boolean tryFindPlacement() { - Optional optional = this.findSuitableFace(this.targetPos); - if (optional.isPresent()) { - BlockWater.PlacementData blockWater$PlacementData = optional.get(); - this.targetRotation = RotationUtil.exactRotation(mc.player.getEyePosition(), blockWater$PlacementData.hitVec()); - this.currentPlacement = blockWater$PlacementData; + Optional placementOpt = this.findSuitableFace(this.targetPos); + if (placementOpt.isPresent()) { + BlockWater.PlacementData placementData = placementOpt.get(); + this.targetRotation = RotationUtil.exactRotation(mc.player.getEyePosition(), placementData.hitVec()); + this.currentPlacement = placementData; return true; } return false; @@ -191,72 +191,71 @@ extends HelperBase { this.targetPos = null; return; } - BlockPos blockPos2 = mc.player.blockPosition(); - ArrayList arrayList = new ArrayList<>(); - for (int i = -3; i <= 3; ++i) { - for (int j = -2; j <= 2; ++j) { - for (int k = -3; k <= 3; ++k) { - BlockPos blockPos3 = blockPos2.offset(i, j, k); - if (Helper.hasWaterPlacement(blockPos3) || !mc.level.getBlockState(blockPos3).is(Blocks.WATER) || !mc.level.getFluidState(blockPos3).isSource() || !Helper.isPositionInFov(Vec3.atCenterOf(blockPos3))) continue; - arrayList.add(blockPos3); + BlockPos playerPos = mc.player.blockPosition(); + ArrayList candidates = new ArrayList<>(); + for (int dx = -3; dx <= 3; ++dx) { + for (int dy = -2; dy <= 2; ++dy) { + for (int dz = -3; dz <= 3; ++dz) { + BlockPos candidatePos = playerPos.offset(dx, dy, dz); + if (Helper.hasWaterPlacement(candidatePos) || !mc.level.getBlockState(candidatePos).is(Blocks.WATER) || !mc.level.getFluidState(candidatePos).isSource() || !Helper.isPositionInFov(Vec3.atCenterOf(candidatePos))) continue; + candidates.add(candidatePos); } } } - Vec3 vec3 = mc.player.getEyePosition(); - this.targetPos = (BlockPos)arrayList.stream().min(Comparator.comparingDouble(blockPos -> Vec3.atCenterOf((Vec3i)blockPos).distanceToSqr(vec3))).orElse(null); + Vec3 eyePos = mc.player.getEyePosition(); + this.targetPos = (BlockPos)candidates.stream().min(Comparator.comparingDouble(blockPos -> Vec3.atCenterOf((Vec3i)blockPos).distanceToSqr(eyePos))).orElse(null); } private int findBlockSlot() { - int n = ItemUtil.getSlot(Items.COBBLESTONE); - if (n != -1 && n < 9) { - return n; + int cobblestoneSlot = ItemUtil.getSlot(Items.COBBLESTONE); + if (cobblestoneSlot != -1 && cobblestoneSlot < 9) { + return cobblestoneSlot; } - for (int i = 0; i < 9; ++i) { + for (int slot = 0; slot < 9; ++slot) { Block block; - ItemStack itemStack = mc.player.getInventory().getItem(i); + ItemStack itemStack = mc.player.getInventory().getItem(slot); if (!(itemStack.getItem() instanceof BlockItem) || !(block = ((BlockItem)itemStack.getItem()).getBlock()).defaultBlockState().isSolid()) continue; - return i; + return slot; } return -1; } private Optional findSuitableFace(BlockPos blockPos) { for (Direction direction : Direction.values()) { - BlockPos blockPos3 = blockPos.relative(direction); - if (mc.level.getBlockState(blockPos3).isSolid() && !mc.level.getBlockState(blockPos3).is(Blocks.WATER)) { - Vec3 hitVec = Vec3.atCenterOf(blockPos3).add(direction.getOpposite().getStepX() * 0.5, direction.getOpposite().getStepY() * 0.5, direction.getOpposite().getStepZ() * 0.5); - if (mc.player.getEyePosition().distanceToSqr(hitVec) <= 25.0 && this.canSeeBlockFace(blockPos3, direction.getOpposite())) { - return Optional.of(new BlockWater.PlacementData(blockPos3, direction.getOpposite(), hitVec)); + BlockPos neighborPos = blockPos.relative(direction); + if (mc.level.getBlockState(neighborPos).isSolid() && !mc.level.getBlockState(neighborPos).is(Blocks.WATER)) { + Vec3 hitVec = Vec3.atCenterOf(neighborPos).add(direction.getOpposite().getStepX() * 0.5, direction.getOpposite().getStepY() * 0.5, direction.getOpposite().getStepZ() * 0.5); + if (mc.player.getEyePosition().distanceToSqr(hitVec) <= 25.0 && this.canSeeBlockFace(neighborPos, direction.getOpposite())) { + return Optional.of(new BlockWater.PlacementData(neighborPos, direction.getOpposite(), hitVec)); } } if (direction != Direction.DOWN) continue; - BlockPos blockPos2 = blockPos3; - for (int i = 0; i < 8 && mc.level.getBlockState(blockPos2).is(Blocks.WATER); ++i) { - blockPos2 = blockPos2.below(); + BlockPos belowPos = neighborPos; + for (int i = 0; i < 8 && mc.level.getBlockState(belowPos).is(Blocks.WATER); ++i) { + belowPos = belowPos.below(); } - if (!mc.level.getBlockState(blockPos2).isSolid() || mc.level.getBlockState(blockPos2).is(Blocks.WATER)) continue; - Vec3 vec3 = Vec3.atCenterOf(blockPos2).add(new Vec3((double)Direction.UP.getStepX() * 0.5, (double)Direction.UP.getStepY() * 0.5, (double)Direction.UP.getStepZ() * 0.5)); - if (!(mc.player.getEyePosition().distanceToSqr(vec3) <= 25.0) || !this.canSeeBlockFace(blockPos2, Direction.UP)) continue; - return Optional.of(new BlockWater.PlacementData(blockPos2, Direction.UP, vec3)); + if (!mc.level.getBlockState(belowPos).isSolid() || mc.level.getBlockState(belowPos).is(Blocks.WATER)) continue; + Vec3 topHitVec = Vec3.atCenterOf(belowPos).add(new Vec3((double)Direction.UP.getStepX() * 0.5, (double)Direction.UP.getStepY() * 0.5, (double)Direction.UP.getStepZ() * 0.5)); + if (!(mc.player.getEyePosition().distanceToSqr(topHitVec) <= 25.0) || !this.canSeeBlockFace(belowPos, Direction.UP)) continue; + return Optional.of(new BlockWater.PlacementData(belowPos, Direction.UP, topHitVec)); } return Optional.empty(); } private boolean canSeeBlockFace(BlockPos blockPos, Direction direction) { - Vec3 vec3; + Vec3 targetVec; if (mc.player == null || mc.level == null) { return false; } - Vec3 vec32 = mc.player.getEyePosition(); - BlockHitResult blockHitResult = mc.level.clip(new ClipContext(vec32, vec3 = Vec3.atCenterOf(blockPos).add(new Vec3((double)direction.getStepX() * 0.49, (double)direction.getStepY() * 0.49, (double)direction.getStepZ() * 0.49)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); - if (blockHitResult.getType() != HitResult.Type.BLOCK) { + Vec3 eyePos = mc.player.getEyePosition(); + BlockHitResult hit = mc.level.clip(new ClipContext(eyePos, targetVec = Vec3.atCenterOf(blockPos).add(new Vec3((double)direction.getStepX() * 0.49, (double)direction.getStepY() * 0.49, (double)direction.getStepZ() * 0.49)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); + if (hit.getType() != HitResult.Type.BLOCK) { return false; } - BlockHitResult blockHitResult2 = blockHitResult; - if (!blockHitResult2.getBlockPos().equals(blockPos)) { + if (!hit.getBlockPos().equals(blockPos)) { return false; } - return blockHitResult2.getLocation().distanceToSqr(vec3) < 0.25; + return hit.getLocation().distanceToSqr(targetVec) < 0.25; } @Override diff --git a/src/main/java/shit/zen/modules/impl/player/helper/impl/SelfExtinguish.java b/src/main/java/shit/zen/modules/impl/player/helper/impl/SelfExtinguish.java index f8d165a..2e8fa34 100644 --- a/src/main/java/shit/zen/modules/impl/player/helper/impl/SelfExtinguish.java +++ b/src/main/java/shit/zen/modules/impl/player/helper/impl/SelfExtinguish.java @@ -117,24 +117,24 @@ extends HelperBase { return InteractionResult.PASS; } PlayerUtil.sendCarriedItem(); - PacketUtil.sendPredictive(n -> new ServerboundUseItemPacket(interactionHand, n)); - ItemStack itemStack = player.getItemInHand(interactionHand); - if (player.getCooldowns().isOnCooldown(itemStack.getItem())) { + PacketUtil.sendPredictive(seq -> new ServerboundUseItemPacket(interactionHand, seq)); + ItemStack heldStack = player.getItemInHand(interactionHand); + if (player.getCooldowns().isOnCooldown(heldStack.getItem())) { return InteractionResult.PASS; } - InteractionResult interactionResult = ForgeHooks.onItemRightClick(player, interactionHand); - if (interactionResult != null) { - return interactionResult; + InteractionResult forgeResult = ForgeHooks.onItemRightClick(player, interactionHand); + if (forgeResult != null) { + return forgeResult; } - InteractionResultHolder interactionResultHolder = itemStack.use(level, player, interactionHand); - ItemStack itemStack2 = (ItemStack)interactionResultHolder.getObject(); - if (itemStack2 != itemStack) { - player.setItemInHand(interactionHand, itemStack2); - if (itemStack2.isEmpty()) { - ForgeEventFactory.onPlayerDestroyItem(player, itemStack, interactionHand); + InteractionResultHolder resultHolder = heldStack.use(level, player, interactionHand); + ItemStack resultStack = (ItemStack)resultHolder.getObject(); + if (resultStack != heldStack) { + player.setItemInHand(interactionHand, resultStack); + if (resultStack.isEmpty()) { + ForgeEventFactory.onPlayerDestroyItem(player, heldStack, interactionHand); } } - return interactionResultHolder.getResult(); + return resultHolder.getResult(); } @Override @@ -147,12 +147,12 @@ extends HelperBase { return this.targetRotation; } - public static boolean willCollideBelow(double d) { + public static boolean willCollideBelow(double deltaY) { if (mc.level == null || mc.player == null) { return false; } - Iterable iterable = mc.level.getBlockCollisions(mc.player, mc.player.getBoundingBox().move(0.0, d, 0.0)); - return iterable.iterator().hasNext(); + Iterable collisions = mc.level.getBlockCollisions(mc.player, mc.player.getBoundingBox().move(0.0, deltaY, 0.0)); + return collisions.iterator().hasNext(); } @Override @@ -178,9 +178,9 @@ extends HelperBase { this.isAiming = false; this.targetRotation = null; if (mc.hitResult != null && mc.hitResult.getType() == HitResult.Type.BLOCK && ((BlockHitResult)mc.hitResult).getBlockPos().above().equals(this.waterBlockPos)) { - int n = ItemUtil.getSlot(Items.BUCKET); - if (n != -1 && n < 9) { - mc.player.getInventory().selected = n; + int bucketSlot = ItemUtil.getSlot(Items.BUCKET); + if (bucketSlot != -1 && bucketSlot < 9) { + mc.player.getInventory().selected = bucketSlot; this.useItem(mc.player, mc.level, InteractionHand.MAIN_HAND); } Helper.removeWaterPlacement(this.waterBlockPos); diff --git a/src/main/java/shit/zen/modules/impl/render/Compass.java b/src/main/java/shit/zen/modules/impl/render/Compass.java index 7f0ebe2..198765c 100644 --- a/src/main/java/shit/zen/modules/impl/render/Compass.java +++ b/src/main/java/shit/zen/modules/impl/render/Compass.java @@ -106,12 +106,12 @@ extends Module { if (this.spawnPosition == null) { return; } - float f = (float)(Math.toDegrees(Math.atan2((double)this.spawnPosition.getZ() - this.renderZ, (double)this.spawnPosition.getX() - this.renderX)) - 90.0 - (double)this.renderYaw); - float f2 = (float)mc.getWindow().getGuiScaledWidth() / 2.0f; - float f3 = (float)mc.getWindow().getGuiScaledHeight() / 2.0f; + float angle = (float)(Math.toDegrees(Math.atan2((double)this.spawnPosition.getZ() - this.renderZ, (double)this.spawnPosition.getX() - this.renderX)) - 90.0 - (double)this.renderYaw); + float centerX = (float)mc.getWindow().getGuiScaledWidth() / 2.0f; + float centerY = (float)mc.getWindow().getGuiScaledHeight() / 2.0f; drawContext.save(); - drawContext.translate(f2, f3); - drawContext.rotate(f); + drawContext.translate(centerX, centerY); + drawContext.rotate(angle); try (Path path = new Path()){ path.moveTo(-6.0f, -30.0f); path.lineTo(0.0f, -36.0f); diff --git a/src/main/java/shit/zen/modules/impl/render/ESP.java b/src/main/java/shit/zen/modules/impl/render/ESP.java index 50b6e2f..f01e678 100644 --- a/src/main/java/shit/zen/modules/impl/render/ESP.java +++ b/src/main/java/shit/zen/modules/impl/render/ESP.java @@ -100,8 +100,8 @@ public class ESP extends Module { } private boolean isInRange(Entity entity) { - double d = mc.player.distanceToSqr(entity); - return d < 10000.0; + double distSq = mc.player.distanceToSqr(entity); + return distSq < 10000.0; } @EventTarget @@ -226,7 +226,7 @@ public class ESP extends Module { // Skeleton rendering omitted (heavy obfuscated code); enable Glow mode instead. } - private Color getHealthColor(float f) { - return Color.getHSBColor(Math.max(0.0f, f) / 3.0f, 1.0f, 1.0f); + private Color getHealthColor(float fraction) { + return Color.getHSBColor(Math.max(0.0f, fraction) / 3.0f, 1.0f, 1.0f); } } diff --git a/src/main/java/shit/zen/modules/impl/render/OldHitting.java b/src/main/java/shit/zen/modules/impl/render/OldHitting.java index 1f12a6d..4085c7b 100644 --- a/src/main/java/shit/zen/modules/impl/render/OldHitting.java +++ b/src/main/java/shit/zen/modules/impl/render/OldHitting.java @@ -27,71 +27,71 @@ extends Module { return KillAura.INSTANCE != null && KillAura.INSTANCE.isEnabled() && KillAura.INSTANCE.noUseItem.getValue() != false && KillAura.aimingTarget != null; } - public static void applyTranslate(double d, double d2, double d3, PoseStack poseStack) { - poseStack.translate(d, d2, d3); + public static void applyTranslate(double tx, double ty, double tz, PoseStack poseStack) { + poseStack.translate(tx, ty, tz); } - public static void applyRotate(float f, float f2, float f3, float f4, PoseStack poseStack) { - poseStack.mulPose(new Quaternionf().rotationAxis(f * ((float)Math.PI / 180), f2, f3, f4)); + public static void applyRotate(float angle, float ax, float ay, float az, PoseStack poseStack) { + poseStack.mulPose(new Quaternionf().rotationAxis(angle * ((float)Math.PI / 180), ax, ay, az)); } - public static void applyScale(float f, float f2, float f3, PoseStack poseStack) { - poseStack.scale(f, f2, f3); + public static void applyScale(float sx, float sy, float sz, PoseStack poseStack) { + poseStack.scale(sx, sy, sz); } - public void applyHitAnimation(PoseStack poseStack, float f, HumanoidArm humanoidArm, float f2) { - float f3 = f * this.speedSetting.getValue().floatValue(); - float f4 = this.sizeSetting.getValue().floatValue(); + public void applyHitAnimation(PoseStack poseStack, float progress, HumanoidArm humanoidArm, float equipProgress) { + float scaledProgress = progress * this.speedSetting.getValue().floatValue(); + float size = this.sizeSetting.getValue().floatValue(); poseStack.translate(0.0f, this.yOffsetSetting.getValue().floatValue(), 0.0f); if (this.animationModeSetting.getValue().equalsIgnoreCase("vanilla")) { - int n = humanoidArm == HumanoidArm.RIGHT ? 1 : -1; - OldHitting.applyTranslate((float)n * 0.56f, -0.52f + f2 * -0.6f, -0.72, poseStack); - OldHitting.applyTranslate((float)n * -0.1414214f, 0.08f, 0.1414213925600052, poseStack); + int side = humanoidArm == HumanoidArm.RIGHT ? 1 : -1; + OldHitting.applyTranslate((float)side * 0.56f, -0.52f + equipProgress * -0.6f, -0.72, poseStack); + OldHitting.applyTranslate((float)side * -0.1414214f, 0.08f, 0.1414213925600052, poseStack); OldHitting.applyRotate(-102.25f, 1.0f, 0.0f, 0.0f, poseStack); - OldHitting.applyRotate((float)n * 13.365f, 0.0f, 1.0f, 0.0f, poseStack); - OldHitting.applyRotate((float)n * 78.05f, 0.0f, 0.0f, 1.0f, poseStack); - double d = Math.sin((double)(f3 * f3) * Math.PI); - double d2 = Math.sin(Math.sqrt(f3) * Math.PI); - OldHitting.applyRotate((float)(d * -20.0), 0.0f, 1.0f, 0.0f, poseStack); - OldHitting.applyRotate((float)(d2 * -20.0), 0.0f, 0.0f, 1.0f, poseStack); - OldHitting.applyRotate((float)(d2 * -80.0), 1.0f, 0.0f, 0.0f, poseStack); - OldHitting.applyScale(f4, f4, f4, poseStack); + OldHitting.applyRotate((float)side * 13.365f, 0.0f, 1.0f, 0.0f, poseStack); + OldHitting.applyRotate((float)side * 78.05f, 0.0f, 0.0f, 1.0f, poseStack); + double sinSquared = Math.sin((double)(scaledProgress * scaledProgress) * Math.PI); + double sinSqrt = Math.sin(Math.sqrt(scaledProgress) * Math.PI); + OldHitting.applyRotate((float)(sinSquared * -20.0), 0.0f, 1.0f, 0.0f, poseStack); + OldHitting.applyRotate((float)(sinSqrt * -20.0), 0.0f, 0.0f, 1.0f, poseStack); + OldHitting.applyRotate((float)(sinSqrt * -80.0), 1.0f, 0.0f, 0.0f, poseStack); + OldHitting.applyScale(size, size, size, poseStack); } if (this.animationModeSetting.getValue().equalsIgnoreCase("leaked")) { - this.setupLeakedAnim(poseStack, f2, f3, f4); + this.setupLeakedAnim(poseStack, equipProgress, scaledProgress, size); this.setupLeakedArmPos(poseStack); - float f5 = Mth.sin(Mth.sqrt(f3) * (float)Math.PI) / 8.0f; + float pulse = Mth.sin(Mth.sqrt(scaledProgress) * (float)Math.PI) / 8.0f; poseStack.translate(0.008, 0.24, 0.03); poseStack.translate(-0.16, -0.25, 0.0); - poseStack.scale((float)(0.8 + (double)f5) * f4, (float)(0.8 + (double)f5) * f4, (float)(0.8 + (double)f5) * f4); - OldHitting.applyRotate(-Mth.sin((float)((double)Mth.sqrt(f3) * Math.PI)) * 20.0f, 0.0f, 1.2f, -0.8f, poseStack); - OldHitting.applyRotate(-Mth.sin((float)((double)Mth.sqrt(f3) * Math.PI)) * 30.0f, 1.0f, 0.0f, 0.0f, poseStack); - poseStack.scale(2.4f * f4, 2.4f * f4, 2.4f * f4); + poseStack.scale((float)(0.8 + (double)pulse) * size, (float)(0.8 + (double)pulse) * size, (float)(0.8 + (double)pulse) * size); + OldHitting.applyRotate(-Mth.sin((float)((double)Mth.sqrt(scaledProgress) * Math.PI)) * 20.0f, 0.0f, 1.2f, -0.8f, poseStack); + OldHitting.applyRotate(-Mth.sin((float)((double)Mth.sqrt(scaledProgress) * Math.PI)) * 30.0f, 1.0f, 0.0f, 0.0f, poseStack); + poseStack.scale(2.4f * size, 2.4f * size, 2.4f * size); OldHitting.applyRotate(-38.4f, 0.0f, 1.0f, 0.0f, poseStack); - OldHitting.applyScale(f4, f4, f4, poseStack); + OldHitting.applyScale(size, size, size, poseStack); } if (this.animationModeSetting.getValue().equalsIgnoreCase("slide")) { - float f6 = Mth.sin(Mth.sqrt(f3) * (float)Math.PI); + float slideSwing = Mth.sin(Mth.sqrt(scaledProgress) * (float)Math.PI); OldHitting.applyTranslate(0.648f, -0.55f, -0.7199999690055847, poseStack); OldHitting.applyTranslate(0.0, 0.0, 0.0, poseStack); OldHitting.applyRotate(77.0f, 0.0f, 1.0f, 0.0f, poseStack); OldHitting.applyRotate(-10.0f, 0.0f, 0.0f, 1.0f, poseStack); OldHitting.applyRotate(-80.0f, 1.0f, 0.0f, 0.0f, poseStack); - OldHitting.applyRotate(-f6 * 20.0f, 1.0f, 0.0f, 0.0f, poseStack); - OldHitting.applyScale(1.2f * f4, 1.2f * f4, 1.2f * f4, poseStack); - OldHitting.applyScale(f4, f4, f4, poseStack); + OldHitting.applyRotate(-slideSwing * 20.0f, 1.0f, 0.0f, 0.0f, poseStack); + OldHitting.applyScale(1.2f * size, 1.2f * size, 1.2f * size, poseStack); + OldHitting.applyScale(size, size, size, poseStack); } } - private void setupLeakedAnim(PoseStack poseStack, float f, float f2, float f3) { + private void setupLeakedAnim(PoseStack poseStack, float equipProgress, float scaledProgress, float size) { poseStack.translate(0.56f, -0.52f, -0.71999997f); OldHitting.applyRotate(45.0f, 0.0f, 1.0f, 0.0f, poseStack); - float f4 = Mth.sin(f2 * f2 * (float)Math.PI); - float f5 = Mth.sin(Mth.sqrt(f2) * (float)Math.PI); - OldHitting.applyRotate(f4 * -20.0f, 0.0f, 1.0f, 0.0f, poseStack); - OldHitting.applyRotate(f5 * -20.0f, 0.0f, 0.0f, 1.0f, poseStack); - OldHitting.applyRotate(f5 * -80.0f, 1.0f, 0.0f, 0.0f, poseStack); - poseStack.scale(0.4f * f3, 0.4f * f3, 0.4f * f3); + float sinSquared = Mth.sin(scaledProgress * scaledProgress * (float)Math.PI); + float sinSqrt = Mth.sin(Mth.sqrt(scaledProgress) * (float)Math.PI); + OldHitting.applyRotate(sinSquared * -20.0f, 0.0f, 1.0f, 0.0f, poseStack); + OldHitting.applyRotate(sinSqrt * -20.0f, 0.0f, 0.0f, 1.0f, poseStack); + OldHitting.applyRotate(sinSqrt * -80.0f, 1.0f, 0.0f, 0.0f, poseStack); + poseStack.scale(0.4f * size, 0.4f * size, 0.4f * size); } private void setupLeakedArmPos(PoseStack poseStack) { diff --git a/src/main/java/shit/zen/modules/impl/render/Projectiles.java b/src/main/java/shit/zen/modules/impl/render/Projectiles.java index aa60a01..dccbda6 100644 --- a/src/main/java/shit/zen/modules/impl/render/Projectiles.java +++ b/src/main/java/shit/zen/modules/impl/render/Projectiles.java @@ -275,7 +275,7 @@ public class Projectiles extends Module { double dy = entity.getDeltaMovement().y; double dz = entity.getDeltaMovement().z; Projectile projectile = (Projectile) entity; - for (int n = 0; n < 1000; ++n) { + for (int step = 0; step < 1000; ++step) { Vec3 start = new Vec3(x, y, z); Vec3 end = new Vec3(x + dx, y + dy, z + dz); BlockHitResult blockHit = mc.level.clip(new ClipContext( @@ -300,7 +300,7 @@ public class Projectiles extends Module { Vec3 hitLoc = bestHit.getLocation(); Entity owner = projectile.getOwner(); String ownerName = owner != null ? owner.getName().getString() : "Unknown"; - double flightTime = n / 20.0; + double flightTime = step / 20.0; double distance = mc.player.getEyePosition().distanceTo(hitLoc); return new ProjectileEntry(ownerName, flightTime, distance, System.currentTimeMillis(), Items.ENDER_PEARL, hitLoc); } @@ -485,7 +485,7 @@ public class Projectiles extends Module { double dy = entity.getDeltaMovement().y; double dz = entity.getDeltaMovement().z; this.drawVertex(color, builder, poseStack, x, y, z); - for (int n = 0; n < 1000; ++n) { + for (int step = 0; step < 1000; ++step) { float halfWidth = provider.getFillAlpha(); float height = provider.getOutlineAlpha(); AABB box = new AABB(x - halfWidth, y, z - halfWidth, x + halfWidth, y + height, z + halfWidth); diff --git a/src/main/java/shit/zen/modules/impl/world/AutoPlay.java b/src/main/java/shit/zen/modules/impl/world/AutoPlay.java index 479bc6c..9531a2f 100644 --- a/src/main/java/shit/zen/modules/impl/world/AutoPlay.java +++ b/src/main/java/shit/zen/modules/impl/world/AutoPlay.java @@ -51,15 +51,15 @@ extends Module { if (mc.player == null || mc.level == null) { return; } - if (packetEvent.getPacket() instanceof ClientboundSystemChatPacket clientboundSystemChatPacket) { - String string = clientboundSystemChatPacket.content().getString().replaceAll("§[0-9a-fk-or]", "").trim(); - if (string.contains("地图评分")) { + if (packetEvent.getPacket() instanceof ClientboundSystemChatPacket chatPacket) { + String message = chatPacket.content().getString().replaceAll("§[0-9a-fk-or]", "").trim(); + if (message.contains("地图评分")) { ChatUtil.print("1"); if (this.disconnectTime == -1L) { this.disconnectTime = System.currentTimeMillis(); this.pendingDisconnect = true; } - } else if (string.contains("游戏将在 1 秒 后开始")) { + } else if (message.contains("游戏将在 1 秒 后开始")) { ChatUtil.print("2"); this.disconnectTime = -1L; this.pendingDisconnect = false; @@ -69,7 +69,7 @@ extends Module { @EventTarget public void onTick(TickEvent tickEvent) { - long l; + long elapsed; if (mc.player == null || mc.level == null) { return; } @@ -81,7 +81,7 @@ extends Module { } return; } - if (this.disconnectTime != -1L && (double)(l = System.currentTimeMillis() - this.disconnectTime) >= this.delay.getValue().doubleValue() * 1000.0) { + if (this.disconnectTime != -1L && (double)(elapsed = System.currentTimeMillis() - this.disconnectTime) >= this.delay.getValue().doubleValue() * 1000.0) { mc.player.connection.sendCommand("again"); this.reconnectTime = System.currentTimeMillis(); } diff --git a/src/main/java/shit/zen/modules/impl/world/AutoTools.java b/src/main/java/shit/zen/modules/impl/world/AutoTools.java index bb364b4..a4943e7 100644 --- a/src/main/java/shit/zen/modules/impl/world/AutoTools.java +++ b/src/main/java/shit/zen/modules/impl/world/AutoTools.java @@ -58,15 +58,15 @@ extends Module { } if (motionEvent.isPost()) { if (mc.gameMode.isDestroying()) { - int n; - ItemStack itemStack; - if (this.checkSword.getValue() && (itemStack = mc.player.getMainHandItem()).getItem() instanceof SwordItem) { + int bestSlot; + ItemStack heldStack; + if (this.checkSword.getValue() && (heldStack = mc.player.getMainHandItem()).getItem() instanceof SwordItem) { return; } - BlockHitResult blockHitResult; - if (mc.hitResult != null && mc.hitResult.getType() == HitResult.Type.BLOCK && (n = this.getBestTool((blockHitResult = (BlockHitResult)mc.hitResult).getBlockPos())) != -1 && n != mc.player.getInventory().selected) { + BlockHitResult blockHit; + if (mc.hitResult != null && mc.hitResult.getType() == HitResult.Type.BLOCK && (bestSlot = this.getBestTool((blockHit = (BlockHitResult)mc.hitResult).getBlockPos())) != -1 && bestSlot != mc.player.getInventory().selected) { this.previousSlot = mc.player.getInventory().selected; - mc.player.getInventory().selected = n; + mc.player.getInventory().selected = bestSlot; } } } else if (!mc.gameMode.isDestroying() && this.switchBack.getValue() && this.previousSlot != -1) { @@ -78,22 +78,22 @@ extends Module { private int getBestTool(BlockPos blockPos) { BlockState blockState = mc.level.getBlockState(blockPos); Block block = blockState.getBlock(); - int n = 0; - float f = 1.0f; + int bestSlot = 0; + float bestSpeed = 1.0f; for (int i = 0; i < 9; ++i) { - int n2; + int efficiencyLevel; ItemStack itemStack = mc.player.getInventory().getItem(i); if (ItemUtil.isWeaponItem(itemStack) || itemStack.isEmpty() || blockState.isAir() || itemStack.getItem() instanceof SwordItem && !(block instanceof WebBlock)) continue; - float f2 = itemStack.getItem().getDestroySpeed(itemStack, blockState); - if (f2 > 1.0f && !(block instanceof DropExperienceBlock) && !(block instanceof RedStoneOreBlock) && (n2 = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_EFFICIENCY, itemStack)) > 0) { - f2 += (float)(n2 * n2 + 1); + float destroySpeed = itemStack.getItem().getDestroySpeed(itemStack, blockState); + if (destroySpeed > 1.0f && !(block instanceof DropExperienceBlock) && !(block instanceof RedStoneOreBlock) && (efficiencyLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_EFFICIENCY, itemStack)) > 0) { + destroySpeed += (float)(efficiencyLevel * efficiencyLevel + 1); } - if (!(f2 > f)) continue; - n = i; - f = f2; + if (!(destroySpeed > bestSpeed)) continue; + bestSlot = i; + bestSpeed = destroySpeed; } - if (f > 1.0f) { - return n; + if (bestSpeed > 1.0f) { + return bestSlot; } return -1; } diff --git a/src/main/java/shit/zen/modules/impl/world/Debugger.java b/src/main/java/shit/zen/modules/impl/world/Debugger.java index 4ed20b8..6c83a45 100644 --- a/src/main/java/shit/zen/modules/impl/world/Debugger.java +++ b/src/main/java/shit/zen/modules/impl/world/Debugger.java @@ -19,30 +19,30 @@ extends Module { @EventTarget public void onDisconnect(DisconnectEvent disconnectEvent) { - HashSet hashSet = new HashSet<>(); + HashSet suspiciousClasses = new HashSet<>(); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); if (threadMXBean == null) { return; } ThreadInfo[] threads = threadMXBean.dumpAllThreads(false, false); - int n = 0; + int count = 0; for (ThreadInfo threadInfo : threads) { - String string = threadInfo.getThreadName(); - StackTraceElement[] stackTraceElementArray = threadInfo.getStackTrace(); - if (string == null || stackTraceElementArray == null) continue; - for (StackTraceElement stackTraceElement : stackTraceElementArray) { - String string2 = stackTraceElement.getClassName(); - String string3 = stackTraceElement.getFileName(); - String string4 = stackTraceElement.getModuleName(); - if (string3 != null || string4 != null) continue; - hashSet.add(string2); - ++n; + String threadName = threadInfo.getThreadName(); + StackTraceElement[] stackTrace = threadInfo.getStackTrace(); + if (threadName == null || stackTrace == null) continue; + for (StackTraceElement stackTraceElement : stackTrace) { + String className = stackTraceElement.getClassName(); + String fileName = stackTraceElement.getFileName(); + String moduleName = stackTraceElement.getModuleName(); + if (fileName != null || moduleName != null) continue; + suspiciousClasses.add(className); + ++count; } } - ChatUtil.print("N: " + n + ", Set: "); + ChatUtil.print("N: " + count + ", Set: "); ChatUtil.print("=========================="); - for (String string : hashSet) { - ChatUtil.print(string); + for (String className : suspiciousClasses) { + ChatUtil.print(className); } ChatUtil.print("=========================="); } diff --git a/src/main/java/shit/zen/render/BlurFbo.java b/src/main/java/shit/zen/render/BlurFbo.java index 32ab516..7731fe7 100644 --- a/src/main/java/shit/zen/render/BlurFbo.java +++ b/src/main/java/shit/zen/render/BlurFbo.java @@ -12,35 +12,35 @@ public final class BlurFbo { private int height = 0; private static final String INCOMPLETE_FBO_MSG = "[BlurFbo] incomplete framebuffer status=0x"; - public void resize(int n, int n2) { - if (n <= 0 || n2 <= 0) { + public void resize(int width, int height) { + if (width <= 0 || height <= 0) { return; } - if (this.fboId != 0 && n == this.width && n2 == this.height) { + if (this.fboId != 0 && width == this.width && height == this.height) { return; } this.delete(); - this.width = n; - this.height = n2; + this.width = width; + this.height = height; this.fboId = GL30.glGenFramebuffers(); this.textureId = GL11.glGenTextures(); - int n3 = GL11.glGetInteger(32873); - int n4 = GL11.glGetInteger(36006); + int prevTex2d = GL11.glGetInteger(32873); + int prevFbo = GL11.glGetInteger(36006); GL11.glBindTexture(3553, this.textureId); - GL11.glTexImage2D(3553, 0, 32856, n, n2, 0, 6408, 5121, (ByteBuffer)null); + GL11.glTexImage2D(3553, 0, 32856, width, height, 0, 6408, 5121, (ByteBuffer)null); GL11.glTexParameteri(3553, 10241, 9729); GL11.glTexParameteri(3553, 10240, 9729); GL11.glTexParameteri(3553, 10242, 33071); GL11.glTexParameteri(3553, 10243, 33071); GL30.glBindFramebuffer(36160, this.fboId); GL30.glFramebufferTexture2D(36160, 36064, 3553, this.textureId, 0); - int n5 = GL30.glCheckFramebufferStatus(36160); - if (n5 != 36053) { - System.err.println(INCOMPLETE_FBO_MSG + Integer.toHexString(n5)); + int status = GL30.glCheckFramebufferStatus(36160); + if (status != 36053) { + System.err.println(INCOMPLETE_FBO_MSG + Integer.toHexString(status)); } - GL30.glBindFramebuffer(36160, n4); - GL11.glBindTexture(3553, n3); - GlStateManager._bindTexture(n3); + GL30.glBindFramebuffer(36160, prevFbo); + GL11.glBindTexture(3553, prevTex2d); + GlStateManager._bindTexture(prevTex2d); } public void bind() { diff --git a/src/main/java/shit/zen/render/BlurRenderer.java b/src/main/java/shit/zen/render/BlurRenderer.java index f6b3d33..98010be 100644 --- a/src/main/java/shit/zen/render/BlurRenderer.java +++ b/src/main/java/shit/zen/render/BlurRenderer.java @@ -30,67 +30,67 @@ public final class BlurRenderer { initialized = true; } - public static void renderBlur(DrawContext drawContext, float f, float f2, float f3, float f4, float f5, Runnable runnable) { - if (f3 <= 0.0f || f4 <= 0.0f || f5 <= 0.001f) { - runnable.run(); + public static void renderBlur(DrawContext drawContext, float x, float y, float width, float height, float radius, Runnable drawCallback) { + if (width <= 0.0f || height <= 0.0f || radius <= 0.001f) { + drawCallback.run(); return; } BlurRenderer.ensureInitialized(); - float f6 = Math.max(4.0f, f5 * 3.0f); - float f7 = f - f6; - float f8 = f2 - f6; - float f9 = f3 + 2.0f * f6; - float f10 = f4 + 2.0f * f6; - float f11 = (float)Minecraft.getInstance().getWindow().getGuiScale(); - int n = Math.max(4, Math.min(2048, (int)Math.ceil(f9 * f11))); - int n2 = Math.max(4, Math.min(2048, (int)Math.ceil(f10 * f11))); - fboA.resize(n, n2); - fboB.resize(n, n2); - int n3 = GL11.glGetInteger(36006); - int[] nArray = new int[4]; - GL11.glGetIntegerv(2978, nArray); - Matrix4f matrix4f = RenderSystem.getProjectionMatrix(); - VertexSorting vertexSorting = RenderSystem.getVertexSorting(); - Matrix4f matrix4f2 = new Matrix4f().setOrtho(f7, f7 + f9, f8 + f10, f8, 1000.0f, 3000.0f); + float padding = Math.max(4.0f, radius * 3.0f); + float paddedX = x - padding; + float paddedY = y - padding; + float paddedWidth = width + 2.0f * padding; + float paddedHeight = height + 2.0f * padding; + float guiScale = (float)Minecraft.getInstance().getWindow().getGuiScale(); + int fboWidth = Math.max(4, Math.min(2048, (int)Math.ceil(paddedWidth * guiScale))); + int fboHeight = Math.max(4, Math.min(2048, (int)Math.ceil(paddedHeight * guiScale))); + fboA.resize(fboWidth, fboHeight); + fboB.resize(fboWidth, fboHeight); + int prevFbo = GL11.glGetInteger(36006); + int[] viewport = new int[4]; + GL11.glGetIntegerv(2978, viewport); + Matrix4f prevProj = RenderSystem.getProjectionMatrix(); + VertexSorting prevSorting = RenderSystem.getVertexSorting(); + Matrix4f ortho = new Matrix4f().setOrtho(paddedX, paddedX + paddedWidth, paddedY + paddedHeight, paddedY, 1000.0f, 3000.0f); fboA.bind(); fboA.clear(); - RenderSystem.setProjectionMatrix(matrix4f2, VertexSorting.ORTHOGRAPHIC_Z); + RenderSystem.setProjectionMatrix(ortho, VertexSorting.ORTHOGRAPHIC_Z); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.disableCull(); try { - runnable.run(); + drawCallback.run(); } catch (Throwable throwable) { throwable.printStackTrace(); } - float f12 = Math.max(1.0f, f5 * f11); + float pixelRadius = Math.max(1.0f, radius * guiScale); GlStateManager._disableBlend(); fboB.bind(); fboB.clear(); - blurShader.render(fboA.getTextureId(), 1.0f, 0.0f, n, n2, f12); + blurShader.render(fboA.getTextureId(), 1.0f, 0.0f, fboWidth, fboHeight, pixelRadius); fboA.bind(); fboA.clear(); - blurShader.render(fboB.getTextureId(), 0.0f, 1.0f, n, n2, f12); - GL30.glBindFramebuffer(36160, n3); - GL11.glViewport(nArray[0], nArray[1], nArray[2], nArray[3]); - RenderSystem.setProjectionMatrix(matrix4f, vertexSorting); - BlurRenderer.blitTexture(drawContext, fboA.getTextureId(), f7, f8, f9, f10); + blurShader.render(fboB.getTextureId(), 0.0f, 1.0f, fboWidth, fboHeight, pixelRadius); + GL30.glBindFramebuffer(36160, prevFbo); + GL11.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); + RenderSystem.setProjectionMatrix(prevProj, prevSorting); + BlurRenderer.blitTexture(drawContext, fboA.getTextureId(), paddedX, paddedY, paddedWidth, paddedHeight); } - private static void blitTexture(DrawContext drawContext, int n, float f, float f2, float f3, float f4) { + private static void blitTexture(DrawContext drawContext, int textureId, float x, float y, float width, float height) { RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - RenderSystem.setShaderTexture(0, n); + RenderSystem.setShaderTexture(0, textureId); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); RenderSystem.disableCull(); - Matrix4f matrix4f = drawContext.getPoseStack().last().pose(); + Matrix4f pose = drawContext.getPoseStack().last().pose(); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).uv(0.0f, 1.0f).color(1.0f, 1.0f, 1.0f, 1.0f).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, 0.0f).uv(0.0f, 0.0f).color(1.0f, 1.0f, 1.0f, 1.0f).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, 0.0f).uv(1.0f, 0.0f).color(1.0f, 1.0f, 1.0f, 1.0f).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, 0.0f).uv(1.0f, 1.0f).color(1.0f, 1.0f, 1.0f, 1.0f).endVertex(); + bufferBuilder.vertex(pose, x, y, 0.0f).uv(0.0f, 1.0f).color(1.0f, 1.0f, 1.0f, 1.0f).endVertex(); + bufferBuilder.vertex(pose, x, y + height, 0.0f).uv(0.0f, 0.0f).color(1.0f, 1.0f, 1.0f, 1.0f).endVertex(); + bufferBuilder.vertex(pose, x + width, y + height, 0.0f).uv(1.0f, 0.0f).color(1.0f, 1.0f, 1.0f, 1.0f).endVertex(); + bufferBuilder.vertex(pose, x + width, y, 0.0f).uv(1.0f, 1.0f).color(1.0f, 1.0f, 1.0f, 1.0f).endVertex(); tesselator.end(); RenderSystem.defaultBlendFunc(); } diff --git a/src/main/java/shit/zen/render/BlurShader.java b/src/main/java/shit/zen/render/BlurShader.java index 4b75a85..bbaa57e 100644 --- a/src/main/java/shit/zen/render/BlurShader.java +++ b/src/main/java/shit/zen/render/BlurShader.java @@ -21,75 +21,75 @@ public final class BlurShader { if (this.programId != 0) { return; } - int n = BlurShader.compileShader(35633, "#version 150\nin vec3 Position;\nin vec2 UV0;\nout vec2 texCoord;\nvoid main() {\n gl_Position = vec4(Position, 1.0);\n texCoord = UV0;\n}\n"); - int n2 = BlurShader.compileShader(35632, "#version 150\nuniform sampler2D Sampler0;\nuniform vec2 BlurDir;\nuniform vec2 TexelSize;\nuniform float Radius;\nin vec2 texCoord;\nout vec4 fragColor;\nvoid main() {\n float sigma = max(Radius, 1.0);\n int halfK = int(ceil(sigma * 2.0));\n if (halfK > 24) halfK = 24;\n float twoSigmaSq = 2.0 * sigma * sigma;\n vec4 sum = vec4(0.0);\n float weightSum = 0.0;\n for (int i = -halfK; i <= halfK; i++) {\n float w = exp(-float(i * i) / twoSigmaSq);\n vec2 offset = BlurDir * float(i) * TexelSize;\n sum += texture(Sampler0, texCoord + offset) * w;\n weightSum += w;\n }\n fragColor = sum / max(weightSum, 0.0001);\n}\n"); - int n3 = GL20.glCreateProgram(); - GL20.glAttachShader(n3, n); - GL20.glAttachShader(n3, n2); - GL20.glBindAttribLocation(n3, 0, "Position"); - GL20.glBindAttribLocation(n3, 1, "UV0"); - GL20.glLinkProgram(n3); - if (GL20.glGetProgrami(n3, 35714) == 0) { - String string = GL20.glGetProgramInfoLog(n3); - GL20.glDeleteProgram(n3); - GL20.glDeleteShader(n); - GL20.glDeleteShader(n2); - throw new IllegalStateException("Blur shader link failed: " + string); + int vertexShader = BlurShader.compileShader(35633, "#version 150\nin vec3 Position;\nin vec2 UV0;\nout vec2 texCoord;\nvoid main() {\n gl_Position = vec4(Position, 1.0);\n texCoord = UV0;\n}\n"); + int fragmentShader = BlurShader.compileShader(35632, "#version 150\nuniform sampler2D Sampler0;\nuniform vec2 BlurDir;\nuniform vec2 TexelSize;\nuniform float Radius;\nin vec2 texCoord;\nout vec4 fragColor;\nvoid main() {\n float sigma = max(Radius, 1.0);\n int halfK = int(ceil(sigma * 2.0));\n if (halfK > 24) halfK = 24;\n float twoSigmaSq = 2.0 * sigma * sigma;\n vec4 sum = vec4(0.0);\n float weightSum = 0.0;\n for (int i = -halfK; i <= halfK; i++) {\n float w = exp(-float(i * i) / twoSigmaSq);\n vec2 offset = BlurDir * float(i) * TexelSize;\n sum += texture(Sampler0, texCoord + offset) * w;\n weightSum += w;\n }\n fragColor = sum / max(weightSum, 0.0001);\n}\n"); + int program = GL20.glCreateProgram(); + GL20.glAttachShader(program, vertexShader); + GL20.glAttachShader(program, fragmentShader); + GL20.glBindAttribLocation(program, 0, "Position"); + GL20.glBindAttribLocation(program, 1, "UV0"); + GL20.glLinkProgram(program); + if (GL20.glGetProgrami(program, 35714) == 0) { + String log = GL20.glGetProgramInfoLog(program); + GL20.glDeleteProgram(program); + GL20.glDeleteShader(vertexShader); + GL20.glDeleteShader(fragmentShader); + throw new IllegalStateException("Blur shader link failed: " + log); } - GL20.glDeleteShader(n); - GL20.glDeleteShader(n2); - this.programId = n3; + GL20.glDeleteShader(vertexShader); + GL20.glDeleteShader(fragmentShader); + this.programId = program; this.samplerUniform = GL20.glGetUniformLocation(this.programId, "Sampler0"); this.blurDirUniform = GL20.glGetUniformLocation(this.programId, "BlurDir"); this.texelSizeUniform = GL20.glGetUniformLocation(this.programId, "TexelSize"); this.radiusUniform = GL20.glGetUniformLocation(this.programId, "Radius"); this.vaoId = GL30.glGenVertexArrays(); this.vboId = GL15.glGenBuffers(); - int n4 = GL11.glGetInteger(34229); - int n5 = GL11.glGetInteger(34964); + int prevVao = GL11.glGetInteger(34229); + int prevVbo = GL11.glGetInteger(34964); GL30.glBindVertexArray(this.vaoId); GL15.glBindBuffer(34962, this.vboId); try (MemoryStack memoryStack = MemoryStack.stackPush()){ - FloatBuffer floatBuffer = memoryStack.mallocFloat(30); - BlurShader.putVertex(floatBuffer, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f); - BlurShader.putVertex(floatBuffer, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f); - BlurShader.putVertex(floatBuffer, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f); - BlurShader.putVertex(floatBuffer, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f); - BlurShader.putVertex(floatBuffer, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f); - BlurShader.putVertex(floatBuffer, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f); - floatBuffer.flip(); - GL15.glBufferData(34962, floatBuffer, 35044); + FloatBuffer vertexBuffer = memoryStack.mallocFloat(30); + BlurShader.putVertex(vertexBuffer, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f); + BlurShader.putVertex(vertexBuffer, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f); + BlurShader.putVertex(vertexBuffer, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f); + BlurShader.putVertex(vertexBuffer, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f); + BlurShader.putVertex(vertexBuffer, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f); + BlurShader.putVertex(vertexBuffer, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f); + vertexBuffer.flip(); + GL15.glBufferData(34962, vertexBuffer, 35044); } GL20.glEnableVertexAttribArray(0); GL20.glVertexAttribPointer(0, 3, 5126, false, 20, 0L); GL20.glEnableVertexAttribArray(1); GL20.glVertexAttribPointer(1, 2, 5126, false, 20, 12L); - GL30.glBindVertexArray(n4); - GL15.glBindBuffer(34962, n5); + GL30.glBindVertexArray(prevVao); + GL15.glBindBuffer(34962, prevVbo); } - private static void putVertex(FloatBuffer floatBuffer, float f, float f2, float f3, float f4, float f5) { - floatBuffer.put(f).put(f2).put(f3).put(f4).put(f5); + private static void putVertex(FloatBuffer buffer, float x, float y, float z, float u, float v) { + buffer.put(x).put(y).put(z).put(u).put(v); } - public void render(int n, float f, float f2, int n2, int n3, float f3) { - int n4 = GL11.glGetInteger(35725); - int n5 = GL11.glGetInteger(34229); - int n6 = GL11.glGetInteger(34016); + public void render(int textureId, float dirX, float dirY, int width, int height, float radius) { + int prevProgram = GL11.glGetInteger(35725); + int prevVao = GL11.glGetInteger(34229); + int prevActiveTex = GL11.glGetInteger(34016); GL13.glActiveTexture(33984); - int n7 = GL11.glGetInteger(32873); + int prevTex2d = GL11.glGetInteger(32873); GL20.glUseProgram(this.programId); - GL20.glUniform2f(this.blurDirUniform, f, f2); - GL20.glUniform2f(this.texelSizeUniform, 1.0f / (float)n2, 1.0f / (float)n3); - GL20.glUniform1f(this.radiusUniform, Math.max(f3, 1.0f)); + GL20.glUniform2f(this.blurDirUniform, dirX, dirY); + GL20.glUniform2f(this.texelSizeUniform, 1.0f / (float)width, 1.0f / (float)height); + GL20.glUniform1f(this.radiusUniform, Math.max(radius, 1.0f)); GL20.glUniform1i(this.samplerUniform, 0); - GL11.glBindTexture(3553, n); + GL11.glBindTexture(3553, textureId); GL30.glBindVertexArray(this.vaoId); GL11.glDrawArrays(4, 0, 6); - GL11.glBindTexture(3553, n7); - GL13.glActiveTexture(n6); - GL30.glBindVertexArray(n5); - GL20.glUseProgram(n4); + GL11.glBindTexture(3553, prevTex2d); + GL13.glActiveTexture(prevActiveTex); + GL30.glBindVertexArray(prevVao); + GL20.glUseProgram(prevProgram); } public void delete() { @@ -107,15 +107,15 @@ public final class BlurShader { } } - private static int compileShader(int n, String string) { - int n2 = GL20.glCreateShader(n); - GL20.glShaderSource(n2, string); - GL20.glCompileShader(n2); - if (GL20.glGetShaderi(n2, 35713) == 0) { - String string2 = GL20.glGetShaderInfoLog(n2); - GL20.glDeleteShader(n2); - throw new IllegalStateException("Blur shader " + n + " compile failed: " + string2); + private static int compileShader(int type, String source) { + int shader = GL20.glCreateShader(type); + GL20.glShaderSource(shader, source); + GL20.glCompileShader(shader); + if (GL20.glGetShaderi(shader, 35713) == 0) { + String log = GL20.glGetShaderInfoLog(shader); + GL20.glDeleteShader(shader); + throw new IllegalStateException("Blur shader " + type + " compile failed: " + log); } - return n2; + return shader; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/CustomFont.java b/src/main/java/shit/zen/render/CustomFont.java index c064dee..735f628 100644 --- a/src/main/java/shit/zen/render/CustomFont.java +++ b/src/main/java/shit/zen/render/CustomFont.java @@ -78,53 +78,53 @@ implements Closeable { private float letterSpacing = 0.0f; private FontMetricsImpl fontMetrics; - public CustomFont(Font font, float f, int n, int n2, @Nullable String string) { - this.fontSize = f; - this.pageSize = n; - this.charsPerPage = n2; - this.preloadChars = string; + public CustomFont(Font font, float fontSize, int pageSize, int charsPerPage, @Nullable String preloadChars) { + this.fontSize = fontSize; + this.pageSize = pageSize; + this.charsPerPage = charsPerPage; + this.preloadChars = preloadChars; this.fontMetrics = new FontMetricsImpl(font); - this.initFont(font, f); + this.initFont(font, fontSize); } - public CustomFont(Font font, float f) { - this(font, f, 256, 5, null); + public CustomFont(Font font, float fontSize) { + this(font, fontSize, 256, 5, null); } - private static int alignToPageBoundary(int n, int n2) { - return n2 * (int)Math.floor((double)n / (double)n2); + private static int alignToPageBoundary(int value, int pageSize) { + return pageSize * (int)Math.floor((double)value / (double)pageSize); } - public static String stripFormatting(String string) { - char[] cArray = string.toCharArray(); - StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < cArray.length; ++i) { - char c = cArray[i]; + public static String stripFormatting(String text) { + char[] chars = text.toCharArray(); + StringBuilder result = new StringBuilder(); + for (int i = 0; i < chars.length; ++i) { + char c = chars[i]; if (c == '§') { ++i; continue; } - stringBuilder.append(c); + result.append(c); } - return stringBuilder.toString(); + return result.toString(); } private void checkGuiScaleChanged() { - int n = (int)ClientBase.mc.getWindow().getGuiScale(); - if (n != this.guiScaleCache) { + int guiScale = (int)ClientBase.mc.getWindow().getGuiScale(); + if (guiScale != this.guiScaleCache) { this.close(); this.initFont(this.scaledFont, this.fontSize); } } - private void initFont(Font font, float f) { + private void initFont(Font font, float fontSize) { if (this.initialized) { throw new IllegalStateException("Double call to init()"); } this.initialized = true; this.guiScaleCache = (int)ClientBase.mc.getWindow().getGuiScale(); this.scale = Math.max(2, this.guiScaleCache * 2); - this.scaledFont = font.deriveFont(f * (float)this.scale); + this.scaledFont = font.deriveFont(fontSize * (float)this.scale); this.fontMetrics = new FontMetricsImpl(this.scaledFont); if (this.preloadChars != null && !this.preloadChars.isEmpty()) { this.preloadFuture = this.startPreload(); @@ -141,8 +141,8 @@ implements Closeable { }); } - private GlyphPage createGlyphPage(char c, char c2) { - GlyphPage glyphPage = new GlyphPage(c, c2, this.scaledFont, CustomFont.getTempResourceLocation(), this.charsPerPage); + private GlyphPage createGlyphPage(char startChar, char endChar) { + GlyphPage glyphPage = new GlyphPage(startChar, endChar, this.scaledFont, CustomFont.getTempResourceLocation(), this.charsPerPage); this.glyphPages.add(glyphPage); return glyphPage; } @@ -152,8 +152,8 @@ implements Closeable { if (!existing.contains(c)) continue; return existing.getGlyph(c); } - int n = CustomFont.alignToPageBoundary(c, this.pageSize); - GlyphPage page = this.createGlyphPage((char)n, (char)(n + this.pageSize)); + int pageStart = CustomFont.alignToPageBoundary(c, this.pageSize); + GlyphPage page = this.createGlyphPage((char)pageStart, (char)(pageStart + this.pageSize)); return page.getGlyph(c); } @@ -162,185 +162,185 @@ implements Closeable { return this.glyphCache.computeIfAbsent(c, this::loadGlyph); } - public void drawString(PoseStack poseStack, String string, double d, double d2, int n) { - float f = (float)(n >> 16 & 0xFF) / 255.0f; - float f2 = (float)(n >> 8 & 0xFF) / 255.0f; - float f3 = (float)(n & 0xFF) / 255.0f; - float f4 = (float)(n >> 24 & 0xFF) / 255.0f; - this.drawStringRGB(poseStack, string, (float)d, (float)d2, f, f2, f3, f4); + public void drawString(PoseStack poseStack, String text, double x, double y, int color) { + float r = (float)(color >> 16 & 0xFF) / 255.0f; + float g = (float)(color >> 8 & 0xFF) / 255.0f; + float b = (float)(color & 0xFF) / 255.0f; + float a = (float)(color >> 24 & 0xFF) / 255.0f; + this.drawStringRGB(poseStack, text, (float)x, (float)y, r, g, b, a); } - public void drawStringShadow(PoseStack poseStack, String string, double d, double d2, int n) { - float f = (float)(n >> 16 & 0xFF) / 255.0f; - float f2 = (float)(n >> 8 & 0xFF) / 255.0f; - float f3 = (float)(n & 0xFF) / 255.0f; - float f4 = (float)(n >> 24 & 0xFF) / 255.0f; - this.drawStringRGB(poseStack, string, (float)d, (float)d2, f, f2, f3, f4); + public void drawStringShadow(PoseStack poseStack, String text, double x, double y, int color) { + float r = (float)(color >> 16 & 0xFF) / 255.0f; + float g = (float)(color >> 8 & 0xFF) / 255.0f; + float b = (float)(color & 0xFF) / 255.0f; + float a = (float)(color >> 24 & 0xFF) / 255.0f; + this.drawStringRGB(poseStack, text, (float)x, (float)y, r, g, b, a); } - public void drawStringWithShadow(PoseStack poseStack, String string, double d, double d2, int n) { - this.drawStringColor(poseStack, string, (double)((float)d) + 0.5, (double)((float)d2) + 0.5, SHADOW_COLOR); - this.drawString(poseStack, string, (float)d, (float)d2, n); + public void drawStringWithShadow(PoseStack poseStack, String text, double x, double y, int color) { + this.drawStringColor(poseStack, text, (double)((float)x) + 0.5, (double)((float)y) + 0.5, SHADOW_COLOR); + this.drawString(poseStack, text, (float)x, (float)y, color); } - public void drawStringColor(PoseStack poseStack, String string, double d, double d2, Color color) { - this.drawStringRGB(poseStack, string, (float)d, (float)d2, (float)color.getRed() / 255.0f, (float)color.getGreen() / 255.0f, (float)color.getBlue() / 255.0f, color.getAlpha()); + public void drawStringColor(PoseStack poseStack, String text, double x, double y, Color color) { + this.drawStringRGB(poseStack, text, (float)x, (float)y, (float)color.getRed() / 255.0f, (float)color.getGreen() / 255.0f, (float)color.getBlue() / 255.0f, color.getAlpha()); } - public void drawStringRGB(PoseStack poseStack, String string, float f, float f2, float f3, float f4, float f5, float f6) { - this.drawStringRGBFull(poseStack, string, f, f2, f3, f4, f5, f6, false, 0); + public void drawStringRGB(PoseStack poseStack, String text, float x, float y, float r, float g, float b, float a) { + this.drawStringRGBFull(poseStack, text, x, y, r, g, b, a, false, 0); } - public void drawStringRGBFull(PoseStack var1, String var2, float var3, float var4, float var5, float var6, float var7, float var8, boolean var9, int var10) { + public void drawStringRGBFull(PoseStack poseStack, String text, float x, float y, float baseR, float baseG, float baseB, float alpha, boolean rainbow, int rainbowOffset) { if (this.preloadFuture != null && !this.preloadFuture.isDone()) { try { this.preloadFuture.get(); - } catch (ExecutionException | InterruptedException var44) { + } catch (ExecutionException | InterruptedException ex) { } } this.checkGuiScaleChanged(); - float var13 = var5; - float var14 = var6; - float var15 = var7; - var1.pushPose(); - var1.translate(MathUtil.round(var3, 1), MathUtil.round(--var4, 1), 0.0); - var1.scale(1.0F / this.scale, 1.0F / this.scale, 1.0F); + float curR = baseR; + float curG = baseG; + float curB = baseB; + poseStack.pushPose(); + poseStack.translate(MathUtil.round(x, 1), MathUtil.round(--y, 1), 0.0); + poseStack.scale(1.0F / this.scale, 1.0F / this.scale, 1.0F); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.disableCull(); RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - Matrix4f var16 = var1.last().pose(); - char[] var17 = var2.toCharArray(); - float var18 = 0.0F; - float var19 = 0.0F; - boolean var20 = false; - int var21 = 0; + Matrix4f pose = poseStack.last().pose(); + char[] chars = text.toCharArray(); + float penX = 0.0F; + float penY = 0.0F; + boolean inFormatting = false; + int lineStart = 0; synchronized (this.glyphPageMap) { - for (int var23 = 0; var23 < var17.length; var23++) { - char var24 = var17[var23]; - if (var20) { - var20 = false; - char var25 = Character.toUpperCase(var24); - if (MC_COLOR_CODES.containsKey(var25)) { - int var26 = MC_COLOR_CODES.get(var25); - int[] var27 = colorToRGB(var26); - var13 = var27[0] / 255.0F; - var14 = var27[1] / 255.0F; - var15 = var27[2] / 255.0F; - } else if (var25 == 'R') { - var13 = var5; - var14 = var6; - var15 = var7; + for (int i = 0; i < chars.length; i++) { + char ch = chars[i]; + if (inFormatting) { + inFormatting = false; + char upper = Character.toUpperCase(ch); + if (MC_COLOR_CODES.containsKey(upper)) { + int packed = MC_COLOR_CODES.get(upper); + int[] rgb = colorToRGB(packed); + curR = rgb[0] / 255.0F; + curG = rgb[1] / 255.0F; + curB = rgb[2] / 255.0F; + } else if (upper == 'R') { + curR = baseR; + curG = baseG; + curB = baseB; } - } else if (var24 == 167) { - var20 = true; - } else if (var24 == '\n') { - var19 += this.getStringHeight(var2.substring(var21, var23)) * this.scale; - var18 = 0.0F; - var21 = var23 + 1; + } else if (ch == 167) { + inFormatting = true; + } else if (ch == '\n') { + penY += this.getStringHeight(text.substring(lineStart, i)) * this.scale; + penX = 0.0F; + lineStart = i + 1; } else { - Glyph var49 = this.getOrLoadGlyph(var24); - if (var49 != null) { - if (var49.value() != ' ') { - ResourceLocation var51 = var49.owner().textureLocation; - GlyphEntry var53 = new GlyphEntry(var18, var19, var13, var14, var15, var49); - this.glyphPageMap.computeIfAbsent(var51, var0 -> new ObjectArrayList<>()).add(var53); + Glyph glyph = this.getOrLoadGlyph(ch); + if (glyph != null) { + if (glyph.value() != ' ') { + ResourceLocation textureLocation = glyph.owner().textureLocation; + GlyphEntry entry = new GlyphEntry(penX, penY, curR, curG, curB, glyph); + this.glyphPageMap.computeIfAbsent(textureLocation, key -> new ObjectArrayList<>()).add(entry); } - var18 += var49.width() + this.letterSpacing; + penX += glyph.width() + this.letterSpacing; } } } - for (ResourceLocation var48 : this.glyphPageMap.keySet()) { - RenderSystem.setShaderTexture(0, var48); - List var50 = this.glyphPageMap.get(var48); - Tesselator var52 = Tesselator.getInstance(); - BufferBuilder var28 = var52.getBuilder(); - var28.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); + for (ResourceLocation textureLocation : this.glyphPageMap.keySet()) { + RenderSystem.setShaderTexture(0, textureLocation); + List entries = this.glyphPageMap.get(textureLocation); + Tesselator tesselator = Tesselator.getInstance(); + BufferBuilder bufferBuilder = tesselator.getBuilder(); + bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - for (GlyphEntry var29 : var50) { - float var30 = var29.atX; - float var31 = var29.atY; - float var32 = var29.r; - float var33 = var29.g; - float var34 = var29.b; - Glyph var35 = var29.toDraw; - GlyphPage var36 = var35.owner(); - float var37 = var35.width(); - float var38 = var35.height(); - float var39 = (float) var35.u() / var36.imageWidth; - float var40 = (float) var35.v() / var36.imageHeight; - float var41 = (float) (var35.u() + var35.width()) / var36.imageWidth; - float var42 = (float) (var35.v() + var35.height()) / var36.imageHeight; - var28.vertex(var16, var30 + 0.0F, var31 + var38, 0.0F).uv(var39, var42).color(var32, var33, var34, var8).endVertex(); - var28.vertex(var16, var30 + var37, var31 + var38, 0.0F).uv(var41, var42).color(var32, var33, var34, var8).endVertex(); - var28.vertex(var16, var30 + var37, var31 + 0.0F, 0.0F).uv(var41, var40).color(var32, var33, var34, var8).endVertex(); - var28.vertex(var16, var30 + 0.0F, var31 + 0.0F, 0.0F).uv(var39, var40).color(var32, var33, var34, var8).endVertex(); + for (GlyphEntry entry : entries) { + float atX = entry.atX; + float atY = entry.atY; + float r = entry.r; + float g = entry.g; + float b = entry.b; + Glyph glyph = entry.toDraw; + GlyphPage page = glyph.owner(); + float glyphWidth = glyph.width(); + float glyphHeight = glyph.height(); + float u1 = (float) glyph.u() / page.imageWidth; + float v1 = (float) glyph.v() / page.imageHeight; + float u2 = (float) (glyph.u() + glyph.width()) / page.imageWidth; + float v2 = (float) (glyph.v() + glyph.height()) / page.imageHeight; + bufferBuilder.vertex(pose, atX + 0.0F, atY + glyphHeight, 0.0F).uv(u1, v2).color(r, g, b, alpha).endVertex(); + bufferBuilder.vertex(pose, atX + glyphWidth, atY + glyphHeight, 0.0F).uv(u2, v2).color(r, g, b, alpha).endVertex(); + bufferBuilder.vertex(pose, atX + glyphWidth, atY + 0.0F, 0.0F).uv(u2, v1).color(r, g, b, alpha).endVertex(); + bufferBuilder.vertex(pose, atX + 0.0F, atY + 0.0F, 0.0F).uv(u1, v1).color(r, g, b, alpha).endVertex(); } - var52.end(); + tesselator.end(); } this.glyphPageMap.clear(); } - var1.popPose(); + poseStack.popPose(); RenderSystem.disableBlend(); } - public void drawStringCentered(PoseStack poseStack, String string, double d, double d2, int n) { - float f = (float)(n >> 16 & 0xFF) / 255.0f; - float f2 = (float)(n >> 8 & 0xFF) / 255.0f; - float f3 = (float)(n & 0xFF) / 255.0f; - float f4 = (float)(n >> 24 & 0xFF) / 255.0f; - this.drawStringRGB(poseStack, string, (float)(d - (double)(this.getStringWidth(string) / 2.0f)), (float)d2, f, f2, f3, f4); + public void drawStringCentered(PoseStack poseStack, String text, double x, double y, int color) { + float r = (float)(color >> 16 & 0xFF) / 255.0f; + float g = (float)(color >> 8 & 0xFF) / 255.0f; + float b = (float)(color & 0xFF) / 255.0f; + float a = (float)(color >> 24 & 0xFF) / 255.0f; + this.drawStringRGB(poseStack, text, (float)(x - (double)(this.getStringWidth(text) / 2.0f)), (float)y, r, g, b, a); } - public void drawStringCenteredColor(PoseStack poseStack, String string, double d, double d2, Color color) { - this.drawStringRGB(poseStack, string, (float)(d - (double)(this.getStringWidth(string) / 2.0f)), (float)d2, (float)color.getRed() / 255.0f, (float)color.getGreen() / 255.0f, (float)color.getBlue() / 255.0f, (float)color.getAlpha() / 255.0f); + public void drawStringCenteredColor(PoseStack poseStack, String text, double x, double y, Color color) { + this.drawStringRGB(poseStack, text, (float)(x - (double)(this.getStringWidth(text) / 2.0f)), (float)y, (float)color.getRed() / 255.0f, (float)color.getGreen() / 255.0f, (float)color.getBlue() / 255.0f, (float)color.getAlpha() / 255.0f); } - public void drawStringCenteredRGB(PoseStack poseStack, String string, float f, float f2, float f3, float f4, float f5, float f6) { - this.drawStringRGB(poseStack, string, f - this.getStringWidth(string) / 2.0f, f2, f3, f4, f5, f6); + public void drawStringCenteredRGB(PoseStack poseStack, String text, float x, float y, float r, float g, float b, float a) { + this.drawStringRGB(poseStack, text, x - this.getStringWidth(text) / 2.0f, y, r, g, b, a); } - public float getStringWidth(String string) { - char[] cArray = CustomFont.stripFormatting(string).toCharArray(); - float f = 0.0f; - float f2 = 0.0f; - for (char c : cArray) { + public float getStringWidth(String text) { + char[] chars = CustomFont.stripFormatting(text).toCharArray(); + float lineWidth = 0.0f; + float maxWidth = 0.0f; + for (char c : chars) { if (c == '\n') { - f2 = Math.max(f, f2); - f = 0.0f; + maxWidth = Math.max(lineWidth, maxWidth); + lineWidth = 0.0f; continue; } Glyph glyph = this.getOrLoadGlyph(c); - f += (glyph == null ? 0.0f : (float)glyph.width() / (float)this.scale) + this.letterSpacing; + lineWidth += (glyph == null ? 0.0f : (float)glyph.width() / (float)this.scale) + this.letterSpacing; } - return Math.max(f, f2); + return Math.max(lineWidth, maxWidth); } - public float getStringHeight(String string) { - char[] cArray = CustomFont.stripFormatting(string).toCharArray(); - if (cArray.length == 0) { - cArray = new char[]{' '}; + public float getStringHeight(String text) { + char[] chars = CustomFont.stripFormatting(text).toCharArray(); + if (chars.length == 0) { + chars = new char[]{' '}; } - float f = 0.0f; - float f2 = 0.0f; - for (char c : cArray) { + float lineHeight = 0.0f; + float totalHeight = 0.0f; + for (char c : chars) { if (c == '\n') { - if (f == 0.0f) { - f = this.getOrLoadGlyph(' ') == null ? 0.0f : (float)((Glyph)(Objects.requireNonNull((Object)(this.getOrLoadGlyph(' '))))).height() / (float)this.scale; + if (lineHeight == 0.0f) { + lineHeight = this.getOrLoadGlyph(' ') == null ? 0.0f : (float)((Glyph)(Objects.requireNonNull((Object)(this.getOrLoadGlyph(' '))))).height() / (float)this.scale; } - f2 += f; - f = 0.0f; + totalHeight += lineHeight; + lineHeight = 0.0f; continue; } Glyph glyph = this.getOrLoadGlyph(c); - f = Math.max(glyph == null ? 0.0f : (float)glyph.height() / (float)this.scale, f); + lineHeight = Math.max(glyph == null ? 0.0f : (float)glyph.height() / (float)this.scale, lineHeight); } - return f + f2; + return lineHeight + totalHeight; } public float getFontHeight() { @@ -380,26 +380,26 @@ implements Closeable { } private static String generateRandomName() { - return IntStream.range(0, 32).mapToObj(n -> String.valueOf((char)new Random().nextInt(97, 123))).collect(Collectors.joining()); + return IntStream.range(0, 32).mapToObj(i -> String.valueOf((char)new Random().nextInt(97, 123))).collect(Collectors.joining()); } - public static int @NotNull [] colorToRGB(int n) { - int n2 = n >> 16 & 0xFF; - int n3 = n >> 8 & 0xFF; - int n4 = n & 0xFF; - return new int[]{n2, n3, n4}; + public static int @NotNull [] colorToRGB(int color) { + int r = color >> 16 & 0xFF; + int g = color >> 8 & 0xFF; + int b = color & 0xFF; + return new int[]{r, g, b}; } - public float getStringHeightAlias(String string) { - return this.getStringHeight(string); + public float getStringHeightAlias(String text) { + return this.getStringHeight(text); } - public void drawStringRainbow(PoseStack poseStack, String string, float f, float f2, int n) { - this.drawStringRGBFull(poseStack, string, f, f2, 255.0f, 255.0f, 255.0f, 255.0f, true, n); + public void drawStringRainbow(PoseStack poseStack, String text, float x, float y, int offset) { + this.drawStringRGBFull(poseStack, text, x, y, 255.0f, 255.0f, 255.0f, 255.0f, true, offset); } - public void drawStringCenteredRainbow(PoseStack poseStack, String string, float f, float f2, int n) { - this.drawStringRainbow(poseStack, string, f - this.getStringWidth(string) / 2.0f, f2, n); + public void drawStringCenteredRainbow(PoseStack poseStack, String text, float x, float y, int offset) { + this.drawStringRainbow(poseStack, text, x - this.getStringWidth(text) / 2.0f, y, offset); } public void resetLetterSpacing() { diff --git a/src/main/java/shit/zen/render/DrawContext.java b/src/main/java/shit/zen/render/DrawContext.java index 5266b59..5d07309 100644 --- a/src/main/java/shit/zen/render/DrawContext.java +++ b/src/main/java/shit/zen/render/DrawContext.java @@ -89,23 +89,23 @@ public class DrawContext { } public void restore() { - boolean bl; - if (!this.clipStack.isEmpty() && (bl = this.clipStack.pop()) && this.guiGraphics != null) { + boolean useScissor; + if (!this.clipStack.isEmpty() && (useScissor = this.clipStack.pop()) && this.guiGraphics != null) { this.guiGraphics.disableScissor(); } this.poseStack.popPose(); } - public void translate(float f, float f2) { - this.poseStack.translate(f, f2, 0.0f); + public void translate(float x, float y) { + this.poseStack.translate(x, y, 0.0f); } - public void scale(float f, float f2) { - this.poseStack.scale(f, f2, 1.0f); + public void scale(float scaleX, float scaleY) { + this.poseStack.scale(scaleX, scaleY, 1.0f); } - public void rotate(float f) { - this.poseStack.mulPose(Axis.ZP.rotationDegrees(f)); + public void rotate(float degrees) { + this.poseStack.mulPose(Axis.ZP.rotationDegrees(degrees)); } public void flush() { @@ -115,33 +115,33 @@ public class DrawContext { this.clipRect(rectangle, true); } - public void clipRect(Rectangle rectangle, boolean bl) { + public void clipRect(Rectangle rectangle, boolean enable) { if (this.guiGraphics == null) { return; } - Matrix4f matrix4f = this.poseStack.last().pose(); - Vector4f vector4f = new Vector4f(rectangle.getX(), rectangle.getY(), 0.0f, 1.0f).mul(matrix4f); - Vector4f vector4f2 = new Vector4f(rectangle.getRight(), rectangle.getBottom(), 0.0f, 1.0f).mul(matrix4f); - int n = (int)Math.floor(Math.min(vector4f.x, vector4f2.x)); - int n2 = (int)Math.floor(Math.min(vector4f.y, vector4f2.y)); - int n3 = (int)Math.ceil(Math.max(vector4f.x, vector4f2.x)); - int n4 = (int)Math.ceil(Math.max(vector4f.y, vector4f2.y)); - this.guiGraphics.enableScissor(n, n2, n3, n4); + Matrix4f pose = this.poseStack.last().pose(); + Vector4f topLeft = new Vector4f(rectangle.getX(), rectangle.getY(), 0.0f, 1.0f).mul(pose); + Vector4f bottomRight = new Vector4f(rectangle.getRight(), rectangle.getBottom(), 0.0f, 1.0f).mul(pose); + int minX = (int)Math.floor(Math.min(topLeft.x, bottomRight.x)); + int minY = (int)Math.floor(Math.min(topLeft.y, bottomRight.y)); + int maxX = (int)Math.ceil(Math.max(topLeft.x, bottomRight.x)); + int maxY = (int)Math.ceil(Math.max(topLeft.y, bottomRight.y)); + this.guiGraphics.enableScissor(minX, minY, maxX, maxY); this.updateClipStack(); } - public void clipRoundedRect(RoundedRectangle roundedRectangle, boolean bl) { + public void clipRoundedRect(RoundedRectangle roundedRectangle, boolean enable) { if (this.guiGraphics == null) { return; } - Matrix4f matrix4f = this.poseStack.last().pose(); - Vector4f vector4f = new Vector4f(roundedRectangle.x1, roundedRectangle.y1, 0.0f, 1.0f).mul(matrix4f); - Vector4f vector4f2 = new Vector4f(roundedRectangle.x2, roundedRectangle.y2, 0.0f, 1.0f).mul(matrix4f); - int n = (int)Math.floor(Math.min(vector4f.x, vector4f2.x)); - int n2 = (int)Math.floor(Math.min(vector4f.y, vector4f2.y)); - int n3 = (int)Math.ceil(Math.max(vector4f.x, vector4f2.x)); - int n4 = (int)Math.ceil(Math.max(vector4f.y, vector4f2.y)); - this.guiGraphics.enableScissor(n, n2, n3, n4); + Matrix4f pose = this.poseStack.last().pose(); + Vector4f topLeft = new Vector4f(roundedRectangle.x1, roundedRectangle.y1, 0.0f, 1.0f).mul(pose); + Vector4f bottomRight = new Vector4f(roundedRectangle.x2, roundedRectangle.y2, 0.0f, 1.0f).mul(pose); + int minX = (int)Math.floor(Math.min(topLeft.x, bottomRight.x)); + int minY = (int)Math.floor(Math.min(topLeft.y, bottomRight.y)); + int maxX = (int)Math.ceil(Math.max(topLeft.x, bottomRight.x)); + int maxY = (int)Math.ceil(Math.max(topLeft.y, bottomRight.y)); + this.guiGraphics.enableScissor(minX, minY, maxX, maxY); this.updateClipStack(); } @@ -156,128 +156,128 @@ public class DrawContext { this.drawRectXYWH(rectangle.getX(), rectangle.getY(), rectangle.getWidth(), rectangle.getHeight(), paint); } - public void drawRectXYWH(float f, float f2, float f3, float f4, Paint paint) { + public void drawRectXYWH(float x, float y, float width, float height, Paint paint) { if (paint.getCapStyle() == Paint.StrokeCap.STROKE) { - this.drawRectStroke(f, f2, f3, f4, paint); + this.drawRectStroke(x, y, width, height, paint); return; } this.setupColorShader(); - Matrix4f matrix4f = this.poseStack.last().pose(); - float[] fArray = DrawContext.colorToFloats(paint.getColor()); + Matrix4f pose = this.poseStack.last().pose(); + float[] color = DrawContext.colorToFloats(paint.getColor()); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); if (paint.getGradCoords() != null) { - boolean bl; - Paint.GradientCoords paint$GradientCoords = paint.getGradCoords(); - float[] fArray2 = DrawContext.colorToFloats(paint$GradientCoords.color1); - float[] fArray3 = DrawContext.colorToFloats(paint$GradientCoords.color2); - boolean bl2 = bl = Math.abs(paint$GradientCoords.y2 - paint$GradientCoords.y1) >= Math.abs(paint$GradientCoords.x2 - paint$GradientCoords.x1); - if (bl) { - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).color(fArray2[0], fArray2[1], fArray2[2], fArray2[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, 0.0f).color(fArray3[0], fArray3[1], fArray3[2], fArray3[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, 0.0f).color(fArray3[0], fArray3[1], fArray3[2], fArray3[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, 0.0f).color(fArray2[0], fArray2[1], fArray2[2], fArray2[3]).endVertex(); + boolean vertical; + Paint.GradientCoords gradCoords = paint.getGradCoords(); + float[] color1 = DrawContext.colorToFloats(gradCoords.color1); + float[] color2 = DrawContext.colorToFloats(gradCoords.color2); + boolean isVertical = vertical = Math.abs(gradCoords.y2 - gradCoords.y1) >= Math.abs(gradCoords.x2 - gradCoords.x1); + if (vertical) { + bufferBuilder.vertex(pose, x, y, 0.0f).color(color1[0], color1[1], color1[2], color1[3]).endVertex(); + bufferBuilder.vertex(pose, x, y + height, 0.0f).color(color2[0], color2[1], color2[2], color2[3]).endVertex(); + bufferBuilder.vertex(pose, x + width, y + height, 0.0f).color(color2[0], color2[1], color2[2], color2[3]).endVertex(); + bufferBuilder.vertex(pose, x + width, y, 0.0f).color(color1[0], color1[1], color1[2], color1[3]).endVertex(); } else { - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).color(fArray2[0], fArray2[1], fArray2[2], fArray2[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, 0.0f).color(fArray2[0], fArray2[1], fArray2[2], fArray2[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, 0.0f).color(fArray3[0], fArray3[1], fArray3[2], fArray3[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, 0.0f).color(fArray3[0], fArray3[1], fArray3[2], fArray3[3]).endVertex(); + bufferBuilder.vertex(pose, x, y, 0.0f).color(color1[0], color1[1], color1[2], color1[3]).endVertex(); + bufferBuilder.vertex(pose, x, y + height, 0.0f).color(color1[0], color1[1], color1[2], color1[3]).endVertex(); + bufferBuilder.vertex(pose, x + width, y + height, 0.0f).color(color2[0], color2[1], color2[2], color2[3]).endVertex(); + bufferBuilder.vertex(pose, x + width, y, 0.0f).color(color2[0], color2[1], color2[2], color2[3]).endVertex(); } } else { - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); + bufferBuilder.vertex(pose, x, y, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, x, y + height, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, x + width, y + height, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, x + width, y, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); } tesselator.end(); } public void drawRoundedRect(RoundedRectangle roundedRectangle, Paint paint) { - int n; - int n2 = n = paint.getColor(); - boolean bl = false; - Paint.GradientCoords paint$GradientCoords = paint.getGradCoords(); - if (paint$GradientCoords != null) { - n = paint$GradientCoords.color1; - n2 = paint$GradientCoords.color2; - bl = true; + int color2; + int color1 = color2 = paint.getColor(); + boolean hasGradient = false; + Paint.GradientCoords gradCoords = paint.getGradCoords(); + if (gradCoords != null) { + color1 = gradCoords.color1; + color2 = gradCoords.color2; + hasGradient = true; } - float f = paint.getCapStyle() == Paint.StrokeCap.STROKE ? Math.max(0.5f, paint.getStrokeWidth()) : 0.0f; - ROUNDED_RECT_SHADER.draw(this.poseStack.last().pose(), roundedRectangle.x1, roundedRectangle.y1, roundedRectangle.x2, roundedRectangle.y2, roundedRectangle.topLeftRadius, roundedRectangle.topRightRadius, roundedRectangle.bottomRightRadius, roundedRectangle.bottomLeftRadius, n, n2, bl, f); + float strokeWidth = paint.getCapStyle() == Paint.StrokeCap.STROKE ? Math.max(0.5f, paint.getStrokeWidth()) : 0.0f; + ROUNDED_RECT_SHADER.draw(this.poseStack.last().pose(), roundedRectangle.x1, roundedRectangle.y1, roundedRectangle.x2, roundedRectangle.y2, roundedRectangle.topLeftRadius, roundedRectangle.topRightRadius, roundedRectangle.bottomRightRadius, roundedRectangle.bottomLeftRadius, color1, color2, hasGradient, strokeWidth); } - private void drawCornerArc(BufferBuilder bufferBuilder, Matrix4f matrix4f, float f, float f2, float f3, float f4, float f5, int n, Paint paint, RoundedRectangle roundedRectangle) { - int n2 = paint.getColor(); - Paint.GradientCoords paint$GradientCoords = paint.getGradCoords(); - if (f3 <= 0.0f) { - float[] fArray = DrawContext.interpolateGradientColor(paint$GradientCoords, f, f2, roundedRectangle, n2); - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); + private void drawCornerArc(BufferBuilder bufferBuilder, Matrix4f pose, float centerX, float centerY, float radius, float startAngle, float sweepAngle, int segments, Paint paint, RoundedRectangle roundedRectangle) { + int color = paint.getColor(); + Paint.GradientCoords gradCoords = paint.getGradCoords(); + if (radius <= 0.0f) { + float[] colorFloats = DrawContext.interpolateGradientColor(gradCoords, centerX, centerY, roundedRectangle, color); + bufferBuilder.vertex(pose, centerX, centerY, 0.0f).color(colorFloats[0], colorFloats[1], colorFloats[2], colorFloats[3]).endVertex(); return; } - for (int i = 0; i <= n; ++i) { - float f6 = (float)i / (float)n; - double d = Math.toRadians(f4 + (f5 - f4) * f6); - float f7 = f + (float)Math.cos(d) * f3; - float f8 = f2 + (float)Math.sin(d) * f3; - float[] fArray = DrawContext.interpolateGradientColor(paint$GradientCoords, f7, f8, roundedRectangle, n2); - bufferBuilder.vertex(matrix4f, f7, f8, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); + for (int i = 0; i <= segments; ++i) { + float t = (float)i / (float)segments; + double angle = Math.toRadians(startAngle + (sweepAngle - startAngle) * t); + float vx = centerX + (float)Math.cos(angle) * radius; + float vy = centerY + (float)Math.sin(angle) * radius; + float[] colorFloats = DrawContext.interpolateGradientColor(gradCoords, vx, vy, roundedRectangle, color); + bufferBuilder.vertex(pose, vx, vy, 0.0f).color(colorFloats[0], colorFloats[1], colorFloats[2], colorFloats[3]).endVertex(); } } - private static float[] interpolateGradientColor(Paint.GradientCoords paint$GradientCoords, float f, float f2, RoundedRectangle roundedRectangle, int n) { - if (paint$GradientCoords == null) { - return DrawContext.colorToFloats(n); + private static float[] interpolateGradientColor(Paint.GradientCoords gradCoords, float vx, float vy, RoundedRectangle roundedRectangle, int fallbackColor) { + if (gradCoords == null) { + return DrawContext.colorToFloats(fallbackColor); } - float f3 = roundedRectangle.getHeight(); - if (f3 <= 0.0f) { - return DrawContext.colorToFloats(paint$GradientCoords.color1); + float height = roundedRectangle.getHeight(); + if (height <= 0.0f) { + return DrawContext.colorToFloats(gradCoords.color1); } - float f4 = Math.max(0.0f, Math.min(1.0f, (f2 - roundedRectangle.y1) / f3)); - float[] fArray = DrawContext.colorToFloats(paint$GradientCoords.color1); - float[] fArray2 = DrawContext.colorToFloats(paint$GradientCoords.color2); - return new float[]{fArray[0] + (fArray2[0] - fArray[0]) * f4, fArray[1] + (fArray2[1] - fArray[1]) * f4, fArray[2] + (fArray2[2] - fArray[2]) * f4, fArray[3] + (fArray2[3] - fArray[3]) * f4}; + float t = Math.max(0.0f, Math.min(1.0f, (vy - roundedRectangle.y1) / height)); + float[] color1 = DrawContext.colorToFloats(gradCoords.color1); + float[] color2 = DrawContext.colorToFloats(gradCoords.color2); + return new float[]{color1[0] + (color2[0] - color1[0]) * t, color1[1] + (color2[1] - color1[1]) * t, color1[2] + (color2[2] - color1[2]) * t, color1[3] + (color2[3] - color1[3]) * t}; } - private void drawRectStroke(float f, float f2, float f3, float f4, Paint paint) { - float f5 = Math.max(0.5f, paint.getStrokeWidth()); - float f6 = f5 * 0.5f; - this.drawRectXYWH(f - f6, f2 - f6, f3 + f5, f5, paint.copy()); - this.drawRectXYWH(f - f6, f2 + f4 - f6, f3 + f5, f5, paint.copy()); - this.drawRectXYWH(f - f6, f2 - f6, f5, f4 + f5, paint.copy()); - this.drawRectXYWH(f + f3 - f6, f2 - f6, f5, f4 + f5, paint.copy()); + private void drawRectStroke(float x, float y, float width, float height, Paint paint) { + float strokeWidth = Math.max(0.5f, paint.getStrokeWidth()); + float half = strokeWidth * 0.5f; + this.drawRectXYWH(x - half, y - half, width + strokeWidth, strokeWidth, paint.copy()); + this.drawRectXYWH(x - half, y + height - half, width + strokeWidth, strokeWidth, paint.copy()); + this.drawRectXYWH(x - half, y - half, strokeWidth, height + strokeWidth, paint.copy()); + this.drawRectXYWH(x + width - half, y - half, strokeWidth, height + strokeWidth, paint.copy()); } private void drawRoundedRectStroke(RoundedRectangle roundedRectangle, Paint paint) { - Paint paint2 = paint.copy(); + Paint copy = paint.copy(); this.drawRectStroke(roundedRectangle.x1, roundedRectangle.y1, roundedRectangle.getWidth(), roundedRectangle.getHeight(), paint); } - public void drawLine(float f, float f2, float f3, float f4, Paint paint) { - float f5 = Math.max(0.5f, paint.getStrokeWidth()); - float f6 = f3 - f; - float f7 = f4 - f2; - float f8 = (float)Math.hypot(f6, f7); - if (f8 < 1.0E-4f) { + public void drawLine(float x1, float y1, float x2, float y2, Paint paint) { + float strokeWidth = Math.max(0.5f, paint.getStrokeWidth()); + float dx = x2 - x1; + float dy = y2 - y1; + float length = (float)Math.hypot(dx, dy); + if (length < 1.0E-4f) { return; } - float f9 = -f7 / f8 * f5 * 0.5f; - float f10 = f6 / f8 * f5 * 0.5f; + float normalX = -dy / length * strokeWidth * 0.5f; + float normalY = dx / length * strokeWidth * 0.5f; this.setupColorShader(); - Matrix4f matrix4f = this.poseStack.last().pose(); - float[] fArray = DrawContext.colorToFloats(paint.getColor()); + Matrix4f pose = this.poseStack.last().pose(); + float[] color = DrawContext.colorToFloats(paint.getColor()); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - bufferBuilder.vertex(matrix4f, f + f9, f2 + f10, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f - f9, f2 - f10, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f3 - f9, f4 - f10, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f3 + f9, f4 + f10, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); + bufferBuilder.vertex(pose, x1 + normalX, y1 + normalY, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, x1 - normalX, y1 - normalY, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, x2 - normalX, y2 - normalY, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, x2 + normalX, y2 + normalY, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); tesselator.end(); } - public void drawString(String string, float f, float f2, FontRenderer fontRenderer, Paint paint) { - if (string == null || string.isEmpty()) { + public void drawString(String text, float x, float y, FontRenderer fontRenderer, Paint paint) { + if (text == null || text.isEmpty()) { return; } CustomFont customFont = fontRenderer.getFont(); @@ -285,42 +285,42 @@ public class DrawContext { return; } GlyphMetrics glyphMetrics = fontRenderer.getMetrics(); - float f3 = f2 + glyphMetrics.ascent(); - customFont.drawString(this.poseStack, string, f, f3, paint.getColor()); + float baselineY = y + glyphMetrics.ascent(); + customFont.drawString(this.poseStack, text, x, baselineY, paint.getColor()); } - public void drawArc(float f, float f2, float f3, float f4, float f5, float f6, boolean bl, Paint paint) { + public void drawArc(float x1, float y1, float x2, float y2, float startAngle, float sweepAngle, boolean unused, Paint paint) { this.setupColorShader(); - Matrix4f matrix4f = this.poseStack.last().pose(); - float f7 = (f + f3) * 0.5f; - float f8 = (f2 + f4) * 0.5f; - float f9 = Math.min(f3 - f, f4 - f2) * 0.5f; - float[] fArray = DrawContext.colorToFloats(paint.getColor()); - int n = 32; + Matrix4f pose = this.poseStack.last().pose(); + float centerX = (x1 + x2) * 0.5f; + float centerY = (y1 + y2) * 0.5f; + float radius = Math.min(x2 - x1, y2 - y1) * 0.5f; + float[] color = DrawContext.colorToFloats(paint.getColor()); + int segments = 32; Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); if (paint.getCapStyle() == Paint.StrokeCap.STROKE) { - float f10 = Math.max(0.5f, paint.getStrokeWidth()); - float f11 = f9 - f10 * 0.5f; - float f12 = f9 + f10 * 0.5f; + float strokeWidth = Math.max(0.5f, paint.getStrokeWidth()); + float innerRadius = radius - strokeWidth * 0.5f; + float outerRadius = radius + strokeWidth * 0.5f; bufferBuilder.begin(VertexFormat.Mode.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR); - for (int i = 0; i <= n; ++i) { - float f13 = (float)i / (float)n; - double d = Math.toRadians(f5 + f6 * f13); - float f14 = (float)Math.cos(d); - float f15 = (float)Math.sin(d); - bufferBuilder.vertex(matrix4f, f7 + f14 * f12, f8 + f15 * f12, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f7 + f14 * f11, f8 + f15 * f11, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); + for (int i = 0; i <= segments; ++i) { + float t = (float)i / (float)segments; + double angle = Math.toRadians(startAngle + sweepAngle * t); + float cos = (float)Math.cos(angle); + float sin = (float)Math.sin(angle); + bufferBuilder.vertex(pose, centerX + cos * outerRadius, centerY + sin * outerRadius, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, centerX + cos * innerRadius, centerY + sin * innerRadius, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); } } else { bufferBuilder.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); - bufferBuilder.vertex(matrix4f, f7, f8, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - for (int i = 0; i <= n; ++i) { - float f16 = (float)i / (float)n; - double d = Math.toRadians(f5 + f6 * f16); - float f17 = f7 + (float)Math.cos(d) * f9; - float f18 = f8 + (float)Math.sin(d) * f9; - bufferBuilder.vertex(matrix4f, f17, f18, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); + bufferBuilder.vertex(pose, centerX, centerY, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + for (int i = 0; i <= segments; ++i) { + float t = (float)i / (float)segments; + double angle = Math.toRadians(startAngle + sweepAngle * t); + float vx = centerX + (float)Math.cos(angle) * radius; + float vy = centerY + (float)Math.sin(angle) * radius; + bufferBuilder.vertex(pose, vx, vy, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); } } tesselator.end(); @@ -330,57 +330,57 @@ public class DrawContext { if (path == null) { return; } - float f = Math.max(0.5f, paint.getStrokeWidth()); - float[] fArray = DrawContext.colorToFloats(paint.getColor()); - DrawContext.StrokeState drawContext$StrokeState = new DrawContext.StrokeState(paint.getLinGradient()); - Matrix4f matrix4f = this.poseStack.last().pose(); - float f2 = 0.0f; - float f3 = 0.0f; - float f4 = 0.0f; - float f5 = 0.0f; - boolean bl = false; + float strokeWidth = Math.max(0.5f, paint.getStrokeWidth()); + float[] color = DrawContext.colorToFloats(paint.getColor()); + DrawContext.StrokeState strokeState = new DrawContext.StrokeState(paint.getLinGradient()); + Matrix4f pose = this.poseStack.last().pose(); + float currX = 0.0f; + float currY = 0.0f; + float startX = 0.0f; + float startY = 0.0f; + boolean hasCurrent = false; if (paint.getCapStyle() == Paint.StrokeCap.STROKE || paint.getCapStyle() == Paint.StrokeCap.STROKE_AND_FILL) { for (Path.PathSegment path$PathSegment : path.getSegments()) { switch (path$PathSegment.type) { case MOVE_TO: { - f2 = path$PathSegment.coords[0]; - f3 = path$PathSegment.coords[1]; - f4 = f2; - f5 = f3; - bl = true; + currX = path$PathSegment.coords[0]; + currY = path$PathSegment.coords[1]; + startX = currX; + startY = currY; + hasCurrent = true; break; } case LINE_TO: { - if (bl) { - this.drawStrokedLineSegment(matrix4f, f2, f3, path$PathSegment.coords[0], path$PathSegment.coords[1], f, fArray, drawContext$StrokeState); + if (hasCurrent) { + this.drawStrokedLineSegment(pose, currX, currY, path$PathSegment.coords[0], path$PathSegment.coords[1], strokeWidth, color, strokeState); } - f2 = path$PathSegment.coords[0]; - f3 = path$PathSegment.coords[1]; - bl = true; + currX = path$PathSegment.coords[0]; + currY = path$PathSegment.coords[1]; + hasCurrent = true; break; } case QUAD_TO: { - if (bl) { - this.drawStrokedCubicBezier(matrix4f, f2, f3, (f2 + 2.0f * path$PathSegment.coords[0]) / 3.0f, (f3 + 2.0f * path$PathSegment.coords[1]) / 3.0f, (path$PathSegment.coords[2] + 2.0f * path$PathSegment.coords[0]) / 3.0f, (path$PathSegment.coords[3] + 2.0f * path$PathSegment.coords[1]) / 3.0f, path$PathSegment.coords[2], path$PathSegment.coords[3], f, fArray, drawContext$StrokeState); + if (hasCurrent) { + this.drawStrokedCubicBezier(pose, currX, currY, (currX + 2.0f * path$PathSegment.coords[0]) / 3.0f, (currY + 2.0f * path$PathSegment.coords[1]) / 3.0f, (path$PathSegment.coords[2] + 2.0f * path$PathSegment.coords[0]) / 3.0f, (path$PathSegment.coords[3] + 2.0f * path$PathSegment.coords[1]) / 3.0f, path$PathSegment.coords[2], path$PathSegment.coords[3], strokeWidth, color, strokeState); } - f2 = path$PathSegment.coords[2]; - f3 = path$PathSegment.coords[3]; + currX = path$PathSegment.coords[2]; + currY = path$PathSegment.coords[3]; break; } case CUBIC_TO: { - if (bl) { - this.drawStrokedCubicBezier(matrix4f, f2, f3, path$PathSegment.coords[0], path$PathSegment.coords[1], path$PathSegment.coords[2], path$PathSegment.coords[3], path$PathSegment.coords[4], path$PathSegment.coords[5], f, fArray, drawContext$StrokeState); + if (hasCurrent) { + this.drawStrokedCubicBezier(pose, currX, currY, path$PathSegment.coords[0], path$PathSegment.coords[1], path$PathSegment.coords[2], path$PathSegment.coords[3], path$PathSegment.coords[4], path$PathSegment.coords[5], strokeWidth, color, strokeState); } - f2 = path$PathSegment.coords[4]; - f3 = path$PathSegment.coords[5]; + currX = path$PathSegment.coords[4]; + currY = path$PathSegment.coords[5]; break; } case CLOSE: { - if (bl) { - this.drawStrokedLineSegment(matrix4f, f2, f3, f4, f5, f, fArray, drawContext$StrokeState); + if (hasCurrent) { + this.drawStrokedLineSegment(pose, currX, currY, startX, startY, strokeWidth, color, strokeState); } - f2 = f4; - f3 = f5; + currX = startX; + currY = startY; break; } case RRECT: { @@ -399,38 +399,38 @@ public class DrawContext { } private void fillPath(Path path, Paint paint) { - ArrayList arrayList = new ArrayList<>(); - float f = 0.0f; - float f2 = 0.0f; - float f3 = 0.0f; - float f4 = 0.0f; + ArrayList polygon = new ArrayList<>(); + float currX = 0.0f; + float currY = 0.0f; + float startX = 0.0f; + float startY = 0.0f; block7: for (Path.PathSegment path$PathSegment : path.getSegments()) { switch (path$PathSegment.type) { case MOVE_TO: { - if (!arrayList.isEmpty()) { - this.fillPolygon((List)arrayList, paint); - arrayList.clear(); + if (!polygon.isEmpty()) { + this.fillPolygon((List)polygon, paint); + polygon.clear(); } - f = path$PathSegment.coords[0]; - f2 = path$PathSegment.coords[1]; - f3 = f; - f4 = f2; - arrayList.add(new float[]{f, f2}); + currX = path$PathSegment.coords[0]; + currY = path$PathSegment.coords[1]; + startX = currX; + startY = currY; + polygon.add(new float[]{currX, currY}); continue block7; } case LINE_TO: { - f = path$PathSegment.coords[0]; - f2 = path$PathSegment.coords[1]; - arrayList.add(new float[]{f, f2}); + currX = path$PathSegment.coords[0]; + currY = path$PathSegment.coords[1]; + polygon.add(new float[]{currX, currY}); continue block7; } case CLOSE: { - if (!arrayList.isEmpty()) { - this.fillPolygon((List)arrayList, paint); - arrayList.clear(); + if (!polygon.isEmpty()) { + this.fillPolygon((List)polygon, paint); + polygon.clear(); } - f = f3; - f2 = f4; + currX = startX; + currY = startY; continue block7; } case RRECT: { @@ -443,70 +443,70 @@ public class DrawContext { } } } - if (!arrayList.isEmpty()) { - this.fillPolygon((List)arrayList, paint); + if (!polygon.isEmpty()) { + this.fillPolygon((List)polygon, paint); } } - private void fillPolygon(List list, Paint paint) { - if (list.size() < 3) { + private void fillPolygon(List polygon, Paint paint) { + if (polygon.size() < 3) { return; } this.setupColorShader(); - Matrix4f matrix4f = this.poseStack.last().pose(); - float[] fArray = DrawContext.colorToFloats(paint.getColor()); + Matrix4f pose = this.poseStack.last().pose(); + float[] color = DrawContext.colorToFloats(paint.getColor()); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); - for (float[] fArray2 : list) { - bufferBuilder.vertex(matrix4f, fArray2[0], fArray2[1], 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); + for (float[] vertex : polygon) { + bufferBuilder.vertex(pose, vertex[0], vertex[1], 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); } tesselator.end(); } - private void drawStrokedCubicBezier(Matrix4f matrix4f, float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float[] fArray, DrawContext.StrokeState drawContext$StrokeState) { - int n = 24; - float f10 = f; - float f11 = f2; - for (int i = 1; i <= n; ++i) { - float f12 = (float)i / (float)n; - float f13 = 1.0f - f12; - float f14 = f13 * f13 * f13 * f + 3.0f * f13 * f13 * f12 * f3 + 3.0f * f13 * f12 * f12 * f5 + f12 * f12 * f12 * f7; - float f15 = f13 * f13 * f13 * f2 + 3.0f * f13 * f13 * f12 * f4 + 3.0f * f13 * f12 * f12 * f6 + f12 * f12 * f12 * f8; - this.drawStrokedLineSegment(matrix4f, f10, f11, f14, f15, f9, fArray, drawContext$StrokeState); - f10 = f14; - f11 = f15; + private void drawStrokedCubicBezier(Matrix4f pose, float p0x, float p0y, float p1x, float p1y, float p2x, float p2y, float p3x, float p3y, float strokeWidth, float[] color, DrawContext.StrokeState strokeState) { + int steps = 24; + float prevX = p0x; + float prevY = p0y; + for (int i = 1; i <= steps; ++i) { + float t = (float)i / (float)steps; + float oneMinusT = 1.0f - t; + float x = oneMinusT * oneMinusT * oneMinusT * p0x + 3.0f * oneMinusT * oneMinusT * t * p1x + 3.0f * oneMinusT * t * t * p2x + t * t * t * p3x; + float y = oneMinusT * oneMinusT * oneMinusT * p0y + 3.0f * oneMinusT * oneMinusT * t * p1y + 3.0f * oneMinusT * t * t * p2y + t * t * t * p3y; + this.drawStrokedLineSegment(pose, prevX, prevY, x, y, strokeWidth, color, strokeState); + prevX = x; + prevY = y; } } - private void drawStrokedLineSegment(Matrix4f matrix4f, float f, float f2, float f3, float f4, float f5, float[] fArray, DrawContext.StrokeState drawContext$StrokeState) { - if (drawContext$StrokeState.isDrawing()) { - this.drawLineSegment(matrix4f, f, f2, f3, f4, f5, fArray); + private void drawStrokedLineSegment(Matrix4f pose, float x1, float y1, float x2, float y2, float strokeWidth, float[] color, DrawContext.StrokeState strokeState) { + if (strokeState.isDrawing()) { + this.drawLineSegment(pose, x1, y1, x2, y2, strokeWidth, color); } - drawContext$StrokeState.advance((float)Math.hypot(f3 - f, f4 - f2)); + strokeState.advance((float)Math.hypot(x2 - x1, y2 - y1)); } - private void drawLineSegment(Matrix4f matrix4f, float f, float f2, float f3, float f4, float f5, float[] fArray) { - float f6 = f3 - f; - float f7 = f4 - f2; - float f8 = (float)Math.hypot(f6, f7); - if (f8 < 1.0E-4f) { + private void drawLineSegment(Matrix4f pose, float x1, float y1, float x2, float y2, float strokeWidth, float[] color) { + float dx = x2 - x1; + float dy = y2 - y1; + float length = (float)Math.hypot(dx, dy); + if (length < 1.0E-4f) { return; } - float f9 = -f7 / f8 * f5 * 0.5f; - float f10 = f6 / f8 * f5 * 0.5f; + float normalX = -dy / length * strokeWidth * 0.5f; + float normalY = dx / length * strokeWidth * 0.5f; this.setupColorShader(); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - bufferBuilder.vertex(matrix4f, f + f9, f2 + f10, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f - f9, f2 - f10, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f3 - f9, f4 - f10, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f3 + f9, f4 + f10, 0.0f).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); + bufferBuilder.vertex(pose, x1 + normalX, y1 + normalY, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, x1 - normalX, y1 - normalY, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, x2 - normalX, y2 - normalY, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, x2 + normalX, y2 + normalY, 0.0f).color(color[0], color[1], color[2], color[3]).endVertex(); tesselator.end(); } - public void drawTexture(Texture texture, Rectangle rectangle, Rectangle rectangle2, Paint paint) { + public void drawTexture(Texture texture, Rectangle srcRect, Rectangle dstRect, Paint paint) { if (texture == null) { return; } @@ -516,49 +516,49 @@ public class DrawContext { } else { RenderSystem.setShaderTexture(0, texture.getGlId()); } - Matrix4f matrix4f = this.poseStack.last().pose(); - float[] fArray = DrawContext.colorToFloats(paint.getColor()); - float f = rectangle.getX() / (float)texture.getWidth(); - float f2 = rectangle.getY() / (float)texture.getHeight(); - float f3 = rectangle.getRight() / (float)texture.getWidth(); - float f4 = rectangle.getBottom() / (float)texture.getHeight(); - float f5 = rectangle2.getX(); - float f6 = rectangle2.getY(); - float f7 = rectangle2.getWidth(); - float f8 = rectangle2.getHeight(); + Matrix4f pose = this.poseStack.last().pose(); + float[] color = DrawContext.colorToFloats(paint.getColor()); + float u1 = srcRect.getX() / (float)texture.getWidth(); + float v1 = srcRect.getY() / (float)texture.getHeight(); + float u2 = srcRect.getRight() / (float)texture.getWidth(); + float v2 = srcRect.getBottom() / (float)texture.getHeight(); + float dstX = dstRect.getX(); + float dstY = dstRect.getY(); + float dstWidth = dstRect.getWidth(); + float dstHeight = dstRect.getHeight(); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - bufferBuilder.vertex(matrix4f, f5, f6, 0.0f).uv(f, f2).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f5, f6 + f8, 0.0f).uv(f, f4).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f5 + f7, f6 + f8, 0.0f).uv(f3, f4).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); - bufferBuilder.vertex(matrix4f, f5 + f7, f6, 0.0f).uv(f3, f2).color(fArray[0], fArray[1], fArray[2], fArray[3]).endVertex(); + bufferBuilder.vertex(pose, dstX, dstY, 0.0f).uv(u1, v1).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, dstX, dstY + dstHeight, 0.0f).uv(u1, v2).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, dstX + dstWidth, dstY + dstHeight, 0.0f).uv(u2, v2).color(color[0], color[1], color[2], color[3]).endVertex(); + bufferBuilder.vertex(pose, dstX + dstWidth, dstY, 0.0f).uv(u2, v1).color(color[0], color[1], color[2], color[3]).endVertex(); tesselator.end(); } - public void drawBlurredRoundedRect(RoundedRectangle roundedRectangle, float f, float f2, float f3, float f4, int n) { - float f5 = roundedRectangle.x1 + f - f4; - float f6 = roundedRectangle.y1 + f2 - f4; - float f7 = roundedRectangle.getWidth() + f4 * 2.0f; - float f8 = roundedRectangle.getHeight() + f4 * 2.0f; - float f9 = Math.max(0.0f, roundedRectangle.topLeftRadius + f4); - float f10 = Math.max(0.0f, roundedRectangle.topRightRadius + f4); - float f11 = Math.max(0.0f, roundedRectangle.bottomRightRadius + f4); - float f12 = Math.max(0.0f, roundedRectangle.bottomLeftRadius + f4); - RoundedRectangle roundedRectangle2 = RoundedRectangle.ofXYWHRadii(f5, f6, f7, f8, new float[]{f9, f10, f11, f12}); - Paint paint = new Paint().setColor(n); - float f13 = Math.max(0.01f, f3 * 0.5f); - BlurRenderer.renderBlur(this, f5, f6, f7, f8, f13, () -> this.drawRoundedRect(roundedRectangle2, paint)); + public void drawBlurredRoundedRect(RoundedRectangle roundedRectangle, float offsetX, float offsetY, float blurRadius, float spread, int color) { + float x = roundedRectangle.x1 + offsetX - spread; + float y = roundedRectangle.y1 + offsetY - spread; + float width = roundedRectangle.getWidth() + spread * 2.0f; + float height = roundedRectangle.getHeight() + spread * 2.0f; + float tlRadius = Math.max(0.0f, roundedRectangle.topLeftRadius + spread); + float trRadius = Math.max(0.0f, roundedRectangle.topRightRadius + spread); + float brRadius = Math.max(0.0f, roundedRectangle.bottomRightRadius + spread); + float blRadius = Math.max(0.0f, roundedRectangle.bottomLeftRadius + spread); + RoundedRectangle expanded = RoundedRectangle.ofXYWHRadii(x, y, width, height, new float[]{tlRadius, trRadius, brRadius, blRadius}); + Paint paint = new Paint().setColor(color); + float halfBlur = Math.max(0.01f, blurRadius * 0.5f); + BlurRenderer.renderBlur(this, x, y, width, height, halfBlur, () -> this.drawRoundedRect(expanded, paint)); } - public void drawBlur(float f, float f2, float f3, float f4, float f5, Runnable runnable) { - BlurRenderer.renderBlur(this, f, f2, f3, f4, f5, runnable); + public void drawBlur(float x, float y, float width, float height, float radius, Runnable runnable) { + BlurRenderer.renderBlur(this, x, y, width, height, radius, runnable); } void clearClipStack() { while (!this.clipStack.isEmpty()) { - boolean bl = this.clipStack.pop(); - if (!bl || this.guiGraphics == null) continue; + boolean useScissor = this.clipStack.pop(); + if (!useScissor || this.guiGraphics == null) continue; this.guiGraphics.disableScissor(); } } @@ -577,8 +577,8 @@ public class DrawContext { RenderSystem.disableCull(); } - static float[] colorToFloats(int n) { - return new float[]{(float)(n >> 16 & 0xFF) / 255.0f, (float)(n >> 8 & 0xFF) / 255.0f, (float)(n & 0xFF) / 255.0f, (float)(n >>> 24 & 0xFF) / 255.0f}; + static float[] colorToFloats(int color) { + return new float[]{(float)(color >> 16 & 0xFF) / 255.0f, (float)(color >> 8 & 0xFF) / 255.0f, (float)(color & 0xFF) / 255.0f, (float)(color >>> 24 & 0xFF) / 255.0f}; } public static AbstractTexture getTexture(ResourceLocation resourceLocation) { diff --git a/src/main/java/shit/zen/render/FontPresets.java b/src/main/java/shit/zen/render/FontPresets.java index f26ffa6..80fa759 100644 --- a/src/main/java/shit/zen/render/FontPresets.java +++ b/src/main/java/shit/zen/render/FontPresets.java @@ -4,51 +4,51 @@ import shit.zen.render.FontRenderer; import shit.zen.render.Fonts; public final class FontPresets { - public static FontRenderer pingfang(float f) { - return Fonts.getRenderer("pingfang_sc_regular.ttf", f); + public static FontRenderer pingfang(float size) { + return Fonts.getRenderer("pingfang_sc_regular.ttf", size); } - public static FontRenderer productSans(float f) { - return Fonts.getRenderer("product_sans_regular.ttf", f); + public static FontRenderer productSans(float size) { + return Fonts.getRenderer("product_sans_regular.ttf", size); } - public static FontRenderer astaSans(float f) { - return Fonts.getRenderer("AstaSans-Medium.ttf", f); + public static FontRenderer astaSans(float size) { + return Fonts.getRenderer("AstaSans-Medium.ttf", size); } - public static FontRenderer poppinsRegular(float f) { - return Fonts.getRenderer("Poppins-Regular.ttf", f); + public static FontRenderer poppinsRegular(float size) { + return Fonts.getRenderer("Poppins-Regular.ttf", size); } - public static FontRenderer poppinsMedium(float f) { - return Fonts.getRenderer("Poppins-Medium.ttf", f); + public static FontRenderer poppinsMedium(float size) { + return Fonts.getRenderer("Poppins-Medium.ttf", size); } - public static FontRenderer poppinsBold(float f) { - return Fonts.getRenderer("Poppins-Bold.ttf", f); + public static FontRenderer poppinsBold(float size) { + return Fonts.getRenderer("Poppins-Bold.ttf", size); } - public static FontRenderer zenIcon(float f) { - return Fonts.getRenderer("zenicon-Regular.ttf", f); + public static FontRenderer zenIcon(float size) { + return Fonts.getRenderer("zenicon-Regular.ttf", size); } - public static FontRenderer museoSans(float f) { - return Fonts.getRenderer("MuseoSansCyrl-900.ttf", f); + public static FontRenderer museoSans(float size) { + return Fonts.getRenderer("MuseoSansCyrl-900.ttf", size); } - public static FontRenderer materialIcons(float f) { - return Fonts.getRenderer("MaterialIcons-Regular.ttf", f); + public static FontRenderer materialIcons(float size) { + return Fonts.getRenderer("MaterialIcons-Regular.ttf", size); } - public static FontRenderer axiformaBold(float f) { - return Fonts.getRenderer("axiforma_bold.ttf", f); + public static FontRenderer axiformaBold(float size) { + return Fonts.getRenderer("axiforma_bold.ttf", size); } - public static FontRenderer axiformaRegular(float f) { - return Fonts.getRenderer("axiforma_regular.ttf", f); + public static FontRenderer axiformaRegular(float size) { + return Fonts.getRenderer("axiforma_regular.ttf", size); } - public static FontRenderer axiformaExtraBold(float f) { - return Fonts.getRenderer("axiforma_extrabold.ttf", f); + public static FontRenderer axiformaExtraBold(float size) { + return Fonts.getRenderer("axiforma_extrabold.ttf", size); } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/Fonts.java b/src/main/java/shit/zen/render/Fonts.java index d8cfdf8..7baa4a4 100644 --- a/src/main/java/shit/zen/render/Fonts.java +++ b/src/main/java/shit/zen/render/Fonts.java @@ -51,10 +51,10 @@ public final class Fonts { } private static FontFormat detectFormat(String name) { - int n = name.lastIndexOf(46); - if (n < 0) { + int dotIndex = name.lastIndexOf(46); + if (dotIndex < 0) { return FontFormat.UNKNOWN; } - return FontFormat.fromExtension(name.substring(n + 1)); + return FontFormat.fromExtension(name.substring(dotIndex + 1)); } } diff --git a/src/main/java/shit/zen/render/GaussianBlur.java b/src/main/java/shit/zen/render/GaussianBlur.java index e938b51..ae1fc9c 100644 --- a/src/main/java/shit/zen/render/GaussianBlur.java +++ b/src/main/java/shit/zen/render/GaussianBlur.java @@ -9,133 +9,133 @@ public class GaussianBlur { protected Kernel kernel; private static final String NAME = "Blur/Gaussian Blur..."; - public GaussianBlur(float f) { - this.setRadius(f); + public GaussianBlur(float radius) { + this.setRadius(radius); } - public static void convolve(Kernel kernel, int[] nArray, int[] nArray2, int n, int n2, boolean bl, boolean bl2, boolean bl3, int n3) { - float[] fArray = kernel.getKernelData(null); - int n4 = kernel.getWidth(); - int n5 = n4 / 2; - for (int i = 0; i < n2; ++i) { - int n6 = i; - int n7 = i * n; - for (int j = 0; j < n; ++j) { - int n8; - int n9; - int n10; - float f = 0.0f; - float f2 = 0.0f; - float f3 = 0.0f; - float f4 = 0.0f; - int n11 = n5; - for (n10 = -n5; n10 <= n5; ++n10) { - float f5 = fArray[n11 + n10]; - if (f5 == 0.0f) continue; - n9 = j + n10; - if (n9 < 0) { - if (n3 == 1) { - n9 = 0; - } else if (n3 == 2) { - n9 = (j + n) % n; + public static void convolve(Kernel kernel, int[] src, int[] dst, int width, int height, boolean alphaChannel, boolean premultiply, boolean unpremultiply, int edgeAction) { + float[] kernelData = kernel.getKernelData(null); + int kernelWidth = kernel.getWidth(); + int half = kernelWidth / 2; + for (int i = 0; i < height; ++i) { + int dstIndex = i; + int srcRowStart = i * width; + for (int j = 0; j < width; ++j) { + int argb; + int srcX; + int k; + float red = 0.0f; + float green = 0.0f; + float blue = 0.0f; + float alpha = 0.0f; + int kernelOffset = half; + for (k = -half; k <= half; ++k) { + float weight = kernelData[kernelOffset + k]; + if (weight == 0.0f) continue; + srcX = j + k; + if (srcX < 0) { + if (edgeAction == 1) { + srcX = 0; + } else if (edgeAction == 2) { + srcX = (j + width) % width; } - } else if (n9 >= n) { - if (n3 == 1) { - n9 = n - 1; - } else if (n3 == 2) { - n9 = (j + n) % n; + } else if (srcX >= width) { + if (edgeAction == 1) { + srcX = width - 1; + } else if (edgeAction == 2) { + srcX = (j + width) % width; } } - n8 = nArray[n7 + n9]; - int n12 = n8 >> 24 & 0xFF; - int n13 = n8 >> 16 & 0xFF; - int n14 = n8 >> 8 & 0xFF; - int n15 = n8 & 0xFF; - if (bl2) { - float f6 = (float)n12 * 0.003921569f; - n13 = (int)((float)n13 * f6); - n14 = (int)((float)n14 * f6); - n15 = (int)((float)n15 * f6); + argb = src[srcRowStart + srcX]; + int a = argb >> 24 & 0xFF; + int r = argb >> 16 & 0xFF; + int g = argb >> 8 & 0xFF; + int b = argb & 0xFF; + if (premultiply) { + float scale = (float)a * 0.003921569f; + r = (int)((float)r * scale); + g = (int)((float)g * scale); + b = (int)((float)b * scale); } - f4 += f5 * (float)n12; - f += f5 * (float)n13; - f2 += f5 * (float)n14; - f3 += f5 * (float)n15; + alpha += weight * (float)a; + red += weight * (float)r; + green += weight * (float)g; + blue += weight * (float)b; } - if (bl3 && f4 != 0.0f && f4 != 255.0f) { - float f7 = 255.0f / f4; - f *= f7; - f2 *= f7; - f3 *= f7; + if (unpremultiply && alpha != 0.0f && alpha != 255.0f) { + float invAlpha = 255.0f / alpha; + red *= invAlpha; + green *= invAlpha; + blue *= invAlpha; } - n10 = bl ? GaussianBlur.clamp((int)((double)f4 + 0.5)) : 255; - int n16 = GaussianBlur.clamp((int)((double)f + 0.5)); - n9 = GaussianBlur.clamp((int)((double)f2 + 0.5)); - n8 = GaussianBlur.clamp((int)((double)f3 + 0.5)); - nArray2[n6] = n10 << 24 | n16 << 16 | n9 << 8 | n8; - n6 += n2; + k = alphaChannel ? GaussianBlur.clamp((int)((double)alpha + 0.5)) : 255; + int outR = GaussianBlur.clamp((int)((double)red + 0.5)); + srcX = GaussianBlur.clamp((int)((double)green + 0.5)); + argb = GaussianBlur.clamp((int)((double)blue + 0.5)); + dst[dstIndex] = k << 24 | outR << 16 | srcX << 8 | argb; + dstIndex += height; } } } - public static int clamp(int n) { - if (n < 0) { + public static int clamp(int value) { + if (value < 0) { return 0; } - return Math.min(n, 255); + return Math.min(value, 255); } - public static Kernel makeKernel(float f) { - int n; - int n2 = (int)Math.ceil(f); - int n3 = n2 * 2 + 1; - float[] fArray = new float[n3]; - float f2 = f / 3.0f; - float f3 = 2.0f * f2 * f2; - float f4 = (float)Math.PI * 2 * f2; - float f5 = (float)Math.sqrt(f4); - float f6 = f * f; - float f7 = 0.0f; - int n4 = 0; - for (n = -n2; n <= n2; ++n) { - float f8 = n * n; - fArray[n4] = f8 > f6 ? 0.0f : (float)Math.exp(-f8 / f3) / f5; - f7 += fArray[n4]; - ++n4; + public static Kernel makeKernel(float radius) { + int i; + int kernelHalf = (int)Math.ceil(radius); + int kernelSize = kernelHalf * 2 + 1; + float[] kernelData = new float[kernelSize]; + float sigma = radius / 3.0f; + float twoSigmaSq = 2.0f * sigma * sigma; + float sigmaSqTwoPi = (float)Math.PI * 2 * sigma; + float sqrtTwoPiSigma = (float)Math.sqrt(sigmaSqTwoPi); + float radiusSq = radius * radius; + float sum = 0.0f; + int index = 0; + for (i = -kernelHalf; i <= kernelHalf; ++i) { + float distSq = i * i; + kernelData[index] = distSq > radiusSq ? 0.0f : (float)Math.exp(-distSq / twoSigmaSq) / sqrtTwoPiSigma; + sum += kernelData[index]; + ++index; } - for (n = 0; n < n3; ++n) { - fArray[n] = fArray[n] / f7; + for (i = 0; i < kernelSize; ++i) { + kernelData[i] = kernelData[i] / sum; } - return new Kernel(n3, 1, fArray); + return new Kernel(kernelSize, 1, kernelData); } - public void setRadius(float f) { - this.radius = f; - this.kernel = GaussianBlur.makeKernel(f); + public void setRadius(float radius) { + this.radius = radius; + this.kernel = GaussianBlur.makeKernel(radius); } - public BufferedImage filter(BufferedImage bufferedImage, BufferedImage bufferedImage2) { - int n = bufferedImage.getWidth(); - int n2 = bufferedImage.getHeight(); - if (bufferedImage2 == null) { - bufferedImage2 = this.createCompatibleDestImage(bufferedImage, null); + public BufferedImage filter(BufferedImage source, BufferedImage dest) { + int width = source.getWidth(); + int height = source.getHeight(); + if (dest == null) { + dest = this.createCompatibleDestImage(source, null); } - int[] nArray = new int[n * n2]; - int[] nArray2 = new int[n * n2]; - bufferedImage.getRGB(0, 0, n, n2, nArray, 0, n); + int[] srcPixels = new int[width * height]; + int[] dstPixels = new int[width * height]; + source.getRGB(0, 0, width, height, srcPixels, 0, width); if (this.radius > 0.0f) { - GaussianBlur.convolve(this.kernel, nArray, nArray2, n, n2, true, true, false, 1); - GaussianBlur.convolve(this.kernel, nArray2, nArray, n2, n, true, false, true, 1); + GaussianBlur.convolve(this.kernel, srcPixels, dstPixels, width, height, true, true, false, 1); + GaussianBlur.convolve(this.kernel, dstPixels, srcPixels, height, width, true, false, true, 1); } - bufferedImage2.setRGB(0, 0, n, n2, nArray, 0, n); - return bufferedImage2; + dest.setRGB(0, 0, width, height, srcPixels, 0, width); + return dest; } - public BufferedImage createCompatibleDestImage(BufferedImage bufferedImage, ColorModel colorModel) { + public BufferedImage createCompatibleDestImage(BufferedImage source, ColorModel colorModel) { if (colorModel == null) { - colorModel = bufferedImage.getColorModel(); + colorModel = source.getColorModel(); } - return new BufferedImage(colorModel, colorModel.createCompatibleWritableRaster(bufferedImage.getWidth(), bufferedImage.getHeight()), colorModel.isAlphaPremultiplied(), null); + return new BufferedImage(colorModel, colorModel.createCompatibleWritableRaster(source.getWidth(), source.getHeight()), colorModel.isAlphaPremultiplied(), null); } public String toString() { diff --git a/src/main/java/shit/zen/render/GlHelper.java b/src/main/java/shit/zen/render/GlHelper.java index 72cf137..836f9d7 100644 --- a/src/main/java/shit/zen/render/GlHelper.java +++ b/src/main/java/shit/zen/render/GlHelper.java @@ -23,182 +23,182 @@ public final class GlHelper { return drawContext; } - public static float drawText(String string, float f, float f2, FontRenderer fontRenderer, int n) { - Paint paint = GlHelper.toPaint(n); - return GlHelper.drawTextFormatted(string, f, f2, fontRenderer, paint, false); + public static float drawText(String text, float x, float y, FontRenderer fontRenderer, int color) { + Paint paint = GlHelper.toPaint(color); + return GlHelper.drawTextFormatted(text, x, y, fontRenderer, paint, false); } public static int getFontAscent(FontRenderer fontRenderer) { GlyphMetrics glyphMetrics = fontRenderer.getMetrics(); - float f = (glyphMetrics.getLineGap() - glyphMetrics.ascent() - glyphMetrics.descent()) / 2.0f; - return (int)Math.ceil(f); + float ascent = (glyphMetrics.getLineGap() - glyphMetrics.ascent() - glyphMetrics.descent()) / 2.0f; + return (int)Math.ceil(ascent); } public static Texture wrapTexture(AbstractTexture abstractTexture) { if (abstractTexture == null) { return null; } - int n = abstractTexture.getId(); - int n2 = GL11.glGetTexLevelParameteri(3553, 0, 4096); - int n3 = GL11.glGetTexLevelParameteri(3553, 0, 4097); - if (n2 <= 0) { - n2 = 64; + int glId = abstractTexture.getId(); + int width = GL11.glGetTexLevelParameteri(3553, 0, 4096); + int height = GL11.glGetTexLevelParameteri(3553, 0, 4097); + if (width <= 0) { + width = 64; } - if (n3 <= 0) { - n3 = 64; + if (height <= 0) { + height = 64; } - return new Texture(n, n2, n3); + return new Texture(glId, width, height); } - public static void drawPlayerHead(AbstractClientPlayer abstractClientPlayer, float f, float f2, float f3, float f4, float f5) { - GlHelper.drawPlayerHeadRounded(abstractClientPlayer, f, f2, f3, f4, f5, 0.0f); + public static void drawPlayerHead(AbstractClientPlayer player, float x, float y, float width, float height, float alpha) { + GlHelper.drawPlayerHeadRounded(player, x, y, width, height, alpha, 0.0f); } - public static void drawPlayerHeadRounded(AbstractClientPlayer abstractClientPlayer, float f, float f2, float f3, float f4, float f5, float f6) { - ResourceLocation resourceLocation = abstractClientPlayer.getSkinTextureLocation(); + public static void drawPlayerHeadRounded(AbstractClientPlayer player, float x, float y, float width, float height, float alpha, float radius) { + ResourceLocation resourceLocation = player.getSkinTextureLocation(); if (resourceLocation == null || ClientBase.mc.getTextureManager().getTexture(resourceLocation) == null) { return; } AbstractTexture abstractTexture = ClientBase.mc.getTextureManager().getTexture(resourceLocation); - int n = abstractTexture.getId(); + int glId = abstractTexture.getId(); DrawContext drawContext = GlHelper.getCanvas(); - int n2 = (int)Math.max(0.0f, Math.min(255.0f, f5 * 255.0f)) << 24 | 0xFFFFFF; + int packedColor = (int)Math.max(0.0f, Math.min(255.0f, alpha * 255.0f)) << 24 | 0xFFFFFF; RoundedRectShader roundedRectShader = DrawContext.getRoundedRectShader(); - float f7 = 0.125f; - float f8 = 0.125f; - float f9 = 0.25f; - float f10 = 0.25f; - float f11 = 0.625f; - float f12 = 0.125f; - float f13 = 0.75f; - float f14 = 0.25f; - Matrix4f matrix4f = drawContext.getPoseStack().last().pose(); - roundedRectShader.drawTextured(matrix4f, f, f2, f + f3, f2 + f4, f6, f6, f6, f6, n2, n, f7, f8, f9, f10); - roundedRectShader.drawTextured(matrix4f, f, f2, f + f3, f2 + f4, f6, f6, f6, f6, n2, n, f11, f12, f13, f14); - if (abstractClientPlayer.hurtTime > 0) { - int n3 = ColorUtil.withAlphaColor(new Color(255, 0, 0, abstractClientPlayer.hurtTime * 18), f5).getRGB(); - Paint paint = new Paint().setColor(n3); - drawContext.drawRoundedRect(RoundedRectangle.ofXYWHR(f, f2, f3, f4, f6), paint); + float baseU1 = 0.125f; + float baseV1 = 0.125f; + float baseU2 = 0.25f; + float baseV2 = 0.25f; + float hatU1 = 0.625f; + float hatV1 = 0.125f; + float hatU2 = 0.75f; + float hatV2 = 0.25f; + Matrix4f pose = drawContext.getPoseStack().last().pose(); + roundedRectShader.drawTextured(pose, x, y, x + width, y + height, radius, radius, radius, radius, packedColor, glId, baseU1, baseV1, baseU2, baseV2); + roundedRectShader.drawTextured(pose, x, y, x + width, y + height, radius, radius, radius, radius, packedColor, glId, hatU1, hatV1, hatU2, hatV2); + if (player.hurtTime > 0) { + int hurtColor = ColorUtil.withAlphaColor(new Color(255, 0, 0, player.hurtTime * 18), alpha).getRGB(); + Paint paint = new Paint().setColor(hurtColor); + drawContext.drawRoundedRect(RoundedRectangle.ofXYWHR(x, y, width, height, radius), paint); } } - public static float drawTextFormatted(String string, float f, float f2, FontRenderer fontRenderer, Paint paint, boolean bl) { - if (string == null || string.isEmpty()) { - return f; + public static float drawTextFormatted(String text, float x, float y, FontRenderer fontRenderer, Paint paint, boolean keepColor) { + if (text == null || text.isEmpty()) { + return x; } DrawContext drawContext = GlHelper.getCanvas(); - int n = paint.getColor(); - float f3 = f; - float f4 = f2 + (float)GlHelper.getFontAscent(fontRenderer); - String[] stringArray = string.split("§"); - for (int i = 0; i < stringArray.length; ++i) { - char c; + int color = paint.getColor(); + float cursorX = x; + float baselineY = y + (float)GlHelper.getFontAscent(fontRenderer); + String[] parts = text.split("§"); + for (int i = 0; i < parts.length; ++i) { + char code; ChatFormatting chatFormatting; - String string2 = stringArray[i]; - if (i > 0 && !string2.isEmpty() && (chatFormatting = ChatFormatting.getByCode(c = string2.charAt(0))) != null) { - if (!bl && chatFormatting.getColor() != null) { - n = ColorUtil.withAlpha(chatFormatting.getColor(), (float)(n >> 24 & 0xFF) / 255.0f); + String part = parts[i]; + if (i > 0 && !part.isEmpty() && (chatFormatting = ChatFormatting.getByCode(code = part.charAt(0))) != null) { + if (!keepColor && chatFormatting.getColor() != null) { + color = ColorUtil.withAlpha(chatFormatting.getColor(), (float)(color >> 24 & 0xFF) / 255.0f); } - string2 = string2.substring(1); + part = part.substring(1); } - drawContext.drawString(string2, f3, f4, fontRenderer, paint.setColor(n)); - f3 += GlHelper.getStringWidth(string2, fontRenderer); + drawContext.drawString(part, cursorX, baselineY, fontRenderer, paint.setColor(color)); + cursorX += GlHelper.getStringWidth(part, fontRenderer); } - return f3; + return cursorX; } - public static float drawTextWithShadow(String string, float f, float f2, FontRenderer fontRenderer, Paint paint) { - int n = paint.getColor(); - GlHelper.drawTextFormatted(string, f + 0.5f, f2 + 0.5f, fontRenderer, paint.setColor(ColorUtil.fromARGB(0, 0, 0, (int)((float)ColorUtil.getAlpha(paint.getColor()) * 0.65f * 255.0f))), true); - paint.setColor(n); - return GlHelper.drawTextFormatted(string, f, f2, fontRenderer, paint, false); + public static float drawTextWithShadow(String text, float x, float y, FontRenderer fontRenderer, Paint paint) { + int color = paint.getColor(); + GlHelper.drawTextFormatted(text, x + 0.5f, y + 0.5f, fontRenderer, paint.setColor(ColorUtil.fromARGB(0, 0, 0, (int)((float)ColorUtil.getAlpha(paint.getColor()) * 0.65f * 255.0f))), true); + paint.setColor(color); + return GlHelper.drawTextFormatted(text, x, y, fontRenderer, paint, false); } - public static float drawTextShadowLegacy(String string, float f, float f2, FontRenderer fontRenderer, int n) { - Paint paint = GlHelper.toPaint(n); - float f3 = (float)(n >> 24 & 0xFF) / 255.0f; - GlHelper.drawTextFormatted(string, f + 0.5f, f2 + 0.5f, fontRenderer, GlHelper.toPaint(ColorUtil.fromARGB(0, 0, 0, (int)(f3 * 0.65f * 255.0f))), true); - return GlHelper.drawTextFormatted(string, f, f2, fontRenderer, paint, false); + public static float drawTextShadowLegacy(String text, float x, float y, FontRenderer fontRenderer, int color) { + Paint paint = GlHelper.toPaint(color); + float alpha = (float)(color >> 24 & 0xFF) / 255.0f; + GlHelper.drawTextFormatted(text, x + 0.5f, y + 0.5f, fontRenderer, GlHelper.toPaint(ColorUtil.fromARGB(0, 0, 0, (int)(alpha * 0.65f * 255.0f))), true); + return GlHelper.drawTextFormatted(text, x, y, fontRenderer, paint, false); } - public static float drawTextBlurred(String string, float f, float f2, FontRenderer fontRenderer, int n, int n2, float f3) { - if (string == null || string.isEmpty()) { - return f; + public static float drawTextBlurred(String text, float x, float y, FontRenderer fontRenderer, int color, int blurColor, float radius) { + if (text == null || text.isEmpty()) { + return x; } DrawContext drawContext = GlHelper.getCanvas(); - float f4 = fontRenderer.getWidth(string); - float f5 = fontRenderer.getFont() != null ? fontRenderer.getFont().getFontHeight() : fontRenderer.getSize(); - float f6 = Math.max(0.01f, f3 * 0.5f); - drawContext.drawBlur(f, f2 - f5, f4, f5 * 2.0f, f6, () -> drawContext.drawString(string, f, f2, fontRenderer, GlHelper.toPaint(n2))); - return GlHelper.drawText(string, f, f2, fontRenderer, n); + float width = fontRenderer.getWidth(text); + float height = fontRenderer.getFont() != null ? fontRenderer.getFont().getFontHeight() : fontRenderer.getSize(); + float halfBlur = Math.max(0.01f, radius * 0.5f); + drawContext.drawBlur(x, y - height, width, height * 2.0f, halfBlur, () -> drawContext.drawString(text, x, y, fontRenderer, GlHelper.toPaint(blurColor))); + return GlHelper.drawText(text, x, y, fontRenderer, color); } - public static float drawTextCentered(float f, float f2, String string, FontRenderer fontRenderer, Paint paint) { - float f3 = fontRenderer.getWidth(string); - float f4 = fontRenderer.getFont() != null ? fontRenderer.getFont().getFontHeight() : fontRenderer.getSize(); - return GlHelper.drawTextFormatted(string, f - f3 / 2.0f, f2 - f4 / 2.0f, fontRenderer, paint, false); + public static float drawTextCentered(float centerX, float centerY, String text, FontRenderer fontRenderer, Paint paint) { + float width = fontRenderer.getWidth(text); + float height = fontRenderer.getFont() != null ? fontRenderer.getFont().getFontHeight() : fontRenderer.getSize(); + return GlHelper.drawTextFormatted(text, centerX - width / 2.0f, centerY - height / 2.0f, fontRenderer, paint, false); } - public static Paint toPaint(Object object) { + public static Paint toPaint(Object source) { Paint paint = new Paint(); - if (object instanceof float[]) { - paint.setColorFromArray((float[])object); - } else if (object instanceof Color color) { + if (source instanceof float[]) { + paint.setColorFromArray((float[])source); + } else if (source instanceof Color color) { paint.setColorARGB(color.getAlpha(), color.getRed(), color.getGreen(), color.getBlue()); - } else if (object instanceof Integer n) { - paint.setColor(n); + } else if (source instanceof Integer color) { + paint.setColor(color); } return paint; } - public static float getStringWidth(String string2, FontRenderer fontRenderer2) { - if (string2 == null || string2.isEmpty()) { + public static float getStringWidth(String text, FontRenderer fontRenderer) { + if (text == null || text.isEmpty()) { return 0.0f; } - return stringWidthCache.computeIfAbsent(fontRenderer2, fontRenderer -> new HashMap<>()).computeIfAbsent(string2, string -> string != null ? fontRenderer2.getWidth(string.replaceAll("§.", "")) : 0.0f); + return stringWidthCache.computeIfAbsent(fontRenderer, key -> new HashMap<>()).computeIfAbsent(text, key -> key != null ? fontRenderer.getWidth(key.replaceAll("§.", "")) : 0.0f); } - public static void drawRoundedRect(float f, float f2, float f3, float f4, float f5, Paint paint) { - GlHelper.getCanvas().drawRoundedRect(RoundedRectangle.ofXYWHR(f, f2, f3, f4, f5), paint); + public static void drawRoundedRect(float x, float y, float width, float height, float radius, Paint paint) { + GlHelper.getCanvas().drawRoundedRect(RoundedRectangle.ofXYWHR(x, y, width, height, radius), paint); } - public static void drawRoundedRectCorners(float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8, Paint paint) { - float[] fArray = new float[]{f5, f5, f6, f6, f7, f7, f8, f8}; - GlHelper.getCanvas().drawRoundedRect(RoundedRectangle.ofXYWHRadii(f, f2, f3, f4, fArray), paint); + public static void drawRoundedRectCorners(float x, float y, float width, float height, float tlRadius, float trRadius, float brRadius, float blRadius, Paint paint) { + float[] radii = new float[]{tlRadius, tlRadius, trRadius, trRadius, brRadius, brRadius, blRadius, blRadius}; + GlHelper.getCanvas().drawRoundedRect(RoundedRectangle.ofXYWHRadii(x, y, width, height, radii), paint); } private static int colorToInt(Color color) { return color.getAlpha() << 24 | color.getRed() << 16 | color.getGreen() << 8 | color.getBlue(); } - public static void drawGradientRoundedRect(float f, float f2, float f3, float f4, float f5, Color color, Color color2) { - Paint.GradientCoords paint$GradientCoords = new Paint.GradientCoords(f, f2, f, f2 + f4, GlHelper.colorToInt(color), GlHelper.colorToInt(color2)); - Paint paint = new Paint().setGradCoords(paint$GradientCoords); - GlHelper.getCanvas().drawRoundedRect(RoundedRectangle.ofXYWHR(f, f2, f3, f4, f5), paint); + public static void drawGradientRoundedRect(float x, float y, float width, float height, float radius, Color color, Color color2) { + Paint.GradientCoords gradCoords = new Paint.GradientCoords(x, y, x, y + height, GlHelper.colorToInt(color), GlHelper.colorToInt(color2)); + Paint paint = new Paint().setGradCoords(gradCoords); + GlHelper.getCanvas().drawRoundedRect(RoundedRectangle.ofXYWHR(x, y, width, height, radius), paint); } - public static void drawBlurredRoundedRectColor(float f, float f2, float f3, float f4, float f5, Color color, float f6, float f7, float f8) { - GlHelper.getCanvas().drawBlurredRoundedRect(RoundedRectangle.ofXYWHR(f, f2, f3, f4, f5), f7, f8, f6, 1.0f, color.getRGB()); + public static void drawBlurredRoundedRectColor(float x, float y, float width, float height, float radius, Color color, float blurRadius, float offsetX, float offsetY) { + GlHelper.getCanvas().drawBlurredRoundedRect(RoundedRectangle.ofXYWHR(x, y, width, height, radius), offsetX, offsetY, blurRadius, 1.0f, color.getRGB()); } - public static void drawShadowRoundedRect(float f, float f2, float f3, float f4, float f5, Color color) { - GlHelper.getCanvas().drawBlurredRoundedRect(RoundedRectangle.ofXYWHR(f, f2, f3, f4, f5), 0.0f, 0.0f, 10.0f, 1.0f, color.getRGB()); + public static void drawShadowRoundedRect(float x, float y, float width, float height, float radius, Color color) { + GlHelper.getCanvas().drawBlurredRoundedRect(RoundedRectangle.ofXYWHR(x, y, width, height, radius), 0.0f, 0.0f, 10.0f, 1.0f, color.getRGB()); } - public static void drawRoundedRectCornersColor(float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8, Color color) { - float[] fArray = new float[]{f5, f5, f6, f6, f7, f7, f8, f8}; - GlHelper.getCanvas().drawBlurredRoundedRect(RoundedRectangle.ofXYWHRadii(f, f2, f3, f4, fArray), 0.0f, 0.0f, 10.0f, 1.0f, color.getRGB()); + public static void drawRoundedRectCornersColor(float x, float y, float width, float height, float tlRadius, float trRadius, float brRadius, float blRadius, Color color) { + float[] radii = new float[]{tlRadius, tlRadius, trRadius, trRadius, brRadius, brRadius, blRadius, blRadius}; + GlHelper.getCanvas().drawBlurredRoundedRect(RoundedRectangle.ofXYWHRadii(x, y, width, height, radii), 0.0f, 0.0f, 10.0f, 1.0f, color.getRGB()); } - public static void drawRect(float f, float f2, float f3, float f4, Paint paint) { - GlHelper.getCanvas().drawRect(Rectangle.ofXYWH(f, f2, f3, f4), paint); + public static void drawRect(float x, float y, float width, float height, Paint paint) { + GlHelper.getCanvas().drawRect(Rectangle.ofXYWH(x, y, width, height), paint); } - public static void drawLine(float f, float f2, float f3, float f4, float f5, int n) { - Paint paint = GlHelper.toPaint(n); - paint.setStrokeWidth(f5); + public static void drawLine(float x1, float y1, float x2, float y2, float strokeWidth, int color) { + Paint paint = GlHelper.toPaint(color); + paint.setStrokeWidth(strokeWidth); paint.setStrokeCap(Paint.StrokeCap.STROKE); - GlHelper.getCanvas().drawLine(f, f2, f3, f4, paint); + GlHelper.getCanvas().drawLine(x1, y1, x2, y2, paint); } static { diff --git a/src/main/java/shit/zen/render/GlyphPage.java b/src/main/java/shit/zen/render/GlyphPage.java index 18cb842..50eeead 100644 --- a/src/main/java/shit/zen/render/GlyphPage.java +++ b/src/main/java/shit/zen/render/GlyphPage.java @@ -35,12 +35,12 @@ class GlyphPage { int imageHeight; boolean uploaded = false; - public GlyphPage(char c, char c2, Font font, ResourceLocation resourceLocation, int n) { - this.startChar = c; - this.endChar = c2; + public GlyphPage(char startChar, char endChar, Font font, ResourceLocation textureLocation, int padding) { + this.startChar = startChar; + this.endChar = endChar; this.font = font; - this.textureLocation = resourceLocation; - this.padding = n; + this.textureLocation = textureLocation; + this.padding = padding; } public Glyph getGlyph(char c) { @@ -106,12 +106,12 @@ class GlyphPage { curX += width + this.padding; ++colCount; } - BufferedImage bufferedImage = new BufferedImage( + BufferedImage atlasImage = new BufferedImage( Math.max(maxWidth + this.padding, 1), Math.max(maxHeight + this.padding, 1), 2); - this.imageWidth = bufferedImage.getWidth(); - this.imageHeight = bufferedImage.getHeight(); - java.awt.Graphics2D graphics = bufferedImage.createGraphics(); + this.imageWidth = atlasImage.getWidth(); + this.imageHeight = atlasImage.getHeight(); + java.awt.Graphics2D graphics = atlasImage.createGraphics(); graphics.setColor(new Color(255, 255, 255, 1)); graphics.fillRect(0, 0, this.imageWidth, this.imageHeight); graphics.setColor(Color.WHITE); @@ -126,39 +126,39 @@ class GlyphPage { graphics.drawString(String.valueOf(glyph.value()), glyph.u(), glyph.v() + fontMetrics.getAscent()); this.glyphMap.put(glyph.value(), glyph); } - GlyphPage.uploadTexture(this.textureLocation, bufferedImage); + GlyphPage.uploadTexture(this.textureLocation, atlasImage); this.uploaded = true; } - public static void uploadTexture(ResourceLocation resourceLocation, BufferedImage bufferedImage) { + public static void uploadTexture(ResourceLocation resourceLocation, BufferedImage source) { try { - int n = bufferedImage.getWidth(); - int n2 = bufferedImage.getHeight(); - NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, n, n2, false); - long l = (Long)ReflectionUtil.getStaticField(nativeImage, "pixels", "com/mojang/blaze3d/platform/NativeImage"); - IntBuffer intBuffer = MemoryUtil.memIntBuffer(l, nativeImage.getWidth() * nativeImage.getHeight()); - boolean bl = false; - WritableRaster writableRaster = bufferedImage.getRaster(); - ColorModel colorModel = bufferedImage.getColorModel(); - int n3 = writableRaster.getNumBands(); - int n4 = writableRaster.getDataBuffer().getDataType(); - Object pixelData = switch (n4) { - case 0 -> new byte[n3]; - case 1 -> new short[n3]; - case 3 -> new int[n3]; - case 4 -> new float[n3]; - case 5 -> new double[n3]; - default -> throw new IllegalArgumentException("Unknown data buffer type: " + n4); + int width = source.getWidth(); + int height = source.getHeight(); + NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, width, height, false); + long pixelsPtr = (Long)ReflectionUtil.getStaticField(nativeImage, "pixels", "com/mojang/blaze3d/platform/NativeImage"); + IntBuffer intBuffer = MemoryUtil.memIntBuffer(pixelsPtr, nativeImage.getWidth() * nativeImage.getHeight()); + boolean unused = false; + WritableRaster raster = source.getRaster(); + ColorModel colorModel = source.getColorModel(); + int numBands = raster.getNumBands(); + int dataType = raster.getDataBuffer().getDataType(); + Object pixelData = switch (dataType) { + case 0 -> new byte[numBands]; + case 1 -> new short[numBands]; + case 3 -> new int[numBands]; + case 4 -> new float[numBands]; + case 5 -> new double[numBands]; + default -> throw new IllegalArgumentException("Unknown data buffer type: " + dataType); }; - for (int i = 0; i < n2; ++i) { - for (int j = 0; j < n; ++j) { - writableRaster.getDataElements(j, i, pixelData); - int n5 = colorModel.getAlpha(pixelData); - int n6 = colorModel.getRed(pixelData); - int n7 = colorModel.getGreen(pixelData); - int n8 = colorModel.getBlue(pixelData); - int n9 = n5 << 24 | n8 << 16 | n7 << 8 | n6; - intBuffer.put(n9); + for (int i = 0; i < height; ++i) { + for (int j = 0; j < width; ++j) { + raster.getDataElements(j, i, pixelData); + int a = colorModel.getAlpha(pixelData); + int r = colorModel.getRed(pixelData); + int g = colorModel.getGreen(pixelData); + int b = colorModel.getBlue(pixelData); + int abgr = a << 24 | b << 16 | g << 8 | r; + intBuffer.put(abgr); } } DynamicTexture dynamicTexture = new DynamicTexture(nativeImage); diff --git a/src/main/java/shit/zen/render/GradientFactory.java b/src/main/java/shit/zen/render/GradientFactory.java index 01f5be1..6fe84fe 100644 --- a/src/main/java/shit/zen/render/GradientFactory.java +++ b/src/main/java/shit/zen/render/GradientFactory.java @@ -3,7 +3,7 @@ package shit.zen.render; import shit.zen.render.Paint.LinearGradient; public final class GradientFactory { - public static Paint.LinearGradient buildLinearGradient(float[] fArray, float f) { - return new Paint.LinearGradient(fArray, f); + public static Paint.LinearGradient buildLinearGradient(float[] stops, float angle) { + return new Paint.LinearGradient(stops, angle); } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/GradientHelper.java b/src/main/java/shit/zen/render/GradientHelper.java index 5c1c704..87e4323 100644 --- a/src/main/java/shit/zen/render/GradientHelper.java +++ b/src/main/java/shit/zen/render/GradientHelper.java @@ -3,13 +3,13 @@ package shit.zen.render; import shit.zen.render.Paint.GradientCoords; public final class GradientHelper { - public static Paint.GradientCoords createLinearGradientEx(float f, float f2, float f3, float f4, int[] nArray, float[] fArray, Object object) { - int n = nArray.length > 0 ? nArray[0] : 0; - int n2 = nArray.length > 1 ? nArray[nArray.length - 1] : n; - return new Paint.GradientCoords(f, f2, f3, f4, n, n2); + public static Paint.GradientCoords createLinearGradientEx(float x1, float y1, float x2, float y2, int[] colors, float[] stops, Object tileMode) { + int firstColor = colors.length > 0 ? colors[0] : 0; + int lastColor = colors.length > 1 ? colors[colors.length - 1] : firstColor; + return new Paint.GradientCoords(x1, y1, x2, y2, firstColor, lastColor); } - public static Paint.GradientCoords createLinearGradient(float f, float f2, float f3, float f4, int[] nArray) { - return GradientHelper.createLinearGradientEx(f, f2, f3, f4, nArray, null, null); + public static Paint.GradientCoords createLinearGradient(float x1, float y1, float x2, float y2, int[] colors) { + return GradientHelper.createLinearGradientEx(x1, y1, x2, y2, colors, null, null); } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/Paint.java b/src/main/java/shit/zen/render/Paint.java index beda8f5..8f35c65 100644 --- a/src/main/java/shit/zen/render/Paint.java +++ b/src/main/java/shit/zen/render/Paint.java @@ -42,50 +42,50 @@ implements AutoCloseable { private Object shader; private boolean antialias = true; - public Paint setColor(int n) { - this.color = n; + public Paint setColor(int color) { + this.color = color; return this; } - public Paint setColorFromArray(float[] fArray) { - int n = (int)Math.max(0.0f, Math.min(255.0f, fArray[3] * 255.0f)); - int n2 = (int)Math.max(0.0f, Math.min(255.0f, fArray[0] * 255.0f)); - int n3 = (int)Math.max(0.0f, Math.min(255.0f, fArray[1] * 255.0f)); - int n4 = (int)Math.max(0.0f, Math.min(255.0f, fArray[2] * 255.0f)); - this.color = n << 24 | n2 << 16 | n3 << 8 | n4; + public Paint setColorFromArray(float[] rgba) { + int a = (int)Math.max(0.0f, Math.min(255.0f, rgba[3] * 255.0f)); + int r = (int)Math.max(0.0f, Math.min(255.0f, rgba[0] * 255.0f)); + int g = (int)Math.max(0.0f, Math.min(255.0f, rgba[1] * 255.0f)); + int b = (int)Math.max(0.0f, Math.min(255.0f, rgba[2] * 255.0f)); + this.color = a << 24 | r << 16 | g << 8 | b; return this; } - public Paint setColorARGB(int n, int n2, int n3, int n4) { - this.color = (n & 0xFF) << 24 | (n2 & 0xFF) << 16 | (n3 & 0xFF) << 8 | n4 & 0xFF; + public Paint setColorARGB(int a, int r, int g, int b) { + this.color = (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | b & 0xFF; return this; } - public Paint setAlpha(float f) { - int n = (int)Math.max(0.0f, Math.min(255.0f, f * 255.0f)); - this.color = this.color & 0xFFFFFF | n << 24; + public Paint setAlpha(float alpha) { + int a = (int)Math.max(0.0f, Math.min(255.0f, alpha * 255.0f)); + this.color = this.color & 0xFFFFFF | a << 24; return this; } - public Paint setStrokeWidth(float f) { - this.strokeWidth = f; + public Paint setStrokeWidth(float strokeWidth) { + this.strokeWidth = strokeWidth; return this; } - public Paint setStrokeCap(Paint.StrokeCap paint$StrokeCap) { - this.capStyle = paint$StrokeCap; + public Paint setStrokeCap(Paint.StrokeCap capStyle) { + this.capStyle = capStyle; return this; } - public Paint setStrokeJoin(Paint.StrokeJoin paint$StrokeJoin) { - this.joinStyle = paint$StrokeJoin; + public Paint setStrokeJoin(Paint.StrokeJoin joinStyle) { + this.joinStyle = joinStyle; return this; } - public Paint setMaskFilter(Object object) { - if (object instanceof Paint.BlurMaskFilter) { - this.blurRadius = ((Paint.BlurMaskFilter)object).blurRadius; - } else if (object == null) { + public Paint setMaskFilter(Object maskFilter) { + if (maskFilter instanceof Paint.BlurMaskFilter) { + this.blurRadius = ((Paint.BlurMaskFilter)maskFilter).blurRadius; + } else if (maskFilter == null) { this.blurRadius = 0.0f; } return this; @@ -101,13 +101,13 @@ implements AutoCloseable { return this; } - public Paint setShader(Object object) { - this.shader = object; + public Paint setShader(Object shader) { + this.shader = shader; return this; } - public Paint setAntialias(boolean bl) { - this.antialias = bl; + public Paint setAntialias(boolean antialias) { + this.antialias = antialias; return this; } diff --git a/src/main/java/shit/zen/render/PathMeasure.java b/src/main/java/shit/zen/render/PathMeasure.java index 5711cc4..d427bcb 100644 --- a/src/main/java/shit/zen/render/PathMeasure.java +++ b/src/main/java/shit/zen/render/PathMeasure.java @@ -5,99 +5,99 @@ implements AutoCloseable { private final float totalLength; public PathMeasure(Path path) { - float f = 0.0f; - float f2 = 0.0f; - float f3 = 0.0f; - float f4 = 0.0f; - float f5 = 0.0f; + float length = 0.0f; + float currX = 0.0f; + float currY = 0.0f; + float startX = 0.0f; + float startY = 0.0f; if (path != null) { block7: for (Path.PathSegment path$PathSegment : path.getSegments()) { switch (path$PathSegment.type) { case MOVE_TO: { - f2 = path$PathSegment.coords[0]; - f3 = path$PathSegment.coords[1]; - f4 = f2; - f5 = f3; + currX = path$PathSegment.coords[0]; + currY = path$PathSegment.coords[1]; + startX = currX; + startY = currY; continue block7; } case LINE_TO: { - float f6 = path$PathSegment.coords[0]; - float f7 = path$PathSegment.coords[1]; - f += (float)Math.hypot(f6 - f2, f7 - f3); - f2 = f6; - f3 = f7; + float endX = path$PathSegment.coords[0]; + float endY = path$PathSegment.coords[1]; + length += (float)Math.hypot(endX - currX, endY - currY); + currX = endX; + currY = endY; continue block7; } case QUAD_TO: { - float f6 = path$PathSegment.coords[0]; - float f7 = path$PathSegment.coords[1]; - float f8 = path$PathSegment.coords[2]; - float f9 = path$PathSegment.coords[3]; - f += PathMeasure.quadraticBezierLength(f2, f3, f6, f7, f8, f9); - f2 = f8; - f3 = f9; + float ctrlX = path$PathSegment.coords[0]; + float ctrlY = path$PathSegment.coords[1]; + float endX = path$PathSegment.coords[2]; + float endY = path$PathSegment.coords[3]; + length += PathMeasure.quadraticBezierLength(currX, currY, ctrlX, ctrlY, endX, endY); + currX = endX; + currY = endY; continue block7; } case CUBIC_TO: { - float f6 = path$PathSegment.coords[0]; - float f7 = path$PathSegment.coords[1]; - float f8 = path$PathSegment.coords[2]; - float f9 = path$PathSegment.coords[3]; - float f10 = path$PathSegment.coords[4]; - float f11 = path$PathSegment.coords[5]; - f += PathMeasure.cubicBezierLength(f2, f3, f6, f7, f8, f9, f10, f11); - f2 = f10; - f3 = f11; + float ctrlX = path$PathSegment.coords[0]; + float ctrlY = path$PathSegment.coords[1]; + float ctrl2X = path$PathSegment.coords[2]; + float ctrl2Y = path$PathSegment.coords[3]; + float endX = path$PathSegment.coords[4]; + float endY = path$PathSegment.coords[5]; + length += PathMeasure.cubicBezierLength(currX, currY, ctrlX, ctrlY, ctrl2X, ctrl2Y, endX, endY); + currX = endX; + currY = endY; continue block7; } case CLOSE: { - f += (float)Math.hypot(f4 - f2, f5 - f3); - f2 = f4; - f3 = f5; + length += (float)Math.hypot(startX - currX, startY - currY); + currX = startX; + currY = startY; continue block7; } } } } - this.totalLength = f; + this.totalLength = length; } public float getLength() { return this.totalLength; } - private static float quadraticBezierLength(float f, float f2, float f3, float f4, float f5, float f6) { - float f7 = 0.0f; - float f8 = f; - float f9 = f2; - int n = 16; - for (int i = 1; i <= n; ++i) { - float f10 = (float)i / (float)n; - float f11 = 1.0f - f10; - float f12 = f11 * f11 * f + 2.0f * f11 * f10 * f3 + f10 * f10 * f5; - float f13 = f11 * f11 * f2 + 2.0f * f11 * f10 * f4 + f10 * f10 * f6; - f7 += (float)Math.hypot(f12 - f8, f13 - f9); - f8 = f12; - f9 = f13; + private static float quadraticBezierLength(float p0x, float p0y, float p1x, float p1y, float p2x, float p2y) { + float length = 0.0f; + float prevX = p0x; + float prevY = p0y; + int steps = 16; + for (int i = 1; i <= steps; ++i) { + float t = (float)i / (float)steps; + float oneMinusT = 1.0f - t; + float x = oneMinusT * oneMinusT * p0x + 2.0f * oneMinusT * t * p1x + t * t * p2x; + float y = oneMinusT * oneMinusT * p0y + 2.0f * oneMinusT * t * p1y + t * t * p2y; + length += (float)Math.hypot(x - prevX, y - prevY); + prevX = x; + prevY = y; } - return f7; + return length; } - private static float cubicBezierLength(float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8) { - float f9 = 0.0f; - float f10 = f; - float f11 = f2; - int n = 24; - for (int i = 1; i <= n; ++i) { - float f12 = (float)i / (float)n; - float f13 = 1.0f - f12; - float f14 = f13 * f13 * f13 * f + 3.0f * f13 * f13 * f12 * f3 + 3.0f * f13 * f12 * f12 * f5 + f12 * f12 * f12 * f7; - float f15 = f13 * f13 * f13 * f2 + 3.0f * f13 * f13 * f12 * f4 + 3.0f * f13 * f12 * f12 * f6 + f12 * f12 * f12 * f8; - f9 += (float)Math.hypot(f14 - f10, f15 - f11); - f10 = f14; - f11 = f15; + private static float cubicBezierLength(float p0x, float p0y, float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { + float length = 0.0f; + float prevX = p0x; + float prevY = p0y; + int steps = 24; + for (int i = 1; i <= steps; ++i) { + float t = (float)i / (float)steps; + float oneMinusT = 1.0f - t; + float x = oneMinusT * oneMinusT * oneMinusT * p0x + 3.0f * oneMinusT * oneMinusT * t * p1x + 3.0f * oneMinusT * t * t * p2x + t * t * t * p3x; + float y = oneMinusT * oneMinusT * oneMinusT * p0y + 3.0f * oneMinusT * oneMinusT * t * p1y + 3.0f * oneMinusT * t * t * p2y + t * t * t * p3y; + length += (float)Math.hypot(x - prevX, y - prevY); + prevX = x; + prevY = y; } - return f9; + return length; } public void close() { diff --git a/src/main/java/shit/zen/render/Rectangle.java b/src/main/java/shit/zen/render/Rectangle.java index 7763ac8..e1a6a4d 100644 --- a/src/main/java/shit/zen/render/Rectangle.java +++ b/src/main/java/shit/zen/render/Rectangle.java @@ -2,12 +2,12 @@ package shit.zen.render; public record Rectangle(float x1, float y1, float x2, float y2) { - public static Rectangle ofXYWH(float f, float f2, float f3, float f4) { - return new Rectangle(f, f2, f + f3, f2 + f4); + public static Rectangle ofXYWH(float x, float y, float width, float height) { + return new Rectangle(x, y, x + width, y + height); } - public static Rectangle ofCorners(float f, float f2, float f3, float f4) { - return new Rectangle(f, f2, f3, f4); + public static Rectangle ofCorners(float x1, float y1, float x2, float y2) { + return new Rectangle(x1, y1, x2, y2); } public float getWidth() { diff --git a/src/main/java/shit/zen/render/Renderer.java b/src/main/java/shit/zen/render/Renderer.java index 8c997b9..f962878 100644 --- a/src/main/java/shit/zen/render/Renderer.java +++ b/src/main/java/shit/zen/render/Renderer.java @@ -37,9 +37,9 @@ extends ClientBase { Renderer.setGuiScale((float)mc.getWindow().getGuiScale()); } - public static void setGuiScale(float f) { + public static void setGuiScale(float scale) { RenderSystem.assertOnRenderThread(); - guiScale = f; + guiScale = scale; Renderer.verify(); } @@ -92,12 +92,12 @@ extends ClientBase { RenderSystem.defaultBlendFunc(); RenderSystem.disableCull(); DrawContext drawContext = new DrawContext(guiGraphics); - DrawContext drawContext2 = currentCanvas; + DrawContext previousCanvas = currentCanvas; currentCanvas = drawContext; try { consumer.accept(drawContext); } finally { - currentCanvas = drawContext2; + currentCanvas = previousCanvas; drawContext.clearClipStack(); } Renderer.resetRenderState(); @@ -111,7 +111,7 @@ extends ClientBase { Renderer.render(null, consumer); } - public static void setGuiScaleVerified(float f) { - Renderer.setGuiScale(f); + public static void setGuiScaleVerified(float scale) { + Renderer.setGuiScale(scale); } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/RoundedRectShader.java b/src/main/java/shit/zen/render/RoundedRectShader.java index 57d3ab1..b8f9321 100644 --- a/src/main/java/shit/zen/render/RoundedRectShader.java +++ b/src/main/java/shit/zen/render/RoundedRectShader.java @@ -31,25 +31,25 @@ public final class RoundedRectShader { if (this.programId != 0) { return; } - int n = RoundedRectShader.compileShader(35633, "#version 150\nin vec2 Position;\nin vec2 LocalPos;\nin vec2 UV;\nuniform mat4 ModelViewMat;\nuniform mat4 ProjMat;\nout vec2 localPos;\nout vec2 uvCoord;\nvoid main() {\n gl_Position = ProjMat * ModelViewMat * vec4(Position, 0.0, 1.0);\n localPos = LocalPos;\n uvCoord = UV;\n}\n"); - int n2 = RoundedRectShader.compileShader(35632, "#version 150\nuniform vec2 HalfSize;\nuniform vec4 Radii;\nuniform vec4 Color1;\nuniform vec4 Color2;\nuniform int UseGradient;\nuniform int UseTexture;\nuniform sampler2D Sampler0;\nuniform float StrokeWidth;\nin vec2 localPos;\nin vec2 uvCoord;\nout vec4 fragColor;\nvoid main() {\n vec2 p = localPos;\n float r;\n if (p.x < 0.0) {\n r = (p.y < 0.0) ? Radii.x : Radii.w;\n } else {\n r = (p.y < 0.0) ? Radii.y : Radii.z;\n }\n vec2 q = abs(p) - HalfSize + r;\n float d = length(max(q, vec2(0.0))) + min(max(q.x, q.y), 0.0) - r;\n float alpha;\n if (StrokeWidth > 0.0) {\n float halfStroke = StrokeWidth * 0.5;\n alpha = 1.0 - smoothstep(halfStroke - 0.5, halfStroke + 0.5, abs(d));\n } else {\n alpha = 1.0 - smoothstep(-0.5, 0.5, d);\n }\n vec4 col;\n if (UseTexture == 1) {\n col = texture(Sampler0, uvCoord) * Color1;\n } else if (UseGradient == 1) {\n float t = clamp((p.y + HalfSize.y) / max(2.0 * HalfSize.y, 0.0001), 0.0, 1.0);\n col = mix(Color1, Color2, t);\n } else {\n col = Color1;\n }\n fragColor = vec4(col.rgb, col.a * alpha);\n}\n"); - int n3 = GL20.glCreateProgram(); - GL20.glAttachShader(n3, n); - GL20.glAttachShader(n3, n2); - GL20.glBindAttribLocation(n3, 0, "Position"); - GL20.glBindAttribLocation(n3, 1, "LocalPos"); - GL20.glBindAttribLocation(n3, 2, "UV"); - GL20.glLinkProgram(n3); - if (GL20.glGetProgrami(n3, 35714) == 0) { - String string = GL20.glGetProgramInfoLog(n3); - GL20.glDeleteProgram(n3); - GL20.glDeleteShader(n); - GL20.glDeleteShader(n2); - throw new IllegalStateException("RoundedRectShader link failed: " + string); + int vertexShader = RoundedRectShader.compileShader(35633, "#version 150\nin vec2 Position;\nin vec2 LocalPos;\nin vec2 UV;\nuniform mat4 ModelViewMat;\nuniform mat4 ProjMat;\nout vec2 localPos;\nout vec2 uvCoord;\nvoid main() {\n gl_Position = ProjMat * ModelViewMat * vec4(Position, 0.0, 1.0);\n localPos = LocalPos;\n uvCoord = UV;\n}\n"); + int fragmentShader = RoundedRectShader.compileShader(35632, "#version 150\nuniform vec2 HalfSize;\nuniform vec4 Radii;\nuniform vec4 Color1;\nuniform vec4 Color2;\nuniform int UseGradient;\nuniform int UseTexture;\nuniform sampler2D Sampler0;\nuniform float StrokeWidth;\nin vec2 localPos;\nin vec2 uvCoord;\nout vec4 fragColor;\nvoid main() {\n vec2 p = localPos;\n float r;\n if (p.x < 0.0) {\n r = (p.y < 0.0) ? Radii.x : Radii.w;\n } else {\n r = (p.y < 0.0) ? Radii.y : Radii.z;\n }\n vec2 q = abs(p) - HalfSize + r;\n float d = length(max(q, vec2(0.0))) + min(max(q.x, q.y), 0.0) - r;\n float alpha;\n if (StrokeWidth > 0.0) {\n float halfStroke = StrokeWidth * 0.5;\n alpha = 1.0 - smoothstep(halfStroke - 0.5, halfStroke + 0.5, abs(d));\n } else {\n alpha = 1.0 - smoothstep(-0.5, 0.5, d);\n }\n vec4 col;\n if (UseTexture == 1) {\n col = texture(Sampler0, uvCoord) * Color1;\n } else if (UseGradient == 1) {\n float t = clamp((p.y + HalfSize.y) / max(2.0 * HalfSize.y, 0.0001), 0.0, 1.0);\n col = mix(Color1, Color2, t);\n } else {\n col = Color1;\n }\n fragColor = vec4(col.rgb, col.a * alpha);\n}\n"); + int program = GL20.glCreateProgram(); + GL20.glAttachShader(program, vertexShader); + GL20.glAttachShader(program, fragmentShader); + GL20.glBindAttribLocation(program, 0, "Position"); + GL20.glBindAttribLocation(program, 1, "LocalPos"); + GL20.glBindAttribLocation(program, 2, "UV"); + GL20.glLinkProgram(program); + if (GL20.glGetProgrami(program, 35714) == 0) { + String log = GL20.glGetProgramInfoLog(program); + GL20.glDeleteProgram(program); + GL20.glDeleteShader(vertexShader); + GL20.glDeleteShader(fragmentShader); + throw new IllegalStateException("RoundedRectShader link failed: " + log); } - GL20.glDeleteShader(n); - GL20.glDeleteShader(n2); - this.programId = n3; + GL20.glDeleteShader(vertexShader); + GL20.glDeleteShader(fragmentShader); + this.programId = program; this.uModelViewMat = GL20.glGetUniformLocation(this.programId, "ModelViewMat"); this.uProjMat = GL20.glGetUniformLocation(this.programId, "ProjMat"); this.uHalfSize = GL20.glGetUniformLocation(this.programId, "HalfSize"); @@ -62,70 +62,70 @@ public final class RoundedRectShader { this.uStrokeWidth = GL20.glGetUniformLocation(this.programId, "StrokeWidth"); this.vaoId = GL30.glGenVertexArrays(); this.vboId = GL15.glGenBuffers(); - int n4 = GL11.glGetInteger(34229); - int n5 = GL11.glGetInteger(34964); + int prevVao = GL11.glGetInteger(34229); + int prevVbo = GL11.glGetInteger(34964); GL30.glBindVertexArray(this.vaoId); GL15.glBindBuffer(34962, this.vboId); GL15.glBufferData(34962, 144L, 35048); - int n6 = 24; + int stride = 24; GL20.glEnableVertexAttribArray(0); - GL20.glVertexAttribPointer(0, 2, 5126, false, n6, 0L); + GL20.glVertexAttribPointer(0, 2, 5126, false, stride, 0L); GL20.glEnableVertexAttribArray(1); - GL20.glVertexAttribPointer(1, 2, 5126, false, n6, 8L); + GL20.glVertexAttribPointer(1, 2, 5126, false, stride, 8L); GL20.glEnableVertexAttribArray(2); - GL20.glVertexAttribPointer(2, 2, 5126, false, n6, 16L); - GL30.glBindVertexArray(n4); - GL15.glBindBuffer(34962, n5); + GL20.glVertexAttribPointer(2, 2, 5126, false, stride, 16L); + GL30.glBindVertexArray(prevVao); + GL15.glBindBuffer(34962, prevVbo); } - public void draw(Matrix4f matrix4f, float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8, int n, int n2, boolean bl, float f9) { - this.drawInternal(matrix4f, f, f2, f3, f4, f5, f6, f7, f8, n, n2, bl, f9, -1, 0.0f, 0.0f, 1.0f, 1.0f); + public void draw(Matrix4f pose, float x1, float y1, float x2, float y2, float tlRadius, float trRadius, float brRadius, float blRadius, int color1, int color2, boolean useGradient, float strokeWidth) { + this.drawInternal(pose, x1, y1, x2, y2, tlRadius, trRadius, brRadius, blRadius, color1, color2, useGradient, strokeWidth, -1, 0.0f, 0.0f, 1.0f, 1.0f); } - public void drawTextured(Matrix4f matrix4f, float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8, int n, int n2, float f9, float f10, float f11, float f12) { - this.drawInternal(matrix4f, f, f2, f3, f4, f5, f6, f7, f8, n, n, false, 0.0f, n2, f9, f10, f11, f12); + public void drawTextured(Matrix4f pose, float x1, float y1, float x2, float y2, float tlRadius, float trRadius, float brRadius, float blRadius, int color, int textureId, float u1, float v1, float u2, float v2) { + this.drawInternal(pose, x1, y1, x2, y2, tlRadius, trRadius, brRadius, blRadius, color, color, false, 0.0f, textureId, u1, v1, u2, v2); } - private void drawInternal(Matrix4f matrix4f, float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8, int n, int n2, boolean bl, float f9, int n3, float f10, float f11, float f12, float f13) { - int n4; + private void drawInternal(Matrix4f pose, float x1, float y1, float x2, float y2, float tlRadius, float trRadius, float brRadius, float blRadius, int color1, int color2, boolean useGradient, float strokeWidth, int textureId, float u1, float v1, float u2, float v2) { + int i; this.init(); - float f14 = (f + f3) * 0.5f; - float f15 = (f2 + f4) * 0.5f; - float f16 = (f3 - f) * 0.5f; - float f17 = (f4 - f2) * 0.5f; - if (f16 <= 0.0f || f17 <= 0.0f) { + float centerX = (x1 + x2) * 0.5f; + float centerY = (y1 + y2) * 0.5f; + float halfWidth = (x2 - x1) * 0.5f; + float halfHeight = (y2 - y1) * 0.5f; + if (halfWidth <= 0.0f || halfHeight <= 0.0f) { return; } - float f18 = Math.min(f16, f17); - f5 = Math.min(Math.max(f5, 0.0f), f18); - f6 = Math.min(Math.max(f6, 0.0f), f18); - f7 = Math.min(Math.max(f7, 0.0f), f18); - f8 = Math.min(Math.max(f8, 0.0f), f18); - float f19 = f16 + 1.0f; - float f20 = f17 + 1.0f; - Vector4f vector4f = new Vector4f(); - float[] fArray = new float[36]; - float[][] fArrayArray = new float[][]{{-f19, -f20}, {f19, -f20}, {f19, f20}, {-f19, -f20}, {f19, f20}, {-f19, f20}}; - for (n4 = 0; n4 < 6; ++n4) { - vector4f.set(f14 + fArrayArray[n4][0], f15 + fArrayArray[n4][1], 0.0f, 1.0f).mul(matrix4f); - float f21 = fArrayArray[n4][0]; - float f22 = fArrayArray[n4][1]; - float f23 = f10 + (f21 + f16) / (2.0f * f16) * (f12 - f10); - float f24 = f11 + (f22 + f17) / (2.0f * f17) * (f13 - f11); - int n5 = n4 * 6; - fArray[n5] = vector4f.x; - fArray[n5 + 1] = vector4f.y; - fArray[n5 + 2] = f21; - fArray[n5 + 3] = f22; - fArray[n5 + 4] = f23; - fArray[n5 + 5] = f24; + float maxRadius = Math.min(halfWidth, halfHeight); + tlRadius = Math.min(Math.max(tlRadius, 0.0f), maxRadius); + trRadius = Math.min(Math.max(trRadius, 0.0f), maxRadius); + brRadius = Math.min(Math.max(brRadius, 0.0f), maxRadius); + blRadius = Math.min(Math.max(blRadius, 0.0f), maxRadius); + float expandedHalfW = halfWidth + 1.0f; + float expandedHalfH = halfHeight + 1.0f; + Vector4f vertexPos = new Vector4f(); + float[] vertexData = new float[36]; + float[][] cornerOffsets = new float[][]{{-expandedHalfW, -expandedHalfH}, {expandedHalfW, -expandedHalfH}, {expandedHalfW, expandedHalfH}, {-expandedHalfW, -expandedHalfH}, {expandedHalfW, expandedHalfH}, {-expandedHalfW, expandedHalfH}}; + for (i = 0; i < 6; ++i) { + vertexPos.set(centerX + cornerOffsets[i][0], centerY + cornerOffsets[i][1], 0.0f, 1.0f).mul(pose); + float localX = cornerOffsets[i][0]; + float localY = cornerOffsets[i][1]; + float u = u1 + (localX + halfWidth) / (2.0f * halfWidth) * (u2 - u1); + float v = v1 + (localY + halfHeight) / (2.0f * halfHeight) * (v2 - v1); + int base = i * 6; + vertexData[base] = vertexPos.x; + vertexData[base + 1] = vertexPos.y; + vertexData[base + 2] = localX; + vertexData[base + 3] = localY; + vertexData[base + 4] = u; + vertexData[base + 5] = v; } - n4 = GL11.glGetInteger(35725); - int n6 = GL11.glGetInteger(34229); - int n7 = GL11.glGetInteger(34964); - int n8 = GL11.glGetInteger(34016); + i = GL11.glGetInteger(35725); + int prevVao = GL11.glGetInteger(34229); + int prevVbo = GL11.glGetInteger(34964); + int prevActiveTex = GL11.glGetInteger(34016); GL13.glActiveTexture(33984); - int n9 = GL11.glGetInteger(32873); + int prevTex2d = GL11.glGetInteger(32873); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.disableCull(); @@ -133,37 +133,37 @@ public final class RoundedRectShader { GL30.glBindVertexArray(this.vaoId); GL15.glBindBuffer(34962, this.vboId); try (MemoryStack memoryStack = MemoryStack.stackPush()){ - FloatBuffer floatBuffer = memoryStack.mallocFloat(fArray.length); - floatBuffer.put(fArray).flip(); - GL15.glBufferSubData(34962, 0L, floatBuffer); - FloatBuffer floatBuffer2 = memoryStack.mallocFloat(16); - RenderSystem.getModelViewMatrix().get(floatBuffer2); - GL20.glUniformMatrix4fv(this.uModelViewMat, false, floatBuffer2); - FloatBuffer floatBuffer3 = memoryStack.mallocFloat(16); - RenderSystem.getProjectionMatrix().get(floatBuffer3); - GL20.glUniformMatrix4fv(this.uProjMat, false, floatBuffer3); + FloatBuffer vertexBuffer = memoryStack.mallocFloat(vertexData.length); + vertexBuffer.put(vertexData).flip(); + GL15.glBufferSubData(34962, 0L, vertexBuffer); + FloatBuffer modelViewBuffer = memoryStack.mallocFloat(16); + RenderSystem.getModelViewMatrix().get(modelViewBuffer); + GL20.glUniformMatrix4fv(this.uModelViewMat, false, modelViewBuffer); + FloatBuffer projBuffer = memoryStack.mallocFloat(16); + RenderSystem.getProjectionMatrix().get(projBuffer); + GL20.glUniformMatrix4fv(this.uProjMat, false, projBuffer); } - GL20.glUniform2f(this.uHalfSize, f16, f17); - GL20.glUniform4f(this.uRadii, f5, f6, f7, f8); - GL20.glUniform4f(this.uColor1, (float)(n >> 16 & 0xFF) / 255.0f, (float)(n >> 8 & 0xFF) / 255.0f, (float)(n & 0xFF) / 255.0f, (float)(n >>> 24 & 0xFF) / 255.0f); - GL20.glUniform4f(this.uColor2, (float)(n2 >> 16 & 0xFF) / 255.0f, (float)(n2 >> 8 & 0xFF) / 255.0f, (float)(n2 & 0xFF) / 255.0f, (float)(n2 >>> 24 & 0xFF) / 255.0f); - GL20.glUniform1i(this.uUseGradient, bl ? 1 : 0); - GL20.glUniform1f(this.uStrokeWidth, Math.max(0.0f, f9)); - if (n3 > 0) { + GL20.glUniform2f(this.uHalfSize, halfWidth, halfHeight); + GL20.glUniform4f(this.uRadii, tlRadius, trRadius, brRadius, blRadius); + GL20.glUniform4f(this.uColor1, (float)(color1 >> 16 & 0xFF) / 255.0f, (float)(color1 >> 8 & 0xFF) / 255.0f, (float)(color1 & 0xFF) / 255.0f, (float)(color1 >>> 24 & 0xFF) / 255.0f); + GL20.glUniform4f(this.uColor2, (float)(color2 >> 16 & 0xFF) / 255.0f, (float)(color2 >> 8 & 0xFF) / 255.0f, (float)(color2 & 0xFF) / 255.0f, (float)(color2 >>> 24 & 0xFF) / 255.0f); + GL20.glUniform1i(this.uUseGradient, useGradient ? 1 : 0); + GL20.glUniform1f(this.uStrokeWidth, Math.max(0.0f, strokeWidth)); + if (textureId > 0) { GL20.glUniform1i(this.uUseTexture, 1); GL20.glUniform1i(this.uSampler0, 0); - GL11.glBindTexture(3553, n3); + GL11.glBindTexture(3553, textureId); GL11.glTexParameteri(3553, 10241, 9728); GL11.glTexParameteri(3553, 10240, 9728); } else { GL20.glUniform1i(this.uUseTexture, 0); } GL11.glDrawArrays(4, 0, 6); - GL11.glBindTexture(3553, n9); - GL13.glActiveTexture(n8); - GL15.glBindBuffer(34962, n7); - GL30.glBindVertexArray(n6); - GL20.glUseProgram(n4); + GL11.glBindTexture(3553, prevTex2d); + GL13.glActiveTexture(prevActiveTex); + GL15.glBindBuffer(34962, prevVbo); + GL30.glBindVertexArray(prevVao); + GL20.glUseProgram(i); } public void dispose() { @@ -181,15 +181,15 @@ public final class RoundedRectShader { } } - private static int compileShader(int n, String string) { - int n2 = GL20.glCreateShader(n); - GL20.glShaderSource(n2, string); - GL20.glCompileShader(n2); - if (GL20.glGetShaderi(n2, 35713) == 0) { - String string2 = GL20.glGetShaderInfoLog(n2); - GL20.glDeleteShader(n2); - throw new IllegalStateException("RoundedRectShader shader compile failed: " + string2); + private static int compileShader(int type, String source) { + int shader = GL20.glCreateShader(type); + GL20.glShaderSource(shader, source); + GL20.glCompileShader(shader); + if (GL20.glGetShaderi(shader, 35713) == 0) { + String log = GL20.glGetShaderInfoLog(shader); + GL20.glDeleteShader(shader); + throw new IllegalStateException("RoundedRectShader shader compile failed: " + log); } - return n2; + return shader; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/RoundedRectangle.java b/src/main/java/shit/zen/render/RoundedRectangle.java index 5741028..d9dae51 100644 --- a/src/main/java/shit/zen/render/RoundedRectangle.java +++ b/src/main/java/shit/zen/render/RoundedRectangle.java @@ -10,30 +10,30 @@ public final class RoundedRectangle { public final float bottomRightRadius; public final float bottomLeftRadius; - private RoundedRectangle(float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8) { - this.x1 = f; - this.y1 = f2; - this.x2 = f3; - this.y2 = f4; - this.topLeftRadius = f5; - this.topRightRadius = f6; - this.bottomRightRadius = f7; - this.bottomLeftRadius = f8; + private RoundedRectangle(float x1, float y1, float x2, float y2, float tlRadius, float trRadius, float brRadius, float blRadius) { + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.topLeftRadius = tlRadius; + this.topRightRadius = trRadius; + this.bottomRightRadius = brRadius; + this.bottomLeftRadius = blRadius; } - public static RoundedRectangle ofXYWHR(float f, float f2, float f3, float f4, float f5) { - return new RoundedRectangle(f, f2, f + f3, f2 + f4, f5, f5, f5, f5); + public static RoundedRectangle ofXYWHR(float x, float y, float width, float height, float radius) { + return new RoundedRectangle(x, y, x + width, y + height, radius, radius, radius, radius); } - public static RoundedRectangle ofXYWHRadii(float f, float f2, float f3, float f4, float[] fArray) { - if (fArray.length >= 8) { - return new RoundedRectangle(f, f2, f + f3, f2 + f4, fArray[0], fArray[2], fArray[4], fArray[6]); + public static RoundedRectangle ofXYWHRadii(float x, float y, float width, float height, float[] radii) { + if (radii.length >= 8) { + return new RoundedRectangle(x, y, x + width, y + height, radii[0], radii[2], radii[4], radii[6]); } - if (fArray.length >= 4) { - return new RoundedRectangle(f, f2, f + f3, f2 + f4, fArray[0], fArray[1], fArray[2], fArray[3]); + if (radii.length >= 4) { + return new RoundedRectangle(x, y, x + width, y + height, radii[0], radii[1], radii[2], radii[3]); } - float f5 = fArray.length > 0 ? fArray[0] : 0.0f; - return new RoundedRectangle(f, f2, f + f3, f2 + f4, f5, f5, f5, f5); + float radius = radii.length > 0 ? radii[0] : 0.0f; + return new RoundedRectangle(x, y, x + width, y + height, radius, radius, radius, radius); } public float getWidth() { diff --git a/src/main/java/shit/zen/render/StencilHelper.java b/src/main/java/shit/zen/render/StencilHelper.java index 527e0c5..98fd001 100644 --- a/src/main/java/shit/zen/render/StencilHelper.java +++ b/src/main/java/shit/zen/render/StencilHelper.java @@ -28,66 +28,66 @@ public class StencilHelper { private static final Supplier contentTarget = Suppliers.memoize(() -> new TextureTarget(360, 360, false, Minecraft.ON_OSX)); private static final RenderTarget mainRenderTarget = ClientBase.mc.getMainRenderTarget(); - public static void applyStencil(PoseStack poseStack, Runnable runnable, Runnable runnable2, float f) { - Matrix4f matrix4f = poseStack.last().pose(); - RenderTarget renderTarget = maskTarget.get(); - if (renderTarget.width != StencilHelper.mainRenderTarget.width || renderTarget.height != StencilHelper.mainRenderTarget.height) { - renderTarget.resize(StencilHelper.mainRenderTarget.width, StencilHelper.mainRenderTarget.height, Minecraft.ON_OSX); + public static void applyStencil(PoseStack poseStack, Runnable drawMask, Runnable drawContent, float opacity) { + Matrix4f pose = poseStack.last().pose(); + RenderTarget mask = maskTarget.get(); + if (mask.width != StencilHelper.mainRenderTarget.width || mask.height != StencilHelper.mainRenderTarget.height) { + mask.resize(StencilHelper.mainRenderTarget.width, StencilHelper.mainRenderTarget.height, Minecraft.ON_OSX); } - renderTarget.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); - renderTarget.clear(Minecraft.ON_OSX); - renderTarget.bindWrite(false); - runnable.run(); - RenderTarget renderTarget2 = contentTarget.get(); - if (renderTarget2.width != StencilHelper.mainRenderTarget.width || renderTarget2.height != StencilHelper.mainRenderTarget.height) { - renderTarget2.resize(StencilHelper.mainRenderTarget.width, StencilHelper.mainRenderTarget.height, Minecraft.ON_OSX); + mask.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); + mask.clear(Minecraft.ON_OSX); + mask.bindWrite(false); + drawMask.run(); + RenderTarget content = contentTarget.get(); + if (content.width != StencilHelper.mainRenderTarget.width || content.height != StencilHelper.mainRenderTarget.height) { + content.resize(StencilHelper.mainRenderTarget.width, StencilHelper.mainRenderTarget.height, Minecraft.ON_OSX); } - renderTarget2.clear(Minecraft.ON_OSX); - renderTarget2.bindWrite(false); - runnable2.run(); + content.clear(Minecraft.ON_OSX); + content.bindWrite(false); + drawContent.run(); mainRenderTarget.bindWrite(false); RenderSystem.disableBlend(); stencilShader.use(); - GL20.glUniform1f(stencilShader.getUniformLocation("Opacity"), f); + GL20.glUniform1f(stencilShader.getUniformLocation("Opacity"), opacity); GL20.glUniform1i(stencilShader.getUniformLocation("StencilTexture"), 2); GL20.glUniform1i(stencilShader.getUniformLocation("TargetTexture"), 0); GL13.glActiveTexture(33986); - GlStateManager._bindTexture(renderTarget.getColorTextureId()); + GlStateManager._bindTexture(mask.getColorTextureId()); GL13.glActiveTexture(33984); - GlStateManager._bindTexture(renderTarget2.getColorTextureId()); + GlStateManager._bindTexture(content.getColorTextureId()); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - bufferBuilder.vertex(matrix4f, 0.0f, 0.0f, 0.0f).uv(0.0f, 1.0f).endVertex(); - bufferBuilder.vertex(matrix4f, 0.0f, (float)ClientBase.mc.getWindow().getGuiScaledHeight(), 0.0f).uv(0.0f, 0.0f).endVertex(); - bufferBuilder.vertex(matrix4f, (float)ClientBase.mc.getWindow().getGuiScaledWidth(), (float)ClientBase.mc.getWindow().getGuiScaledHeight(), 0.0f).uv(1.0f, 0.0f).endVertex(); - bufferBuilder.vertex(matrix4f, (float)ClientBase.mc.getWindow().getGuiScaledWidth(), 0.0f, 0.0f).uv(1.0f, 1.0f).endVertex(); + bufferBuilder.vertex(pose, 0.0f, 0.0f, 0.0f).uv(0.0f, 1.0f).endVertex(); + bufferBuilder.vertex(pose, 0.0f, (float)ClientBase.mc.getWindow().getGuiScaledHeight(), 0.0f).uv(0.0f, 0.0f).endVertex(); + bufferBuilder.vertex(pose, (float)ClientBase.mc.getWindow().getGuiScaledWidth(), (float)ClientBase.mc.getWindow().getGuiScaledHeight(), 0.0f).uv(1.0f, 0.0f).endVertex(); + bufferBuilder.vertex(pose, (float)ClientBase.mc.getWindow().getGuiScaledWidth(), 0.0f, 0.0f).uv(1.0f, 1.0f).endVertex(); BufferUploader.draw(bufferBuilder.end()); stencilShader.stopUsing(); RenderSystem.enableBlend(); } - public static void beginWrite(boolean bl) { - StencilHelper.beginWriteFull(bl, ClientBase.mc.getMainRenderTarget(), true, false); + public static void beginWrite(boolean keepColor) { + StencilHelper.beginWriteFull(keepColor, ClientBase.mc.getMainRenderTarget(), true, false); } - public static void beginWriteFull(boolean bl, RenderTarget renderTarget, boolean bl2, boolean bl3) { + public static void beginWriteFull(boolean keepColor, RenderTarget renderTarget, boolean clearStencil, boolean invertMask) { renderTarget.bindWrite(false); StencilHelper.setupFBO(renderTarget); GL11.glEnable(2960); - if (bl2) { + if (clearStencil) { GL11.glClearStencil(0); GL11.glClear(1024); } - GL11.glStencilFunc(519, bl3 ? 0 : 1, 255); + GL11.glStencilFunc(519, invertMask ? 0 : 1, 255); GL11.glStencilOp(7680, 7680, 7681); - if (!bl) { + if (!keepColor) { GlStateManager._colorMask(false, false, false, false); } } - public static void beginRead(boolean bl) { - GL11.glStencilFunc(bl ? 514 : 517, 1, 255); + public static void beginRead(boolean inside) { + GL11.glStencilFunc(inside ? 514 : 517, 1, 255); GL11.glStencilOp(7680, 7680, 7681); GlStateManager._colorMask(true, true, true, true); GlStateManager._enableBlend(); @@ -106,10 +106,10 @@ public class StencilHelper { public static void attachStencilBuffer(RenderTarget renderTarget) { EXTFramebufferObject.glDeleteRenderbuffersEXT(renderTarget.getDepthTextureId()); - int n = EXTFramebufferObject.glGenRenderbuffersEXT(); - EXTFramebufferObject.glBindRenderbufferEXT(36161, n); + int rbo = EXTFramebufferObject.glGenRenderbuffersEXT(); + EXTFramebufferObject.glBindRenderbufferEXT(36161, rbo); EXTFramebufferObject.glRenderbufferStorageEXT(36161, 34041, ClientBase.mc.getMainRenderTarget().width, ClientBase.mc.getMainRenderTarget().height); - EXTFramebufferObject.glFramebufferRenderbufferEXT(36160, 36128, 36161, n); - EXTFramebufferObject.glFramebufferRenderbufferEXT(36160, 36096, 36161, n); + EXTFramebufferObject.glFramebufferRenderbufferEXT(36160, 36128, 36161, rbo); + EXTFramebufferObject.glFramebufferRenderbufferEXT(36160, 36096, 36161, rbo); } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/TextGlow.java b/src/main/java/shit/zen/render/TextGlow.java index 5c3fa5f..1a9ddef 100644 --- a/src/main/java/shit/zen/render/TextGlow.java +++ b/src/main/java/shit/zen/render/TextGlow.java @@ -10,18 +10,18 @@ public final class TextGlow { private TextGlow() { } - public static void drawBackground(PoseStack poseStack, float f, float f2, float f3, float f4, float f5, float f6) { - int n = TextGlow.clampAlpha(150.0f * f6); - int n2 = TextGlow.clampAlpha(35.0f * f6); - RenderUtil.drawRoundedRect(poseStack, f, f2, f3, f4, f5, new Color(24, 24, 24, n).getRGB()); - RenderUtil.drawRoundedRect(poseStack, f, f2, f3, f4, f5, new Color(255, 255, 255, n2).getRGB()); + public static void drawBackground(PoseStack poseStack, float x, float y, float width, float height, float radius, float alpha) { + int darkAlpha = TextGlow.clampAlpha(150.0f * alpha); + int lightAlpha = TextGlow.clampAlpha(35.0f * alpha); + RenderUtil.drawRoundedRect(poseStack, x, y, width, height, radius, new Color(24, 24, 24, darkAlpha).getRGB()); + RenderUtil.drawRoundedRect(poseStack, x, y, width, height, radius, new Color(255, 255, 255, lightAlpha).getRGB()); } - public static float drawGlowText(String string, float f, float f2, FontRenderer fontRenderer, int n, int n2, float f3) { - return GlHelper.drawText(string, f, f2, fontRenderer, n); + public static float drawGlowText(String text, float x, float y, FontRenderer fontRenderer, int color, int glowColor, float radius) { + return GlHelper.drawText(text, x, y, fontRenderer, color); } - private static int clampAlpha(float f) { - return Math.max(0, Math.min(255, Math.round(f))); + private static int clampAlpha(float value) { + return Math.max(0, Math.min(255, Math.round(value))); } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/Texture.java b/src/main/java/shit/zen/render/Texture.java index 0e0c503..b8c512c 100644 --- a/src/main/java/shit/zen/render/Texture.java +++ b/src/main/java/shit/zen/render/Texture.java @@ -8,24 +8,24 @@ public final class Texture { private final int height; private final ResourceLocation resourceLocation; - public Texture(int n, int n2, int n3) { - this.glId = n; - this.width = n2; - this.height = n3; + public Texture(int glId, int width, int height) { + this.glId = glId; + this.width = width; + this.height = height; this.resourceLocation = null; } - public Texture(ResourceLocation resourceLocation, int n, int n2) { + public Texture(ResourceLocation resourceLocation, int width, int height) { this.glId = 0; - this.width = n; - this.height = n2; + this.width = width; + this.height = height; this.resourceLocation = resourceLocation; } - public Texture(int n, ResourceLocation resourceLocation, int n2, int n3) { - this.glId = n; - this.width = n2; - this.height = n3; + public Texture(int glId, ResourceLocation resourceLocation, int width, int height) { + this.glId = glId; + this.width = width; + this.height = height; this.resourceLocation = resourceLocation; } diff --git a/src/main/java/shit/zen/render/shader/BufferUtil.java b/src/main/java/shit/zen/render/shader/BufferUtil.java index b9829d6..bdb9de0 100644 --- a/src/main/java/shit/zen/render/shader/BufferUtil.java +++ b/src/main/java/shit/zen/render/shader/BufferUtil.java @@ -4,15 +4,15 @@ import java.nio.FloatBuffer; import org.joml.Matrix4f; public class BufferUtil { - public static void fill(FloatBuffer floatBuffer, float f) { - floatBuffer.clear(); - for (int i = 0; i < floatBuffer.capacity(); ++i) { - floatBuffer.put(i, f); + public static void fill(FloatBuffer buffer, float value) { + buffer.clear(); + for (int i = 0; i < buffer.capacity(); ++i) { + buffer.put(i, value); } - floatBuffer.clear(); + buffer.clear(); } - public static FloatBuffer storeMatrix(FloatBuffer floatBuffer, Matrix4f matrix4f) { - return matrix4f.get(floatBuffer); + public static FloatBuffer storeMatrix(FloatBuffer buffer, Matrix4f matrix) { + return matrix.get(buffer); } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/shader/Matrix4Uniform.java b/src/main/java/shit/zen/render/shader/Matrix4Uniform.java index 4e0a1b5..febfef6 100644 --- a/src/main/java/shit/zen/render/shader/Matrix4Uniform.java +++ b/src/main/java/shit/zen/render/shader/Matrix4Uniform.java @@ -17,32 +17,32 @@ extends Uniform { @Getter private final FloatBuffer stagingBuffer = MemoryUtil.memAllocFloat(16); - public Matrix4Uniform(String string) { - super(string); + public Matrix4Uniform(String name) { + super(name); } - public void upload(Matrix4f matrix4f) { + public void upload(Matrix4f matrix) { this.stagingBuffer.clear(); - BufferUtil.storeMatrix(this.stagingBuffer, matrix4f); + BufferUtil.storeMatrix(this.stagingBuffer, matrix); this.uploadRaw(false, this.stagingBuffer); } - public void uploadRaw(boolean bl, FloatBuffer floatBuffer) { - this.transpose = bl; - floatBuffer.mark(); + public void uploadRaw(boolean transpose, FloatBuffer buffer) { + this.transpose = transpose; + buffer.mark(); this.dataBuffer.clear(); - this.dataBuffer.put(floatBuffer); + this.dataBuffer.put(buffer); this.dataBuffer.rewind(); - floatBuffer.reset(); - int n = this.getLocation(); - if (n >= 0) { - GL20.glUniformMatrix4fv(n, bl, this.dataBuffer); + buffer.reset(); + int location = this.getLocation(); + if (location >= 0) { + GL20.glUniformMatrix4fv(location, transpose, this.dataBuffer); } } - public float getElement(int n, int n2) { - int n3 = this.transpose ? n2 * 4 + n : n * 4 + n2; - return this.dataBuffer.get(n3); + public float getElement(int row, int col) { + int index = this.transpose ? col * 4 + row : row * 4 + col; + return this.dataBuffer.get(index); } protected void clear() { diff --git a/src/main/java/shit/zen/render/shader/ShaderProgram.java b/src/main/java/shit/zen/render/shader/ShaderProgram.java index d176c14..65a74c2 100644 --- a/src/main/java/shit/zen/render/shader/ShaderProgram.java +++ b/src/main/java/shit/zen/render/shader/ShaderProgram.java @@ -30,29 +30,29 @@ public class ShaderProgram { private Matrix4f cachedProjection; private static int prevProgram; - public ShaderProgram(String string) { - this(string, "vertex", ShaderFormats.POSITION_UV, "ModelViewMat", "ProjMat"); + public ShaderProgram(String name) { + this(name, "vertex", ShaderFormats.POSITION_UV, "ModelViewMat", "ProjMat"); } - public ShaderProgram(String string, String string2, Supplier> supplier) { - this(string, string2, supplier, "ModelViewMat", "ProjMat"); + public ShaderProgram(String fragmentName, String vertexName, Supplier> attributesSupplier) { + this(fragmentName, vertexName, attributesSupplier, "ModelViewMat", "ProjMat"); } - public ShaderProgram(String string, Supplier> supplier) { - this(string, string, supplier, "ModelViewMat", "ProjMat"); + public ShaderProgram(String name, Supplier> attributesSupplier) { + this(name, name, attributesSupplier, "ModelViewMat", "ProjMat"); } - public ShaderProgram(String string, Supplier> supplier, String string2, String string3) { - this(string, string, supplier, string2, string3); + public ShaderProgram(String name, Supplier> attributesSupplier, String modelViewName, String projName) { + this(name, name, attributesSupplier, modelViewName, projName); } - public ShaderProgram(String string, String string2, Supplier> supplier, String string3, String string4) { + public ShaderProgram(String fragmentName, String vertexName, Supplier> attributesSupplier, String modelViewName, String projName) { this.programId = GL20.glCreateProgram(); - int n = ShaderProgram.compileShader(ShaderSource.getByFileName(string + ".fsh").getSource(), 35632); - int n2 = ShaderProgram.compileShader(ShaderSource.getByFileName(string2 + ".vsh").getSource(), 35633); - GL20.glAttachShader(this.programId, n); - GL20.glAttachShader(this.programId, n2); - for (Map.Entry entry : supplier.get().entrySet()) { + int fragmentShader = ShaderProgram.compileShader(ShaderSource.getByFileName(fragmentName + ".fsh").getSource(), 35632); + int vertexShader = ShaderProgram.compileShader(ShaderSource.getByFileName(vertexName + ".vsh").getSource(), 35633); + GL20.glAttachShader(this.programId, fragmentShader); + GL20.glAttachShader(this.programId, vertexShader); + for (Map.Entry entry : attributesSupplier.get().entrySet()) { GL20.glEnableVertexAttribArray(entry.getKey()); GL20.glBindAttribLocation(this.programId, entry.getKey(), entry.getValue()); } @@ -61,10 +61,10 @@ public class ShaderProgram { LOGGER.error(GL20.glGetProgramInfoLog(this.programId, Short.MAX_VALUE)); throw new IllegalStateException("Failed to link shader program!"); } - GL20.glDeleteShader(n); - GL20.glDeleteShader(n2); - this.modelViewUniform = new Matrix4Uniform(string3).bindToProgram(this.programId); - this.projectionUniform = new Matrix4Uniform(string4).bindToProgram(this.programId); + GL20.glDeleteShader(fragmentShader); + GL20.glDeleteShader(vertexShader); + this.modelViewUniform = new Matrix4Uniform(modelViewName).bindToProgram(this.programId); + this.projectionUniform = new Matrix4Uniform(projName).bindToProgram(this.programId); } public void use() { @@ -74,17 +74,17 @@ public class ShaderProgram { this.setProjection(RenderSystem.getProjectionMatrix()); } - public void setModelView(Matrix4f matrix4f) { - if (this.cachedModelView != matrix4f) { - this.modelViewUniform.upload(matrix4f); - this.cachedModelView = matrix4f; + public void setModelView(Matrix4f modelView) { + if (this.cachedModelView != modelView) { + this.modelViewUniform.upload(modelView); + this.cachedModelView = modelView; } } - public void setProjection(Matrix4f matrix4f) { - if (this.cachedProjection != matrix4f) { - this.projectionUniform.upload(matrix4f); - this.cachedProjection = matrix4f; + public void setProjection(Matrix4f projection) { + if (this.cachedProjection != projection) { + this.projectionUniform.upload(projection); + this.cachedProjection = projection; } } @@ -92,30 +92,30 @@ public class ShaderProgram { GL20.glUseProgram(prevProgram); } - public int getUniformLocation(String string) { - if (!this.uniformCache.containsKey(string)) { - this.uniformCache.put(string, GL20.glGetUniformLocation(this.programId, string)); + public int getUniformLocation(String uniformName) { + if (!this.uniformCache.containsKey(uniformName)) { + this.uniformCache.put(uniformName, GL20.glGetUniformLocation(this.programId, uniformName)); } - return this.uniformCache.get(string); + return this.uniformCache.get(uniformName); } - private static int compileShader(String string, int n) { - int n2 = GL20.glCreateShader(n); - Matcher matcher = ShaderFormats.IMPORT_PATTERN.matcher(string); + private static int compileShader(String source, int type) { + int shader = GL20.glCreateShader(type); + Matcher matcher = ShaderFormats.IMPORT_PATTERN.matcher(source); while (matcher.find()) { - boolean bl = matcher.group(2) == null; - if (!bl) continue; - String string2 = matcher.group(3); - String string3 = ShaderSource.getByFileName(string2).getSource(); - string = string.replaceAll(ShaderFormats.IMPORT_PATTERN.pattern(), string3); + boolean isPlainImport = matcher.group(2) == null; + if (!isPlainImport) continue; + String importName = matcher.group(3); + String importSource = ShaderSource.getByFileName(importName).getSource(); + source = source.replaceAll(ShaderFormats.IMPORT_PATTERN.pattern(), importSource); } - GL20.glShaderSource(n2, string); - GL20.glCompileShader(n2); - if (GL20.glGetShaderi(n2, 35713) == 0) { - LOGGER.error(GL20.glGetShaderInfoLog(n2, Short.MAX_VALUE)); - throw new IllegalStateException(String.format("Failed to compile shader! (Type: %s)", new Object[]{n})); + GL20.glShaderSource(shader, source); + GL20.glCompileShader(shader); + if (GL20.glGetShaderi(shader, 35713) == 0) { + LOGGER.error(GL20.glGetShaderInfoLog(shader, Short.MAX_VALUE)); + throw new IllegalStateException(String.format("Failed to compile shader! (Type: %s)", new Object[]{type})); } - return n2; + return shader; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/render/shader/ShaderSource.java b/src/main/java/shit/zen/render/shader/ShaderSource.java index b0ee329..b4925cb 100644 --- a/src/main/java/shit/zen/render/shader/ShaderSource.java +++ b/src/main/java/shit/zen/render/shader/ShaderSource.java @@ -23,14 +23,14 @@ public enum ShaderSource { private final String source; private static final HashMap BY_FILENAME; - public static ShaderSource getByFileName(String string) { - return BY_FILENAME.getOrDefault(string, SHADER_0); + public static ShaderSource getByFileName(String fileName) { + return BY_FILENAME.getOrDefault(fileName, SHADER_0); } @Generated - ShaderSource(String string2, String string3) { - this.fileName = string2; - this.source = string3; + ShaderSource(String fileName, String source) { + this.fileName = fileName; + this.source = source; } static { diff --git a/src/main/java/shit/zen/render/shader/Uniform.java b/src/main/java/shit/zen/render/shader/Uniform.java index 63ab463..2f7e437 100644 --- a/src/main/java/shit/zen/render/shader/Uniform.java +++ b/src/main/java/shit/zen/render/shader/Uniform.java @@ -12,14 +12,14 @@ public abstract class Uniform> { @Getter private int location; - public T bindToProgram(int n) { - this.programId = n; + public T bindToProgram(int programId) { + this.programId = programId; this.location = GL20.glGetUniformLocation(this.programId, this.name); return (T)this; } @Generated - public Uniform(String string) { - this.name = string; + public Uniform(String name) { + this.name = name; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/utils/ByteCipher.java b/src/main/java/shit/zen/utils/ByteCipher.java index f326eb6..dbd313a 100644 --- a/src/main/java/shit/zen/utils/ByteCipher.java +++ b/src/main/java/shit/zen/utils/ByteCipher.java @@ -6,24 +6,24 @@ import java.util.Arrays; public class ByteCipher { private final byte[] key; - public ByteCipher(byte[] byArray) { - this.key = Arrays.copyOf(byArray, byArray.length); + public ByteCipher(byte[] keyBytes) { + this.key = Arrays.copyOf(keyBytes, keyBytes.length); } - public byte[] encrypt(byte[] byArray, int n) { - byte[] byArray2 = new byte[byArray.length]; - for (int i = 0; i < byArray.length; ++i) { - byArray2[i] = (byte)(byArray[i] + this.key[i % this.key.length] + n); + public byte[] encrypt(byte[] input, int shift) { + byte[] output = new byte[input.length]; + for (int i = 0; i < input.length; ++i) { + output[i] = (byte)(input[i] + this.key[i % this.key.length] + shift); } - return byArray2; + return output; } - public byte[] decrypt(byte[] byArray, int n) { - byte[] byArray2 = new byte[byArray.length]; - for (int i = 0; i < byArray.length; ++i) { - byArray2[i] = (byte)(byArray[i] - this.key[i % this.key.length] - n); + public byte[] decrypt(byte[] input, int shift) { + byte[] output = new byte[input.length]; + for (int i = 0; i < input.length; ++i) { + output[i] = (byte)(input[i] - this.key[i % this.key.length] - shift); } - return byArray2; + return output; } static { diff --git a/src/main/java/shit/zen/utils/animation/AnimatedColor.java b/src/main/java/shit/zen/utils/animation/AnimatedColor.java index a8401f0..c54c3f9 100644 --- a/src/main/java/shit/zen/utils/animation/AnimatedColor.java +++ b/src/main/java/shit/zen/utils/animation/AnimatedColor.java @@ -19,19 +19,19 @@ public class AnimatedColor { @Getter @Setter private SmoothAnimationTimer aTimer = new SmoothAnimationTimer(); - public AnimatedColor(int n) { - this.color = n; + public AnimatedColor(int color) { + this.color = color; } - public void animateTo(int n, float f) { - this.animateTo(n, f, Easings.EASE_OUT_QUAD); + public void animateTo(int targetColor, float speed) { + this.animateTo(targetColor, speed, Easings.EASE_OUT_QUAD); } - public void animateTo(int n, float f, Easing easing) { - this.rTimer.animate(ColorUtil.getRed(n), 0.2 / (double)f, easing); - this.gTimer.animate(ColorUtil.getGreen(n), 0.2 / (double)f, easing); - this.bTimer.animate(ColorUtil.getBlue(n), 0.2 / (double)f, easing); - this.aTimer.animate(ColorUtil.getAlpha(n), 0.2 / (double)f, easing); + public void animateTo(int targetColor, float speed, Easing easing) { + this.rTimer.animate(ColorUtil.getRed(targetColor), 0.2 / (double)speed, easing); + this.gTimer.animate(ColorUtil.getGreen(targetColor), 0.2 / (double)speed, easing); + this.bTimer.animate(ColorUtil.getBlue(targetColor), 0.2 / (double)speed, easing); + this.aTimer.animate(ColorUtil.getAlpha(targetColor), 0.2 / (double)speed, easing); this.rTimer.tick(); this.gTimer.tick(); this.bTimer.tick(); diff --git a/src/main/java/shit/zen/utils/animation/AnimationBuilder.java b/src/main/java/shit/zen/utils/animation/AnimationBuilder.java index e77ee46..9b023b0 100644 --- a/src/main/java/shit/zen/utils/animation/AnimationBuilder.java +++ b/src/main/java/shit/zen/utils/animation/AnimationBuilder.java @@ -13,46 +13,46 @@ public class AnimationBuilder { private Easing easing = Easings.EASE_OUT_QUAD; private boolean debug = false; - public NamedAnimationTimer getOrCreate(String string) { - NamedAnimationTimer namedAnimationTimer2; - Optional optional = this.timers.stream().filter(namedAnimationTimer -> namedAnimationTimer.getName().equalsIgnoreCase(string)).findFirst(); - if (!optional.isPresent()) { - namedAnimationTimer2 = new NamedAnimationTimer(string, this); - this.timers.add(namedAnimationTimer2); + public NamedAnimationTimer getOrCreate(String name) { + NamedAnimationTimer timer; + Optional existing = this.timers.stream().filter(t -> t.getName().equalsIgnoreCase(name)).findFirst(); + if (!existing.isPresent()) { + timer = new NamedAnimationTimer(name, this); + this.timers.add(timer); } else { - namedAnimationTimer2 = optional.get(); + timer = existing.get(); } - return namedAnimationTimer2; + return timer; } - public AnimationBuilder animate(String string, double d, double d2) { - return this.animate(string, d, d2, Easings.EASE_OUT_QUAD); + public AnimationBuilder animate(String name, double target, double duration) { + return this.animate(name, target, duration, Easings.EASE_OUT_QUAD); } - public AnimationBuilder animate(String string, double d, double d2, Easing easing) { - return this.animate(string, d, d2, easing, false); + public AnimationBuilder animate(String name, double target, double duration, Easing easing) { + return this.animate(name, target, duration, easing, false); } - private AnimationBuilder animate(String string, double d, double d2, Easing easing, boolean bl) { - this.setDuration(d2); + private AnimationBuilder animate(String name, double target, double duration, Easing easing, boolean debug) { + this.setDuration(duration); this.setEasing(easing); - this.setDebug(bl); - this.getOrCreate(string).setCurrentValue(d); + this.setDebug(debug); + this.getOrCreate(name).setCurrentValue(target); return this; } - public AnimationBuilder withTask(double d, Runnable runnable) { - return this.withTask(d, this.easing, runnable); + public AnimationBuilder withTask(double duration, Runnable runnable) { + return this.withTask(duration, this.easing, runnable); } - public AnimationBuilder withTask(double d, Easing easing, Runnable runnable) { - return this.withTask(d, easing, false, runnable); + public AnimationBuilder withTask(double duration, Easing easing, Runnable runnable) { + return this.withTask(duration, easing, false, runnable); } - private AnimationBuilder withTask(double d, Easing easing, boolean bl, Runnable runnable) { - this.setDuration(d); + private AnimationBuilder withTask(double duration, Easing easing, boolean debug, Runnable runnable) { + this.setDuration(duration); this.setEasing(easing); - this.setDebug(bl); + this.setDebug(debug); runnable.run(); return this; } @@ -62,12 +62,12 @@ public class AnimationBuilder { return this.getTimers().stream().anyMatch(AnimationTimer::isAnimating); } - public void setDuration(double d) { - this.duration = d; + public void setDuration(double duration) { + this.duration = duration; } - public void setDebug(boolean bl) { - this.debug = bl; + public void setDebug(boolean debug) { + this.debug = debug; } public void setEasing(Easing easing) { diff --git a/src/main/java/shit/zen/utils/animation/AnimationTimer.java b/src/main/java/shit/zen/utils/animation/AnimationTimer.java index 44635fb..f4f4f2c 100644 --- a/src/main/java/shit/zen/utils/animation/AnimationTimer.java +++ b/src/main/java/shit/zen/utils/animation/AnimationTimer.java @@ -20,14 +20,14 @@ public abstract class AnimationTimer { private boolean debug; public boolean tick() { - boolean bl = this.isAnimating(); - if (bl) { + boolean animating = this.isAnimating(); + if (animating) { this.currentValue = this.lerp(this.getFromValue(), this.getToValue(), this.getEasing().ease(this.getProgress())); } else { this.setStartTime(0L); this.currentValue = this.getToValue(); } - return bl; + return animating; } public boolean isAnimating() { @@ -42,8 +42,8 @@ public abstract class AnimationTimer { return (double)(System.currentTimeMillis() - this.getStartTime()) / this.getDuration(); } - public double lerp(double d, double d2, double d3) { - return d + (d2 - d) * d3; + public double lerp(double from, double to, double progress) { + return from + (to - from) * progress; } public float getValueF() { diff --git a/src/main/java/shit/zen/utils/animation/NamedAnimationTimer.java b/src/main/java/shit/zen/utils/animation/NamedAnimationTimer.java index 7f44342..515da11 100644 --- a/src/main/java/shit/zen/utils/animation/NamedAnimationTimer.java +++ b/src/main/java/shit/zen/utils/animation/NamedAnimationTimer.java @@ -8,18 +8,18 @@ extends AnimationTimer { private final String name; private final AnimationBuilder builder; - public NamedAnimationTimer(String string, AnimationBuilder animationBuilder) { - this.name = string; - this.builder = animationBuilder; + public NamedAnimationTimer(String name, AnimationBuilder builder) { + this.name = name; + this.builder = builder; } @Override - public void setCurrentValue(double d) { - if (d == (double)this.getValueF()) { + public void setCurrentValue(double target) { + if (target == (double)this.getValueF()) { return; } this.setDebug(this.getBuilder().isDebug()); - if (this.isAnimating() && (d == this.getFromValue() || d == this.getToValue() || d == (double)this.getValueF())) { + if (this.isAnimating() && (target == this.getFromValue() || target == this.getToValue() || target == (double)this.getValueF())) { if (this.isDebug()) { System.out.println("Animating " + this.name + " cancelled due to valueTo equals fromValue"); } @@ -29,12 +29,12 @@ extends AnimationTimer { this.setDuration(this.getBuilder().getDuration() * 1000.0); this.setStartTime(System.currentTimeMillis()); this.setFromValue(this.getValueF()); - this.setToValue(d); + this.setToValue(target); if (this.isDebug()) { - double d2 = this.getDuration(); - float f = this.getValueF(); - double d3 = this.getToValue(); - System.out.println(this.name + "#animate {\n to value: " + d3 + "\n from value: " + f + "\n duration: " + d2 + "\n}"); + double duration = this.getDuration(); + float current = this.getValueF(); + double to = this.getToValue(); + System.out.println(this.name + "#animate {\n to value: " + to + "\n from value: " + current + "\n duration: " + duration + "\n}"); } } diff --git a/src/main/java/shit/zen/utils/animation/SmoothAnimationTimer.java b/src/main/java/shit/zen/utils/animation/SmoothAnimationTimer.java index 085b481..2d14d01 100644 --- a/src/main/java/shit/zen/utils/animation/SmoothAnimationTimer.java +++ b/src/main/java/shit/zen/utils/animation/SmoothAnimationTimer.java @@ -6,32 +6,32 @@ import shit.zen.utils.math.Easings; public class SmoothAnimationTimer extends AnimationTimer { - public void animate(double d, double d2) { - this.animate(d, d2, Easings.EASE_OUT_QUAD); + public void animate(double target, double duration) { + this.animate(target, duration, Easings.EASE_OUT_QUAD); } - public void animate(double d, double d2, Easing easing) { - this.animate(d, d2, easing, false); + public void animate(double target, double duration, Easing easing) { + this.animate(target, duration, easing, false); } - public void animate(double d, double d2, Easing easing, boolean bl) { - this.setDebug(bl); - if (this.isAnimating() && (d == this.getFromValue() || d == this.getToValue() || d == (double)this.getValueF())) { + public void animate(double target, double duration, Easing easing, boolean debug) { + this.setDebug(debug); + if (this.isAnimating() && (target == this.getFromValue() || target == this.getToValue() || target == (double)this.getValueF())) { if (this.isDebug()) { System.out.println("Animate cancelled due to valueTo equals fromValue"); } return; } this.setEasing(easing); - this.setDuration(d2 * 1000.0); + this.setDuration(duration * 1000.0); this.setStartTime(System.currentTimeMillis()); this.setFromValue(this.getValueF()); - this.setToValue(d); + this.setToValue(target); if (this.isDebug()) { - double d3 = this.getDuration(); - float f = this.getValueF(); - double d4 = this.getToValue(); - System.out.println("#animate {\n to value: " + d4 + "\n from value: " + f + "\n duration: " + d3 + "\n}"); + double durationMs = this.getDuration(); + float current = this.getValueF(); + double to = this.getToValue(); + System.out.println("#animate {\n to value: " + to + "\n from value: " + current + "\n duration: " + durationMs + "\n}"); } } } \ No newline at end of file diff --git a/src/main/java/shit/zen/utils/animation/SpringAnimation.java b/src/main/java/shit/zen/utils/animation/SpringAnimation.java index 357de40..d83944e 100644 --- a/src/main/java/shit/zen/utils/animation/SpringAnimation.java +++ b/src/main/java/shit/zen/utils/animation/SpringAnimation.java @@ -12,36 +12,36 @@ public class SpringAnimation { private float currentValue; private float velocity; - public SpringAnimation(float f, float f2, float f3, float f4) { - this.stiffness = f; - this.mass = f2; - this.damping = f3; - this.currentValue = f4; - this.targetValue = f4; + public SpringAnimation(float stiffness, float mass, float damping, float initialValue) { + this.stiffness = stiffness; + this.mass = mass; + this.damping = damping; + this.currentValue = initialValue; + this.targetValue = initialValue; } - public void reset(float f) { - this.currentValue = f; - this.targetValue = f; + public void reset(float value) { + this.currentValue = value; + this.targetValue = value; this.velocity = 0.0f; } - public void update(float f) { - if (f <= 0.0f) { + public void update(float deltaTime) { + if (deltaTime <= 0.0f) { return; } - float f2 = -this.stiffness * (this.currentValue - this.targetValue) - this.damping * this.velocity; - float f3 = f2 / this.mass; - this.velocity += f3 * f; - this.currentValue += this.velocity * f; + float force = -this.stiffness * (this.currentValue - this.targetValue) - this.damping * this.velocity; + float acceleration = force / this.mass; + this.velocity += acceleration * deltaTime; + this.currentValue += this.velocity * deltaTime; } public float getValue() { return this.currentValue; } - public void setValue(float f) { - this.currentValue = f; + public void setValue(float value) { + this.currentValue = value; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/utils/animation/TickTimer.java b/src/main/java/shit/zen/utils/animation/TickTimer.java index 72a65ed..98517f5 100644 --- a/src/main/java/shit/zen/utils/animation/TickTimer.java +++ b/src/main/java/shit/zen/utils/animation/TickTimer.java @@ -17,12 +17,12 @@ public class TickTimer { instances.add(this); } - public boolean hasPassed(int n) { - return this.ticks >= n; + public boolean hasPassed(int requiredTicks) { + return this.ticks >= requiredTicks; } - public boolean hasPassed(float f) { - return (float)this.ticks >= f; + public boolean hasPassed(float requiredTicks) { + return (float)this.ticks >= requiredTicks; } public void reset() { diff --git a/src/main/java/shit/zen/utils/animation/Timer.java b/src/main/java/shit/zen/utils/animation/Timer.java index e5b71d0..a1ff7b3 100644 --- a/src/main/java/shit/zen/utils/animation/Timer.java +++ b/src/main/java/shit/zen/utils/animation/Timer.java @@ -9,17 +9,17 @@ public class Timer { this.time = System.currentTimeMillis(); } - public void setTime(long l) { - this.time = l; + public void setTime(long time) { + this.time = time; } - public void setTimeMs(long l) { - this.time = l; + public void setTimeMs(long time) { + this.time = time; } - public boolean hasPassedReset(long l, boolean bl) { - if (System.currentTimeMillis() - this.time > l) { - if (bl) { + public boolean hasPassedReset(long durationMs, boolean reset) { + if (System.currentTimeMillis() - this.time > durationMs) { + if (reset) { this.reset(); } return true; @@ -27,28 +27,27 @@ public class Timer { return false; } - public boolean hasPassed(float f) { - return (float)(System.currentTimeMillis() - this.time) >= f; + public boolean hasPassed(float durationMs) { + return (float)(System.currentTimeMillis() - this.time) >= durationMs; } - public boolean hasPassedDouble(double d, boolean bl) { - boolean bl2; - boolean bl3 = bl2 = (double)Mth.clamp((float)(System.currentTimeMillis() - this.time), 0.0f, (float)d) >= d; - if (bl2 && bl) { + public boolean hasPassedDouble(double durationMs, boolean reset) { + boolean passed = (double)Mth.clamp((float)(System.currentTimeMillis() - this.time), 0.0f, (float)durationMs) >= durationMs; + if (passed && reset) { this.reset(); } - return bl2; + return passed; } public long getElapsed() { return System.currentTimeMillis() - this.time; } - public boolean hasPassed(long l) { - return System.currentTimeMillis() - this.time > l; + public boolean hasPassed(long durationMs) { + return System.currentTimeMillis() - this.time > durationMs; } - public boolean hasPassedOrEqual(long l) { - return System.currentTimeMillis() - this.time >= l; + public boolean hasPassedOrEqual(long durationMs) { + return System.currentTimeMillis() - this.time >= durationMs; } } \ No newline at end of file diff --git a/src/main/java/shit/zen/utils/game/BlockUtil.java b/src/main/java/shit/zen/utils/game/BlockUtil.java index e9f690a..eaac2f2 100644 --- a/src/main/java/shit/zen/utils/game/BlockUtil.java +++ b/src/main/java/shit/zen/utils/game/BlockUtil.java @@ -86,12 +86,12 @@ extends ClientBase { return mc.level.getBlockState(blockPos).getBlock(); } - public static BlockPos getPos(double d, double d2, double d3) { - return new BlockPos((int)Math.floor(d), (int)Math.floor(d2), (int)Math.floor(d3)); + public static BlockPos getPos(double x, double y, double z) { + return new BlockPos((int)Math.floor(x), (int)Math.floor(y), (int)Math.floor(z)); } - public static BlockPos getOffsetPos(BlockPos blockPos, double d, double d2, double d3) { - return new BlockPos((int)Math.floor((double)blockPos.getX() + d), (int)Math.floor((double)blockPos.getY() + d2), (int)Math.floor((double)blockPos.getZ() + d3)); + public static BlockPos getOffsetPos(BlockPos blockPos, double dx, double dy, double dz) { + return new BlockPos((int)Math.floor((double)blockPos.getX() + dx), (int)Math.floor((double)blockPos.getY() + dy), (int)Math.floor((double)blockPos.getZ() + dz)); } public static boolean isPlaceable(ItemStack itemStack) { @@ -99,8 +99,8 @@ extends ClientBase { if (!ItemUtil.isUsable(itemStack)) { return false; } - String string = itemStack.getDisplayName().getString(); - if (string.contains("Click") || string.contains("点击")) { + String displayName = itemStack.getDisplayName().getString(); + if (displayName.contains("Click") || displayName.contains("点击")) { return false; } if (itemStack.getItem() instanceof ItemNameBlockItem) { diff --git a/src/main/java/shit/zen/utils/game/CpsUtil.java b/src/main/java/shit/zen/utils/game/CpsUtil.java index c0dcd8d..55ce0b4 100644 --- a/src/main/java/shit/zen/utils/game/CpsUtil.java +++ b/src/main/java/shit/zen/utils/game/CpsUtil.java @@ -4,24 +4,24 @@ import lombok.Generated; import shit.zen.utils.math.MathUtil; public final class CpsUtil { - public static long toDelayMs(String string, double d) { - if (string.equals("DBC")) { - return (long)(500.0 / d + MathUtil.randomDouble(-50.0, 50.0)); + public static long toDelayMs(String mode, double cps) { + if (mode.equals("DBC")) { + return (long)(500.0 / cps + MathUtil.randomDouble(-50.0, 50.0)); } - return (long)(1000.0 / d + MathUtil.randomDouble(-25.0, 25.0)); + return (long)(1000.0 / cps + MathUtil.randomDouble(-25.0, 25.0)); } - public static long toDelayMs(double d) { - return (long)(1000.0 / d); + public static long toDelayMs(double cps) { + return (long)(1000.0 / cps); } - public static long toDelayMsWithJitter(double d, double d2) { - double d3 = 1000.0 / d; - return (long)(d3 + MathUtil.randomDouble(-d2, d2)); + public static long toDelayMsWithJitter(double cps, double jitter) { + double baseDelay = 1000.0 / cps; + return (long)(baseDelay + MathUtil.randomDouble(-jitter, jitter)); } @Generated private CpsUtil() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/game/EntityUtil.java b/src/main/java/shit/zen/utils/game/EntityUtil.java index 5ea3262..0731fec 100644 --- a/src/main/java/shit/zen/utils/game/EntityUtil.java +++ b/src/main/java/shit/zen/utils/game/EntityUtil.java @@ -24,63 +24,63 @@ extends ClientBase { return frustum.isVisible(entity.getBoundingBox()); } - public static Vec3 getInterpolatedPos(Entity entity, float f) { - double d = Mth.lerp(f, entity.xOld, entity.getX()); - double d2 = Mth.lerp(f, entity.yOld, entity.getY()); - double d3 = Mth.lerp(f, entity.zOld, entity.getZ()); - return new Vec3(d, d2, d3); + public static Vec3 getInterpolatedPos(Entity entity, float partialTicks) { + double x = Mth.lerp(partialTicks, entity.xOld, entity.getX()); + double y = Mth.lerp(partialTicks, entity.yOld, entity.getY()); + double z = Mth.lerp(partialTicks, entity.zOld, entity.getZ()); + return new Vec3(x, y, z); } - public static AABB getInterpolatedAABB(Entity entity, float f) { - Vec3 vec3 = EntityUtil.getInterpolatedPos(entity, f); - double d = (double)entity.getBbWidth() / 2.0; - return new AABB(vec3.x - d, vec3.y, vec3.z - d, vec3.x + d, vec3.y + (double)entity.getBbHeight(), vec3.z + d); + public static AABB getInterpolatedAABB(Entity entity, float partialTicks) { + Vec3 pos = EntityUtil.getInterpolatedPos(entity, partialTicks); + double halfWidth = (double)entity.getBbWidth() / 2.0; + return new AABB(pos.x - halfWidth, pos.y, pos.z - halfWidth, pos.x + halfWidth, pos.y + (double)entity.getBbHeight(), pos.z + halfWidth); } - public static Vector4d getScreenBounds(AABB aABB, Matrix4f matrix4f, Matrix4f matrix4f2) { - Matrix4f matrix4f3 = new Matrix4f(matrix4f2).mul(matrix4f); - int[] nArray = new int[]{0, 0, mc.getWindow().getWidth(), mc.getWindow().getHeight()}; - return EntityUtil.getScreenBoundsInternal(nArray, aABB, matrix4f3); + public static Vector4d getScreenBounds(AABB aABB, Matrix4f modelView, Matrix4f projection) { + Matrix4f combined = new Matrix4f(projection).mul(modelView); + int[] viewport = new int[]{0, 0, mc.getWindow().getWidth(), mc.getWindow().getHeight()}; + return EntityUtil.getScreenBoundsInternal(viewport, aABB, combined); } - private static Vector4d getScreenBoundsInternal(int[] nArray, AABB aABB, Matrix4f matrix4f) { - List list = Arrays.asList(new Vec3(aABB.minX, aABB.minY, aABB.minZ), new Vec3(aABB.minX, aABB.maxY, aABB.minZ), new Vec3(aABB.maxX, aABB.minY, aABB.minZ), new Vec3(aABB.maxX, aABB.maxY, aABB.minZ), new Vec3(aABB.minX, aABB.minY, aABB.maxZ), new Vec3(aABB.minX, aABB.maxY, aABB.maxZ), new Vec3(aABB.maxX, aABB.minY, aABB.maxZ), new Vec3(aABB.maxX, aABB.maxY, aABB.maxZ)); - Vector4f vector4f = new Vector4f(); - Vector4d vector4d = null; - boolean bl = false; - for (Vec3 vec3 : list) { - Vector4f vector4f2 = new Vector4f((float)vec3.x(), (float)vec3.y(), (float)vec3.z(), 1.0f); - matrix4f.transform(vector4f2); - if (!(vector4f2.w > 0.0f)) continue; - matrix4f.project((float)vec3.x(), (float)vec3.y(), (float)vec3.z(), nArray, vector4f); - vector4f.y = (float)nArray[3] - vector4f.y; - bl = true; - if (vector4d == null) { - vector4d = new Vector4d(vector4f.x, vector4f.y, vector4f.x, vector4f.y); + private static Vector4d getScreenBoundsInternal(int[] viewport, AABB aABB, Matrix4f mvpMatrix) { + List corners = Arrays.asList(new Vec3(aABB.minX, aABB.minY, aABB.minZ), new Vec3(aABB.minX, aABB.maxY, aABB.minZ), new Vec3(aABB.maxX, aABB.minY, aABB.minZ), new Vec3(aABB.maxX, aABB.maxY, aABB.minZ), new Vec3(aABB.minX, aABB.minY, aABB.maxZ), new Vec3(aABB.minX, aABB.maxY, aABB.maxZ), new Vec3(aABB.maxX, aABB.minY, aABB.maxZ), new Vec3(aABB.maxX, aABB.maxY, aABB.maxZ)); + Vector4f projected = new Vector4f(); + Vector4d bounds = null; + boolean anyVisible = false; + for (Vec3 corner : corners) { + Vector4f clipPos = new Vector4f((float)corner.x(), (float)corner.y(), (float)corner.z(), 1.0f); + mvpMatrix.transform(clipPos); + if (!(clipPos.w > 0.0f)) continue; + mvpMatrix.project((float)corner.x(), (float)corner.y(), (float)corner.z(), viewport, projected); + projected.y = (float)viewport[3] - projected.y; + anyVisible = true; + if (bounds == null) { + bounds = new Vector4d(projected.x, projected.y, projected.x, projected.y); continue; } - vector4d.x = Math.min(vector4f.x, vector4d.x); - vector4d.y = Math.min(vector4f.y, vector4d.y); - vector4d.z = Math.max(vector4f.x, vector4d.z); - vector4d.w = Math.max(vector4f.y, vector4d.w); + bounds.x = Math.min(projected.x, bounds.x); + bounds.y = Math.min(projected.y, bounds.y); + bounds.z = Math.max(projected.x, bounds.z); + bounds.w = Math.max(projected.y, bounds.w); } - return bl ? vector4d : null; + return anyVisible ? bounds : null; } - public static Vector3f getCameraRelativePos(Entity entity, float f) { + public static Vector3f getCameraRelativePos(Entity entity, float partialTicks) { if (mc == null || mc.gameRenderer == null || mc.gameRenderer.getMainCamera() == null) { return null; } - Vec3 vec3 = EntityUtil.getInterpolatedPos(entity, f); - double d = vec3.x(); - double d2 = vec3.y(); - double d3 = vec3.z(); + Vec3 entityPos = EntityUtil.getInterpolatedPos(entity, partialTicks); + double entityX = entityPos.x(); + double entityY = entityPos.y(); + double entityZ = entityPos.z(); Camera camera = mc.gameRenderer.getMainCamera(); - Vec3 vec32 = camera.getPosition(); - Quaternionf quaternionf = camera.rotation(); - Quaternionf quaternionf2 = new Quaternionf(quaternionf).conjugate(); - Vector3f vector3f = new Vector3f((float)(d - vec32.x), (float)(d2 - vec32.y), (float)(d3 - vec32.z)); - vector3f.rotate(quaternionf2); - return vector3f; + Vec3 cameraPos = camera.getPosition(); + Quaternionf cameraRotation = camera.rotation(); + Quaternionf invRotation = new Quaternionf(cameraRotation).conjugate(); + Vector3f relativePos = new Vector3f((float)(entityX - cameraPos.x), (float)(entityY - cameraPos.y), (float)(entityZ - cameraPos.z)); + relativePos.rotate(invRotation); + return relativePos; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/game/ItemAlertTracker.java b/src/main/java/shit/zen/utils/game/ItemAlertTracker.java index d4de7d5..a357c45 100644 --- a/src/main/java/shit/zen/utils/game/ItemAlertTracker.java +++ b/src/main/java/shit/zen/utils/game/ItemAlertTracker.java @@ -31,33 +31,33 @@ public class ItemAlertTracker { if (!ItemUtil.isOtherCheat(itemStack)) { return; } - int n = itemStack.getDamageValue(); - UUID uUID2 = player.getUUID(); - Integer n2 = trackedItems.get(uUID2); - if (n2 != null && n > n2) { + int damageValue = itemStack.getDamageValue(); + UUID playerId = player.getUUID(); + Integer prevDamage = trackedItems.get(playerId); + if (prevDamage != null && damageValue > prevDamage) { ChatUtil.print(String.format(ALERT_FORMAT, new Object[]{player.getName().getString()})); - alertedItems.computeIfAbsent(uUID2, uUID -> new HashSet<>()).add(itemStack.getItem()); + alertedItems.computeIfAbsent(playerId, uUID -> new HashSet<>()).add(itemStack.getItem()); } - trackedItems.put(uUID2, n); + trackedItems.put(playerId, damageValue); } - public static void trackEntityItem(Object object2, ItemStack itemStack) { + public static void trackEntityItem(Object entityKey, ItemStack itemStack) { if (!ItemAlertTracker.isNewItem(itemStack)) { return; } - Set set = entityItems.computeIfAbsent(object2, object -> new CopyOnWriteArraySet<>()); - if (set.stream().noneMatch(itemStack2 -> ItemStack.matches(itemStack2, itemStack))) { - set.add(itemStack); + Set stacks = entityItems.computeIfAbsent(entityKey, key -> new CopyOnWriteArraySet<>()); + if (stacks.stream().noneMatch(existing -> ItemStack.matches(existing, itemStack))) { + stacks.add(itemStack); } } - public static Set getEntityItems(Object object) { - return entityItems.getOrDefault(object, Collections.emptySet()); + public static Set getEntityItems(Object entityKey) { + return entityItems.getOrDefault(entityKey, Collections.emptySet()); } - public static boolean hasItem(UUID uUID, Item item) { - Set set = alertedItems.getOrDefault(uUID, Collections.emptySet()); - return set.contains(item); + public static boolean hasItem(UUID playerId, Item item) { + Set items = alertedItems.getOrDefault(playerId, Collections.emptySet()); + return items.contains(item); } public static void clear() { @@ -66,20 +66,20 @@ public class ItemAlertTracker { entityItems.clear(); } - public static void removeEntity(Object object) { - entityItems.remove(object); + public static void removeEntity(Object entityKey) { + entityItems.remove(entityKey); } - public static void updateItems(Set set) { - entityItems.keySet().removeIf(object -> !set.contains(object)); + public static void updateItems(Set activeEntities) { + entityItems.keySet().removeIf(entityKey -> !activeEntities.contains(entityKey)); } - public static Integer getItemCount(UUID uUID) { - return trackedItems.get(uUID); + public static Integer getItemCount(UUID playerId) { + return trackedItems.get(playerId); } - public static void setItemCount(UUID uUID, int n) { - trackedItems.put(uUID, n); + public static void setItemCount(UUID playerId, int count) { + trackedItems.put(playerId, count); } static { @@ -88,4 +88,4 @@ public class ItemAlertTracker { alertedItems = new ConcurrentHashMap<>(); entityItems = new ConcurrentHashMap<>(); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/game/ItemUtil.java b/src/main/java/shit/zen/utils/game/ItemUtil.java index 7c8d91e..296bfa2 100644 --- a/src/main/java/shit/zen/utils/game/ItemUtil.java +++ b/src/main/java/shit/zen/utils/game/ItemUtil.java @@ -42,8 +42,8 @@ extends ClientBase { public static boolean hasServerItem() { return ItemUtil.getAllItems().stream().anyMatch(itemStack -> { if (!itemStack.isEmpty()) { - String string = itemStack.getDisplayName().getString(); - return string.contains("长按点击") || string.contains("点击使用") || string.contains("离开游戏") || string.contains("选择一个队伍") || string.contains("再来一局"); + String displayName = itemStack.getDisplayName().getString(); + return displayName.contains("长按点击") || displayName.contains("点击使用") || displayName.contains("离开游戏") || displayName.contains("选择一个队伍") || displayName.contains("再来一局"); } return false; }); @@ -107,13 +107,13 @@ extends ClientBase { } public static List getAllItems() { - ArrayList arrayList = new ArrayList<>(40); + ArrayList items = new ArrayList<>(40); if (mc.player == null) { - return arrayList; + return items; } - arrayList.addAll(mc.player.getInventory().items); - arrayList.addAll(mc.player.getInventory().armor); - return arrayList; + items.addAll(mc.player.getInventory().items); + items.addAll(mc.player.getInventory().armor); + return items; } public static float getBestArmorScore(EquipmentSlot equipmentSlot) { @@ -160,11 +160,11 @@ extends ClientBase { return 0.0f; } if (itemStack.getItem() instanceof BowItem) { - float f = 10.0f; - f += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, itemStack); - f += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, itemStack); - f += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, itemStack); - return (f += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, itemStack) / 10.0f) + (float)itemStack.getDamageValue() / (float)itemStack.getMaxDamage(); + float score = 10.0f; + score += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, itemStack); + score += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, itemStack); + score += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, itemStack); + return (score += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, itemStack) / 10.0f) + (float)itemStack.getDamageValue() / (float)itemStack.getMaxDamage(); } return 0.0f; } @@ -177,17 +177,17 @@ extends ClientBase { return 0.0f; } if (itemStack.getItem() instanceof BowItem) { - float f = 10.0f; - f += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, itemStack) / 10.0f; - f += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, itemStack); - f += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, itemStack); - return (f += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, itemStack)) + (float)itemStack.getDamageValue() / (float)itemStack.getMaxDamage(); + float score = 10.0f; + score += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, itemStack) / 10.0f; + score += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, itemStack); + score += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, itemStack); + return (score += (float)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, itemStack)) + (float)itemStack.getDamageValue() / (float)itemStack.getMaxDamage(); } return 0.0f; } public static float getDigSpeed(ItemStack itemStack) { - float f = 0.0f; + float speed = 0.0f; if (itemStack == null) { return 0.0f; } @@ -201,24 +201,24 @@ extends ClientBase { return 0.0f; } if (itemStack.getItem() instanceof PickaxeItem) { - f += itemStack.getDestroySpeed(Blocks.STONE.defaultBlockState()); + speed += itemStack.getDestroySpeed(Blocks.STONE.defaultBlockState()); } else if (itemStack.getItem() instanceof AxeItem) { - f += itemStack.getDestroySpeed(Blocks.OAK_LOG.defaultBlockState()); + speed += itemStack.getDestroySpeed(Blocks.OAK_LOG.defaultBlockState()); } else if (itemStack.getItem() instanceof ShovelItem) { - f += itemStack.getDestroySpeed(Blocks.DIRT.defaultBlockState()); + speed += itemStack.getDestroySpeed(Blocks.DIRT.defaultBlockState()); } else { return 0.0f; } - int n = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_EFFICIENCY, itemStack); - if (n > 0) { - f += (float)n * 0.0075f; + int efficiencyLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_EFFICIENCY, itemStack); + if (efficiencyLevel > 0) { + speed += (float)efficiencyLevel * 0.0075f; } - return f; + return speed; } public static float getAxeDamage(ItemStack itemStack) { - int n; - float f = 0.0f; + int sharpnessLevel; + float damage = 0.0f; if (itemStack == null) { return 0.0f; } @@ -229,28 +229,28 @@ extends ClientBase { if (item instanceof AxeItem axeItem) { if (ItemUtil.isLegitAxe(itemStack)) { if (axeItem == Items.WOODEN_AXE) { - f += 4.0f; + damage += 4.0f; } else if (axeItem == Items.STONE_AXE) { - f += 5.0f; + damage += 5.0f; } else if (axeItem == Items.IRON_AXE) { - f += 6.0f; + damage += 6.0f; } else if (axeItem == Items.GOLDEN_AXE) { - f += 4.0f; + damage += 4.0f; } else if (axeItem == Items.DIAMOND_AXE) { - f += 7.0f; + damage += 7.0f; } } } - if ((n = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemStack)) > 0) { - float f2 = Enchantments.SHARPNESS.getDamageBonus(n, MobType.UNDEFINED); - f += f2; + if ((sharpnessLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemStack)) > 0) { + float sharpnessBonus = Enchantments.SHARPNESS.getDamageBonus(sharpnessLevel, MobType.UNDEFINED); + damage += sharpnessBonus; } - return f; + return damage; } public static float getSwordDamage(ItemStack itemStack) { - int n; - float f = 0.0f; + int sharpnessLevel; + float damage = 0.0f; if (itemStack == null) { return 0.0f; } @@ -259,35 +259,35 @@ extends ClientBase { } Item item = itemStack.getItem(); if (item instanceof SwordItem swordItem) { - f += swordItem.getDamage() + 1.0f; + damage += swordItem.getDamage() + 1.0f; } - if ((n = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemStack)) > 0) { - float f2 = Enchantments.SHARPNESS.getDamageBonus(n, MobType.UNDEFINED); - f += f2; + if ((sharpnessLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemStack)) > 0) { + float sharpnessBonus = Enchantments.SHARPNESS.getDamageBonus(sharpnessLevel, MobType.UNDEFINED); + damage += sharpnessBonus; } - return f; + return damage; } public static float getArmorScore(ItemStack itemStack) { - int n = 0; + int score = 0; if (itemStack == null || itemStack.isEmpty()) { return 0.0f; } Item item = itemStack.getItem(); if (item instanceof ArmorItem armorItem) { net.minecraft.world.item.ArmorMaterial material = armorItem.getMaterial(); - if (material == ArmorMaterials.LEATHER) n += 100; - else if (material == ArmorMaterials.CHAIN) n += 200; - else if (material == ArmorMaterials.IRON) n += 400; - else if (material == ArmorMaterials.GOLD) n += 300; - else if (material == ArmorMaterials.DIAMOND) n += 500; - else if (material == ArmorMaterials.NETHERITE) n += 600; + if (material == ArmorMaterials.LEATHER) score += 100; + else if (material == ArmorMaterials.CHAIN) score += 200; + else if (material == ArmorMaterials.IRON) score += 400; + else if (material == ArmorMaterials.GOLD) score += 300; + else if (material == ArmorMaterials.DIAMOND) score += 500; + else if (material == ArmorMaterials.NETHERITE) score += 600; } - return n + EnchantmentHelper.getItemEnchantmentLevel(Enchantments.ALL_DAMAGE_PROTECTION, itemStack); + return score + EnchantmentHelper.getItemEnchantmentLevel(Enchantments.ALL_DAMAGE_PROTECTION, itemStack); } public static float getCrossbowScore(ItemStack itemStack) { - int n = 0; + int score = 0; if (itemStack == null) { return 0.0f; } @@ -295,11 +295,11 @@ extends ClientBase { return 0.0f; } if (itemStack.getItem() instanceof CrossbowItem) { - n += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.QUICK_CHARGE, itemStack); - n += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MULTISHOT, itemStack); - n += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PIERCING, itemStack); + score += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.QUICK_CHARGE, itemStack); + score += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MULTISHOT, itemStack); + score += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PIERCING, itemStack); } - return n; + return score; } public static boolean isWeaponItem(ItemStack itemStack) { @@ -319,20 +319,20 @@ extends ClientBase { } public static double getAttackDamage(ItemStack itemStack) { - double d = 0.0; - Multimap multimap = itemStack.getAttributeModifiers(EquipmentSlot.MAINHAND); - for (Attribute attribute : multimap.keySet()) { + double damage = 0.0; + Multimap modifiers = itemStack.getAttributeModifiers(EquipmentSlot.MAINHAND); + for (Attribute attribute : modifiers.keySet()) { if (!attribute.getDescriptionId().equals("attribute.name.generic.attack_damage")) continue; - Iterator iterator = multimap.get(attribute).iterator(); + Iterator iterator = modifiers.get(attribute).iterator(); if (!iterator.hasNext()) break; - d += iterator.next().getAmount(); + damage += iterator.next().getAmount(); break; } if (itemStack.hasFoil()) { - d += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FIRE_ASPECT, itemStack); - d += (double)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemStack) * 1.25; + damage += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FIRE_ASPECT, itemStack); + damage += (double)EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemStack) * 1.25; } - return d; + return damage; } public static boolean isSkullItem(ItemStack itemStack) { @@ -363,16 +363,16 @@ extends ClientBase { if (!(itemStack.getItem() instanceof AxeItem)) { return false; } - int n = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemStack); - return n >= 8 && n < 50; + int sharpnessLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemStack); + return sharpnessLevel >= 8 && sharpnessLevel < 50; } public static boolean isOtherCheat(ItemStack itemStack) { if (itemStack.isEmpty()) { return false; } - String string = itemStack.getDisplayName().getString(); - if (string.contains("一刀")) { + String displayName = itemStack.getDisplayName().getString(); + if (displayName.contains("一刀")) { return true; } if (itemStack.getTag() != null && itemStack.getTag().toString().contains("一刀")) { @@ -519,35 +519,35 @@ extends ClientBase { if (itemStack.getItem() instanceof PlayerHeadItem) { return false; } - String string = itemStack.getDisplayName().getString(); - if (string.contains("Click")) { + String displayName = itemStack.getDisplayName().getString(); + if (displayName.contains("Click")) { return false; } - if (string.contains("Right")) { + if (displayName.contains("Right")) { return false; } - if (string.contains("点击")) { + if (displayName.contains("点击")) { return false; } - if (string.contains("Teleport")) { + if (displayName.contains("Teleport")) { return false; } - if (string.contains("使用")) { + if (displayName.contains("使用")) { return false; } - if (string.contains("传送")) { + if (displayName.contains("传送")) { return false; } - return !string.contains("再来"); + return !displayName.contains("再来"); } return true; } - public static int findItemInRange(int n, int n2, Item item) { + public static int findItemInRange(int startSlot, int endSlot, Item item) { if (mc.player == null) { return -1; } - for (int i = n; i < n2; ++i) { + for (int i = startSlot; i < endSlot; ++i) { ItemStack itemStack = mc.player.getInventory().getItem(i); if (itemStack.isEmpty() || itemStack.getItem() != item) continue; return i; diff --git a/src/main/java/shit/zen/utils/game/MotionSimulator.java b/src/main/java/shit/zen/utils/game/MotionSimulator.java index e4be9d8..46d8e21 100644 --- a/src/main/java/shit/zen/utils/game/MotionSimulator.java +++ b/src/main/java/shit/zen/utils/game/MotionSimulator.java @@ -23,43 +23,43 @@ public class MotionSimulator { private final float forwardSpeed; private float jumpPower; - public MotionSimulator(double d, double d2, double d3, double d4, double d5, double d6, float f, float f2, float f3) { - this.x = d; - this.y = d2; - this.z = d3; - this.motionX = d4; - this.motionY = d5; - this.motionZ = d6; - this.yaw = f; - this.strafeSpeed = f2; - this.forwardSpeed = f3; + public MotionSimulator(double x, double y, double z, double motionX, double motionY, double motionZ, float yaw, float strafeSpeed, float forwardSpeed) { + this.x = x; + this.y = y; + this.z = z; + this.motionX = motionX; + this.motionY = motionY; + this.motionZ = motionZ; + this.yaw = yaw; + this.strafeSpeed = strafeSpeed; + this.forwardSpeed = forwardSpeed; } public MotionSimulator(Player player) { this(player.getX(), player.getY(), player.getZ(), player.getDeltaMovement().x, player.getDeltaMovement().y, player.getDeltaMovement().z, player.getYRot(), player.xxa, player.zza); - float f; - float f2 = player.level().getBlockState(player.blockPosition()).getBlock().getJumpFactor(); - float f3 = player.level().getBlockState(player.getOnPos()).getBlock().getJumpFactor(); - this.jumpPower = f = 0.42f * ((double)f2 == 1.0 ? f3 : f2) + player.getJumpBoostPower(); + float jumpPower; + float currentJumpFactor = player.level().getBlockState(player.blockPosition()).getBlock().getJumpFactor(); + float belowJumpFactor = player.level().getBlockState(player.getOnPos()).getBlock().getJumpFactor(); + this.jumpPower = jumpPower = 0.42f * ((double)currentJumpFactor == 1.0 ? belowJumpFactor : currentJumpFactor) + player.getJumpBoostPower(); } private void tick() { - float f = this.strafeSpeed; - float f2 = this.forwardSpeed; - float f3 = f * f + f2 * f2; - if (f3 >= 1.0E-4f) { - if ((f3 = Mth.sqrt(f3)) < 1.0f) { - f3 = 1.0f; + float strafe = this.strafeSpeed; + float forward = this.forwardSpeed; + float magSqr = strafe * strafe + forward * forward; + if (magSqr >= 1.0E-4f) { + if ((magSqr = Mth.sqrt(magSqr)) < 1.0f) { + magSqr = 1.0f; } - float f4 = this.jumpPower; + float speed = this.jumpPower; if (ClientBase.mc.player.isSprinting()) { - f4 *= 1.3f; + speed *= 1.3f; } - f3 = f4 / f3; - float f5 = Mth.sin(this.yaw * (float)Math.PI / 180.0f); - float f6 = Mth.cos(this.yaw * (float)Math.PI / 180.0f); - this.motionX += (f *= f3) * f6 - (f2 *= f3) * f5; - this.motionZ += f2 * f6 + f * f5; + magSqr = speed / magSqr; + float sinYaw = Mth.sin(this.yaw * (float)Math.PI / 180.0f); + float cosYaw = Mth.cos(this.yaw * (float)Math.PI / 180.0f); + this.motionX += (strafe *= magSqr) * cosYaw - (forward *= magSqr) * sinYaw; + this.motionZ += forward * cosYaw + strafe * sinYaw; } this.motionY -= 0.08; this.motionY *= 0.98f; @@ -69,22 +69,22 @@ public class MotionSimulator { } private void tickWithFriction() { - float f = this.strafeSpeed * 0.98f; - float f2 = this.forwardSpeed * 0.98f; - float f3 = f * f + f2 * f2; - if (f3 >= 1.0E-4f) { - if ((f3 = Mth.sqrt(f3)) < 1.0f) { - f3 = 1.0f; + float strafe = this.strafeSpeed * 0.98f; + float forward = this.forwardSpeed * 0.98f; + float magSqr = strafe * strafe + forward * forward; + if (magSqr >= 1.0E-4f) { + if ((magSqr = Mth.sqrt(magSqr)) < 1.0f) { + magSqr = 1.0f; } - float f4 = this.jumpPower; + float speed = this.jumpPower; if (ClientBase.mc.player.isSprinting()) { - f4 *= 1.3f; + speed *= 1.3f; } - f3 = f4 / f3; - float f5 = Mth.sin(this.yaw * (float)Math.PI / 180.0f); - float f6 = Mth.cos(this.yaw * (float)Math.PI / 180.0f); - this.motionX += (f *= f3) * f6 - (f2 *= f3) * f5; - this.motionZ += f2 * f6 + f * f5; + magSqr = speed / magSqr; + float sinYaw = Mth.sin(this.yaw * (float)Math.PI / 180.0f); + float cosYaw = Mth.cos(this.yaw * (float)Math.PI / 180.0f); + this.motionX += (strafe *= magSqr) * cosYaw - (forward *= magSqr) * sinYaw; + this.motionZ += forward * cosYaw + strafe * sinYaw; } this.motionY -= 0.08; this.motionY *= 0.98f; @@ -95,69 +95,69 @@ public class MotionSimulator { this.motionZ *= 0.91; } - public BlockPos findLandingBlock(int n) { - for (int i = 0; i < n; ++i) { - Vec3 vec3 = new Vec3(this.x, this.y, this.z); + public BlockPos findLandingBlock(int maxTicks) { + for (int i = 0; i < maxTicks; ++i) { + Vec3 fromPos = new Vec3(this.x, this.y, this.z); this.tickWithFriction(); - Vec3 vec32 = new Vec3(this.x, this.y, this.z); - float f = ClientBase.mc.player.getBbWidth() / 2.0f; - BlockPos blockPos = this.rayTraceBlock(vec3, vec32); - if (blockPos != null) { - return blockPos; + Vec3 toPos = new Vec3(this.x, this.y, this.z); + float halfWidth = ClientBase.mc.player.getBbWidth() / 2.0f; + BlockPos hit = this.rayTraceBlock(fromPos, toPos); + if (hit != null) { + return hit; } - blockPos = this.rayTraceBlock(vec3.add(f, 0.0, f), vec32); - if (blockPos != null) { - return blockPos; + hit = this.rayTraceBlock(fromPos.add(halfWidth, 0.0, halfWidth), toPos); + if (hit != null) { + return hit; } - blockPos = this.rayTraceBlock(vec3.add(-f, 0.0, f), vec32); - if (blockPos != null) { - return blockPos; + hit = this.rayTraceBlock(fromPos.add(-halfWidth, 0.0, halfWidth), toPos); + if (hit != null) { + return hit; } - blockPos = this.rayTraceBlock(vec3.add(f, 0.0, -f), vec32); - if (blockPos != null) { - return blockPos; + hit = this.rayTraceBlock(fromPos.add(halfWidth, 0.0, -halfWidth), toPos); + if (hit != null) { + return hit; } - blockPos = this.rayTraceBlock(vec3.add(-f, 0.0, -f), vec32); - if (blockPos != null) { - return blockPos; + hit = this.rayTraceBlock(fromPos.add(-halfWidth, 0.0, -halfWidth), toPos); + if (hit != null) { + return hit; } - blockPos = this.rayTraceBlock(vec3.add(f, 0.0, f / 2.0f), vec32); - if (blockPos != null) { - return blockPos; + hit = this.rayTraceBlock(fromPos.add(halfWidth, 0.0, halfWidth / 2.0f), toPos); + if (hit != null) { + return hit; } - blockPos = this.rayTraceBlock(vec3.add(-f, 0.0, f / 2.0f), vec32); - if (blockPos != null) { - return blockPos; + hit = this.rayTraceBlock(fromPos.add(-halfWidth, 0.0, halfWidth / 2.0f), toPos); + if (hit != null) { + return hit; } - blockPos = this.rayTraceBlock(vec3.add(f / 2.0f, 0.0, f), vec32); - if (blockPos != null) { - return blockPos; + hit = this.rayTraceBlock(fromPos.add(halfWidth / 2.0f, 0.0, halfWidth), toPos); + if (hit != null) { + return hit; } - blockPos = this.rayTraceBlock(vec3.add(f / 2.0f, 0.0, -f), vec32); - if (blockPos == null) continue; - return blockPos; + hit = this.rayTraceBlock(fromPos.add(halfWidth / 2.0f, 0.0, -halfWidth), toPos); + if (hit == null) continue; + return hit; } return null; } - private BlockPos rayTraceBlock(Vec3 vec3, Vec3 vec32) { + private BlockPos rayTraceBlock(Vec3 fromPos, Vec3 toPos) { BlockHitResult blockHitResult; - HitResult hitResult = RayTraceUtil.clipWithEntity(vec3, vec32, false, false, false, ClientBase.mc.player); + HitResult hitResult = RayTraceUtil.clipWithEntity(fromPos, toPos, false, false, false, ClientBase.mc.player); if (hitResult != null && hitResult.getType() == HitResult.Type.BLOCK && hitResult instanceof BlockHitResult && (blockHitResult = (BlockHitResult)hitResult).getDirection() == Direction.UP) { return blockHitResult.getBlockPos(); } return null; } - public void simulate(int n) { - for (int i = 0; i < n; ++i) { + public void simulate(int ticks) { + for (int i = 0; i < ticks; ++i) { this.tick(); } } - public void simulateWithFriction(int n) { - for (int i = 0; i < n; ++i) { + public void simulateWithFriction(int ticks) { + for (int i = 0; i < ticks; ++i) { this.tickWithFriction(); } } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/game/MovementUtil.java b/src/main/java/shit/zen/utils/game/MovementUtil.java index e0b6150..e46ee4f 100644 --- a/src/main/java/shit/zen/utils/game/MovementUtil.java +++ b/src/main/java/shit/zen/utils/game/MovementUtil.java @@ -22,85 +22,85 @@ extends ClientBase { return mc.options.keyUp.isDown() || mc.options.keyDown.isDown() || mc.options.keyLeft.isDown() || mc.options.keyRight.isDown(); } - public static void strafeWithYaw(double d, double d2) { + public static void strafeWithYaw(double yawRad, double speed) { if (!MovementUtil.isInputActive()) { return; } - Vec3 vec3 = mc.player.getDeltaMovement(); - mc.player.setDeltaMovement(vec3.x + (double)(-Mth.sin((float)d)) * d2, vec3.y, vec3.z + (double)Mth.cos((float)d) * d2); + Vec3 deltaMovement = mc.player.getDeltaMovement(); + mc.player.setDeltaMovement(deltaMovement.x + (double)(-Mth.sin((float)yawRad)) * speed, deltaMovement.y, deltaMovement.z + (double)Mth.cos((float)yawRad) * speed); } - public static void strafeForward(double d) { + public static void strafeForward(double speed) { if (!MovementUtil.isInputActive()) { return; } - double d2 = MovementUtil.getMovementYaw(); - Vec3 vec3 = mc.player.getDeltaMovement(); - mc.player.setDeltaMovement(vec3.x + (double)(-Mth.sin((float)d2)) * d, vec3.y, vec3.z + (double)Mth.cos((float)d2) * d); + double movementYaw = MovementUtil.getMovementYaw(); + Vec3 deltaMovement = mc.player.getDeltaMovement(); + mc.player.setDeltaMovement(deltaMovement.x + (double)(-Mth.sin((float)movementYaw)) * speed, deltaMovement.y, deltaMovement.z + (double)Mth.cos((float)movementYaw) * speed); } public static double getMovementYaw() { - float f = mc.player.getYRot(); + float yaw = mc.player.getYRot(); if (mc.player.zza < 0.0f) { - f += 180.0f; + yaw += 180.0f; } - float f2 = 1.0f; + float strafeFactor = 1.0f; if (mc.player.zza < 0.0f) { - f2 = -0.5f; + strafeFactor = -0.5f; } else if (mc.player.zza > 0.0f) { - f2 = 0.5f; + strafeFactor = 0.5f; } if (mc.player.xxa > 0.0f) { - f -= 90.0f * f2; + yaw -= 90.0f * strafeFactor; } else if (mc.player.xxa < 0.0f) { - f += 90.0f * f2; + yaw += 90.0f * strafeFactor; } - return Math.toRadians(f); + return Math.toRadians(yaw); } public static double getBaseSpeed() { - double d = 0.2875; + double baseSpeed = 0.2875; if (mc.player.hasEffect(MobEffects.MOVEMENT_SPEED)) { - int n = mc.player.getEffect(MobEffects.MOVEMENT_SPEED).getAmplifier(); - d *= 1.0 + 0.2 * (double)(n + 1); + int amplifier = mc.player.getEffect(MobEffects.MOVEMENT_SPEED).getAmplifier(); + baseSpeed *= 1.0 + 0.2 * (double)(amplifier + 1); } - return d; + return baseSpeed; } - public static double hypot(double d, double d2) { - return Math.sqrt(d * d + d2 * d2); + public static double hypot(double x, double z) { + return Math.sqrt(x * x + z * z); } public static double getSpeed() { return MovementUtil.hypot(mc.player.getDeltaMovement().x, mc.player.getDeltaMovement().z); } - public static void setSpeed(double d) { - float f = mc.player.input.forwardImpulse; - float f2 = mc.player.input.leftImpulse; - float f3 = mc.player.getYRot(); - if (f == 0.0f && f2 == 0.0f) { + public static void setSpeed(double speed) { + float forward = mc.player.input.forwardImpulse; + float strafe = mc.player.input.leftImpulse; + float yaw = mc.player.getYRot(); + if (forward == 0.0f && strafe == 0.0f) { mc.player.setDeltaMovement(0.0, mc.player.getDeltaMovement().y, 0.0); return; } - if (f != 0.0f && f2 != 0.0f) { - f = (float)((double)f * Math.sin(0.7853981633974483)); - f2 = (float)((double)f2 * Math.cos(0.7853981633974483)); + if (forward != 0.0f && strafe != 0.0f) { + forward = (float)((double)forward * Math.sin(0.7853981633974483)); + strafe = (float)((double)strafe * Math.cos(0.7853981633974483)); } - double d2 = (double)f * d * -Math.sin(Math.toRadians(f3)) + (double)f2 * d * Math.cos(Math.toRadians(f3)); - double d3 = (double)f * d * Math.cos(Math.toRadians(f3)) - (double)f2 * d * -Math.sin(Math.toRadians(f3)); - mc.player.setDeltaMovement(d2, mc.player.getDeltaMovement().y, d3); + double motionX = (double)forward * speed * -Math.sin(Math.toRadians(yaw)) + (double)strafe * speed * Math.cos(Math.toRadians(yaw)); + double motionZ = (double)forward * speed * Math.cos(Math.toRadians(yaw)) - (double)strafe * speed * -Math.sin(Math.toRadians(yaw)); + mc.player.setDeltaMovement(motionX, mc.player.getDeltaMovement().y, motionZ); } - public static boolean isAboveVoid(double d, double d2, double d3) { - while (d2 > 0.0) { - Vec3 vec3 = new Vec3(d, d2, d3); - Vec3 vec32 = new Vec3(d, d2 - 1.0, d3); - BlockHitResult blockHitResult = mc.level.clip(new ClipContext(vec3, vec32, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); + public static boolean isAboveVoid(double x, double y, double z) { + while (y > 0.0) { + Vec3 startPos = new Vec3(x, y, z); + Vec3 endPos = new Vec3(x, y - 1.0, z); + BlockHitResult blockHitResult = mc.level.clip(new ClipContext(startPos, endPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); if (blockHitResult != null && blockHitResult.getType() != HitResult.Type.MISS) { return false; } - d2 -= 1.0; + y -= 1.0; } return true; } @@ -113,96 +113,96 @@ extends ClientBase { return Math.hypot(mc.player.getDeltaMovement().x, mc.player.getDeltaMovement().z); } - public static void handleStrafe(StrafeEvent strafeEvent, float f) { - float f2 = strafeEvent.getForward(); - float f3 = strafeEvent.getStrafe(); - float f4 = mc.player.getYRot(); + public static void handleStrafe(StrafeEvent strafeEvent, float partialTicks) { + float forward = strafeEvent.getForward(); + float strafe = strafeEvent.getStrafe(); + float yaw = mc.player.getYRot(); if (TargetStrafe.strafeTarget != null && TargetStrafe.INSTANCE.isEnabled() && (!TargetStrafe.isSmartStrafe() || mc.options.keyJump.isDown())) { - float f5 = (float)(MovementUtil.getBaseSpeed() / ((double)TargetStrafe.getRange() * Math.PI * 2.0) * 360.0) * (float)TargetStrafe.strafeDirectionSign; + float yawOffset = (float)(MovementUtil.getBaseSpeed() / ((double)TargetStrafe.getRange() * Math.PI * 2.0) * 360.0) * (float)TargetStrafe.strafeDirectionSign; Rotation rotation = RotationUtil.rotationToForBow(new Vec3(TargetStrafe.strafeTarget.getX(), TargetStrafe.strafeTarget.getY(), TargetStrafe.strafeTarget.getZ()), new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ())); - rotation.setYaw(rotation.getYaw() + f5); - float f6 = rotation.getYaw() * ((float)Math.PI / 180); - double d = TargetStrafe.strafeTarget.getX() - Math.sin(f6) * (double)TargetStrafe.getRange(); - double d2 = TargetStrafe.strafeTarget.getZ() + Math.cos(f6) * (double)TargetStrafe.getRange(); - f4 = (float)Math.toDegrees(RotationUtil.rotationToForBow(new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ()), new Vec3(d, TargetStrafe.strafeTarget.getY(), d2)).getYaw() * ((float)Math.PI / 180)); + rotation.setYaw(rotation.getYaw() + yawOffset); + float yawRad = rotation.getYaw() * ((float)Math.PI / 180); + double circleX = TargetStrafe.strafeTarget.getX() - Math.sin(yawRad) * (double)TargetStrafe.getRange(); + double circleZ = TargetStrafe.strafeTarget.getZ() + Math.cos(yawRad) * (double)TargetStrafe.getRange(); + yaw = (float)Math.toDegrees(RotationUtil.rotationToForBow(new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ()), new Vec3(circleX, TargetStrafe.strafeTarget.getY(), circleZ)).getYaw() * ((float)Math.PI / 180)); } - double d = Mth.wrapDegrees(Math.toDegrees(MovementUtil.getDirectionYaw(f4, f2, f3))); - if (f2 == 0.0f && f3 == 0.0f) { + double targetDirection = Mth.wrapDegrees(Math.toDegrees(MovementUtil.getDirectionYaw(yaw, forward, strafe))); + if (forward == 0.0f && strafe == 0.0f) { return; } - int n = 0; - int n2 = 0; - float f7 = Float.MAX_VALUE; + int bestForward = 0; + int bestStrafe = 0; + float bestDiff = Float.MAX_VALUE; for (int i = -1; i <= 1; ++i) { for (int j = -1; j <= 1; ++j) { - double d3; - double d4; - if (j == 0 && i == 0 || !((d4 = Math.abs(d - (d3 = Mth.wrapDegrees(Math.toDegrees(MovementUtil.getDirectionYaw(f, i, j)))))) < (double)f7)) continue; - f7 = (float)d4; - n = i; - n2 = j; + double candidateDir; + double diff; + if (j == 0 && i == 0 || !((diff = Math.abs(targetDirection - (candidateDir = Mth.wrapDegrees(Math.toDegrees(MovementUtil.getDirectionYaw(partialTicks, i, j)))))) < (double)bestDiff)) continue; + bestDiff = (float)diff; + bestForward = i; + bestStrafe = j; } } - strafeEvent.setForward(n); - strafeEvent.setStrafe(n2); + strafeEvent.setForward(bestForward); + strafeEvent.setStrafe(bestStrafe); } public static boolean isInputActive() { return mc.player != null && mc.level != null && ((double)mc.player.input.forwardImpulse != 0.0 || (double)mc.player.input.leftImpulse != 0.0); } - public static double getDirectionYaw(float f, double d, double d2) { - if (d < 0.0) { - f += 180.0f; + public static double getDirectionYaw(float yaw, double forward, double strafe) { + if (forward < 0.0) { + yaw += 180.0f; } - float f2 = 1.0f; - if (d < 0.0) { - f2 = -0.5f; - } else if (d > 0.0) { - f2 = 0.5f; + float strafeFactor = 1.0f; + if (forward < 0.0) { + strafeFactor = -0.5f; + } else if (forward > 0.0) { + strafeFactor = 0.5f; } - if (d2 > 0.0) { - f -= 90.0f * f2; + if (strafe > 0.0) { + yaw -= 90.0f * strafeFactor; } - if (d2 < 0.0) { - f += 90.0f * f2; + if (strafe < 0.0) { + yaw += 90.0f * strafeFactor; } - return Math.toRadians(f); + return Math.toRadians(yaw); } - private static float getDirectionAngle(float f, float f2) { - boolean bl; - float f3 = mc.player.getYRot(); - boolean bl2 = f > 0.0f; - boolean bl3 = f < 0.0f; - boolean bl4 = f2 > 0.0f; - boolean bl5 = f2 < 0.0f; - boolean bl6 = bl4 || bl5; - boolean bl7 = bl = bl2 || bl3; - if (f != 0.0f || f2 != 0.0f) { - if (bl3 && !bl6) { - return f3 + 180.0f; + private static float getDirectionAngle(float forward, float strafe) { + boolean hasForward; + float yaw = mc.player.getYRot(); + boolean forwardPositive = forward > 0.0f; + boolean forwardNegative = forward < 0.0f; + boolean strafePositive = strafe > 0.0f; + boolean strafeNegative = strafe < 0.0f; + boolean hasStrafe = strafePositive || strafeNegative; + boolean hasForwardTmp = hasForward = forwardPositive || forwardNegative; + if (forward != 0.0f || strafe != 0.0f) { + if (forwardNegative && !hasStrafe) { + return yaw + 180.0f; } - if (bl2 && bl5) { - return f3 + 45.0f; + if (forwardPositive && strafeNegative) { + return yaw + 45.0f; } - if (bl2 && bl4) { - return f3 - 45.0f; + if (forwardPositive && strafePositive) { + return yaw - 45.0f; } - if (!bl && bl5) { - return f3 + 90.0f; + if (!hasForward && strafeNegative) { + return yaw + 90.0f; } - if (!bl && bl4) { - return f3 - 90.0f; + if (!hasForward && strafePositive) { + return yaw - 90.0f; } - if (bl3 && bl5) { - return f3 + 135.0f; + if (forwardNegative && strafeNegative) { + return yaw + 135.0f; } - if (bl3) { - return f3 - 135.0f; + if (forwardNegative) { + return yaw - 135.0f; } } - return f3; + return yaw; } public static double getEntitySpeed(Entity entity) { @@ -217,4 +217,4 @@ extends ClientBase { private MovementUtil() { throw new UnsupportedOperationException(UTILITY_MSG); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/game/PlayerUtil.java b/src/main/java/shit/zen/utils/game/PlayerUtil.java index aaf41d0..a48993d 100644 --- a/src/main/java/shit/zen/utils/game/PlayerUtil.java +++ b/src/main/java/shit/zen/utils/game/PlayerUtil.java @@ -34,11 +34,11 @@ extends ClientBase { return; } mc.player.walkAnimation.setSpeed(mc.player.walkAnimation.speed()); - double d = mc.player.getX() - mc.player.xo; - double d2 = mc.player.getZ() - mc.player.zo; - float f = Mth.sqrt((float)(d * d + d2 * d2)) * 4.0f; - f = Mth.clamp(f, 0.0f, 1.0f); - mc.player.walkAnimation.update(f, 0.4f); + double dx = mc.player.getX() - mc.player.xo; + double dz = mc.player.getZ() - mc.player.zo; + float speed = Mth.sqrt((float)(dx * dx + dz * dz)) * 4.0f; + speed = Mth.clamp(speed, 0.0f, 1.0f); + mc.player.walkAnimation.update(speed, 0.4f); } public static void sendCarriedItem() { @@ -52,14 +52,14 @@ extends ClientBase { } } - public static boolean isSafe(double d) { - int n = 0; - while ((double)n < d) { - AABB aABB = mc.player.getBoundingBox().move(0.0, -n, 0.0); + public static boolean isSafe(double maxFall) { + int offset = 0; + while ((double)offset < maxFall) { + AABB aABB = mc.player.getBoundingBox().move(0.0, -offset, 0.0); if (!PlayerUtil.isNoClip(mc.player, aABB)) { return true; } - n += 2; + offset += 2; } return false; } @@ -72,26 +72,26 @@ extends ClientBase { return true; } - public static void click(int n, boolean bl) { - InputConstants.Key key = n == 0 ? mc.options.keyAttack.getKey() : mc.options.keyUse.getKey(); - KeyMapping.set(key, bl); - if (bl) { + public static void click(int button, boolean pressed) { + InputConstants.Key key = button == 0 ? mc.options.keyAttack.getKey() : mc.options.keyUse.getKey(); + KeyMapping.set(key, pressed); + if (pressed) { KeyMapping.click(key); } } public static int getArmorPoints(LivingEntity livingEntity) { - int n = 0; + int totalDefense = 0; for (ItemStack itemStack : livingEntity.getArmorSlots()) { Item item = itemStack.getItem(); if (!(item instanceof ArmorItem armorItem)) continue; - n += armorItem.getDefense(); + totalDefense += armorItem.getDefense(); } - return n; + return totalDefense; } - public static Block getBlock(double d, double d2, double d3) { - return PlayerUtil.getBlock(BlockPos.containing(d, d2, d3)); + public static Block getBlock(double x, double y, double z) { + return PlayerUtil.getBlock(BlockPos.containing(x, y, z)); } public static Block getBlock(BlockPos blockPos) { @@ -105,36 +105,36 @@ extends ClientBase { return PlayerUtil.getBlock(BlockPos.containing(player.getX(), player.getY() - 1.0, player.getZ())); } - public static HitResult rayTrace(double d, float f, float f2) { + public static HitResult rayTrace(double range, float yaw, float pitch) { if (mc.player == null || mc.level == null) { return null; } - Vec3 vec3 = mc.player.getEyePosition(1.0f); - Vec3 vec32 = RotationUtil.directionFromRotation(new Rotation(f, f2)); - Vec3 vec33 = vec3.add(vec32.x * d, vec32.y * d, vec32.z * d); - return mc.level.clip(new ClipContext(vec3, vec33, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); + Vec3 eyePos = mc.player.getEyePosition(1.0f); + Vec3 lookDir = RotationUtil.directionFromRotation(new Rotation(yaw, pitch)); + Vec3 endPos = eyePos.add(lookDir.x * range, lookDir.y * range, lookDir.z * range); + return mc.level.clip(new ClipContext(eyePos, endPos, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); } public static boolean isSafeToScaffold() { if (mc.player == null || mc.level == null) { return true; } - Vec3 vec3 = mc.player.position(); - BlockPos blockPos = new BlockPos((int)Math.floor(vec3.x + Math.sin(Math.toRadians(mc.player.getYRot())) * 0.8), (int)Math.floor(vec3.y), (int)Math.floor(vec3.z + -Math.cos(Math.toRadians(mc.player.getYRot())) * 0.8)); - if (mc.level.getBlockState(blockPos).is(Blocks.LAVA)) { + Vec3 playerPos = mc.player.position(); + BlockPos frontPos = new BlockPos((int)Math.floor(playerPos.x + Math.sin(Math.toRadians(mc.player.getYRot())) * 0.8), (int)Math.floor(playerPos.y), (int)Math.floor(playerPos.z + -Math.cos(Math.toRadians(mc.player.getYRot())) * 0.8)); + if (mc.level.getBlockState(frontPos).is(Blocks.LAVA)) { return false; } - BlockPos blockPos2 = blockPos.below(); - BlockState blockState = mc.level.getBlockState(blockPos2); - if (blockState.is(Blocks.LAVA)) { + BlockPos belowPos = frontPos.below(); + BlockState belowState = mc.level.getBlockState(belowPos); + if (belowState.is(Blocks.LAVA)) { return false; } - if (blockState.isAir()) { - if (blockPos2.getY() < mc.level.getMinBuildHeight()) { + if (belowState.isAir()) { + if (belowPos.getY() < mc.level.getMinBuildHeight()) { return false; } - if (mc.level.getBlockState(blockPos2.below()).isAir()) { - return blockPos2.below().getY() >= mc.level.getMinBuildHeight() && !mc.level.getBlockState(blockPos2.below().below()).isAir(); + if (mc.level.getBlockState(belowPos.below()).isAir()) { + return belowPos.below().getY() >= mc.level.getMinBuildHeight() && !mc.level.getBlockState(belowPos.below().below()).isAir(); } } return true; @@ -144,4 +144,4 @@ extends ClientBase { private PlayerUtil() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/game/RayTraceUtil.java b/src/main/java/shit/zen/utils/game/RayTraceUtil.java index 332d138..a8862a1 100644 --- a/src/main/java/shit/zen/utils/game/RayTraceUtil.java +++ b/src/main/java/shit/zen/utils/game/RayTraceUtil.java @@ -22,118 +22,118 @@ public final class RayTraceUtil extends ClientBase { private static final String UTILITY_MSG = "This is a utility class and cannot be instantiated"; - public static boolean canRayTrace(Rotation rotation, Direction direction, BlockPos blockPos, boolean bl) { - Vec3 vec3; - Vec3 vec32; + public static boolean canRayTrace(Rotation rotation, Direction direction, BlockPos blockPos, boolean checkFace) { + Vec3 lookDir; + Vec3 endPos; if (mc.player == null || mc.level == null) { return false; } - float f = rotation.getYaw(); - float f2 = rotation.getPitch(); - Vec3 vec33 = mc.player.getEyePosition(1.0f); - BlockHitResult blockHitResult = mc.level.clip(new ClipContext(vec33, vec32 = vec33.add((vec3 = Vec3.directionFromRotation(f2, f)).scale(5.0)), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); + float yaw = rotation.getYaw(); + float pitch = rotation.getPitch(); + Vec3 eyePos = mc.player.getEyePosition(1.0f); + BlockHitResult blockHitResult = mc.level.clip(new ClipContext(eyePos, endPos = eyePos.add((lookDir = Vec3.directionFromRotation(pitch, yaw)).scale(5.0)), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); if (blockHitResult.getType() != HitResult.Type.BLOCK) { return false; } - boolean bl2 = blockHitResult.getBlockPos().equals(blockPos); - boolean bl3 = !bl || blockHitResult.getDirection() == direction; - return bl2 && bl3; + boolean samePos = blockHitResult.getBlockPos().equals(blockPos); + boolean sameFace = !checkFace || blockHitResult.getDirection() == direction; + return samePos && sameFace; } - public static HitResult rayTrace(float f, Rotation rotation) { + public static HitResult rayTrace(float partialTicks, Rotation rotation) { HitResult hitResult = null; Entity entity = mc.getCameraEntity(); if (entity != null && mc.level != null) { - double d = mc.gameMode.getPickRange(); - hitResult = RayTraceUtil.rayTrace(d, f, true, rotation.getYaw(), rotation.getPitch()); + double pickRange = mc.gameMode.getPickRange(); + hitResult = RayTraceUtil.rayTrace(pickRange, partialTicks, true, rotation.getYaw(), rotation.getPitch()); } return hitResult; } - public static HitResult rayTrace(double d, float f, boolean bl, Rotation rotation) { + public static HitResult rayTrace(double range, float partialTicks, boolean clipFluids, Rotation rotation) { HitResult hitResult = null; Entity entity = mc.getCameraEntity(); if (entity != null && mc.level != null) { - hitResult = RayTraceUtil.rayTrace(d, f, bl, rotation.getYaw(), rotation.getPitch()); + hitResult = RayTraceUtil.rayTrace(range, partialTicks, clipFluids, rotation.getYaw(), rotation.getPitch()); } return hitResult; } - public static Vec3 getViewVector(float f, float f2) { - float f3 = f * ((float)Math.PI / 180); - float f4 = -f2 * ((float)Math.PI / 180); - float f5 = Mth.cos(f4); - float f6 = Mth.sin(f4); - float f7 = Mth.cos(f3); - float f8 = Mth.sin(f3); - return new Vec3(f6 * f7, -f8, f5 * f7); + public static Vec3 getViewVector(float pitch, float yaw) { + float yawRad = yaw * ((float)Math.PI / 180); + float pitchRad = -pitch * ((float)Math.PI / 180); + float cosPitch = Mth.cos(pitchRad); + float sinPitch = Mth.sin(pitchRad); + float cosYaw = Mth.cos(yawRad); + float sinYaw = Mth.sin(yawRad); + return new Vec3(sinPitch * cosYaw, -sinYaw, cosPitch * cosYaw); } - public static HitResult rayTrace(double d, float f, boolean bl, float f2, float f3) { - Vec3 vec3 = new Vec3(mc.player.getX(), mc.player.getY() + 1.62, mc.player.getZ()); - Vec3 vec32 = RayTraceUtil.getViewVector(f3, f2); - Vec3 vec33 = vec3.add(vec32.x * d, vec32.y * d, vec32.z * d); - return mc.player.level().clip(new ClipContext(vec3, vec33, ClipContext.Block.OUTLINE, bl ? ClipContext.Fluid.ANY : ClipContext.Fluid.NONE, mc.player)); + public static HitResult rayTrace(double range, float partialTicks, boolean clipFluids, float yaw, float pitch) { + Vec3 eyePos = new Vec3(mc.player.getX(), mc.player.getY() + 1.62, mc.player.getZ()); + Vec3 viewVec = RayTraceUtil.getViewVector(pitch, yaw); + Vec3 endPos = eyePos.add(viewVec.x * range, viewVec.y * range, viewVec.z * range); + return mc.player.level().clip(new ClipContext(eyePos, endPos, ClipContext.Block.OUTLINE, clipFluids ? ClipContext.Fluid.ANY : ClipContext.Fluid.NONE, mc.player)); } - public static HitResult clipWithEntity(Vec3 vec3, Vec3 vec32, boolean bl, boolean bl2, boolean bl3, Entity entity) { - ClipContext.Block block = bl2 ? ClipContext.Block.COLLIDER : (bl3 ? ClipContext.Block.VISUAL : ClipContext.Block.OUTLINE); - ClipContext.Fluid fluid = bl ? ClipContext.Fluid.ANY : ClipContext.Fluid.NONE; - ClipContext clipContext = new ClipContext(vec3, vec32, block, fluid, entity); + public static HitResult clipWithEntity(Vec3 fromPos, Vec3 toPos, boolean clipFluids, boolean useCollider, boolean useVisual, Entity entity) { + ClipContext.Block blockMode = useCollider ? ClipContext.Block.COLLIDER : (useVisual ? ClipContext.Block.VISUAL : ClipContext.Block.OUTLINE); + ClipContext.Fluid fluidMode = clipFluids ? ClipContext.Fluid.ANY : ClipContext.Fluid.NONE; + ClipContext clipContext = new ClipContext(fromPos, toPos, blockMode, fluidMode, entity); return mc.level.clip(clipContext); } - public static EntityHitResult getEntityHit(AABB aABB, Vec3 vec32, Vec3 vec33) { - Optional optional = aABB.clip(vec32, vec33); - return optional.map(vec3 -> new EntityHitResult(null, vec3)).orElse(null); + public static EntityHitResult getEntityHit(AABB aABB, Vec3 fromPos, Vec3 toPos) { + Optional clipResult = aABB.clip(fromPos, toPos); + return clipResult.map(hit -> new EntityHitResult(null, hit)).orElse(null); } - public static HitResult rayTraceForEntity(Rotation rotation, double d, float f, Entity entity, Entity entity2, boolean bl) { + public static HitResult rayTraceForEntity(Rotation rotation, double range, float inflate, Entity entity, Entity onlyTarget, boolean ignoreBlocks) { if (entity == null || mc.level == null) { return null; } - float f2 = mc.getFrameTime(); - Vec3 vec3 = entity.getEyePosition(f2); - Vec3 vec32 = RotationUtil.directionFromRotation(rotation); - Vec3 vec33 = vec3.add(vec32.x * d, vec32.y * d, vec32.z * d); + float partialTicks = mc.getFrameTime(); + Vec3 eyePos = entity.getEyePosition(partialTicks); + Vec3 lookDir = RotationUtil.directionFromRotation(rotation); + Vec3 endPos = eyePos.add(lookDir.x * range, lookDir.y * range, lookDir.z * range); BlockHitResult blockHitResult = null; - double d2 = d; - if (!bl) { - blockHitResult = mc.level.clip(new ClipContext(vec3, vec33, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)); - d2 = blockHitResult.getType() == HitResult.Type.BLOCK ? vec3.distanceTo(blockHitResult.getLocation()) : d; + double blockDist = range; + if (!ignoreBlocks) { + blockHitResult = mc.level.clip(new ClipContext(eyePos, endPos, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)); + blockDist = blockHitResult.getType() == HitResult.Type.BLOCK ? eyePos.distanceTo(blockHitResult.getLocation()) : range; } - double d3 = Math.min(d, d2) + (double)f; - AABB aABB = new AABB(vec3.x - d3, vec3.y - d3, vec3.z - d3, vec3.x + d3, vec3.y + d3, vec3.z + d3); - List list = mc.level.getEntitiesOfClass(Entity.class, aABB, entity3 -> entity3 != entity && (entity2 == null || entity3 == entity2) && EntitySelector.NO_SPECTATORS.test(entity3) && entity3.isPickable()); - Entity entity4 = null; - Vec3 vec34 = null; - double d4 = Math.min(d, d2); - d4 *= d4; - for (Entity entity5 : list) { - Vec3 vec35; - BlockHitResult blockHitResult2; - Vec3 vec36; - double d5; - AABB aABB2 = entity5.getBoundingBox().inflate(f); - Optional optional = aABB2.clip(vec3, vec33); - if (!optional.isPresent() || !((d5 = vec3.distanceToSqr(vec36 = optional.get())) < d4)) continue; - boolean bl2 = bl || (blockHitResult2 = mc.level.clip(new ClipContext(vec3, vec35 = aABB2.getCenter(), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity))).getType() != HitResult.Type.BLOCK || !(vec3.distanceToSqr(blockHitResult2.getLocation()) <= d5); - if (!bl2) continue; - d4 = d5; - entity4 = entity5; - vec34 = vec36; + double searchRange = Math.min(range, blockDist) + (double)inflate; + AABB searchBox = new AABB(eyePos.x - searchRange, eyePos.y - searchRange, eyePos.z - searchRange, eyePos.x + searchRange, eyePos.y + searchRange, eyePos.z + searchRange); + List entities = mc.level.getEntitiesOfClass(Entity.class, searchBox, candidate -> candidate != entity && (onlyTarget == null || candidate == onlyTarget) && EntitySelector.NO_SPECTATORS.test(candidate) && candidate.isPickable()); + Entity hitEntity = null; + Vec3 hitVec = null; + double bestDistSqr = Math.min(range, blockDist); + bestDistSqr *= bestDistSqr; + for (Entity candidate : entities) { + Vec3 centerVec; + BlockHitResult occlusionResult; + Vec3 entityHitVec; + double candidateDistSqr; + AABB inflatedBox = candidate.getBoundingBox().inflate(inflate); + Optional optional = inflatedBox.clip(eyePos, endPos); + if (!optional.isPresent() || !((candidateDistSqr = eyePos.distanceToSqr(entityHitVec = optional.get())) < bestDistSqr)) continue; + boolean visible = ignoreBlocks || (occlusionResult = mc.level.clip(new ClipContext(eyePos, centerVec = inflatedBox.getCenter(), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity))).getType() != HitResult.Type.BLOCK || !(eyePos.distanceToSqr(occlusionResult.getLocation()) <= candidateDistSqr); + if (!visible) continue; + bestDistSqr = candidateDistSqr; + hitEntity = candidate; + hitVec = entityHitVec; } - if (entity4 != null) { - return new EntityHitResult(entity4, vec34); + if (hitEntity != null) { + return new EntityHitResult(hitEntity, hitVec); } - if (!bl && blockHitResult != null) { + if (!ignoreBlocks && blockHitResult != null) { return blockHitResult; } - return mc.level.clip(new ClipContext(vec3, vec33, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)); + return mc.level.clip(new ClipContext(eyePos, endPos, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)); } @Generated private RayTraceUtil() { throw new UnsupportedOperationException(UTILITY_MSG); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/game/RotationUtil.java b/src/main/java/shit/zen/utils/game/RotationUtil.java index b575cdf..15c27c4 100644 --- a/src/main/java/shit/zen/utils/game/RotationUtil.java +++ b/src/main/java/shit/zen/utils/game/RotationUtil.java @@ -31,137 +31,137 @@ extends ClientBase { return new Rotation(Mth.wrapDegrees(rotation.getYaw()), Mth.wrapDegrees(rotation.getPitch())); } - public static Rotation smoothRotation(Rotation rotation, Rotation rotation2, double d) { - float f = rotation2.getYaw(); - float f2 = rotation2.getPitch(); - float f3 = rotation.getYaw(); - float f4 = rotation.getPitch(); - if (d != 0.0) { - float f5 = (float)d; - double d2 = Mth.wrapDegrees(rotation2.getYaw() - rotation.getYaw()); - double d3 = f2 - f4; - double d4 = Math.sqrt(d2 * d2 + d3 * d3); - double d5 = Math.abs(d2 / d4); - double d6 = Math.abs(d3 / d4); - double d7 = (double)f5 * d5; - double d8 = (double)f5 * d6; - float f6 = (float)Math.max(Math.min(d2, d7), -d7); - float f7 = (float)Math.max(Math.min(d3, d8), -d8); - f = f3 + f6; - f2 = f4 + f7; + public static Rotation smoothRotation(Rotation current, Rotation target, double speed) { + float targetYaw = target.getYaw(); + float targetPitch = target.getPitch(); + float currYaw = current.getYaw(); + float currPitch = current.getPitch(); + if (speed != 0.0) { + float maxStep = (float)speed; + double yawDiff = Mth.wrapDegrees(target.getYaw() - current.getYaw()); + double pitchDiff = targetPitch - currPitch; + double dist = Math.sqrt(yawDiff * yawDiff + pitchDiff * pitchDiff); + double yawRatio = Math.abs(yawDiff / dist); + double pitchRatio = Math.abs(pitchDiff / dist); + double maxYawStep = (double)maxStep * yawRatio; + double maxPitchStep = (double)maxStep * pitchRatio; + float yawStep = (float)Math.max(Math.min(yawDiff, maxYawStep), -maxYawStep); + float pitchStep = (float)Math.max(Math.min(pitchDiff, maxPitchStep), -maxPitchStep); + targetYaw = currYaw + yawStep; + targetPitch = currPitch + pitchStep; } - boolean bl = Math.random() > 0.8; + boolean addJitter = Math.random() > 0.8; for (int i = 1; i <= (int)(2.0 + Math.random() * 2.0); ++i) { - Rotation rotation3; - Rotation rotation4; - if (bl) { - f += (float)((Math.random() - 0.5) / 1.0E8); - f2 -= (float)(Math.random() / 2.0E8); + Rotation candidate; + Rotation snapped; + if (addJitter) { + targetYaw += (float)((Math.random() - 0.5) / 1.0E8); + targetPitch -= (float)(Math.random() / 2.0E8); } - if ((rotation4 = (rotation3 = new Rotation(f, f2)).snapToSensitivity(Float.valueOf(mc.options.sensitivity().get().floatValue()))) == null) continue; - f = rotation4.getYaw(); - f2 = Mth.clamp(rotation4.getPitch(), -90.0f, 90.0f); + if ((snapped = (candidate = new Rotation(targetYaw, targetPitch)).snapToSensitivity(Float.valueOf(mc.options.sensitivity().get().floatValue()))) == null) continue; + targetYaw = snapped.getYaw(); + targetPitch = Mth.clamp(snapped.getPitch(), -90.0f, 90.0f); } - return new Rotation(f, f2); + return new Rotation(targetYaw, targetPitch); } - public static float clampAngle(float f, float f2) { - if (Math.abs(f) < f2) { - return f; + public static float clampAngle(float angle, float max) { + if (Math.abs(angle) < max) { + return angle; } - if (f > 0.0f) { - return f2; + if (angle > 0.0f) { + return max; } - if (f < 0.0f) { - return -f2; + if (angle < 0.0f) { + return -max; } return 0.0f; } - public static Rotation rotationTo(Vec3 vec3, Vec3 vec32) { - double d = vec32.x - vec3.x; - double d2 = vec32.y - vec3.y; - double d3 = vec32.z - vec3.z; - double d4 = Math.sqrt(d * d + d3 * d3); - float f = RotationUtil.toDegrees(Math.atan2(d3, d)) - 90.0f; - float f2 = RotationUtil.toDegrees(-Math.atan2(d2, d4)); - return new Rotation(f, f2); + public static Rotation rotationTo(Vec3 from, Vec3 to) { + double dx = to.x - from.x; + double dy = to.y - from.y; + double dz = to.z - from.z; + double horizontalDist = Math.sqrt(dx * dx + dz * dz); + float yaw = RotationUtil.toDegrees(Math.atan2(dz, dx)) - 90.0f; + float pitch = RotationUtil.toDegrees(-Math.atan2(dy, horizontalDist)); + return new Rotation(yaw, pitch); } - public static float toDegrees(double d) { - return (float)(d * 180.0 / Math.PI); + public static float toDegrees(double radians) { + return (float)(radians * 180.0 / Math.PI); } - public static Rotation rotationToForBow(Vec3 vec3, Vec3 vec32) { - double d = vec32.x - vec3.x; - double d2 = vec32.y - vec3.y; - double d3 = vec32.z - vec3.z; - return RotationUtil.rotationFromDeltas(d, d2, d3); + public static Rotation rotationToForBow(Vec3 from, Vec3 to) { + double dx = to.x - from.x; + double dy = to.y - from.y; + double dz = to.z - from.z; + return RotationUtil.rotationFromDeltas(dx, dy, dz); } - public static boolean isLookingAt(float f, LivingEntity livingEntity) { + public static boolean isLookingAt(float maxAngle, LivingEntity livingEntity) { if (mc.player == null) { return false; } - Vec3 vec3 = mc.player.getEyePosition(1.0f); - Vec3 vec32 = new Vec3(livingEntity.getX(), livingEntity.getY() + (double)livingEntity.getBbHeight() * 0.5, livingEntity.getZ()); - Vec3 vec33 = mc.player.getLookAngle(); - Vec3 vec34 = vec32.subtract(vec3); - if (vec34.lengthSqr() < 1.0E-7) { + Vec3 eyePos = mc.player.getEyePosition(1.0f); + Vec3 targetPos = new Vec3(livingEntity.getX(), livingEntity.getY() + (double)livingEntity.getBbHeight() * 0.5, livingEntity.getZ()); + Vec3 lookVec = mc.player.getLookAngle(); + Vec3 deltaVec = targetPos.subtract(eyePos); + if (deltaVec.lengthSqr() < 1.0E-7) { return true; } - Vec3 vec35 = vec34.normalize(); - double d = vec33.dot(vec35); - double d2 = Math.toDegrees(Math.acos(d)); - return f >= 180.0f || d2 <= (double)f; + Vec3 deltaNorm = deltaVec.normalize(); + double dot = lookVec.dot(deltaNorm); + double angleDegrees = Math.toDegrees(Math.acos(dot)); + return maxAngle >= 180.0f || angleDegrees <= (double)maxAngle; } - public static Rotation rotationFromEyes(Vec3 vec3) { + public static Rotation rotationFromEyes(Vec3 target) { if (mc.player == null) { return null; } - return RotationUtil.bowRotation(mc.player.position().add(0.0, mc.player.getEyeHeight(), 0.0), vec3); + return RotationUtil.bowRotation(mc.player.position().add(0.0, mc.player.getEyeHeight(), 0.0), target); } - public static Rotation bowRotation(Vec3 vec3, Vec3 vec32) { - Vec3 vec33 = vec32.add(0.0, -0.7, 0.0).subtract(vec3); - double d = Math.hypot(vec33.x, vec33.z); - double d2 = 0.03; - double d3 = 1.5; - float f = (float)(Mth.atan2(vec33.z, vec33.x) * 57.29577951308232) - 90.0f; - double d4 = d / 1.5; - double d5 = 0.015 * d4 * d4; - double d6 = vec33.y + d5; - double d7 = Math.atan2(d6, d); - float f2 = (float)(-(d7 * 57.29577951308232)); - return new Rotation(f, f2); + public static Rotation bowRotation(Vec3 from, Vec3 to) { + Vec3 delta = to.add(0.0, -0.7, 0.0).subtract(from); + double horizontalDist = Math.hypot(delta.x, delta.z); + double gravity = 0.03; + double velocity = 1.5; + float yaw = (float)(Mth.atan2(delta.z, delta.x) * 57.29577951308232) - 90.0f; + double normalizedDist = horizontalDist / 1.5; + double drop = 0.015 * normalizedDist * normalizedDist; + double adjustedDy = delta.y + drop; + double pitchRad = Math.atan2(adjustedDy, horizontalDist); + float pitch = (float)(-(pitchRad * 57.29577951308232)); + return new Rotation(yaw, pitch); } - public static Rotation rotationToBlock(BlockPos blockPos, float f) { - Vec3 vec3 = new Vec3(mc.player.getX() + mc.player.getDeltaMovement().x * (double)f, mc.player.getY() + (double)mc.player.getEyeHeight() + mc.player.getDeltaMovement().y() * (double)f, mc.player.getZ() + mc.player.getDeltaMovement().z() * (double)f); - double d = (double)blockPos.getX() - vec3.x + 0.5; - double d2 = (double)blockPos.getY() - vec3.y + 0.5; - double d3 = (double)blockPos.getZ() - vec3.z + 0.5; - return RotationUtil.rotationFromDeltas(RotationUtil.addNoise(d), RotationUtil.addNoise(d2), RotationUtil.addNoise(d3)); + public static Rotation rotationToBlock(BlockPos blockPos, float partialTicks) { + Vec3 predictedPos = new Vec3(mc.player.getX() + mc.player.getDeltaMovement().x * (double)partialTicks, mc.player.getY() + (double)mc.player.getEyeHeight() + mc.player.getDeltaMovement().y() * (double)partialTicks, mc.player.getZ() + mc.player.getDeltaMovement().z() * (double)partialTicks); + double dx = (double)blockPos.getX() - predictedPos.x + 0.5; + double dy = (double)blockPos.getY() - predictedPos.y + 0.5; + double dz = (double)blockPos.getZ() - predictedPos.z + 0.5; + return RotationUtil.rotationFromDeltas(RotationUtil.addNoise(dx), RotationUtil.addNoise(dy), RotationUtil.addNoise(dz)); } - public static Rotation rotationFromDeltas(double d, double d2, double d3) { - double d4 = Math.sqrt(d * d + d3 * d3); - float f = (float)Math.toDegrees(Math.atan2(d3, d)) - 90.0f; - float f2 = (float)(-Math.toDegrees(Math.atan2(d2, d4))); - return new Rotation(Mth.wrapDegrees(f), Mth.wrapDegrees(f2)); + public static Rotation rotationFromDeltas(double dx, double dy, double dz) { + double horizontalDist = Math.sqrt(dx * dx + dz * dz); + float yaw = (float)Math.toDegrees(Math.atan2(dz, dx)) - 90.0f; + float pitch = (float)(-Math.toDegrees(Math.atan2(dy, horizontalDist))); + return new Rotation(Mth.wrapDegrees(yaw), Mth.wrapDegrees(pitch)); } - private static double addNoise(double d) { - return d + MathUtil.randomDouble(0.05, 0.08) * (MathUtil.randomDouble(0.0, 1.0) * 2.0 - 1.0); + private static double addNoise(double value) { + return value + MathUtil.randomDouble(0.05, 0.08) * (MathUtil.randomDouble(0.0, 1.0) * 2.0 - 1.0); } - public static double getHitDistance(Entity entity, Vec3 vec3, Rotation rotation) { + public static double getHitDistance(Entity entity, Vec3 eyePos, Rotation rotation) { AABB aABB = RotationUtil.getEntityBB(entity); - HitResult hitResult = RotationUtil.raycastForBB(aABB, rotation, vec3, 6.0); + HitResult hitResult = RotationUtil.raycastForBB(aABB, rotation, eyePos, 6.0); if (hitResult != null) { - Vec3 vec32 = hitResult.getLocation(); - return vec32.distanceTo(vec3); + Vec3 hitLocation = hitResult.getLocation(); + return hitLocation.distanceTo(eyePos); } return 1000.0; } @@ -171,140 +171,140 @@ extends ClientBase { } public static double getMinHitDistance(Entity entity, Rotation rotation) { - double d = Double.MAX_VALUE; + double minDist = Double.MAX_VALUE; Iterator iterator = RotationUtil.getEyeHeights().iterator(); while (iterator.hasNext()) { - double d2 = iterator.next(); - Vec3 vec3 = new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ()); - Vec3 vec32 = vec3.add(0.0, d2, 0.0); - d = Math.min(d, RotationUtil.getHitDistance(entity, vec32, rotation)); + double eyeHeight = iterator.next(); + Vec3 playerPos = new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ()); + Vec3 eyePos = playerPos.add(0.0, eyeHeight, 0.0); + minDist = Math.min(minDist, RotationUtil.getHitDistance(entity, eyePos, rotation)); } - return d; + return minDist; } - public static HitResult raycastForBB(AABB aABB, Rotation rotation, Vec3 vec3, double d) { - Vec3 vec32 = RotationUtil.getDirection(rotation.getYaw(), rotation.getPitch()); - Vec3 vec33 = vec3.add(vec32.x * d, vec32.y * d, vec32.z * d); - return ProjectileUtil.getEntityHitResult(mc.player, vec3, vec33, aABB, entity -> !entity.isSpectator() && entity.isPickable(), d * d); + public static HitResult raycastForBB(AABB aABB, Rotation rotation, Vec3 eyePos, double range) { + Vec3 direction = RotationUtil.getDirection(rotation.getYaw(), rotation.getPitch()); + Vec3 endPos = eyePos.add(direction.x * range, direction.y * range, direction.z * range); + return ProjectileUtil.getEntityHitResult(mc.player, eyePos, endPos, aABB, entity -> !entity.isSpectator() && entity.isPickable(), range * range); } - public static float moveTowards(float f, float f2, float f3) { - return RotationUtil.rotateTowards(f2, f3, f); + public static float moveTowards(float maxStep, float current, float target) { + return RotationUtil.rotateTowards(current, target, maxStep); } - public static float rotateTowards(float f, float f2, float f3) { - float f4 = Mth.wrapDegrees(f2 - f); - if (f4 > f3) { - f4 = f3; + public static float rotateTowards(float current, float target, float maxStep) { + float diff = Mth.wrapDegrees(target - current); + if (diff > maxStep) { + diff = maxStep; } - if (f4 < -f3) { - f4 = -f3; + if (diff < -maxStep) { + diff = -maxStep; } - return f + f4; + return current + diff; } - public static float angleDiff(float f, float f2) { - float f3 = Math.abs(f - f2) % 360.0f; - if (f3 > 180.0f) { - f3 = 0.0f; + public static float angleDiff(float angleA, float angleB) { + float diff = Math.abs(angleA - angleB) % 360.0f; + if (diff > 180.0f) { + diff = 0.0f; } - return f3; + return diff; } - public static float ballisticPitch(float f, float f2, float f3, float f4) { - float f5 = f3 * f3 * f3 * f3 - f4 * (f4 * (f * f) + 2.0f * f2 * (f3 * f3)); - return (float)Math.toDegrees(Math.atan(((double)(f3 * f3) - Math.sqrt(f5)) / (double)(f4 * f))); + public static float ballisticPitch(float horizontalDist, float verticalDist, float velocity, float gravity) { + float discriminant = velocity * velocity * velocity * velocity - gravity * (gravity * (horizontalDist * horizontalDist) + 2.0f * verticalDist * (velocity * velocity)); + return (float)Math.toDegrees(Math.atan(((double)(velocity * velocity) - Math.sqrt(discriminant)) / (double)(gravity * horizontalDist))); } - public static float[] getBallisticAngles(Vec3 vec3) { + public static float[] getBallisticAngles(Vec3 target) { if (mc.player == null || mc.level == null) { return null; } - Vec3 vec32 = mc.player.getEyePosition(); - double d = 1.5; - double d2 = 0.03; - double d3 = 0.99; - double d4 = vec3.x - vec32.x; - double d5 = vec3.y - vec32.y; - double d6 = vec3.z - vec32.z; - float f = (float)(Math.toDegrees(Math.atan2(d6, d4)) - 90.0); - double d7 = Math.sqrt(d4 * d4 + d6 * d6); - if (d7 == 0.0) { - return new float[]{f, d5 > 0.0 ? -90.0f : 90.0f}; + Vec3 eyePos = mc.player.getEyePosition(); + double velocity = 1.5; + double gravity = 0.03; + double drag = 0.99; + double dx = target.x - eyePos.x; + double dy = target.y - eyePos.y; + double dz = target.z - eyePos.z; + float yaw = (float)(Math.toDegrees(Math.atan2(dz, dx)) - 90.0); + double horizontalDist = Math.sqrt(dx * dx + dz * dz); + if (horizontalDist == 0.0) { + return new float[]{yaw, dy > 0.0 ? -90.0f : 90.0f}; } - block0: for (float f2 = 90.0f; f2 >= -90.0f; f2 -= 0.5f) { - double d8 = Math.toRadians(f2); - double d9 = -Math.sin(Math.toRadians(f)) * Math.cos(d8); - double d10 = -Math.sin(d8); - double d11 = Math.cos(Math.toRadians(f)) * Math.cos(d8); - double d12 = Math.sqrt(d9 * d9 + d10 * d10 + d11 * d11); - d9 = d9 / d12 * d; - d10 = d10 / d12 * d; - d11 = d11 / d12 * d; - Vec3 vec33 = new Vec3(vec32.x, vec32.y, vec32.z); - Vec3 vec34 = new Vec3(d9, d10, d11); + block0: for (float pitch = 90.0f; pitch >= -90.0f; pitch -= 0.5f) { + double pitchRad = Math.toRadians(pitch); + double velX = -Math.sin(Math.toRadians(yaw)) * Math.cos(pitchRad); + double velY = -Math.sin(pitchRad); + double velZ = Math.cos(Math.toRadians(yaw)) * Math.cos(pitchRad); + double mag = Math.sqrt(velX * velX + velY * velY + velZ * velZ); + velX = velX / mag * velocity; + velY = velY / mag * velocity; + velZ = velZ / mag * velocity; + Vec3 projectilePos = new Vec3(eyePos.x, eyePos.y, eyePos.z); + Vec3 projectileVel = new Vec3(velX, velY, velZ); for (int i = 0; i < 300; ++i) { - vec33 = vec33.add(vec34); - vec34 = new Vec3(vec34.x * d3, vec34.y * d3 - d2, vec34.z * d3); - if (vec33.y < (double)(mc.level.getMinBuildHeight() - 10)) continue block0; - double d13 = Math.sqrt(Math.pow(vec33.x - vec32.x, 2.0) + Math.pow(vec33.z - vec32.z, 2.0)); - if (!(d13 >= d7)) continue; - if (Math.abs(vec33.y - vec3.y) < 1.0) { - return new float[]{Mth.wrapDegrees(f), Mth.wrapDegrees(f2)}; + projectilePos = projectilePos.add(projectileVel); + projectileVel = new Vec3(projectileVel.x * drag, projectileVel.y * drag - gravity, projectileVel.z * drag); + if (projectilePos.y < (double)(mc.level.getMinBuildHeight() - 10)) continue block0; + double traveledDist = Math.sqrt(Math.pow(projectilePos.x - eyePos.x, 2.0) + Math.pow(projectilePos.z - eyePos.z, 2.0)); + if (!(traveledDist >= horizontalDist)) continue; + if (Math.abs(projectilePos.y - target.y) < 1.0) { + return new float[]{Mth.wrapDegrees(yaw), Mth.wrapDegrees(pitch)}; } - if (vec34.y < 0.0 && vec33.y < vec3.y) continue block0; + if (projectileVel.y < 0.0 && projectilePos.y < target.y) continue block0; } } return null; } public static RotationUtil.BestHitInfo getBestHit(Entity entity) { - double d; - double d2; - Vec3 vec3 = new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ()); - Vec3 vec32 = vec3.add(0.0, mc.player.getEyeHeight(), 0.0); + double sampleAxis2; + double sampleAxis1; + Vec3 playerPos = new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ()); + Vec3 eyePos = playerPos.add(0.0, mc.player.getEyeHeight(), 0.0); AABB aABB = RotationUtil.getEntityBB(entity); - double d3 = aABB.minX; - double d4 = aABB.minY; - double d5 = aABB.minZ; - double d6 = aABB.maxX; - double d7 = aABB.maxY; - double d8 = aABB.maxZ; - double d9 = 0.1; - OrderedHashSet orderedHashSet = new OrderedHashSet<>(); - orderedHashSet.add(new Vec3(d3 + d6 / 2.0, d4 + d7 / 2.0, d5 + d8 / 2.0)); - orderedHashSet.add(RotationUtil.closestPoint(vec32, aABB)); - for (d2 = d3; d2 <= d6; d2 += d9) { - for (d = d4; d <= d7; d += d9) { - orderedHashSet.add(new Vec3(d2, d, d5)); - orderedHashSet.add(new Vec3(d2, d, d8)); + double minX = aABB.minX; + double minY = aABB.minY; + double minZ = aABB.minZ; + double maxX = aABB.maxX; + double maxY = aABB.maxY; + double maxZ = aABB.maxZ; + double step = 0.1; + OrderedHashSet samplePoints = new OrderedHashSet<>(); + samplePoints.add(new Vec3(minX + maxX / 2.0, minY + maxY / 2.0, minZ + maxZ / 2.0)); + samplePoints.add(RotationUtil.closestPoint(eyePos, aABB)); + for (sampleAxis1 = minX; sampleAxis1 <= maxX; sampleAxis1 += step) { + for (sampleAxis2 = minY; sampleAxis2 <= maxY; sampleAxis2 += step) { + samplePoints.add(new Vec3(sampleAxis1, sampleAxis2, minZ)); + samplePoints.add(new Vec3(sampleAxis1, sampleAxis2, maxZ)); } } - for (d2 = d3; d2 <= d6; d2 += d9) { - for (d = d5; d <= d8; d += d9) { - orderedHashSet.add(new Vec3(d2, d4, d)); - orderedHashSet.add(new Vec3(d2, d7, d)); + for (sampleAxis1 = minX; sampleAxis1 <= maxX; sampleAxis1 += step) { + for (sampleAxis2 = minZ; sampleAxis2 <= maxZ; sampleAxis2 += step) { + samplePoints.add(new Vec3(sampleAxis1, minY, sampleAxis2)); + samplePoints.add(new Vec3(sampleAxis1, maxY, sampleAxis2)); } } - for (d2 = d4; d2 <= d7; d2 += d9) { - for (d = d5; d <= d8; d += d9) { - orderedHashSet.add(new Vec3(d3, d2, d)); - orderedHashSet.add(new Vec3(d6, d2, d)); + for (sampleAxis1 = minY; sampleAxis1 <= maxY; sampleAxis1 += step) { + for (sampleAxis2 = minZ; sampleAxis2 <= maxZ; sampleAxis2 += step) { + samplePoints.add(new Vec3(minX, sampleAxis1, sampleAxis2)); + samplePoints.add(new Vec3(maxX, sampleAxis1, sampleAxis2)); } } - for (Vec3 vec33 : orderedHashSet) { + for (Vec3 samplePoint : samplePoints) { HitResult hitResult; - Rotation rotation = RotationUtil.exactRotation(vec32, vec33); + Rotation rotation = RotationUtil.exactRotation(eyePos, samplePoint); if (rotation == null) { logger.error("NULL????"); } if ((hitResult = RotationUtil.performRaycast(rotation)) == null) { logger.error("NULL2????"); } - if (!RotationUtil.isHitValid(vec32, hitResult, entity)) continue; + if (!RotationUtil.isHitValid(eyePos, hitResult, entity)) continue; try { - Vec3 vec34 = hitResult.getLocation(); - return new RotationUtil.BestHitInfo(vec32, vec34, vec34.distanceTo(vec32), RotationUtil.getSensitivitySnappedRotation(rotation.getYaw(), rotation.getPitch(), RotationHandler.prevRotation.yaw, RotationHandler.prevRotation.pitch)); + Vec3 hitLocation = hitResult.getLocation(); + return new RotationUtil.BestHitInfo(eyePos, hitLocation, hitLocation.distanceTo(eyePos), RotationUtil.getSensitivitySnappedRotation(rotation.getYaw(), rotation.getPitch(), RotationHandler.prevRotation.yaw, RotationHandler.prevRotation.pitch)); } catch (Exception exception) { logger.error("er here"); logger.error(exception); @@ -312,10 +312,10 @@ extends ClientBase { return null; } } - return new RotationUtil.BestHitInfo(vec32, vec32, 1000.0, null); + return new RotationUtil.BestHitInfo(eyePos, eyePos, 1000.0, null); } - public static Rotation getEntityRotation(Entity entity, float f, float f2, float f3) { + public static Rotation getEntityRotation(Entity entity, float spreadFactor, float verticalSpread, float heightFraction) { if (entity == null) { return null; } @@ -324,174 +324,174 @@ extends ClientBase { return null; } Random random = new Random(); - double d = (random.nextDouble() - 0.5) * (double)entity.getBbWidth() * 0.5 * (double)f; - double d2 = (random.nextDouble() - 0.5) * (double)entity.getBbWidth() * 0.5 * (double)f; - double d3 = entity.getY(); - d3 = f3 <= 0.1f ? (d3 += entity.getBbHeight() * 0.1f) : (f3 >= 0.9f ? (d3 += entity.getEyeHeight() * (0.8f + random.nextFloat() * 0.2f)) : (d3 += entity.getBbHeight() * Mth.clamp(f3, 0.1f, 0.9f))); - double d4 = (random.nextDouble() - 0.5) * (double)entity.getBbHeight() * 0.3 * (double)f2; - double d5 = entity.getX() + d; - double d6 = d3 + d4; - double d7 = entity.getZ() + d2; - double d8 = d5 - localPlayer.getX(); - double d9 = d6 - (localPlayer.getY() + (double)localPlayer.getEyeHeight()); - double d10 = d7 - localPlayer.getZ(); - double d11 = Mth.sqrt((float)(d8 * d8 + d10 * d10)); - float f4 = (float)(Math.atan2(d10, d8) * 180.0 / Math.PI) - 90.0f; - float f5 = (float)(-(Math.atan2(d9, d11) * 180.0 / Math.PI)); - float f6 = localPlayer.getYRot() + Mth.wrapDegrees(f4 - localPlayer.getYRot()); - float f7 = localPlayer.getXRot() + Mth.wrapDegrees(f5 - localPlayer.getXRot()); - f7 = Mth.clamp(f7, -90.0f, 90.0f); - return RotationUtil.getSensitivitySnappedRotation(f6, f7, RotationHandler.prevRotation.yaw, RotationHandler.prevRotation.pitch); + double offsetX = (random.nextDouble() - 0.5) * (double)entity.getBbWidth() * 0.5 * (double)spreadFactor; + double offsetZ = (random.nextDouble() - 0.5) * (double)entity.getBbWidth() * 0.5 * (double)spreadFactor; + double aimY = entity.getY(); + aimY = heightFraction <= 0.1f ? (aimY += entity.getBbHeight() * 0.1f) : (heightFraction >= 0.9f ? (aimY += entity.getEyeHeight() * (0.8f + random.nextFloat() * 0.2f)) : (aimY += entity.getBbHeight() * Mth.clamp(heightFraction, 0.1f, 0.9f))); + double offsetY = (random.nextDouble() - 0.5) * (double)entity.getBbHeight() * 0.3 * (double)verticalSpread; + double aimX = entity.getX() + offsetX; + double targetY = aimY + offsetY; + double aimZ = entity.getZ() + offsetZ; + double dx = aimX - localPlayer.getX(); + double dy = targetY - (localPlayer.getY() + (double)localPlayer.getEyeHeight()); + double dz = aimZ - localPlayer.getZ(); + double horizontalDist = Mth.sqrt((float)(dx * dx + dz * dz)); + float rawYaw = (float)(Math.atan2(dz, dx) * 180.0 / Math.PI) - 90.0f; + float rawPitch = (float)(-(Math.atan2(dy, horizontalDist) * 180.0 / Math.PI)); + float finalYaw = localPlayer.getYRot() + Mth.wrapDegrees(rawYaw - localPlayer.getYRot()); + float finalPitch = localPlayer.getXRot() + Mth.wrapDegrees(rawPitch - localPlayer.getXRot()); + finalPitch = Mth.clamp(finalPitch, -90.0f, 90.0f); + return RotationUtil.getSensitivitySnappedRotation(finalYaw, finalPitch, RotationHandler.prevRotation.yaw, RotationHandler.prevRotation.pitch); } - public static Rotation getSensitivitySnappedRotation(float f, float f2, float f3, float f4) { - float f5 = (float)(mc.options.sensitivity().get() * (double)0.6f + (double)0.2f); - float f6 = f5 * f5 * f5 * 1.2f; - float f7 = f - f3; - float f8 = f2 - f4; - float f9 = f7 - f7 % f6; - float f10 = f8 - f8 % f6; - float f11 = f3 + f9; - float f12 = f4 + f10; - return new Rotation(f11, f12); + public static Rotation getSensitivitySnappedRotation(float yaw, float pitch, float prevYaw, float prevPitch) { + float sensitivityFactor = (float)(mc.options.sensitivity().get() * (double)0.6f + (double)0.2f); + float gcd = sensitivityFactor * sensitivityFactor * sensitivityFactor * 1.2f; + float yawDelta = yaw - prevYaw; + float pitchDelta = pitch - prevPitch; + float snappedYawDelta = yawDelta - yawDelta % gcd; + float snappedPitchDelta = pitchDelta - pitchDelta % gcd; + float snappedYaw = prevYaw + snappedYawDelta; + float snappedPitch = prevPitch + snappedPitchDelta; + return new Rotation(snappedYaw, snappedPitch); } private static AABB getEntityBB(Entity entity) { return entity.getBoundingBox(); } - private static boolean isHitValid(Vec3 vec3, HitResult hitResult, Entity entity) { + private static boolean isHitValid(Vec3 eyePos, HitResult hitResult, Entity entity) { if (hitResult.getType() == HitResult.Type.ENTITY && ((EntityHitResult)hitResult).getEntity() == entity) { - Vec3 vec32 = hitResult.getLocation(); - return RotationUtil.isInsideAABB(RotationUtil.getEntityBB(entity), vec3) || vec32.distanceTo(vec3) <= 3.0; + Vec3 hitLocation = hitResult.getLocation(); + return RotationUtil.isInsideAABB(RotationUtil.getEntityBB(entity), eyePos) || hitLocation.distanceTo(eyePos) <= 3.0; } return false; } private static HitResult performRaycast(Rotation rotation) { - AABB aABB; - double d = mc.gameMode.getPickRange(); - HitResult hitResult = RayTraceUtil.rayTrace(d, 1.0f, false, rotation); - Vec3 vec3 = mc.player.getEyePosition(1.0f); - boolean bl = false; - double d2 = d; + AABB expandedBB; + double pickRange = mc.gameMode.getPickRange(); + HitResult hitResult = RayTraceUtil.rayTrace(pickRange, 1.0f, false, rotation); + Vec3 eyePos = mc.player.getEyePosition(1.0f); + boolean checkClampedRange = false; + double maxRangeSqr = pickRange; if (mc.gameMode.hasFarPickRange()) { - d = d2 = 6.0; - } else if (d > 3.0) { - bl = true; + pickRange = maxRangeSqr = 6.0; + } else if (pickRange > 3.0) { + checkClampedRange = true; } - d2 *= d2; + maxRangeSqr *= maxRangeSqr; if (hitResult != null) { - d2 = hitResult.getLocation().distanceToSqr(vec3); + maxRangeSqr = hitResult.getLocation().distanceToSqr(eyePos); } - Vec3 vec32 = RotationUtil.getDirection(rotation.getYaw(), rotation.getPitch()); - Vec3 vec33 = vec3.add(vec32.x * d, vec32.y * d, vec32.z * d); - EntityHitResult entityHitResult = ProjectileUtil.getEntityHitResult(mc.player, vec3, vec33, aABB = mc.player.getBoundingBox().expandTowards(vec32.scale(d)).inflate(1.0, 1.0, 1.0), entity -> !entity.isSpectator() && entity.isPickable(), d2); + Vec3 direction = RotationUtil.getDirection(rotation.getYaw(), rotation.getPitch()); + Vec3 endPos = eyePos.add(direction.x * pickRange, direction.y * pickRange, direction.z * pickRange); + EntityHitResult entityHitResult = ProjectileUtil.getEntityHitResult(mc.player, eyePos, endPos, expandedBB = mc.player.getBoundingBox().expandTowards(direction.scale(pickRange)).inflate(1.0, 1.0, 1.0), entity -> !entity.isSpectator() && entity.isPickable(), maxRangeSqr); if (entityHitResult != null) { - Vec3 vec34 = entityHitResult.getLocation(); - double d3 = vec3.distanceToSqr(vec34); - if (bl && d3 > 9.0) { - hitResult = BlockHitResult.miss(vec34, Direction.getNearest(vec32.x, vec32.y, vec32.z), BlockPos.containing(vec34)); - } else if (d3 < d2 || hitResult == null) { + Vec3 hitLocation = entityHitResult.getLocation(); + double hitDistSqr = eyePos.distanceToSqr(hitLocation); + if (checkClampedRange && hitDistSqr > 9.0) { + hitResult = BlockHitResult.miss(hitLocation, Direction.getNearest(direction.x, direction.y, direction.z), BlockPos.containing(hitLocation)); + } else if (hitDistSqr < maxRangeSqr || hitResult == null) { hitResult = entityHitResult; } } return hitResult; } - public static Vec3 getDirection(float f, float f2) { - float f3 = Mth.cos(-f * ((float)Math.PI / 180) - (float)Math.PI); - float f4 = Mth.sin(-f * ((float)Math.PI / 180) - (float)Math.PI); - float f5 = -Mth.cos(-f2 * ((float)Math.PI / 180)); - float f6 = Mth.sin(-f2 * ((float)Math.PI / 180)); - return new Vec3(f4 * f5, f6, f3 * f5); + public static Vec3 getDirection(float yaw, float pitch) { + float cosYaw = Mth.cos(-yaw * ((float)Math.PI / 180) - (float)Math.PI); + float sinYaw = Mth.sin(-yaw * ((float)Math.PI / 180) - (float)Math.PI); + float cosPitch = -Mth.cos(-pitch * ((float)Math.PI / 180)); + float sinPitch = Mth.sin(-pitch * ((float)Math.PI / 180)); + return new Vec3(sinYaw * cosPitch, sinPitch, cosYaw * cosPitch); } - public static boolean isInsideAABB(AABB aABB, Vec3 vec3) { - return vec3.x > aABB.minX && vec3.x < aABB.maxX && vec3.y > aABB.minY && vec3.y < aABB.maxY && vec3.z > aABB.minZ && vec3.z < aABB.maxZ; + public static boolean isInsideAABB(AABB aABB, Vec3 point) { + return point.x > aABB.minX && point.x < aABB.maxX && point.y > aABB.minY && point.y < aABB.maxY && point.z > aABB.minZ && point.z < aABB.maxZ; } - public static Rotation exactRotation(Vec3 vec3, Vec3 vec32) { - double d = vec32.x - vec3.x; - double d2 = vec32.y - vec3.y; - double d3 = vec32.z - vec3.z; - double d4 = Math.sqrt(d * d + d3 * d3); - float f = (float)Math.toDegrees(Math.atan2(d3, d)) - 90.0f; - float f2 = (float)(-Math.toDegrees(Math.atan2(d2, d4))); - return new Rotation(Mth.wrapDegrees(f), Mth.wrapDegrees(f2)); + public static Rotation exactRotation(Vec3 from, Vec3 to) { + double dx = to.x - from.x; + double dy = to.y - from.y; + double dz = to.z - from.z; + double horizontalDist = Math.sqrt(dx * dx + dz * dz); + float yaw = (float)Math.toDegrees(Math.atan2(dz, dx)) - 90.0f; + float pitch = (float)(-Math.toDegrees(Math.atan2(dy, horizontalDist))); + return new Rotation(Mth.wrapDegrees(yaw), Mth.wrapDegrees(pitch)); } - public static Vec3 closestPoint(Vec3 vec3, AABB aABB) { - double d = Math.max(aABB.minX, Math.min(vec3.x, aABB.maxX)); - double d2 = Math.max(aABB.minY, Math.min(vec3.y, aABB.maxY)); - double d3 = Math.max(aABB.minZ, Math.min(vec3.z, aABB.maxZ)); - return new Vec3(d, d2, d3); + public static Vec3 closestPoint(Vec3 point, AABB aABB) { + double clampedX = Math.max(aABB.minX, Math.min(point.x, aABB.maxX)); + double clampedY = Math.max(aABB.minY, Math.min(point.y, aABB.maxY)); + double clampedZ = Math.max(aABB.minZ, Math.min(point.z, aABB.maxZ)); + return new Vec3(clampedX, clampedY, clampedZ); } - public static Rotation rotationFromVec(Vec3 vec3) { - return RotationUtil.rotationFromCoords(vec3.x, vec3.y, vec3.z); + public static Rotation rotationFromVec(Vec3 target) { + return RotationUtil.rotationFromCoords(target.x, target.y, target.z); } - public static Rotation rotationFromCoords(double d, double d2, double d3) { + public static Rotation rotationFromCoords(double x, double y, double z) { if (mc.player == null) { return new Rotation(0.0f, 0.0f); } - return RotationUtil.rotationFromPoints(d, d2, d3, mc.player.getX(), mc.player.getY() + (double)mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ()); + return RotationUtil.rotationFromPoints(x, y, z, mc.player.getX(), mc.player.getY() + (double)mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ()); } - private static double normalizeAngle(double d) { - return ((d + 180.0) % 360.0 + 360.0) % 360.0 - 180.0; + private static double normalizeAngle(double angle) { + return ((angle + 180.0) % 360.0 + 360.0) % 360.0 - 180.0; } - public static double angleDiffDouble(float f, float f2) { - double d = f - f2; - return RotationUtil.normalizeAngle(d); + public static double angleDiffDouble(float angleA, float angleB) { + double diff = angleA - angleB; + return RotationUtil.normalizeAngle(diff); } - public static Rotation rotationFromPoints(double d, double d2, double d3, double d4, double d5, double d6) { - double d7 = RotationUtil.addNoise(d - d4); - double d8 = RotationUtil.addNoise(d2 - d5); - double d9 = RotationUtil.addNoise(d3 - d6); - double d10 = Mth.sqrt((float)(d7 * d7 + d9 * d9)); - float f = (float)(Math.atan2(d9, d7) * 180.0 / Math.PI) - 90.0f; - float f2 = (float)(-(Math.atan2(d8, d10) * 180.0 / Math.PI)); - return new Rotation(f, f2); + public static Rotation rotationFromPoints(double targetX, double targetY, double targetZ, double fromX, double fromY, double fromZ) { + double dx = RotationUtil.addNoise(targetX - fromX); + double dy = RotationUtil.addNoise(targetY - fromY); + double dz = RotationUtil.addNoise(targetZ - fromZ); + double horizontalDist = Mth.sqrt((float)(dx * dx + dz * dz)); + float yaw = (float)(Math.atan2(dz, dx) * 180.0 / Math.PI) - 90.0f; + float pitch = (float)(-(Math.atan2(dy, horizontalDist) * 180.0 / Math.PI)); + return new Rotation(yaw, pitch); } public static Rotation entityRotation(Entity entity) { if (entity == null) { return null; } - double d = entity.getX() - mc.player.getX(); - double d2 = entity.getZ() - mc.player.getZ(); - double d3 = entity.getY() + (double)entity.getEyeHeight() - (mc.player.getY() + (double)mc.player.getEyeHeight()); - return RotationUtil.createRotation(d, d3, d2); + double dx = entity.getX() - mc.player.getX(); + double dz = entity.getZ() - mc.player.getZ(); + double dy = entity.getY() + (double)entity.getEyeHeight() - (mc.player.getY() + (double)mc.player.getEyeHeight()); + return RotationUtil.createRotation(dx, dy, dz); } - public static Rotation createRotation(double d, double d2, double d3) { - double d4 = Math.sqrt(d * d + d3 * d3); - float f = (float)Math.toDegrees(Math.atan2(d3, d)) - 90.0f; - float f2 = (float)(-Math.toDegrees(Math.atan2(d2, d4))); - return new Rotation(Mth.wrapDegrees(f), Mth.wrapDegrees(f2)); + public static Rotation createRotation(double dx, double dy, double dz) { + double horizontalDist = Math.sqrt(dx * dx + dz * dz); + float yaw = (float)Math.toDegrees(Math.atan2(dz, dx)) - 90.0f; + float pitch = (float)(-Math.toDegrees(Math.atan2(dy, horizontalDist))); + return new Rotation(Mth.wrapDegrees(yaw), Mth.wrapDegrees(pitch)); } - public static boolean isEntityInFov(Entity entity, float f) { + public static boolean isEntityInFov(Entity entity, float fov) { Rotation rotation = RotationUtil.entityRotation(entity); - float f2 = Math.abs(mc.player.getYRot() % 360.0f - rotation.getYaw()); - float f3 = Math.abs(Math.min(f2, 360.0f - f2)); - return f3 <= f; + float yawDiff = Math.abs(mc.player.getYRot() % 360.0f - rotation.getYaw()); + float wrappedDiff = Math.abs(Math.min(yawDiff, 360.0f - yawDiff)); + return wrappedDiff <= fov; } public static Vec3 directionFromRotation(Rotation rotation) { - float f = (float)Math.cos(-rotation.getYaw() * ((float)Math.PI / 180) - (float)Math.PI); - float f2 = (float)Math.sin(-rotation.getYaw() * ((float)Math.PI / 180) - (float)Math.PI); - float f3 = (float)(-Math.cos(-rotation.getPitch() * ((float)Math.PI / 180))); - float f4 = (float)Math.sin(-rotation.getPitch() * ((float)Math.PI / 180)); - return new Vec3(f2 * f3, f4, f * f3); + float cosYaw = (float)Math.cos(-rotation.getYaw() * ((float)Math.PI / 180) - (float)Math.PI); + float sinYaw = (float)Math.sin(-rotation.getYaw() * ((float)Math.PI / 180) - (float)Math.PI); + float cosPitch = (float)(-Math.cos(-rotation.getPitch() * ((float)Math.PI / 180))); + float sinPitch = (float)Math.sin(-rotation.getPitch() * ((float)Math.PI / 180)); + return new Vec3(sinYaw * cosPitch, sinPitch, cosYaw * cosPitch); } @Generated private RotationUtil() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/math/CubicBezier.java b/src/main/java/shit/zen/utils/math/CubicBezier.java index 4b03ec9..fe318dd 100644 --- a/src/main/java/shit/zen/utils/math/CubicBezier.java +++ b/src/main/java/shit/zen/utils/math/CubicBezier.java @@ -21,46 +21,46 @@ extends AbstractEasing { this.setSampleCount(30); } - public CubicBezier(int n) { + public CubicBezier(int sampleCount) { this(); - this.setSampleCount(n); + this.setSampleCount(sampleCount); } - public CubicBezier(Point2d point2d, Point2d point2d2) { - this.localP1 = point2d; - this.localP2 = point2d2; + public CubicBezier(Point2d p1, Point2d p2) { + this.localP1 = p1; + this.localP2 = p2; this.setSampleCount(30); } - public CubicBezier(Point2d point2d, Point2d point2d2, int n) { - this(point2d, point2d2); - this.setSampleCount(n); + public CubicBezier(Point2d p1, Point2d p2, int sampleCount) { + this(p1, p2); + this.setSampleCount(sampleCount); } - public CubicBezier(CubicBezier cubicBezier) { - this.localP1 = cubicBezier.getP1(); - this.localP2 = cubicBezier.getP2(); + public CubicBezier(CubicBezier other) { + this.localP1 = other.getP1(); + this.localP2 = other.getP2(); this.setSampleCount(30); } - public CubicBezier(CubicBezier cubicBezier, int n) { - this(cubicBezier); - this.setSampleCount(n); + public CubicBezier(CubicBezier other, int sampleCount) { + this(other); + this.setSampleCount(sampleCount); } - public CubicBezier(String string) { - String[] stringArray = string.replace(" ", "").split(","); - if (stringArray.length != 4) { - throw new IllegalArgumentException("Couldn't parse " + string + ", please follow this format: x1,y1,x2,y2"); + public CubicBezier(String spec) { + String[] parts = spec.replace(" ", "").split(","); + if (parts.length != 4) { + throw new IllegalArgumentException("Couldn't parse " + spec + ", please follow this format: x1,y1,x2,y2"); } - this.localP1 = new Point2d(stringArray[0] + "," + stringArray[1]); - this.localP2 = new Point2d(stringArray[2] + "," + stringArray[3]); + this.localP1 = new Point2d(parts[0] + "," + parts[1]); + this.localP2 = new Point2d(parts[2] + "," + parts[3]); this.setSampleCount(30); } - public CubicBezier(String string, int n) { - this(string); - this.setSampleCount(n); + public CubicBezier(String spec, int sampleCount) { + this(spec); + this.setSampleCount(sampleCount); } private void buildLookupTable() { @@ -68,61 +68,61 @@ extends AbstractEasing { return; } this.lookupTable.clear(); - double d = 0.03333333333333333; - for (double d2 = 0.0; d2 <= 1.0; d2 += d) { - Point2d point2d = this.computeBezier(d2); - this.lookupTable.add(new Point2d(point2d.x, 1.0).sub(0.0, point2d.y)); + double step = 0.03333333333333333; + for (double t = 0.0; t <= 1.0; t += step) { + Point2d point = this.computeBezier(t); + this.lookupTable.add(new Point2d(point.x, 1.0).sub(0.0, point.y)); } this.lookupTable.add(new Point2d(1.0, 0.0)); } - private Point2d computeBezier(double d) { + private Point2d computeBezier(double t) { if (this.localP1 == null || this.localP2 == null) { throw new NullPointerException("firstPoint or secondPoint is null"); } - Point2d point2d = this.localP1.copy(); - Point2d point2d2 = this.localP2.copy(); - double d2 = 1.0 - d; - return new Point2d(this.p1.x * Math.pow(d2, 3.0) + 3.0 * point2d.x * d * Math.pow(d2, 2.0) + 3.0 * point2d2.x * Math.pow(d, 2.0) * d2 + this.p2.x * Math.pow(d, 3.0), this.p1.y * Math.pow(d2, 3.0) + 3.0 * point2d.y * d * Math.pow(d2, 2.0) + 3.0 * point2d2.y * Math.pow(d, 2.0) * d2 + this.p2.y * Math.pow(d, 3.0)); + Point2d cp1 = this.localP1.copy(); + Point2d cp2 = this.localP2.copy(); + double inv = 1.0 - t; + return new Point2d(this.p1.x * Math.pow(inv, 3.0) + 3.0 * cp1.x * t * Math.pow(inv, 2.0) + 3.0 * cp2.x * Math.pow(t, 2.0) * inv + this.p2.x * Math.pow(t, 3.0), this.p1.y * Math.pow(inv, 3.0) + 3.0 * cp1.y * t * Math.pow(inv, 2.0) + 3.0 * cp2.y * Math.pow(t, 2.0) * inv + this.p2.y * Math.pow(t, 3.0)); } - private Map.Entry findClosestEntry(double d) { + private Map.Entry findClosestEntry(double t) { if (this.lookupTable.isEmpty()) { return new AbstractMap.SimpleEntry(new Point2d(0.0, 0.0), new Point2d(0.0, 0.0)); } - Point2d point2d = this.lookupTable.get(0); - Point2d point2d2 = this.lookupTable.get(this.lookupTable.size() - 1); - for (Point2d point2d3 : this.lookupTable) { - if (point2d3.x < d) { - point2d = point2d3; + Point2d lower = this.lookupTable.get(0); + Point2d upper = this.lookupTable.get(this.lookupTable.size() - 1); + for (Point2d entry : this.lookupTable) { + if (entry.x < t) { + lower = entry; continue; } - if (!(point2d3.x > d) || !(point2d2.x >= point2d3.x)) continue; - point2d2 = point2d3; + if (!(entry.x > t) || !(upper.x >= entry.x)) continue; + upper = entry; break; } - if (point2d2.x < d) { - point2d2 = point2d; + if (upper.x < t) { + upper = lower; } - if (point2d.x > d) { - point2d = point2d2; + if (lower.x > t) { + lower = upper; } - return new AbstractMap.SimpleEntry(point2d, point2d2); + return new AbstractMap.SimpleEntry(lower, upper); } @Override - public double ease(double d) { - Point2d point2d; + public double ease(double t) { + Point2d upper; if (this.localP1 == null || this.localP2 == null) { return 0.0; } - Map.Entry entry = this.findClosestEntry(d); - Point2d point2d2 = entry.getKey(); - if (point2d2.equals(point2d = entry.getValue())) { - return 1.0 - point2d2.y; + Map.Entry entry = this.findClosestEntry(t); + Point2d lower = entry.getKey(); + if (lower.equals(upper = entry.getValue())) { + return 1.0 - lower.y; } - double d2 = (point2d.y - point2d2.y) / (point2d.x - point2d2.x) * (d - point2d2.x) + point2d2.y; - return 1.0 - d2; + double interpolatedY = (upper.y - lower.y) / (upper.x - lower.x) * (t - lower.x) + lower.y; + return 1.0 - interpolatedY; } public Point2d getP1() { @@ -141,15 +141,15 @@ extends AbstractEasing { return this.sampleCount; } - public void setSampleCount(int n) { - if (this.sampleCount == n) { + public void setSampleCount(int sampleCount) { + if (this.sampleCount == sampleCount) { return; } - this.sampleCount = n; + this.sampleCount = sampleCount; this.buildLookupTable(); } public CubicBezier copy() { return new CubicBezier(this); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/math/Easings.java b/src/main/java/shit/zen/utils/math/Easings.java index 05720d4..965bc3c 100644 --- a/src/main/java/shit/zen/utils/math/Easings.java +++ b/src/main/java/shit/zen/utils/math/Easings.java @@ -3,146 +3,146 @@ package shit.zen.utils.math; import shit.zen.utils.math.Easing; public class Easings { - public static final Easing BACK_OUT = d -> 1.0 + 2.70158 * Math.pow(d - 1.0, 3.0) + 1.70158 * Math.pow(d - 1.0, 2.0); - public static final Easing EASE_OUT_QUAD = d -> 1.0 - (d - 1.0) * (d - 1.0); + public static final Easing BACK_OUT = t -> 1.0 + 2.70158 * Math.pow(t - 1.0, 3.0) + 1.70158 * Math.pow(t - 1.0, 2.0); + public static final Easing EASE_OUT_QUAD = t -> 1.0 - (t - 1.0) * (t - 1.0); public static final Easing EASE_OUT_POW2 = Easings.easeOut(2); public static final Easing EASE_IN_POW3 = Easings.easeIn(3); public static final Easing EASE_OUT_POW3 = Easings.easeOut(3); public static final Easing EASE_OUT_POW4 = Easings.easeOut(4); public static final Easing EASE_OUT_POW5 = Easings.easeOut(5); - public static final Easing EASE_OUT_SINE = d -> Math.sin(d * Math.PI / 2.0); - public static final Easing EASE_OUT_ELASTIC = d -> { - if (d == 0.0 || d == 1.0) { - return d; + public static final Easing EASE_OUT_SINE = t -> Math.sin(t * Math.PI / 2.0); + public static final Easing EASE_OUT_ELASTIC = t -> { + if (t == 0.0 || t == 1.0) { + return t; } - return Math.pow(2.0, -10.0 * d) * Math.sin((d * 10.0 - 0.75) * 2.0943951023931953) + 1.0; + return Math.pow(2.0, -10.0 * t) * Math.sin((t * 10.0 - 0.75) * 2.0943951023931953) + 1.0; }; - public static final Easing EASE_OUT_BOUNCE = d -> { - double d2 = 7.5625; - double d3 = 2.75; - if (d < 1.0 / d3) { - return d2 * Math.pow(d, 2.0); + public static final Easing EASE_OUT_BOUNCE = t -> { + double n1 = 7.5625; + double d1 = 2.75; + if (t < 1.0 / d1) { + return n1 * Math.pow(t, 2.0); } - if (d < 2.0 / d3) { - return d2 * Math.pow(d - 1.5 / d3, 2.0) + 0.75; + if (t < 2.0 / d1) { + return n1 * Math.pow(t - 1.5 / d1, 2.0) + 0.75; } - if (d < 2.5 / d3) { - return d2 * Math.pow(d - 2.25 / d3, 2.0) + 0.9375; + if (t < 2.5 / d1) { + return n1 * Math.pow(t - 2.25 / d1, 2.0) + 0.9375; } - return d2 * Math.pow(d - 2.625 / d3, 2.0) + 0.984375; + return n1 * Math.pow(t - 2.625 / d1, 2.0) + 0.984375; }; private Easings() { } - public static Easing easeIn(double d) { - return d2 -> Math.pow(d2, d); + public static Easing easeIn(double power) { + return t -> Math.pow(t, power); } - public static Easing easeIn(int n) { - return Easings.easeIn((double)n); + public static Easing easeIn(int power) { + return Easings.easeIn((double)power); } - public static Easing easeOut(double d) { - return d2 -> 1.0 - Math.pow(1.0 - d2, d); + public static Easing easeOut(double power) { + return t -> 1.0 - Math.pow(1.0 - t, power); } - public static Easing easeOut(int n) { - return Easings.easeOut((double)n); + public static Easing easeOut(int power) { + return Easings.easeOut((double)power); } - public static Easing easeInOut(double d) { - return d2 -> { - if (d2 < 0.5) { - return Math.pow(2.0, d - 1.0) * Math.pow(d2, d); + public static Easing easeInOut(double power) { + return t -> { + if (t < 0.5) { + return Math.pow(2.0, power - 1.0) * Math.pow(t, power); } - return 1.0 - Math.pow(-2.0 * d2 + 2.0, d) / 2.0; + return 1.0 - Math.pow(-2.0 * t + 2.0, power) / 2.0; }; } - private static /* synthetic */ double easeInOutBounce(double d) { - if (d < 0.5) { - return (1.0 - EASE_OUT_BOUNCE.ease(1.0 - 2.0 * d)) / 2.0; + private static /* synthetic */ double easeInOutBounce(double t) { + if (t < 0.5) { + return (1.0 - EASE_OUT_BOUNCE.ease(1.0 - 2.0 * t)) / 2.0; } - return (1.0 + EASE_OUT_BOUNCE.ease(2.0 * d - 1.0)) / 2.0; + return (1.0 + EASE_OUT_BOUNCE.ease(2.0 * t - 1.0)) / 2.0; } - private static /* synthetic */ double easeInBounce(double d) { - return 1.0 - EASE_OUT_BOUNCE.ease(1.0 - d); + private static /* synthetic */ double easeInBounce(double t) { + return 1.0 - EASE_OUT_BOUNCE.ease(1.0 - t); } - private static /* synthetic */ double easeInOutExpo(double d) { - if (d == 0.0 || d == 1.0) { - return d; + private static /* synthetic */ double easeInOutExpo(double t) { + if (t == 0.0 || t == 1.0) { + return t; } - if (d < 0.5) { - return Math.pow(2.0, 20.0 * d - 10.0) / 2.0; + if (t < 0.5) { + return Math.pow(2.0, 20.0 * t - 10.0) / 2.0; } - return (2.0 - Math.pow(2.0, -20.0 * d + 10.0)) / 2.0; + return (2.0 - Math.pow(2.0, -20.0 * t + 10.0)) / 2.0; } - private static /* synthetic */ double easeOutExpo(double d) { - if (d != 1.0) { - return 1.0 - Math.pow(2.0, -10.0 * d); + private static /* synthetic */ double easeOutExpo(double t) { + if (t != 1.0) { + return 1.0 - Math.pow(2.0, -10.0 * t); } - return d; + return t; } - private static /* synthetic */ double easeInExpo(double d) { - if (d != 0.0) { - return Math.pow(2.0, 10.0 * d - 10.0); + private static /* synthetic */ double easeInExpo(double t) { + if (t != 0.0) { + return Math.pow(2.0, 10.0 * t - 10.0); } - return d; + return t; } - private static /* synthetic */ double easeInOutElastic(double d) { - if (d == 0.0 || d == 1.0) { - return d; + private static /* synthetic */ double easeInOutElastic(double t) { + if (t == 0.0 || t == 1.0) { + return t; } - if (d < 0.5) { - return -(Math.pow(2.0, 20.0 * d - 10.0) * Math.sin((20.0 * d - 11.125) * 1.3962634015954636)) / 2.0; + if (t < 0.5) { + return -(Math.pow(2.0, 20.0 * t - 10.0) * Math.sin((20.0 * t - 11.125) * 1.3962634015954636)) / 2.0; } - return Math.pow(2.0, -20.0 * d + 10.0) * Math.sin((20.0 * d - 11.125) * 1.3962634015954636) / 2.0 + 1.0; + return Math.pow(2.0, -20.0 * t + 10.0) * Math.sin((20.0 * t - 11.125) * 1.3962634015954636) / 2.0 + 1.0; } - private static /* synthetic */ double easeInElastic(double d) { - if (d == 0.0 || d == 1.0) { - return d; + private static /* synthetic */ double easeInElastic(double t) { + if (t == 0.0 || t == 1.0) { + return t; } - return Math.pow(-2.0, 10.0 * d - 10.0) * Math.sin((d * 10.0 - 10.75) * 2.0943951023931953); + return Math.pow(-2.0, 10.0 * t - 10.0) * Math.sin((t * 10.0 - 10.75) * 2.0943951023931953); } - private static /* synthetic */ double easeInOutCirc(double d) { - if (d < 0.5) { - return (1.0 - Math.sqrt(1.0 - Math.pow(2.0 * d, 2.0))) / 2.0; + private static /* synthetic */ double easeInOutCirc(double t) { + if (t < 0.5) { + return (1.0 - Math.sqrt(1.0 - Math.pow(2.0 * t, 2.0))) / 2.0; } - return (Math.sqrt(1.0 - Math.pow(-2.0 * d + 2.0, 2.0)) + 1.0) / 2.0; + return (Math.sqrt(1.0 - Math.pow(-2.0 * t + 2.0, 2.0)) + 1.0) / 2.0; } - private static /* synthetic */ double easeOutCirc(double d) { - return Math.sqrt(1.0 - Math.pow(d - 1.0, 2.0)); + private static /* synthetic */ double easeOutCirc(double t) { + return Math.sqrt(1.0 - Math.pow(t - 1.0, 2.0)); } - private static /* synthetic */ double easeInCirc(double d) { - return 1.0 - Math.sqrt(1.0 - Math.pow(d, 2.0)); + private static /* synthetic */ double easeInCirc(double t) { + return 1.0 - Math.sqrt(1.0 - Math.pow(t, 2.0)); } - private static /* synthetic */ double easeInOutSine(double d) { - return -(Math.cos(Math.PI * d) - 1.0) / 2.0; + private static /* synthetic */ double easeInOutSine(double t) { + return -(Math.cos(Math.PI * t) - 1.0) / 2.0; } - private static /* synthetic */ double easeInSine(double d) { - return 1.0 - Math.cos(d * Math.PI / 2.0); + private static /* synthetic */ double easeInSine(double t) { + return 1.0 - Math.cos(t * Math.PI / 2.0); } - private static /* synthetic */ double easeInBack(double d) { - return 2.70158 * Math.pow(d, 3.0) - 1.70158 * Math.pow(d, 2.0); + private static /* synthetic */ double easeInBack(double t) { + return 2.70158 * Math.pow(t, 3.0) - 1.70158 * Math.pow(t, 2.0); } - private static /* synthetic */ double easeInOutBack(double d) { - if (d < 0.5) { - return Math.pow(2.0 * d, 2.0) * (7.189819 * d - 2.5949095) / 2.0; + private static /* synthetic */ double easeInOutBack(double t) { + if (t < 0.5) { + return Math.pow(2.0 * t, 2.0) * (7.189819 * t - 2.5949095) / 2.0; } - return (Math.pow(2.0 * d - 2.0, 2.0) * (3.5949095 * (d * 2.0 - 2.0) + 2.5949095) + 2.0) / 2.0; + return (Math.pow(2.0 * t - 2.0, 2.0) * (3.5949095 * (t * 2.0 - 2.0) + 2.5949095) + 2.0) / 2.0; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/math/LerpUtil.java b/src/main/java/shit/zen/utils/math/LerpUtil.java index e07f09e..08a3272 100644 --- a/src/main/java/shit/zen/utils/math/LerpUtil.java +++ b/src/main/java/shit/zen/utils/math/LerpUtil.java @@ -13,40 +13,40 @@ public final class LerpUtil { } public static void update() { - long l = System.nanoTime(); + long now = System.nanoTime(); if (0L == 0L) { - lastTime = l; + lastTime = now; delta = 1.0f; return; } - float f = (float)(l) / 1.0E9f; - lastTime = l; - if (f <= 0.0f || Float.isNaN(f) || Float.isInfinite(f)) { + float elapsed = (float)(now) / 1.0E9f; + lastTime = now; + if (elapsed <= 0.0f || Float.isNaN(elapsed) || Float.isInfinite(elapsed)) { delta = 1.0f; return; } - delta = Math.min(f * 60.0f, 12.0f); + delta = Math.min(elapsed * 60.0f, 12.0f); } - public static float lerp(float f, float f2, float f3) { - float f4 = f3 * delta; - if (f < f2) { - return Math.min(f2, f + f4); + public static float lerp(float current, float target, float speed) { + float step = speed * delta; + if (current < target) { + return Math.min(target, current + step); } - return Math.max(f2, f - f4); + return Math.max(target, current - step); } - public static float smoothLerp(float f, float f2, float f3) { - return f + (f2 - f) * LerpUtil.ease(f3); + public static float smoothLerp(float start, float end, float progress) { + return start + (end - start) * LerpUtil.ease(progress); } - public static float ease(float f) { - if (f <= 0.0f) { + public static float ease(float progress) { + if (progress <= 0.0f) { return 0.0f; } - if (f >= 1.0f) { + if (progress >= 1.0f) { return 1.0f; } - return 1.0f - (float)Math.pow(1.0f - f, delta); + return 1.0f - (float)Math.pow(1.0f - progress, delta); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/math/MathUtil.java b/src/main/java/shit/zen/utils/math/MathUtil.java index 30497c7..7e40270 100644 --- a/src/main/java/shit/zen/utils/math/MathUtil.java +++ b/src/main/java/shit/zen/utils/math/MathUtil.java @@ -12,88 +12,88 @@ extends ClientBase { public static final Random RANDOM; private static final String UTILITY_MSG; - public static double clamp(double d, double d2, double d3) { - return Math.min(Math.max(d, d2), d3); + public static double clamp(double value, double min, double max) { + return Math.min(Math.max(value, min), max); } - public static double round(double d, int n) { - if (n == 0) { - return Math.floor(d); + public static double round(double value, int decimals) { + if (decimals == 0) { + return Math.floor(value); } - double d2 = Math.pow(10.0, n); - return (double)Math.round(d * d2) / d2; + double factor = Math.pow(10.0, decimals); + return (double)Math.round(value * factor) / factor; } - public static double randomInt(int n, int n2) { - return n >= n2 ? (double)n : (double)(RANDOM.nextInt() * (n2 - n) + n); + public static double randomInt(int min, int max) { + return min >= max ? (double)min : (double)(RANDOM.nextInt() * (max - min) + min); } - public static double randomDouble(double d, double d2) { - return d >= d2 ? d : RANDOM.nextDouble() * (d2 - d) + d; + public static double randomDouble(double min, double max) { + return min >= max ? min : RANDOM.nextDouble() * (max - min) + min; } - public static double snap(double d, double d2) { - double d3 = (double)Math.round(d / d2) * d2; - d3 *= 1000.0; - d3 = (int)d3; - return d3 /= 1000.0; + public static double snap(double value, double step) { + double snapped = (double)Math.round(value / step) * step; + snapped *= 1000.0; + snapped = (int)snapped; + return snapped /= 1000.0; } - public static double roundDecimal(double d, int n) { - if (n < 0) { - return d; + public static double roundDecimal(double value, int decimals) { + if (decimals < 0) { + return value; } - BigDecimal bigDecimal = new BigDecimal(d); - bigDecimal = bigDecimal.setScale(n, RoundingMode.HALF_UP); + BigDecimal bigDecimal = new BigDecimal(value); + bigDecimal = bigDecimal.setScale(decimals, RoundingMode.HALF_UP); return bigDecimal.doubleValue(); } - public static float randomFloat(float f, float f2) { + public static float randomFloat(float max, float min) { SecureRandom secureRandom = new SecureRandom(); - return secureRandom.nextFloat() * (f - f2) + f2; + return secureRandom.nextFloat() * (max - min) + min; } - public static float clampPitch(float f) { - if (f > 90.0f) { + public static float clampPitch(float pitch) { + if (pitch > 90.0f) { return 90.0f; } - if (f < -90.0f) { + if (pitch < -90.0f) { return -90.0f; } - return f; + return pitch; } - public static float clamp(float f, float f2, float f3) { - return f < f2 ? f2 : Math.min(f, f3); + public static float clamp(float value, float min, float max) { + return value < min ? min : Math.min(value, max); } - public static float lerp(float f, float f2, float f3) { - return f2 + f * (f3 - f2); + public static float lerp(float progress, float start, float end) { + return start + progress * (end - start); } - public static double lerp(double d, double d2, float f) { - return d2 + d * ((double)f - d2); + public static double lerp(double progress, double start, float end) { + return start + progress * ((double)end - start); } - public static double lerp(float f, double d, double d2) { - return d + (double)f * (d2 - d); + public static double lerp(float progress, double start, double end) { + return start + (double)progress * (end - start); } - public static int lerpColor(int n, int n2, float f) { - f = Math.max(0.0f, Math.min(1.0f, f)); - int n3 = n >> 24 & 0xFF; - int n4 = n >> 16 & 0xFF; - int n5 = n >> 8 & 0xFF; - int n6 = n & 0xFF; - int n7 = n2 >> 24 & 0xFF; - int n8 = n2 >> 16 & 0xFF; - int n9 = n2 >> 8 & 0xFF; - int n10 = n2 & 0xFF; - int n11 = (int)((float)n3 * (1.0f - f) + (float)n7 * f); - int n12 = (int)((float)n4 * (1.0f - f) + (float)n8 * f); - int n13 = (int)((float)n5 * (1.0f - f) + (float)n9 * f); - int n14 = (int)((float)n6 * (1.0f - f) + (float)n10 * f); - return n11 << 24 | n12 << 16 | n13 << 8 | n14; + public static int lerpColor(int colorA, int colorB, float progress) { + progress = Math.max(0.0f, Math.min(1.0f, progress)); + int alphaA = colorA >> 24 & 0xFF; + int redA = colorA >> 16 & 0xFF; + int greenA = colorA >> 8 & 0xFF; + int blueA = colorA & 0xFF; + int alphaB = colorB >> 24 & 0xFF; + int redB = colorB >> 16 & 0xFF; + int greenB = colorB >> 8 & 0xFF; + int blueB = colorB & 0xFF; + int alpha = (int)((float)alphaA * (1.0f - progress) + (float)alphaB * progress); + int red = (int)((float)redA * (1.0f - progress) + (float)redB * progress); + int green = (int)((float)greenA * (1.0f - progress) + (float)greenB * progress); + int blue = (int)((float)blueA * (1.0f - progress) + (float)blueB * progress); + return alpha << 24 | red << 16 | green << 8 | blue; } @Generated @@ -105,4 +105,4 @@ extends ClientBase { UTILITY_MSG = "This is a utility class and cannot be instantiated"; RANDOM = new Random(); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/math/Point2d.java b/src/main/java/shit/zen/utils/math/Point2d.java index c53848a..371230d 100644 --- a/src/main/java/shit/zen/utils/math/Point2d.java +++ b/src/main/java/shit/zen/utils/math/Point2d.java @@ -9,98 +9,98 @@ public class Point2d { this.y = 0.0; } - public Point2d(double d, double d2) { - this.x = d; - this.y = d2; + public Point2d(double x, double y) { + this.x = x; + this.y = y; } - public Point2d(Point2d point2d) { - this.x = point2d.x; - this.y = point2d.y; + public Point2d(Point2d other) { + this.x = other.x; + this.y = other.y; } - public Point2d(String string) { - string = string.replace(" ", ""); - if (!string.contains(",")) { + public Point2d(String spec) { + spec = spec.replace(" ", ""); + if (!spec.contains(",")) { return; } - String[] stringArray = string.split(","); - if (stringArray.length <= 1) { + String[] parts = spec.split(","); + if (parts.length <= 1) { return; } - String string2 = stringArray[0]; - String string3 = stringArray[1]; - this.x = Double.parseDouble(string2.trim().replace("", "")); - this.y = Double.parseDouble(string3.trim().replace("", "")); + String xPart = parts[0]; + String yPart = parts[1]; + this.x = Double.parseDouble(xPart.trim().replace("", "")); + this.y = Double.parseDouble(yPart.trim().replace("", "")); } public Point2d copy() { return new Point2d(this); } - public Point2d scale(double d, double d2) { - this.x *= d; - this.y *= d2; + public Point2d scale(double sx, double sy) { + this.x *= sx; + this.y *= sy; return this; } - public Point2d scale(double d) { - return this.scale(d, d); + public Point2d scale(double scale) { + return this.scale(scale, scale); } - public Point2d scale(Point2d point2d) { - return this.scale(point2d.x, point2d.y); + public Point2d scale(Point2d other) { + return this.scale(other.x, other.y); } - public Point2d add(double d, double d2) { - this.x += d; - this.y += d2; + public Point2d add(double dx, double dy) { + this.x += dx; + this.y += dy; return this; } - public Point2d add(Point2d point2d) { - return this.add(point2d.x, point2d.y); + public Point2d add(Point2d other) { + return this.add(other.x, other.y); } - public Point2d add(double d) { - return this.add(d, d); + public Point2d add(double value) { + return this.add(value, value); } - public Point2d sub(double d, double d2) { - this.x -= d; - this.y -= d2; + public Point2d sub(double dx, double dy) { + this.x -= dx; + this.y -= dy; return this; } - public Point2d sub(Point2d point2d) { - return this.add(point2d.x, point2d.y); + public Point2d sub(Point2d other) { + return this.add(other.x, other.y); } - public Point2d sub(double d) { - return this.add(d, d); + public Point2d sub(double value) { + return this.add(value, value); } - public Point2d div(double d, double d2) { - this.x /= d; - this.y /= d2; + public Point2d div(double dx, double dy) { + this.x /= dx; + this.y /= dy; return this; } - public Point2d div(Point2d point2d) { - return this.div(point2d.x, point2d.y); + public Point2d div(Point2d other) { + return this.div(other.x, other.y); } - public Point2d div(double d) { - return this.div(d, d); + public Point2d div(double value) { + return this.div(value, value); } - public Point2d set(double d, double d2) { - this.x = d; - this.y = d2; + public Point2d set(double x, double y) { + this.x = x; + this.y = y; return this; } - public Point2d set(Point2d point2d) { - return this.set(point2d.x, point2d.y); + public Point2d set(Point2d other) { + return this.set(other.x, other.y); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/math/Vector2f.java b/src/main/java/shit/zen/utils/math/Vector2f.java index 64dc70c..81f3e08 100644 --- a/src/main/java/shit/zen/utils/math/Vector2f.java +++ b/src/main/java/shit/zen/utils/math/Vector2f.java @@ -15,42 +15,42 @@ public final class Vector2f { @Getter @Setter public float y; - public Vector2f(Vector2f vector2f) { - this(vector2f.x, vector2f.y); + public Vector2f(Vector2f other) { + this(other.x, other.y); } - public Vector2f add(float f, float f2) { - return new Vector2f(this.x + f, this.y + f2); + public Vector2f add(float x, float y) { + return new Vector2f(this.x + x, this.y + y); } - public Vector2f fill(float f) { - this.x = f; - this.y = f; + public Vector2f fill(float value) { + this.x = value; + this.y = value; return this; } - public Vector2f set(float f, float f2) { - this.x = f; - this.y = f2; + public Vector2f set(float x, float y) { + this.x = x; + this.y = y; return this; } - public Vector2f fillD(double d) { - this.x = (float)d; - this.y = (float)d; + public Vector2f fillD(double value) { + this.x = (float)value; + this.y = (float)value; return this; } - public Vector2f setD(double d, double d2) { - this.x = (float)d; - this.y = (float)d2; + public Vector2f setD(double x, double y) { + this.x = (float)x; + this.y = (float)y; return this; } - public Vector2f fromArray(float[] fArray) { - this.x = fArray[0]; - this.y = fArray[1]; + public Vector2f fromArray(float[] values) { + this.x = values[0]; + this.y = values[1]; return this; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/misc/ChatUtil.java b/src/main/java/shit/zen/utils/misc/ChatUtil.java index 3fe797c..14a4b73 100644 --- a/src/main/java/shit/zen/utils/misc/ChatUtil.java +++ b/src/main/java/shit/zen/utils/misc/ChatUtil.java @@ -12,12 +12,12 @@ extends ClientBase { chatComponent.addMessage(component); } - public static void print(String string) { - ChatUtil.print(true, string); + public static void print(String message) { + ChatUtil.print(true, message); } - public static void print(boolean bl, String string) { - ChatUtil.addMessage(Component.nullToEmpty((bl ? "§7[§b§7] " : "") + string)); + public static void print(boolean withPrefix, String message) { + ChatUtil.addMessage(Component.nullToEmpty((withPrefix ? "§7[§b§7] " : "") + message)); } @Generated diff --git a/src/main/java/shit/zen/utils/misc/CursorUtil.java b/src/main/java/shit/zen/utils/misc/CursorUtil.java index da1440d..6a44d07 100644 --- a/src/main/java/shit/zen/utils/misc/CursorUtil.java +++ b/src/main/java/shit/zen/utils/misc/CursorUtil.java @@ -9,13 +9,13 @@ public class CursorUtil { private static final Map cursorCache = new HashMap<>(); static long windowHandle = ClientBase.mc.getWindow().getWindow(); - public static boolean isInBounds(float f, float f2, float f3, float f4, float f5, float f6) { - return f > f3 && f2 > f4 && f < f3 + f5 && f2 < f4 + f6; + public static boolean isInBounds(float mouseX, float mouseY, float x, float y, float width, float height) { + return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; } - public static void setCursor(int n) { - long l = cursorCache.computeIfAbsent(n, GLFW::glfwCreateStandardCursor); - GLFW.glfwSetCursor(windowHandle, l); + public static void setCursor(int shape) { + long cursor = cursorCache.computeIfAbsent(shape, GLFW::glfwCreateStandardCursor); + GLFW.glfwSetCursor(windowHandle, cursor); } public static void setDefaultCursor() { diff --git a/src/main/java/shit/zen/utils/misc/GamePathLocator.java b/src/main/java/shit/zen/utils/misc/GamePathLocator.java index 50b8315..1201c70 100644 --- a/src/main/java/shit/zen/utils/misc/GamePathLocator.java +++ b/src/main/java/shit/zen/utils/misc/GamePathLocator.java @@ -16,40 +16,40 @@ import shit.zen.exception.SilentException; public final class GamePathLocator { public static Path getGamePath() { if (GamePathLocator.isWindows()) { - String string = System.getenv("USERPROFILE"); - String string2 = "AppData/LocalLow/miHoYo"; - return Paths.get(string, new String[0]).resolve(string2); + String userProfile = System.getenv("USERPROFILE"); + String miHoYoSubPath = "AppData/LocalLow/miHoYo"; + return Paths.get(userProfile, new String[0]).resolve(miHoYoSubPath); } throw new SilentException(); } public static List getGamePaths() throws Exception { - Path path = GamePathLocator.getGamePath(); - ArrayList arrayList = new ArrayList<>(); - Path path2 = null; - String string = "绝区零/Player.log"; - String string2 = "/ZenlessZoneZero_Data/"; - path2 = path.resolve("绝区零/Player.log"); - Optional optional = GamePathLocator.findExecutable(path2, "/ZenlessZoneZero_Data/"); - optional.ifPresent(arg_0 -> arrayList.add(arg_0)); - return arrayList; + Path basePath = GamePathLocator.getGamePath(); + ArrayList paths = new ArrayList<>(); + Path logPath = null; + String logRelative = "绝区零/Player.log"; + String dataMarker = "/ZenlessZoneZero_Data/"; + logPath = basePath.resolve("绝区零/Player.log"); + Optional exePath = GamePathLocator.findExecutable(logPath, "/ZenlessZoneZero_Data/"); + exePath.ifPresent(path -> paths.add(path)); + return paths; } - private static Optional findExecutable(Path path, String string) { - try (Stream stream = Files.lines(path, StandardCharsets.UTF_8)) { - return stream.filter(line -> line.contains(string)).map(line -> GamePathLocator.findGamePath(line, string)).filter(Optional::isPresent).map(Optional::get).findFirst(); - } catch (Exception exception) { - exception.printStackTrace(); + private static Optional findExecutable(Path logPath, String marker) { + try (Stream stream = Files.lines(logPath, StandardCharsets.UTF_8)) { + return stream.filter(line -> line.contains(marker)).map(line -> GamePathLocator.findGamePath(line, marker)).filter(Optional::isPresent).map(Optional::get).findFirst(); + } catch (Exception ex) { + ex.printStackTrace(); return Optional.empty(); } } - private static Optional findGamePath(String string, String string2) { + private static Optional findGamePath(String line, String marker) { try { - int n = string.indexOf(string2); - if (n != -1) { - String string3 = string.substring(string.indexOf("at path ") + 8).replace("/UnitySubsystems", "").replace("/ZenlessZoneZero_Data", "/ZenlessZoneZero.exe").trim(); - return Optional.of(Paths.get(string3, new String[0])); + int markerIdx = line.indexOf(marker); + if (markerIdx != -1) { + String exePath = line.substring(line.indexOf("at path ") + 8).replace("/UnitySubsystems", "").replace("/ZenlessZoneZero_Data", "/ZenlessZoneZero.exe").trim(); + return Optional.of(Paths.get(exePath, new String[0])); } } catch (InvalidPathException invalidPathException) { // empty catch block diff --git a/src/main/java/shit/zen/utils/misc/IOUtil.java b/src/main/java/shit/zen/utils/misc/IOUtil.java index d172e66..6f6ab74 100644 --- a/src/main/java/shit/zen/utils/misc/IOUtil.java +++ b/src/main/java/shit/zen/utils/misc/IOUtil.java @@ -44,9 +44,9 @@ public class IOUtil { byte[] bytes = new byte[fis.available()]; int read = 0; while (read < bytes.length) { - int n = fis.read(bytes, read, bytes.length - read); - if (n < 0) break; - read += n; + int count = fis.read(bytes, read, bytes.length - read); + if (count < 0) break; + read += count; } return bytes; } diff --git a/src/main/java/shit/zen/utils/misc/PacketUtil.java b/src/main/java/shit/zen/utils/misc/PacketUtil.java index fd1db8f..3297894 100644 --- a/src/main/java/shit/zen/utils/misc/PacketUtil.java +++ b/src/main/java/shit/zen/utils/misc/PacketUtil.java @@ -50,20 +50,20 @@ extends ClientBase { return; } try { - String string = ReflectionUtil.getMappedFieldName(ClientLevel.class, "blockStatePredictionHandler"); - if (string == null) { + String fieldName = ReflectionUtil.getMappedFieldName(ClientLevel.class, "blockStatePredictionHandler"); + if (fieldName == null) { return; } - Field field = ClientLevel.class.getDeclaredField(string); + Field field = ClientLevel.class.getDeclaredField(fieldName); field.setAccessible(true); - BlockStatePredictionHandler blockStatePredictionHandler = (BlockStatePredictionHandler)field.get(mc.level); - try (BlockStatePredictionHandler blockStatePredictionHandler2 = blockStatePredictionHandler.startPredicting()){ - int n = blockStatePredictionHandler2.currentSequence(); - mc.getConnection().send(predictiveAction.predict(n)); + BlockStatePredictionHandler predictionHandler = (BlockStatePredictionHandler)field.get(mc.level); + try (BlockStatePredictionHandler predicting = predictionHandler.startPredicting()){ + int sequence = predicting.currentSequence(); + mc.getConnection().send(predictiveAction.predict(sequence)); } - } catch (Exception exception) { - logger.error(exception); - exception.printStackTrace(); + } catch (Exception ex) { + logger.error(ex); + ex.printStackTrace(); } } @@ -72,20 +72,20 @@ extends ClientBase { return; } try { - String string = ReflectionUtil.getMappedFieldName(ClientLevel.class, "blockStatePredictionHandler"); - if (string == null) { + String fieldName = ReflectionUtil.getMappedFieldName(ClientLevel.class, "blockStatePredictionHandler"); + if (fieldName == null) { return; } - Field field = ClientLevel.class.getDeclaredField(string); + Field field = ClientLevel.class.getDeclaredField(fieldName); field.setAccessible(true); - BlockStatePredictionHandler blockStatePredictionHandler = (BlockStatePredictionHandler)field.get(mc.level); - try (BlockStatePredictionHandler blockStatePredictionHandler2 = blockStatePredictionHandler.startPredicting()){ - int n = blockStatePredictionHandler2.currentSequence(); - PacketUtil.sendQueued(predictiveAction.predict(n)); + BlockStatePredictionHandler predictionHandler = (BlockStatePredictionHandler)field.get(mc.level); + try (BlockStatePredictionHandler predicting = predictionHandler.startPredicting()){ + int sequence = predicting.currentSequence(); + PacketUtil.sendQueued(predictiveAction.predict(sequence)); } - } catch (Exception exception) { - logger.error(exception); - exception.printStackTrace(); + } catch (Exception ex) { + logger.error(ex); + ex.printStackTrace(); } } diff --git a/src/main/java/shit/zen/utils/misc/ReflectionUtil.java b/src/main/java/shit/zen/utils/misc/ReflectionUtil.java index f1afd13..a4eb708 100644 --- a/src/main/java/shit/zen/utils/misc/ReflectionUtil.java +++ b/src/main/java/shit/zen/utils/misc/ReflectionUtil.java @@ -56,50 +56,50 @@ public final class ReflectionUtil { } } - public static void setClassRedefinedCount(Class clazz, int n) { + public static void setClassRedefinedCount(Class clazz, int count) { if (clazz == null) return; try { Field field = Class.class.getDeclaredField("classRedefinedCount"); UnsafeUtil.makeAccessible(field); - field.setInt(clazz, n); + field.setInt(clazz, count); } catch (Throwable throwable) { throw new Error(throwable); } } - public static void incrementClassRedefinedCount(Class clazz, int n) { + public static void incrementClassRedefinedCount(Class clazz, int delta) { if (clazz == null) return; try { Field field = Class.class.getDeclaredField("classRedefinedCount"); UnsafeUtil.makeAccessible(field); - field.setInt(clazz, field.getInt(clazz) + n); + field.setInt(clazz, field.getInt(clazz) + delta); } catch (Throwable throwable) { throw new Error(throwable); } } - public static void setJumpDelay(int n) { + public static void setJumpDelay(int delay) { if (ClientBase.mc == null || ClientBase.mc.player == null) return; - setJumpDelay(ClientBase.mc.player, n); + setJumpDelay(ClientBase.mc.player, delay); } - public static void setJumpDelay(LivingEntity livingEntity, int n) { + public static void setJumpDelay(LivingEntity livingEntity, int delay) { if (livingEntity == null) return; try { Field field = findField(livingEntity.getClass(), "noJumpDelay", "f_20889_"); - field.setInt(livingEntity, n); - } catch (Exception exception) { - ClientBase.logger.error("Failed to set noJumpDelay field", exception); + field.setInt(livingEntity, delay); + } catch (Exception ex) { + ClientBase.logger.error("Failed to set noJumpDelay field", ex); } } - public static void setRightClickDelay(int n) { + public static void setRightClickDelay(int delay) { if (ClientBase.mc == null) return; try { Field field = findField(ClientBase.mc.getClass(), "rightClickDelay", "f_91076_"); - field.setInt(ClientBase.mc, n); - } catch (Exception exception) { - ClientBase.logger.error("Failed to set rightClickDelay field", exception); + field.setInt(ClientBase.mc, delay); + } catch (Exception ex) { + ClientBase.logger.error("Failed to set rightClickDelay field", ex); } } @@ -108,8 +108,8 @@ public final class ReflectionUtil { Field field = findField(packet.getClass(), ZenClient.isMCPMapped ? "f_134121_" : "yRot"); try { return field.getFloat(packet); - } catch (Exception exception) { - ClientBase.logger.error("Failed to get yrot field", exception); + } catch (Exception ex) { + ClientBase.logger.error("Failed to get yrot field", ex); return 0.0f; } } @@ -119,38 +119,38 @@ public final class ReflectionUtil { Field field = findField(packet.getClass(), ZenClient.isMCPMapped ? "f_134122_" : "xRot"); try { return field.getFloat(packet); - } catch (Exception exception) { - ClientBase.logger.error("Failed to get xrot field", exception); + } catch (Exception ex) { + ClientBase.logger.error("Failed to get xrot field", ex); return 0.0f; } } - public static void setYRot(ServerboundMovePlayerPacket packet, float f) { + public static void setYRot(ServerboundMovePlayerPacket packet, float yaw) { if (ClientBase.mc.gameMode == null) return; Field field = findField(packet.getClass(), ZenClient.isMCPMapped ? "f_134121_" : "yRot"); try { - field.setFloat(packet, f); - } catch (Exception exception) { - ClientBase.logger.error("Failed to set yrot field", exception); + field.setFloat(packet, yaw); + } catch (Exception ex) { + ClientBase.logger.error("Failed to set yrot field", ex); } } - public static void setDepthBufferId(RenderTarget renderTarget, int n) { + public static void setDepthBufferId(RenderTarget renderTarget, int depthBufferId) { Field field = findField(renderTarget.getClass(), ZenClient.isMCPMapped ? "f_83924_" : "depthBufferId"); try { - field.setInt(renderTarget, n); - } catch (Exception exception) { - exception.printStackTrace(); + field.setInt(renderTarget, depthBufferId); + } catch (Exception ex) { + ex.printStackTrace(); } } - public static void setXRot(ServerboundMovePlayerPacket packet, float f) { + public static void setXRot(ServerboundMovePlayerPacket packet, float pitch) { if (ClientBase.mc.gameMode == null) return; Field field = findField(packet.getClass(), ZenClient.isMCPMapped ? "f_134122_" : "xRot"); try { - field.setFloat(packet, f); - } catch (Exception exception) { - ClientBase.logger.error("Failed to set xrot field", exception); + field.setFloat(packet, pitch); + } catch (Exception ex) { + ClientBase.logger.error("Failed to set xrot field", ex); } } @@ -159,8 +159,8 @@ public final class ReflectionUtil { Field field = findField(menu.getClass(), ZenClient.isMCPMapped ? "f_39086_" : "brewingStand"); try { return (Container) field.get(menu); - } catch (Exception exception) { - exception.printStackTrace(); + } catch (Exception ex) { + ex.printStackTrace(); return null; } } @@ -185,21 +185,21 @@ public final class ReflectionUtil { throw new ReflectionException(last); } - public static void setMissTime(int n) { + public static void setMissTime(int missTime) { Field field = findField(ClientBase.mc.getClass(), "missTime", "f_91078_"); try { - field.setInt(ClientBase.mc, n); - } catch (Exception exception) { - exception.printStackTrace(); + field.setInt(ClientBase.mc, missTime); + } catch (Exception ex) { + ex.printStackTrace(); } } - public static String getMappedFieldName(Class clazz, String string) { - return string; + public static String getMappedFieldName(Class clazz, String fieldName) { + return fieldName; } - public static String getMappedMethodName(Class clazz, String string, String string2) { - return string; + public static String getMappedMethodName(Class clazz, String methodName, String descriptor) { + return methodName; } private static long getFieldOffset(Class clazz, String name) { diff --git a/src/main/java/shit/zen/utils/misc/SoundUtil.java b/src/main/java/shit/zen/utils/misc/SoundUtil.java index ee7f92c..d25cb57 100644 --- a/src/main/java/shit/zen/utils/misc/SoundUtil.java +++ b/src/main/java/shit/zen/utils/misc/SoundUtil.java @@ -17,12 +17,12 @@ import shit.zen.manager.ConfigManager; import shit.zen.utils.math.MathUtil; public final class SoundUtil { - public static void playSound(String string, String string2) { - JOptionPane.showMessageDialog(null, string2, string, 0); + public static void playSound(String title, String message) { + JOptionPane.showMessageDialog(null, message, title, 0); } - public static void playSound(String string, float f) { - File file = new File(ConfigManager.CONFIG_DIR, string); + public static void playSound(String fileName, float gain) { + File file = new File(ConfigManager.CONFIG_DIR, fileName); if (!file.exists()) { System.out.println("Failed to find target file!"); return; @@ -34,10 +34,10 @@ public final class SoundUtil { clip.open(audioInputStream); clip.start(); FloatControl floatControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN); - floatControl.setValue(f); + floatControl.setValue(gain); clip.start(); - } catch (IOException | LineUnavailableException | UnsupportedAudioFileException throwable) { - throwable.printStackTrace(); + } catch (IOException | LineUnavailableException | UnsupportedAudioFileException ex) { + ex.printStackTrace(); } }, "Netty Client IO #" + MathUtil.randomInt(0, 100)).start(); } diff --git a/src/main/java/shit/zen/utils/render/ColorUtil.java b/src/main/java/shit/zen/utils/render/ColorUtil.java index ef414a8..a5a5b32 100644 --- a/src/main/java/shit/zen/utils/render/ColorUtil.java +++ b/src/main/java/shit/zen/utils/render/ColorUtil.java @@ -10,75 +10,75 @@ extends ClientBase { private static final String UTILITY_CLASS_MSG = "This is a utility class and cannot be instantiated"; public static Color getPlayerColor(Player player) { - int n = player.getName().getString().hashCode(); - int n2 = (n & 0xFF0000) >> 16; - int n3 = (n & 0xFF00) >> 8; - int n4 = n & 0xFF; - return new Color(n2, n3, n4); + int hash = player.getName().getString().hashCode(); + int red = (hash & 0xFF0000) >> 16; + int green = (hash & 0xFF00) >> 8; + int blue = hash & 0xFF; + return new Color(red, green, blue); } - public static int animateColor(int n, int n2, double d) { - if (d > 1.0) { - d = 1.0 - d % 1.0; + public static int animateColor(int colorA, int colorB, double progress) { + if (progress > 1.0) { + progress = 1.0 - progress % 1.0; } - return ColorUtil.interpolateColor(n, n2, d); + return ColorUtil.interpolateColor(colorA, colorB, progress); } - public static int animateColorOffset(int n, int n2, long l) { - return ColorUtil.animateColor(n, n2, (double)((System.currentTimeMillis() + l) % 4000L) / 2000.0); + public static int animateColorOffset(int colorA, int colorB, long offsetMs) { + return ColorUtil.animateColor(colorA, colorB, (double)((System.currentTimeMillis() + offsetMs) % 4000L) / 2000.0); } - public static int interpolateColor(int n, int n2, double d) { - double d2 = 1.0 - d; - int n3 = (int)((double)(n >> 16 & 0xFF) * d2 + (double)(n2 >> 16 & 0xFF) * d); - int n4 = (int)((double)(n >> 8 & 0xFF) * d2 + (double)(n2 >> 8 & 0xFF) * d); - int n5 = (int)((double)(n & 0xFF) * d2 + (double)(n2 & 0xFF) * d); - int n6 = (int)((double)(n >> 24 & 0xFF) * d2 + (double)(n2 >> 24 & 0xFF) * d); - return (n6 & 0xFF) << 24 | (n3 & 0xFF) << 16 | (n4 & 0xFF) << 8 | n5 & 0xFF; + public static int interpolateColor(int colorA, int colorB, double progress) { + double inverse = 1.0 - progress; + int red = (int)((double)(colorA >> 16 & 0xFF) * inverse + (double)(colorB >> 16 & 0xFF) * progress); + int green = (int)((double)(colorA >> 8 & 0xFF) * inverse + (double)(colorB >> 8 & 0xFF) * progress); + int blue = (int)((double)(colorA & 0xFF) * inverse + (double)(colorB & 0xFF) * progress); + int alpha = (int)((double)(colorA >> 24 & 0xFF) * inverse + (double)(colorB >> 24 & 0xFF) * progress); + return (alpha & 0xFF) << 24 | (red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF; } - public static Color getRainbowColor(int n, int n2) { - int n3 = (int)((System.currentTimeMillis() / (long)n + (long)n2) % 360L); - float f = (float)n3 / 360.0f; - return new Color(Color.HSBtoRGB(f, 0.5f, 1.0f)); + public static Color getRainbowColor(int speed, int offset) { + int hueDegrees = (int)((System.currentTimeMillis() / (long)speed + (long)offset) % 360L); + float hue = (float)hueDegrees / 360.0f; + return new Color(Color.HSBtoRGB(hue, 0.5f, 1.0f)); } - public static int fromRGB(int n, int n2, int n3) { - return ColorUtil.fromARGB(n, n2, n3, 255); + public static int fromRGB(int red, int green, int blue) { + return ColorUtil.fromARGB(red, green, blue, 255); } - public static int fromARGB(int n, int n2, int n3, int n4) { - return (n4 & 0xFF) << 24 | (n & 0xFF) << 16 | (n2 & 0xFF) << 8 | n3 & 0xFF; + public static int fromARGB(int red, int green, int blue, int alpha) { + return (alpha & 0xFF) << 24 | (red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF; } - public static int withAlpha(int n, float f) { - Color color = new Color(n); - return ColorUtil.withAlphaColor(color, f).getRGB(); + public static int withAlpha(int color, float alphaScale) { + Color colorObj = new Color(color); + return ColorUtil.withAlphaColor(colorObj, alphaScale).getRGB(); } - public static Color withAlphaColor(Color color, float f) { - f = Math.min(1.0f, Math.max(0.0f, f)); - return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)((float)color.getAlpha() * f)); + public static Color withAlphaColor(Color color, float alphaScale) { + alphaScale = Math.min(1.0f, Math.max(0.0f, alphaScale)); + return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)((float)color.getAlpha() * alphaScale)); } - public static int getAlpha(int n) { - return n >> 24 & 0xFF; + public static int getAlpha(int color) { + return color >> 24 & 0xFF; } - public static int getRed(int n) { - return n >> 16 & 0xFF; + public static int getRed(int color) { + return color >> 16 & 0xFF; } - public static int getGreen(int n) { - return n >> 8 & 0xFF; + public static int getGreen(int color) { + return color >> 8 & 0xFF; } - public static int getBlue(int n) { - return n & 0xFF; + public static int getBlue(int color) { + return color & 0xFF; } @Generated private ColorUtil() { throw new UnsupportedOperationException(UTILITY_CLASS_MSG); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/render/ProjectionUtil.java b/src/main/java/shit/zen/utils/render/ProjectionUtil.java index e448b70..73ec7c1 100644 --- a/src/main/java/shit/zen/utils/render/ProjectionUtil.java +++ b/src/main/java/shit/zen/utils/render/ProjectionUtil.java @@ -45,57 +45,57 @@ extends ClientBase { tempVec4a.set((float)viewport.get(0), (float)viewport.get(1), (float)viewport.get(2), (float)viewport.get(3)); } - public static Vector2f project(double d, double d2, double d3, float f) { - Entity entity; - Vec3 vec3 = mc.getEntityRenderDispatcher().camera.getPosition(); - Quaternionf quaternionf = new Quaternionf(mc.getEntityRenderDispatcher().cameraOrientation()); - quaternionf.conjugate(); - Vector3f vector3f = new Vector3f((float)(vec3.x - d), (float)(vec3.y - d2), (float)(vec3.z - d3)); - vector3f.rotate(quaternionf); - if (mc.options.bobView().get() && (entity = mc.getCameraEntity()) instanceof Player) { - Player player = (Player)entity; - ProjectionUtil.applyBobbing(player, vector3f, f); + public static Vector2f project(double worldX, double worldY, double worldZ, float partialTicks) { + Entity cameraEntity; + Vec3 cameraPos = mc.getEntityRenderDispatcher().camera.getPosition(); + Quaternionf cameraRotation = new Quaternionf(mc.getEntityRenderDispatcher().cameraOrientation()); + cameraRotation.conjugate(); + Vector3f relativePos = new Vector3f((float)(cameraPos.x - worldX), (float)(cameraPos.y - worldY), (float)(cameraPos.z - worldZ)); + relativePos.rotate(cameraRotation); + if (mc.options.bobView().get() && (cameraEntity = mc.getCameraEntity()) instanceof Player) { + Player player = (Player)cameraEntity; + ProjectionUtil.applyBobbing(player, relativePos, partialTicks); } - double d4 = 1.2f; + double fov = 1.2f; try { Method method = mc.gameRenderer.getClass().getDeclaredMethod(ReflectionUtil.getMappedMethodName(mc.gameRenderer.getClass(), "getFov", "(Lnet/minecraft/client/Camera;FZ)D"), Camera.class, Float.TYPE, Boolean.TYPE); method.setAccessible(true); - d4 = (Double)method.invoke(mc.gameRenderer, new Object[]{mc.getEntityRenderDispatcher().camera, Float.valueOf(f), true}); + fov = (Double)method.invoke(mc.gameRenderer, new Object[]{mc.getEntityRenderDispatcher().camera, Float.valueOf(partialTicks), true}); } catch (Exception exception) { exception.printStackTrace(); } - return ProjectionUtil.projectInternal(vector3f, d4); + return ProjectionUtil.projectInternal(relativePos, fov); } - private static void applyBobbing(Player player, Vector3f vector3f, float f) { - float f2 = player.walkDist; - float f3 = f2 - player.walkDistO; - float f4 = -(f2 + f3 * f); - float f5 = Mth.lerp(f, player.oBob, player.bob); - Quaternionf quaternionf = new Quaternionf().rotationX(Math.abs(Mth.cos(f4 * (float)Math.PI - 0.2f) * f5) * 5.0f * ((float)Math.PI / 180)); - quaternionf.conjugate(); - vector3f.rotate(quaternionf); - Quaternionf quaternionf2 = new Quaternionf().rotationZ(Mth.sin(f4 * (float)Math.PI) * f5 * 3.0f * ((float)Math.PI / 180)); - quaternionf2.conjugate(); - vector3f.rotate(quaternionf2); - Vector3f vector3f2 = new Vector3f(Mth.sin(f4 * (float)Math.PI) * f5 * 0.5f, -Math.abs(Mth.cos(f4 * (float)Math.PI) * f5), 0.0f); - vector3f2.y = -vector3f2.y; - vector3f.add(vector3f2); + private static void applyBobbing(Player player, Vector3f relativePos, float partialTicks) { + float walkDist = player.walkDist; + float walkDelta = walkDist - player.walkDistO; + float walkProgress = -(walkDist + walkDelta * partialTicks); + float bobAmount = Mth.lerp(partialTicks, player.oBob, player.bob); + Quaternionf pitchRotation = new Quaternionf().rotationX(Math.abs(Mth.cos(walkProgress * (float)Math.PI - 0.2f) * bobAmount) * 5.0f * ((float)Math.PI / 180)); + pitchRotation.conjugate(); + relativePos.rotate(pitchRotation); + Quaternionf rollRotation = new Quaternionf().rotationZ(Mth.sin(walkProgress * (float)Math.PI) * bobAmount * 3.0f * ((float)Math.PI / 180)); + rollRotation.conjugate(); + relativePos.rotate(rollRotation); + Vector3f bobOffset = new Vector3f(Mth.sin(walkProgress * (float)Math.PI) * bobAmount * 0.5f, -Math.abs(Mth.cos(walkProgress * (float)Math.PI) * bobAmount), 0.0f); + bobOffset.y = -bobOffset.y; + relativePos.add(bobOffset); } - private static Vector2f projectInternal(Vector3f vector3f, double d) { - float f = (float)mc.getWindow().getGuiScaledHeight() / 2.0f; - float f2 = f / (vector3f.z() * (float)Math.tan(Math.toRadians(d / 2.0))); - if (vector3f.z() < 0.0f) { - return new Vector2f(-vector3f.x() * f2 + (float)mc.getWindow().getGuiScaledWidth() / 2.0f, (float)mc.getWindow().getGuiScaledHeight() / 2.0f - vector3f.y() * f2); + private static Vector2f projectInternal(Vector3f relativePos, double fov) { + float halfHeight = (float)mc.getWindow().getGuiScaledHeight() / 2.0f; + float scale = halfHeight / (relativePos.z() * (float)Math.tan(Math.toRadians(fov / 2.0))); + if (relativePos.z() < 0.0f) { + return new Vector2f(-relativePos.x() * scale + (float)mc.getWindow().getGuiScaledWidth() / 2.0f, (float)mc.getWindow().getGuiScaledHeight() / 2.0f - relativePos.y() * scale); } return new Vector2f(Float.MAX_VALUE, Float.MAX_VALUE); } - public static Vector2f project(double d, double d2, double d3) { + public static Vector2f project(double worldX, double worldY, double worldZ) { Camera camera = mc.gameRenderer.getMainCamera(); - Vec3 vec3 = camera.getPosition(); - tempVec3.set((float)(d - vec3.x), (float)(d2 - vec3.y), (float)(d3 - vec3.z)); + Vec3 cameraPos = camera.getPosition(); + tempVec3.set((float)(worldX - cameraPos.x), (float)(worldY - cameraPos.y), (float)(worldZ - cameraPos.z)); tempQuat.set(camera.rotation()).conjugate(); tempVec3.rotate(tempQuat); ProjectionUtil.tempVec3.x = -ProjectionUtil.tempVec3.x; @@ -104,24 +104,24 @@ extends ClientBase { if (ProjectionUtil.tempVec4b.w <= 0.0f) { return null; } - float f = ProjectionUtil.tempVec4b.x / ProjectionUtil.tempVec4b.w; - float f2 = ProjectionUtil.tempVec4b.y / ProjectionUtil.tempVec4b.w; - if (Float.isNaN(f) || Float.isNaN(f2) || f < -1.2f || f > 1.2f || f2 < -1.2f || f2 > 1.2f) { + float ndcX = ProjectionUtil.tempVec4b.x / ProjectionUtil.tempVec4b.w; + float ndcY = ProjectionUtil.tempVec4b.y / ProjectionUtil.tempVec4b.w; + if (Float.isNaN(ndcX) || Float.isNaN(ndcY) || ndcX < -1.2f || ndcX > 1.2f || ndcY < -1.2f || ndcY > 1.2f) { return null; } - float f3 = tempVec4a.x() + (1.0f + f) * tempVec4a.z() / 2.0f; - float f4 = tempVec4a.y() + (1.0f - f2) * tempVec4a.w() / 2.0f; - double d4 = mc.getWindow().getGuiScale(); - if (d4 == 0.0) { - d4 = 1.0; + float screenX = tempVec4a.x() + (1.0f + ndcX) * tempVec4a.z() / 2.0f; + float screenY = tempVec4a.y() + (1.0f - ndcY) * tempVec4a.w() / 2.0f; + double guiScale = mc.getWindow().getGuiScale(); + if (guiScale == 0.0) { + guiScale = 1.0; } - f3 = (float)((double)f3 / d4); - f4 = (float)((double)f4 / d4); - return new Vector2f(f3, f4); + screenX = (float)((double)screenX / guiScale); + screenY = (float)((double)screenY / guiScale); + return new Vector2f(screenX, screenY); } @Generated private ProjectionUtil() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/render/RenderHelper.java b/src/main/java/shit/zen/utils/render/RenderHelper.java index 0418cc8..1ea05bf 100644 --- a/src/main/java/shit/zen/utils/render/RenderHelper.java +++ b/src/main/java/shit/zen/utils/render/RenderHelper.java @@ -20,83 +20,83 @@ import shit.zen.ClientBase; import shit.zen.utils.render.ColorUtil; public final class RenderHelper { - public static void blitRenderTarget(RenderTarget renderTarget, PoseStack poseStack, int n, int n2) { + public static void blitRenderTarget(RenderTarget renderTarget, PoseStack poseStack, int width, int height) { Matrix4f matrix4f = poseStack.last().pose(); ShaderInstance shaderInstance = ClientBase.mc.gameRenderer.blitShader; shaderInstance.setSampler("DiffuseSampler", renderTarget.getColorTextureId()); shaderInstance.apply(); - float f = (float)renderTarget.viewWidth / (float)renderTarget.width; - float f2 = (float)renderTarget.viewHeight / (float)renderTarget.height; + float uMax = (float)renderTarget.viewWidth / (float)renderTarget.width; + float vMax = (float)renderTarget.viewHeight / (float)renderTarget.height; Tesselator tesselator = RenderSystem.renderThreadTesselator(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - bufferBuilder.vertex(matrix4f, 0.0f, (float)n2, 0.0f).uv(0.0f, 0.0f).color(255, 255, 255, 255).endVertex(); - bufferBuilder.vertex(matrix4f, (float)n, (float)n2, 0.0f).uv(f, 0.0f).color(255, 255, 255, 255).endVertex(); - bufferBuilder.vertex(matrix4f, (float)n, 0.0f, 0.0f).uv(f, f2).color(255, 255, 255, 255).endVertex(); - bufferBuilder.vertex(matrix4f, 0.0f, 0.0f, 0.0f).uv(0.0f, f2).color(255, 255, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, 0.0f, (float)height, 0.0f).uv(0.0f, 0.0f).color(255, 255, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, (float)width, (float)height, 0.0f).uv(uMax, 0.0f).color(255, 255, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, (float)width, 0.0f, 0.0f).uv(uMax, vMax).color(255, 255, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, 0.0f, 0.0f, 0.0f).uv(0.0f, vMax).color(255, 255, 255, 255).endVertex(); BufferUploader.draw(bufferBuilder.end()); shaderInstance.clear(); } - public static void blitRenderTargetSafe(RenderTarget renderTarget, PoseStack poseStack, int n, int n2) { + public static void blitRenderTargetSafe(RenderTarget renderTarget, PoseStack poseStack, int width, int height) { RenderSystem.assertOnRenderThread(); Matrix4f matrix4f = poseStack.last().pose(); Minecraft minecraft = ClientBase.mc; ShaderInstance shaderInstance = minecraft.gameRenderer.blitShader; shaderInstance.setSampler("DiffuseSampler", renderTarget.getColorTextureId()); shaderInstance.apply(); - float f = n; - float f2 = n2; - float f3 = (float)renderTarget.viewWidth / (float)renderTarget.width; - float f4 = (float)renderTarget.viewHeight / (float)renderTarget.height; + float widthF = width; + float heightF = height; + float uMax = (float)renderTarget.viewWidth / (float)renderTarget.width; + float vMax = (float)renderTarget.viewHeight / (float)renderTarget.height; Tesselator tesselator = RenderSystem.renderThreadTesselator(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - bufferBuilder.vertex(matrix4f, 0.0f, f2, 0.0f).uv(0.0f, 0.0f).color(255, 255, 255, 255).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).uv(f3, 0.0f).color(255, 255, 255, 255).endVertex(); - bufferBuilder.vertex(matrix4f, f, 0.0f, 0.0f).uv(f3, f4).color(255, 255, 255, 255).endVertex(); - bufferBuilder.vertex(matrix4f, 0.0f, 0.0f, 0.0f).uv(0.0f, f4).color(255, 255, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, 0.0f, heightF, 0.0f).uv(0.0f, 0.0f).color(255, 255, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, widthF, heightF, 0.0f).uv(uMax, 0.0f).color(255, 255, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, widthF, 0.0f, 0.0f).uv(uMax, vMax).color(255, 255, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, 0.0f, 0.0f, 0.0f).uv(0.0f, vMax).color(255, 255, 255, 255).endVertex(); BufferUploader.draw(bufferBuilder.end()); shaderInstance.clear(); } - public static void setTexFilter(int n, int n2) { - RenderSystem.texParameter(3553, 10241, n); - RenderSystem.texParameter(3553, 10240, n2); + public static void setTexFilter(int minFilter, int magFilter) { + RenderSystem.texParameter(3553, 10241, minFilter); + RenderSystem.texParameter(3553, 10240, magFilter); } - public static void pushScaleAround(PoseStack poseStack, float f, float f2, float f3) { + public static void pushScaleAround(PoseStack poseStack, float pivotX, float pivotY, float scale) { poseStack.pushPose(); - poseStack.translate(f, f2, 0.0f); - poseStack.scale(f3, f3, 1.0f); - poseStack.translate(-f, -f2, 0.0f); + poseStack.translate(pivotX, pivotY, 0.0f); + poseStack.scale(scale, scale, 1.0f); + poseStack.translate(-pivotX, -pivotY, 0.0f); } public static void popPose(PoseStack poseStack) { poseStack.popPose(); } - public static void pushRotateAround(PoseStack poseStack, float f, float f2, float f3) { + public static void pushRotateAround(PoseStack poseStack, float pivotX, float pivotY, float angleDegrees) { poseStack.pushPose(); - poseStack.translate(f, f2, 0.0f); - poseStack.mulPose(Axis.ZP.rotationDegrees(f3)); - poseStack.translate(-f, -f2, 0.0f); + poseStack.translate(pivotX, pivotY, 0.0f); + poseStack.mulPose(Axis.ZP.rotationDegrees(angleDegrees)); + poseStack.translate(-pivotX, -pivotY, 0.0f); } public static void resetShaderColor() { RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); } - public static void setShaderColorRGBA(int n, int n2, int n3, int n4) { - RenderSystem.setShaderColor((float)n / 255.0f, (float)n2 / 255.0f, (float)n3 / 255.0f, (float)n4 / 255.0f); + public static void setShaderColorRGBA(int r, int g, int b, int a) { + RenderSystem.setShaderColor((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)a / 255.0f); } - public static void setShaderColorWithAlpha(int n, int n2) { - RenderSystem.setShaderColor((float)ColorUtil.getRed(n) / 255.0f, (float)ColorUtil.getGreen(n) / 255.0f, (float)ColorUtil.getBlue(n) / 255.0f, (float)n2 / 255.0f); + public static void setShaderColorWithAlpha(int color, int alpha) { + RenderSystem.setShaderColor((float)ColorUtil.getRed(color) / 255.0f, (float)ColorUtil.getGreen(color) / 255.0f, (float)ColorUtil.getBlue(color) / 255.0f, (float)alpha / 255.0f); } - public static void setShaderColor(int n) { - RenderSystem.setShaderColor((float)ColorUtil.getRed(n) / 255.0f, (float)ColorUtil.getGreen(n) / 255.0f, (float)ColorUtil.getBlue(n) / 255.0f, (float)ColorUtil.getAlpha(n) / 255.0f); + public static void setShaderColor(int color) { + RenderSystem.setShaderColor((float)ColorUtil.getRed(color) / 255.0f, (float)ColorUtil.getGreen(color) / 255.0f, (float)ColorUtil.getBlue(color) / 255.0f, (float)ColorUtil.getAlpha(color) / 255.0f); } public static void withBlend(Runnable runnable) { @@ -107,8 +107,8 @@ public final class RenderHelper { RenderSystem.disableBlend(); } - public static void setShaderColorComponents(int n) { - RenderHelper.setShaderColorRGBA(ColorUtil.getRed(n), ColorUtil.getGreen(n), ColorUtil.getBlue(n), ColorUtil.getAlpha(n)); + public static void setShaderColorComponents(int color) { + RenderHelper.setShaderColorRGBA(ColorUtil.getRed(color), ColorUtil.getGreen(color), ColorUtil.getBlue(color), ColorUtil.getAlpha(color)); } public static DynamicTexture uploadTexture(NativeImage nativeImage, BufferedImage bufferedImage) { @@ -124,4 +124,4 @@ public final class RenderHelper { private RenderHelper() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/render/RenderUtil.java b/src/main/java/shit/zen/utils/render/RenderUtil.java index 2e231c7..51df1e1 100644 --- a/src/main/java/shit/zen/utils/render/RenderUtil.java +++ b/src/main/java/shit/zen/utils/render/RenderUtil.java @@ -74,7 +74,7 @@ extends ClientBase { private static boolean blurFailed; private static float zLevel; - public static void drawGradientV(PoseStack poseStack, float f, float f2, float f3, float f4, int n, int n2) { + public static void drawGradientV(PoseStack poseStack, float x, float y, float width, float height, int colorTop, int colorBottom) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderHelper.resetShaderColor(); @@ -82,15 +82,15 @@ extends ClientBase { RenderSystem.setShader(GameRenderer::getPositionColorShader); BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - bufferBuilder.vertex(matrix4f, f, f2, zLevel).color(n).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, zLevel).color(n2).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, zLevel).color(n2).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, zLevel).color(n).endVertex(); + bufferBuilder.vertex(matrix4f, x, y, zLevel).color(colorTop).endVertex(); + bufferBuilder.vertex(matrix4f, x, y + height, zLevel).color(colorBottom).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y + height, zLevel).color(colorBottom).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y, zLevel).color(colorTop).endVertex(); BufferUploader.drawWithShader(bufferBuilder.end()); RenderSystem.disableBlend(); } - public static void drawGradientH(PoseStack poseStack, float f, float f2, float f3, float f4, int n, int n2) { + public static void drawGradientH(PoseStack poseStack, float x, float y, float width, float height, int colorLeft, int colorRight) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderHelper.resetShaderColor(); @@ -98,15 +98,15 @@ extends ClientBase { RenderSystem.setShader(GameRenderer::getPositionColorShader); BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - bufferBuilder.vertex(matrix4f, f, f2, zLevel).color(n).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, zLevel).color(n).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, zLevel).color(n2).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, zLevel).color(n2).endVertex(); + bufferBuilder.vertex(matrix4f, x, y, zLevel).color(colorLeft).endVertex(); + bufferBuilder.vertex(matrix4f, x, y + height, zLevel).color(colorLeft).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y + height, zLevel).color(colorRight).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y, zLevel).color(colorRight).endVertex(); BufferUploader.drawWithShader(bufferBuilder.end()); RenderSystem.disableBlend(); } - public static void drawDiamond(PoseStack poseStack, float f, float f2, float f3, float f4, float f5, int n) { + public static void drawDiamond(PoseStack poseStack, float centerX, float centerY, float size, float widthRatio, float bottomRatio, int color) { GL11.glEnable(3042); GL11.glBlendFunc(770, 771); GL11.glDisable(2929); @@ -114,17 +114,17 @@ extends ClientBase { GL11.glEnable(2848); RenderSystem.setShader(GameRenderer::getPositionColorShader); Matrix4f matrix4f = poseStack.last().pose(); - float f6 = (float)(n >> 24 & 0xFF) / 255.0f; - float f7 = (float)(n >> 16 & 0xFF) / 255.0f; - float f8 = (float)(n >> 8 & 0xFF) / 255.0f; - float f9 = (float)(n & 0xFF) / 255.0f; + float alpha = (float)(color >> 24 & 0xFF) / 255.0f; + float red = (float)(color >> 16 & 0xFF) / 255.0f; + float green = (float)(color >> 8 & 0xFF) / 255.0f; + float blue = (float)(color & 0xFF) / 255.0f; BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).color(f7, f8, f9, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f - f3 / f4, f2 + f3, 0.0f).color(f7, f8, f9, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f3 / f5, 0.0f).color(f7, f8, f9, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3 / f4, f2 + f3, 0.0f).color(f7, f8, f9, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).color(f7, f8, f9, f6).endVertex(); + bufferBuilder.vertex(matrix4f, centerX, centerY, 0.0f).color(red, green, blue, alpha).endVertex(); + bufferBuilder.vertex(matrix4f, centerX - size / widthRatio, centerY + size, 0.0f).color(red, green, blue, alpha).endVertex(); + bufferBuilder.vertex(matrix4f, centerX, centerY + size / bottomRatio, 0.0f).color(red, green, blue, alpha).endVertex(); + bufferBuilder.vertex(matrix4f, centerX + size / widthRatio, centerY + size, 0.0f).color(red, green, blue, alpha).endVertex(); + bufferBuilder.vertex(matrix4f, centerX, centerY, 0.0f).color(red, green, blue, alpha).endVertex(); Tesselator.getInstance().end(); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); GL11.glDisable(3042); @@ -133,89 +133,89 @@ extends ClientBase { GL11.glDisable(2848); } - public static void drawRoundedRect(PoseStack poseStack, float f, float f2, float f3, float f4, float f5, int n) { - RenderUtil.drawRoundedRect(poseStack, f, f2, f3, f4, f5, 1.0f, n); + public static void drawRoundedRect(PoseStack poseStack, float x, float y, float width, float height, float radius, int color) { + RenderUtil.drawRoundedRect(poseStack, x, y, width, height, radius, 1.0f, color); } - public static void drawRoundedRect(PoseStack poseStack, float f, float f2, float f3, float f4, float f5, float f6, int n) { + public static void drawRoundedRect(PoseStack poseStack, float x, float y, float width, float height, float radius, float smoothness, int color) { if (roundedRectShader == null) { roundedRectShader = new ShaderProgram("rounded_rect", "vertex_color", ShaderFormats.POSITION_UV_COLOR); } Matrix4f matrix4f = poseStack.last().pose(); roundedRectShader.use(); - GL20.glUniform2f(roundedRectShader.getUniformLocation("Size"), f3, f4); - GL20.glUniform1f(roundedRectShader.getUniformLocation("Radius"), f5); - GL20.glUniform1f(roundedRectShader.getUniformLocation("Smoothness"), f6); + GL20.glUniform2f(roundedRectShader.getUniformLocation("Size"), width, height); + GL20.glUniform1f(roundedRectShader.getUniformLocation("Radius"), radius); + GL20.glUniform1f(roundedRectShader.getUniformLocation("Smoothness"), smoothness); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).uv(0.0f, 0.0f).color(n).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, 0.0f).uv(0.0f, 1.0f).color(n).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, 0.0f).uv(1.0f, 1.0f).color(n).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, 0.0f).uv(1.0f, 0.0f).color(n).endVertex(); + bufferBuilder.vertex(matrix4f, x, y, 0.0f).uv(0.0f, 0.0f).color(color).endVertex(); + bufferBuilder.vertex(matrix4f, x, y + height, 0.0f).uv(0.0f, 1.0f).color(color).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y + height, 0.0f).uv(1.0f, 1.0f).color(color).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y, 0.0f).uv(1.0f, 0.0f).color(color).endVertex(); BufferUploader.draw(bufferBuilder.end()); RenderSystem.disableBlend(); roundedRectShader.stopUsing(); } - public static void drawRoundedRectCorners(PoseStack poseStack, float f, float f2, float f3, float f4, float f5, boolean bl, boolean bl2, boolean bl3, boolean bl4, int n) { - if (f5 <= 0.0f || !bl && !bl2 && !bl3 && !bl4) { - RenderUtil.drawFilledRect(poseStack, f, f2, f3, f4, n); + public static void drawRoundedRectCorners(PoseStack poseStack, float x, float y, float width, float height, float radius, boolean topLeft, boolean topRight, boolean bottomLeft, boolean bottomRight, int color) { + if (radius <= 0.0f || !topLeft && !topRight && !bottomLeft && !bottomRight) { + RenderUtil.drawFilledRect(poseStack, x, y, width, height, color); return; } - f5 = Math.min(f5, Math.min(f3, f4) / 2.0f); - float f6 = f3 - 2.0f * f5; - float f7 = f4 - 2.0f * f5; + radius = Math.min(radius, Math.min(width, height) / 2.0f); + float innerWidth = width - 2.0f * radius; + float innerHeight = height - 2.0f * radius; RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - if (f6 > 0.0f && f7 > 0.0f) { - RenderUtil.drawFilledRect(poseStack, f + f5, f2 + f5, f6, f7, n); + if (innerWidth > 0.0f && innerHeight > 0.0f) { + RenderUtil.drawFilledRect(poseStack, x + radius, y + radius, innerWidth, innerHeight, color); } - if (f6 > 0.0f) { - RenderUtil.drawFilledRect(poseStack, f + f5, f2, f6, f5, n); - RenderUtil.drawFilledRect(poseStack, f + f5, f2 + f4 - f5, f6, f5, n); + if (innerWidth > 0.0f) { + RenderUtil.drawFilledRect(poseStack, x + radius, y, innerWidth, radius, color); + RenderUtil.drawFilledRect(poseStack, x + radius, y + height - radius, innerWidth, radius, color); } - if (f7 > 0.0f) { - RenderUtil.drawFilledRect(poseStack, f, f2 + f5, f5, f7, n); - RenderUtil.drawFilledRect(poseStack, f + f3 - f5, f2 + f5, f5, f7, n); + if (innerHeight > 0.0f) { + RenderUtil.drawFilledRect(poseStack, x, y + radius, radius, innerHeight, color); + RenderUtil.drawFilledRect(poseStack, x + width - radius, y + radius, radius, innerHeight, color); } - if (bl) { - RenderUtil.pushScissor((int)f, (int)f2, (int)f5, (int)f5); - RenderUtil.drawRoundedRect(poseStack, f, f2, f5 * 2.0f, f5 * 2.0f, f5, n); + if (topLeft) { + RenderUtil.pushScissor((int)x, (int)y, (int)radius, (int)radius); + RenderUtil.drawRoundedRect(poseStack, x, y, radius * 2.0f, radius * 2.0f, radius, color); RenderUtil.popScissor(); } else { - RenderUtil.drawFilledRect(poseStack, f, f2, f5, f5, n); + RenderUtil.drawFilledRect(poseStack, x, y, radius, radius, color); } - if (bl2) { - RenderUtil.pushScissor((int)(f + f3 - f5), (int)f2, (int)f5, (int)f5); - RenderUtil.drawRoundedRect(poseStack, f + f3 - f5 * 2.0f, f2, f5 * 2.0f, f5 * 2.0f, f5, n); + if (topRight) { + RenderUtil.pushScissor((int)(x + width - radius), (int)y, (int)radius, (int)radius); + RenderUtil.drawRoundedRect(poseStack, x + width - radius * 2.0f, y, radius * 2.0f, radius * 2.0f, radius, color); RenderUtil.popScissor(); } else { - RenderUtil.drawFilledRect(poseStack, f + f3 - f5, f2, f5, f5, n); + RenderUtil.drawFilledRect(poseStack, x + width - radius, y, radius, radius, color); } - if (bl3) { - RenderUtil.pushScissor((int)f, (int)(f2 + f4 - f5), (int)f5, (int)f5); - RenderUtil.drawRoundedRect(poseStack, f, f2 + f4 - f5 * 2.0f, f5 * 2.0f, f5 * 2.0f, f5, n); + if (bottomLeft) { + RenderUtil.pushScissor((int)x, (int)(y + height - radius), (int)radius, (int)radius); + RenderUtil.drawRoundedRect(poseStack, x, y + height - radius * 2.0f, radius * 2.0f, radius * 2.0f, radius, color); RenderUtil.popScissor(); } else { - RenderUtil.drawFilledRect(poseStack, f, f2 + f4 - f5, f5, f5, n); + RenderUtil.drawFilledRect(poseStack, x, y + height - radius, radius, radius, color); } - if (bl4) { - RenderUtil.pushScissor((int)(f + f3 - f5), (int)(f2 + f4 - f5), (int)f5, (int)f5); - RenderUtil.drawRoundedRect(poseStack, f + f3 - f5 * 2.0f, f2 + f4 - f5 * 2.0f, f5 * 2.0f, f5 * 2.0f, f5, n); + if (bottomRight) { + RenderUtil.pushScissor((int)(x + width - radius), (int)(y + height - radius), (int)radius, (int)radius); + RenderUtil.drawRoundedRect(poseStack, x + width - radius * 2.0f, y + height - radius * 2.0f, radius * 2.0f, radius * 2.0f, radius, color); RenderUtil.popScissor(); } else { - RenderUtil.drawFilledRect(poseStack, f + f3 - f5, f2 + f4 - f5, f5, f5, n); + RenderUtil.drawFilledRect(poseStack, x + width - radius, y + height - radius, radius, radius, color); } RenderSystem.enableBlend(); } - public static void drawBlurredRect(PoseStack poseStack, float f, float f2, float f3, float f4, float f5, float f6, float f7, int n) { + public static void drawBlurredRect(PoseStack poseStack, float x, float y, float width, float height, float radius, float blurRadius, float opacity, int color) { try { - PoseStack poseStack2; - boolean bl; + PoseStack blitPoseStack; + boolean shouldBlur; if (blurFailed) { return; } @@ -230,37 +230,37 @@ extends ClientBase { textureTarget.resize(RenderUtil.mainRenderTarget.width, RenderUtil.mainRenderTarget.height, Minecraft.ON_OSX); } Matrix4f matrix4f = poseStack.last().pose(); - int n2 = n == 0 ? ColorUtil.fromARGB(255, 255, 255, 255) : n; - n2 = ColorUtil.withAlpha(n2, f7); + int blendColor = color == 0 ? ColorUtil.fromARGB(255, 255, 255, 255) : color; + blendColor = ColorUtil.withAlpha(blendColor, opacity); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - float f8 = RenderUtil.mainRenderTarget.width * RenderUtil.mainRenderTarget.height; - float f9 = f3 * f4; - boolean bl2 = f9 / f8 >= 0.05f; - long l = mc.level != null ? mc.level.getGameTime() : -1L; - boolean bl3 = bl = !bl2 || l != -1L; - if (bl) { + float screenArea = RenderUtil.mainRenderTarget.width * RenderUtil.mainRenderTarget.height; + float rectArea = width * height; + boolean isLargeRect = rectArea / screenArea >= 0.05f; + long gameTime = mc.level != null ? mc.level.getGameTime() : -1L; + boolean shouldBlurTmp = shouldBlur = !isLargeRect || gameTime != -1L; + if (shouldBlur) { textureTarget.bindWrite(false); - poseStack2 = new PoseStack(); - RenderHelper.blitRenderTarget(mainRenderTarget, poseStack2, textureTarget.width, textureTarget.height); + blitPoseStack = new PoseStack(); + RenderHelper.blitRenderTarget(mainRenderTarget, blitPoseStack, textureTarget.width, textureTarget.height); mainRenderTarget.bindWrite(false); } blurShader.use(); GL20.glUniform1i(blurShader.getUniformLocation("Sampler0"), 0); GlStateManager._activeTexture(33984); GlStateManager._bindTexture(textureTarget.getColorTextureId()); - GL20.glUniform2f(blurShader.getUniformLocation("Size"), f3, f4); - GL20.glUniform4f(blurShader.getUniformLocation("Radius"), f5, f5, f5, f5); + GL20.glUniform2f(blurShader.getUniformLocation("Size"), width, height); + GL20.glUniform4f(blurShader.getUniformLocation("Radius"), radius, radius, radius, radius); GL20.glUniform1f(blurShader.getUniformLocation("Smoothness"), 1.0f); - GL20.glUniform1f(blurShader.getUniformLocation("BlurRadius"), f6); - GL20.glUniform1f(blurShader.getUniformLocation("Opacity"), f7); + GL20.glUniform1f(blurShader.getUniformLocation("BlurRadius"), blurRadius); + GL20.glUniform1f(blurShader.getUniformLocation("Opacity"), opacity); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).uv(0.0f, 1.0f).color(n2).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, 0.0f).uv(0.0f, 0.0f).color(n2).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, 0.0f).uv(1.0f, 0.0f).color(n2).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, 0.0f).uv(1.0f, 1.0f).color(n2).endVertex(); + bufferBuilder.vertex(matrix4f, x, y, 0.0f).uv(0.0f, 1.0f).color(blendColor).endVertex(); + bufferBuilder.vertex(matrix4f, x, y + height, 0.0f).uv(0.0f, 0.0f).color(blendColor).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y + height, 0.0f).uv(1.0f, 0.0f).color(blendColor).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y, 0.0f).uv(1.0f, 1.0f).color(blendColor).endVertex(); BufferUploader.draw(bufferBuilder.end()); GlStateManager._bindTexture(0); blurShader.stopUsing(); @@ -271,28 +271,28 @@ extends ClientBase { } } - public static void pushScissor(int n, int n2, int n3, int n4) { - int n5 = (int)mc.getWindow().getGuiScale(); - int n6 = n * n5; - int n7 = mc.getWindow().getHeight() - (n2 + n4) * n5; - int n8 = n3 * n5; - int n9 = n4 * n5; - int[] nArray = new int[4]; + public static void pushScissor(int x, int y, int width, int height) { + int guiScale = (int)mc.getWindow().getGuiScale(); + int scaledX = x * guiScale; + int scaledY = mc.getWindow().getHeight() - (y + height) * guiScale; + int scaledWidth = width * guiScale; + int scaledHeight = height * guiScale; + int[] parentBounds = new int[4]; if (!scissorStack.isEmpty()) { - nArray = scissorStack.peek(); + parentBounds = scissorStack.peek(); } else { - nArray[0] = 0; - nArray[1] = 0; - nArray[2] = mc.getWindow().getWidth(); - nArray[3] = mc.getWindow().getHeight(); + parentBounds[0] = 0; + parentBounds[1] = 0; + parentBounds[2] = mc.getWindow().getWidth(); + parentBounds[3] = mc.getWindow().getHeight(); } - int n10 = Math.max(n6, nArray[0]); - int n11 = Math.max(n7, nArray[1]); - int n12 = Math.min(n6 + n8, nArray[0] + nArray[2]) - n10; - int n13 = Math.min(n7 + n9, nArray[1] + nArray[3]) - n11; - int[] nArray2 = new int[]{n10, n11, n12, n13}; - scissorStack.push(nArray2); - RenderSystem.enableScissor(nArray2[0], nArray2[1], nArray2[2], nArray2[3]); + int clippedX = Math.max(scaledX, parentBounds[0]); + int clippedY = Math.max(scaledY, parentBounds[1]); + int clippedWidth = Math.min(scaledX + scaledWidth, parentBounds[0] + parentBounds[2]) - clippedX; + int clippedHeight = Math.min(scaledY + scaledHeight, parentBounds[1] + parentBounds[3]) - clippedY; + int[] clippedBounds = new int[]{clippedX, clippedY, clippedWidth, clippedHeight}; + scissorStack.push(clippedBounds); + RenderSystem.enableScissor(clippedBounds[0], clippedBounds[1], clippedBounds[2], clippedBounds[3]); } public static void popScissor() { @@ -304,45 +304,45 @@ extends ClientBase { if (scissorStack.isEmpty()) { RenderSystem.disableScissor(); } else { - int[] nArray = scissorStack.peek(); - RenderSystem.enableScissor(nArray[0], nArray[1], nArray[2], nArray[3]); + int[] bounds = scissorStack.peek(); + RenderSystem.enableScissor(bounds[0], bounds[1], bounds[2], bounds[3]); } } - public static void drawTexturedRect(PoseStack poseStack, int n, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, int n10) { - float f = (float)n5 / (float)n9; - float f2 = (float)(n5 + n7) / (float)n9; - float f3 = (float)n6 / (float)n10; - float f4 = (float)(n6 + n8) / (float)n10; + public static void drawTexturedRect(PoseStack poseStack, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight, int textureWidth, int textureHeight) { + float u0 = (float)u / (float)textureWidth; + float u1 = (float)(u + regionWidth) / (float)textureWidth; + float v0 = (float)v / (float)textureHeight; + float v1 = (float)(v + regionHeight) / (float)textureHeight; RenderSystem.setShader(GameRenderer::getPositionTexShader); BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); Matrix4f matrix4f = poseStack.last().pose(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - bufferBuilder.vertex(matrix4f, (float)n, (float)(n2 + n4), 0.0f).uv(f, f4).endVertex(); - bufferBuilder.vertex(matrix4f, (float)(n + n3), (float)(n2 + n4), 0.0f).uv(f2, f4).endVertex(); - bufferBuilder.vertex(matrix4f, (float)(n + n3), (float)n2, 0.0f).uv(f2, f3).endVertex(); - bufferBuilder.vertex(matrix4f, (float)n, (float)n2, 0.0f).uv(f, f3).endVertex(); + bufferBuilder.vertex(matrix4f, (float)x, (float)(y + height), 0.0f).uv(u0, v1).endVertex(); + bufferBuilder.vertex(matrix4f, (float)(x + width), (float)(y + height), 0.0f).uv(u1, v1).endVertex(); + bufferBuilder.vertex(matrix4f, (float)(x + width), (float)y, 0.0f).uv(u1, v0).endVertex(); + bufferBuilder.vertex(matrix4f, (float)x, (float)y, 0.0f).uv(u0, v0).endVertex(); BufferUploader.drawWithShader(bufferBuilder.end()); } - public static void drawFilledRect(PoseStack poseStack, float f, float f2, float f3, float f4, int n) { + public static void drawFilledRect(PoseStack poseStack, float x, float y, float width, float height, int color) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - RenderHelper.setShaderColor(n); - RenderUtil.drawFilledRect(poseStack, f, f2, f3, f4); + RenderHelper.setShaderColor(color); + RenderUtil.drawFilledRect(poseStack, x, y, width, height); RenderSystem.disableBlend(); RenderHelper.resetShaderColor(); } - public static void drawFilledRect(PoseStack poseStack, float f, float f2, float f3, float f4) { + public static void drawFilledRect(PoseStack poseStack, float x, float y, float width, float height) { Matrix4f matrix4f = poseStack.last().pose(); RenderSystem.setShader(GameRenderer::getPositionShader); BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); - bufferBuilder.vertex(matrix4f, f, f2, zLevel).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, zLevel).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, zLevel).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, zLevel).endVertex(); + bufferBuilder.vertex(matrix4f, x, y, zLevel).endVertex(); + bufferBuilder.vertex(matrix4f, x, y + height, zLevel).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y + height, zLevel).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y, zLevel).endVertex(); BufferUploader.drawWithShader(bufferBuilder.end()); } @@ -410,48 +410,48 @@ extends ClientBase { BufferUploader.drawWithShader(bufferBuilder.end()); } - public static boolean isHovered(float f, float f2, float f3, float f4, int n, int n2) { - return (float)n >= f && (float)n2 >= f2 && (float)n < f + f3 && (float)n2 < f2 + f4; + public static boolean isHovered(float x, float y, float width, float height, int mouseX, int mouseY) { + return (float)mouseX >= x && (float)mouseY >= y && (float)mouseX < x + width && (float)mouseY < y + height; } - public static void drawQuad(BufferBuilder bufferBuilder, Matrix4f matrix4f, float f, float f2, float f3, float f4, Color color) { - float f5 = (float)color.getRed() / 255.0f; - float f6 = (float)color.getGreen() / 255.0f; - float f7 = (float)color.getBlue() / 255.0f; - float f8 = (float)color.getAlpha() / 255.0f; - bufferBuilder.vertex(matrix4f, f, f4, 0.0f).color(f5, f6, f7, f8).endVertex(); - bufferBuilder.vertex(matrix4f, f3, f4, 0.0f).color(f5, f6, f7, f8).endVertex(); - bufferBuilder.vertex(matrix4f, f3, f2, 0.0f).color(f5, f6, f7, f8).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).color(f5, f6, f7, f8).endVertex(); + public static void drawQuad(BufferBuilder bufferBuilder, Matrix4f matrix4f, float left, float top, float right, float bottom, Color color) { + float red = (float)color.getRed() / 255.0f; + float green = (float)color.getGreen() / 255.0f; + float blue = (float)color.getBlue() / 255.0f; + float alpha = (float)color.getAlpha() / 255.0f; + bufferBuilder.vertex(matrix4f, left, bottom, 0.0f).color(red, green, blue, alpha).endVertex(); + bufferBuilder.vertex(matrix4f, right, bottom, 0.0f).color(red, green, blue, alpha).endVertex(); + bufferBuilder.vertex(matrix4f, right, top, 0.0f).color(red, green, blue, alpha).endVertex(); + bufferBuilder.vertex(matrix4f, left, top, 0.0f).color(red, green, blue, alpha).endVertex(); } - public static void drawSpiralEffect(PoseStack poseStack, Entity entity, float f) { - double d; - double d2; - double d3; - double d4; - double d5; - double d6; - int n; + public static void drawSpiralEffect(PoseStack poseStack, Entity entity, float partialTicks) { + double topY; + double posZ; + double posX; + double offsetX; + double offsetZ; + double angle; + int outerColor; if (mc == null || mc.gameRenderer == null || mc.gameRenderer.getMainCamera() == null) { return; } - double d7 = 2000.0; - double d8 = (double)System.currentTimeMillis() % d7; - boolean bl = d8 > d7 / 2.0; - double d9 = d8 / (d7 / 2.0); - d9 = bl ? (d9 -= 1.0) : 1.0 - d9; - d9 = d9 < 0.5 ? 2.0 * d9 * d9 : 1.0 - Math.pow(-2.0 * d9 + 2.0, 2.0) / 2.0; - Vec3 vec3 = EntityUtil.getInterpolatedPos(entity, f); - double d10 = vec3.x(); - double d11 = vec3.y(); - double d12 = vec3.z(); - float f2 = entity.getBbHeight(); - double d13 = (double)entity.getBbWidth() * 0.975; - double d14 = (double)f2 * d9; - double d15 = (double)f2 / 1.2 * (d9 > 0.5 ? 1.0 - d9 : d9) * (double)(bl ? -1 : 1); - double d16 = d11 + d14; - double d17 = d16 + d15; + double cycleMs = 2000.0; + double cycleTime = (double)System.currentTimeMillis() % cycleMs; + boolean secondHalf = cycleTime > cycleMs / 2.0; + double progress = cycleTime / (cycleMs / 2.0); + progress = secondHalf ? (progress -= 1.0) : 1.0 - progress; + progress = progress < 0.5 ? 2.0 * progress * progress : 1.0 - Math.pow(-2.0 * progress + 2.0, 2.0) / 2.0; + Vec3 vec3 = EntityUtil.getInterpolatedPos(entity, partialTicks); + double entityX = vec3.x(); + double entityY = vec3.y(); + double entityZ = vec3.z(); + float entityHeight = entity.getBbHeight(); + double entityWidth = (double)entity.getBbWidth() * 0.975; + double heightOffset = (double)entityHeight * progress; + double extraOffset = (double)entityHeight / 1.2 * (progress > 0.5 ? 1.0 - progress : progress) * (double)(secondHalf ? -1 : 1); + double ringY = entityY + heightOffset; + double ringTopY = ringY + extraOffset; RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); @@ -463,20 +463,20 @@ extends ClientBase { Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR); - int n2 = 60; - for (int i = 0; i <= n2; ++i) { + int segments = 60; + for (int i = 0; i <= segments; ++i) { Color color = ColorUtil.getRainbowColor(10, i * 5); - int n3 = color.getRGB(); - n = ColorUtil.withAlphaColor(color, 0.004f).getRGB(); - d6 = (double)i / (double)n2 * Math.PI * 2.0; - d5 = Math.cos(d6) * d13; - d4 = Math.sin(d6) * d13; - d3 = d10 + d5; - d2 = d12 + d4; - d = d16; - double d18 = d17; - bufferBuilder.vertex(matrix4f, (float)d3, (float)d, (float)d2).color(n3).endVertex(); - bufferBuilder.vertex(matrix4f, (float)d3, (float)d18, (float)d2).color(n).endVertex(); + int baseColor = color.getRGB(); + outerColor = ColorUtil.withAlphaColor(color, 0.004f).getRGB(); + angle = (double)i / (double)segments * Math.PI * 2.0; + offsetZ = Math.cos(angle) * entityWidth; + offsetX = Math.sin(angle) * entityWidth; + posX = entityX + offsetZ; + posZ = entityZ + offsetX; + topY = ringY; + double topY2 = ringTopY; + bufferBuilder.vertex(matrix4f, (float)posX, (float)topY, (float)posZ).color(baseColor).endVertex(); + bufferBuilder.vertex(matrix4f, (float)posX, (float)topY2, (float)posZ).color(outerColor).endVertex(); } BufferBuilder.RenderedBuffer renderedBuffer = bufferBuilder.end(); if (renderedBuffer != null) { @@ -485,16 +485,16 @@ extends ClientBase { bufferBuilder = Tesselator.getInstance().getBuilder(); bufferBuilder.begin(VertexFormat.Mode.LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); RenderSystem.lineWidth(1.0f); - for (int i = 0; i <= n2; ++i) { + for (int i = 0; i <= segments; ++i) { Color color = ColorUtil.getRainbowColor(10, i * 5); - n = ColorUtil.withAlphaColor(color, 0.004f).getRGB(); - d6 = (double)i / (double)n2 * Math.PI * 2.0; - d5 = Math.cos(d6) * d13; - d4 = Math.sin(d6) * d13; - d3 = d10 + d5; - d2 = d12 + d4; - d = d16; - bufferBuilder.vertex(matrix4f, (float)d3, (float)d, (float)d2).color(n).endVertex(); + outerColor = ColorUtil.withAlphaColor(color, 0.004f).getRGB(); + angle = (double)i / (double)segments * Math.PI * 2.0; + offsetZ = Math.cos(angle) * entityWidth; + offsetX = Math.sin(angle) * entityWidth; + posX = entityX + offsetZ; + posZ = entityZ + offsetX; + topY = ringY; + bufferBuilder.vertex(matrix4f, (float)posX, (float)topY, (float)posZ).color(outerColor).endVertex(); } BufferUploader.drawWithShader(bufferBuilder.end()); RenderSystem.lineWidth(1.0f); @@ -504,7 +504,7 @@ extends ClientBase { RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); } - public static void drawColoredBox(AABB aABB, PoseStack poseStack, Color color, Color color2) { + public static void drawColoredBox(AABB aABB, PoseStack poseStack, Color topColor, Color bottomColor) { Matrix4f matrix4f = poseStack.last().pose(); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); @@ -513,123 +513,123 @@ extends ClientBase { RenderSystem.setShader(GameRenderer::getPositionColorShader); RenderSystem.lineWidth(1.5f); bufferBuilder.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR); - float f = (float)aABB.minX; - float f2 = (float)aABB.minY; - float f3 = (float)aABB.minZ; - float f4 = (float)aABB.maxX; - float f5 = (float)aABB.maxY; - float f6 = (float)aABB.maxZ; - bufferBuilder.vertex(matrix4f, f, f2, f3).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f3).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f3).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f6).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f6).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f6).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f6).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f3).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f3).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f3).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f3).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f6).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f6).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f6).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f6).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f3).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f3).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f3).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f3).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f3).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f6).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f6).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f6).color(color2.getRed(), color2.getGreen(), color2.getBlue(), color2.getAlpha()).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f6).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); + float minX = (float)aABB.minX; + float minY = (float)aABB.minY; + float minZ = (float)aABB.minZ; + float maxX = (float)aABB.maxX; + float maxY = (float)aABB.maxY; + float maxZ = (float)aABB.maxZ; + bufferBuilder.vertex(matrix4f, minX, minY, minZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, minZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, minZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, maxZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, maxZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, maxZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, maxZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, minZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, minZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, minZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, minZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, maxZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, maxZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, maxZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, maxZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, minZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, minZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, minZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, minZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, minZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, maxZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, maxZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, maxZ).color(bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, maxZ).color(topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()).endVertex(); BufferUploader.drawWithShader(bufferBuilder.end()); RenderSystem.lineWidth(1.0f); RenderSystem.disableBlend(); } - public static void drawFilledColoredBox(AABB aABB, PoseStack poseStack, Color color, Color color2) { + public static void drawFilledColoredBox(AABB aABB, PoseStack poseStack, Color topColor, Color bottomColor) { Matrix4f matrix4f = poseStack.last().pose(); Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShader(GameRenderer::getPositionColorShader); - float f = (float)aABB.minX; - float f2 = (float)aABB.minY; - float f3 = (float)aABB.minZ; - float f4 = (float)aABB.maxX; - float f5 = (float)aABB.maxY; - float f6 = (float)aABB.maxZ; - int n = color.getRed(); - int n2 = color.getGreen(); - int n3 = color.getBlue(); - int n4 = color.getAlpha(); - int n5 = color2.getRed(); - int n6 = color2.getGreen(); - int n7 = color2.getBlue(); - int n8 = color2.getAlpha(); + float minX = (float)aABB.minX; + float minY = (float)aABB.minY; + float minZ = (float)aABB.minZ; + float maxX = (float)aABB.maxX; + float maxY = (float)aABB.maxY; + float maxZ = (float)aABB.maxZ; + int topR = topColor.getRed(); + int topG = topColor.getGreen(); + int topB = topColor.getBlue(); + int topA = topColor.getAlpha(); + int botR = bottomColor.getRed(); + int botG = bottomColor.getGreen(); + int botB = bottomColor.getBlue(); + int botA = bottomColor.getAlpha(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - bufferBuilder.vertex(matrix4f, f, f2, f6).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f6).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f6).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f6).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f3).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f3).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f3).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f3).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f3).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f6).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f6).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f3).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f3).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f3).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f6).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f6).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f3).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f6).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f6).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f3).color(n, n2, n3, n4).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f3).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f3).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f6).color(n5, n6, n7, n8).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f6).color(n5, n6, n7, n8).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, maxZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, maxZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, maxZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, maxZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, minZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, minZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, minZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, minZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, minZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, maxZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, maxZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, minZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, minZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, minZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, maxZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, maxZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, minZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, maxZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, maxZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, minZ).color(topR, topG, topB, topA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, minZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, minZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, maxZ).color(botR, botG, botB, botA).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, maxZ).color(botR, botG, botB, botA).endVertex(); BufferUploader.drawWithShader(bufferBuilder.end()); RenderSystem.disableBlend(); } public static void drawBoxVerts(BufferBuilder bufferBuilder, Matrix4f matrix4f, AABB aABB) { - float f = (float)(aABB.minX - mc.getEntityRenderDispatcher().camera.getPosition().x()); - float f2 = (float)(aABB.minY - mc.getEntityRenderDispatcher().camera.getPosition().y()); - float f3 = (float)(aABB.minZ - mc.getEntityRenderDispatcher().camera.getPosition().z()); - float f4 = (float)(aABB.maxX - mc.getEntityRenderDispatcher().camera.getPosition().x()); - float f5 = (float)(aABB.maxY - mc.getEntityRenderDispatcher().camera.getPosition().y()); - float f6 = (float)(aABB.maxZ - mc.getEntityRenderDispatcher().camera.getPosition().z()); + float minX = (float)(aABB.minX - mc.getEntityRenderDispatcher().camera.getPosition().x()); + float minY = (float)(aABB.minY - mc.getEntityRenderDispatcher().camera.getPosition().y()); + float minZ = (float)(aABB.minZ - mc.getEntityRenderDispatcher().camera.getPosition().z()); + float maxX = (float)(aABB.maxX - mc.getEntityRenderDispatcher().camera.getPosition().x()); + float maxY = (float)(aABB.maxY - mc.getEntityRenderDispatcher().camera.getPosition().y()); + float maxZ = (float)(aABB.maxZ - mc.getEntityRenderDispatcher().camera.getPosition().z()); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); - bufferBuilder.vertex(matrix4f, f, f2, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f2, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f4, f5, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f3).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f6).endVertex(); - bufferBuilder.vertex(matrix4f, f, f5, f3).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, minY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, maxX, maxY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, minZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, minY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, maxZ).endVertex(); + bufferBuilder.vertex(matrix4f, minX, maxY, minZ).endVertex(); BufferUploader.drawWithShader(bufferBuilder.end()); } @@ -643,46 +643,46 @@ extends ClientBase { RenderSystem.disableBlend(); } - public static void drawTexture(ResourceLocation resourceLocation, PoseStack poseStack, float f, float f2, float f3, float f4, float f5, int n) { - RenderUtil.drawTexture(mc.getTextureManager().getTexture(resourceLocation).getId(), poseStack, f, f2, f3, f4, f5, n); + public static void drawTexture(ResourceLocation resourceLocation, PoseStack poseStack, float x, float y, float width, float height, float alpha, int color) { + RenderUtil.drawTexture(mc.getTextureManager().getTexture(resourceLocation).getId(), poseStack, x, y, width, height, alpha, color); } - public static void drawTexture(int n, PoseStack poseStack, float f, float f2, float f3, float f4, float f5, int n2) { + public static void drawTexture(int textureId, PoseStack poseStack, float x, float y, float width, float height, float alpha, int color) { Matrix4f matrix4f = poseStack.last().pose(); - RenderHelper.setShaderColor(ColorUtil.withAlpha(n2, f5)); - if (n != -1) { + RenderHelper.setShaderColor(ColorUtil.withAlpha(color, alpha)); + if (textureId != -1) { RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, n); + RenderSystem.setShaderTexture(0, textureId); } Tesselator tesselator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tesselator.getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - bufferBuilder.vertex(matrix4f, f, f2, 0.0f).uv(0.0f, 0.0f).endVertex(); - bufferBuilder.vertex(matrix4f, f, f2 + f4, 0.0f).uv(0.0f, 1.0f).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2 + f4, 0.0f).uv(1.0f, 1.0f).endVertex(); - bufferBuilder.vertex(matrix4f, f + f3, f2, 0.0f).uv(1.0f, 0.0f).endVertex(); + bufferBuilder.vertex(matrix4f, x, y, 0.0f).uv(0.0f, 0.0f).endVertex(); + bufferBuilder.vertex(matrix4f, x, y + height, 0.0f).uv(0.0f, 1.0f).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y + height, 0.0f).uv(1.0f, 1.0f).endVertex(); + bufferBuilder.vertex(matrix4f, x + width, y, 0.0f).uv(1.0f, 0.0f).endVertex(); BufferUploader.drawWithShader(bufferBuilder.end()); RenderHelper.resetShaderColor(); } - public static void drawShadow(PoseStack poseStack, float f, float f2, float f3, float f4, int n, int n2) { - int n3; - f -= (float)n; - f2 -= (float)n; - if (!shadowCache.containsKey(n3 = (int)((f3 += (float)(n * 2)) * (f4 += (float)(n * 2)) + f3 * (float)n))) { - BufferedImage bufferedImage = new BufferedImage((int)f3, (int)f4, 2); + public static void drawShadow(PoseStack poseStack, float x, float y, float width, float height, int blurRadius, int color) { + int cacheKey; + x -= (float)blurRadius; + y -= (float)blurRadius; + if (!shadowCache.containsKey(cacheKey = (int)((width += (float)(blurRadius * 2)) * (height += (float)(blurRadius * 2)) + width * (float)blurRadius))) { + BufferedImage bufferedImage = new BufferedImage((int)width, (int)height, 2); Graphics graphics = bufferedImage.getGraphics(); graphics.setColor(new Color(-1)); - graphics.fillRect(n, n, (int)(f3 - (float)(n * 2)), (int)(f4 - (float)(n * 2))); + graphics.fillRect(blurRadius, blurRadius, (int)(width - (float)(blurRadius * 2)), (int)(height - (float)(blurRadius * 2))); graphics.dispose(); - GaussianBlur gaussianBlur = new GaussianBlur(n); - BufferedImage bufferedImage2 = gaussianBlur.filter(bufferedImage, null); - shadowCache.put(n3, new RenderUtil.ShadowTexture(bufferedImage2)); + GaussianBlur gaussianBlur = new GaussianBlur(blurRadius); + BufferedImage blurredImage = gaussianBlur.filter(bufferedImage, null); + shadowCache.put(cacheKey, new RenderUtil.ShadowTexture(blurredImage)); return; } - shadowCache.get(n3).bind(); + shadowCache.get(cacheKey).bind(); RenderUtil.enableBlend(); - RenderUtil.drawTexture(-1, poseStack, f, f2, f3, f4, (float)ColorUtil.getAlpha(n2) / 255.0f, n2); + RenderUtil.drawTexture(-1, poseStack, x, y, width, height, (float)ColorUtil.getAlpha(color) / 255.0f, color); RenderUtil.disableBlend(); } @@ -690,16 +690,16 @@ extends ClientBase { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write((RenderedImage)bufferedImage, (String)"png", (OutputStream)byteArrayOutputStream); - byte[] byArray = byteArrayOutputStream.toByteArray(); - RenderUtil.registerTextureBytes(resourceLocationWrapper, byArray); + byte[] pngBytes = byteArrayOutputStream.toByteArray(); + RenderUtil.registerTextureBytes(resourceLocationWrapper, pngBytes); } catch (Exception exception) { // empty catch block } } - private static void registerTextureBytes(ResourceLocationWrapper resourceLocationWrapper, byte[] byArray) { + private static void registerTextureBytes(ResourceLocationWrapper resourceLocationWrapper, byte[] pngBytes) { try { - ByteBuffer byteBuffer = BufferUtils.createByteBuffer(byArray.length).put(byArray); + ByteBuffer byteBuffer = BufferUtils.createByteBuffer(pngBytes.length).put(pngBytes); byteBuffer.flip(); DynamicTexture dynamicTexture = new DynamicTexture(NativeImage.read(byteBuffer)); mc.execute(() -> mc.getTextureManager().register(resourceLocationWrapper.get(), dynamicTexture)); @@ -708,16 +708,16 @@ extends ClientBase { } } - public static int lerpColorHSB(int n, int n2, float f) { - float[] fArray = new float[3]; - float[] fArray2 = new float[3]; - Color.RGBtoHSB(n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF, fArray); - Color.RGBtoHSB(n2 >> 16 & 0xFF, n2 >> 8 & 0xFF, n2 & 0xFF, fArray2); - float f2 = fArray[0] + (fArray2[0] - fArray[0]) * f; - float f3 = fArray[1] + (fArray2[1] - fArray[1]) * f; - float f4 = fArray[2] + (fArray2[2] - fArray[2]) * f; - int n3 = (int)((float)(n >> 24 & 0xFF) + (float)((n2 >> 24 & 0xFF) - (n >> 24 & 0xFF)) * f); - return n3 << 24 | Color.HSBtoRGB(f2, f3, f4) & 0xFFFFFF; + public static int lerpColorHSB(int colorA, int colorB, float progress) { + float[] hsbA = new float[3]; + float[] hsbB = new float[3]; + Color.RGBtoHSB(colorA >> 16 & 0xFF, colorA >> 8 & 0xFF, colorA & 0xFF, hsbA); + Color.RGBtoHSB(colorB >> 16 & 0xFF, colorB >> 8 & 0xFF, colorB & 0xFF, hsbB); + float hue = hsbA[0] + (hsbB[0] - hsbA[0]) * progress; + float saturation = hsbA[1] + (hsbB[1] - hsbA[1]) * progress; + float brightness = hsbA[2] + (hsbB[2] - hsbA[2]) * progress; + int alpha = (int)((float)(colorA >> 24 & 0xFF) + (float)((colorB >> 24 & 0xFF) - (colorA >> 24 & 0xFF)) * progress); + return alpha << 24 | Color.HSBtoRGB(hue, saturation, brightness) & 0xFFFFFF; } @Generated @@ -726,8 +726,8 @@ extends ClientBase { } @Generated - public static void setZLevel(float f) { - zLevel = f; + public static void setZLevel(float zLevelValue) { + zLevel = zLevelValue; } static { @@ -737,4 +737,4 @@ extends ClientBase { blurFailed = false; zLevel = 0.0f; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/render/TextureUtil.java b/src/main/java/shit/zen/utils/render/TextureUtil.java index 25fb688..7ba4fd6 100644 --- a/src/main/java/shit/zen/utils/render/TextureUtil.java +++ b/src/main/java/shit/zen/utils/render/TextureUtil.java @@ -16,18 +16,18 @@ import shit.zen.manager.ConfigManager; public final class TextureUtil { private static final Map textureCache = new HashMap<>(); - public static DynamicTexture loadTexture(String string) { - File file = new File(ConfigManager.CONFIG_DIR, string); + public static DynamicTexture loadTexture(String fileName) { + File file = new File(ConfigManager.CONFIG_DIR, fileName); if (!file.exists()) { System.out.println("Failed to find target file!"); return TextureUtil.getMissingTexture(); } - DynamicTexture dynamicTexture = textureCache.get(string); + DynamicTexture dynamicTexture = textureCache.get(fileName); if (dynamicTexture == null) { try (FileInputStream fileInputStream = new FileInputStream(file)){ NativeImage nativeImage = NativeImage.read(fileInputStream); dynamicTexture = new DynamicTexture(nativeImage); - textureCache.put(string, dynamicTexture); + textureCache.put(fileName, dynamicTexture); } catch (java.io.IOException ioException) { return TextureUtil.getMissingTexture(); } @@ -49,23 +49,23 @@ public final class TextureUtil { return dynamicTexture; } - public static HashMap parseQueryString(String string) { - String[] stringArray; - HashMap hashMap = new HashMap<>(); - if (string == null) { - return hashMap; + public static HashMap parseQueryString(String queryString) { + String[] pairs; + HashMap result = new HashMap<>(); + if (queryString == null) { + return result; } - for (String string2 : stringArray = string.split("&")) { - int n = string2.indexOf(61); - if (n != -1) { - String string3 = string2.substring(0, n); - String string4 = string2.substring(n + 1); - hashMap.put(URLDecoder.decode(string3, StandardCharsets.UTF_8), URLDecoder.decode(string4, StandardCharsets.UTF_8)); + for (String pair : pairs = queryString.split("&")) { + int equalsIndex = pair.indexOf(61); + if (equalsIndex != -1) { + String key = pair.substring(0, equalsIndex); + String value = pair.substring(equalsIndex + 1); + result.put(URLDecoder.decode(key, StandardCharsets.UTF_8), URLDecoder.decode(value, StandardCharsets.UTF_8)); continue; } - hashMap.put(URLDecoder.decode(string2, StandardCharsets.UTF_8), ""); + result.put(URLDecoder.decode(pair, StandardCharsets.UTF_8), ""); } - return hashMap; + return result; } @Generated @@ -76,4 +76,4 @@ public final class TextureUtil { private static UnsupportedEncodingException wrapEncodingException(UnsupportedEncodingException unsupportedEncodingException) { return unsupportedEncodingException; } -} \ No newline at end of file +} diff --git a/src/main/java/shit/zen/utils/rotation/Rotation.java b/src/main/java/shit/zen/utils/rotation/Rotation.java index a161e6e..d9c9ccb 100644 --- a/src/main/java/shit/zen/utils/rotation/Rotation.java +++ b/src/main/java/shit/zen/utils/rotation/Rotation.java @@ -32,20 +32,20 @@ public class Rotation { this.pitch = 0.0f; } - public Rotation(float f, float f2) { - this.yaw = f; - this.pitch = f2; + public Rotation(float yaw, float pitch) { + this.yaw = yaw; + this.pitch = pitch; } - public Rotation(Vector2f vector2f) { - this.yaw = vector2f.getX(); - this.pitch = vector2f.getY(); + public Rotation(Vector2f yawPitch) { + this.yaw = yawPitch.getX(); + this.pitch = yawPitch.getY(); } - public Rotation(Vec3 vec3, Vec3 vec32) { - Vec3 vec33 = vec32.subtract(vec3); - this.yaw = Mth.wrapDegrees((float)Math.toDegrees(Math.atan2(vec33.z, vec33.x)) - 90.0f); - this.pitch = Mth.wrapDegrees((float)(-Math.toDegrees(Math.atan2(vec33.y, Math.sqrt(vec33.x * vec33.x + vec33.z * vec33.z))))); + public Rotation(Vec3 from, Vec3 to) { + Vec3 delta = to.subtract(from); + this.yaw = Mth.wrapDegrees((float)Math.toDegrees(Math.atan2(delta.z, delta.x)) - 90.0f); + this.pitch = Mth.wrapDegrees((float)(-Math.toDegrees(Math.atan2(delta.y, Math.sqrt(delta.x * delta.x + delta.z * delta.z))))); } public Rotation clone() { @@ -64,13 +64,13 @@ public class Rotation { return new Rotation(-this.yaw, -this.pitch); } - public Rotation withTask(Runnable runnable) { - this.task = runnable; + public Rotation withTask(Runnable task) { + this.task = task; return this; } - public Rotation withPostTask(Runnable runnable) { - this.postTask = runnable; + public Rotation withPostTask(Runnable postTask) { + this.postTask = postTask; return this; } @@ -88,119 +88,119 @@ public class Rotation { player.setXRot(this.pitch); } - public Rotation snapToSensitivity(Float f) { - float f2 = f.floatValue() * 0.6f + 0.2f; - float f3 = f2 * f2 * f2 * 1.2f; - this.yaw -= this.yaw % f3; - this.pitch -= this.pitch % f3; + public Rotation snapToSensitivity(Float sensitivity) { + float scaled = sensitivity.floatValue() * 0.6f + 0.2f; + float step = scaled * scaled * scaled * 1.2f; + this.yaw -= this.yaw % step; + this.pitch -= this.pitch % step; return this; } - public static float moveTowards(float f, float f2, float f3) { - float f4 = Mth.wrapDegrees(f2 - f); - if (f4 > f3) { - f4 = f3; + public static float moveTowards(float current, float target, float maxStep) { + float diff = Mth.wrapDegrees(target - current); + if (diff > maxStep) { + diff = maxStep; } - if (f4 < -f3) { - f4 = -f3; + if (diff < -maxStep) { + diff = -maxStep; } - return f + f4; + return current + diff; } - public double distanceTo(Rotation rotation) { - float f = Mth.wrapDegrees(this.yaw); - float f2 = Mth.wrapDegrees(rotation.yaw); - float f3 = Mth.wrapDegrees(f - f2); - float f4 = Mth.wrapDegrees(this.pitch); - float f5 = Mth.wrapDegrees(rotation.pitch); - float f6 = Mth.wrapDegrees(f4 - f5); - return Math.sqrt(f3 * f3 + f6 * f6); + public double distanceTo(Rotation other) { + float thisYaw = Mth.wrapDegrees(this.yaw); + float otherYaw = Mth.wrapDegrees(other.yaw); + float yawDiff = Mth.wrapDegrees(thisYaw - otherYaw); + float thisPitch = Mth.wrapDegrees(this.pitch); + float otherPitch = Mth.wrapDegrees(other.pitch); + float pitchDiff = Mth.wrapDegrees(thisPitch - otherPitch); + return Math.sqrt(yawDiff * yawDiff + pitchDiff * pitchDiff); } - public float smoothYaw(float f, float f2, float f3) { - float f4 = Rotation.moveTowards(f2, f3, f + RandomUtils.nextFloat(0.0f, 15.0f)); - double d = Mth.wrapDegrees(f3 - f2); - if ((double)(-f) > d || d > (double)f) { + public float smoothYaw(float speed, float current, float target) { + float stepped = Rotation.moveTowards(current, target, speed + RandomUtils.nextFloat(0.0f, 15.0f)); + double diff = Mth.wrapDegrees(target - current); + if ((double)(-speed) > diff || diff > (double)speed) { if (!Đ && ClientBase.mc.player == null) { throw new AssertionError(); } - f4 += (float)((double)RandomUtils.nextFloat(1.0f, 2.0f) * Math.sin((double)ClientBase.mc.player.getXRot() * Math.PI)); + stepped += (float)((double)RandomUtils.nextFloat(1.0f, 2.0f) * Math.sin((double)ClientBase.mc.player.getXRot() * Math.PI)); } - if (f4 == f2) { - return f2; + if (stepped == current) { + return current; } - float f5 = ClientBase.mc.options.sensitivity().get().floatValue(); - if ((double)f5 == 0.5) { - f5 = 0.47887325f; + float sensitivity = ClientBase.mc.options.sensitivity().get().floatValue(); + if ((double)sensitivity == 0.5) { + sensitivity = 0.47887325f; } - float f6 = f5 * 0.6f + 0.2f; - float f7 = f6 * f6 * f6 * 8.0f; - int n = (int)((6.667 * (double)f4 - 6.666666666666667 * (double)f2) / (double)f7); - float f8 = (float)n * f7; - f4 = (float)((double)f2 + (double)f8 * 0.15); - return f4; + float scaled = sensitivity * 0.6f + 0.2f; + float gcd = scaled * scaled * scaled * 8.0f; + int steps = (int)((6.667 * (double)stepped - 6.666666666666667 * (double)current) / (double)gcd); + float snapped = (float)steps * gcd; + stepped = (float)((double)current + (double)snapped * 0.15); + return stepped; } - public float smoothYawArray(float f, float[] fArray, float f2) { - float f3 = Rotation.moveTowards(fArray[0], f2, f + RandomUtils.nextFloat(0.0f, 15.0f)); - if (f3 != f2) { - f3 += (float)((double)RandomUtils.nextFloat(1.0f, 2.0f) * Math.sin((double)fArray[1] * Math.PI)); + public float smoothYawArray(float speed, float[] currentPair, float target) { + float stepped = Rotation.moveTowards(currentPair[0], target, speed + RandomUtils.nextFloat(0.0f, 15.0f)); + if (stepped != target) { + stepped += (float)((double)RandomUtils.nextFloat(1.0f, 2.0f) * Math.sin((double)currentPair[1] * Math.PI)); } - if (f3 == fArray[0]) { - return fArray[0]; + if (stepped == currentPair[0]) { + return currentPair[0]; } - float f4 = ClientBase.mc.options.sensitivity().get().floatValue(); - f3 += (float)(ThreadLocalRandom.current().nextGaussian() * 0.2); - if ((double)f4 == 0.5) { - f4 = 0.47887325f; + float sensitivity = ClientBase.mc.options.sensitivity().get().floatValue(); + stepped += (float)(ThreadLocalRandom.current().nextGaussian() * 0.2); + if ((double)sensitivity == 0.5) { + sensitivity = 0.47887325f; } - float f5 = f4 * 0.6f + 0.2f; - float f6 = f5 * f5 * f5 * 8.0f; - int n = (int)((6.667 * (double)f3 - 6.6666667 * (double)fArray[0]) / (double)f6); - float f7 = (float)n * f6; - f3 = (float)((double)fArray[0] + (double)f7 * 0.15); - return f3; + float scaled = sensitivity * 0.6f + 0.2f; + float gcd = scaled * scaled * scaled * 8.0f; + int steps = (int)((6.667 * (double)stepped - 6.6666667 * (double)currentPair[0]) / (double)gcd); + float snapped = (float)steps * gcd; + stepped = (float)((double)currentPair[0] + (double)snapped * 0.15); + return stepped; } - public float smoothPitch(float f, float f2, float f3) { - float f4; - float f5 = Rotation.moveTowards(f2, f3, f + RandomUtils.nextFloat(0.0f, 15.0f)); - if (f5 != f3) { - f5 += (float)((double)RandomUtils.nextFloat(1.0f, 2.0f) * Math.sin((double)ClientBase.mc.player.getYRot() * Math.PI)); + public float smoothPitch(float speed, float current, float target) { + float sensitivity; + float stepped = Rotation.moveTowards(current, target, speed + RandomUtils.nextFloat(0.0f, 15.0f)); + if (stepped != target) { + stepped += (float)((double)RandomUtils.nextFloat(1.0f, 2.0f) * Math.sin((double)ClientBase.mc.player.getYRot() * Math.PI)); } - if ((double)(f4 = ClientBase.mc.options.sensitivity().get().floatValue()) == 0.5) { - f4 = 0.47887325f; + if ((double)(sensitivity = ClientBase.mc.options.sensitivity().get().floatValue()) == 0.5) { + sensitivity = 0.47887325f; } - float f6 = f4 * 0.6f + 0.2f; - float f7 = f6 * f6 * f6 * 8.0f; - int n = (int)((6.667 * (double)f5 - 6.666667 * (double)f2) / (double)f7) * -1; - float f8 = (float)n * f7; - float f9 = (float)((double)f2 - (double)f8 * 0.15); - f5 = Mth.clamp(f9, -90.0f, 90.0f); - return f5; + float scaled = sensitivity * 0.6f + 0.2f; + float gcd = scaled * scaled * scaled * 8.0f; + int steps = (int)((6.667 * (double)stepped - 6.666667 * (double)current) / (double)gcd) * -1; + float snapped = (float)steps * gcd; + float result = (float)((double)current - (double)snapped * 0.15); + stepped = Mth.clamp(result, -90.0f, 90.0f); + return stepped; } - public float smoothPitchArray(float f, float[] fArray, float f2) { - float f3; - float f4 = Rotation.moveTowards(fArray[1], f2, f + RandomUtils.nextFloat(0.0f, 15.0f)); - if (f4 != f2) { - f4 += (float)((double)RandomUtils.nextFloat(1.0f, 2.0f) * Math.sin((double)fArray[0] * Math.PI)); + public float smoothPitchArray(float speed, float[] currentPair, float target) { + float sensitivity; + float stepped = Rotation.moveTowards(currentPair[1], target, speed + RandomUtils.nextFloat(0.0f, 15.0f)); + if (stepped != target) { + stepped += (float)((double)RandomUtils.nextFloat(1.0f, 2.0f) * Math.sin((double)currentPair[0] * Math.PI)); } - if ((double)(f3 = ClientBase.mc.options.sensitivity().get().floatValue()) == 0.5) { - f3 = 0.47887325f; + if ((double)(sensitivity = ClientBase.mc.options.sensitivity().get().floatValue()) == 0.5) { + sensitivity = 0.47887325f; } - float f5 = f3 * 0.6f + 0.2f; - float f6 = f5 * f5 * f5 * 8.0f; - int n = (int)((6.667 * (double)f4 - 6.666667 * (double)fArray[1]) / (double)f6) * -1; - float f7 = (float)n * f6; - float f8 = (float)((double)fArray[1] - (double)f7 * 0.15); - f4 = Mth.clamp(f8, -90.0f, 90.0f); - return f4; + float scaled = sensitivity * 0.6f + 0.2f; + float gcd = scaled * scaled * scaled * 8.0f; + int steps = (int)((6.667 * (double)stepped - 6.666667 * (double)currentPair[1]) / (double)gcd) * -1; + float snapped = (float)steps * gcd; + float result = (float)((double)currentPair[1] - (double)snapped * 0.15); + stepped = Mth.clamp(result, -90.0f, 90.0f); + return stepped; } - public void setYawPitch(float f, float f2) { - this.yaw = f; - this.pitch = f2; + public void setYawPitch(float yaw, float pitch) { + this.yaw = yaw; + this.pitch = pitch; } } \ No newline at end of file