use of lykrast.defiledlands.common.entity.projectile.EntityRavagerProjectile in project DefiledLands by Lykrast.
the class ItemRavager method onItemRightClick.
/**
* Called when the equipped item is right clicked.
*/
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
boolean flag = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, itemstack) > 0;
ItemStack ammo = findAmmo(playerIn);
if (!ammo.isEmpty() || flag) {
if (ammo.isEmpty()) {
ammo = new ItemStack(ModItems.pelletUmbrium);
}
worldIn.playSound((EntityPlayer) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!worldIn.isRemote) {
Vec3d vec3d = playerIn.getLook(1.0F);
EntityRavagerProjectile projectile = new EntityRavagerProjectile(worldIn, playerIn, vec3d.x, vec3d.y, vec3d.z, getSharpshooterBonus(itemstack));
projectile.posY = playerIn.posY + (double) playerIn.getEyeHeight();
if (ammo.getItem() instanceof IPellet) {
((IPellet) ammo.getItem()).applyAttributes(projectile, ammo);
}
worldIn.spawnEntity(projectile);
itemstack.damageItem(1, playerIn);
}
if (!flag) {
consumeAmmo(itemstack, ammo, playerIn, worldIn.rand);
}
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
} else {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
}
}
Aggregations