Java Code Examples for net.minecraft.inventory.Slot#isItemValid()
The following examples show how to use
net.minecraft.inventory.Slot#isItemValid() .
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: ECContainer.java From ExtraCells1 with MIT License | 6 votes |
private boolean tryShiftItem(ItemStack stackToShift, int numSlots) { for (int machineIndex = 0; machineIndex < numSlots - 9 * 4; machineIndex++) { Slot slot = (Slot) inventorySlots.get(machineIndex); if (slot instanceof SlotFake) { continue; } if (!slot.isItemValid(stackToShift)) { continue; } if (shiftItemStack(stackToShift, machineIndex, machineIndex + 1)) { return true; } } return false; }
Example 2
Source File: GuiContainer.java From NotEnoughItems with MIT License | 5 votes |
/** * Called when a mouse button is pressed and the mouse is moved around. Parameters are : mouseX, mouseY, * lastButtonClicked & timeSinceMouseClick. */ protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { Slot slot = this.getSlotAtPosition(mouseX, mouseY); ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); manager.mouseDragged(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); if (this.clickedSlot != null && this.mc.gameSettings.touchscreen) { if (clickedMouseButton == 0 || clickedMouseButton == 1) { if (this.draggedStack == null) { if (slot != this.clickedSlot && this.clickedSlot.getStack() != null) { this.draggedStack = this.clickedSlot.getStack().copy(); } } else if (this.draggedStack.stackSize > 1 && slot != null && Container.canAddItemToSlot(slot, this.draggedStack, false)) { long i = Minecraft.getSystemTime(); if (this.currentDragTargetSlot == slot) { if (i - this.dragItemDropDelay > 500L) { managerHandleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, ClickType.PICKUP); managerHandleMouseClick(slot, slot.slotNumber, 1, ClickType.PICKUP); managerHandleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, ClickType.PICKUP); this.dragItemDropDelay = i + 750L; --this.draggedStack.stackSize; } } else { this.currentDragTargetSlot = slot; this.dragItemDropDelay = i; } } } } else if (this.dragSplitting && slot != null && itemstack != null && itemstack.stackSize > this.dragSplittingSlots.size() && Container.canAddItemToSlot(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot)) { this.dragSplittingSlots.add(slot); this.updateActivePotionEffects(); } }
Example 3
Source File: NEIDummySlotHandler.java From NotEnoughItems with MIT License | 5 votes |
@Override public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) { Slot slot = gui.getSlotAtPosition(mouseX, mouseY); if (slot instanceof SlotDummy && slot.isItemValid(draggedStack) && gui.inventorySlots instanceof ContainerExtended) { ((SlotDummy) slot).slotClick(draggedStack, button, NEIClientUtils.shiftKey()); NEIClientPacketHandler.sendDummySlotSet(slot.slotNumber, slot.getStack()); return true; } return false; }
Example 4
Source File: FastTransferManager.java From NotEnoughItems with MIT License | 5 votes |
public void transferItem(GuiContainer window, int fromSlot) { int toSlot = findShiftClickDestinationSlot(window.inventorySlots, fromSlot); if (toSlot == -1) { return; } Slot from = window.inventorySlots.getSlot(fromSlot); if (from.isItemValid(from.getStack())) { moveOneItem(window, fromSlot, toSlot); } else//slots that you can't put stuff in { moveOutputSet(window, fromSlot, toSlot); } }
Example 5
Source File: ContainerPneumaticBase.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player){ ItemStack stack = null; if(mouseButton == 2) { if(((IPhantomSlot)slot).canAdjust()) { slot.putStack(null); } } else if(mouseButton == 0 || mouseButton == 1) { InventoryPlayer playerInv = player.inventory; slot.onSlotChanged(); ItemStack stackSlot = slot.getStack(); ItemStack stackHeld = playerInv.getItemStack(); if(stackSlot != null) { stack = stackSlot.copy(); } if(stackSlot == null) { if(stackHeld != null && slot.isItemValid(stackHeld)) { fillPhantomSlot(slot, stackHeld, mouseButton, modifier); } } else if(stackHeld == null) { adjustPhantomSlot(slot, mouseButton, modifier); slot.onPickupFromSlot(player, playerInv.getItemStack()); } else if(slot.isItemValid(stackHeld)) { if(canStacksMerge(stackSlot, stackHeld)) { adjustPhantomSlot(slot, mouseButton, modifier); } else { fillPhantomSlot(slot, stackHeld, mouseButton, modifier); } } } return stack; }
Example 6
Source File: ContainerPlasticMixer.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 < 9) { if(!mergeItemStack(var5, 9, 45, false)) return null; var4.onSlotChange(var5, var3); } else { for(int i = 0; i < 9; i++) { Slot slot = (Slot)inventorySlots.get(i); if(slot.isItemValid(var5)) { if(!mergeItemStack(var5, i, i + 1, 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 7
Source File: SlotUtil.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public static ItemStack slotClickPhantom(Slot slot, int mouseButton, ClickType clickTypeIn, ItemStack stackHeld) { ItemStack stack = ItemStack.EMPTY; ItemStack stackSlot = slot.getStack(); if (!stackSlot.isEmpty()) { stack = stackSlot.copy(); } if (mouseButton == 2) { fillPhantomSlot(slot, ItemStack.EMPTY, mouseButton); } else if (mouseButton == 0 || mouseButton == 1) { if (stackSlot.isEmpty()) { if (!stackHeld.isEmpty() && slot.isItemValid(stackHeld)) { fillPhantomSlot(slot, stackHeld, mouseButton); } } else if (stackHeld.isEmpty()) { adjustPhantomSlot(slot, mouseButton, clickTypeIn); } else if (slot.isItemValid(stackHeld)) { if (areItemsEqual(stackSlot, stackHeld)) { adjustPhantomSlot(slot, mouseButton, clickTypeIn); } else { fillPhantomSlot(slot, stackHeld, mouseButton); } } } else if (mouseButton == 5) { if (!slot.getHasStack()) { fillPhantomSlot(slot, stackHeld, mouseButton); } } return stack; }
Example 8
Source File: FastTransferManager.java From NotEnoughItems with MIT License | 5 votes |
public void transferItem(GuiContainer window, int fromSlot) { int toSlot = findShiftClickDestinationSlot(window.inventorySlots, fromSlot); if (toSlot == -1) return; Slot from = window.inventorySlots.getSlot(fromSlot); if (from.isItemValid(from.getStack())) moveOneItem(window, fromSlot, toSlot); else//slots that you can't put stuff in moveOutputSet(window, fromSlot, toSlot); }
Example 9
Source File: NEIDummySlotHandler.java From NotEnoughItems with MIT License | 5 votes |
@Override public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) { Slot slot = gui.getSlotAtPosition(mousex, mousey); if(slot instanceof SlotDummy && slot.isItemValid(draggedStack) && gui.inventorySlots instanceof ContainerExtended) { ((SlotDummy)slot).slotClick(draggedStack, button, NEIClientUtils.shiftKey()); NEICPH.sendDummySlotSet(slot.slotNumber, slot.getStack()); return true; } return false; }
Example 10
Source File: ContainerHelper.java From AgriCraft with MIT License | 5 votes |
public static final boolean isSlotValidFor(@Nonnull Slot slot, @Nonnull ItemStack stack) { // Validate the input parameters. Preconditions.checkNotNull(slot); Preconditions.checkNotNull(stack); // Fetch the slot stack. final ItemStack slotStack = slot.getStack(); // Return return slot.isItemValid(stack) && (slotStack.isEmpty() || StackHelper.areCompatible(stack, slotStack)); }
Example 11
Source File: NEIController.java From NotEnoughItems with MIT License | 4 votes |
@Override public boolean handleSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier, boolean eventconsumed) { if (eventconsumed || !NEIClientConfig.isEnabled() || isSpreading(gui)) return eventconsumed; if (deleteMode && slotIndex >= 0 && slot != null) { if (NEIClientUtils.shiftKey() && button == 0) { ItemStack itemstack1 = slot.getStack(); if (itemstack1 != null) NEIClientUtils.deleteItemsOfType(itemstack1); } else if (button == 1) NEIClientUtils.decreaseSlotStack(slot.slotNumber); else NEIClientUtils.deleteSlotStack(slot.slotNumber); return true; } 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, 0); return true; } if (NEIClientUtils.controlKey() && slot != null && slot.getStack() != null && slot.isItemValid(slot.getStack())) { NEIClientUtils.cheatItem(slot.getStack(), button, 1); return true; } if(GuiInfo.hasCustomSlots(gui)) return false; if (slotIndex >= 0 && NEIClientUtils.shiftKey() && NEIClientUtils.getHeldItem() != null && !slot.getHasStack()) { ItemStack held = NEIClientUtils.getHeldItem(); manager.handleSlotClick(slot.slotNumber, button, 0); if (slot.isItemValid(held) && !ItemInfo.fastTransferExemptions.contains(slot.getClass())) fastTransferManager.performMassTransfer(gui, pickedUpFromSlot, slotIndex, held); return true; } if (slotIndex == -999 && NEIClientUtils.shiftKey() && button == 0) { fastTransferManager.throwAll(gui, pickedUpFromSlot); return true; } return false; }
Example 12
Source File: ContainerPedestal.java From Artifacts with MIT License | 4 votes |
@Override protected boolean mergeItemStack(ItemStack itemstack, int i, int j, boolean flag) { // The default implementation in Slot doesn't take into account the Slot.isItemValid() and Slot.getSlotStackLimit() values. // So here is a modified implementation. I have only modified the parts with a comment. boolean flag1 = false; int k = i; if (flag) { k = j - 1; } if (itemstack.isStackable()) { while (itemstack.stackSize > 0 && (!flag && k < j || flag && k >= i)) { Slot slot = (Slot)inventorySlots.get(k); ItemStack itemstack1 = slot.getStack(); if (flag) { k--; } else { k++; } // Check if item is valid: if (!slot.isItemValid(itemstack)) { continue; } if (itemstack1 != null && itemstack1.getItem() == itemstack.getItem() && (!itemstack.getHasSubtypes() || itemstack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(itemstack, itemstack1)) { //ItemStack.areItemStacksEqual(par0ItemStack, par1ItemStack) //ItemStack.areItemStackTagsEqual(par0ItemStack, par1ItemStack) int i1 = itemstack1.stackSize + itemstack.stackSize; // Don't put more items than the slot can take: int maxItemsInDest = Math.min(itemstack1.getMaxStackSize(), slot.getSlotStackLimit()); if (i1 <= maxItemsInDest) { itemstack.stackSize = 0; itemstack1.stackSize = i1; slot.onSlotChanged(); flag1 = true; } else if (itemstack1.stackSize < maxItemsInDest) { itemstack.stackSize -= maxItemsInDest - itemstack1.stackSize; itemstack1.stackSize = maxItemsInDest; slot.onSlotChanged(); flag1 = true; } } } } if (itemstack.stackSize > 0) { int l; if (flag) { l = j - 1; } else { l = i; } do { if ((flag || l >= j) && (!flag || l < i)) { break; } Slot slot1 = (Slot)inventorySlots.get(l); ItemStack itemstack2 = slot1.getStack(); if (flag) { l--; } else { l++; } // Check if item is valid: if (!slot1.isItemValid(itemstack)) { continue; } if (itemstack2 == null) { // Don't put more items than the slot can take: int nbItemsInDest = Math.min(itemstack.stackSize, slot1.getSlotStackLimit()); ItemStack itemStack1 = itemstack.copy(); itemstack.stackSize -= nbItemsInDest; itemStack1.stackSize = nbItemsInDest; slot1.putStack(itemStack1); slot1.onSlotChanged(); // itemstack.stackSize = 0; flag1 = true; break; } } while (true); } return flag1; }
Example 13
Source File: ECContainer.java From ExtraCells1 with MIT License | 4 votes |
private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player) { ItemStack stack = null; if (mouseButton == 2) { if (((SlotFake) slot).canAdjust()) { slot.putStack(null); } } else if (mouseButton == 0 || mouseButton == 1) { InventoryPlayer playerInv = player.inventory; slot.onSlotChanged(); ItemStack stackSlot = slot.getStack(); ItemStack stackHeld = playerInv.getItemStack(); if (stackSlot != null) { stack = stackSlot.copy(); } if (stackSlot == null) { if (stackHeld != null && slot.isItemValid(stackHeld)) { fillPhantomSlot(slot, stackHeld, mouseButton, modifier); } } else if (stackHeld == null) { adjustPhantomSlot(slot, mouseButton, modifier); slot.onPickupFromSlot(player, playerInv.getItemStack()); } else if (slot.isItemValid(stackHeld)) { if (canStacksMerge(stackSlot, stackHeld)) { adjustPhantomSlot(slot, mouseButton, modifier); } else { fillPhantomSlot(slot, stackHeld, mouseButton, modifier); } } } return stack; }
Example 14
Source File: ContainerCamoMine.java From AdvancedMod with GNU General Public License v3.0 | 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 player, int slotIndex){ ItemStack itemstack = null; Slot slot = (Slot)inventorySlots.get(slotIndex); if(slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); //From here change accordingly... if(slotIndex < 6) { if(!mergeItemStack(itemstack1, 6, 42, true)) { return null; } } else { //Shift click single items only. if(itemstack1.stackSize == 1) { for(int i = 0; i < 6; i++) { Slot shiftedInSlot = (Slot)inventorySlots.get(i); if(!shiftedInSlot.getHasStack() && shiftedInSlot.isItemValid(itemstack1)) mergeItemStack(itemstack1, i, i + 1, false); } } } //...till here. if(itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } if(itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(player, itemstack1); } return itemstack; }
Example 15
Source File: ItemPanel.java From NotEnoughItems with MIT License | 4 votes |
private boolean handleDraggedClick(int mousex, int mousey, int button) { if (draggedStack == null) return false; GuiContainer gui = NEIClientUtils.getGuiContainer(); boolean handled = false; for (INEIGuiHandler handler : GuiInfo.guiHandlers) if (handler.handleDragNDrop(gui, mousex, mousey, draggedStack, button)) { handled = true; if (draggedStack.stackSize == 0) { draggedStack = null; return true; } } if (handled) return true; Slot overSlot = gui.getSlotAtPosition(mousex, mousey); if (overSlot != null && overSlot.isItemValid(draggedStack)) { if (NEIClientConfig.canCheatItem(draggedStack)) { int contents = overSlot.getHasStack() ? overSlot.getStack().stackSize : 0; int add = button == 0 ? draggedStack.stackSize : 1; if (overSlot.getHasStack() && !NEIServerUtils.areStacksSameType(draggedStack, overSlot.getStack())) contents = 0; int total = Math.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize())); if (total > contents) { NEIClientUtils.setSlotContents(overSlot.slotNumber, NEIServerUtils.copyStack(draggedStack, total), true); NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false); draggedStack.stackSize -= total - contents; } if (draggedStack.stackSize == 0) draggedStack = null; } else { draggedStack = null; } } else if (mousex < gui.guiLeft || mousey < gui.guiTop || mousex >= gui.guiLeft + gui.xSize || mousey >= gui.guiTop + gui.ySize) { draggedStack = null; } return true; }
Example 16
Source File: GuiContainer.java From NotEnoughItems with MIT License | 4 votes |
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { Slot slot = this.getSlotAtPosition(mouseX, mouseY); ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); manager.mouseDragged(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); if (this.clickedSlot != null && this.mc.gameSettings.touchscreen) { if (clickedMouseButton == 0 || clickedMouseButton == 1) { if (this.draggedStack == null) { if (slot != this.clickedSlot) { this.draggedStack = this.clickedSlot.getStack().copy(); } } else if (this.draggedStack.stackSize > 1 && slot != null && Container.canAddItemToSlot(slot, this.draggedStack, false)) { long i1 = Minecraft.getSystemTime(); if (this.currentDragTargetSlot == slot) { if (i1 - this.dragItemDropDelay > 500L) { managerHandleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0); managerHandleMouseClick(slot, slot.slotNumber, 1, 0); managerHandleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0); this.dragItemDropDelay = i1 + 750L; --this.draggedStack.stackSize; } } else { this.currentDragTargetSlot = slot; this.dragItemDropDelay = i1; } } } } else if (this.dragSplitting && slot != null && itemstack != null && itemstack.stackSize > this.dragSplittingSlots.size() && Container.canAddItemToSlot(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot)) { this.dragSplittingSlots.add(slot); this.updateDragSplitting(); } }
Example 17
Source File: ItemPanel.java From NotEnoughItems with MIT License | 4 votes |
private boolean handleDraggedClick(int mousex, int mousey, int button) { if (draggedStack.isEmpty()) { return false; } GuiContainer gui = NEIClientUtils.getGuiContainer(); boolean handled = false; for (INEIGuiHandler handler : GuiInfo.guiHandlers) { if (handler.handleDragNDrop(gui, mousex, mousey, draggedStack, button)) { handled = true; if (draggedStack.getCount() == 0) { draggedStack = ItemStack.EMPTY; return true; } } } if (handled) { return true; } Slot overSlot = gui.getSlotAtPosition(mousex, mousey); if (overSlot != null && overSlot.isItemValid(draggedStack)) { if (NEIClientConfig.canCheatItem(draggedStack)) { int contents = overSlot.getHasStack() ? overSlot.getStack().getCount() : 0; int add = button == 0 ? draggedStack.getCount() : 1; if (overSlot.getHasStack() && !NEIServerUtils.areStacksSameType(draggedStack, overSlot.getStack())) { contents = 0; } int total = Math.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize())); if (total > contents) { int slotNumber = overSlot.slotNumber; if (gui instanceof GuiContainerCreative) { //Because Mojang.. slotNumber = slotNumber - gui.inventorySlots.inventorySlots.size() + 9 + 36; } NEIClientUtils.setSlotContents(slotNumber, NEIServerUtils.copyStack(draggedStack, total), true); NEIClientPacketHandler.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false); draggedStack.shrink(total - contents); } if (draggedStack.getCount() == 0) { draggedStack = ItemStack.EMPTY; } } else { draggedStack = ItemStack.EMPTY; } } else if (mousex < gui.getGuiLeft() || mousey < gui.getGuiTop() || mousex >= gui.getGuiLeft() + gui.getXSize() || mousey >= gui.getGuiTop() + gui.getYSize()) { draggedStack = ItemStack.EMPTY; } return true; }
Example 18
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 19
Source File: ContainerBase.java From Signals with GNU General Public License v3.0 | 4 votes |
/** * Source: Buildcraft */ /* @Override public ItemStack slotClick(int slotNum, int modifier, int mouseButton, EntityPlayer player){ Slot slot = slotNum < 0 ? null : (Slot)inventorySlots.get(slotNum); if(slot instanceof IPhantomSlot) { return slotClickPhantom(slot, modifier, mouseButton, player); } return super.slotClick(slotNum, modifier, mouseButton, player); } */ private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player){ ItemStack stack = ItemStack.EMPTY; if(mouseButton == 2) { if(((IPhantomSlot)slot).canAdjust()) { slot.putStack(ItemStack.EMPTY); } } else if(mouseButton == 0 || mouseButton == 1) { InventoryPlayer playerInv = player.inventory; slot.onSlotChanged(); ItemStack stackSlot = slot.getStack(); ItemStack stackHeld = playerInv.getItemStack(); if(!stackSlot.isEmpty()) { stack = stackSlot.copy(); } if(stackSlot.isEmpty()) { if(!stackHeld.isEmpty() && slot.isItemValid(stackHeld)) { fillPhantomSlot(slot, stackHeld, mouseButton, modifier); } } else if(stackHeld.isEmpty()) { adjustPhantomSlot(slot, mouseButton, modifier); slot.onTake(player, playerInv.getItemStack()); } else if(slot.isItemValid(stackHeld)) { if(canStacksMerge(stackSlot, stackHeld)) { adjustPhantomSlot(slot, mouseButton, modifier); } else { fillPhantomSlot(slot, stackHeld, mouseButton, modifier); } } } return stack; }