Search in sources :

Example 6 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class PlayerEntityMixin method attackTargetEntityWithCurrentItem.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void attackTargetEntityWithCurrentItem(final Entity entity) {
    if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget((PlayerEntity) (Object) this, entity))
        return;
    if (entity.canBeAttackedWithItem() && !entity.hitByEntity((PlayerEntity) (Object) this)) {
        float f = (float) this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getValue();
        float f2;
        if (entity instanceof LivingEntity) {
            f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((LivingEntity) entity).getCreatureAttribute());
        } else {
            f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), CreatureAttribute.UNDEFINED);
        }
        final float f3 = this.getCooledAttackStrength(0.5f);
        f *= 0.2f + f3 * f3 * 0.8f;
        f2 *= f3;
        this.resetCooldown();
        if (f > 0.0f || f2 > 0.0f) {
            final boolean flag = f3 > 0.9f;
            boolean flag2 = false;
            final byte b0 = 0;
            int i = b0 + EnchantmentHelper.getKnockbackModifier((PlayerEntity) (Object) this);
            if (this.isSprinting() && flag) {
                this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.getSoundCategory(), 1.0f, 1.0f);
                ++i;
                flag2 = true;
            }
            boolean flag3 = flag && this.fallDistance > 0.0f && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Effects.BLINDNESS) && !this.isPassenger() && entity instanceof LivingEntity;
            net.minecraftforge.event.entity.player.CriticalHitEvent hitResult = net.minecraftforge.common.ForgeHooks.getCriticalHit((PlayerEntity) (Object) this, entity, flag3, flag3 ? 1.5F : 1.0F);
            flag3 = hitResult != null;
            if (flag3) {
                f *= hitResult.getDamageModifier();
            }
            f += f2;
            boolean flag4 = false;
            final double d0 = this.distanceWalkedModified - this.prevDistanceWalkedModified;
            if (flag && !flag3 && !flag2 && this.onGround && d0 < this.getAIMoveSpeed()) {
                final ItemStack itemstack = this.getHeldItem(Hand.MAIN_HAND);
                if (itemstack.getItem() instanceof SwordItem) {
                    flag4 = true;
                }
            }
            float f4 = 0.0f;
            boolean flag5 = false;
            final int j = EnchantmentHelper.getFireAspectModifier((PlayerEntity) (Object) this);
            if (entity instanceof LivingEntity) {
                f4 = ((LivingEntity) entity).getHealth();
                if (j > 0 && !entity.isBurning()) {
                    final EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), 1);
                    Bukkit.getPluginManager().callEvent(combustEvent);
                    if (!combustEvent.isCancelled()) {
                        flag5 = true;
                        ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false);
                    }
                }
            }
            final Vec3d vec3d = entity.getMotion();
            final boolean flag6 = entity.attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity) (Object) this), f);
            if (flag6) {
                if (i > 0) {
                    if (entity instanceof LivingEntity) {
                        ((LivingEntity) entity).knockBack((PlayerEntity) (Object) this, i * 0.5f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
                    } else {
                        entity.addVelocity(-MathHelper.sin(this.rotationYaw * 0.017453292f) * i * 0.5f, 0.1, MathHelper.cos(this.rotationYaw * 0.017453292f) * i * 0.5f);
                    }
                    this.setMotion(this.getMotion().mul(0.6, 1.0, 0.6));
                    this.setSprinting(false);
                }
                if (flag4) {
                    final float f5 = 1.0f + EnchantmentHelper.getSweepingDamageRatio((PlayerEntity) (Object) this) * f;
                    final List<LivingEntity> list = this.world.getEntitiesWithinAABB((Class<? extends LivingEntity>) LivingEntity.class, entity.getBoundingBox().grow(1.0, 0.25, 1.0));
                    for (final LivingEntity entityliving : list) {
                        if (entityliving != (Object) this && entityliving != entity && !this.isOnSameTeam(entityliving) && (!(entityliving instanceof ArmorStandEntity) || !((ArmorStandEntity) entityliving).hasMarker()) && this.getDistanceSq(entityliving) < 9.0 && entityliving.attackEntityFrom(((DamageSourceBridge) DamageSource.causePlayerDamage((PlayerEntity) (Object) this)).bridge$sweep(), f5)) {
                            entityliving.knockBack((PlayerEntity) (Object) this, 0.4f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
                        }
                    }
                    this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0f, 1.0f);
                    this.spawnSweepParticles();
                }
                if (entity instanceof ServerPlayerEntity && entity.velocityChanged) {
                    boolean cancelled = false;
                    final Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity();
                    final Vector velocity = CraftVector.toBukkit(vec3d);
                    final PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
                    Bukkit.getPluginManager().callEvent(event);
                    if (event.isCancelled()) {
                        cancelled = true;
                    } else if (!velocity.equals(event.getVelocity())) {
                        player.setVelocity(event.getVelocity());
                    }
                    if (!cancelled) {
                        ((ServerPlayerEntity) entity).connection.sendPacket(new SEntityVelocityPacket(entity));
                        entity.velocityChanged = false;
                        entity.setMotion(vec3d);
                    }
                }
                if (flag3) {
                    this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0f, 1.0f);
                    this.onCriticalHit(entity);
                }
                if (!flag3 && !flag4) {
                    if (flag) {
                        this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0f, 1.0f);
                    } else {
                        this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0f, 1.0f);
                    }
                }
                if (f2 > 0.0f) {
                    this.onEnchantmentCritical(entity);
                }
                this.setLastAttackedEntity(entity);
                if (entity instanceof LivingEntity) {
                    EnchantmentHelper.applyThornEnchantments((LivingEntity) entity, (PlayerEntity) (Object) this);
                }
                EnchantmentHelper.applyArthropodEnchantments((PlayerEntity) (Object) this, entity);
                final ItemStack itemstack2 = this.getHeldItemMainhand();
                Object object = entity;
                if (entity instanceof EnderDragonPartEntity) {
                    object = ((EnderDragonPartEntity) entity).dragon;
                }
                if (!this.world.isRemote && !itemstack2.isEmpty() && object instanceof LivingEntity) {
                    ItemStack copy = itemstack2.copy();
                    itemstack2.hitEntity((LivingEntity) object, (PlayerEntity) (Object) this);
                    if (itemstack2.isEmpty()) {
                        net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem((PlayerEntity) (Object) this, copy, Hand.MAIN_HAND);
                        this.setHeldItem(Hand.MAIN_HAND, ItemStack.EMPTY);
                    }
                }
                if (entity instanceof LivingEntity) {
                    final float f6 = f4 - ((LivingEntity) entity).getHealth();
                    this.addStat(Stats.DAMAGE_DEALT, Math.round(f6 * 10.0f));
                    if (j > 0) {
                        final EntityCombustByEntityEvent combustEvent2 = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), j * 4);
                        Bukkit.getPluginManager().callEvent(combustEvent2);
                        if (!combustEvent2.isCancelled()) {
                            ((EntityBridge) entity).bridge$setOnFire(combustEvent2.getDuration(), false);
                        }
                    }
                    if (this.world instanceof ServerWorld && f6 > 2.0f) {
                        final int k = (int) (f6 * 0.5);
                        ((ServerWorld) this.world).spawnParticle(ParticleTypes.DAMAGE_INDICATOR, entity.posX, entity.posY + entity.getHeight() * 0.5f, entity.posZ, k, 0.1, 0.0, 0.1, 0.2);
                    }
                }
                this.addExhaustion(0.1f);
            } else {
                this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0f, 1.0f);
                if (flag5) {
                    entity.extinguish();
                }
                if (this instanceof ServerPlayerEntityBridge) {
                    ((ServerPlayerEntityBridge) this).bridge$getBukkitEntity().updateInventory();
                }
            }
        }
    }
}
Also used : PlayerVelocityEvent(org.bukkit.event.player.PlayerVelocityEvent) SwordItem(net.minecraft.item.SwordItem) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) ServerWorld(net.minecraft.world.server.ServerWorld) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) ArmorStandEntity(net.minecraft.entity.item.ArmorStandEntity) Vector(org.bukkit.util.Vector) CraftVector(org.bukkit.craftbukkit.v.util.CraftVector) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) DamageSourceBridge(io.izzel.arclight.common.bridge.util.DamageSourceBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) EnderDragonPartEntity(net.minecraft.entity.boss.dragon.EnderDragonPartEntity) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 7 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class ZombieEntityMixin method arclight$entityCombust.

