Java Code Examples for net.minecraft.item.ItemStack#shrink()
The following examples show how to use
net.minecraft.item.ItemStack#shrink() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemListGridWidget.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
private void handleSlotShiftClick(INativeWidget clickedSlot) { ItemStack itemStack = clickedSlot.getHandle().getStack(); if (clickedSlot.getHandle().canTakeStack(gui.entityPlayer) && !itemStack.isEmpty()) { itemStack = clickedSlot.onItemTake(gui.entityPlayer, itemStack, true); int amountInserted = getItemList().insertItem(new ItemStackKey(itemStack), itemStack.getCount(), false, InsertMode.LOWEST_PRIORITY); if (amountInserted > 0) { clickedSlot.onItemTake(gui.entityPlayer, itemStack, false); itemStack.shrink(amountInserted); if (!clickedSlot.canMergeSlot(itemStack)) { gui.entityPlayer.dropItem(itemStack.copy(), false, false); itemStack.setCount(0); } clickedSlot.getHandle().onSlotChanged(); uiAccess.sendSlotUpdate(clickedSlot); gui.entityPlayer.openContainer.detectAndSendChanges(); } } }
Example 2
Source File: ItemEnderPart.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase livingBase, EnumHand hand) { // Jailer module if (this.getModuleType(stack).equals(ModuleType.TYPE_MOBPERSISTENCE)) { if (livingBase instanceof EntityLiving && EntityUtils.applyMobPersistence((EntityLiving)livingBase)) { if (player.getEntityWorld().isRemote == false && player.capabilities.isCreativeMode == false) { stack.shrink(1); } return true; } } return false; }
Example 3
Source File: TileEntityBarrel.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
private boolean tryApplyUpgrade(EntityPlayer player, EnumHand hand, int slot, Item item, int meta) { ItemStack stack = player.getHeldItem(hand); if (stack.getItem() == item && stack.getMetadata() == meta) { if (this.itemHandlerUpgrades.insertItem(slot, new ItemStack(EnderUtilitiesItems.ENDER_PART, 1, meta), false).isEmpty()) { if (player.capabilities.isCreativeMode == false) { stack.shrink(1); player.setHeldItem(hand, stack.isEmpty() ? ItemStack.EMPTY : stack); } this.getWorld().playSound(null, this.getPos(), SoundEvents.ENTITY_ITEMFRAME_PLACE, SoundCategory.BLOCKS, 1f, 1f); return true; } } return false; }
Example 4
Source File: ItemEnderPart.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return EnumActionResult.PASS; } ItemStack stack = player.getHeldItem(hand); // Ender Relic if (stack.getMetadata() == 40 && EntityUtils.spawnEnderCrystal(world, pos)) { if (player.capabilities.isCreativeMode == false) { stack.shrink(1); } return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }
Example 5
Source File: GTTileMagicEnergyAbsorber.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
public boolean isConvertingToolItem() { ItemStack inputStack = this.getStackInSlot(slotInput); int level = GTHelperStack.getItemStackEnchantmentLevel(inputStack); if (level > 0 && !this.isFull()) { int generate = world.rand.nextInt(20000 * level); ItemStack blankTool = inputStack.copy(); blankTool.getTagCompound().removeTag("ench"); if (!GTHelperStack.canMerge(blankTool, this.getStackInSlot(slotOutput))) { return false; } this.addEnergy(generate); this.setStackInSlot(slotOutput, StackUtil.copyWithSize(blankTool, this.getStackInSlot(slotOutput).getCount() + 1)); inputStack.shrink(1); world.playSound((EntityPlayer) null, this.pos, SoundEvents.BLOCK_PORTAL_AMBIENT, SoundCategory.BLOCKS, 0.5F, 0.75F + world.rand.nextFloat()); return true; } return false; }
Example 6
Source File: ItemBomb.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if (!world.isRemote) { EntityBomb bomb = new EntityBomb(world, player); bomb.setBombItem(stack); bomb.setPosition(player.posX, player.posY + player.eyeHeight, player.posZ); bomb.shoot(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f); stack.shrink(1); world.spawnEntity(bomb); bomb.velocityChanged = true; } player.getCooldownTracker().setCooldown(this, 20); return new ActionResult<>(EnumActionResult.PASS, stack); }
Example 7
Source File: EntityFluidCow.java From Moo-Fluids with GNU General Public License v3.0 | 6 votes |
private boolean attemptToBreedCow(final ItemStack currentItemStack, final EntityPlayer entityPlayer) { if (isBreedingItem(currentItemStack) && getGrowingAge() == 0) { if (!entityPlayer.capabilities.isCreativeMode) { currentItemStack.shrink(1); if (currentItemStack.isEmpty()) { entityPlayer.inventory.setInventorySlotContents( entityPlayer.inventory.currentItem, ItemStack.EMPTY); } } setInLove(entityPlayer); return true; } return false; }
Example 8
Source File: ItemRainStick.java From CommunityMod with GNU Lesser General Public License v2.1 | 6 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack heldStack = player.getHeldItem(hand); if (!player.capabilities.isCreativeMode) heldStack.shrink(1); world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_SKELETON_DEATH, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!world.isRemote) { WorldInfo worldinfo = world.getWorldInfo(); worldinfo.setCleanWeatherTime(0); worldinfo.setRainTime(1200); worldinfo.setThunderTime(1200); worldinfo.setRaining(true); worldinfo.setThundering(false); } else player.sendMessage(new TextComponentString("Dark clouds start forming in the sky")); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, heldStack); }
Example 9
Source File: GTHelperFluid.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
public static boolean doClickableFluidContainerEmptyThings(EntityPlayer player, EnumHand hand, World world, BlockPos pos, IC2Tank tank) { ItemStack playerStack = player.getHeldItem(hand); if (!playerStack.isEmpty()) { FluidActionResult result = FluidUtil.tryEmptyContainer(playerStack, tank, tank.getCapacity() - tank.getFluidAmount(), player, true); if (result.isSuccess()) { playerStack.shrink(1); ItemStack resultStack = result.getResult(); if (!resultStack.isEmpty()) { if (!player.inventory.addItemStackToInventory(resultStack)) { player.dropItem(resultStack, false); } } return true; } } return false; }
Example 10
Source File: ItemSeeds.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack itemstack = player.getHeldItem(hand); IBlockState state = worldIn.getBlockState(pos); if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, itemstack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up())) { worldIn.setBlockState(pos.up(), content.plant.createState()); if (player instanceof EntityPlayerMP) { CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos.up(), itemstack); } itemstack.shrink(1); return EnumActionResult.SUCCESS; } else { return EnumActionResult.FAIL; } }
Example 11
Source File: GTTileEnergyTransmitter.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean onRightClick(EntityPlayer player, EnumHand arg1, EnumFacing arg2, Side arg3) { ItemStack slotStack = this.getStackInSlot(0); if (slotStack.isEmpty() || !player.isSneaking()) { return false; } ItemHandlerHelper.giveItemToPlayer(player, slotStack.copy()); slotStack.shrink(1); this.targetPos = null; IC2.audioManager.playOnce(player, Ic2Sounds.wrenchUse); return true; }
Example 12
Source File: TileEntityDistillation.java From Sakura_mod with MIT License | 5 votes |
private void DrainInput() { ItemStack itemstack = this.inventory.get(3); ItemStack itemstack2 = this.inventory.get(4); if (this.getResultTank() != null) { FluidStack fluid = LiquidToItemRecipe.instance().getResultFluid(this.getResultTank().getFluid()); if (fluid != null) { ItemStack itemstack1 = LiquidToItemRecipe.instance().getResultItemStack(this.getResultTank().getFluid(), itemstack); if (itemstack1.isEmpty()) return; if (this.getResultTank().getFluid().amount < fluid.amount) return; boolean not_full = (itemstack2.getCount() + itemstack1.getCount() <= this.getInventoryStackLimit() && itemstack2.getCount() + itemstack1.getCount() <= itemstack2.getMaxStackSize()); if (!not_full) return; if (itemstack2.isEmpty()) { this.inventory.set(4, itemstack1.copy()); } else if (itemstack2.getItem() == itemstack1.getItem()) { itemstack2.grow(itemstack1.getCount()); } if (!itemstack.getItem().hasContainerItem(itemstack)) itemstack.shrink(1); else this.inventory.set(3, new ItemStack(itemstack.getItem().getContainerItem())); this.getResultTank().drain(fluid, true); } } }
Example 13
Source File: TurbineRotorBehavior.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public void applyRotorDamage(ItemStack itemStack, int damageApplied) { int rotorDurability = getPartMaxDurability(itemStack); int resultDamage = getPartDamage(itemStack) + damageApplied; if (resultDamage >= rotorDurability) { itemStack.shrink(1); } else { setPartDamage(itemStack, resultDamage); } }
Example 14
Source File: BlockFoam.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stackInHand = playerIn.getHeldItem(hand); if (!stackInHand.isEmpty() && OreDictUnifier.getOreDictionaryNames(stackInHand).contains("sand")) { worldIn.setBlockState(pos, getPetrifiedBlock(state)); worldIn.playSound(playerIn, pos, SoundEvents.BLOCK_SAND_PLACE, SoundCategory.BLOCKS, 1.0f, 1.0f); if (!playerIn.capabilities.isCreativeMode) stackInHand.shrink(1); return true; } return false; }
Example 15
Source File: EntityFluidCow.java From Moo-Fluids with GNU General Public License v3.0 | 5 votes |
private boolean attemptToGetFluidFromCow(final ItemStack currentItemStack, final EntityPlayer entityPlayer) { boolean canGetFluid = false; if (!currentItemStack.isEmpty() && entityFluid != null) { ItemStack filledItemStack = ItemHandlerHelper.copyStackWithSize(currentItemStack, 1); IFluidHandlerItem fluidHandlerItem = FluidUtil.getFluidHandler(filledItemStack); if (fluidHandlerItem != null) { if (fluidHandlerItem.fill( new FluidStack(entityFluid, Fluid.BUCKET_VOLUME), true) == Fluid.BUCKET_VOLUME) { filledItemStack = fluidHandlerItem.getContainer(); currentItemStack.shrink(1); if (currentItemStack.isEmpty()) { entityPlayer.inventory.setInventorySlotContents( entityPlayer.inventory.currentItem, filledItemStack.copy()); } else { ItemHandlerHelper.giveItemToPlayer(entityPlayer, filledItemStack.copy()); } canGetFluid = true; } } } return canGetFluid; }
Example 16
Source File: EventHandlers.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@SubscribeEvent public static void onPlayerInteraction(PlayerInteractEvent.RightClickBlock event) { ItemStack stack = event.getItemStack(); if (!stack.isEmpty() && stack.getItem() == Items.FLINT_AND_STEEL) { if (!event.getWorld().isRemote && !event.getEntityPlayer().capabilities.isCreativeMode && event.getWorld().rand.nextInt(100) >= ConfigHolder.flintChanceToCreateFire) { stack.damageItem(1, event.getEntityPlayer()); if (stack.getItemDamage() >= stack.getMaxDamage()) { stack.shrink(1); } event.setCanceled(true); } } }
Example 17
Source File: SawmillTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void processItem(ChoppingContext ctx, ChoppingRecipe recipe) { ItemStack input = inventory.getStackInSlot(0); if (input.isEmpty()) return; ItemStack result = getResult(ctx, recipe); if (result.getCount() <= 0) return; inventory.insertItem(2, result, false); input.shrink(1); }
Example 18
Source File: EngineItemHandler.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate){ if(cap.isMotorized()) return onceInstalled.insertItem(slot, stack, simulate); if(stack.isEmpty() || slot != 0 || stack.getItem() != ModItems.CART_ENGINE) return stack; if(!simulate) cap.setMotorized(); stack = stack.copy(); stack.shrink(1); return stack; }
Example 19
Source File: ItemNigari.java From TofuCraftReload with MIT License | 4 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { if (worldIn.isRemote) return new ActionResult<ItemStack>(EnumActionResult.PASS, ItemStack.EMPTY); RayTraceResult var4 = this.rayTrace(worldIn, playerIn, true); ItemStack itemStackIn = playerIn.getHeldItem(handIn); if (var4 == null) { return new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn); } else { if (var4.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos targetPos = var4.getBlockPos(); Block var11 = worldIn.getBlockState(targetPos).getBlock(); Block var13 = null; if (var11 == BlockLoader.SOYMILK) { var13 = BlockLoader.KINUTOFU; } else if (var11 == BlockLoader.SOYMILKHELL) { var13 = BlockLoader.TOFUHELL; } else if (var11 == BlockLoader.ZUNDASOYMILK) { var13 = BlockLoader.TOFUZUNDA; } if (var13 != null) { worldIn.playSound(playerIn, targetPos.add(0.5, 0.5, 0.5), var13.getSoundType(var13.getDefaultState(), worldIn, targetPos, playerIn).getBreakSound(), SoundCategory.BLOCKS, (var13.getSoundType(var13.getDefaultState(), worldIn, targetPos, playerIn).getVolume() + 1.0F) / 2.0F, var13.getSoundType(var13.getDefaultState(), worldIn, targetPos, playerIn).getPitch() * 0.8F); worldIn.setBlockState(targetPos, var13.getDefaultState()); if (!playerIn.capabilities.isCreativeMode) { itemStackIn.shrink(1); ItemStack container = new ItemStack(this.getContainerItem()); if (itemStackIn.getCount() <= 0) { return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, container); } if (!playerIn.inventory.addItemStackToInventory(container)) { playerIn.dropItem(container, false); } } } } return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn); } }
Example 20
Source File: ItemPetContract.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase target, EnumHand hand) { if (target instanceof EntityTameable) { if (player.getEntityWorld().isRemote == false) { if (this.isSigned(stack)) { UUID targetOwner = ((EntityTameable) target).getOwnerId(); UUID signedOwner = this.getOwnerUUID(stack); // This contract is signed by the current owner of the target, // and the contract is for this target entity, and the player is not the owner // -> change the owner of the target. if (targetOwner != null && targetOwner.equals(signedOwner) && target.getUniqueID().equals(this.getSubjectUUID(stack)) && player.getUniqueID().equals(signedOwner) == false) { ((EntityTameable) target).setTamed(true); ((EntityTameable) target).setOwnerId(player.getUniqueID()); // See EntityTameable#handleStatusUpdate() player.getEntityWorld().setEntityState(target, (byte) 7); stack.shrink(1); } } // Blank contract - if the target is tamed, and owned by the player, sign the contract else { if (((EntityTameable) target).isTamed() && ((EntityTameable) target).isOwner(player)) { ItemStack stackSigned = stack.copy(); stackSigned.setCount(1); this.signContract(stackSigned, player, target); if (player.addItemStackToInventory(stackSigned) == false) { player.dropItem(stackSigned, false); } stack.shrink(1); } } } return true; } return super.itemInteractionForEntity(stack, player, target, hand); }