2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei.api;
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
import codechicken.lib.vec.Rectangle4i;
|
2014-04-29 10:54:20 +10:00
|
|
|
import codechicken.nei.NEIChestGuiHandler;
|
|
|
|
|
import codechicken.nei.NEICreativeGuiHandler;
|
|
|
|
|
import codechicken.nei.NEIDummySlotHandler;
|
2022-05-27 07:42:41 -04:00
|
|
|
import codechicken.nei.NEIPotionGuiHandler;
|
2022-06-24 12:32:13 +01:00
|
|
|
import codechicken.nei.recipe.CheatItemHandler;
|
|
|
|
|
import codechicken.nei.recipe.FillFluidContainerHandler;
|
2022-01-22 13:16:28 +09:00
|
|
|
import codechicken.nei.recipe.GuiRecipeCatalyst;
|
2022-05-06 22:41:45 +03:00
|
|
|
import codechicken.nei.recipe.SearchInputDropHandler;
|
2014-06-29 20:31:37 +10:00
|
|
|
import java.util.HashSet;
|
2014-04-29 10:54:20 +10:00
|
|
|
import java.util.LinkedList;
|
2021-06-05 10:47:58 -07:00
|
|
|
import java.util.concurrent.locks.Lock;
|
|
|
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
2022-06-24 12:32:13 +01:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainerCreative;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2021-06-05 10:47:58 -07:00
|
|
|
public class GuiInfo {
|
2019-12-30 20:19:16 -08:00
|
|
|
public static final LinkedList<INEIGuiHandler> guiHandlers = new LinkedList<>();
|
|
|
|
|
public static final HashSet<Class<? extends GuiContainer>> customSlotGuis = new HashSet<>();
|
2021-06-05 10:47:58 -07:00
|
|
|
public static ReentrantReadWriteLock guiHandlersLock = new ReentrantReadWriteLock();
|
|
|
|
|
public static Lock writeLock = guiHandlersLock.writeLock();
|
|
|
|
|
public static Lock readLock = guiHandlersLock.readLock();
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public static void load() {
|
|
|
|
|
API.registerNEIGuiHandler(new NEICreativeGuiHandler());
|
|
|
|
|
API.registerNEIGuiHandler(new NEIChestGuiHandler());
|
|
|
|
|
API.registerNEIGuiHandler(new NEIDummySlotHandler());
|
2022-01-22 13:16:28 +09:00
|
|
|
API.registerNEIGuiHandler(new GuiRecipeCatalyst(null));
|
2022-05-06 22:41:45 +03:00
|
|
|
API.registerNEIGuiHandler(new SearchInputDropHandler());
|
|
|
|
|
API.registerNEIGuiHandler(new FillFluidContainerHandler());
|
|
|
|
|
API.registerNEIGuiHandler(new CheatItemHandler());
|
2022-05-27 07:42:41 -04:00
|
|
|
API.registerNEIGuiHandler(new NEIPotionGuiHandler());
|
2014-06-29 20:31:37 +10:00
|
|
|
customSlotGuis.add(GuiContainerCreative.class);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void clearGuiHandlers() {
|
2021-06-05 10:47:58 -07:00
|
|
|
try {
|
|
|
|
|
GuiInfo.writeLock.lock();
|
|
|
|
|
guiHandlers.removeIf(ineiGuiHandler -> ineiGuiHandler instanceof GuiContainer);
|
|
|
|
|
} finally {
|
|
|
|
|
GuiInfo.writeLock.unlock();
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public static boolean hasCustomSlots(GuiContainer gui) {
|
|
|
|
|
return customSlotGuis.contains(gui.getClass());
|
|
|
|
|
}
|
2022-05-06 22:41:45 +03:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public static boolean hideItemPanelSlot(GuiContainer gui, Rectangle4i rect) {
|
2022-05-06 22:41:45 +03:00
|
|
|
try {
|
|
|
|
|
readLock.lock();
|
2022-06-24 12:32:13 +01:00
|
|
|
if (guiHandlers.stream()
|
|
|
|
|
.anyMatch(handler -> handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h))) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
readLock.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Object item : gui.buttonList) {
|
|
|
|
|
GuiButton button = (GuiButton) item;
|
|
|
|
|
|
|
|
|
|
if ((new Rectangle4i(button.xPosition, button.yPosition, button.width, button.height)).intersects(rect)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|