@SubscribeEvent public void livingAttack(LivingAttackEvent event) { if (event.source instanceof EntityDamageSourceIndirect) { EntityDamageSourceIndirect dmgSrc = (EntityDamageSourceIndirect) event.source; if (dmgSrc.getSourceOfDamage() instanceof EntityTippedArrow) { EntityTippedArrow tippedArrow = (EntityTippedArrow) dmgSrc.getSourceOfDamage(); if (!tippedArrow.worldObj.isRemote) event.entityLiving.addPotionEffect(tippedArrow.getEffect()); } } }
@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; } } }