@SuppressWarnings("static-access") @SubscribeEvent public void onBowFire(ArrowLooseEvent event) { EntityPlayer player = event.getEntityPlayer(); ItemStack stack = event.getBow(); NBTTagCompound nbt = NBTHelper.loadStackNBT(stack); if (player != null && stack != null && nbt != null && !player.getEntityWorld().isRemote) { if (BowAttribute.BARRAGE.hasAttribute(nbt)) { for (int i = 0; i < (int) BowAttribute.BARRAGE.getCalculatedValue(nbt, 3, 1.5); i++) { EntityArrow entityarrow = new EntityTippedArrow(player.getEntityWorld(), player); entityarrow.setAim(player, player.rotationPitch, player.rotationYaw, 0, ((ItemBow) event.getBow().getItem()).getArrowVelocity(event.getCharge()) * 3, 20F); entityarrow.pickupStatus = PickupStatus.DISALLOWED; player.getEntityWorld().spawnEntity(entityarrow); } } } }
public void fireArrow(ArrowLooseEvent event) { if(MineFantasyBase.isBGLoaded()) { return; } ItemStack bow = event.bow; float charge = event.charge; EntityPlayer player = event.entityPlayer; World world = event.entity.worldObj; ItemBowMF.loadArrow(player, bow, null, true); for(ItemStack arrow: ArrowsMF.useableArrows) { if(shootSpecificArrow( bow, world, player, charge, arrow)) { event.setCanceled(true); return; } } }
@ForgeSubscribe public void onArrowLooseEvent(ArrowLooseEvent event) { EntityPlayer player = event.entityPlayer; InventoryPlayer inv = player.inventory; ItemStack par1ItemStack = inv.getStackInSlot(inv.currentItem); if(inv.getCurrentItem().itemID == Item.bow.itemID) { if(mod_Rediscovered.QuickBow) { boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; ItemStack itemstack = player.inventory.armorInventory[2]; if (itemstack != null && itemstack.itemID == mod_Rediscovered.Quiver.itemID || itemstack != null && itemstack.itemID == mod_Rediscovered.LeatherQuiver.itemID || itemstack != null && itemstack.itemID == mod_Rediscovered.ChainQuiver.itemID || itemstack != null && itemstack.itemID == mod_Rediscovered.IronQuiver.itemID || itemstack != null && itemstack.itemID == mod_Rediscovered.GoldQuiver.itemID || itemstack != null && itemstack.itemID == mod_Rediscovered.DiamondQuiver.itemID) { event.setCanceled(true); } } } }
@Override public void onPlayerStoppedUsing(ItemStack bow, World world, EntityPlayer player, int ticksRemaining) { ZSSPlayerInfo.get(player).hasAutoBombArrow = false; int ticksInUse = getMaxItemUseDuration(bow) - ticksRemaining; ArrowLooseEvent event = new ArrowLooseEvent(player, bow, ticksInUse); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { if (getArrow(player) != null) { setArrow(player, null); // nocked from inventory from empty quiver slot, then hot-swapped } return; } // Default behavior found usable arrow in standard player inventory ItemStack arrowStack = getArrow(player); if (arrowStack != null) { // can be null when hot-swapping to an empty quiver slot if (canShootArrow(player, bow, arrowStack)) { fireArrow(event, arrowStack, bow, player); } setArrow(player, null); } }
@Override public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int par4) { int chargeTime = this.getMaxItemUseDuration(stack) - par4; ArrowLooseEvent event = new ArrowLooseEvent(player, stack, chargeTime); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } // Not having it chargeTime = event.charge; // Either creative mode or infinity enchantment is higher than 0. Not using arrows boolean freeShot = player.capabilities.isCreativeMode; if (freeShot || player.inventory.hasItemStack(new ItemStack(Items.arrow)) ) { float f = (float) chargeTime / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntityArrow entityarrow = new EntityArrow(world, player, f * 2.0F); if (f == 1.0F) { entityarrow.setIsCritical(true); } stack.damageItem(1, player); world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (freeShot) { entityarrow.canBePickedUp = 2; } else { player.inventory.consumeInventoryItem(Items.arrow); } if (!world.isRemote) { world.spawnEntityInWorld(entityarrow); } // pew. } }
@Override public void onPlayerStoppedUsing(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer, int par4) { if (!par2World.isRemote) { int j = this.getMaxItemUseDuration(stack) - par4; // Reduces the durability by the ItemInUseCount (probably 1 for anything that isn't a tool) ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, stack, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } j = event.charge; if (this.getDamage(stack) == this.getMaxDamage()) { return; } // No arrows in the quiver? Getting out of here early 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); } par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (par3EntityPlayer.capabilities.isCreativeMode) { entityarrow.canBePickedUp = 0; } else { entityarrow.canBePickedUp = 1; stack.setItemDamage(this.getDamage(stack) + 1); // Reversed. MORE Damage for a shorter durability bar } par2World.spawnEntityInWorld(entityarrow); } }
public static int onArrowLoose(ItemStack stack, World world, EntityPlayer player, int charge, boolean hasAmmo) { ArrowLooseEvent event = new ArrowLooseEvent(player, stack, world, charge, hasAmmo); if (MinecraftForge.EVENT_BUS.post(event)) return -1; return event.getCharge(); }
@SubscribeEvent public void handleLoose(ArrowLooseEvent event){ if(event.getEntityPlayer() !=null){ ExtendedPlayer exPlayer = ExtendedPlayerProvider.getExtendedPlayer(event.getEntityPlayer()); if(exPlayer !=null){ ExtendedPlayerInventory inv = exPlayer.getInventory(); ItemStack backpack = inv.getStackInSlot(ExtendedPlayerInventory.BACKPACK_SLOT_ID); if(ItemStackTools.isValid(backpack)){ InventoryBackpackUpgrades upgrades = BackpackUtil.getUpgradeInventory(event.getEntityPlayer(), backpack); if(upgrades !=null && upgrades.hasUpgrade(BackpackUpgrade.BOW)){ InventoryBackpack backpackInv = BackpackUtil.getInventory(event.getEntityPlayer(), backpack); if(backpackInv !=null){ for(int i = 0; i < backpackInv.getSize(); i++){ ItemStack st = backpackInv.getStackInSlot(i); if(ItemStackTools.isValid(st) && st.getItem() instanceof ItemArrow){ if(!EntityUtil.shootArrow(event.getWorld(), event.getEntityPlayer(), event.getBow(), st, event.getCharge())){ backpackInv.decrStackSize(i, 1); backpackInv.markDirty(); backpackInv.guiSave(event.getEntityPlayer()); inv.setChanged(ExtendedPlayerInventory.BACKPACK_SLOT_ID, true); event.setCanceled(true); return; } } } } } } } } }
/** * Event listener for Action.SHOOT_ARROW */ @SubscribeEvent public void onArrowLooseEvent(ArrowLooseEvent event) throws IOException { EntityPlayer player = event.getEntityPlayer(); List<Action> events = CommonProxy.manager.getActions(player); if (!player.worldObj.isRemote && events != null) { events.add(new ShootArrowAction(event.getCharge())); } }
@SubscribeEvent public void onArrowLooseEvent(ArrowLooseEvent event) { EntityPlayer player = event.entityPlayer; InventoryPlayer inv = player.inventory; ItemStack par1ItemStack = inv.getStackInSlot(inv.currentItem); ItemStack blah = new ItemStack(Items.bow); ItemStack quiver = new ItemStack(mod_Rediscovered.Quiver); ItemStack lquiver = new ItemStack(mod_Rediscovered.LeatherQuiver); ItemStack cquiver = new ItemStack(mod_Rediscovered.ChainQuiver); ItemStack gquiver = new ItemStack(mod_Rediscovered.GoldQuiver); ItemStack iquiver = new ItemStack(mod_Rediscovered.IronQuiver); ItemStack dquiver = new ItemStack(mod_Rediscovered.DiamondQuiver); ItemStack lcquiver = new ItemStack(mod_Rediscovered.LeatherChainQuiver); if(inv.getCurrentItem().equals(blah)) { boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; ItemStack itemstack = player.inventory.armorInventory[2]; if (itemstack != null && (itemstack.equals(quiver) || itemstack.equals(lquiver) || itemstack.equals(cquiver) || itemstack.equals(iquiver) || itemstack.equals(gquiver) || itemstack.equals(dquiver) || itemstack.equals(lcquiver))) { event.setCanceled(true); } } }
@SubscribeEvent public void onArrowLooseEvent(ArrowLooseEvent ev) throws IOException { Side side = FMLCommonHandler.instance().getEffectiveSide(); if (side == Side.SERVER) { List<MocapAction> aList = Mocap.instance .getActionListForPlayer(ev.entityPlayer); if (aList != null) { MocapAction ma = new MocapAction(MocapActionTypes.SHOOTARROW); ma.arrowCharge = ev.charge; aList.add(ma); } } }
@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; if (par3EntityPlayer.capabilities.isCreativeMode||par3EntityPlayer.inventory.hasItem(IlluminatedItems.illuminatedArrow)) { float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntityIlluminatedArrow arrow = new EntityIlluminatedArrow(par2World, par3EntityPlayer, f*2.0F); arrow.setBlockToSet(IlluminatedBlocks.illuminatedBlock); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (Config.bowTakesDamage) par1ItemStack.damageItem(1, par3EntityPlayer); if (!par3EntityPlayer.capabilities.isCreativeMode) par3EntityPlayer.inventory.consumeInventoryItem(IlluminatedItems.illuminatedArrow); if (!par2World.isRemote) { par2World.spawnEntityInWorld(arrow); } } }
@SubscribeEvent public void detectArrow(ArrowLooseEvent event) { if (!ConfigHandler.BACKPACK_ABILITIES) return; if (Wearing.isWearingTheRightBackpack(event.entityPlayer, "Skeleton")) { InventoryBackpack backpack = new InventoryBackpack(Wearing.getWearingBackpack(event.entityPlayer)); if (backpack.hasItem(Items.arrow)) { ServerActions.leakArrow(event.entityPlayer, event.bow, event.charge); event.setCanceled(true); } } }
@SubscribeEvent public void onArrowLoose(ArrowLooseEvent event) { if (event.entity.worldObj.isRemote) { return; } if (event.entityPlayer != null && event.entityPlayer.getHeldItem() != null) { this.lastBow.put(event.entityPlayer, event.entityPlayer.getHeldItem()); } }
/** * Called if ArrowLooseEvent was not canceled, so either the player is not using a quiver, * or Battlegear2 is not loaded. * Constructs and fires the arrow, if possible, and may consume the appropriate inventory item. */ private void fireArrow(ArrowLooseEvent event, ItemStack arrowStack, ItemStack bow, EntityPlayer player) { boolean flag = (player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, bow) > 0); if (flag || PlayerUtils.hasItem(player, arrowStack)) { float charge = (float) event.charge / 20.0F; charge = Math.min((charge * charge + charge * 2.0F) / 3.0F, 1.0F); if ((double) charge < 0.1D) { return; } EntityArrow arrowEntity = getArrowEntity(arrowStack, player.worldObj, player, charge * 2.0F); if (arrowEntity == null && ZSSMain.isBG2Enabled) { // try to construct BG2 arrow arrowEntity = QuiverArrowRegistry.getArrowType(arrowStack, player.worldObj, player, charge * 2.0F); } if (arrowEntity != null && confirmArrowShot(arrowStack, player)) { applyArrowSettings(arrowEntity, bow, charge); if (arrowEntity instanceof EntityArrowCustom) { applyCustomArrowSettings(event.entityPlayer, event.bow, arrowStack, (EntityArrowCustom) arrowEntity, charge); } player.worldObj.playSoundAtEntity(player, Sounds.BOW_RELEASE, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + charge * 0.5F); if (flag) { arrowEntity.canBePickedUp = 2; } else { PlayerUtils.consumeInventoryItem(player, arrowStack, 1); } if (!player.worldObj.isRemote) { player.worldObj.spawnEntityInWorld(arrowEntity); } } } }
@Override public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int time) { int maxItemUse = getMaxItemUseDuration(stack) - time; ArrowLooseEvent event = new ArrowLooseEvent(player, stack, maxItemUse); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) return; maxItemUse = event.charge; boolean infiniteAmmo = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0; if (infiniteAmmo || player.inventory.hasItem(ammo)) { float scaledItemUse = (float) maxItemUse / 20.0F; scaledItemUse = (scaledItemUse * scaledItemUse + scaledItemUse * 2) / 3; if ((double) scaledItemUse < 0.1) return; if (scaledItemUse > 1) scaledItemUse = 1; EntityROCArrow entityarrow = new EntityROCArrow(world, player, scaledItemUse*2, damage, ammo.getUnlocalizedName().replace("item.arrow", "")); entityarrow.setAmmoItem(ammo); if (scaledItemUse == 1) entityarrow.setIsCritical(true); int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack); if (powerLevel > 0) entityarrow.setDamage(entityarrow.getDamage() + (double) powerLevel * 0.5 + 0.5); int punchLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack); if (punchLevel > 0) entityarrow.setKnockbackStrength(punchLevel); if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) entityarrow.setFire(100); stack.damageItem(1, player); world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + scaledItemUse * 0.5F); if (infiniteAmmo) entityarrow.canBePickedUp = 2; else player.inventory.consumeInventoryItem(ammo); if (!world.isRemote) world.spawnEntityInWorld(entityarrow); } }
@SubscribeEvent public void onArrowLooseEvent(ArrowLooseEvent event) { EntityPlayer player = event.entityPlayer; InventoryPlayer inv = player.inventory; ItemStack par1ItemStack = inv.getStackInSlot(inv.currentItem); ItemStack blah = new ItemStack(Items.bow); ItemStack quiver = new ItemStack(mod_Rediscovered.Quiver); ItemStack lquiver = new ItemStack(mod_Rediscovered.LeatherQuiver); ItemStack cquiver = new ItemStack(mod_Rediscovered.ChainQuiver); ItemStack gquiver = new ItemStack(mod_Rediscovered.GoldQuiver); ItemStack iquiver = new ItemStack(mod_Rediscovered.IronQuiver); ItemStack dquiver = new ItemStack(mod_Rediscovered.DiamondQuiver); ItemStack squiver = new ItemStack(mod_Rediscovered.LeatherChainQuiver); if(inv.getCurrentItem().equals(blah)) { boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; ItemStack itemstack = player.inventory.armorInventory[2]; if (itemstack != null && (itemstack.equals(quiver) || itemstack.equals(lquiver) || itemstack.equals(cquiver) || itemstack.equals(iquiver) || itemstack.equals(gquiver) || itemstack.equals(dquiver) || itemstack.equals(squiver))) { event.setCanceled(true); } } }
@ForgeSubscribe public void onArrowLoose(ArrowLooseEvent event) { EntityStats stats = Dota2Items.stats.getOrCreateEntityStats(event.entityPlayer); float speed = (float) MAX_CHARGE / stats.getAttackTime(); float timeCharged = (float) event.charge / MCConstants.TICKS_PER_SECOND; int newCharge = MathHelper.ceiling_float_int( speed * timeCharged ); if (Dota2Items.debug) { Dota2Items.logger.info(String.format("Changed bow charge from %d to %d", event.charge, newCharge)); } event.charge = newCharge; }
@SubscribeEvent public void arrowLoose(ArrowLooseEvent event) { if (event.bow == null) return; IInventory invt = event.entityPlayer.inventory; for (int i = 0; i < invt.getSizeInventory(); i++) { ItemStack arrow = invt.getStackInSlot(i); if (arrow != null && arrow.stackSize > 0 && arrow.getItem() == ModItems.tipped_arrow) { float charge = event.charge / 20.0F; charge = (charge * charge + charge * 2.0F) / 3.0F; if (charge < 0.1D) return; if (charge > 1.0F) charge = 1.0F; EntityTippedArrow arrowEntity = new EntityTippedArrow(event.entityPlayer.worldObj, event.entityPlayer, charge * 2.0F); arrowEntity.setEffect(TippedArrow.getEffect(arrow)); if (charge == 1.0F) arrowEntity.setIsCritical(true); int power = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, event.bow); if (power > 0) arrowEntity.setDamage(arrowEntity.getDamage() + power * 0.5D + 0.5D); int punch = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, event.bow); if (punch > 0) arrowEntity.setKnockbackStrength(punch); if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, event.bow) > 0) arrowEntity.setFire(100); event.bow.damageItem(1, event.entityPlayer); event.entityPlayer.worldObj.playSoundAtEntity(event.entityPlayer, "random.bow", 1.0F, 1.0F / (event.entityPlayer.worldObj.rand.nextFloat() * 0.4F + 1.2F) + charge * 0.5F); if (!event.entityPlayer.capabilities.isCreativeMode && --arrow.stackSize <= 0) event.entityPlayer.inventory.setInventorySlotContents(i, null); if (!event.entityPlayer.worldObj.isRemote) event.entityPlayer.worldObj.spawnEntityInWorld(arrowEntity); event.setCanceled(true); return; } } }
@Override public void onPlayerStoppedUsing(ItemStack is, World world, EntityPlayer player, int inUseCount) { int j = this.getMaxItemUseDuration(is) - inUseCount; ArrowLooseEvent event = new ArrowLooseEvent(player, is, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) return; j = event.charge; boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, is) > 0; boolean hasAmmo = flag || player.inventory.hasItem(ModItems.itemSharpStone) || player.inventory.hasItem(ModItems.itemHardStone) || player.inventory.hasItem(ModItems.itemSoftStone); if (hasAmmo) { float forceMult = j / getUseSpeed(player); //f = (f * f + f * 2.0F) / 3.0F; if (forceMult < 0.25D) return; if (forceMult > 1.25F) forceMult = 1.25F; EntityProjectileSharpStone entitysharpstone = new EntityProjectileSharpStone(world, player, forceMult * 1.2F); EntityProjectileHardStone entityhardstone = new EntityProjectileHardStone(world, player, forceMult * 1.5F); EntityProjectileSoftStone entitysoftstone = new EntityProjectileSoftStone(world, player, forceMult * 0.8F); entitysharpstone.setDamage(forceMult * 40.0); entityhardstone.setDamage(forceMult * 50.0); entitysoftstone.setDamage(forceMult * 30.0); is.damageItem(1, player); world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + forceMult * 0.5F); if (flag) { // entitysharpstone.canBePickedUp = 2; entityhardstone.canBePickedUp = 2; // entitysoftstone.canBePickedUp = 2; if (!world.isRemote) world.spawnEntityInWorld(entityhardstone); } else if(hasAmmo) { if (player.inventory.hasItem(ModItems.itemHardStone)) { player.inventory.consumeInventoryItem(ModItems.itemHardStone); if (!world.isRemote) world.spawnEntityInWorld(entityhardstone); } else if (player.inventory.hasItem(ModItems.itemSharpStone)) { player.inventory.consumeInventoryItem(ModItems.itemSharpStone); if (!world.isRemote) world.spawnEntityInWorld(entitysharpstone); } else { player.inventory.consumeInventoryItem(ModItems.itemSoftStone); if (!world.isRemote) world.spawnEntityInWorld(entitysoftstone); } } } }
@SubscribeEvent public void onArrowLoose(ArrowLooseEvent event) { EntityPlayer player = event.getEntityPlayer(); if (this.isActive(player)) { if (!event.hasAmmo()) { ItemStack stack = event.getBow(); World world = player.getEntityWorld(); EntitySkeleton skeleton = (EntitySkeleton) PossessHandler.get(player).getPossessing(); float velocity = ItemBow.getArrowVelocity(event.getCharge()); if (velocity >= 0.1) { if (!world.isRemote) { EntityTippedArrow arrow = new EntityTippedArrow(world, player); if (skeleton.getSkeletonType() != SkeletonType.STRAY) { arrow.setPotionEffect(new ItemStack(Items.ARROW)); } else { arrow.setPotionEffect(new ItemStack(Items.TIPPED_ARROW)); arrow.addEffect(new PotionEffect(MobEffects.SLOWNESS, 600)); } arrow.setAim(player, player.rotationPitch, player.rotationYaw, 0.0F, velocity * 3.0F, 1.0F); arrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY; if (velocity == 1.0F) { arrow.setIsCritical(true); } int power = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack); if (power > 0) { arrow.setDamage(arrow.getDamage() + (double) power * 0.5 + 0.5); } int punch = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack); if (punch > 0) { arrow.setKnockbackStrength(punch); } if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) { arrow.setFire(100); } stack.damageItem(1, player); world.spawnEntityInWorld(arrow); } world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (world.rand.nextFloat() * 0.4F + 1.2F) + velocity * 0.5F); player.addStat(StatList.getObjectUseStats(stack.getItem())); } } } }
@SubscribeEvent(priority = EventPriority.LOWEST) public void onArrowLoose(ArrowLooseEvent event) { updateWeight(event.getEntityPlayer()); }
/** * 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_) { int j = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_; ArrowLooseEvent event = new ArrowLooseEvent(p_77615_3_, p_77615_1_, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } j = event.charge; boolean flag = p_77615_3_.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0; if (flag || p_77615_3_.inventory.hasItem(ItemLoader.itemPatArrow)) { float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntilyPatArrow entitypatarrow = new EntilyPatArrow(p_77615_2_, p_77615_3_, f * 2.0F); if (f == 1.0F) { entitypatarrow.setIsCritical(true); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_); if (k > 0) { entitypatarrow.setDamage(entitypatarrow.getDamage() + (double)k * 0.5D + 0.5D); } int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_); if (l > 0) { entitypatarrow.setKnockbackStrength(l); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0) { entitypatarrow.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) + f * 0.5F); if (flag) { entitypatarrow.canBePickedUp = 2; } else { p_77615_3_.inventory.consumeInventoryItem(ItemLoader.itemPatArrow); } if (!p_77615_2_.isRemote) { p_77615_2_.spawnEntityInWorld(entitypatarrow); } } }
/** * 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_) { int j = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_; ArrowLooseEvent event = new ArrowLooseEvent(p_77615_3_, p_77615_1_, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } j = event.charge; boolean flag = p_77615_3_.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0; if (flag || p_77615_3_.inventory.hasItem(ItemLoader.itemJenArrow)) { float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntilyJenArrow entityjenarrow = new EntilyJenArrow(p_77615_2_, p_77615_3_, f * 2.0F); if (f == 1.0F) { entityjenarrow.setIsCritical(true); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_); if (k > 0) { entityjenarrow.setDamage(entityjenarrow.getDamage() + (double)k * 0.5D + 0.5D); } int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_); if (l > 0) { entityjenarrow.setKnockbackStrength(l); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0) { entityjenarrow.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) + f * 0.5F); if (flag) { entityjenarrow.canBePickedUp = 2; } else { p_77615_3_.inventory.consumeInventoryItem(ItemLoader.itemJenArrow); } if (!p_77615_2_.isRemote) { p_77615_2_.spawnEntityInWorld(entityjenarrow); } } }
/** * 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_) { int j = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_; ArrowLooseEvent event = new ArrowLooseEvent(p_77615_3_, p_77615_1_, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } j = event.charge; boolean flag = p_77615_3_.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0; if (flag || p_77615_3_.inventory.hasItem(Items.arrow)) { float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntityArrow entityarrow = new EntityArrow(p_77615_2_, p_77615_3_, f * 2.0F); if (f == 1.0F) { entityarrow.setIsCritical(true); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_); if (k > 0) { entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D); } int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_); if (l > 0) { entityarrow.setKnockbackStrength(l); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0) { entityarrow.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) + f * 0.5F); if (flag) { entityarrow.canBePickedUp = 2; } else { p_77615_3_.inventory.consumeInventoryItem(Items.arrow); } if (!p_77615_2_.isRemote) { p_77615_2_.spawnEntityInWorld(entityarrow); } } }
@Override public void onPlayerStoppedUsing (ItemStack stack, World world, EntityPlayer player, int useDur ) { // Ammo check and stuff Ammo ammo = getActiveArrow( player ); if ( ammo == null || ammo.inv == null || ammo.stack == null || ammo.slot == -1 ) { return; } boolean ignoreArrows = EnchantmentHelper.getEnchantmentLevel( Enchantment.infinity.effectId, stack ) > 0 && Arrow.getData( ArrowItem.getHeadMaterial( ammo.stack ) ).affectedByInfinity(); ignoreArrows = player.capabilities.isCreativeMode || ignoreArrows; // Charge int charge = getMaxItemUseDuration( stack ) - useDur; ArrowLooseEvent event = new ArrowLooseEvent( player, stack, charge ); MinecraftForge.EVENT_BUS.post( event ); if ( event.isCanceled() || charge < 5 ) { return; } charge = event.charge; // Shoot arrow float f = (float) charge / 20.0F; f = ( f * f + f * 2.0F ) / 3.0F; if ( f > 1.0F ) { f = 1.0F; } ArrowEntity arrow = new ArrowEntity( world, player, f * 2.0F ); arrow.setHeadMaterial( ArrowItem.getHeadMaterial( ammo.stack ) ); arrow.setFeathered( ArrowItem.getFeathered( ammo.stack ) ); if (f == 1.0F) { arrow.setIsCritical( true ); } // TODO: Detect TConstruct and double damage? int powerLevel = EnchantmentHelper.getEnchantmentLevel( Enchantment.power.effectId, stack ); if ( powerLevel > 0 ) { arrow.setDamage( arrow.getDamage() + (double) powerLevel * 0.5D + 0.5D ); } int punchLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack); if ( punchLevel > 0 ) { arrow.setKnockbackStrength( punchLevel ); } if ( EnchantmentHelper.getEnchantmentLevel( Enchantment.flame.effectId, stack ) > 0 ) { arrow.setFire( 100 ); } if ( !player.capabilities.isCreativeMode ) { damageItemStack( player, stack, 1 ); } world.playSoundAtEntity( player, "random.bow", 1.0F, 1.0F / ( itemRand.nextFloat() * 0.4F + 1.2F ) + f * 0.5F ); if ( ignoreArrows ) { arrow.canBePickedUp = 2; } else { ammo.inv.decrStackSize( ammo.slot, 1 ); } if ( !world.isRemote ) { world.spawnEntityInWorld( arrow ); } }
@Override public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int itemUse) { int j = getMaxItemUseDuration(stack) - itemUse; ArrowLooseEvent event = new ArrowLooseEvent(player, stack, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } j = event.charge; boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0; if (flag || player.inventory.hasItem(TDEWeapons.daedric_arrow)) { float f = (float) j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double) f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntityDragonArrow entityarrow = new EntityDragonArrow(world, player, f * 2.0F); entityarrow.setFire(100); entityarrow.setDamage(entityarrow.getDamage() + 1.0D + 1.0D); if (f == 1.0F) { entityarrow.setIsCritical(true); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack); if (k > 0) { entityarrow.setDamage(entityarrow.getDamage() + (double) k * 1.0D + 1.0D); } int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack); if (l > 0) { entityarrow.setKnockbackStrength(l); } /*if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) { entityarrow.setFire(100); }*/ stack.damageItem(1, player); world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (flag) { entityarrow.canBePickedUp = 2; } else { player.inventory.consumeInventoryItem(TDEWeapons.daedric_arrow); } if (!world.isRemote) { world.spawnEntityInWorld(entityarrow); } } }
@Override public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int itemUse) { int j = getMaxItemUseDuration(stack) - itemUse; ArrowLooseEvent event = new ArrowLooseEvent(player, stack, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } j = event.charge; boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0; if (flag || player.inventory.hasItem(TDEWeapons.dragon_arrow)) { float f = (float) j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double) f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntityDaedricArrow entityarrow = new EntityDaedricArrow(world, player, f * 2.0F); entityarrow.setFire(100); entityarrow.setDamage(entityarrow.getDamage() + 1.0D + 1.0D); if (f == 1.0F) { entityarrow.setIsCritical(true); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack); if (k > 0) { entityarrow.setDamage(entityarrow.getDamage() + (double) k * 1.0D + 1.0D); } int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack); if (l > 0) { entityarrow.setKnockbackStrength(l); } /*if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) { entityarrow.setFire(100); }*/ stack.damageItem(1, player); world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (flag) { entityarrow.canBePickedUp = 2; } else { player.inventory.consumeInventoryItem(TDEWeapons.dragon_arrow); } if (!world.isRemote) { world.spawnEntityInWorld(entityarrow); } } }
public QuiverArrowEvent(ArrowLooseEvent event){ super(event); this.event = event; }
public Firing(ArrowLooseEvent parent, ItemStack quiver, EntityArrow arrow) { super(parent); this.quiver = quiver; this.arrow = arrow; }
public ChargeCalculations(ArrowLooseEvent event){ super(event); }
public void onPlayerStoppedUsing(ItemStack item, World world, EntityPlayer player, int time) { int power = (this.getMaxItemUseDuration(item) - time); power *= model.speed; // Speeds up the power in relation to ticks used power = (int)((float)power / 20F * getMaxPower());//scales the power down from full if(power > getMaxPower())power = (int)getMaxPower();//limits the power to max ArrowLooseEvent event = new ArrowLooseEvent(player, item, power); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } power = event.charge; boolean var5 = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, item) > 0; if (var5 || player.inventory.hasItem(Item.arrow.itemID)) { float var7 = (float)power / 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(world, player, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, item); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, item); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, item) > 0) { var8.setFire(100); } item.damageItem(1, player); world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { player.inventory.consumeInventoryItem(Item.arrow.itemID); } if (!world.isRemote) { world.spawnEntityInWorld(var8); } } }
/** * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount */ public void onPlayerStoppedUsing(ItemStack item, World world, EntityPlayer player, int time) { int power = (this.getMaxItemUseDuration(item) - time); power *= model.speed; // Speeds up the power in relation to ticks used power = (int)((float)power / 20F * getMaxPower());//scales the power down from full if(power > getMaxPower())power = (int)getMaxPower();//limits the power to max ArrowLooseEvent event = new ArrowLooseEvent(player, item, power); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } power = event.charge; boolean var5 = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, item) > 0; if (var5 || player.inventory.hasItem(Item.arrow.itemID)) { float var7 = (float)power / 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(world, player, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, item); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, item); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, item) > 0) { var8.setFire(100); } item.damageItem(1, player); world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { player.inventory.consumeInventoryItem(Item.arrow.itemID); } if (!world.isRemote) { world.spawnEntityInWorld(var8); } } }
@Override public void onPlayerStoppedUsingFocus(ItemStack itemstack, World world, EntityPlayer player, int count) { int j = 72000 - count; ArrowLooseEvent event = new ArrowLooseEvent(player, itemstack, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } j = event.charge; if (player.capabilities.isCreativeMode||ThaumcraftApiHelper.consumeVisFromWand(itemstack, player, visCost, true,false)) { float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntityIlluminatedArrow arrow = new EntityIlluminatedArrow(world, player, 2.0F*f); arrow.setDamage(0); arrow.setDeadOnLand(true); arrow.isMagic(true); world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (!world.isRemote) { world.spawnEntityInWorld(arrow); } } else { world.playSoundAtEntity(player, "thaumcraft:craftfail", 1.0F, 1.0F); } }
@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; if (par3EntityPlayer.capabilities.isCreativeMode||ThaumcraftApiHelper.consumeVisFromInventory(par3EntityPlayer, ItemFocusIlluminating.visCost)) { float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntityIlluminatedArrow arrow = new EntityIlluminatedArrow(par2World, par3EntityPlayer, 2.0F*f); arrow.setDamage(0); arrow.isMagic(true); arrow.arrowShake=0; par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (Config.bowTakesDamage) { par1ItemStack.damageItem(1, par3EntityPlayer); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(arrow); } } else { par2World.playSoundAtEntity(par3EntityPlayer, "thaumcraft:craftfail", 1.0F, 1.0F); } }
@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; float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 6.0F) { f = 4.0F; } if ((f >= 4.0F) && (f < 6.0F)) { par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.jump.id, 90, 20)); par1ItemStack.damageItem(8, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.orb", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); } if ((f >= 2.5F) && (f < 4.0F)) { par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.jump.id, 60, 15)); par1ItemStack.damageItem(6, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.orb", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); } if ((f >= 1.0F) && (f < 2.5F)) { par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.jump.id, 50, 10)); par1ItemStack.damageItem(4, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.orb", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); } else { par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.jump.id, 50, 4)); par1ItemStack.damageItem(2, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.orb", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); } }
@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(ModItems.FireCastingPowder.itemID)); { float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntityRuneFireBall entityarrow = new EntityRuneFireBall(par2World, par3EntityPlayer); int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (l > 0) { entityarrow.setKnockbackStrength(1); } par3EntityPlayer.inventory.consumeInventoryItem(ModItems.FireCastingPowder.itemID); par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "ghast.fireball4", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (!par2World.isRemote) { par2World.spawnEntityInWorld(entityarrow); } } }