From 32a1b3bcded76d262a1410a2276616759f1e54d3 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Thu, 8 Dec 2022 20:29:03 +0800 Subject: [PATCH] Fix mixin conflict with the vault (#824) They use overwrite --- .../core/world/item/CrossbowItemMixin.java | 29 +++++++++---------- .../mixin/core/world/item/ItemStackMixin.java | 29 +++++++++++-------- .../main/resources/mixins.arclight.core.json | 1 + 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/CrossbowItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/CrossbowItemMixin.java index 4587adf2..b20eb150 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/CrossbowItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/CrossbowItemMixin.java @@ -3,10 +3,10 @@ package io.izzel.arclight.common.mixin.core.world.item; import io.izzel.arclight.common.bridge.core.entity.EntityBridge; import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.mod.util.DistValidate; -import io.izzel.arclight.mixin.Eject; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.item.CrossbowItem; @@ -27,29 +27,28 @@ public class CrossbowItemMixin { private static void arclight$entityShoot(Level worldIn, LivingEntity shooter, InteractionHand handIn, ItemStack crossbow, ItemStack projectile, float soundPitch, boolean isCreativeMode, float velocity, float inaccuracy, float projectileAngle, CallbackInfo ci, boolean flag, Projectile proj) { if (!DistValidate.isValid(worldIn)) { - arclight$capturedBoolean = true; return; } EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(shooter, crossbow, projectile, proj, shooter.getUsedItemHand(), soundPitch, true); if (event.isCancelled()) { event.getProjectile().remove(); ci.cancel(); + return; + } + if (event.getProjectile() != ((EntityBridge) proj).bridge$getBukkitEntity()) { + worldIn.playSound(null, shooter.getX(), shooter.getY(), shooter.getZ(), SoundEvents.CROSSBOW_SHOOT, SoundSource.PLAYERS, 1.0F, soundPitch); + ci.cancel(); } - arclight$capturedBoolean = event.getProjectile() == ((EntityBridge) proj).bridge$getBukkitEntity(); } - private static transient boolean arclight$capturedBoolean; - - @Eject(method = "shootProjectile", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) - private static boolean arclight$addEntity(Level world, Entity entityIn, CallbackInfo ci, Level worldIn, LivingEntity shooter) { - if (arclight$capturedBoolean) { - if (!world.addFreshEntity(entityIn)) { - if (shooter instanceof ServerPlayer) { - ((ServerPlayerEntityBridge) shooter).bridge$getBukkitEntity().updateInventory(); - } - ci.cancel(); + @Inject(method = "shootProjectile", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private static void arclight$addEntity(Level p_40895_, LivingEntity shooter, InteractionHand p_40897_, ItemStack p_40898_, ItemStack p_40899_, float p_40900_, boolean p_40901_, float p_40902_, float p_40903_, float p_40904_, CallbackInfo ci, + boolean b, Projectile projectile) { + if (!projectile.isAddedToWorld()) { + if (shooter instanceof ServerPlayer) { + ((ServerPlayerEntityBridge) shooter).bridge$getBukkitEntity().updateInventory(); } + ci.cancel(); } - return true; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/ItemStackMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/ItemStackMixin.java index dc846067..ffbe1483 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/ItemStackMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/ItemStackMixin.java @@ -69,21 +69,26 @@ public abstract class ItemStackMixin extends CapabilityProvider imple this.convertStack(version); } - @ModifyVariable(method = "hurt", index = 1, name = "amount", at = @At(value = "JUMP", opcode = Opcodes.IFGT, ordinal = 0)) - private int arclight$itemDamage(int i, int amount, Random rand, ServerPlayer damager) { - if (damager != null) { - PlayerItemDamageEvent event = new PlayerItemDamageEvent(((ServerPlayerEntityBridge) damager).bridge$getBukkitEntity(), CraftItemStack.asCraftMirror((ItemStack) (Object) this), i); - event.getPlayer().getServer().getPluginManager().callEvent(event); + // https://github.com/IzzelAliz/Arclight/issues/824 + @Mixin(value = ItemStack.class, priority = 1500) + public static class TheVaultCompat { - if (i != event.getDamage() || event.isCancelled()) { - event.getPlayer().updateInventory(); + @ModifyVariable(method = "hurt", index = 1, name = "amount", at = @At(value = "JUMP", opcode = Opcodes.IFGT, ordinal = 0), argsOnly = true) + private int arclight$itemDamage(int i, int amount, Random rand, ServerPlayer damager) { + if (damager != null) { + PlayerItemDamageEvent event = new PlayerItemDamageEvent(((ServerPlayerEntityBridge) damager).bridge$getBukkitEntity(), CraftItemStack.asCraftMirror((ItemStack) (Object) this), i); + event.getPlayer().getServer().getPluginManager().callEvent(event); + + if (i != event.getDamage() || event.isCancelled()) { + event.getPlayer().updateInventory(); + } + if (event.isCancelled()) { + return -1; + } + return event.getDamage(); } - if (event.isCancelled()) { - return -1; - } - return event.getDamage(); + return i; } - return i; } @Inject(method = "hurtAndBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V")) diff --git a/arclight-common/src/main/resources/mixins.arclight.core.json b/arclight-common/src/main/resources/mixins.arclight.core.json index 94d17563..5b413e21 100644 --- a/arclight-common/src/main/resources/mixins.arclight.core.json +++ b/arclight-common/src/main/resources/mixins.arclight.core.json @@ -288,6 +288,7 @@ "world.item.FlintAndSteelItemMixin", "world.item.HangingEntityItemMixin", "world.item.ItemStackMixin", + "world.item.ItemStackMixin$TheVaultCompat", "world.item.LeadItemMixin", "world.item.MapItemMixin", "world.item.MerchantMixin",