Skip to content

Commit

Permalink
Merge pull request #1598 from ManInMyVan/fix/1.8-swords
Browse files Browse the repository at this point in the history
fix falses while block hitting and switching slots
  • Loading branch information
SamB440 committed Aug 11, 2024
2 parents 1222db1 + 8ec63fc commit 2ff0bcd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ac/grim/grimac/utils/data/PacketStateData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2ff0bcd

Please sign in to comment.