use of net.minecraft.entity.projectile.EntityArrow in project Tale-of-Kingdoms by Ivasik78.
the class EntityHired method attackEntity.
protected void attackEntity(Entity entity, float f) {
if (defaultHeldItem.getItem() == Item.getItemById(267)) {
if (this.attackTime <= 0 && f < 2.0F && entity.boundingBox.maxY > this.boundingBox.minY && entity.boundingBox.minY < this.boundingBox.maxY) {
this.swingItem();
this.attackTime = 20;
this.attackEntityAsMob(entity);
}
} else if (f < 10.0F) {
double d = entity.posX - this.posX;
double d1 = entity.posZ - this.posZ;
if (this.attackTime == 0) {
EntityArrow entityarrow = new EntityArrow(this.worldObj, this, 1.0F);
double d2 = entity.posY + (double) entity.getEyeHeight() - 0.699999988079071D - entityarrow.posY;
float f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F;
this.worldObj.playSoundAtEntity(this, "random.bow", 1.0F, 1.0F / (this.random.nextFloat() * 0.4F + 0.8F));
this.worldObj.spawnEntityInWorld(entityarrow);
entityarrow.setThrowableHeading(d, d2 + (double) f1, d1, 1.6F, 12.0F);
this.attackTime = 30;
}
this.rotationYaw = (float) (Math.atan2(d1, d) * 180.0D / 3.1415927410125732D) - 90.0F;
this.hasAttacked = true;
}
}
use of net.minecraft.entity.projectile.EntityArrow in project Tale-of-Kingdoms by Ivasik78.
the class EntityReficulGuardian method attackEntity.
protected void attackEntity(Entity entity, float f) {
if (f < 10.0F) {
double d = entity.posX - this.posX;
double d1 = entity.posZ - this.posZ;
if (this.attackTime == 0) {
EntityArrow entityarrow = new EntityArrow(this.worldObj, this, 1.0F);
double d2 = entity.posY + (double) entity.getEyeHeight() - 0.699999988079071D - entityarrow.posY;
float f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F;
this.worldObj.playSoundAtEntity(this, "random.bow", 1.0F, 1.0F / (this.worldObj.rand.nextFloat() * 0.4F + 0.8F));
if (this.worldObj.rand.nextInt(8) != 0) {
this.worldObj.spawnEntityInWorld(entityarrow);
entityarrow.setThrowableHeading(d, d2 + (double) f1, d1, 1.6F, 12.0F);
}
this.attackTime = 30;
}
this.rotationYaw = (float) (Math.atan2(d1, d) * 180.0D / 3.1415927410125732D) - 90.0F;
this.hasAttacked = true;
}
}
use of net.minecraft.entity.projectile.EntityArrow in project takumicraft by TNTModders.
the class TakumiExplosion method doExplosionA.
/**
* Does the first part of the explosion (destroy blocks)
*/
@Override
public void doExplosionA() {
Set<BlockPos> set = Sets.newHashSet();
int i = 16;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = j / 15.0F * 2.0F - 1.0F;
double d1 = k / 15.0F * 2.0F - 1.0F;
double d2 = l / 15.0F * 2.0F - 1.0F;
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = this.size * (0.7F + this.world.rand.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
IBlockState iblockstate = this.world.getBlockState(blockpos);
if (iblockstate.getMaterial() != Material.AIR) {
float f2 = this.exploder != null ? this.exploder.getExplosionResistance(this, this.world, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(world, blockpos, null, this);
f -= (f2 + 0.3F) * 0.3F;
}
if (f > 0.0F && (this.exploder == null || this.exploder.canExplosionDestroyBlock(this, this.world, blockpos, iblockstate, f))) {
set.add(blockpos);
}
d4 += d0 * 0.30000001192092896D;
d6 += d1 * 0.30000001192092896D;
d8 += d2 * 0.30000001192092896D;
}
}
}
}
}
this.affectedBlockPositions.addAll(set);
float f3 = this.size * 2.0F;
int k1 = MathHelper.floor(this.x - f3 - 1.0D);
int l1 = MathHelper.floor(this.x + f3 + 1.0D);
int i2 = MathHelper.floor(this.y - f3 - 1.0D);
int i1 = MathHelper.floor(this.y + f3 + 1.0D);
int j2 = MathHelper.floor(this.z - f3 - 1.0D);
int j1 = MathHelper.floor(this.z + f3 + 1.0D);
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB(k1, i2, j2, l1, i1, j1));
ForgeEventFactory.onExplosionDetonate(this.world, this, list, f3);
Vec3d vec3d = new Vec3d(this.x, this.y, this.z);
for (Entity entity : list) {
if (!entity.isImmuneToExplosions()) {
double d12 = entity.getDistance(this.x, this.y, this.z) / f3;
if (d12 <= 1.0D) {
double d5 = entity.posX - this.x;
double d7 = entity.posY + entity.getEyeHeight() - this.y;
double d9 = entity.posZ - this.z;
double d13 = MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = this.world.getBlockDensity(vec3d, entity.getEntityBoundingBox());
double d10 = (1.0D - d12) * d14;
if (exploder instanceof EntityArrow) {
entity.attackEntityFrom(new EntityDamageSourceIndirect("explosion", ((EntityArrow) this.exploder).shootingEntity, this.exploder).setExplosion(), (int) ((d10 * d10 + d10) / 2.0D * 7.0D * f3 + 1.0D));
} else {
entity.attackEntityFrom(new EntityDamageSource("explosion", this.exploder).setExplosion(), (int) ((d10 * d10 + d10) / 2.0D * 7.0D * f3 + 1.0D));
}
d10 = d10 * this.amp;
double d11 = d10;
if (entity instanceof EntityLivingBase) {
d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase) entity, d10);
}
entity.motionX += d5 * d11;
entity.motionY += d7 * d11;
entity.motionZ += d9 * d11;
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.capabilities.isFlying)) {
this.playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
use of net.minecraft.entity.projectile.EntityArrow in project takumicraft by TNTModders.
the class ItemMagicBow method onPlayerStoppedUsing.
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
if (entityLiving instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entityLiving;
boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = this.findAmmo(entityplayer);
int i = this.getMaxItemUseDuration(stack) - timeLeft;
i = ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
if (i < 0) {
return;
}
if (!itemstack.isEmpty() || flag) {
if (itemstack.isEmpty()) {
itemstack = new ItemStack(Items.ARROW);
}
float f = getArrowVelocity(i);
if ((double) f >= 0.1D) {
boolean flag1 = entityplayer.capabilities.isCreativeMode || itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer);
if (!worldIn.isRemote) {
for (int i1 = -2; i1 <= 2; i1++) {
ItemArrow itemarrow = (ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, (float) (entityplayer.rotationYaw + 15 * i1 / Math.PI), 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F) {
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0) {
entityarrow.setDamage(entityarrow.getDamage() + (double) j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0) {
entityarrow.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
entityarrow.setFire(100);
}
stack.damageItem(1, entityplayer);
entityarrow.pickupStatus = PickupStatus.CREATIVE_ONLY;
worldIn.spawnEntity(entityarrow);
}
}
worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1 && !entityplayer.capabilities.isCreativeMode) {
itemstack.shrink(1);
if (itemstack.isEmpty()) {
entityplayer.inventory.deleteStack(itemstack);
}
}
entityplayer.addStat(StatList.getObjectUseStats(this));
}
}
}
}
use of net.minecraft.entity.projectile.EntityArrow in project takumicraft by TNTModders.
the class EntitySkeletonCreeper method attackEntityWithRangedAttack.
/**
* Attack the specified entity using a ranged attack.
*/
@Override
public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor) {
EntityArrow entityarrow = this.getArrow(distanceFactor);
double d0 = target.posX - this.posX;
double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityarrow.posY;
double d2 = target.posZ - this.posZ;
double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
entityarrow.setThrowableHeading(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - this.world.getDifficulty().getDifficultyId() * 4));
this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
this.world.spawnEntity(entityarrow);
}
Aggregations