Skip to content

Commit

Permalink
Update packetevents
Browse files Browse the repository at this point in the history
  • Loading branch information
SamB440 committed Dec 7, 2024
1 parent 912939a commit b0790af
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 56 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ repositories {
maven("https://repo.opencollab.dev/maven-releases/") // Cumulus (for Floodgate)
maven("https://repo.codemc.io/repository/maven-releases/") // PacketEvents
maven("https://repo.codemc.io/repository/maven-snapshots/")
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
mavenCentral()
// FastUtil, Discord-Webhooks
}

dependencies {
implementation("com.github.retrooper:packetevents-spigot:2.6.1-SNAPSHOT")
implementation("com.github.retrooper:packetevents-spigot:2.7.0-SNAPSHOT")
implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT")
implementation("club.minnced:discord-webhooks:0.8.0") // Newer versions include kotlin-stdlib, which leads to incompatibility with plugins that use Kotlin
implementation("it.unimi.dsi:fastutil:8.5.15")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void onPacketReceive(final PacketReceiveEvent event) {
// 27/12/2023 - Dynamic values for more than just one entity type?
// 28/12/2023 - Player-only is fine
// 30/12/2023 - Expansions differ in 1.9+
final float scale = (float) packetEntity.getAttributeValue(Attributes.GENERIC_SCALE);
final float scale = (float) packetEntity.getAttributeValue(Attributes.SCALE);
if (targetVector.y > (minVerticalDisplacement * scale) && targetVector.y < (maxVerticalDisplacement * scale)
&& Math.abs(targetVector.x) < (maxHorizontalDisplacement * scale)
&& Math.abs(targetVector.z) < (maxHorizontalDisplacement * scale)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
import com.github.retrooper.packetevents.protocol.world.states.type.StateValue;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.util.Vector3f;
import com.github.retrooper.packetevents.util.Vector3i;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerExplosion;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void onPacketReceive(PacketReceiveEvent event) {
// 1.9+ players who have attack speed cannot slow themselves twice in one tick because their attack cooldown gets reset on swing.
if (player.maxPlayerAttackSlow > 0
&& PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)
&& player.compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_ATTACK_SPEED) < 16) { // 16 is a reasonable limit
&& player.compensatedEntities.getSelf().getAttributeValue(Attributes.ATTACK_SPEED) < 16) { // 16 is a reasonable limit
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ac/grim/grimac/player/GrimPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public GrimPlayer(User user) {
uncertaintyHandler.collidingEntities.add(0);

if (getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) {
final float scale = (float) compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_SCALE);
final float scale = (float) compensatedEntities.getSelf().getAttributeValue(Attributes.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), Elytra
Expand Down Expand Up @@ -376,14 +376,14 @@ public void trackBaseTickAddition(Vector vector) {
public float getMaxUpStep() {
final PacketEntitySelf self = compensatedEntities.getSelf();
final PacketEntity riding = self.getRiding();
if (riding == null) return (float) self.getAttributeValue(Attributes.GENERIC_STEP_HEIGHT);
if (riding == null) return (float) self.getAttributeValue(Attributes.STEP_HEIGHT);

if (riding.isBoat()) {
return 0f;
}

// Pigs, horses, striders, and other vehicles all have 1 stepping height by default
return (float) riding.getAttributeValue(Attributes.GENERIC_STEP_HEIGHT);
return (float) riding.getAttributeValue(Attributes.STEP_HEIGHT);
}

public void sendTransaction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void check(PositionUpdate update) {
SimpleCollisionBox interTruePositions = riding.getPossibleCollisionBoxes();

// We shrink the expanded bounding box to what the packet positions can be, for a smaller box
final float scale = (float) riding.getAttributeValue(Attributes.GENERIC_SCALE);
final float scale = (float) riding.getAttributeValue(Attributes.SCALE);
float width = BoundingBoxSize.getWidth(player, riding) * scale;
float height = BoundingBoxSize.getHeight(player, riding) * scale;
interTruePositions.expand(-width, 0, -width);
Expand Down Expand Up @@ -236,7 +236,7 @@ private void check(PositionUpdate update) {
if (player.isInBed) return;

if (!player.compensatedEntities.getSelf().inVehicle()) {
player.speed = player.compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_MOVEMENT_SPEED);
player.speed = player.compensatedEntities.getSelf().getAttributeValue(Attributes.MOVEMENT_SPEED);
if (player.hasGravity != player.playerEntityHasGravity) {
player.pointThreeEstimator.updatePlayerGravity();
}
Expand Down Expand Up @@ -441,7 +441,7 @@ private void check(PositionUpdate update) {
} else if (riding == null) {
wasChecked = true;

player.depthStriderLevel = (float) player.compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_WATER_MOVEMENT_EFFICIENCY);
player.depthStriderLevel = (float) player.compensatedEntities.getSelf().getAttributeValue(Attributes.WATER_MOVEMENT_EFFICIENCY);
player.sneakingSpeedMultiplier = (float) player.compensatedEntities.getSelf().getAttributeValue(Attributes.PLAYER_SNEAKING_SPEED);

// This is wrong and the engine was not designed around stuff like this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static boolean canEnterPose(GrimPlayer player, Pose pose, double x, doubl
}

protected static SimpleCollisionBox getBoundingBoxForPose(GrimPlayer player, Pose pose, double x, double y, double z) {
final float scale = (float) player.compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_SCALE);
final float scale = (float) player.compensatedEntities.getSelf().getAttributeValue(Attributes.SCALE);
final float width = pose.width * scale;
final float height = pose.height * scale;
float radius = width / 2.0F;
Expand Down Expand Up @@ -147,7 +147,7 @@ public void updatePowderSnow() {
// Pre-1.17 clients don't have powder snow and therefore don't desync
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_16_4)) return;

final ValuedAttribute playerSpeed = player.compensatedEntities.getSelf().getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get();
final ValuedAttribute playerSpeed = player.compensatedEntities.getSelf().getAttribute(Attributes.MOVEMENT_SPEED).get();

// Might be null after respawn?
final Optional<WrapperPlayServerUpdateAttributes.Property> property = playerSpeed.property();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void tickFireworksBox() {
if (entity == null) continue;

SimpleCollisionBox entityBox = entity.getPossibleCollisionBoxes();
final float scale = (float) entity.getAttributeValue(Attributes.GENERIC_SCALE);
final float scale = (float) entity.getAttributeValue(Attributes.SCALE);
float width = BoundingBoxSize.getWidth(player, entity) * scale;
float height = BoundingBoxSize.getHeight(player, entity) * scale;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ public void doNormalMove(float blockFriction) {

public void livingEntityTravel() {
double playerGravity = player.compensatedEntities.getSelf().getRiding() == null
? player.compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_GRAVITY)
: player.compensatedEntities.getSelf().getRiding().getAttributeValue(Attributes.GENERIC_GRAVITY);
? player.compensatedEntities.getSelf().getAttributeValue(Attributes.GRAVITY)
: player.compensatedEntities.getSelf().getRiding().getAttributeValue(Attributes.GRAVITY);

boolean isFalling = player.actualMovement.getY() <= 0.0;
if (isFalling && player.compensatedEntities.getSlowFallingAmplifier().isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public MovementTickerHorse(GrimPlayer player) {

if (!horsePacket.hasSaddle) return;

player.speed = horsePacket.getAttributeValue(Attributes.GENERIC_MOVEMENT_SPEED);
player.speed = horsePacket.getAttributeValue(Attributes.MOVEMENT_SPEED);

// Setup player inputs
float horizInput = player.vehicleData.vehicleHorizontal * 0.5F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public MovementTickerPig(GrimPlayer player) {
@Override
public float getSteeringSpeed() { // Vanilla multiples by 0.225f
PacketEntityRideable pig = (PacketEntityRideable) player.compensatedEntities.getSelf().getRiding();
return (float) pig.getAttributeValue(Attributes.GENERIC_MOVEMENT_SPEED) * 0.225f;
return (float) pig.getAttributeValue(Attributes.MOVEMENT_SPEED) * 0.225f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public float getSteeringSpeed() {

// Client desyncs the attribute
// Again I don't know when this was changed, or whether it always existed, so I will just put it behind 1.20+
final ValuedAttribute movementSpeedAttr = strider.getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get();
final ValuedAttribute movementSpeedAttr = strider.getAttribute(Attributes.MOVEMENT_SPEED).get();
float updatedMovementSpeed = (float) movementSpeedAttr.get();
if (newSpeed) {
final WrapperPlayServerUpdateAttributes.Property lastProperty = movementSpeedAttr.property().orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public Vector handleStartingVelocityUncertainty(GrimPlayer player, VectorData ve
// We can't simulate the player's Y velocity, unknown number of ticks with a gravity change
// Feel free to simulate all 104857600000000000000000000 possibilities!
if (!player.pointThreeEstimator.canPredictNextVerticalMovement()) {
minVector.setY(minVector.getY() - player.compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_GRAVITY));
minVector.setY(minVector.getY() - player.compensatedEntities.getSelf().getAttributeValue(Attributes.GRAVITY));
}

// Hidden slime block bounces by missing idle tick and 0.03
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Vector getElytraMovement(GrimPlayer player, Vector vector, Vector
// So we actually use the player's actual movement to get the gravity/slow falling status
// However, this is wrong with elytra movement because players can control vertical movement after gravity is calculated
// Yeah, slow falling needs a refactor in grim.
double recalculatedGravity = player.compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_GRAVITY);
double recalculatedGravity = player.compensatedEntities.getSelf().getAttributeValue(Attributes.GRAVITY);
if (player.clientVelocity.getY() <= 0 && player.compensatedEntities.getSlowFallingAmplifier().isPresent()) {
recalculatedGravity = player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5) ? 0.01 : Math.min(recalculatedGravity, 0.01);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Set<VectorData> handleJumps(GrimPlayer player, Set<VectorData> pos
//
// There's a float/double error causing 1e-8 imprecision if anyone wants to debug it
if (player.vehicleData.horseJump > 0.0F && !player.vehicleData.horseJumping && player.lastOnGround) {
double d0 = horse.getAttributeValue(Attributes.GENERIC_JUMP_STRENGTH) * player.vehicleData.horseJump * JumpPower.getPlayerJumpFactor(player);
double d0 = horse.getAttributeValue(Attributes.JUMP_STRENGTH) * player.vehicleData.horseJump * JumpPower.getPlayerJumpFactor(player);
double d1;

// This doesn't even work because vehicle jump boost has (likely) been
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public void set(Vector3i position, WrappedBlockState state) {
for (PacketEntity entity : player.compensatedEntities.entityMap.values()) {
SimpleCollisionBox interpBox = entity.getPossibleCollisionBoxes();

final double scale = entity.getAttributeValue(Attributes.GENERIC_SCALE);
final double scale = entity.getAttributeValue(Attributes.SCALE);
double width = BoundingBoxSize.getWidth(player, entity) * scale;
double height = BoundingBoxSize.getHeight(player, entity) * scale;
double interpWidth = Math.max(interpBox.maxX - interpBox.minX, interpBox.maxZ - interpBox.minZ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ protected void trackAttribute(ValuedAttribute valuedAttribute) {
}

protected void initAttributes(GrimPlayer player) {
trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_SCALE, 1.0, 0.0625, 16)
trackAttribute(ValuedAttribute.ranged(Attributes.SCALE, 1.0, 0.0625, 16)
.requiredVersion(player, ClientVersion.V_1_20_5));
trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_STEP_HEIGHT, 0.6f, 0, 10)
trackAttribute(ValuedAttribute.ranged(Attributes.STEP_HEIGHT, 0.6f, 0, 10)
.requiredVersion(player, ClientVersion.V_1_20_5));
trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_GRAVITY, 0.08, -1, 1)
trackAttribute(ValuedAttribute.ranged(Attributes.GRAVITY, 0.08, -1, 1)
.requiredVersion(player, ClientVersion.V_1_20_5));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class PacketEntityCamel extends PacketEntityHorse {
public PacketEntityCamel(GrimPlayer player, UUID uuid, EntityType type, double x, double y, double z, float xRot) {
super(player, uuid, type, x, y, z, xRot);

setAttribute(Attributes.GENERIC_JUMP_STRENGTH, 0.42f);
setAttribute(Attributes.GENERIC_MOVEMENT_SPEED, 0.09f);
setAttribute(Attributes.GENERIC_STEP_HEIGHT, 1.5f);
setAttribute(Attributes.JUMP_STRENGTH, 0.42f);
setAttribute(Attributes.MOVEMENT_SPEED, 0.09f);
setAttribute(Attributes.STEP_HEIGHT, 1.5f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class PacketEntityHorse extends PacketEntityTrackXRot {

public PacketEntityHorse(GrimPlayer player, UUID uuid, EntityType type, double x, double y, double z, float xRot) {
super(player, uuid, type, x, y, z, xRot);
setAttribute(Attributes.GENERIC_STEP_HEIGHT, 1.0f);
setAttribute(Attributes.STEP_HEIGHT, 1.0f);

final boolean preAttribute = player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5);
// This was horse.jump_strength pre-attribute
trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_JUMP_STRENGTH, 0.7, 0, preAttribute ? 2 : 32)
trackAttribute(ValuedAttribute.ranged(Attributes.JUMP_STRENGTH, 0.7, 0, preAttribute ? 2 : 32)
.withSetRewriter((oldValue, newValue) -> {
// Seems viabackwards doesn't rewrite this (?)
if (preAttribute && PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_20_5)) {
Expand All @@ -32,15 +32,15 @@ public PacketEntityHorse(GrimPlayer player, UUID uuid, EntityType type, double x
// Modern player OR an old server setting legacy horse.jump_strength attribute
return newValue;
}));
trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_MOVEMENT_SPEED, 0.225f, 0, 1024));
trackAttribute(ValuedAttribute.ranged(Attributes.MOVEMENT_SPEED, 0.225f, 0, 1024));

if (EntityTypes.isTypeInstanceOf(type, EntityTypes.CHESTED_HORSE)) {
setAttribute(Attributes.GENERIC_JUMP_STRENGTH, 0.5);
setAttribute(Attributes.GENERIC_MOVEMENT_SPEED, 0.175f);
setAttribute(Attributes.JUMP_STRENGTH, 0.5);
setAttribute(Attributes.MOVEMENT_SPEED, 0.175f);
}

if (type == EntityTypes.ZOMBIE_HORSE || type == EntityTypes.SKELETON_HORSE) {
setAttribute(Attributes.GENERIC_MOVEMENT_SPEED, 0.2f);
setAttribute(Attributes.MOVEMENT_SPEED, 0.2f);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PacketEntityRideable extends PacketEntity {

public PacketEntityRideable(GrimPlayer player, UUID uuid, EntityType type, double x, double y, double z) {
super(player, uuid, type, x, y, z);
setAttribute(Attributes.GENERIC_STEP_HEIGHT, 1.0f);
trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_MOVEMENT_SPEED, 0.1f, 0, 1024));
setAttribute(Attributes.STEP_HEIGHT, 1.0f);
trackAttribute(ValuedAttribute.ranged(Attributes.MOVEMENT_SPEED, 0.1f, 0, 1024));
}
}
Loading

0 comments on commit b0790af

Please sign in to comment.