@Redirect(method = "attackEntityAsMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V"))
private void arclight$entityCombust(Entity entity, int seconds) {
    EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        ((EntityBridge) entity).bridge$setOnFire(event.getDuration(), false);
    }
}
Also used : MobEntityBridge(io.izzel.arclight.common.bridge.entity.MobEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 8 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class ZombiePigmanEntityMixin_1_15 method arclight$anger.

@Inject(method = "func_226547_i_", cancellable = true, at = @At("HEAD"))
private void arclight$anger(LivingEntity entity, CallbackInfoReturnable<Boolean> cir) {
    PigZombieAngerEvent event = new PigZombieAngerEvent((PigZombie) this.getBukkitEntity(), (entity == null) ? null : ((EntityBridge) entity).bridge$getBukkitEntity(), this.func_223336_ef());
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        cir.setReturnValue(false);
    } else {
        arclight$capture = event.getNewAnger();
    }
}
Also used : PigZombieAngerEvent(org.bukkit.event.entity.PigZombieAngerEvent) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 9 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class HangingEntityItemMixin method arclight$hangingPlace.

@Inject(method = "onItemUse", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/HangingEntity;playPlaceSound()V"))
public void arclight$hangingPlace(ItemUseContext context, CallbackInfoReturnable<ActionResultType> cir, BlockPos blockPos, Direction direction, BlockPos blockPos1, PlayerEntity playerEntity, ItemStack itemStack, World world, HangingEntity hangingEntity) {
    Player who = (context.getPlayer() == null) ? null : (Player) ((PlayerEntityBridge) context.getPlayer()).bridge$getBukkitEntity();
    Block blockClicked = CraftBlock.at(world, blockPos);
    BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
    HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) hangingEntity).bridge$getBukkitEntity(), who, blockClicked, blockFace);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        cir.setReturnValue(ActionResultType.FAIL);
    }
}
Also used : Player(org.bukkit.entity.Player) HangingPlaceEvent(org.bukkit.event.hanging.HangingPlaceEvent) BlockFace(org.bukkit.block.BlockFace) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class FollowOwnerGoalMixin_1_14 method arclight$teleport.

