public static void decrStackSize(EntityPlayer entityPlayer, int currentItem) { if (entityPlayer.capabilities.isCreativeMode == false) { entityPlayer.inventory.decrStackSize(currentItem, 1); } }
/** Call this to reward the player with an item **/ protected final void takeHeldStack(EntityPlayer player, int amount) { player.inventory.decrStackSize(player.inventory.currentItem, amount); }
public void activate( final EntityPlayer player ) { if( !Platform.hasPermissions( new DimensionalCoord( this ), player ) ) { return; } final ItemStack myItem = this.inv.getStackInSlot( 0 ); if( myItem.isEmpty() ) { ItemStack held = player.inventory.getCurrentItem(); if( AEApi.instance().definitions().materials().certusQuartzCrystal().isSameAs( held ) || Platform.isChargeable( held ) ) { held = player.inventory.decrStackSize( player.inventory.currentItem, 1 ); this.inv.setStackInSlot( 0, held ); } } else { final List<ItemStack> drops = new ArrayList<>(); drops.add( myItem ); this.inv.setStackInSlot( 0, ItemStack.EMPTY ); Platform.spawnDrops( this.world, this.pos.offset( this.getForward() ), drops ); } }
public void selectDinosaur(Dinosaur dinosaur) { this.mc.displayGuiScreen(null); if (!this.mc.player.capabilities.isCreativeMode) { InventoryPlayer inventory = this.mc.player.inventory; inventory.decrStackSize(inventory.currentItem, 1); } JurassiCraft.NETWORK_WRAPPER.sendToServer(new PlacePaddockSignMessage(this.hand, this.facing, this.pos, dinosaur)); }
@Override public void onWornTick(ItemStack itemStack, EntityLivingBase wearer) { if (!(wearer instanceof EntityPlayer)) { return; } EntityPlayer player = (EntityPlayer) wearer; if (player.ticksExisted % 50 == 0) { for (int i = 0; i < InventoryPlayer.getHotbarSize(); i++) { ItemStack item = player.inventory.getStackInSlot(i); if (item != null && item.getItem() instanceof ItemSteamCell && ItemSteamCell.chargeItems(player, false)) { player.inventory.decrStackSize(i, 1); break; } } } } }
@Override public void onQuestCompleted(QuestStack questStack, EntityPlayer entityPlayer) { if (!destroyOnCollect) { int itemCount = getMaxItemCount(questStack); for (int i = 0; i < entityPlayer.inventory.getSizeInventory(); i++) { ItemStack stackInSlot = entityPlayer.inventory.getStackInSlot(i); if (!stackInSlot.isEmpty()) { if (matches(questStack, stackInSlot) && itemCount > 0) { int newItemCount = Math.max(0, itemCount - stackInSlot.getCount()); int takenFromStack = itemCount - newItemCount; entityPlayer.inventory.decrStackSize(i, takenFromStack); itemCount = newItemCount; } } } } }
/** * Removes from an inventory slot up to a specified number of items and returns them in a new stack. * @param slot to remove from * @param amount to remove in the item stack * @return the removed items in a item stack, if any */ @Override public ItemStack decrStackSize(int slot, int amount) { if (slot >= OFFSET) { ItemStack targetStack = extraItems[slot - OFFSET]; if (!targetStack.isEmpty()) { hasChanged = true; if (targetStack.getCount() <= amount) { extraItems[slot - OFFSET] = ItemStack.EMPTY; return targetStack; } else { targetStack = extraItems[slot - OFFSET].splitStack(amount); if (extraItems[slot - OFFSET].getCount() == 0) { extraItems[slot - OFFSET] = ItemStack.EMPTY; } return targetStack; } } return ItemStack.EMPTY; } else { return super.decrStackSize(slot, amount); } }
@Override public void onServerReceived(MinecraftServer server, PlacePaddockSignMessage message, EntityPlayer player, MessageContext messageContext) { World world = player.world; EnumFacing side = message.facing; BlockPos pos = message.pos; PaddockSignEntity paddockSign = new PaddockSignEntity(world, pos, side, message.dino); ItemStack heldItem = player.getHeldItem(message.hand); if (heldItem != null && heldItem.getItem() == ItemHandler.PADDOCK_SIGN) { if (player.canPlayerEdit(pos, side, heldItem) && paddockSign.onValidSurface()) { world.spawnEntity(paddockSign); if (!player.capabilities.isCreativeMode) { InventoryPlayer inventory = player.inventory; inventory.decrStackSize(inventory.currentItem, 1); } } } }
protected void consumeItems(AndroidPlayer androidPlayer) { for (ItemStack itemStack : requiredItems) { int itemCount = itemStack.getCount(); for (int j = 0; j < androidPlayer.getPlayer().inventory.getSizeInventory(); j++) { ItemStack pStack = androidPlayer.getPlayer().inventory.getStackInSlot(j); if (!pStack.isEmpty() && pStack.isItemEqual(itemStack)) { int countShouldTake = Math.min(itemCount, pStack.getCount()); androidPlayer.getPlayer().inventory.decrStackSize(j, countShouldTake); itemCount -= countShouldTake; } if (itemCount <= 0) { return; } } } }
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack heldItem = playerIn.getHeldItem(handIn); if (worldIn.isRemote) { return ActionResult.newResult(EnumActionResult.PASS, heldItem); } ResearchNote note = new ResearchNote(heldItem.getTagCompound()); if (note.registerResults(worldIn, playerIn)) { playerIn.inventory.decrStackSize(playerIn.inventory.currentItem, 1); // Notify player that his inventory has changed. NetworkUtil.inventoryChangeNotify(playerIn); } return ActionResult.newResult(EnumActionResult.SUCCESS, heldItem); } }
player.inventory.decrStackSize((Integer) obj[0], 4); player.inventoryContainer.detectAndSendChanges(); return EnumActionResult.SUCCESS;
findFirstSlotInItemHandlerWith(new InvWrapper(player.inventory), itemStack -> itemStack.isItemEqual(new ItemStack(Blocks.EMERALD_BLOCK))); player.inventory.decrStackSize(slot, 1);
@Nonnull @Override protected ItemStack findAmmo(EntityPlayer player, ItemStack bowStack) { boolean arrow = reduceArrowCount(bowStack, player.getRNG()); if (!arrow) { for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { ItemStack itemstack = player.inventory.getStackInSlot(i); if (!itemstack.isEmpty() && this.isArrowPackage(itemstack)) { setArrowsLeft(bowStack, MAX_ARROW_COUNT); if (!player.capabilities.isCreativeMode) { player.inventory.decrStackSize(i, 1); } player.getCooldownTracker().setCooldown(bowStack.getItem(), getReloadCooldown(player, bowStack)); } } return ItemStack.EMPTY; } return new ItemStack(ModItems.crossbow_arrow); }
if (contract.getItem() instanceof Contract) { extendedProperties.addQuest(((Contract) contract.getItem()).getQuest(contract).copy()); extendedProperties.getPlayer().inventory.decrStackSize(message.questID, 1);
player.inventory.decrStackSize(slot, 1);
entityPlayer.inventory.decrStackSize(slot, 1);
world.setBlockState(pos, this.getStateFromMeta(color.ordinal()), 2); if(!player.capabilities.isCreativeMode){ player.inventory.decrStackSize(player.inventory.currentItem, 1);
private void extractIntoContainer(EntityPlayer player, IFluidHandler tank) { FluidStack fluidStack = tank.drain(1, false); if (fluidStack != null) { ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND).copy(); if (1 <= 0) { heldItem.setCount(0); } else { heldItem.setCount(1); } int capacity = FluidTools.getCapacity(fluidStack, heldItem); if (capacity != 0) { fluidStack = tank.drain(capacity, false); if (fluidStack != null && fluidStack.amount == capacity) { fluidStack = tank.drain(capacity, true); ItemStack filledContainer = FluidTools.fillContainer(fluidStack, heldItem); if (!filledContainer.isEmpty()) { player.inventory.decrStackSize(player.inventory.currentItem, 1); if (!player.inventory.addItemStackToInventory(filledContainer)) { EntityItem entityItem = new EntityItem(player.getEntityWorld(), player.posX, player.posY, player.posZ, filledContainer); player.getEntityWorld().spawnEntity(entityItem); } player.openContainer.detectAndSendChanges(); } else { // Try to insert the fluid back into the tank tank.fill(fluidStack, true); } } } } }
toPut.setCount(1); reconstructor.inv.setStackInSlot(0, toPut); player.inventory.decrStackSize(player.inventory.currentItem, 1);
bucket = StackUtils.EMPTY_BUCKET.copy(); player.inventory.decrStackSize(i, 1);