Search in sources :

Example 96 with ActionResult

use of net.minecraft.util.ActionResult in project DefiledLands by Lykrast.

the class ItemBlastemFruit 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);
    if (!playerIn.capabilities.isCreativeMode) {
        itemstack.shrink(1);
    }
    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));
    playerIn.getCooldownTracker().setCooldown(this, 20);
    if (!worldIn.isRemote) {
        EntityBlastemFruit projectile = new EntityBlastemFruit(worldIn, playerIn);
        projectile.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
        worldIn.spawnEntity(projectile);
    }
    playerIn.addStat(StatList.getObjectUseStats(this));
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack) EntityBlastemFruit(lykrast.defiledlands.common.entity.projectile.EntityBlastemFruit)

Example 97 with ActionResult

use of net.minecraft.util.ActionResult 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 ItemPellet) {
                ((ItemPellet) ammo.getItem()).applyAttributes(projectile);
            }
            worldIn.spawnEntity(projectile);
            itemstack.damageItem(1, playerIn);
        }
        if (!flag) {
            consumeAmmo(itemstack, ammo, playerIn, worldIn.rand);
        }
        playerIn.addStat(StatList.getObjectUseStats(this));
        return new ActionResult(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)

Example 98 with ActionResult

use of net.minecraft.util.ActionResult in project DefiledLands by Lykrast.

the class ItemUmbraBlaster 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.blastemFruit);
        }
        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));
        playerIn.getCooldownTracker().setCooldown(this, 10);
        if (!worldIn.isRemote) {
            EntityBlastemFruit projectile;
            if (ammo.getItem() == ModItems.blastemFruitBlazing || EnchantmentHelper.getEnchantmentLevel(ModEnchantments.blazing, itemstack) > 0)
                projectile = new EntityBlastemFruitBlazing(worldIn, playerIn);
            else
                projectile = new EntityBlastemFruit(worldIn, playerIn);
            float f = getSharpshooterBonus(itemstack);
            projectile.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F * f, 1.0F / f);
            if (EnchantmentHelper.getEnchantmentLevel(ModEnchantments.safeguard, itemstack) > 0) {
                projectile.setDestructive(false);
            }
            float j = getDestructiveBonus(itemstack);
            projectile.setDamage(projectile.getDamage() * j);
            projectile.setExplosionStrength(projectile.getExplosionStrength() * j);
            worldIn.spawnEntity(projectile);
            itemstack.damageItem(1, playerIn);
        }
        if (!flag) {
            consumeAmmo(itemstack, ammo, playerIn, worldIn.rand);
        }
        playerIn.addStat(StatList.getObjectUseStats(this));
        return new ActionResult(EnumActionResult.SUCCESS, itemstack);
    } else {
        return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
    }
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) EntityBlastemFruitBlazing(lykrast.defiledlands.common.entity.projectile.EntityBlastemFruitBlazing) ItemStack(net.minecraft.item.ItemStack) EntityBlastemFruit(lykrast.defiledlands.common.entity.projectile.EntityBlastemFruit)

Example 99 with ActionResult

use of net.minecraft.util.ActionResult in project Charset by CharsetMC.

the class ToolsUtils method placeBlockOrRollback.

public static ActionResult<ItemStack> placeBlockOrRollback(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos) {
    ItemStack oldStack = stack.copy();
    ItemStack heldItem = playerIn.getHeldItem(EnumHand.MAIN_HAND);
    // Take a snapshot
    IBlockState state = worldIn.getBlockState(pos);
    NBTTagCompound nbtTile = null;
    if (state.getBlock().hasTileEntity(state)) {
        TileEntity tileEntity = worldIn.getTileEntity(pos);
        if (tileEntity != null) {
            nbtTile = tileEntity.writeToNBT(new NBTTagCompound());
        }
    }
    worldIn.setBlockToAir(pos);
    playerIn.setHeldItem(EnumHand.MAIN_HAND, stack);
    EnumActionResult result1 = stack.onItemUse(playerIn, worldIn, pos, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
    ItemStack placedItem = playerIn.getHeldItem(EnumHand.MAIN_HAND);
    playerIn.setHeldItem(EnumHand.MAIN_HAND, heldItem);
    if (result1 == EnumActionResult.SUCCESS && !worldIn.isAirBlock(pos)) {
        // Hooray!
        return new ActionResult<>(EnumActionResult.SUCCESS, placedItem);
    } else {
        // Rollback...
        worldIn.setBlockState(pos, state);
        if (nbtTile != null) {
            worldIn.setTileEntity(pos, TileEntity.create(worldIn, nbtTile));
        }
        return new ActionResult<>(EnumActionResult.FAIL, oldStack);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumActionResult(net.minecraft.util.EnumActionResult) IBlockState(net.minecraft.block.state.IBlockState) EnumActionResult(net.minecraft.util.EnumActionResult) ActionResult(net.minecraft.util.ActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 100 with ActionResult

use of net.minecraft.util.ActionResult in project ConvenientAdditions by Necr0.

the class ItemLocationModule method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack item = player.getHeldItem(hand);
    if (!world.isRemote) {
        if (!item.hasTagCompound())
            item.setTagCompound(new NBTTagCompound());
        if (player.isSneaking()) {
            item.getTagCompound().removeTag("MODULE_LOCATION");
            player.sendMessage(new TextComponentString(Helper.localize("message." + ModConstants.Mod.MODID + ":locationReset")));
            return new ActionResult<>(EnumActionResult.SUCCESS, item);
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, item);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

ActionResult (net.minecraft.util.ActionResult)148 EnumActionResult (net.minecraft.util.EnumActionResult)147 ItemStack (net.minecraft.item.ItemStack)124 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)39 BlockPos (net.minecraft.util.math.BlockPos)31 RayTraceResult (net.minecraft.util.math.RayTraceResult)25 Nonnull (javax.annotation.Nonnull)15 Vec3d (net.minecraft.util.math.Vec3d)14 IBlockState (net.minecraft.block.state.IBlockState)12 TextComponentString (net.minecraft.util.text.TextComponentString)12 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 Entity (net.minecraft.entity.Entity)7 Block (net.minecraft.block.Block)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 TileEntity (net.minecraft.tileentity.TileEntity)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)3 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)3 FluidStack (net.minecraftforge.fluids.FluidStack)3