Search in sources :

Example 1 with EntityRavagerProjectile

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);
    }
}
Also used : EntityRavagerProjectile(lykrast.defiledlands.common.entity.projectile.EntityRavagerProjectile) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

EntityRavagerProjectile (lykrast.defiledlands.common.entity.projectile.EntityRavagerProjectile)1 ItemStack (net.minecraft.item.ItemStack)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 Vec3d (net.minecraft.util.math.Vec3d)1