Search in sources :

Example 56 with ActionResult

use of net.minecraft.util.ActionResult in project Random-Things by lumien231.

the class ItemStableEnderpearl method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    ItemStack itemStackIn = playerIn.getHeldItem(hand);
    if (!worldIn.isRemote) {
        if (itemStackIn.getTagCompound() == null) {
            itemStackIn.setTagCompound(new NBTTagCompound());
        }
        NBTTagCompound compound = itemStackIn.getTagCompound();
        GameProfile gameProfile = playerIn.getGameProfile();
        compound.setString("player-uuid", gameProfile.getId().toString());
        compound.setString("player-name", gameProfile.getName());
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) GameProfile(com.mojang.authlib.GameProfile) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 57 with ActionResult

use of net.minecraft.util.ActionResult in project KalStuff by TEAMModding.

the class ItemClosedSoda method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    super.onItemRightClick(worldIn, playerIn, hand);
    worldIn.playSound(playerIn, playerIn.posX, playerIn.posY, playerIn.posZ, KalStuffSoundEvents.CAN_OPEN, SoundCategory.PLAYERS, 1.0F, 1.0F);
    ItemStack stack = playerIn.getHeldItem(hand);
    stack.shrink(1);
    if (stack.getCount() <= 0)
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, this.getReturnStack());
    playerIn.inventory.addItemStackToInventory(this.getReturnStack());
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
Also used : EnumActionResult(net.minecraft.util.EnumActionResult) ActionResult(net.minecraft.util.ActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 58 with ActionResult

use of net.minecraft.util.ActionResult in project BloodMagic by WayofTime.

the class ItemSentientArmourGem method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    boolean hasSentientArmour = false;
    NonNullList<ItemStack> armourInventory = player.inventory.armorInventory;
    for (ItemStack armourStack : armourInventory) {
        if (armourStack != null && armourStack.getItem() instanceof ItemSentientArmour) {
            hasSentientArmour = true;
        }
    }
    if (hasSentientArmour) {
        ItemSentientArmour.revertAllArmour(player);
    } else {
        EnumDemonWillType type = PlayerDemonWillHandler.getLargestWillType(player);
        double will = PlayerDemonWillHandler.getTotalDemonWill(type, player);
        // PlayerDemonWillHandler.consumeDemonWill(player, willBracket[bracket]);
        ItemSentientArmour.convertPlayerArmour(type, will, player);
    }
    return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType) ItemSentientArmour(WayofTime.bloodmagic.item.armour.ItemSentientArmour)

Example 59 with ActionResult

use of net.minecraft.util.ActionResult in project Ceramics by KnightMiner.

the class ItemClayBucket method onItemRightClick.

