parent
c140e8b150
commit
32a1b3bcde
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,21 +69,26 @@ 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))
|
||||
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"))
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user