net.minecraft.inventory.ContainerEnchantment Java Examples

The following examples show how to use net.minecraft.inventory.ContainerEnchantment. 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: EnchantmentTableTweaks.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void onContainerOpen(EntityPlayer player, Container container) {
    if (container instanceof ContainerEnchantment) {
        //wrap in try-catch because such kind of tweaks is subject to breaking
        //don't let it crash game if some mod borked it
        try {
            int index = getEnchantmentSlotIndex((ContainerEnchantment) container);
            if (index != -1) {
                Slot previousLapisSlot = container.inventorySlots.get(index);
                EnchantmentLapisSlot resultSlot = new EnchantmentLapisSlot(previousLapisSlot);
                resultSlot.slotNumber = previousLapisSlot.slotNumber;
                container.inventorySlots.set(index, resultSlot);
            }
        } catch (Throwable exception) {
            GTLog.logger.warn("Failed to replace enchantment container slot", exception);
        }
    }
}
 
Example #2
Source File: EnchantmentTableTweaks.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static int getEnchantmentSlotIndex(ContainerEnchantment container) {
    IInventory inventory = container.tableInventory;
    for (int i = 0; i < container.inventorySlots.size(); i++) {
        Slot slot = container.inventorySlots.get(i);
        if (slot.isHere(inventory, EnchantmentLapisSlot.ENCHANTMENT_LAPIS_SLOT_INDEX)) return i;
    }
    return -1;
}