@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/TameableEntity;setLocationAndAngles(DDDFF)V"))
public void arclight$teleport(TameableEntity tameableEntity, double x, double y, double z, float yaw, float pitch) {
    CraftEntity craftEntity = ((EntityBridge) this.tameable).bridge$getBukkitEntity();
    Location location = new Location(craftEntity.getWorld(), x, y, z, yaw, pitch);
    EntityTeleportEvent event = new EntityTeleportEvent(craftEntity, craftEntity.getLocation(), location);
    Bukkit.getPluginManager().callEvent(event);
    if (!(arclight$cancelled = event.isCancelled())) {
        tameableEntity.setLocationAndAngles(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Location(org.bukkit.Location) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)39 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)15 Overwrite (org.spongepowered.asm.mixin.Overwrite)15 Entity (net.minecraft.entity.Entity)13 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 Inject (org.spongepowered.asm.mixin.injection.Inject)10 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)9 LivingEntity (net.minecraft.entity.LivingEntity)9 MobEntity (net.minecraft.entity.MobEntity)9 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)9 BlockPos (net.minecraft.util.math.BlockPos)8 Redirect (org.spongepowered.asm.mixin.injection.Redirect)8 MobEntityBridge (io.izzel.arclight.common.bridge.entity.MobEntityBridge)7 Location (org.bukkit.Location)7 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)6 Vec3d (net.minecraft.util.math.Vec3d)6 EntityCombustByEntityEvent (org.bukkit.event.entity.EntityCombustByEntityEvent)6 PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)5 CraftEntity (org.bukkit.craftbukkit.v.entity.CraftEntity)5 Player (org.bukkit.entity.Player)5