/* Bucket behavior */
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    // milk we set active and return success, drinking code is done elsewhere
    if (getSpecialFluid(stack) == SpecialFluid.MILK) {
        player.setActiveHand(hand);
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }
    // empty bucket logic is just an event :)
    if (!hasFluid(stack)) {
        ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, stack, this.rayTrace(world, player, true));
        if (ret != null) {
            return ret;
        }
        return ActionResult.newResult(EnumActionResult.PASS, stack);
    }
    // clicked on a block?
    RayTraceResult mop = this.rayTrace(world, player, false);
    if (mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK) {
        return ActionResult.newResult(EnumActionResult.PASS, stack);
    }
    BlockPos clickPos = mop.getBlockPos();
    // can we place liquid there?
    if (world.isBlockModifiable(player, clickPos)) {
        FluidStack fluidStack = getFluid(stack);
        // first, try cauldron
        IBlockState clickState = world.getBlockState(clickPos);
        if (!player.isSneaking() && clickState.getBlock() == Blocks.CAULDRON) {
            ItemStack returnStack = stack.copy();
            if (clickState.getValue(BlockCauldron.LEVEL).intValue() < 3 && fluidStack.getFluid() == FluidRegistry.WATER) {
                if (!player.capabilities.isCreativeMode) {
                    returnStack.shrink(1);
                    ItemStack drained = new ItemStack(this);
                    // if the stack is empty, relace it with the empty bucket
                    if (returnStack.isEmpty()) {
                        returnStack = drained;
                    } else if (!drained.isEmpty()) {
                        // otheriwise add empty bucket to player inventory
                        ItemHandlerHelper.giveItemToPlayer(player, drained);
                    }
                }
                player.addStat(StatList.CAULDRON_FILLED);
                if (!world.isRemote) {
                    Blocks.CAULDRON.setWaterLevel(world, clickPos, clickState, 3);
                }
                world.playSound((EntityPlayer) null, clickPos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
            }
            return ActionResult.newResult(EnumActionResult.SUCCESS, returnStack);
        // try fluid positions then
        // can the player place there?
        } else if (player.canPlayerEdit(clickPos, mop.sideHit, stack)) {
            BlockPos targetPos = clickPos.offset(mop.sideHit);
            // next, try special fluids
            if (hasSpecialFluid(stack)) {
                // get the state from the fluid
                IBlockState state = getSpecialFluid(stack).getState();
                // if we got a block state (not milk basically)
                if (state != null) {
                    IBlockState currentState = world.getBlockState(targetPos);
                    if (currentState.getBlock().isReplaceable(world, targetPos)) {
                        // place block
                        if (!world.isRemote) {
                            world.setBlockState(targetPos, state);
                        }
                        // sound effect
                        world.playSound(player, targetPos, state.getBlock().getSoundType(state, world, targetPos, player).getPlaceSound(), SoundCategory.BLOCKS, 1.0F, 0.8F);
                        // only empty if not creative
                        if (!player.capabilities.isCreativeMode) {
                            player.addStat(StatList.getObjectUseStats(this));
                            setSpecialFluid(stack, SpecialFluid.EMPTY);
                        }
                        return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
                    }
                }
            // try placing liquid
            } else {
                FluidActionResult result = FluidUtil.tryPlaceFluid(player, player.getEntityWorld(), targetPos, stack, fluidStack);
                if (result.isSuccess()) {
                    // water and lava place non-flowing for some reason
                    if (fluidStack.getFluid() == FluidRegistry.WATER || fluidStack.getFluid() == FluidRegistry.LAVA) {
                        IBlockState state = world.getBlockState(targetPos);
                        world.neighborChanged(targetPos, state.getBlock(), targetPos);
                    }
                    ItemStack returnStack = stack.copy();
                    if (!player.capabilities.isCreativeMode) {
                        returnStack.shrink(1);
                        ItemStack drained = result.getResult().copy();
                        // if the stack is empty, relace it with the empty bucket
                        if (returnStack.isEmpty()) {
                            returnStack = drained;
                        } else if (!drained.isEmpty()) {
                            // otheriwise add empty bucket to player inventory
                            ItemHandlerHelper.giveItemToPlayer(player, drained);
                        }
                    }
                    return ActionResult.newResult(EnumActionResult.SUCCESS, returnStack);
                }
            }
        }
    }
    // couldn't place liquid there
    return ActionResult.newResult(EnumActionResult.FAIL, stack);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) FluidStack(net.minecraftforge.fluids.FluidStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult)

Example 60 with ActionResult

use of net.minecraft.util.ActionResult in project CompositeGear by TwilightWingsStudio.

the class ItemCGBow 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 = !this.findAmmo(playerIn).isEmpty();
    ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, worldIn, playerIn, handIn, flag);
    if (ret != null)
        return ret;
    if (!playerIn.capabilities.isCreativeMode && !flag) {
        return flag ? new ActionResult(EnumActionResult.PASS, itemstack) : new ActionResult(EnumActionResult.FAIL, itemstack);
    } else {
        playerIn.setActiveHand(handIn);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
    }
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

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