2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
|
|
|
|
import codechicken.lib.vec.Rectangle4i;
|
|
|
|
|
import codechicken.nei.api.GuiInfo;
|
|
|
|
|
import codechicken.nei.api.INEIGuiHandler;
|
|
|
|
|
import codechicken.nei.guihook.GuiContainerManager;
|
|
|
|
|
import codechicken.nei.recipe.GuiCraftingRecipe;
|
|
|
|
|
import codechicken.nei.recipe.GuiRecipe;
|
|
|
|
|
import codechicken.nei.recipe.GuiUsageRecipe;
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
import static codechicken.lib.gui.GuiDraw.drawRect;
|
2019-12-24 13:37:41 -08:00
|
|
|
import static codechicken.nei.NEIClientConfig.canPerformAction;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
public class ItemPanel extends Widget {
|
2020-01-20 09:42:39 -08:00
|
|
|
/**
|
|
|
|
|
* Backwards compat :-/
|
|
|
|
|
*/
|
|
|
|
|
public static ArrayList<ItemStack> items = new ArrayList<>();
|
|
|
|
|
|
2014-07-25 14:45:45 +10:00
|
|
|
/**
|
|
|
|
|
* Should not be externally modified, use updateItemList
|
|
|
|
|
*/
|
2020-01-20 09:42:39 -08:00
|
|
|
public ArrayList<ItemStack> realItems = new ArrayList<>();
|
2014-06-29 20:31:37 +10:00
|
|
|
/**
|
|
|
|
|
* Swapped into visible items on update
|
|
|
|
|
*/
|
2020-01-20 09:42:39 -08:00
|
|
|
protected ArrayList<ItemStack> _items = realItems;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
public ArrayList<ItemStack> getItems() {
|
2020-01-20 09:42:39 -08:00
|
|
|
return realItems;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2019-12-30 16:32:04 -08:00
|
|
|
public static void updateItemList(ArrayList<ItemStack> newItems) {
|
|
|
|
|
ItemPanels.itemPanel._items = newItems;
|
2014-06-29 20:31:37 +10:00
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public class ItemPanelSlot
|
|
|
|
|
{
|
2014-06-29 20:31:37 +10:00
|
|
|
public ItemStack item;
|
2014-04-29 10:54:20 +10:00
|
|
|
public int slotIndex;
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public ItemPanelSlot(int index) {
|
2020-01-20 09:42:39 -08:00
|
|
|
item = realItems.get(index);
|
2014-06-29 20:31:37 +10:00
|
|
|
slotIndex = index;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public ItemStack draggedStack;
|
|
|
|
|
public int mouseDownSlot = -1;
|
|
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
public Button prev;
|
|
|
|
|
public Button next;
|
|
|
|
|
public Label pageLabel;
|
|
|
|
|
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
private int marginLeft;
|
|
|
|
|
private int marginTop;
|
|
|
|
|
private int rows;
|
|
|
|
|
private int columns;
|
|
|
|
|
|
|
|
|
|
private boolean[] validSlotMap;
|
|
|
|
|
private int firstIndex;
|
|
|
|
|
private int itemsPerPage;
|
|
|
|
|
|
|
|
|
|
private int page;
|
|
|
|
|
private int numPages;
|
|
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
|
pageLabel = new Label("(0/0)", true);
|
|
|
|
|
|
|
|
|
|
prev = new Button("Prev")
|
|
|
|
|
{
|
|
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
|
|
|
|
if (!rightclick) {
|
|
|
|
|
scroll(-1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getRenderLabel() {
|
|
|
|
|
return "<";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
next = new Button("Next")
|
|
|
|
|
{
|
|
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
|
|
|
|
if (!rightclick) {
|
|
|
|
|
scroll(1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getRenderLabel() {
|
|
|
|
|
return ">";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 20:11:17 -08:00
|
|
|
public int getX(GuiContainer gui) {
|
|
|
|
|
return (gui.xSize + gui.width) / 2 + 3;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
public int getMarginLeft() {
|
|
|
|
|
return x + (w % 18) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMarginTop() {
|
|
|
|
|
return y + (h % 18) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getButtonTop() {
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNextX(GuiContainer gui) {
|
|
|
|
|
return gui.width - prev.w - 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPrevX(GuiContainer gui) {
|
|
|
|
|
return (gui.xSize + gui.width) / 2 + 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPageX(GuiContainer gui) {
|
|
|
|
|
return gui.guiLeft * 3 / 2 + gui.xSize + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getHeight(GuiContainer gui) {
|
2021-08-14 13:42:11 -06:00
|
|
|
return gui.height - 15 - y;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getWidth(GuiContainer gui) {
|
|
|
|
|
return LayoutManager.getSideWidth(gui) - x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getLabelText() {
|
|
|
|
|
return pageLabel.text = "(" + getPage() + "/" + getNumPages() + ")";
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 09:42:39 -08:00
|
|
|
protected void setItems() {
|
|
|
|
|
realItems = _items;
|
|
|
|
|
|
|
|
|
|
// Backwards compat
|
|
|
|
|
ItemPanels.itemPanel._items = _items;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
public void resize(GuiContainer gui) {
|
2020-01-20 09:42:39 -08:00
|
|
|
setItems();
|
2019-12-24 13:37:41 -08:00
|
|
|
final int buttonHeight = 16;
|
|
|
|
|
final int buttonWidth = 16;
|
|
|
|
|
|
|
|
|
|
prev.x = getPrevX(gui);
|
|
|
|
|
prev.y = getButtonTop();
|
|
|
|
|
prev.h = buttonHeight;
|
|
|
|
|
prev.w = buttonWidth;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
next.x = getNextX(gui);
|
|
|
|
|
next.y = getButtonTop();
|
|
|
|
|
next.h = buttonHeight;
|
|
|
|
|
next.w = buttonWidth;
|
|
|
|
|
|
|
|
|
|
pageLabel.x = getPageX(gui);
|
|
|
|
|
pageLabel.y = prev.y + 5;
|
|
|
|
|
pageLabel.text = getLabelText();
|
|
|
|
|
|
|
|
|
|
y = prev.h + prev.y;
|
2020-02-04 20:11:17 -08:00
|
|
|
x = getX(gui);
|
2019-12-24 13:37:41 -08:00
|
|
|
w = getWidth(gui);
|
|
|
|
|
h = getHeight(gui);
|
|
|
|
|
|
|
|
|
|
marginLeft = getMarginLeft();
|
|
|
|
|
marginTop = getMarginTop();
|
2014-06-29 20:31:37 +10:00
|
|
|
columns = w / 18;
|
|
|
|
|
rows = h / 18;
|
2014-09-07 23:22:44 +10:00
|
|
|
//sometimes width and height can be negative with certain resizing
|
|
|
|
|
if(rows < 0) rows = 0;
|
|
|
|
|
if(columns < 0) columns = 0;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
calculatePage();
|
|
|
|
|
updateValidSlots();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
private void calculatePage() {
|
|
|
|
|
if (itemsPerPage == 0)
|
|
|
|
|
numPages = 0;
|
|
|
|
|
else
|
2020-01-20 09:42:39 -08:00
|
|
|
numPages = (int) Math.ceil((float) realItems.size() / (float) itemsPerPage);
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2020-01-20 09:42:39 -08:00
|
|
|
if (firstIndex >= realItems.size())
|
2014-04-29 10:54:20 +10:00
|
|
|
firstIndex = 0;
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
if (numPages == 0)
|
|
|
|
|
page = 0;
|
|
|
|
|
else
|
|
|
|
|
page = firstIndex / itemsPerPage + 1;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
public void setVisible() {
|
|
|
|
|
LayoutManager.addWidget(prev);
|
|
|
|
|
LayoutManager.addWidget(next);
|
|
|
|
|
LayoutManager.addWidget(pageLabel);
|
|
|
|
|
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
private void updateValidSlots() {
|
2014-06-29 20:31:37 +10:00
|
|
|
GuiContainer gui = NEIClientUtils.getGuiContainer();
|
|
|
|
|
validSlotMap = new boolean[rows * columns];
|
|
|
|
|
itemsPerPage = 0;
|
|
|
|
|
for (int i = 0; i < validSlotMap.length; i++)
|
|
|
|
|
if (slotValid(gui, i)) {
|
|
|
|
|
validSlotMap[i] = true;
|
|
|
|
|
itemsPerPage++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
private boolean slotValid(GuiContainer gui, int i) {
|
2014-06-29 20:31:37 +10:00
|
|
|
Rectangle4i rect = getSlotRect(i);
|
2021-06-05 10:47:58 -07:00
|
|
|
try {
|
|
|
|
|
GuiInfo.readLock.lock();
|
|
|
|
|
if(GuiInfo.guiHandlers.stream().anyMatch(handler -> handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h)))
|
2014-06-29 20:31:37 +10:00
|
|
|
return false;
|
2021-06-05 10:47:58 -07:00
|
|
|
} finally {
|
|
|
|
|
GuiInfo.readLock.unlock();
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
return true;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public Rectangle4i getSlotRect(int i) {
|
2014-06-29 20:31:37 +10:00
|
|
|
return getSlotRect(i / columns, i % columns);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public Rectangle4i getSlotRect(int row, int column) {
|
2014-06-29 20:31:37 +10:00
|
|
|
return new Rectangle4i(marginLeft + column * 18, marginTop + row * 18, 18, 18);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public void draw(int mousex, int mousey) {
|
|
|
|
|
if (itemsPerPage == 0)
|
2014-04-29 10:54:20 +10:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
GuiContainerManager.enableMatrixStackLogging();
|
|
|
|
|
int index = firstIndex;
|
2020-01-20 09:42:39 -08:00
|
|
|
for (int i = 0; i < rows * columns && index < realItems.size(); i++) {
|
2014-06-29 20:31:37 +10:00
|
|
|
if (validSlotMap[i]) {
|
2014-04-29 10:54:20 +10:00
|
|
|
Rectangle4i rect = getSlotRect(i);
|
2014-06-29 20:31:37 +10:00
|
|
|
if (rect.contains(mousex, mousey))
|
2014-04-29 10:54:20 +10:00
|
|
|
drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555);//highlight
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2020-01-20 09:42:39 -08:00
|
|
|
GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, realItems.get(index));
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
index++;
|
2014-06-29 20:31:37 +10:00
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
GuiContainerManager.disableMatrixStackLogging();
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public void postDraw(int mousex, int mousey) {
|
|
|
|
|
if (draggedStack != null) {
|
2014-04-29 10:54:20 +10:00
|
|
|
GuiContainerManager.drawItems.zLevel += 100;
|
|
|
|
|
GuiContainerManager.drawItem(mousex - 8, mousey - 8, draggedStack);
|
|
|
|
|
GuiContainerManager.drawItems.zLevel -= 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public void mouseDragged(int mousex, int mousey, int button, long heldTime) {
|
|
|
|
|
if (mouseDownSlot >= 0 && draggedStack == null && NEIClientUtils.getHeldItem() == null &&
|
2019-12-24 13:37:41 -08:00
|
|
|
NEIClientConfig.hasSMPCounterPart() && !GuiInfo.hasCustomSlots(NEIClientUtils.getGuiContainer())) {
|
2014-04-29 10:54:20 +10:00
|
|
|
ItemPanelSlot mouseOverSlot = getSlotMouseOver(mousex, mousey);
|
2014-06-29 20:31:37 +10:00
|
|
|
ItemStack stack = new ItemPanelSlot(mouseDownSlot).item;
|
|
|
|
|
if (stack != null && (mouseOverSlot == null || mouseOverSlot.slotIndex != mouseDownSlot || heldTime > 500)) {
|
2014-04-29 10:54:20 +10:00
|
|
|
int amount = NEIClientConfig.getItemQuantity();
|
2014-06-29 20:31:37 +10:00
|
|
|
if (amount == 0)
|
2014-04-29 10:54:20 +10:00
|
|
|
amount = stack.getMaxStackSize();
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
draggedStack = NEIServerUtils.copyStack(stack, amount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public boolean handleClick(int mousex, int mousey, int button) {
|
|
|
|
|
if (handleDraggedClick(mousex, mousey, button))
|
2014-04-29 10:54:20 +10:00
|
|
|
return true;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
if (NEIClientUtils.getHeldItem() != null) {
|
2021-06-05 10:47:58 -07:00
|
|
|
try {
|
|
|
|
|
GuiInfo.readLock.lock();
|
|
|
|
|
if (GuiInfo.guiHandlers.stream().anyMatch(handler -> handler.hideItemPanelSlot(NEIClientUtils.getGuiContainer(), mousex, mousey, 1, 1)))
|
2014-06-29 20:31:37 +10:00
|
|
|
return false;
|
2021-06-05 10:47:58 -07:00
|
|
|
} finally {
|
|
|
|
|
GuiInfo.readLock.unlock();
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
if (NEIClientConfig.canPerformAction("delete") && NEIClientConfig.canPerformAction("item"))
|
|
|
|
|
if (button == 1)
|
2014-04-29 10:54:20 +10:00
|
|
|
NEIClientUtils.decreaseSlotStack(-999);
|
|
|
|
|
else
|
|
|
|
|
NEIClientUtils.deleteHeldItem();
|
|
|
|
|
else
|
|
|
|
|
NEIClientUtils.dropHeldItem();
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
if (hoverSlot != null) {
|
|
|
|
|
if (button == 2) {
|
|
|
|
|
ItemStack stack = hoverSlot.item;
|
|
|
|
|
if (stack != null) {
|
2014-04-29 10:54:20 +10:00
|
|
|
int amount = NEIClientConfig.getItemQuantity();
|
2014-06-29 20:31:37 +10:00
|
|
|
if (amount == 0)
|
2014-04-29 10:54:20 +10:00
|
|
|
amount = stack.getMaxStackSize();
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
draggedStack = NEIServerUtils.copyStack(stack, amount);
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
} else {
|
2014-04-29 10:54:20 +10:00
|
|
|
mouseDownSlot = hoverSlot.slotIndex;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
private boolean handleDraggedClick(int mousex, int mousey, int button) {
|
|
|
|
|
if (draggedStack == null)
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
GuiContainer gui = NEIClientUtils.getGuiContainer();
|
|
|
|
|
boolean handled = false;
|
2021-06-05 10:47:58 -07:00
|
|
|
try {
|
|
|
|
|
GuiInfo.readLock.lock();
|
|
|
|
|
for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
|
|
|
|
|
if (handler.handleDragNDrop(gui, mousex, mousey, draggedStack, button)) {
|
|
|
|
|
handled = true;
|
|
|
|
|
if (draggedStack.stackSize == 0) {
|
|
|
|
|
draggedStack = null;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-05 10:47:58 -07:00
|
|
|
} finally {
|
|
|
|
|
GuiInfo.readLock.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
if (handled)
|
2014-04-29 10:54:20 +10:00
|
|
|
return true;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
Slot overSlot = gui.getSlotAtPosition(mousex, mousey);
|
2014-06-29 20:31:37 +10:00
|
|
|
if (overSlot != null && overSlot.isItemValid(draggedStack)) {
|
|
|
|
|
if (NEIClientConfig.canCheatItem(draggedStack)) {
|
2014-04-29 10:54:20 +10:00
|
|
|
int contents = overSlot.getHasStack() ? overSlot.getStack().stackSize : 0;
|
|
|
|
|
int add = button == 0 ? draggedStack.stackSize : 1;
|
2014-06-29 20:31:37 +10:00
|
|
|
if (overSlot.getHasStack() && !NEIServerUtils.areStacksSameType(draggedStack, overSlot.getStack()))
|
2014-04-29 10:54:20 +10:00
|
|
|
contents = 0;
|
2014-06-29 20:31:37 +10:00
|
|
|
int total = Math.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize()));
|
|
|
|
|
|
|
|
|
|
if (total > contents) {
|
2014-04-29 10:54:20 +10:00
|
|
|
NEIClientUtils.setSlotContents(overSlot.slotNumber, NEIServerUtils.copyStack(draggedStack, total), true);
|
|
|
|
|
NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false);
|
2014-06-29 20:31:37 +10:00
|
|
|
draggedStack.stackSize -= total - contents;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
if (draggedStack.stackSize == 0)
|
2014-04-29 10:54:20 +10:00
|
|
|
draggedStack = null;
|
2014-06-29 20:31:37 +10:00
|
|
|
} else {
|
2014-04-29 10:54:20 +10:00
|
|
|
draggedStack = null;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
} else if (mousex < gui.guiLeft || mousey < gui.guiTop || mousex >= gui.guiLeft + gui.xSize || mousey >= gui.guiTop + gui.ySize) {
|
2014-04-29 10:54:20 +10:00
|
|
|
draggedStack = null;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public boolean handleClickExt(int mousex, int mousey, int button) {
|
2014-04-29 10:54:20 +10:00
|
|
|
return handleDraggedClick(mousex, mousey, button);
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public void mouseUp(int mousex, int mousey, int button) {
|
|
|
|
|
ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
if (hoverSlot != null && hoverSlot.slotIndex == mouseDownSlot && draggedStack == null) {
|
|
|
|
|
ItemStack item = hoverSlot.item;
|
|
|
|
|
if (NEIController.manager.window instanceof GuiRecipe || !NEIClientConfig.canCheatItem(item)) {
|
|
|
|
|
if (button == 0)
|
2014-04-29 10:54:20 +10:00
|
|
|
GuiCraftingRecipe.openRecipeGui("item", item);
|
2014-06-29 20:31:37 +10:00
|
|
|
else if (button == 1)
|
2014-04-29 10:54:20 +10:00
|
|
|
GuiUsageRecipe.openRecipeGui("item", item);
|
|
|
|
|
|
|
|
|
|
draggedStack = null;
|
|
|
|
|
mouseDownSlot = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
NEIClientUtils.cheatItem(item, button, -1);
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
mouseDownSlot = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public boolean onMouseWheel(int i, int mousex, int mousey) {
|
|
|
|
|
if (!contains(mousex, mousey))
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
scroll(-i);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public boolean handleKeyPress(int keyID, char keyChar) {
|
|
|
|
|
if (keyID == NEIClientConfig.getKeyBinding("gui.next")) {
|
2014-04-29 10:54:20 +10:00
|
|
|
scroll(1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
if (keyID == NEIClientConfig.getKeyBinding("gui.prev")) {
|
2014-04-29 10:54:20 +10:00
|
|
|
scroll(-1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public ItemStack getStackMouseOver(int mousex, int mousey) {
|
2014-04-29 10:54:20 +10:00
|
|
|
ItemPanelSlot slot = getSlotMouseOver(mousex, mousey);
|
2014-06-29 20:31:37 +10:00
|
|
|
return slot == null ? null : slot.item;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) {
|
|
|
|
|
int index = firstIndex;
|
2020-01-20 09:42:39 -08:00
|
|
|
for (int i = 0; i < rows * columns && index < realItems.size(); i++)
|
2014-06-29 20:31:37 +10:00
|
|
|
if (validSlotMap[i]) {
|
|
|
|
|
if (getSlotRect(i).contains(mousex, mousey))
|
|
|
|
|
return new ItemPanelSlot(index);
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return null;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public void scroll(int i) {
|
|
|
|
|
if (itemsPerPage != 0) {
|
|
|
|
|
int oldIndex = firstIndex;
|
|
|
|
|
firstIndex += i * itemsPerPage;
|
2020-01-20 09:42:39 -08:00
|
|
|
if (firstIndex >= realItems.size())
|
2014-06-29 20:31:37 +10:00
|
|
|
firstIndex = 0;
|
|
|
|
|
if (firstIndex < 0)
|
|
|
|
|
if (oldIndex > 0)
|
|
|
|
|
firstIndex = 0;
|
|
|
|
|
else
|
2020-01-20 09:42:39 -08:00
|
|
|
firstIndex = (realItems.size() - 1) / itemsPerPage * itemsPerPage;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
calculatePage();
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public int getPage() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return page;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public int getNumPages() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return numPages;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean contains(int px, int py) {
|
|
|
|
|
GuiContainer gui = NEIClientUtils.getGuiContainer();
|
|
|
|
|
Rectangle4i rect = new Rectangle4i(px, py, 1, 1);
|
2021-06-05 10:47:58 -07:00
|
|
|
try {
|
|
|
|
|
GuiInfo.readLock.lock();
|
|
|
|
|
if(GuiInfo.guiHandlers.stream().anyMatch(handler -> handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h)))
|
2014-06-29 20:31:37 +10:00
|
|
|
return false;
|
2021-06-05 10:47:58 -07:00
|
|
|
} finally {
|
|
|
|
|
GuiInfo.readLock.unlock();
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
return super.contains(px, py);
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|