Java Code Examples for net.minecraft.inventory.Slot#getStack()
The following examples show how to use
net.minecraft.inventory.Slot#getStack() .
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: ContainerInterfaceFluid.java From ExtraCells1 with MIT License | 6 votes |
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slotnumber) { ItemStack itemstack = null; Slot slot = (Slot) inventorySlots.get(slotnumber); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); itemstack.stackSize = 1; if (tileentity.isItemValidForSlot(slotnumber, itemstack1)) { if (slotnumber >= 0 && slotnumber <= 5) { ((Slot) inventorySlots.get(slotnumber)).putStack(null); return null; } } } return null; }
Example 2
Source File: ContainerBase.java From OpenModsLib with MIT License | 6 votes |
@Override @Nonnull public ItemStack transferStackInSlot(EntityPlayer player, int slotId) { final Slot slot = inventorySlots.get(slotId); if (slot != null && canTransferItemOut(slot) && slot.getHasStack()) { ItemStack itemToTransfer = slot.getStack(); ItemStack copy = itemToTransfer.copy(); if (slotId < inventorySize) { if (!mergeItemStackSafe(itemToTransfer, inventorySize, inventorySlots.size(), true)) return ItemStack.EMPTY; } else if (!mergeItemStackSafe(itemToTransfer, 0, inventorySize, false)) return ItemStack.EMPTY; slot.putStack(itemToTransfer); if (itemToTransfer.getCount() != copy.getCount()) return copy; } return ItemStack.EMPTY; }
Example 3
Source File: GuiContainer.java From NotEnoughItems with MIT License | 6 votes |
private void updateActivePotionEffects() { ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); if (itemstack != null && this.dragSplitting) { this.dragSplittingRemnant = itemstack.stackSize; for (Slot slot : this.dragSplittingSlots) { ItemStack itemstack1 = itemstack.copy(); int i = slot.getStack() == null ? 0 : slot.getStack().stackSize; Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack1, i); if (itemstack1.stackSize > itemstack1.getMaxStackSize()) { itemstack1.stackSize = itemstack1.getMaxStackSize(); } if (itemstack1.stackSize > slot.getItemStackLimit(itemstack1)) { itemstack1.stackSize = slot.getItemStackLimit(itemstack1); } this.dragSplittingRemnant -= itemstack1.stackSize - i; } } }
Example 4
Source File: SlotUtil.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
private static void adjustPhantomSlot(Slot slot, int mouseButton, ClickType clickTypeIn) { ItemStack stackSlot = slot.getStack(); int stackSize; if (clickTypeIn == ClickType.QUICK_MOVE) { stackSize = mouseButton == 0 ? (stackSlot.getCount() + 1) / 2 : stackSlot.getCount() * 2; } else { stackSize = mouseButton == 0 ? stackSlot.getCount() - 1 : stackSlot.getCount() + 1; } if (stackSize > slot.getSlotStackLimit()) { stackSize = slot.getSlotStackLimit(); } stackSlot.setCount(stackSize); slot.putStack(stackSlot); }
Example 5
Source File: FastTransferManager.java From NotEnoughItems with MIT License | 5 votes |
public void retrieveItem(GuiContainer window, int toSlot) { Slot slot = window.inventorySlots.getSlot(toSlot); ItemStack slotStack = slot.getStack(); if (slotStack.isEmpty() || slotStack.getCount() == slot.getSlotStackLimit() || slotStack.getCount() == slotStack.getMaxStackSize()) { return; } generateSlotMap(window.inventorySlots, slotStack); Integer destZone = slotZoneMap.get(toSlot); if (destZone == null)//slots that don't accept { return; } int firstZoneSlot = findShiftClickDestinationSlot(window.inventorySlots, toSlot); int firstZone = -1; if (firstZoneSlot != -1) { Integer integer = slotZoneMap.get(firstZoneSlot); if (integer != null) { firstZone = integer; if (retrieveItemFromZone(window, firstZone, toSlot)) { return; } } } for (int zone = 0; zone < slotZones.size(); zone++) { if (zone == destZone || zone == firstZone) { continue; } if (retrieveItemFromZone(window, zone, toSlot)) { return; } } retrieveItemFromZone(window, destZone, toSlot); }
Example 6
Source File: ContainerVessel.java From TFC2 with GNU General Public License v3.0 | 5 votes |
/** * Called to transfer a stack from one inventory to the other eg. when shift clicking. */ @Override public ItemStack transferStackInSlotTFC(EntityPlayer player, int slotNum) { ItemStack origStack = ItemStack.EMPTY; Slot slot = (Slot)this.inventorySlots.get(slotNum); if (slot != null && slot.getHasStack()) { ItemStack slotStack = slot.getStack(); origStack = slotStack.copy(); // From pile to inventory if (slotNum < 36) { if (!this.mergeItemStack(slotStack, 36, inventorySlots.size(), true)) return ItemStack.EMPTY; } else { if (!this.mergeItemStack(slotStack, 0, 36, false)) return ItemStack.EMPTY; } if (slotStack.getMaxStackSize() <= 0) slot.putStack(ItemStack.EMPTY); else slot.onSlotChanged(); if (slotStack.getMaxStackSize() == origStack.getMaxStackSize()) return ItemStack.EMPTY; slot.onTake(player, slotStack); } return origStack; }
Example 7
Source File: ContainerPneumaticGenerator.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
/** * @param itemStack * ItemStack to merge into inventory * @param start * minimum slot to attempt fill * @param end * maximum slot to attempt fill * @param backwards * go backwards * @return true if stacks merged successfully public boolean * mergeItemStack(itemStack, start, end, backwards) */ @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){ ItemStack var3 = null; Slot var4 = (Slot)inventorySlots.get(par2); if(var4 != null && var4.getHasStack()) { ItemStack var5 = var4.getStack(); var3 = var5.copy(); if(par2 < 4) { if(!mergeItemStack(var5, 4, 39, false)) return null; var4.onSlotChange(var5, var3); } else if(var3.getItem() == Itemss.machineUpgrade) { if(!mergeItemStack(var5, 0, 4, false)) return null; var4.onSlotChange(var5, var3); } if(var5.stackSize == 0) { var4.putStack((ItemStack)null); } else { var4.onSlotChanged(); } if(var5.stackSize == var3.stackSize) return null; var4.onPickupFromSlot(par1EntityPlayer, var5); } return var3; }
Example 8
Source File: ContainerThermopneumaticProcessingPlant.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
/** * @param itemStack * ItemStack to merge into inventory * @param start * minimum slot to attempt fill * @param end * maximum slot to attempt fill * @param backwards * go backwards * @return true if stacks merged successfully public boolean * mergeItemStack(itemStack, start, end, backwards) */ @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){ ItemStack var3 = null; Slot var4 = (Slot)inventorySlots.get(par2); if(var4 != null && var4.getHasStack()) { ItemStack var5 = var4.getStack(); var3 = var5.copy(); if(par2 < 5) { if(!mergeItemStack(var5, 5, 41, false)) return null; var4.onSlotChange(var5, var3); } else { if(var5.getItem() == Itemss.machineUpgrade) { if(!mergeItemStack(var5, 0, 4, false)) return null; } else { if(!mergeItemStack(var5, 4, 5, false)) return null; } var4.onSlotChange(var5, var3); } if(var5.stackSize == 0) { var4.putStack((ItemStack)null); } else { var4.onSlotChanged(); } if(var5.stackSize == var3.stackSize) return null; var4.onPickupFromSlot(par1EntityPlayer, var5); } return var3; }
Example 9
Source File: FastTransferManager.java From NotEnoughItems with MIT License | 5 votes |
public void retrieveItem(GuiContainer window, int toSlot) { Slot slot = window.inventorySlots.getSlot(toSlot); ItemStack slotStack = slot.getStack(); if (slotStack == null || slotStack.stackSize == slot.getSlotStackLimit() || slotStack.stackSize == slotStack.getMaxStackSize()) return; generateSlotMap(window.inventorySlots, slotStack); Integer destZone = slotZoneMap.get(toSlot); if (destZone == null)//slots that don't accept return; int firstZoneSlot = findShiftClickDestinationSlot(window.inventorySlots, toSlot); int firstZone = -1; if (firstZoneSlot != -1) { Integer integer = slotZoneMap.get(firstZoneSlot); if (integer != null) { firstZone = integer; if (retrieveItemFromZone(window, firstZone, toSlot)) return; } } for (int zone = 0; zone < slotZones.size(); zone++) { if (zone == destZone || zone == firstZone) continue; if (retrieveItemFromZone(window, zone, toSlot)) return; } retrieveItemFromZone(window, destZone, toSlot); }
Example 10
Source File: ContainerMinecoprocessor.java From Minecoprocessors with GNU General Public License v3.0 | 5 votes |
@Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) { ItemStack previous = ItemStack.EMPTY; Slot slot = this.inventorySlots.get(fromSlot); if (slot != null && slot.getHasStack()) { ItemStack current = slot.getStack(); previous = current.copy(); if (fromSlot == 0) { if (!this.mergeItemStack(current, 1, 37, true)) { return ItemStack.EMPTY; } } else { if (!this.mergeItemStack(current, 0, 1, true)) { return ItemStack.EMPTY; } } slot.onSlotChange(current, previous); if (current.isEmpty()) { slot.putStack(ItemStack.EMPTY); } else { slot.onSlotChanged(); } if (current.getCount() == previous.getCount()) { return ItemStack.EMPTY; } slot.onTake(playerIn, current); } return previous; }
Example 11
Source File: ContainerSpaceLaser.java From AdvancedRocketry with MIT License | 5 votes |
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { ItemStack stack = null; Slot slotObject = (Slot) inventorySlots.get(slot); //null checks and checks if the item can be stacked (maxStackSize > 1) if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); //merges the item into player inventory since its in the tileEntity if (slot == 0) { if (!this.mergeItemStack(stackInSlot, 1, 35, true)) { return null; } } //placing it into the tileEntity is possible since its in the player inventory //check to make sure it's valid for the slot else if (!laserTile.isItemValidForSlot(0, stack) || !this.mergeItemStack(stackInSlot, 0, 1, false)) { return null; } if (stackInSlot.getCount() == 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } if (stackInSlot.getCount() == stack.getCount()) { return null; } slotObject.onTake(player, stackInSlot); } return stack; }
Example 12
Source File: NEIClientUtils.java From NotEnoughItems with MIT License | 5 votes |
public static void deleteItemsOfType(ItemStack type) { Container c = getGuiContainer().inventorySlots; for (int i = 0; i < c.inventorySlots.size(); i++) { Slot slot = c.getSlot(i); if (slot == null) { continue; } ItemStack stack = slot.getStack(); if (!stack.isEmpty() && stack.getItem() == type.getItem() && stack.getItemDamage() == type.getItemDamage()) { setSlotContents(i, ItemStack.EMPTY, true); slot.putStack(ItemStack.EMPTY); } } }
Example 13
Source File: ContainerBlueprintArchive.java From Cyberware with MIT License | 5 votes |
/** * Take a stack from the specified inventory slot. */ @Nullable public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (index < this.numRows * 9) { if (!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } } return itemstack; }
Example 14
Source File: ContainerTFBattery.java From TofuCraftReload with MIT License | 5 votes |
/** * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that. */ @Override public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { ItemStack itemstack = ItemStack.EMPTY; Slot slot = inventorySlots.get(slotIndex); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); switch (slotIndex) { case 0: if (!this.mergeItemStack(itemstack1, 1, 37, true)) return ItemStack.EMPTY; default: if (!this.mergeItemStack(itemstack1, 0, 0, false)) { return ItemStack.EMPTY; } slot.onSlotChange(itemstack1, itemstack); } if (itemstack1.getCount() == 0) slot.putStack(ItemStack.EMPTY); else slot.onSlotChanged(); if (itemstack1.getCount() == itemstack.getCount()) return ItemStack.EMPTY; slot.onTake(player, itemstack1); } return itemstack; }
Example 15
Source File: ContainerProgrammableController.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){ ItemStack var3 = null; Slot var4 = (Slot)inventorySlots.get(par2); if(var4 != null && var4.getHasStack()) { ItemStack var5 = var4.getStack(); var3 = var5.copy(); if(par2 < 5) { if(!mergeItemStack(var5, 5, 40, false)) return null; var4.onSlotChange(var5, var3); } else if(te.isItemValidForSlot(0, var3)) { if(!mergeItemStack(var5, 0, 1, false)) return null; var4.onSlotChange(var5, var3); } else if(var3.getItem() == Itemss.machineUpgrade) { if(!mergeItemStack(var5, 1, 5, false)) return null; var4.onSlotChange(var5, var3); } if(var5.stackSize == 0) { var4.putStack((ItemStack)null); } else { var4.onSlotChanged(); } if(var5.stackSize == var3.stackSize) return null; var4.onPickupFromSlot(par1EntityPlayer, var5); } return var3; }
Example 16
Source File: ContainerTFOven.java From TofuCraftReload with MIT License | 5 votes |
/** * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that. */ @Override public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { ItemStack itemstack = ItemStack.EMPTY; Slot slot = inventorySlots.get(slotIndex); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); switch (slotIndex) { case 0: if (!this.mergeItemStack(itemstack1, 1, 37, true)) return ItemStack.EMPTY; default: if (!this.mergeItemStack(itemstack1, 0, 0, false)) { return ItemStack.EMPTY; } slot.onSlotChange(itemstack1, itemstack); } if (itemstack1.getCount() == 0) slot.putStack(ItemStack.EMPTY); else slot.onSlotChanged(); if (itemstack1.getCount() == itemstack.getCount()) return ItemStack.EMPTY; slot.onTake(player, itemstack1); } return itemstack; }
Example 17
Source File: ContainerElectricCompressor.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
/** * @param itemStack * ItemStack to merge into inventory * @param start * minimum slot to attempt fill * @param end * maximum slot to attempt fill * @param backwards * go backwards * @return true if stacks merged successfully public boolean * mergeItemStack(itemStack, start, end, backwards) */ @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){ ItemStack var3 = null; Slot var4 = (Slot)inventorySlots.get(par2); if(var4 != null && var4.getHasStack()) { ItemStack var5 = var4.getStack(); var3 = var5.copy(); if(par2 < 4) { if(!mergeItemStack(var5, 4, 39, false)) return null; var4.onSlotChange(var5, var3); } else if(var3.getItem() == Itemss.machineUpgrade || PneumaticCraftUtils.isIC2Upgrade(var3.getItem())) { if(!mergeItemStack(var5, 0, 4, false)) return null; var4.onSlotChange(var5, var3); } if(var5.stackSize == 0) { var4.putStack((ItemStack)null); } else { var4.onSlotChanged(); } if(var5.stackSize == var3.stackSize) return null; var4.onPickupFromSlot(par1EntityPlayer, var5); } return var3; }
Example 18
Source File: ContainerStoneMortar.java From Sakura_mod with MIT License | 4 votes |
/** * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that. */ @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int index) { // 0-5: Contain inventory // 6-32: Player inventory // 33-42: Hot bar in the player inventory ItemStack itemStack = ItemStack.EMPTY; Slot slot = this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemStack1 = slot.getStack(); itemStack = itemStack1.copy(); if (index >= 0 && index <= 5){ if (!this.mergeItemStack(itemStack1, 6, 42, true)) { return ItemStack.EMPTY; } slot.onSlotChange(itemStack1, itemStack); } else if (index >= 6){ if (index >= 6 && index < 33){ if (!this.mergeItemStack(itemStack1, 33, 42, false)) { return ItemStack.EMPTY; } } else if (index >= 33 && index < 42 && !this.mergeItemStack(itemStack1, 6, 32, false)) { return ItemStack.EMPTY; } } else if (!this.mergeItemStack(itemStack1, 6, 42, false)) { return ItemStack.EMPTY; } if (itemStack1.getCount() == 0) { slot.putStack(ItemStack.EMPTY); } else { slot.onSlotChanged(); } if (itemStack1.getCount() == itemStack.getCount()) { return ItemStack.EMPTY; } slot.onTake(par1EntityPlayer, itemStack1); } return itemStack; }
Example 19
Source File: NEIController.java From NotEnoughItems with MIT License | 4 votes |
@Override public boolean mouseClicked(GuiScreen screen, int mouseX, int mouseY, int button) { if (!(screen instanceof GuiContainer) || !NEIClientConfig.isEnabled() || isSpreading(((GuiContainer) screen))) { return false; } GuiContainer gui = ((GuiContainer) screen); Slot slot = GuiHelper.getSlotMouseOver(gui); int slotID = -1; boolean outsideGui = (mouseX < gui.getGuiLeft() || mouseY < gui.getGuiTop() || mouseX >= gui.getGuiLeft() + gui.getXSize() || mouseY >= gui.getGuiTop() + gui.getYSize()) && slot == null; if (slot != null) { slotID = slot.slotNumber; } if (outsideGui) { slotID = -999; } //Shift / Click delete. if (deleteMode && slot != null && slot.slotNumber >= 0) { if (NEIClientUtils.shiftKey() && button == 0) { ItemStack itemstack1 = slot.getStack(); if (!itemstack1.isEmpty()) { NEIClientUtils.deleteItemsOfType(itemstack1); } } else if (button == 1) { NEIClientUtils.decreaseSlotStack(slot.slotNumber); } else { NEIClientUtils.deleteSlotStack(slot.slotNumber); } return true; } //Creative click the slot 64 times because mojang. //Seems to already be a thing.. Gonna leave this here and wipe it in a cleanup pass. //if (button == 1 && slot instanceof SlotCrafting)//right click //{ // for (int i1 = 0; i1 < 64; i1++)//click this slot 64 times // { // manager.handleSlotClick(slot.slotNumber, button, ClickType.PICKUP); // } // return true; //} //Control click slot = give me an item. if (NEIClientUtils.controlKey() && slot != null && !slot.getStack().isEmpty() && slot.isItemValid(slot.getStack())) { NEIClientUtils.cheatItem(slot.getStack(), button, 1); return true; } //Custom slots or container? No thanx, bia! if (GuiInfo.hasCustomSlots(gui) || ItemInfo.fastTransferContainerExemptions.contains(gui.getClass())) { return false; } //Disabled for now. //if (slotID >= 0 && NEIClientUtils.shiftKey() && !NEIClientUtils.getHeldItem().isEmpty() && !slot.getHasStack()) { // ItemStack held = NEIClientUtils.getHeldItem(); // GuiHelper.clickSlot(container, slot.slotNumber, button, ClickType.PICKUP); // if (slot.isItemValid(held)) { // fastTransferManager.performMassTransfer(container, pickedUpFromSlot, slot.slotNumber, held); // } // // return true; //} if (slotID == -999 && NEIClientUtils.shiftKey() && button == 0 && !NEIClientUtils.getHeldItem().isEmpty()) { fastTransferManager.throwAll(gui, pickedUpFromSlot); return true; } return false; }
Example 20
Source File: GuiChestHook.java From SkyblockAddons with MIT License | 4 votes |
public static void handleMouseClick(Slot slotIn, Container slots, IInventory lowerChestInventory, ReturnValue<?> returnValue) { SkyblockAddons main = SkyblockAddons.getInstance(); if (main.getUtils().getEnchantmentMatches().size() > 0) { if (slotIn != null && !slotIn.inventory.equals(Minecraft.getMinecraft().thePlayer.inventory) && slotIn.getHasStack()) { if (slotIn.getSlotIndex() == 13 && EnumUtils.InventoryType.getCurrentInventoryType() == EnumUtils.InventoryType.ENCHANTMENT_TABLE) { ItemStack[] enchantBottles = {slots.getSlot(29).getStack(), slots.getSlot(31).getStack(), slots.getSlot(33).getStack()}; for (ItemStack bottle : enchantBottles) { if (bottle != null && bottle.hasDisplayName()) { if (bottle.getDisplayName().startsWith(ChatFormatting.GREEN + "Enchant Item")) { Minecraft mc = Minecraft.getMinecraft(); List<String> toolip = bottle.getTooltip(mc.thePlayer, false); if (toolip.size() > 2) { String[] lines = toolip.get(2).split(Pattern.quote("* ")); if (lines.length > 1) { String enchantLine = lines[1]; if (main.getUtils().enchantReforgeMatches(enchantLine)) { main.getUtils().playLoudSound("random.orb", 0.1); returnValue.cancel(); } } } } else if (bottle.getDisplayName().startsWith(ChatFormatting.RED + "Enchant Item")) { // Stop player from removing item before the enchants have even loaded. returnValue.cancel(); } } } } else if (slotIn.getSlotIndex() == 22 && EnumUtils.InventoryType.getCurrentInventoryType() == EnumUtils.InventoryType.REFORGE_ANVIL) { Slot itemSlot = slots.getSlot(13); if (itemSlot != null && itemSlot.getHasStack()) { ItemStack item = itemSlot.getStack(); if (item.hasDisplayName()) { String reforge = main.getUtils().getReforgeFromItem(item); if (reforge != null) { if (main.getUtils().enchantReforgeMatches(reforge)) { main.getUtils().playLoudSound("random.orb", 0.1); returnValue.cancel(); } } } } } } } if (main.getConfigValues().isEnabled(Feature.STOP_DROPPING_SELLING_RARE_ITEMS) && !main.getUtils().isInDungeon() && lowerChestInventory.hasCustomName() && NPCUtils.isFullMerchant(lowerChestInventory.getDisplayName().getUnformattedText()) && slotIn != null && slotIn.inventory instanceof InventoryPlayer) { if (!main.getUtils().getItemDropChecker().canDropItem(slotIn)) { returnValue.cancel(); } } }