Skip to content

Commit 5b69f97

Browse files
fix #467 (#469)
* fix #467 * add explanation
1 parent 9bbc40b commit 5b69f97

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
package dev.isxander.debugify.mixins.basic.mc168573;
22

3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import com.llamalad7.mixinextras.sugar.Local;
36
import dev.isxander.debugify.fixes.BugFix;
47
import dev.isxander.debugify.fixes.FixCategory;
5-
import net.minecraft.world.InteractionHand;
8+
import net.minecraft.world.entity.EquipmentSlot;
69
import net.minecraft.world.entity.LivingEntity;
710
import net.minecraft.world.item.ItemStack;
811
import net.minecraft.world.item.component.BlocksAttacks;
9-
import net.minecraft.world.level.Level;
1012
import org.spongepowered.asm.mixin.Mixin;
1113
import org.spongepowered.asm.mixin.injection.At;
12-
import org.spongepowered.asm.mixin.injection.Inject;
13-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1414

1515
@BugFix(id = "MC-168573", category = FixCategory.BASIC, env = BugFix.Env.SERVER, description = "After breaking a shield, the player's off-hand can't finish using some items")
1616
@Mixin(BlocksAttacks.class)
1717
public class BlocksAttacksMixin {
18-
@Inject(method = "hurtBlockingItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;hurtAndBreak(ILnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;)V"))
19-
private void fixShieldBreakItemUse(Level level, ItemStack itemStack, LivingEntity livingEntity, InteractionHand interactionHand, float f, CallbackInfo ci) {
20-
livingEntity.stopUsingItem();
18+
/**
19+
* We need to check if the shield is going to break and only stop using the item after it is broken.
20+
* We can't use isBroken here, so instead we check if the next damage will break the blockable, then do the damage call after.
21+
*/
22+
@WrapOperation(method = "hurtBlockingItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;hurtAndBreak(ILnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;)V"))
23+
private void fixShieldBreakItemUse(ItemStack instance, int amount, LivingEntity entity, EquipmentSlot slot, Operation<Void> original, @Local(argsOnly = true) ItemStack stack) {
24+
boolean isBroken = stack.nextDamageWillBreak();
25+
original.call(instance, amount, entity, slot);
26+
if (isBroken) entity.stopUsingItem();
2127
}
2228
}

0 commit comments

Comments
 (0)