|
1 | 1 | package dev.isxander.debugify.mixins.basic.mc168573; |
2 | 2 |
|
| 3 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 4 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 5 | +import com.llamalad7.mixinextras.sugar.Local; |
3 | 6 | import dev.isxander.debugify.fixes.BugFix; |
4 | 7 | import dev.isxander.debugify.fixes.FixCategory; |
5 | | -import net.minecraft.world.InteractionHand; |
| 8 | +import net.minecraft.world.entity.EquipmentSlot; |
6 | 9 | import net.minecraft.world.entity.LivingEntity; |
7 | 10 | import net.minecraft.world.item.ItemStack; |
8 | 11 | import net.minecraft.world.item.component.BlocksAttacks; |
9 | | -import net.minecraft.world.level.Level; |
10 | 12 | import org.spongepowered.asm.mixin.Mixin; |
11 | 13 | import org.spongepowered.asm.mixin.injection.At; |
12 | | -import org.spongepowered.asm.mixin.injection.Inject; |
13 | | -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
14 | 14 |
|
15 | 15 | @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") |
16 | 16 | @Mixin(BlocksAttacks.class) |
17 | 17 | 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(); |
21 | 27 | } |
22 | 28 | } |
0 commit comments