/** Attack the specified entity using a ranged attack. */ public void attackEntityWithRangedAttack(EntityLivingBase par1EntityLivingBase, float par2) { EntityArrow var3 = new EntityArrow(this.worldObj, this, par1EntityLivingBase, 1.6F, 4); if (this.bowType == 1) { var3.setDamage(3.5D); } else { var3.setDamage(2.0D); } this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); this.worldObj.spawnEntityInWorld(var3); }
@Override public void executeActivateBehavior(TileEntityTrophy tile, EntityPlayer player) { if (tile.worldObj.isRemote) { return; } double midX = tile.xCoord + 0.5; double midZ = tile.zCoord + 0.5; EntityArrow entityarrow = new EntityArrow(tile.worldObj, midX, tile.yCoord + 1, midZ); entityarrow.setDamage(0.1); entityarrow.setThrowableHeading( tile.worldObj.rand.nextInt(10) - 5, 40, tile.worldObj.rand.nextInt(10) - 5, 1.0f, 6.0f); player.playSound("random.bow", 1.0F, 1.0F / (tile.worldObj.rand.nextFloat() * 0.4F + 0.8F)); tile.worldObj.spawnEntityInWorld(entityarrow); }
@Override public void onUpdate() { super.onUpdate(); if (ticksInGround == 1) { onHitGround(xTile, yTile, zTile); } }
/** * Helper function for onPlayerStoppedUsing() that allows subclasses to easily overwrite how to * apply bow enchantments to the spawned arrow entity * * @param entityarrow * @param stack */ protected void applyEnchantments(EntityArrow entityarrow, ItemStack stack) { 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); } }
@Override public void onEntityCollidedWithBlock( World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { if (!worldIn.isRemote && entityIn instanceof EntityArrow) { EntityArrow entityarrow = (EntityArrow) entityIn; if (entityarrow.isBurning()) { this.explode( worldIn, pos, worldIn.getBlockState(pos).withProperty(EXPLODE, Boolean.valueOf(true)), entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase) entityarrow.shootingEntity : null); worldIn.setBlockToAir(pos); } } }
/** * called when the player releases the use item button. Args: itemstack, world, entityplayer, * itemInUseCount */ @Override public void onPlayerStoppedUsing(ItemStack var1, World var2, EntityPlayer var3, int var4) { int var6 = this.getMaxItemUseDuration(var1) - var4; float var7 = var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if (var7 < 0.1D) return; boolean var8 = false; if (var7 > 1.0F) { if (var7 > 9.0F) { var8 = true; } var7 = 1.0F; } EntityArrow var9 = new EntityArrow(var2, var3, var7 * 2.0F); int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, var1); if (var10 > 0) { var9.setDamage(var9.getDamage() + var10 * 0.5D + 0.5D); } int var11 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, var1); if (var11 > 0) { var9.setKnockbackStrength(var11); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, var1) > 0) { var9.setFire(100); } var1.damageItem(1, var3); var2.playSoundAtEntity( var3, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (!var2.isRemote) { var2.spawnEntityInWorld(var9); } }
/** * called when the player releases the use item button. Args: itemstack, world, entityplayer, * itemInUseCount */ public void onPlayerStoppedUsing( ItemStack p_77615_1_, World p_77615_2_, EntityPlayer p_77615_3_, int p_77615_4_) { boolean var5 = p_77615_3_.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0; if (var5 || p_77615_3_.inventory.hasItem(Items.arrow)) { int var6 = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_; float var7 = (float) var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double) var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(p_77615_2_, p_77615_3_, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double) var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0) { var8.setFire(100); } p_77615_1_.damageItem(1, p_77615_3_); p_77615_2_.playSoundAtEntity( p_77615_3_, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { p_77615_3_.inventory.consumeInventoryItem(Items.arrow); } if (!p_77615_2_.isClient) { p_77615_2_.spawnEntityInWorld(var8); } } }
/** * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, * y, z, entity */ public void onEntityCollidedWithBlock( World p_149670_1_, int p_149670_2_, int p_149670_3_, int p_149670_4_, Entity p_149670_5_) { if (p_149670_5_ instanceof EntityArrow && !p_149670_1_.isRemote) { EntityArrow entityarrow = (EntityArrow) p_149670_5_; if (entityarrow.isBurning()) { this.func_150114_a( p_149670_1_, p_149670_2_, p_149670_3_, p_149670_4_, 1, entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase) entityarrow.shootingEntity : null); p_149670_1_.setBlockToAir(p_149670_2_, p_149670_3_, p_149670_4_); } } }
@Method(modid = "battlegear2") @Override public boolean catchArrow(ItemStack shield, EntityPlayer player, IProjectile projectile) { if (toolMaterial == ToolMaterial.WOOD && projectile instanceof EntityArrow) { setArrowCount(shield, getArrowCount(shield) + 1); player.setArrowCountInEntity(player.getArrowCountInEntity() - 1); ((EntityArrow) projectile).setDead(); return true; } return false; }
/** Attack the specified entity using a ranged attack. */ public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_) { EntityArrow entityarrow = new EntityArrow( this.worldObj, this, p_82196_1_, 1.6F, (float) (14 - this.worldObj.difficultySetting.getDifficultyId() * 4)); int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem()); int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem()); entityarrow.setDamage( (double) (p_82196_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double) ((float) this.worldObj.difficultySetting.getDifficultyId() * 0.11F)); if (i > 0) { entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D); } if (j > 0) { entityarrow.setKnockbackStrength(j); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0 || this.getSkeletonType() == 1) { entityarrow.setFire(100); } this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); this.worldObj.spawnEntityInWorld(entityarrow); }
public void onPlayerStoppedUsing( ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft) { boolean var5 = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0; if (var5 || playerIn.inventory.hasItem(Items.arrow)) { int var6 = this.getMaxItemUseDuration(stack) - timeLeft; float var7 = (float) var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double) var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(worldIn, playerIn, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double) var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) { var8.setFire(100); } stack.damageItem(1, playerIn); worldIn.playSoundAtEntity( playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { playerIn.inventory.consumeInventoryItem(Items.arrow); } playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]); if (!worldIn.isRemote) { worldIn.spawnEntityInWorld(var8); } } }
/** * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define * their attack. */ protected void attackEntity(Entity entity, float f) { if ((entity instanceof EntityPlayer) || (entity instanceof CREEPSEntityHunchback) || (entity instanceof CREEPSEntityHunchbackSkeleton)) { this.setAttackTarget(null); return; } if (f < 10F) { double d = entity.posX - posX; double d1 = entity.posZ - posZ; EntityArrow entityarrow = new EntityArrow(worldObj, this, 1.0F); entityarrow.posY += 1.3999999761581421D; double d2 = entity.posY - 0.20000000298023224D - entityarrow.posY; float f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F; worldObj.playSoundAtEntity(this, "random.bow", 1.0F, 1.0F / (rand.nextFloat() * 0.4F + 0.8F)); worldObj.spawnEntityInWorld(entityarrow); entityarrow.setThrowableHeading(d, d2 + (double) f1, d1, 0.6F, 12F); rotationYaw = (float) ((Math.atan2(d1, d) * 180D) / Math.PI) - 90F; hasAttacked = true; } }
@Override public void attackEntityWithRangedAttack(EntityLivingBase var1, float var2) { EntityArrow entityarrow = new EntityArrow( this.worldObj, this, var1, Math.max(1F, getDistanceToEntity(var1) / 10F), 1); entityarrow.posX = this.posX; entityarrow.posY = this.posY + this.getEyeHeight(); entityarrow.posZ = this.posZ; int power = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem()); int punch = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem()); double damage = (double) (var2 * 3.0F) + this.rand.nextGaussian() * 0.25D; entityarrow.setDamage(damage); if (power > 0) entityarrow.setDamage(entityarrow.getDamage() + (double) power * 0.5D + 0.5D); if (punch > 0) entityarrow.setKnockbackStrength(punch); if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0) entityarrow.setFire(100); this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); this.worldObj.spawnEntityInWorld(entityarrow); }
/** * called when the player releases the use item button. Args: itemstack, world, entityplayer, * itemInUseCount */ @Override public void onPlayerStoppedUsing( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { int j = this.getMaxItemUseDuration(par1ItemStack) - par4; ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) return; j = event.charge; boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (flag || par3EntityPlayer.inventory.hasItem(ModItem.glassArrow.itemID)) { float f = j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if (f < 0.1D) return; if (f > 1.0F) { f = 1.0F; } EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F); if (f == 1.0F) { entityarrow.setIsCritical(true); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (k > 0) { entityarrow.setDamage(entityarrow.getDamage() + k * 0.5D + 0.5D); } int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (l > 0) { entityarrow.setKnockbackStrength(l); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { entityarrow.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity( par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (flag) { entityarrow.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(ModItem.glassArrow.itemID); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(entityarrow); } } }
protected void initializeArrowVelocity( EntityArrow entityarrow, EntityPlayer player, float arrowDamage) { entityarrow.setAim( player, player.rotationPitch, player.rotationYaw, 0.0F, arrowDamage * 3.0F, 1.0F); }
@Override public void onUpdate() { super.onEntityUpdate(); if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); prevRotationYaw = rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI); prevRotationPitch = rotationPitch = (float) (Math.atan2(motionY, f) * 180.0D / Math.PI); } int i = worldObj.getBlockId(xTile, yTile, zTile); if (i > 0) { Block.blocksList[i].setBlockBoundsBasedOnState(worldObj, xTile, yTile, zTile); AxisAlignedBB axisalignedbb = Block.blocksList[i].getCollisionBoundingBoxFromPool(worldObj, xTile, yTile, zTile); if (axisalignedbb != null && axisalignedbb.isVecInside( worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ))) { this.setDead(); } } ++ticksInAir; Vec3 vec3 = worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ); Vec3 vec31 = worldObj.getWorldVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ); MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks_do_do(vec3, vec31, false, true); vec3 = worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ); vec31 = worldObj.getWorldVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ); if (movingobjectposition != null) { vec31 = worldObj .getWorldVec3Pool() .getVecFromPool( movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List list = worldObj.getEntitiesWithinAABBExcludingEntity( this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D)); double d0 = 0.0D; int l; float f1; for (l = 0; l < list.size(); ++l) { Entity entity1 = (Entity) list.get(l); if (entity1.canBeCollidedWith() && (entity1 != shootingEntity || ticksInAir >= 5)) { f1 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f1, f1, f1); MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec3, vec31); if (movingobjectposition1 != null) { double d1 = vec3.distanceTo(movingobjectposition1.hitVec); if (d1 < d0 || d0 == 0.0D) { entity = entity1; d0 = d1; } } } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit; if (entityplayer.capabilities.disableDamage || shootingEntity instanceof EntityPlayer && !((EntityPlayer) shootingEntity).canAttackPlayer(entityplayer)) { movingobjectposition = null; } } float f2; float f3; if (movingobjectposition != null) { if (movingobjectposition.entityHit != null) { f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ); DamageSource damagesource = null; if (shootingEntity == null) { damagesource = DamageSource.causeArrowDamage(this, this); } else { damagesource = DamageSource.causeArrowDamage(this, shootingEntity); } if (type == DartType.POISON) { damage = 1; if (movingobjectposition.entityHit instanceof EntityLiving) { // // ((EntityLiving)movingobjectposition.entityHit).addPotionEffect(new // PotionEffect(Potion.poison.id, 100)); ((EntityLiving) movingobjectposition.entityHit) .addPotionEffect(new PotionEffect(Potions.paralysis.get().id, 100)); } } if (movingobjectposition.entityHit.attackEntityFrom(damagesource, damage)) { if (movingobjectposition.entityHit instanceof EntityLiving) { if (shootingEntity != null && movingobjectposition.entityHit != shootingEntity && movingobjectposition.entityHit instanceof EntityPlayer && shootingEntity instanceof EntityPlayerMP) { ((EntityPlayerMP) shootingEntity) .playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(6, 0)); } } this.playSound("random.bowhit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F)); this.setDead(); } else { motionX *= -0.10000000149011612D; motionY *= -0.10000000149011612D; motionZ *= -0.10000000149011612D; rotationYaw += 180.0F; prevRotationYaw += 180.0F; ticksInAir = 0; } } else { xTile = movingobjectposition.blockX; yTile = movingobjectposition.blockY; zTile = movingobjectposition.blockZ; motionX = ((float) (movingobjectposition.hitVec.xCoord - posX)); motionY = ((float) (movingobjectposition.hitVec.yCoord - posY)); motionZ = ((float) (movingobjectposition.hitVec.zCoord - posZ)); f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ); posX -= motionX / f2 * 0.05000000074505806D; posY -= motionY / f2 * 0.05000000074505806D; posZ -= motionZ / f2 * 0.05000000074505806D; for (int p = 0; p < 16; ++p) { if (isPoisonous()) { BiomesOPlenty.proxy.spawnParticle("poisondart", posX, posY, posZ); } else { BiomesOPlenty.proxy.spawnParticle("dart", posX, posY, posZ); } } this.playSound("random.bowhit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F)); this.setDead(); } } posX += motionX; posY += motionY; posZ += motionZ; f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI); for (rotationPitch = (float) (Math.atan2(motionY, f2) * 180.0D / Math.PI); rotationPitch - prevRotationPitch < -180.0F; prevRotationPitch -= 360.0F) {; } while (rotationPitch - prevRotationPitch >= 180.0F) { prevRotationPitch += 360.0F; } while (rotationYaw - prevRotationYaw < -180.0F) { prevRotationYaw -= 360.0F; } while (rotationYaw - prevRotationYaw >= 180.0F) { prevRotationYaw += 360.0F; } rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F; rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F; float f4 = 0.99F; f1 = 0.05F; if (this.isInWater()) { for (int j1 = 0; j1 < 4; ++j1) { f3 = 0.25F; worldObj.spawnParticle( "bubble", posX - motionX * f3, posY - motionY * f3, posZ - motionZ * f3, motionX, motionY, motionZ); } f4 = 0.8F; } motionX *= f4; motionY *= f4; motionZ *= f4; motionY -= f1; this.setPosition(posX, posY, posZ); this.doBlockCollisions(); }
@Override public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int itemUse) { int draw = this.getMaxItemUseDuration(stack) - itemUse; ArrowLooseEvent event = new ArrowLooseEvent(player, stack, draw); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } draw = event.charge; boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0; if (flag || player.inventory.hasItem(Items.arrow)) { boolean empowered = isEmpowered(stack); float f = draw / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if (f > 1.0F) { f = 1.0F; } else if (f < 0.1F) { return; } EntityArrow arrow = new EntityArrow(world, player, f * arrowSpeedMultiplier * (empowered ? 1.0F : 1.25F)); double damage = arrow.getDamage() * arrowDamageMultiplier * (empowered ? 1.0F : 1.25F); arrow.setDamage(damage); if (f == 1.0F) { arrow.setIsCritical(true); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack); if (k > 0) { if (empowered) { k++; } arrow.setDamage(arrow.getDamage() + k * 0.5D + 0.5D); } int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack); if (l > 0) { if (empowered) { l++; } arrow.setKnockbackStrength(l); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) { arrow.setFire(100); } world.playSoundAtEntity( player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (flag) { arrow.canBePickedUp = 2; } else { player.inventory.consumeInventoryItem(Items.arrow); } if (ServerHelper.isServerWorld(world)) { world.spawnEntityInWorld(arrow); } if (!player.capabilities.isCreativeMode) { useEnergy(stack); } } }
/** * Called when the player stops using an Item (stops holding the right mouse button). * * @param timeLeft The amount of ticks left before the using would have been complete */ @Override public void onPlayerStoppedUsing( ItemStack stack, World worldIn, EntityLivingBase playerIn, int timeLeft) { if (playerIn instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) playerIn; int itemUseDuration = this.getMaxItemUseDuration(stack) - timeLeft; itemUseDuration = net.minecraftforge.event.ForgeEventFactory.onArrowLoose( stack, worldIn, player, itemUseDuration, isUsableByPlayer(stack, (EntityPlayer) playerIn)); if (isUsableByPlayer(stack, player)) { float arrowDamage = getArrowDamage(itemUseDuration); // I don't understand why this is done, but ItemBow does it, so we'll do it if ((double) arrowDamage < 0.1D) { return; } // MEMLogger.info("ItemCustomBow onPlayerStoppedUsing(): f = " + arrowDamage + "; // j = " + itemUseDuration + "; timeLeft = " + timeLeft); EntityArrow entityarrow = getNewEntityArrow(worldIn, player, itemUseDuration); // FFQLogger.info("Created a(n) " + entityarrow.getName() + " [damage: " + // entityarrow.getDamage() + "]"); entityarrow.setIsCritical(shotIsCritical(itemUseDuration, arrowDamage)); // if (entityarrow.getIsCritical()) { // MEMLogger.info("ItemCustomBow onPlayerStoppedUsing(): PEW! PEW!"); // } applyEnchantments(entityarrow, stack); initializeArrowVelocity(entityarrow, player, arrowDamage); takeDamage(1, stack, player); worldIn.playSound( player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.HOSTILE, 1.0F, (1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + arrowDamage * 0.5F), true); if (hasInfiniteArrows(stack, player)) { entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY; } else { this.consumeAmmo(stack, worldIn, player); } player.addStat(StatList.getObjectUseStats(this)); if (!worldIn.isRemote) { worldIn.spawnEntityInWorld(entityarrow); } } } }
/* Bow usage */ public void onPlayerStoppedUsing( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4; ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, var6); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } var6 = event.charge; boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (var5 || par3EntityPlayer.inventory.hasItem(Item.arrow.itemID)) { float var7 = (float) var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double) var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double) var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { var8.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity( par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Item.arrow.itemID); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(var8); } } }