mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-13 16:53:35 -04:00
Fix non-player handling in CustomDamageHandler (#3781)
(cherry picked from commit 5b61bd2784
)
This commit is contained in:
parent
1997dc5522
commit
8e8943b634
1 changed files with 3 additions and 2 deletions
|
@ -25,6 +25,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
|||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
@ -39,13 +40,13 @@ public abstract class ItemStackMixin implements FabricItemStack {
|
|||
@Shadow public abstract Item getItem();
|
||||
|
||||
@WrapOperation(method = "damage(ILnet/minecraft/entity/LivingEntity;Lnet/minecraft/entity/EquipmentSlot;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/util/math/random/Random;Lnet/minecraft/server/network/ServerPlayerEntity;Ljava/lang/Runnable;)V"))
|
||||
private void hookDamage(ItemStack instance, int amount, Random random, ServerPlayerEntity serverPlayerEntity, Runnable runnable, Operation<Void> original, @Local(argsOnly = true) EquipmentSlot slot) {
|
||||
private void hookDamage(ItemStack instance, int amount, Random random, ServerPlayerEntity serverPlayerEntity, Runnable runnable, Operation<Void> original, @Local(argsOnly = true) LivingEntity entity, @Local(argsOnly = true) EquipmentSlot slot) {
|
||||
CustomDamageHandler handler = ((ItemExtensions) getItem()).fabric_getCustomDamageHandler();
|
||||
|
||||
if (handler != null) {
|
||||
// Track whether an item has been broken by custom handler
|
||||
MutableBoolean mut = new MutableBoolean(false);
|
||||
amount = handler.damage((ItemStack) (Object) this, amount, serverPlayerEntity, slot, () -> {
|
||||
amount = handler.damage((ItemStack) (Object) this, amount, entity, slot, () -> {
|
||||
mut.setTrue();
|
||||
runnable.run();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue