Search in sources :

Example 6 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project Enigmatic-Legacy by Aizistral-Studios.

the class EnigmaticEventHandler method onEntityAttacked.

@SubscribeEvent
public void onEntityAttacked(LivingAttackEvent event) {
    if (event.getEntityLiving().world.isRemote)
        return;
    if (event.getEntityLiving() instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) event.getEntityLiving();
        if (EtheriumArmor.hasShield(player)) {
            if (event.getSource().getImmediateSource() instanceof DamagingProjectileEntity || event.getSource().getImmediateSource() instanceof AbstractArrowEntity) {
                event.setCanceled(true);
                player.world.playSound(null, player.getPosition(), EnigmaticLegacy.SHIELD_TRIGGER, SoundCategory.PLAYERS, 1.0F, 0.9F + (float) (Math.random() * 0.1D));
                player.world.playSound(null, player.getPosition(), EnigmaticLegacy.SHIELD_TRIGGER, SoundCategory.PLAYERS, 1.0F, 0.9F + (float) (Math.random() * 0.1D));
            }
        }
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.enigmaticItem))
            if (EnigmaticItem.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.angelBlessing))
            if (AngelBlessing.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.oceanStone))
            if (OceanStone.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.magmaHeart))
            if (MagmaHeart.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.golemHeart))
            if (GolemHeart.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.voidPearl)) {
            if (VoidPearl.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
            else if (VoidPearl.healList.contains(event.getSource().damageType)) {
                player.heal(event.getAmount());
                event.setCanceled(true);
            } else {
            }
        }
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.eyeOfNebula)) {
            if (EyeOfNebula.immunityList.contains(event.getSource().damageType)) {
                event.setCanceled(true);
            } else if (Math.random() <= ConfigHandler.EYE_OF_NEBULA_DODGE_PROBABILITY.getValue().asMultiplier(false) && player.hurtResistantTime <= 10 && event.getSource().getTrueSource() instanceof LivingEntity) {
                for (int counter = 0; counter <= 32; counter++) {
                    if (SuperpositionHandler.validTeleportRandomly(player, player.world, (int) ConfigHandler.EYE_OF_NEBULA_DODGE_RANGE.getValue()))
                        break;
                }
                player.hurtResistantTime = 20;
                event.setCanceled(true);
            }
        }
    } else if (event.getSource().getImmediateSource() instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) event.getSource().getImmediateSource();
        if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() == EnigmaticLegacy.extradimensionalEye)
            if (ItemNBTHelper.verifyExistance(player.getHeldItemMainhand(), "BoundDimension"))
                if (ItemNBTHelper.getInt(player.getHeldItemMainhand(), "BoundDimension", 0) == event.getEntityLiving().dimension.getId()) {
                    event.setCanceled(true);
                    ItemStack stack = player.getHeldItemMainhand();
                    EnigmaticLegacy.packetInstance.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ, 128, event.getEntityLiving().dimension)), new PacketPortalParticles(event.getEntityLiving().posX, event.getEntityLiving().posY + (event.getEntityLiving().getHeight() / 2), event.getEntityLiving().posZ, 96, 1.5D, false));
                    event.getEntityLiving().world.playSound(null, event.getEntityLiving().getPosition(), SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1.0F, (float) (0.8F + (Math.random() * 0.2)));
                    event.getEntityLiving().setPositionAndUpdate(ItemNBTHelper.getDouble(stack, "BoundX", 0D), ItemNBTHelper.getDouble(stack, "BoundY", 0D), ItemNBTHelper.getDouble(stack, "BoundZ", 0D));
                    event.getEntityLiving().world.playSound(null, event.getEntityLiving().getPosition(), SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1.0F, (float) (0.8F + (Math.random() * 0.2)));
                    EnigmaticLegacy.packetInstance.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ, 128, event.getEntityLiving().dimension)), new PacketRecallParticles(event.getEntityLiving().posX, event.getEntityLiving().posY + (event.getEntityLiving().getHeight() / 2), event.getEntityLiving().posZ, 48, false));
                    if (!player.abilities.isCreativeMode)
                        stack.shrink(1);
                }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) PacketRecallParticles(com.integral.enigmaticlegacy.packets.clients.PacketRecallParticles) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) PacketPortalParticles(com.integral.enigmaticlegacy.packets.clients.PacketPortalParticles) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 7 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project Enigmatic-Legacy by Aizistral-Studios.

