Skip to content

Commit

Permalink
Change getBlockInteractRange and remove debug
Browse files Browse the repository at this point in the history
  • Loading branch information
SamB440 committed Jul 10, 2024
1 parent 796c37d commit ae0ec6e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ac.grim.grimac.utils.anticheat.update.BlockPlace;
import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox;
import ac.grim.grimac.utils.math.VectorUtils;
import com.github.retrooper.packetevents.protocol.attribute.Attributes;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.GameMode;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void onBlockPlace(final BlockPlace place) {

// getPickRange() determines this?
// With 1.20.5+ the new attribute determines creative mode reach using a modifier
double maxReach = player.compensatedEntities.getSelf().getBlockInteractRange();
double maxReach = player.compensatedEntities.getSelf().getAttributeValue(Attributes.PLAYER_BLOCK_INTERACTION_RANGE);
double threshold = player.getMovementThreshold();
maxReach += Math.hypot(threshold, threshold);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ac.grim.grimac.utils.data.Pair;
import ac.grim.grimac.utils.nmsutil.Ray;
import ac.grim.grimac.utils.nmsutil.ReachUtils;
import com.github.retrooper.packetevents.protocol.attribute.Attributes;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.world.BlockFace;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
Expand Down Expand Up @@ -94,7 +95,7 @@ private boolean didRayTraceHit(BlockPlace place) {
possibleLookDirs = Collections.singletonList(new Vector3f(player.xRot, player.yRot, 0));
}

final double distance = player.compensatedEntities.getSelf().getBlockInteractRange();
final double distance = player.compensatedEntities.getSelf().getAttributeValue(Attributes.PLAYER_BLOCK_INTERACTION_RANGE);
for (double d : player.getPossibleEyeHeights()) {
for (Vector3f lookDir : possibleLookDirs) {
// x, y, z are correct for the block placement even after post tick because of code elsewhere
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.attribute.Attributes;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
Expand Down Expand Up @@ -781,7 +782,7 @@ private static HitData getNearestHitResult(GrimPlayer player, StateType heldItem
Vector3d startingPos = new Vector3d(player.x, player.y + player.getEyeHeight(), player.z);
Vector startingVec = new Vector(startingPos.getX(), startingPos.getY(), startingPos.getZ());
Ray trace = new Ray(player, startingPos.getX(), startingPos.getY(), startingPos.getZ(), player.xRot, player.yRot);
final double distance = player.compensatedEntities.getSelf().getBlockInteractRange();
final double distance = player.compensatedEntities.getSelf().getAttributeValue(Attributes.PLAYER_BLOCK_INTERACTION_RANGE);
Vector endVec = trace.getPointAtDistance(distance);
Vector3d endPos = new Vector3d(endVec.getX(), endVec.getY(), endVec.getZ());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ public void livingEntityTravel() {

if (player.depthStriderLevel > 0.0F) {
final float divisor = player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_21) ? 1.0F : 3.0F;
Bukkit.broadcastMessage("level: " + player.depthStriderLevel);
swimFriction += (0.54600006F - swimFriction) * player.depthStriderLevel / divisor;
swimSpeed += (player.speed - swimSpeed) * player.depthStriderLevel / divisor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ public class PacketEntitySelf extends PacketEntity {
@Setter
int opLevel;

public double getBlockInteractRange() {
// Server versions older than 1.20.5 don't send the attribute, if the player is in creative then assume legacy max reach distance.
// Or if they are on a client version older than 1.20.5.
if (player.gamemode == GameMode.CREATIVE
&& (player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5)
|| PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_20_5))) {
return 5.0;
}
return getAttributeValue(Attributes.PLAYER_BLOCK_INTERACTION_RANGE);
}

public PacketEntitySelf(GrimPlayer player) {
super(player, EntityTypes.PLAYER);
this.player = player;
Expand Down Expand Up @@ -68,6 +57,15 @@ protected void initAttributes(GrimPlayer player) {
trackAttribute(ValuedAttribute.ranged(Attributes.PLAYER_ENTITY_INTERACTION_RANGE, 3, 0, 64)
.requiredVersion(player, ClientVersion.V_1_20_5));
trackAttribute(ValuedAttribute.ranged(Attributes.PLAYER_BLOCK_INTERACTION_RANGE, 4.5, 0, 64)
.withGetRewriter(value -> {
// Server versions older than 1.20.5 don't send the attribute, if the player is in creative then assume legacy max reach distance.
if (player.gamemode == GameMode.CREATIVE
&& PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_20_5)) {
return 5.0;
}
// < 1.20.5 is unchanged due to requiredVersion, otherwise controlled by the server
return value;
})
.requiredVersion(player, ClientVersion.V_1_20_5));
trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_WATER_MOVEMENT_EFFICIENCY, 0, 0, 1)
.withGetRewriter(value -> {
Expand Down

0 comments on commit ae0ec6e

Please sign in to comment.