Fix mixin conflict with the vault (#824)

They use overwrite
This commit is contained in:
IzzelAliz 2022-12-08 20:29:03 +08:00
parent c140e8b150
commit 32a1b3bcde
No known key found for this signature in database
GPG Key ID: EE50E123A11D8338
3 changed files with 32 additions and 27 deletions

View File

@ -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)) {
@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;
}
}

View File

@ -69,7 +69,11 @@ public abstract class ItemStackMixin extends CapabilityProvider<ItemStack> imple
this.convertStack(version);
}
@ModifyVariable(method = "hurt", index = 1, name = "amount", at = @At(value = "JUMP", opcode = Opcodes.IFGT, ordinal = 0))
// https://github.com/IzzelAliz/Arclight/issues/824
@Mixin(value = ItemStack.class, priority = 1500)
public static class TheVaultCompat {
@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);
@ -85,6 +89,7 @@ public abstract class ItemStackMixin extends CapabilityProvider<ItemStack> imple
}
return i;
}
}
@Inject(method = "hurtAndBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V"))
private <T extends LivingEntity> void arclight$itemBreak(int amount, T entityIn, Consumer<T> onBroken, CallbackInfo ci) {

View File

@ -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",