Skip to content

Commit 4eeab0e

Browse files
committed
Fix horse hitbox falses
1 parent 1fb1a73 commit 4eeab0e

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/main/java/ac/grim/grimac/checks/impl/combat/Reach.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import ac.grim.grimac.player.GrimPlayer;
2323
import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox;
2424
import ac.grim.grimac.utils.data.packetentity.PacketEntity;
25+
import ac.grim.grimac.utils.data.packetentity.PacketEntityHorse;
2526
import ac.grim.grimac.utils.data.packetentity.dragon.PacketEntityEnderDragonPart;
2627
import ac.grim.grimac.utils.nmsutil.ReachUtils;
2728
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
@@ -234,6 +235,27 @@ private CheckResult checkReach(PacketEntity reachEntity, Vector3d from, boolean
234235
// if the entity is not exempt and the entity is alive
235236
if ((!blacklisted.contains(reachEntity.getType()) && reachEntity.isLivingEntity()) || reachEntity.getType() == EntityTypes.END_CRYSTAL) {
236237
if (minDistance == Double.MAX_VALUE) {
238+
// Interacting with a horse (not necessarily mounting it) forcefully sets the
239+
// rotation of the player to the horse's rotation on the client in versions 1.13
240+
// and lower, so in that case the rotation sent in the following flying packet
241+
// is not the one used for interacting with the horse, but we used it for the reach
242+
// calculation, which leads to hitbox flags. However, the player's position is
243+
// still accurate, so this forced rotation will not cause reach falses, and we
244+
// can still check reach on horse interactions.
245+
//
246+
// This even affects attacks from the same tick as the client only ray traces
247+
// at the start of the tick, so an attack can occur first and then the interaction
248+
// happens which breaks the rotation. We exempt attacks automatically because the
249+
// horseInteractCausedForcedRotation is set as soon as an interact is received
250+
// and is only set to false on the next flying/transaction. This function here is
251+
// run either directly on attack/interact if packets have previously been cancelled
252+
// or on that next flying/transaction so we always know if the rotation was forced.
253+
// If there wasn't any interaction with a horse in a tick, attacks can still be
254+
// checked normally.
255+
if (reachEntity instanceof PacketEntityHorse && player.packetStateData.horseInteractCausedForcedRotation) {
256+
return NONE;
257+
}
258+
237259
cancelBuffer = 1;
238260
return new CheckResult(ResultType.HITBOX, "");
239261
} else if (minDistance > maxReach) {

src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,15 @@ public void onPacketReceive(PacketReceiveEvent event) {
625625
// Such as the NoFall check setting the player to not be on the ground
626626
player.checkManager.onPacketReceive(event);
627627

628+
// Reset exemption for forced horse rotation when we know a new tick is starting
629+
// The second case (transaction) will be quite unlikely since we should receive a rotation
630+
// packet because of the large forced rotation difference.
631+
if (WrapperPlayClientPlayerFlying.isFlying(event.getPacketType())
632+
|| event.getPacketType() == PacketType.Play.Client.WINDOW_CONFIRMATION
633+
) {
634+
player.packetStateData.horseInteractCausedForcedRotation = false;
635+
}
636+
628637
if (player.packetStateData.cancelDuplicatePacket) {
629638
event.setCancelled(true);
630639
player.packetStateData.cancelDuplicatePacket = false;
@@ -813,8 +822,6 @@ private void handleFlying(GrimPlayer player, double x, double y, double z, float
813822
if (!player.packetStateData.lastPacketWasTeleport) {
814823
player.packetStateData.didSendMovementBeforeTickEnd = true;
815824
}
816-
817-
player.packetStateData.horseInteractCausedForcedRotation = false;
818825
}
819826

820827
private static void placeLilypad(GrimPlayer player, InteractionHand hand) {

0 commit comments

Comments
 (0)