Search in sources :

Example 1 with EntityCombustByEntityEvent

use of org.bukkit.event.entity.EntityCombustByEntityEvent in project Arclight by IzzelAliz.

the class MobEntityMixin method arclight$attackCombust.

@Redirect(method = "attackEntityAsMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V"))
public void arclight$attackCombust(Entity entity, int seconds) {
    EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds);
    org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
    if (!combustEvent.isCancelled()) {
        ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false);
    }
}
Also used : LivingEntityBridge(io.izzel.arclight.common.bridge.entity.LivingEntityBridge) 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 2 with EntityCombustByEntityEvent

use of org.bukkit.event.entity.EntityCombustByEntityEvent 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 3 with EntityCombustByEntityEvent

use of org.bukkit.event.entity.EntityCombustByEntityEvent 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 4 with EntityCombustByEntityEvent

use of org.bukkit.event.entity.EntityCombustByEntityEvent in project Citizens2 by CitizensDev.

the class EventListen method onEntityCombust.

/*
     * Entity events
     */
@EventHandler
public void onEntityCombust(EntityCombustEvent event) {
    NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getEntity());
    if (npc == null)
        return;
    event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
    if (event instanceof EntityCombustByEntityEvent) {
        Bukkit.getPluginManager().callEvent(new NPCCombustByEntityEvent((EntityCombustByEntityEvent) event, npc));
    } else if (event instanceof EntityCombustByBlockEvent) {
        Bukkit.getPluginManager().callEvent(new NPCCombustByBlockEvent((EntityCombustByBlockEvent) event, npc));
    } else {
        Bukkit.getPluginManager().callEvent(new NPCCombustEvent(event, npc));
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) EntityCombustByBlockEvent(org.bukkit.event.entity.EntityCombustByBlockEvent) NPCCombustByBlockEvent(net.citizensnpcs.api.event.NPCCombustByBlockEvent) NPCCombustByEntityEvent(net.citizensnpcs.api.event.NPCCombustByEntityEvent) NPCCombustEvent(net.citizensnpcs.api.event.NPCCombustEvent) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) EventHandler(org.bukkit.event.EventHandler)

Example 5 with EntityCombustByEntityEvent

use of org.bukkit.event.entity.EntityCombustByEntityEvent in project Arclight by IzzelAliz.

the class SmallFireballEntityMixin method onImpact.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected void onImpact(RayTraceResult result) {
    if (ArclightVersion.atLeast(ArclightVersion.v1_15)) {
        super.onImpact(result);
    }
    if (!this.world.isRemote) {
        if (result.getType() == RayTraceResult.Type.ENTITY) {
            Entity entity = ((EntityRayTraceResult) result).getEntity();
            if (!entity.isImmuneToFire()) {
                int i = entity.getFireTimer();
                if (isIncendiary) {
                    EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), 5);
                    Bukkit.getPluginManager().callEvent(event);
                    if (!event.isCancelled()) {
                        ((EntityBridge) entity).bridge$setOnFire(event.getDuration(), false);
                    }
                }
                boolean flag = entity.attackEntityFrom(DamageSource.causeFireballDamage((SmallFireballEntity) (Object) this, this.shootingEntity), 5.0F);
                if (flag) {
                    this.applyEnchantments(this.shootingEntity, entity);
                } else {
                    entity.setFireTimer(i);
                }
            }
        } else if (isIncendiary && this.shootingEntity == null || !(this.shootingEntity instanceof MobEntity) || ForgeEventFactory.getMobGriefingEvent(this.world, this.shootingEntity)) {
            BlockRayTraceResult blockraytraceresult = (BlockRayTraceResult) result;
            BlockPos blockpos = blockraytraceresult.getPos().offset(blockraytraceresult.getFace());
            if (this.world.isAirBlock(blockpos) && !CraftEventFactory.callBlockIgniteEvent(this.world, blockpos, (SmallFireballEntity) (Object) this).isCancelled()) {
                this.world.setBlockState(blockpos, Blocks.FIRE.getDefaultState());
            }
        }
        this.remove();
    }
}
Also used : Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) MobEntity(net.minecraft.entity.MobEntity) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) MobEntity(net.minecraft.entity.MobEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

EntityCombustByEntityEvent (org.bukkit.event.entity.EntityCombustByEntityEvent)7 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)6 Redirect (org.spongepowered.asm.mixin.injection.Redirect)4 MobEntityBridge (io.izzel.arclight.common.bridge.entity.MobEntityBridge)3 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)3 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)2 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)2 LivingEntity (net.minecraft.entity.LivingEntity)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)1 DamageSourceBridge (io.izzel.arclight.common.bridge.util.DamageSourceBridge)1 NPCCombustByBlockEvent (net.citizensnpcs.api.event.NPCCombustByBlockEvent)1 NPCCombustByEntityEvent (net.citizensnpcs.api.event.NPCCombustByEntityEvent)1 NPCCombustEvent (net.citizensnpcs.api.event.NPCCombustEvent)1 NPC (net.citizensnpcs.api.npc.NPC)1 Entity (net.minecraft.entity.Entity)1 MobEntity (net.minecraft.entity.MobEntity)1 EnderDragonPartEntity (net.minecraft.entity.boss.dragon.EnderDragonPartEntity)1 ArmorStandEntity (net.minecraft.entity.item.ArmorStandEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1