From 2629536ad7e3417dd85ae61ee2f8531d7072484a Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Sat, 21 Sep 2024 20:18:55 -0400 Subject: [PATCH 01/15] Optimize getPossibleEyeHeights() --- .../java/ac/grim/grimac/player/GrimPlayer.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/ac/grim/grimac/player/GrimPlayer.java b/src/main/java/ac/grim/grimac/player/GrimPlayer.java index 106110eed1..f961fff3bb 100644 --- a/src/main/java/ac/grim/grimac/player/GrimPlayer.java +++ b/src/main/java/ac/grim/grimac/player/GrimPlayer.java @@ -554,14 +554,14 @@ public CompensatedInventory getInventory() { return checkManager.getInventory(); } - public List getPossibleEyeHeights() { // We don't return sleeping eye height - if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) { // Elytra, sneaking (1.14), standing + public double[] getPossibleEyeHeights() { // We don't return sleeping eye height + if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) { // standing, sneaking (1.14), Elytra final float scale = (float) compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_SCALE); - return Arrays.asList(0.4 * scale, 1.27 * scale, 1.62 * scale); - } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { // Elytra, sneaking, standing - return Arrays.asList(0.4, 1.54, 1.62); - } else { // Only sneaking or standing - return Arrays.asList((double) (1.62f - 0.08f), (double) (1.62f)); + return new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; + } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { // standing, sneaking Elytra + return new double[]{1.62, 1.54, 0.4}; + } else { // Only standing or sneaking + return new double[]{(double) (1.62f), (double) (1.62f - 0.08f)}; } } From 290bf9032e6d73e5eeeaac05e5951b511572aacb Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Sat, 21 Sep 2024 20:28:21 -0400 Subject: [PATCH 02/15] Backport patch --- .../ac/grim/grimac/checks/impl/combat/Reach.java | 3 ++- .../grimac/checks/impl/scaffolding/FarPlace.java | 3 ++- .../checks/impl/scaffolding/PositionPlace.java | 9 +++++++-- .../checks/impl/scaffolding/RotationPlace.java | 12 +++++++++--- .../ac/grim/grimac/utils/nmsutil/ReachUtils.java | 3 ++- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java b/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java index 2876d3664d..5c75b5cf06 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java +++ b/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java @@ -201,8 +201,9 @@ private String checkReach(PacketEntity reachEntity, Vector3d from, boolean isPre // +3 would be 3 + 3 = 6, which is the pre-1.20.5 behaviour, preventing "Missed Hitbox" final double distance = player.compensatedEntities.getSelf().getAttributeValue(Attributes.PLAYER_ENTITY_INTERACTION_RANGE) + 3; + double[] possibleEyeHeights = player.getPossibleEyeHeights(); for (Vector lookVec : possibleLookDirs) { - for (double eye : player.getPossibleEyeHeights()) { + for (double eye : possibleEyeHeights) { Vector eyePos = new Vector(from.getX(), from.getY() + eye, from.getZ()); Vector endReachPos = eyePos.clone().add(new Vector(lookVec.getX() * distance, lookVec.getY() * distance, lookVec.getZ() * distance)); diff --git a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/FarPlace.java b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/FarPlace.java index fb9b6a94d5..30d985a1c6 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/FarPlace.java +++ b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/FarPlace.java @@ -26,7 +26,8 @@ public void onBlockPlace(final BlockPlace place) { if (place.getMaterial() == StateTypes.SCAFFOLDING) return; double min = Double.MAX_VALUE; - for (double d : player.getPossibleEyeHeights()) { + double[] possibleEyeHeights = player.getPossibleEyeHeights(); + for (double d : possibleEyeHeights) { SimpleCollisionBox box = new SimpleCollisionBox(blockPos); Vector eyes = new Vector(player.x, player.y + d, player.z); Vector best = VectorUtils.cutBoxToVector(eyes, box); diff --git a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java index 3b20196c04..2dec8c7fcb 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java +++ b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java @@ -28,8 +28,13 @@ public void onBlockPlace(final BlockPlace place) { // Each position represents the best case scenario to have clicked // // We will now calculate the most optimal position for the player's head to be in - double minEyeHeight = Collections.min(player.getPossibleEyeHeights()); - double maxEyeHeight = Collections.max(player.getPossibleEyeHeights()); + double[] possibleEyeHeights = player.getPossibleEyeHeights(); + double minEyeHeight = Double.MAX_VALUE; + double maxEyeHeight = Double.MIN_VALUE; + for (double height : possibleEyeHeights) { + minEyeHeight = Math.min(minEyeHeight, height); + maxEyeHeight = Math.max(maxEyeHeight, height); + } // I love the idle packet, why did you remove it mojang :( // Don't give 0.03 lenience if the player is a 1.8 player and we know they couldn't have 0.03'd because idle packet double movementThreshold = !player.packetStateData.didLastMovementIncludePosition || player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9) ? player.getMovementThreshold() : 0; diff --git a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java index e1081c4d9e..3c7ca7dfad 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java +++ b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java @@ -75,9 +75,15 @@ private boolean didRayTraceHit(BlockPlace place) { new Vector3f(player.xRot, player.yRot, 0) )); + double[] possibleEyeHeights = player.getPossibleEyeHeights(); + // Start checking if player is in the block - double minEyeHeight = Collections.min(player.getPossibleEyeHeights()); - double maxEyeHeight = Collections.max(player.getPossibleEyeHeights()); + double minEyeHeight = Double.MAX_VALUE; + double maxEyeHeight = Double.MIN_VALUE; + for (double height : possibleEyeHeights) { + minEyeHeight = Math.min(minEyeHeight, height); + maxEyeHeight = Math.max(maxEyeHeight, height); + } SimpleCollisionBox eyePositions = new SimpleCollisionBox(player.x, player.y + minEyeHeight, player.z, player.x, player.y + maxEyeHeight, player.z); eyePositions.expand(player.getMovementThreshold()); @@ -99,7 +105,7 @@ private boolean didRayTraceHit(BlockPlace place) { } final double distance = player.compensatedEntities.getSelf().getAttributeValue(Attributes.PLAYER_BLOCK_INTERACTION_RANGE); - for (double d : player.getPossibleEyeHeights()) { + for (double d : possibleEyeHeights) { for (Vector3f lookDir : possibleLookDirs) { // x, y, z are correct for the block placement even after post tick because of code elsewhere Vector3d starting = new Vector3d(player.x, player.y + d, player.z); diff --git a/src/main/java/ac/grim/grimac/utils/nmsutil/ReachUtils.java b/src/main/java/ac/grim/grimac/utils/nmsutil/ReachUtils.java index 44f38f555f..1a38f35257 100644 --- a/src/main/java/ac/grim/grimac/utils/nmsutil/ReachUtils.java +++ b/src/main/java/ac/grim/grimac/utils/nmsutil/ReachUtils.java @@ -181,7 +181,8 @@ public static double getMinReachToBox(GrimPlayer player, SimpleCollisionBox targ double lowest = Double.MAX_VALUE; - for (double eyes : player.getPossibleEyeHeights()) { + double[] possibleEyeHeights = player.getPossibleEyeHeights(); + for (double eyes : possibleEyeHeights) { if (giveMovementThresholdLenience) targetBox.expand(player.getMovementThreshold()); Vector from = new Vector(player.x, player.y + eyes, player.z); Vector closestPoint = VectorUtils.cutBoxToVector(from, targetBox); From bff68541896107461a1a1d74c0a3245e723dbca4 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Sun, 22 Sep 2024 17:17:25 -0400 Subject: [PATCH 03/15] make getPossibleEyeHeights return most likely heights --- .../ac/grim/grimac/player/GrimPlayer.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/ac/grim/grimac/player/GrimPlayer.java b/src/main/java/ac/grim/grimac/player/GrimPlayer.java index f961fff3bb..64211e8b3c 100644 --- a/src/main/java/ac/grim/grimac/player/GrimPlayer.java +++ b/src/main/java/ac/grim/grimac/player/GrimPlayer.java @@ -555,13 +555,29 @@ public CompensatedInventory getInventory() { } public double[] getPossibleEyeHeights() { // We don't return sleeping eye height - if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) { // standing, sneaking (1.14), Elytra + if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) { final float scale = (float) compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_SCALE); - return new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; + if (this.isGliding || this.isSwimming) { + return new double[]{0.4 * scale, 1.62 * scale, 1.27 * scale}; // Elytra, standing, sneaking (1.14) + } else if (this.isSneaking) { + return new double[]{1.27 * scale, 1.62 * scale, 0.4 * scale}; // sneaking (1.14), standing, Elytra + } else { + return new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; // standing, sneaking (1.14), Elytra + } } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { // standing, sneaking Elytra - return new double[]{1.62, 1.54, 0.4}; + if (this.isGliding || this.isSwimming) { + return new double[]{0.4, 1.62, 1.54}; // Elytra, standing, sneaking (1.14) + } else if (this.isSneaking) { + return new double[]{1.54, 1.62, 0.4}; // sneaking (1.14), standing, Elytra + } else { + return new double[]{1.62, 1.54, 0.4}; // standing, sneaking (1.14), Elytra + } } else { // Only standing or sneaking - return new double[]{(double) (1.62f), (double) (1.62f - 0.08f)}; + if (this.isSneaking) { + return new double[]{(double) (1.62f - 0.08f), (double) (1.62f)}; + } else { + return new double[]{(double) (1.62f), (double) (1.62f - 0.08f)}; + } } } From 927b330c4b6c8a70789675563a1dfaecff2aaf97 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Sun, 22 Sep 2024 17:30:02 -0400 Subject: [PATCH 04/15] Cache eyeHeights where possible --- .../ac/grim/grimac/player/GrimPlayer.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/ac/grim/grimac/player/GrimPlayer.java b/src/main/java/ac/grim/grimac/player/GrimPlayer.java index 64211e8b3c..1ff8057707 100644 --- a/src/main/java/ac/grim/grimac/player/GrimPlayer.java +++ b/src/main/java/ac/grim/grimac/player/GrimPlayer.java @@ -199,6 +199,8 @@ public class GrimPlayer implements GrimUser { public long lastBlockPlaceUseItem = 0; public AtomicInteger cancelledPackets = new AtomicInteger(0); public MainSupportingBlockData mainSupportingBlockData = new MainSupportingBlockData(null, false); + // possibleEyeHeights[0] = Standing eye heights, [1] = Sneaking. [2] = Elytra and only exists in 1.9+ + public double[][] possibleEyeHeights = new double[3][]; public void onPacketCancel() { if (spamThreshold != -1 && cancelledPackets.incrementAndGet() > spamThreshold) { @@ -240,6 +242,24 @@ public GrimPlayer(User user) { packetStateData = new PacketStateData(); uncertaintyHandler.collidingEntities.add(0); + + if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) { + // Todo figure out how to deal with scale changing + } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { // standing, sneaking Elytra + if (this.isGliding || this.isSwimming) { + possibleEyeHeights[2] = new double[]{0.4, 1.62, 1.54}; // Elytra, standing, sneaking (1.14) + } else if (this.isSneaking) { + possibleEyeHeights[1] = new double[]{1.54, 1.62, 0.4}; // sneaking (1.14), standing, Elytra + } else { + possibleEyeHeights[0] = new double[]{1.62, 1.54, 0.4}; // standing, sneaking (1.14), Elytra + } + } else { // Only standing or sneaking + if (this.isSneaking) { + possibleEyeHeights[1] = new double[]{(double) (1.62f - 0.08f), (double) (1.62f)}; + } else { + possibleEyeHeights[0] = new double[]{(double) (1.62f), (double) (1.62f - 0.08f)}; + } + } } public Set getPossibleVelocities() { @@ -564,21 +584,16 @@ public double[] getPossibleEyeHeights() { // We don't return sleeping eye height } else { return new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; // standing, sneaking (1.14), Elytra } - } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { // standing, sneaking Elytra + } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { if (this.isGliding || this.isSwimming) { - return new double[]{0.4, 1.62, 1.54}; // Elytra, standing, sneaking (1.14) - } else if (this.isSneaking) { - return new double[]{1.54, 1.62, 0.4}; // sneaking (1.14), standing, Elytra - } else { - return new double[]{1.62, 1.54, 0.4}; // standing, sneaking (1.14), Elytra - } - } else { // Only standing or sneaking - if (this.isSneaking) { - return new double[]{(double) (1.62f - 0.08f), (double) (1.62f)}; - } else { - return new double[]{(double) (1.62f), (double) (1.62f - 0.08f)}; + return possibleEyeHeights[2]; // Elytra } } + if (this.isSneaking) { + return possibleEyeHeights[1]; + } else { + return possibleEyeHeights[0]; + } } @Override From 619e7f1404c0d064e4565e3b0b8432e74fafd937 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:19:05 -0400 Subject: [PATCH 05/15] Simplify logic and handle caching even when scale changes --- .../ac/grim/grimac/player/GrimPlayer.java | 30 +++++++------------ .../utils/data/packetentity/PacketEntity.java | 26 +++++++++++++++- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/main/java/ac/grim/grimac/player/GrimPlayer.java b/src/main/java/ac/grim/grimac/player/GrimPlayer.java index 1ff8057707..da7941edd7 100644 --- a/src/main/java/ac/grim/grimac/player/GrimPlayer.java +++ b/src/main/java/ac/grim/grimac/player/GrimPlayer.java @@ -244,7 +244,14 @@ public GrimPlayer(User user) { uncertaintyHandler.collidingEntities.add(0); if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) { - // Todo figure out how to deal with scale changing + final float scale = (float) compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_SCALE); + if (this.isGliding || this.isSwimming) { + possibleEyeHeights[2] = new double[]{0.4 * scale, 1.62 * scale, 1.27 * scale}; // Elytra, standing, sneaking (1.14) + } else if (this.isSneaking) { + possibleEyeHeights[1] = new double[]{1.27 * scale, 1.62 * scale, 0.4 * scale}; // sneaking (1.14), standing, Elytra + } else { + possibleEyeHeights[0] = new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; // standing, sneaking (1.14), Elytra + } } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { // standing, sneaking Elytra if (this.isGliding || this.isSwimming) { possibleEyeHeights[2] = new double[]{0.4, 1.62, 1.54}; // Elytra, standing, sneaking (1.14) @@ -575,25 +582,10 @@ public CompensatedInventory getInventory() { } public double[] getPossibleEyeHeights() { // We don't return sleeping eye height - if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) { - final float scale = (float) compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_SCALE); - if (this.isGliding || this.isSwimming) { - return new double[]{0.4 * scale, 1.62 * scale, 1.27 * scale}; // Elytra, standing, sneaking (1.14) - } else if (this.isSneaking) { - return new double[]{1.27 * scale, 1.62 * scale, 0.4 * scale}; // sneaking (1.14), standing, Elytra - } else { - return new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; // standing, sneaking (1.14), Elytra - } - } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { - if (this.isGliding || this.isSwimming) { - return possibleEyeHeights[2]; // Elytra - } - } - if (this.isSneaking) { - return possibleEyeHeights[1]; - } else { - return possibleEyeHeights[0]; + if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9) && this.isGliding || this.isSwimming) { + return possibleEyeHeights[2]; } + return this.isSneaking ? possibleEyeHeights[1] : possibleEyeHeights[0]; } @Override diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java index 893771b099..30f39bde25 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java @@ -21,6 +21,8 @@ import ac.grim.grimac.utils.data.TrackedPosition; import ac.grim.grimac.utils.data.attribute.ValuedAttribute; import ac.grim.grimac.utils.nmsutil.GetBoundingBox; +import com.github.retrooper.packetevents.PacketEvents; +import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.attribute.Attribute; import com.github.retrooper.packetevents.protocol.attribute.Attributes; import com.github.retrooper.packetevents.protocol.entity.type.EntityType; @@ -86,7 +88,29 @@ protected void trackAttribute(ValuedAttribute valuedAttribute) { protected void initAttributes(GrimPlayer player) { trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_SCALE, 1.0, 0.0625, 16) - .requiredVersion(player, ClientVersion.V_1_20_5)); + .withSetRewriter((oldValue, newValue) -> { + // Required Version is 1.20.5 but getPossibleEyeHeights start referencing scale in 1.14+ + // What's actually going on? Does this work, if it does how? + if (player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5)) { + return oldValue; + } + // Elytra, standing, sneaking (1.14) + player.possibleEyeHeights[2][0] = 0.4 * newValue; + player.possibleEyeHeights[2][1] = 1.62 * newValue; + player.possibleEyeHeights[2][2] = 1.27 * newValue; + + // sneaking (1.14), standing, Elytra + player.possibleEyeHeights[1][0] = 1.27 * newValue; + player.possibleEyeHeights[1][1] = 1.62 * newValue; + player.possibleEyeHeights[1][2] = 0.4 * newValue; + + // standing, sneaking (1.14), Elytra + player.possibleEyeHeights[0][0] = 1.62 * newValue; + player.possibleEyeHeights[0][1] = 1.27 * newValue; + player.possibleEyeHeights[0][2] = 0.4 * newValue; + return newValue; + }) + ); trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_STEP_HEIGHT, 0.6f, 0, 10) .requiredVersion(player, ClientVersion.V_1_20_5)); trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_GRAVITY, 0.08, -1, 1) From c34ad88a135cb662bf76cbf6ddc723d0b3488a65 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:34:50 -0400 Subject: [PATCH 06/15] Fix intializing array --- .../ac/grim/grimac/player/GrimPlayer.java | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/main/java/ac/grim/grimac/player/GrimPlayer.java b/src/main/java/ac/grim/grimac/player/GrimPlayer.java index da7941edd7..8c2bc4119e 100644 --- a/src/main/java/ac/grim/grimac/player/GrimPlayer.java +++ b/src/main/java/ac/grim/grimac/player/GrimPlayer.java @@ -245,27 +245,17 @@ public GrimPlayer(User user) { if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) { final float scale = (float) compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_SCALE); - if (this.isGliding || this.isSwimming) { - possibleEyeHeights[2] = new double[]{0.4 * scale, 1.62 * scale, 1.27 * scale}; // Elytra, standing, sneaking (1.14) - } else if (this.isSneaking) { - possibleEyeHeights[1] = new double[]{1.27 * scale, 1.62 * scale, 0.4 * scale}; // sneaking (1.14), standing, Elytra - } else { - possibleEyeHeights[0] = new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; // standing, sneaking (1.14), Elytra - } + possibleEyeHeights[2] = new double[]{0.4 * scale, 1.62 * scale, 1.27 * scale}; // Elytra, standing, sneaking (1.14) + possibleEyeHeights[1] = new double[]{1.27 * scale, 1.62 * scale, 0.4 * scale}; // sneaking (1.14), standing, Elytra + possibleEyeHeights[0] = new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; // standing, sneaking (1.14), Elytragit status + } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { // standing, sneaking Elytra - if (this.isGliding || this.isSwimming) { - possibleEyeHeights[2] = new double[]{0.4, 1.62, 1.54}; // Elytra, standing, sneaking (1.14) - } else if (this.isSneaking) { - possibleEyeHeights[1] = new double[]{1.54, 1.62, 0.4}; // sneaking (1.14), standing, Elytra - } else { - possibleEyeHeights[0] = new double[]{1.62, 1.54, 0.4}; // standing, sneaking (1.14), Elytra - } + possibleEyeHeights[2] = new double[]{0.4, 1.62, 1.54}; // Elytra, standing, sneaking (1.14) + possibleEyeHeights[1] = new double[]{1.54, 1.62, 0.4}; // sneaking (1.14), standing, Elytra + possibleEyeHeights[0] = new double[]{1.62, 1.54, 0.4}; // standing, sneaking (1.14), Elytra } else { // Only standing or sneaking - if (this.isSneaking) { - possibleEyeHeights[1] = new double[]{(double) (1.62f - 0.08f), (double) (1.62f)}; - } else { - possibleEyeHeights[0] = new double[]{(double) (1.62f), (double) (1.62f - 0.08f)}; - } + possibleEyeHeights[1] = new double[]{(double) (1.62f - 0.08f), (double) (1.62f)}; + possibleEyeHeights[0] = new double[]{(double) (1.62f), (double) (1.62f - 0.08f)}; } } @@ -582,7 +572,7 @@ public CompensatedInventory getInventory() { } public double[] getPossibleEyeHeights() { // We don't return sleeping eye height - if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9) && this.isGliding || this.isSwimming) { + if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9) && this.isGliding || this.isSwimming || this.isRiptidePose) { return possibleEyeHeights[2]; } return this.isSneaking ? possibleEyeHeights[1] : possibleEyeHeights[0]; From 1beedd77c3651e8670b965503b2674b9d71072cb Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:14:30 -0400 Subject: [PATCH 07/15] Don't bother updating scale attribute if no change is made --- .../ac/grim/grimac/utils/data/packetentity/PacketEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java index 30f39bde25..18d8067b1c 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java @@ -91,7 +91,7 @@ protected void initAttributes(GrimPlayer player) { .withSetRewriter((oldValue, newValue) -> { // Required Version is 1.20.5 but getPossibleEyeHeights start referencing scale in 1.14+ // What's actually going on? Does this work, if it does how? - if (player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5)) { + if (player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5) || oldValue != newValue) { return oldValue; } // Elytra, standing, sneaking (1.14) From bf44dd685555c4d5378cf104e322d37ce5fc2498 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:03:10 -0400 Subject: [PATCH 08/15] Only rewrite player possibleEyeHeights when player scale changes --- .../utils/data/packetentity/PacketEntity.java | 24 +------------------ .../data/packetentity/PacketEntitySelf.java | 22 +++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java index 18d8067b1c..d98860eb3f 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java @@ -88,29 +88,7 @@ protected void trackAttribute(ValuedAttribute valuedAttribute) { protected void initAttributes(GrimPlayer player) { trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_SCALE, 1.0, 0.0625, 16) - .withSetRewriter((oldValue, newValue) -> { - // Required Version is 1.20.5 but getPossibleEyeHeights start referencing scale in 1.14+ - // What's actually going on? Does this work, if it does how? - if (player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5) || oldValue != newValue) { - return oldValue; - } - // Elytra, standing, sneaking (1.14) - player.possibleEyeHeights[2][0] = 0.4 * newValue; - player.possibleEyeHeights[2][1] = 1.62 * newValue; - player.possibleEyeHeights[2][2] = 1.27 * newValue; - - // sneaking (1.14), standing, Elytra - player.possibleEyeHeights[1][0] = 1.27 * newValue; - player.possibleEyeHeights[1][1] = 1.62 * newValue; - player.possibleEyeHeights[1][2] = 0.4 * newValue; - - // standing, sneaking (1.14), Elytra - player.possibleEyeHeights[0][0] = 1.62 * newValue; - player.possibleEyeHeights[0][1] = 1.27 * newValue; - player.possibleEyeHeights[0][2] = 0.4 * newValue; - return newValue; - }) - ); + .requiredVersion(player, ClientVersion.V_1_20_5)); trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_STEP_HEIGHT, 0.6f, 0, 10) .requiredVersion(player, ClientVersion.V_1_20_5)); trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_GRAVITY, 0.08, -1, 1) diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java index f636286fdc..e7920822e9 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java @@ -46,6 +46,28 @@ protected void initAttributes(GrimPlayer player) { if (player.getClientVersion().isOlderThan(ClientVersion.V_1_8)) { setAttribute(Attributes.GENERIC_STEP_HEIGHT, 0.5f); } + getAttribute(Attributes.GENERIC_SCALE).get().withSetRewriter((oldValue, newValue) -> { + // Required Version is 1.20.5 but getPossibleEyeHeights start referencing scale in 1.14+ + // What's actually going on? Does this work, if it does how? + if (player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5) || oldValue != newValue) { + return oldValue; + } + // Elytra, standing, sneaking (1.14) + player.possibleEyeHeights[2][0] = 0.4 * newValue; + player.possibleEyeHeights[2][1] = 1.62 * newValue; + player.possibleEyeHeights[2][2] = 1.27 * newValue; + + // sneaking (1.14), standing, Elytra + player.possibleEyeHeights[1][0] = 1.27 * newValue; + player.possibleEyeHeights[1][1] = 1.62 * newValue; + player.possibleEyeHeights[1][2] = 0.4 * newValue; + + // standing, sneaking (1.14), Elytra + player.possibleEyeHeights[0][0] = 1.62 * newValue; + player.possibleEyeHeights[0][1] = 1.27 * newValue; + player.possibleEyeHeights[0][2] = 0.4 * newValue; + return newValue; + }); final ValuedAttribute movementSpeed = ValuedAttribute.ranged(Attributes.GENERIC_MOVEMENT_SPEED, 0.1f, 0, 1024); movementSpeed.with(new WrapperPlayServerUpdateAttributes.Property("MOVEMENT_SPEED", 0.1f, new ArrayList<>())); From f62d8602b8433d955111253307cd600a454a6b13 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:22:22 -0400 Subject: [PATCH 09/15] fix conditionall check --- .../grim/grimac/utils/data/packetentity/PacketEntitySelf.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java index e7920822e9..21730c02d8 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java @@ -49,7 +49,7 @@ protected void initAttributes(GrimPlayer player) { getAttribute(Attributes.GENERIC_SCALE).get().withSetRewriter((oldValue, newValue) -> { // Required Version is 1.20.5 but getPossibleEyeHeights start referencing scale in 1.14+ // What's actually going on? Does this work, if it does how? - if (player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5) || oldValue != newValue) { + if (oldValue.equals(newValue) || player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5)) { return oldValue; } // Elytra, standing, sneaking (1.14) From e959ef37dbb8ba1b0df2386296c5bdaf9d16321a Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Wed, 25 Sep 2024 00:01:09 -0400 Subject: [PATCH 10/15] Optimize returned array for crawling --- .../java/ac/grim/grimac/player/GrimPlayer.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/ac/grim/grimac/player/GrimPlayer.java b/src/main/java/ac/grim/grimac/player/GrimPlayer.java index 8c2bc4119e..22ea198aa7 100644 --- a/src/main/java/ac/grim/grimac/player/GrimPlayer.java +++ b/src/main/java/ac/grim/grimac/player/GrimPlayer.java @@ -199,7 +199,7 @@ public class GrimPlayer implements GrimUser { public long lastBlockPlaceUseItem = 0; public AtomicInteger cancelledPackets = new AtomicInteger(0); public MainSupportingBlockData mainSupportingBlockData = new MainSupportingBlockData(null, false); - // possibleEyeHeights[0] = Standing eye heights, [1] = Sneaking. [2] = Elytra and only exists in 1.9+ + // possibleEyeHeights[0] = Standing eye heights, [1] = Sneaking. [2] = Elytra, Swimming, and Riptide Trident; only exists in 1.9+ public double[][] possibleEyeHeights = new double[3][]; public void onPacketCancel() { @@ -572,10 +572,16 @@ public CompensatedInventory getInventory() { } public double[] getPossibleEyeHeights() { // We don't return sleeping eye height - if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9) && this.isGliding || this.isSwimming || this.isRiptidePose) { - return possibleEyeHeights[2]; + switch (pose) { + case SWIMMING: // Swimming (includes crawling in 1.14+) + case FALL_FLYING: // Elytra gliding + case SPIN_ATTACK: // Riptide trident + return this.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9) ? possibleEyeHeights[2] : this.isSneaking ? possibleEyeHeights[1] : possibleEyeHeights[0]; + case CROUCHING: + return possibleEyeHeights[1]; + default: + return possibleEyeHeights[0]; } - return this.isSneaking ? possibleEyeHeights[1] : possibleEyeHeights[0]; } @Override From ee6183db900e3d9a4d2e06f802c9d2e21975ce36 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Wed, 25 Sep 2024 00:01:52 -0400 Subject: [PATCH 11/15] Handle player joining on new version -> scale changing -> old version --- .../grimac/utils/data/attribute/ValuedAttribute.java | 2 ++ .../grimac/utils/data/packetentity/PacketEntitySelf.java | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java b/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java index d83882aa53..bd28924a88 100644 --- a/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java +++ b/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java @@ -5,6 +5,7 @@ import com.github.retrooper.packetevents.protocol.attribute.Attribute; import com.github.retrooper.packetevents.protocol.player.ClientVersion; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAttributes; +import lombok.Getter; import java.util.List; import java.util.Optional; @@ -23,6 +24,7 @@ public final class ValuedAttribute { private final double min, max; private WrapperPlayServerUpdateAttributes.Property lastProperty; + @Getter private final double defaultValue; private double value; diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java index 21730c02d8..0108b0890c 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java @@ -46,10 +46,13 @@ protected void initAttributes(GrimPlayer player) { if (player.getClientVersion().isOlderThan(ClientVersion.V_1_8)) { setAttribute(Attributes.GENERIC_STEP_HEIGHT, 0.5f); } + getAttribute(Attributes.GENERIC_SCALE).get().withSetRewriter((oldValue, newValue) -> { - // Required Version is 1.20.5 but getPossibleEyeHeights start referencing scale in 1.14+ - // What's actually going on? Does this work, if it does how? - if (oldValue.equals(newValue) || player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5)) { + if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_20_5)) { + // Handles case where player joins on new version, changes scale + // And then rejoins on old version + return getAttribute(Attributes.GENERIC_SCALE).get().getDefaultValue(); + } else if ((newValue).equals(oldValue)) { return oldValue; } // Elytra, standing, sneaking (1.14) From f724d6d78e13ffcf05c80b2cae5647df4094388c Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Wed, 25 Sep 2024 00:28:59 -0400 Subject: [PATCH 12/15] 1.8 Players --- .../ac/grim/grimac/player/GrimPlayer.java | 25 +++++++++------ .../data/packetentity/PacketEntitySelf.java | 31 ++++++++++--------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/main/java/ac/grim/grimac/player/GrimPlayer.java b/src/main/java/ac/grim/grimac/player/GrimPlayer.java index 22ea198aa7..81b83de3e1 100644 --- a/src/main/java/ac/grim/grimac/player/GrimPlayer.java +++ b/src/main/java/ac/grim/grimac/player/GrimPlayer.java @@ -572,15 +572,22 @@ public CompensatedInventory getInventory() { } public double[] getPossibleEyeHeights() { // We don't return sleeping eye height - switch (pose) { - case SWIMMING: // Swimming (includes crawling in 1.14+) - case FALL_FLYING: // Elytra gliding - case SPIN_ATTACK: // Riptide trident - return this.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9) ? possibleEyeHeights[2] : this.isSneaking ? possibleEyeHeights[1] : possibleEyeHeights[0]; - case CROUCHING: - return possibleEyeHeights[1]; - default: - return possibleEyeHeights[0]; + // 1.8 Players once again ruin my clean switch-case + if (this.getClientVersion().isOlderThan(ClientVersion.V_1_9)) { + return this.isSneaking ? this.possibleEyeHeights[1] : this.possibleEyeHeights[0]; + } else { + // 1.8 players just have their pose set to standing all the time + switch (pose) { + case FALL_FLYING: // Elytra gliding + case SPIN_ATTACK: // Riptide trident + case SWIMMING: // Swimming (includes crawling in 1.14+) + return this.possibleEyeHeights[2]; + case NINE_CROUCHING: + case CROUCHING: + return this.possibleEyeHeights[1]; + default: + return this.possibleEyeHeights[0]; + } } } diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java index 0108b0890c..2c9c621f59 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java @@ -54,22 +54,23 @@ protected void initAttributes(GrimPlayer player) { return getAttribute(Attributes.GENERIC_SCALE).get().getDefaultValue(); } else if ((newValue).equals(oldValue)) { return oldValue; + } else { + // Elytra, standing, sneaking (1.14) + player.possibleEyeHeights[2][0] = 0.4 * newValue; + player.possibleEyeHeights[2][1] = 1.62 * newValue; + player.possibleEyeHeights[2][2] = 1.27 * newValue; + + // sneaking (1.14), standing, Elytra + player.possibleEyeHeights[1][0] = 1.27 * newValue; + player.possibleEyeHeights[1][1] = 1.62 * newValue; + player.possibleEyeHeights[1][2] = 0.4 * newValue; + + // standing, sneaking (1.14), Elytra + player.possibleEyeHeights[0][0] = 1.62 * newValue; + player.possibleEyeHeights[0][1] = 1.27 * newValue; + player.possibleEyeHeights[0][2] = 0.4 * newValue; + return newValue; } - // Elytra, standing, sneaking (1.14) - player.possibleEyeHeights[2][0] = 0.4 * newValue; - player.possibleEyeHeights[2][1] = 1.62 * newValue; - player.possibleEyeHeights[2][2] = 1.27 * newValue; - - // sneaking (1.14), standing, Elytra - player.possibleEyeHeights[1][0] = 1.27 * newValue; - player.possibleEyeHeights[1][1] = 1.62 * newValue; - player.possibleEyeHeights[1][2] = 0.4 * newValue; - - // standing, sneaking (1.14), Elytra - player.possibleEyeHeights[0][0] = 1.62 * newValue; - player.possibleEyeHeights[0][1] = 1.27 * newValue; - player.possibleEyeHeights[0][2] = 0.4 * newValue; - return newValue; }); final ValuedAttribute movementSpeed = ValuedAttribute.ranged(Attributes.GENERIC_MOVEMENT_SPEED, 0.1f, 0, 1024); From 01ca8c894e2fa5d9e309405dfb40f8fe9b9b9048 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Wed, 25 Sep 2024 00:51:22 -0400 Subject: [PATCH 13/15] Readability/documentation improvements --- .../ac/grim/grimac/player/GrimPlayer.java | 22 +++++++++---------- .../data/packetentity/PacketEntitySelf.java | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/ac/grim/grimac/player/GrimPlayer.java b/src/main/java/ac/grim/grimac/player/GrimPlayer.java index 81b83de3e1..64b697d425 100644 --- a/src/main/java/ac/grim/grimac/player/GrimPlayer.java +++ b/src/main/java/ac/grim/grimac/player/GrimPlayer.java @@ -199,7 +199,7 @@ public class GrimPlayer implements GrimUser { public long lastBlockPlaceUseItem = 0; public AtomicInteger cancelledPackets = new AtomicInteger(0); public MainSupportingBlockData mainSupportingBlockData = new MainSupportingBlockData(null, false); - // possibleEyeHeights[0] = Standing eye heights, [1] = Sneaking. [2] = Elytra, Swimming, and Riptide Trident; only exists in 1.9+ + // possibleEyeHeights[0] = Standing eye heights, [1] = Sneaking. [2] = Elytra, Swimming, and Riptide Trident which only exists in 1.9+ public double[][] possibleEyeHeights = new double[3][]; public void onPacketCancel() { @@ -247,15 +247,15 @@ public GrimPlayer(User user) { final float scale = (float) compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_SCALE); possibleEyeHeights[2] = new double[]{0.4 * scale, 1.62 * scale, 1.27 * scale}; // Elytra, standing, sneaking (1.14) possibleEyeHeights[1] = new double[]{1.27 * scale, 1.62 * scale, 0.4 * scale}; // sneaking (1.14), standing, Elytra - possibleEyeHeights[0] = new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; // standing, sneaking (1.14), Elytragit status + possibleEyeHeights[0] = new double[]{1.62 * scale, 1.27 * scale, 0.4 * scale}; // standing, sneaking (1.14), Elytra } else if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) { // standing, sneaking Elytra - possibleEyeHeights[2] = new double[]{0.4, 1.62, 1.54}; // Elytra, standing, sneaking (1.14) - possibleEyeHeights[1] = new double[]{1.54, 1.62, 0.4}; // sneaking (1.14), standing, Elytra - possibleEyeHeights[0] = new double[]{1.62, 1.54, 0.4}; // standing, sneaking (1.14), Elytra - } else { // Only standing or sneaking - possibleEyeHeights[1] = new double[]{(double) (1.62f - 0.08f), (double) (1.62f)}; - possibleEyeHeights[0] = new double[]{(double) (1.62f), (double) (1.62f - 0.08f)}; + possibleEyeHeights[2] = new double[]{0.4, 1.62, 1.54}; // Elytra, standing, sneaking (1.13) + possibleEyeHeights[1] = new double[]{1.54, 1.62, 0.4}; // sneaking (1.9-1.13), standing, Elytra + possibleEyeHeights[0] = new double[]{1.62, 1.54, 0.4}; // standing, sneaking (1.9-1.13), Elytra + } else { + possibleEyeHeights[1] = new double[]{(double) (1.62f - 0.08f), (double) (1.62f)}; // sneaking, standing + possibleEyeHeights[0] = new double[]{(double) (1.62f), (double) (1.62f - 0.08f)}; // standing, sneaking } } @@ -581,12 +581,12 @@ public double[] getPossibleEyeHeights() { // We don't return sleeping eye height case FALL_FLYING: // Elytra gliding case SPIN_ATTACK: // Riptide trident case SWIMMING: // Swimming (includes crawling in 1.14+) - return this.possibleEyeHeights[2]; + return this.possibleEyeHeights[2]; // [swimming/gliding/riptide height, standing height, sneaking height] case NINE_CROUCHING: case CROUCHING: - return this.possibleEyeHeights[1]; + return this.possibleEyeHeights[1]; // [sneaking height, standing height, swimming/gliding/riptide height] default: - return this.possibleEyeHeights[0]; + return this.possibleEyeHeights[0]; // [standing height, sneaking height, swimming/gliding/riptide height] } } } diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java index 2c9c621f59..6819643d73 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java @@ -47,11 +47,12 @@ protected void initAttributes(GrimPlayer player) { setAttribute(Attributes.GENERIC_STEP_HEIGHT, 0.5f); } - getAttribute(Attributes.GENERIC_SCALE).get().withSetRewriter((oldValue, newValue) -> { + ValuedAttribute scale = getAttribute(Attributes.GENERIC_SCALE).get(); + scale.withSetRewriter((oldValue, newValue) -> { if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_20_5)) { // Handles case where player joins on new version, changes scale // And then rejoins on old version - return getAttribute(Attributes.GENERIC_SCALE).get().getDefaultValue(); + return scale.getDefaultValue(); } else if ((newValue).equals(oldValue)) { return oldValue; } else { From 472415e0d41547dc3f55a333246a0ebd9830ace9 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Thu, 26 Sep 2024 17:12:07 -0400 Subject: [PATCH 14/15] Removing unneeded special case handling --- .../grimac/utils/data/attribute/ValuedAttribute.java | 1 - .../grimac/utils/data/packetentity/PacketEntitySelf.java | 9 ++------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java b/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java index bd28924a88..3e88490bd3 100644 --- a/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java +++ b/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java @@ -24,7 +24,6 @@ public final class ValuedAttribute { private final double min, max; private WrapperPlayServerUpdateAttributes.Property lastProperty; - @Getter private final double defaultValue; private double value; diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java index 6819643d73..67d908e4cd 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java @@ -47,13 +47,8 @@ protected void initAttributes(GrimPlayer player) { setAttribute(Attributes.GENERIC_STEP_HEIGHT, 0.5f); } - ValuedAttribute scale = getAttribute(Attributes.GENERIC_SCALE).get(); - scale.withSetRewriter((oldValue, newValue) -> { - if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_20_5)) { - // Handles case where player joins on new version, changes scale - // And then rejoins on old version - return scale.getDefaultValue(); - } else if ((newValue).equals(oldValue)) { + getAttribute(Attributes.GENERIC_SCALE).get().withSetRewriter((oldValue, newValue) -> { + if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_20_5) || (newValue).equals(oldValue)) { return oldValue; } else { // Elytra, standing, sneaking (1.14) From dc7f6dca93e6912f8ca7c0126f49991ea0d6c161 Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:57:23 -0400 Subject: [PATCH 15/15] Make result player.getPossibleEyeHeights() of final in checks and remove unused imports --- src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java | 2 +- .../java/ac/grim/grimac/checks/impl/scaffolding/FarPlace.java | 2 +- .../ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java | 2 +- .../ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java | 2 +- .../ac/grim/grimac/utils/data/attribute/ValuedAttribute.java | 1 - .../ac/grim/grimac/utils/data/packetentity/PacketEntity.java | 2 -- src/main/java/ac/grim/grimac/utils/nmsutil/ReachUtils.java | 2 +- 7 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java b/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java index 5c75b5cf06..4099e04b11 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java +++ b/src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java @@ -201,7 +201,7 @@ private String checkReach(PacketEntity reachEntity, Vector3d from, boolean isPre // +3 would be 3 + 3 = 6, which is the pre-1.20.5 behaviour, preventing "Missed Hitbox" final double distance = player.compensatedEntities.getSelf().getAttributeValue(Attributes.PLAYER_ENTITY_INTERACTION_RANGE) + 3; - double[] possibleEyeHeights = player.getPossibleEyeHeights(); + final double[] possibleEyeHeights = player.getPossibleEyeHeights(); for (Vector lookVec : possibleLookDirs) { for (double eye : possibleEyeHeights) { Vector eyePos = new Vector(from.getX(), from.getY() + eye, from.getZ()); diff --git a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/FarPlace.java b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/FarPlace.java index 30d985a1c6..3f5b289646 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/FarPlace.java +++ b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/FarPlace.java @@ -26,7 +26,7 @@ public void onBlockPlace(final BlockPlace place) { if (place.getMaterial() == StateTypes.SCAFFOLDING) return; double min = Double.MAX_VALUE; - double[] possibleEyeHeights = player.getPossibleEyeHeights(); + final double[] possibleEyeHeights = player.getPossibleEyeHeights(); for (double d : possibleEyeHeights) { SimpleCollisionBox box = new SimpleCollisionBox(blockPos); Vector eyes = new Vector(player.x, player.y + d, player.z); diff --git a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java index 2dec8c7fcb..f541ceebb2 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java +++ b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/PositionPlace.java @@ -28,7 +28,7 @@ public void onBlockPlace(final BlockPlace place) { // Each position represents the best case scenario to have clicked // // We will now calculate the most optimal position for the player's head to be in - double[] possibleEyeHeights = player.getPossibleEyeHeights(); + final double[] possibleEyeHeights = player.getPossibleEyeHeights(); double minEyeHeight = Double.MAX_VALUE; double maxEyeHeight = Double.MIN_VALUE; for (double height : possibleEyeHeights) { diff --git a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java index 3c7ca7dfad..0fadf0a80b 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java +++ b/src/main/java/ac/grim/grimac/checks/impl/scaffolding/RotationPlace.java @@ -75,7 +75,7 @@ private boolean didRayTraceHit(BlockPlace place) { new Vector3f(player.xRot, player.yRot, 0) )); - double[] possibleEyeHeights = player.getPossibleEyeHeights(); + final double[] possibleEyeHeights = player.getPossibleEyeHeights(); // Start checking if player is in the block double minEyeHeight = Double.MAX_VALUE; diff --git a/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java b/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java index 3e88490bd3..d83882aa53 100644 --- a/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java +++ b/src/main/java/ac/grim/grimac/utils/data/attribute/ValuedAttribute.java @@ -5,7 +5,6 @@ import com.github.retrooper.packetevents.protocol.attribute.Attribute; import com.github.retrooper.packetevents.protocol.player.ClientVersion; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAttributes; -import lombok.Getter; import java.util.List; import java.util.Optional; diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java index d98860eb3f..893771b099 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java @@ -21,8 +21,6 @@ import ac.grim.grimac.utils.data.TrackedPosition; import ac.grim.grimac.utils.data.attribute.ValuedAttribute; import ac.grim.grimac.utils.nmsutil.GetBoundingBox; -import com.github.retrooper.packetevents.PacketEvents; -import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.attribute.Attribute; import com.github.retrooper.packetevents.protocol.attribute.Attributes; import com.github.retrooper.packetevents.protocol.entity.type.EntityType; diff --git a/src/main/java/ac/grim/grimac/utils/nmsutil/ReachUtils.java b/src/main/java/ac/grim/grimac/utils/nmsutil/ReachUtils.java index 1a38f35257..6953792b92 100644 --- a/src/main/java/ac/grim/grimac/utils/nmsutil/ReachUtils.java +++ b/src/main/java/ac/grim/grimac/utils/nmsutil/ReachUtils.java @@ -181,7 +181,7 @@ public static double getMinReachToBox(GrimPlayer player, SimpleCollisionBox targ double lowest = Double.MAX_VALUE; - double[] possibleEyeHeights = player.getPossibleEyeHeights(); + final double[] possibleEyeHeights = player.getPossibleEyeHeights(); for (double eyes : possibleEyeHeights) { if (giveMovementThresholdLenience) targetBox.expand(player.getMovementThreshold()); Vector from = new Vector(player.x, player.y + eyes, player.z);