From 8ec63fc381f3afd61ede374ba25ea53be40da2d5 Mon Sep 17 00:00:00 2001 From: ManInMyVan Date: Thu, 18 Jul 2024 14:58:01 -0600 Subject: [PATCH] fix falses while block hitting and switching slots --- .../ac/grim/grimac/events/packets/PacketPlayerAttack.java | 8 ++++++-- .../grim/grimac/events/packets/PacketPlayerDigging.java | 2 +- .../java/ac/grim/grimac/utils/data/PacketStateData.java | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/ac/grim/grimac/events/packets/PacketPlayerAttack.java b/src/main/java/ac/grim/grimac/events/packets/PacketPlayerAttack.java index 4326182586..3a779984ad 100644 --- a/src/main/java/ac/grim/grimac/events/packets/PacketPlayerAttack.java +++ b/src/main/java/ac/grim/grimac/events/packets/PacketPlayerAttack.java @@ -17,6 +17,8 @@ import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity; import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying; +import static ac.grim.grimac.utils.inventory.Inventory.HOTBAR_OFFSET; + public class PacketPlayerAttack extends PacketListenerAbstract { public PacketPlayerAttack() { @@ -45,9 +47,11 @@ public void onPacketReceive(PacketReceiveEvent event) { PacketEntity entity = player.compensatedEntities.getEntity(interact.getEntityId()); // You don't get a release use item with block hitting with a sword? - if (heldItem != null && player.getClientVersion().isOlderThan(ClientVersion.V_1_9)) { - if (heldItem.getType().hasAttribute(ItemTypes.ItemAttribute.SWORD)) + if (player.getClientVersion().isOlderThan(ClientVersion.V_1_9) && player.packetStateData.isSlowedByUsingItem()) { + ItemStack item = player.getInventory().inventory.getPlayerInventoryItem(player.packetStateData.getSlowedByUsingItemSlot() + HOTBAR_OFFSET); + if (item.getType().hasAttribute(ItemTypes.ItemAttribute.SWORD)) { player.packetStateData.setSlowedByUsingItem(false); + } } if (entity != null && (!(entity.isLivingEntity()) || entity.getType() == EntityTypes.PLAYER)) { diff --git a/src/main/java/ac/grim/grimac/events/packets/PacketPlayerDigging.java b/src/main/java/ac/grim/grimac/events/packets/PacketPlayerDigging.java index 86cbdd4aec..c5788e7156 100644 --- a/src/main/java/ac/grim/grimac/events/packets/PacketPlayerDigging.java +++ b/src/main/java/ac/grim/grimac/events/packets/PacketPlayerDigging.java @@ -171,7 +171,7 @@ public void onPacketReceive(PacketReceiveEvent event) { if (player == null) return; if (!player.packetStateData.lastPacketWasTeleport && !player.packetStateData.lastPacketWasOnePointSeventeenDuplicate) { - if (player.packetStateData.isSlowedByUsingItem() && player.packetStateData.slowedByUsingItemSlot != player.packetStateData.lastSlotSelected) { + if (player.packetStateData.isSlowedByUsingItem() && player.packetStateData.getSlowedByUsingItemSlot() != player.packetStateData.lastSlotSelected) { player.packetStateData.setSlowedByUsingItem(false); player.checkManager.getPostPredictionCheck(NoSlowA.class).didSlotChangeLastTick = true; } diff --git a/src/main/java/ac/grim/grimac/utils/data/PacketStateData.java b/src/main/java/ac/grim/grimac/utils/data/PacketStateData.java index e59d7295ac..2886e38af9 100644 --- a/src/main/java/ac/grim/grimac/utils/data/PacketStateData.java +++ b/src/main/java/ac/grim/grimac/utils/data/PacketStateData.java @@ -17,7 +17,9 @@ public class PacketStateData { public boolean tryingToRiptide = false; @Getter private boolean slowedByUsingItem; - public int slowedByUsingItemTransaction, slowedByUsingItemSlot = Integer.MIN_VALUE; + @Getter + private int slowedByUsingItemSlot = Integer.MIN_VALUE; + public int slowedByUsingItemTransaction = Integer.MIN_VALUE; public boolean receivedSteerVehicle = false; // This works on 1.8 only public boolean didLastLastMovementIncludePosition = false;