mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-14 19:25:23 -05:00
Fix non-player handling in CustomDamageHandler (#3781)
This commit is contained in:
parent
e633f8839b
commit
5b61bd2784
1 changed files with 3 additions and 2 deletions
|
@ -27,6 +27,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
@ -45,13 +46,13 @@ public abstract class ItemStackMixin implements FabricItemStack {
|
||||||
public abstract void decrement(int amount);
|
public abstract void decrement(int amount);
|
||||||
|
|
||||||
@WrapOperation(method = "damage(ILnet/minecraft/entity/LivingEntity;Lnet/minecraft/entity/EquipmentSlot;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/server/world/ServerWorld;Lnet/minecraft/server/network/ServerPlayerEntity;Ljava/util/function/Consumer;)V"))
|
@WrapOperation(method = "damage(ILnet/minecraft/entity/LivingEntity;Lnet/minecraft/entity/EquipmentSlot;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/server/world/ServerWorld;Lnet/minecraft/server/network/ServerPlayerEntity;Ljava/util/function/Consumer;)V"))
|
||||||
private void hookDamage(ItemStack instance, int amount, ServerWorld serverWorld, ServerPlayerEntity serverPlayerEntity, Consumer<Item> consumer, Operation<Void> original, @Local(argsOnly = true) EquipmentSlot slot) {
|
private void hookDamage(ItemStack instance, int amount, ServerWorld serverWorld, ServerPlayerEntity serverPlayerEntity, Consumer<Item> consumer, Operation<Void> original, @Local(argsOnly = true) LivingEntity entity, @Local(argsOnly = true) EquipmentSlot slot) {
|
||||||
CustomDamageHandler handler = ((ItemExtensions) getItem()).fabric_getCustomDamageHandler();
|
CustomDamageHandler handler = ((ItemExtensions) getItem()).fabric_getCustomDamageHandler();
|
||||||
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
// Track whether an item has been broken by custom handler
|
// Track whether an item has been broken by custom handler
|
||||||
MutableBoolean mut = new MutableBoolean(false);
|
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();
|
mut.setTrue();
|
||||||
this.decrement(1);
|
this.decrement(1);
|
||||||
consumer.accept(this.getItem());
|
consumer.accept(this.getItem());
|
||||||
|
|
Loading…
Reference in a new issue