Java Code Examples for net.minecraft.inventory.Slot#getSlotIndex()

The following examples show how to use net.minecraft.inventory.Slot#getSlotIndex() . 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: ContainerCustomSlotClick.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Toggles the locked state for the given slot and sets the template stack
 * to the one in the cursor.<br>
 * If <b>requireStorageKey</b> is true, then a "storage key"
 * item needs to be held in the cursor for this to do anything.<br>
 * If <b>requireStorageKey</b> is false, then the template stack is set to
 * whatever is currently in the cursor, and the locked status is toggled.
 * @param slotNum
 * @param inv
 * @return true if the slot locked status was toggled, false if the conditions weren't met
 */
protected boolean toggleSlotLocked(int slotNum, ItemStackHandlerLockable inv)
{
    Slot slot = this.getSlot(slotNum);
    int slotIndex = slot != null ? slot.getSlotIndex() : -1;
    ItemStack stackCursor = this.player.inventory.getItemStack();

    if (slotIndex != -1)
    {
        if (stackCursor.isEmpty() == false)
        {
            inv.setTemplateStackInSlot(slotIndex, stackCursor);
        }
        else
        {
            inv.setTemplateStackInSlot(slotIndex, slot.getStack());
        }

        inv.toggleSlotLocked(slotIndex);
        return true;
    }

    return false;
}
 
Example 2
Source File: ExtraInventory.java    From ForgeHax with MIT License 5 votes vote down vote up
private static void checkSlotIntegrity(Slot s1, Slot s2) throws ExecutionFailure {
  // compare references (yes i realize im doing ItemStack == ItemStack)
  if (s1 != null
      && s2 != null
      && (s1.inventory != s2.inventory
      || s1.getSlotIndex() != s2.getSlotIndex()
      || s1.slotNumber != s2.slotNumber
      || s1.getStack() != s2.getStack())) {
    fail();
  }
}
 
Example 3
Source File: GuiLogisticsBase.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void handleMouseClick(Slot slot, int x, int mouse, int y){
    if(slot instanceof SlotPhantom && Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null && !slot.getHasStack() && mouse == 1) {
        editingSlot = slot.getSlotIndex();
        Minecraft.getMinecraft().displayGuiScreen(searchGui = new GuiSearcher(Minecraft.getMinecraft().thePlayer));
    } else {
        super.handleMouseClick(slot, x, mouse, y);
    }
}
 
Example 4
Source File: GuiChestHook.java    From SkyblockAddons with MIT License 4 votes vote down vote up
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 5
Source File: ExtraInventory.java    From ForgeHax with MIT License 4 votes vote down vote up
private static Slot copyOfSlot(Slot slot) {
  return (slot == null || slot.getSlotIndex() == -999) ? null : new DuplicateSlot(slot);
}
 
Example 6
Source File: ExtraInventory.java    From ForgeHax with MIT License 4 votes vote down vote up
private DuplicateSlot(Slot original) {
  super(original.inventory, original.getSlotIndex(), original.xPos, original.yPos);
  this.slotNumber = original.slotNumber;
  this.stack = original.getStack();
}
 
Example 7
Source File: SlotBackpackWrapper.java    From WearableBackpacks with MIT License 4 votes vote down vote up
public SlotBackpackWrapper(Slot base) {
	super(base.inventory, base.getSlotIndex(), base.xPos, base.yPos);
	this.base = base;
}