Java Code Examples for net.minecraft.inventory.Container#getSlot()
The following examples show how to use
net.minecraft.inventory.Container#getSlot() .
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: FastTransferManager.java From NotEnoughItems with MIT License | 6 votes |
private void findConnectedSlots(Container container, int slotNo, HashSet<Integer> connectedSlots) { connectedSlots.add(slotNo); Slot slot = container.getSlot(slotNo); final int threshold = 18; for (int i = 0; i < container.inventorySlots.size(); i++) { if (connectedSlots.contains(i)) { continue; } Slot slot1 = container.getSlot(i); if (Math.abs(slot.xPos - slot1.xPos) <= threshold && Math.abs(slot.yPos - slot1.yPos) <= threshold) { findConnectedSlots(container, i, connectedSlots); } } }
Example 2
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 3
Source File: FastTransferManager.java From NotEnoughItems with MIT License | 5 votes |
private void findConnectedSlots(Container container, int slotNo, HashSet<Integer> connectedSlots) { connectedSlots.add(slotNo); Slot slot = container.getSlot(slotNo); final int threshold = 18; for (int i = 0; i < container.inventorySlots.size(); i++) { if (connectedSlots.contains(i)) continue; Slot slot1 = container.getSlot(i); if (Math.abs(slot.xDisplayPosition - slot1.xDisplayPosition) <= threshold && Math.abs(slot.yDisplayPosition - slot1.yDisplayPosition) <= threshold) { findConnectedSlots(container, i, connectedSlots); } } }
Example 4
Source File: FastTransferManager.java From NotEnoughItems with MIT License | 5 votes |
/** * @return The slot that one item from the source slot will end up in apon shift clicking, -1 if none. */ public int findShiftClickDestinationSlot(Container container, int fromSlot) { LinkedList<ItemStack> save = saveContainer(container); Slot slot = container.getSlot(fromSlot); ItemStack stack = slot.getStack(); if (stack == null) return -1; stack.stackSize = 1; slot.putStack(stack.copy()); LinkedList<ItemStack> compareBefore = saveContainer(container); container.slotClick(fromSlot, 0, 1, Minecraft.getMinecraft().thePlayer); LinkedList<ItemStack> compareAfter = saveContainer(container); try { //if(compareAfter.get(fromSlot) != null)//transfer failed //return -1; for (int i = 0; i < compareBefore.size(); i++) { if (i == fromSlot) continue; ItemStack before = compareBefore.get(i); ItemStack after = compareAfter.get(i); if (!areStacksIdentical(before, after) && after != null) if (before == null ? areStacksSameType(stack, after) ://transfered into this empty slot areStacksSameType(stack, after) && after.stackSize - before.stackSize > 0)//it added to this stack return i; } return -1; } finally { restoreContainer(container, save); } }
Example 5
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 != null && stack.getItem() == type.getItem() && stack.getItemDamage() == type.getItemDamage()) { setSlotContents(i, null, true); slot.putStack(null); } } }
Example 6
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(); } } }
Example 7
Source File: FastTransferManager.java From NotEnoughItems with MIT License | 4 votes |
/** * @return The slot that one item from the source slot will end up in apon shift clicking, -1 if none. */ public int findShiftClickDestinationSlot(Container container, int fromSlot) { LinkedList<ItemStack> save = saveContainer(container); Slot slot = container.getSlot(fromSlot); ItemStack stack = slot.getStack(); if (stack.isEmpty()) { return -1; } stack.setCount(1); slot.putStack(stack.copy()); LinkedList<ItemStack> compareBefore = saveContainer(container); container.slotClick(fromSlot, 0, ClickType.QUICK_MOVE, Minecraft.getMinecraft().player); LinkedList<ItemStack> compareAfter = saveContainer(container); try { //if(compareAfter.get(fromSlot) != null)//transfer failed //return -1; for (int i = 0; i < compareBefore.size(); i++) { if (i == fromSlot) { continue; } ItemStack before = compareBefore.get(i); ItemStack after = compareAfter.get(i); if (!areStacksIdentical(before, after) && !after.isEmpty()) { if (before.isEmpty() ? areStacksSameType(stack, after) ://transfered into this empty slot areStacksSameType(stack, after) && after.getCount() - before.getCount() > 0)//it added to this stack { return i; } } } return -1; } finally { restoreContainer(container, save); } }