Skip to content

Commit

Permalink
Simplify logic and handle caching even when scale changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Axionize committed Sep 24, 2024
1 parent 927b330 commit 619e7f1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
30 changes: 11 additions & 19 deletions src/main/java/ac/grim/grimac/player/GrimPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 619e7f1

Please sign in to comment.