Java Code Examples for net.minecraft.item.ItemStack#getMaxCount()
The following examples show how to use
net.minecraft.item.ItemStack#getMaxCount() .
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: SyncedGuiDescription.java From LibGui with MIT License | 6 votes |
/** WILL MODIFY toInsert! Returns true if anything was inserted. */ private boolean insertIntoExisting(ItemStack toInsert, Slot slot, PlayerEntity player) { ItemStack curSlotStack = slot.getStack(); if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack) && slot.canTakeItems(player)) { int combinedAmount = curSlotStack.getCount() + toInsert.getCount(); if (combinedAmount <= toInsert.getMaxCount()) { toInsert.setCount(0); curSlotStack.setCount(combinedAmount); slot.markDirty(); return true; } else if (curSlotStack.getCount() < toInsert.getMaxCount()) { toInsert.decrement(toInsert.getMaxCount() - curSlotStack.getCount()); curSlotStack.setCount(toInsert.getMaxCount()); slot.markDirty(); return true; } } return false; }
Example 2
Source File: ElectricCompressorBlockEntity.java From Galacticraft-Rewoven with MIT License | 5 votes |
protected void craftItem(ItemStack craftingResult) { boolean canCraftTwo = true; for (int i = 0; i < 9; i++) { ItemStack item = getInventory().getStack(i); // If slot is not empty ( must be an ingredient if we've made it this far ), and there is less than 2 items in the slot, we cannot craft two. if (!item.isEmpty() && item.getCount() < 2) { canCraftTwo = false; break; } } if (canCraftTwo) { if (getInventory().getStack(OUTPUT_SLOT).getCount() >= craftingResult.getMaxCount() || getInventory().getStack(SECOND_OUTPUT_SLOT).getCount() >= craftingResult.getMaxCount()) { // There would be too many items in the output slot. Just craft one. canCraftTwo = false; } } for (int i = 0; i < 9; i++) { decrement(i, canCraftTwo ? 2 : 1); } // <= because otherwise it loops only once and puts in only one slot for (int i = OUTPUT_SLOT; i <= SECOND_OUTPUT_SLOT; i++) { insert(i, craftingResult); } }
Example 3
Source File: RecipeBook_1_12.java From multiconnect with MIT License | 5 votes |
private boolean canStackAddMore(ItemStack existingStack, ItemStack stack) { return !existingStack.isEmpty() && existingStack.getItem() == stack.getItem() && ItemStack.areTagsEqual(existingStack, stack) && existingStack.isStackable() && existingStack.getCount() < existingStack.getMaxCount() && existingStack.getCount() < 64; }
Example 4
Source File: ItemEntityMixin.java From fabric-carpet with MIT License | 5 votes |
@Redirect( method = "canMerge", at = @At( value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getMaxCount()I" ) ) private int getItemStackMaxAmount(ItemStack stack) { if (CarpetSettings.stackableShulkerBoxes && stack.getItem() instanceof BlockItem && ((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock) return SHULKERBOX_MAX_STACK_AMOUNT; return stack.getMaxCount(); }