Skip to content

Commit

Permalink
fix #23
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyfts committed Aug 2, 2024
1 parent 0831f58 commit 97d8785
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/xonin/backhand/ServerTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ public void onUpdateWorld(TickEvent.WorldTickEvent event) {
if (Backhand.OffhandTickHotswap) {
for (EntityPlayer player : event.world.playerEntities) {
if (!(player instanceof EntityPlayerMP playerMP)) continue;
OffhandExtendedProperty offhandProp = BackhandUtils.getOffhandEP(player);

if (event.phase == TickEvent.Phase.START && !player.isUsingItem()) {
if (event.phase == TickEvent.Phase.START && !player.isUsingItem() && offhandProp.hotswapDelay <= 0) {
tickHotswap(playerMP);
} else {
if (offhandProp.hotswapDelay > 0) offhandProp.hotswapDelay--;
resetTickingHotswap(playerMP);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class OffhandExtendedProperty implements IExtendedEntityProperties {
public int activeSlot = -1;
public boolean arrowHotSwapped = false;
public boolean regularHotSwap = false;
public int hotswapDelay = 0;

public OffhandExtendedProperty(EntityPlayer player) {
this.player = player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;

import xonin.backhand.ServerTickHandler;
import xonin.backhand.api.core.BackhandUtils;
import xonin.backhand.api.core.InventoryPlayerBackhand;

Expand Down Expand Up @@ -56,6 +57,16 @@ public abstract class MixinNetHandlerPlayServer {
instance.tryHarvestBlock(x, y, z);
}

@Inject(
method = "processPlayerDigging",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/player/EntityPlayerMP;dropOneItem(Z)Lnet/minecraft/entity/item/EntityItem;"))
private void backhand$playerDropItem(C07PacketPlayerDigging packetIn, CallbackInfo ci) {
ServerTickHandler.resetTickingHotswap(playerEntity);
BackhandUtils.getOffhandEP(playerEntity).hotswapDelay = 5;
}

@Inject(method = "processUseEntity", at = @At("HEAD"))
private void backhand$hotswapOnEntityInteract(C02PacketUseEntity packetIn, CallbackInfo ci) {
if (backhand$shouldSwapOffhand(packetIn.func_149565_c())) {
Expand Down

0 comments on commit 97d8785

Please sign in to comment.