the class AngelBlessing method redirect.

public void redirect(LivingEntity bearer, Entity redirected) {
    if (redirected instanceof UltimateWitherSkullEntity || redirected instanceof WitherSkullEntity)
        return;
    /*if (redirected instanceof TridentEntity)
	 	 if (((TridentEntity)redirected).getShooter() == bearer)
	 		 return;*/
    Vector3 entityPos = Vector3.fromEntityCenter(redirected);
    Vector3 bearerPos = Vector3.fromEntityCenter(bearer);
    Vector3 redirection = entityPos.subtract(bearerPos);
    redirection = redirection.normalize();
    if (redirected instanceof AbstractArrowEntity && ((AbstractArrowEntity) redirected).getShooter() == bearer) {
        if (redirected instanceof TridentEntity) {
            TridentEntity trident = (TridentEntity) redirected;
            if (trident.returningTicks > 0)
                return;
        }
        redirected.setMotion(redirected.getMotion().x * 1.75D, redirected.getMotion().y * 1.75D, redirected.getMotion().z * 1.75D);
    } else
        redirected.setMotion(redirection.x, redirection.y, redirection.z);
    if (redirected instanceof DamagingProjectileEntity) {
        DamagingProjectileEntity redirectedProjectile = (DamagingProjectileEntity) redirected;
        redirectedProjectile.accelerationX = (redirection.x / 4.0);
        redirectedProjectile.accelerationY = (redirection.y / 4.0);
        redirectedProjectile.accelerationZ = (redirection.z / 4.0);
    }
}
Also used : UltimateWitherSkullEntity(com.integral.enigmaticlegacy.entities.UltimateWitherSkullEntity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) Vector3(com.integral.enigmaticlegacy.helpers.Vector3) TridentEntity(net.minecraft.entity.projectile.TridentEntity) UltimateWitherSkullEntity(com.integral.enigmaticlegacy.entities.UltimateWitherSkullEntity) WitherSkullEntity(net.minecraft.entity.projectile.WitherSkullEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 8 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project Enigmatic-Legacy by Aizistral-Studios.

the class AngelBlessing method onCurioTick.

@Override
public void onCurioTick(String identifier, LivingEntity living) {
    List<DamagingProjectileEntity> projectileEntities = living.world.getEntitiesWithinAABB(DamagingProjectileEntity.class, new AxisAlignedBB(living.posX - range, living.posY - range, living.posZ - range, living.posX + range, living.posY + range, living.posZ + range));
    List<AbstractArrowEntity> arrowEntities = living.world.getEntitiesWithinAABB(AbstractArrowEntity.class, new AxisAlignedBB(living.posX - range, living.posY - range, living.posZ - range, living.posX + range, living.posY + range, living.posZ + range));
    List<PotionEntity> potionEntities = living.world.getEntitiesWithinAABB(PotionEntity.class, new AxisAlignedBB(living.posX - range, living.posY - range, living.posZ - range, living.posX + range, living.posY + range, living.posZ + range));
    for (DamagingProjectileEntity entity : projectileEntities) this.redirect(living, entity);
    for (AbstractArrowEntity entity : arrowEntities) this.redirect(living, entity);
    for (PotionEntity entity : potionEntities) this.redirect(living, entity);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 9 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIAttackRanged method checkAndPerformAttack.

protected void checkAndPerformAttack(LivingEntity attackTarget) {
    if (this.entity.tickCount > this.prevTimeAttacked + this.getAttackCooldown()) {
        if (this.getAttackChargeTicks() > 0) {
            this.entity.startUsingItem(Hand.MAIN_HAND);
            this.entity.swinging = true;
        }
        if (this.entity.getUseItemRemainingTicks() >= this.getAttackChargeTicks()) {
            ItemStack stack = this.getEquippedWeapon();
            Item item = stack.getItem();
            if (item instanceof BowItem) {
                ItemStack arrowItem = this.entity.getItemStackFromExtraSlot(EntityEquipmentExtraSlot.ARROW);
                if (arrowItem.isEmpty() || !(arrowItem.getItem() instanceof ArrowItem)) {
                    arrowItem = new ItemStack(Items.ARROW);
                }
                AbstractArrowEntity arrow = ((ArrowItem) arrowItem.getItem()).createArrow(this.world, arrowItem, this.entity);
                // arrowItem.shrink(1);
                double x = attackTarget.getX() - this.entity.getX();
                double y = attackTarget.getY() + attackTarget.getBbHeight() * 0.5D - arrow.getY();
                double z = attackTarget.getZ() - this.entity.getZ();
                double distance = Math.sqrt(x * x + z * z);
                arrow.shoot(x, y + distance * distance * 0.0045D, z, 2.4F, this.getInaccuracy());
                /*arrow.motionX += this.entity.motionX;
					arrow.motionZ += this.entity.motionZ;
					if (!this.entity.onGround) {
						arrow.motionY += this.entity.motionY;
					}*/
                Vector3d shooterVec = this.entity.getDeltaMovement();
                arrow.setDeltaMovement(arrow.getDeltaMovement().add(shooterVec.x(), this.entity.isOnGround() ? 0 : shooterVec.y(), shooterVec.z()));
                this.world.addFreshEntity(arrow);
                this.entity.playSound(SoundEvents.ARROW_SHOOT, 1.0F, 0.8F + this.random.nextFloat() * 0.4F);
            } else if (item instanceof IRangedWeapon) {
                ((IRangedWeapon) item).shoot(this.world, this.entity, attackTarget, Hand.MAIN_HAND);
                if (((IRangedWeapon) item).getShootSound() != null) {
                    this.entity.playSound(((IRangedWeapon) item).getShootSound(), 1.0F, 0.8F + this.random.nextFloat() * 0.4F);
                }
            }
            this.prevTimeAttacked = this.entity.tickCount;
            if (this.getAttackChargeTicks() > 0) {
                this.entity.stopUsingItem();
                this.entity.swinging = false;
            } else {
                this.entity.startUsingItem(Hand.MAIN_HAND);
            }
        }
    }
}
Also used : Item(net.minecraft.item.Item) ArrowItem(net.minecraft.item.ArrowItem) BowItem(net.minecraft.item.BowItem) Vector3d(net.minecraft.util.math.vector.Vector3d) IRangedWeapon(team.cqr.cqrepoured.item.IRangedWeapon) BowItem(net.minecraft.item.BowItem) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 10 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityCQRWalkerKing method hurt.

@Override
public boolean hurt(DamageSource source, float amount, boolean sentFromPart) {
    if (source == DamageSource.WITHER) {
        this.heal(amount / 2);
        return true;
    }
    if (source == DamageSource.FALL) {
        return true;
    }
    if (source == DamageSource.IN_WALL && this.hasAttackTarget() && this.isServerWorld()) {
        EntityWalkerKingIllusion illusion = new EntityWalkerKingIllusion(1200, this, this.getWorld());
        illusion.setPos(this.getX(), this.getY(), this.getZ());
        this.level.addFreshEntity(illusion);
        this.teleportBehindEntity(this.getTarget(), true);
        this.canAttack(this.getTarget());
        return false;
    }
    /*
		 * boolean spectralFlag = false;
		 * if (source.getTrueSource() instanceof EntityLivingBase) {
		 * if (EnchantmentHelper.getEnchantmentLevel(CQREnchantments.SPECTRAL, ((EntityLivingBase)
		 * source.getTrueSource()).getHeldItemMainhand()) > 0 ||
		 * EnchantmentHelper.getEnchantmentLevel(CQREnchantments.SPECTRAL, ((EntityLivingBase)
		 * source.getTrueSource()).getHeldItemOffhand()) > 0) {
		 * amount *= 2;
		 * spectralFlag = true;
		 * }
		 * }
		 */
    if (/* !spectralFlag && */
    ((source.getDirectEntity() == null) || !(source.getDirectEntity() instanceof SpectralArrowEntity)) && !CQRConfig.bosses.armorForTheWalkerKing) {
        amount *= 0.5F;
    }
    if (source.getDirectEntity() != null) {
        if (source.getDirectEntity() instanceof SpectralArrowEntity) {
            amount *= 2;
            super.hurt(source, amount, sentFromPart);
            return true;
        }
        if ((source.getDirectEntity() instanceof ThrowableEntity || source.getDirectEntity() instanceof AbstractArrowEntity) && !this.level.isClientSide) {
            // STAB HIM IN THE BACK!!
            this.backStabAttacker(source);
            return false;
        }
    }
    this.handleActivation();
    if (source.getEntity() != null && !this.level.isClientSide) {
        ResourceLocation resLoc = EntityList.getKey(source.getEntity());
        if (resLoc != null) {
            // Start IceAndFire compatibility
            boolean flag = resLoc.getNamespace().equalsIgnoreCase("iceandfire") && CQRConfig.advanced.enableSpecialFeatures;
            if (flag) {
                amount /= 2;
            }
            // End IceAndFire compatibility
            Faction fac = FactionRegistry.instance(this).getFactionOf(source.getEntity());
            boolean dragonFactionFlag = fac != null && (fac.getName().equalsIgnoreCase("DRAGON") || fac.getName().equalsIgnoreCase("DRAGONS"));
            // If we are attacked by a dragon: KILL IT
            if (this.dragonAttackCooldown <= 0 && (dragonFactionFlag || resLoc.getPath().contains("dragon") || resLoc.getPath().contains("wyrm") || resLoc.getPath().contains("wyvern") || flag)) {
                this.dragonAttackCooldown = 80;
                this.handleAttackedByDragon(source.getEntity());
            }
        }
    }
    if (!this.level.isClientSide && source.getEntity() instanceof LivingEntity) {
        // How about killing the one who tries with the axe?
        // Maybe move this whole ability to the king shield itself??
        ItemStack shieldStack = this.getItemBySlot(EquipmentSlotType.OFFHAND);
        if (amount > 0F && this.canBlockDamageSource(source) && shieldStack != null && !shieldStack.isEmpty() && shieldStack.getItem() instanceof ShieldItem) {
            this.playSound(CQRSounds.WALKER_KING_LAUGH, 10.0F, 1.0F);
            if (source.getDirectEntity() instanceof LivingEntity && /* && (source.getImmediateSource() instanceof EntityPlayer) */
            ((LivingEntity) source.getDirectEntity()).getMainHandItem().getItem() instanceof AxeItem) {
                if (DungeonGenUtils.percentageRandom(0.75, this.getRandom())) {
                    Vector3d v = source.getDirectEntity().position().subtract(this.position()).normalize().scale(1.25);
                    v = v.add(0, 0.75, 0);
                    LivingEntity attacker = (LivingEntity) source.getDirectEntity();
                    /*attacker.motionX = v.x;
						attacker.motionY = v.y;
						attacker.motionZ = v.z;
						attacker.velocityChanged = true;*/
                    attacker.setDeltaMovement(v);
                    attacker.hasImpulse = true;
                    this.swing(Hand.OFF_HAND);
                    return false;
                }
            }
        }
        if (this.getRandom().nextDouble() < 0.2 && source.getEntity() != null) {
            // Revenge Attack
            if (this.getRandom().nextDouble() < 0.7) {
                this.canAttack((LivingEntity) source.getEntity());
                this.playSound(CQRSounds.WALKER_KING_LAUGH, 10.0F, 1.0F);
                this.teleportBehindEntity(source.getEntity());
            }
        }
    }
    return super.hurt(source, amount, sentFromPart);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) EntityWalkerKingIllusion(team.cqr.cqrepoured.entity.misc.EntityWalkerKingIllusion) ShieldItem(net.minecraft.item.ShieldItem) Vector3d(net.minecraft.util.math.vector.Vector3d) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) AxeItem(net.minecraft.item.AxeItem) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) Faction(team.cqr.cqrepoured.faction.Faction) EDefaultFaction(team.cqr.cqrepoured.faction.EDefaultFaction)

Aggregations

AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)40 ItemStack (net.minecraft.item.ItemStack)19 PlayerEntity (net.minecraft.entity.player.PlayerEntity)16 ArrowItem (net.minecraft.item.ArrowItem)7 LivingEntity (net.minecraft.entity.LivingEntity)6 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)6 Entity (net.minecraft.entity.Entity)5 ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)5 Vector3d (net.minecraft.util.math.vector.Vector3d)5 PotionData (org.bukkit.potion.PotionData)5 PotionEntity (net.minecraft.entity.projectile.PotionEntity)4 SpectralArrowEntity (net.minecraft.entity.projectile.SpectralArrowEntity)4 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)4 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)3 EnderPearlEntity (net.minecraft.entity.item.EnderPearlEntity)3 ExperienceBottleEntity (net.minecraft.entity.item.ExperienceBottleEntity)3 CreeperEntity (net.minecraft.entity.monster.CreeperEntity)3 GhastEntity (net.minecraft.entity.monster.GhastEntity)3 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)3