use of codechicken.nei.api.INEIGuiHandler in project Galacticraft by micdoodle8.
the class ItemPanel method contains.
@Override
public boolean contains(int px, int py) {
GuiContainer gui = NEIClientUtils.getGuiContainer();
Rectangle4i rect = new Rectangle4i(px, py, 1, 1);
for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
if (handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h)) {
return false;
}
}
return super.contains(px, py);
}
use of codechicken.nei.api.INEIGuiHandler in project Galacticraft by micdoodle8.
the class ItemPanel method handleDraggedClick.
private boolean handleDraggedClick(int mousex, int mousey, int button) {
if (draggedStack == null) {
return false;
}
GuiContainer gui = NEIClientUtils.getGuiContainer();
boolean handled = false;
for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
if (handler.handleDragNDrop(gui, mousex, mousey, draggedStack, button)) {
handled = true;
if (draggedStack.stackSize == 0) {
draggedStack = null;
return true;
}
}
}
if (handled) {
return true;
}
Slot overSlot = gui.getSlotAtPosition(mousex, mousey);
if (overSlot != null && overSlot.isItemValid(draggedStack)) {
if (NEIClientConfig.canCheatItem(draggedStack)) {
int contents = overSlot.getHasStack() ? overSlot.getStack().stackSize : 0;
int add = button == 0 ? draggedStack.stackSize : 1;
if (overSlot.getHasStack() && !NEIServerUtils.areStacksSameType(draggedStack, overSlot.getStack())) {
contents = 0;
}
int total = Math.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize()));
if (total > contents) {
NEIClientUtils.setSlotContents(overSlot.slotNumber, NEIServerUtils.copyStack(draggedStack, total), true);
NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false);
draggedStack.stackSize -= total - contents;
}
if (draggedStack.stackSize == 0) {
draggedStack = null;
}
} else {
draggedStack = null;
}
} else if (mousex < gui.guiLeft || mousey < gui.guiTop || mousex >= gui.guiLeft + gui.xSize || mousey >= gui.guiTop + gui.ySize) {
draggedStack = null;
}
return true;
}
use of codechicken.nei.api.INEIGuiHandler in project Galacticraft by micdoodle8.
the class ItemPanel method handleClick.
@Override
public boolean handleClick(int mousex, int mousey, int button) {
if (handleDraggedClick(mousex, mousey, button)) {
return true;
}
if (NEIClientUtils.getHeldItem() != null) {
for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
if (handler.hideItemPanelSlot(NEIClientUtils.getGuiContainer(), mousex, mousey, 1, 1)) {
return false;
}
}
if (NEIClientConfig.canPerformAction("delete") && NEIClientConfig.canPerformAction("item")) {
if (button == 1) {
NEIClientUtils.decreaseSlotStack(-999);
} else {
NEIClientUtils.deleteHeldItem();
}
} else {
NEIClientUtils.dropHeldItem();
}
return true;
}
ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
if (hoverSlot != null) {
if (button == 2) {
ItemStack stack = hoverSlot.item;
if (stack != null) {
int amount = NEIClientConfig.getItemQuantity();
if (amount == 0) {
amount = stack.getMaxStackSize();
}
draggedStack = NEIServerUtils.copyStack(stack, amount);
}
} else {
mouseDownSlot = hoverSlot.slotIndex;
}
return true;
}
return false;
}
use of codechicken.nei.api.INEIGuiHandler in project Galacticraft by micdoodle8.
the class NEIClientUtils method giveStack.
public static void giveStack(ItemStack base, int i, boolean infinite) {
ItemStack stack = copyStack(base, i);
if (hasSMPCounterPart()) {
ItemStack typestack = copyStack(stack, 1);
if (!infinite && !canItemFitInInventory(mc().thePlayer, stack) && (mc().currentScreen instanceof GuiContainer)) {
GuiContainer gui = getGuiContainer();
List<Iterable<Integer>> handlerSlots = new LinkedList<Iterable<Integer>>();
for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
handlerSlots.add(handler.getItemSpawnSlots(gui, typestack));
}
int increment = typestack.getMaxStackSize();
int given = 0;
for (int slotNo : Iterables.concat(handlerSlots)) {
Slot slot = gui.inventorySlots.getSlot(slotNo);
if (!slot.isItemValid(typestack) || !InventoryUtils.canStack(slot.getStack(), typestack)) {
continue;
}
int qty = Math.min(stack.stackSize - given, increment);
int current = slot.getHasStack() ? slot.getStack().stackSize : 0;
qty = Math.min(qty, slot.getSlotStackLimit() - current);
ItemStack newStack = copyStack(typestack, qty + current);
slot.putStack(newStack);
setSlotContents(slotNo, newStack, true);
given += qty;
if (given >= stack.stackSize) {
break;
}
}
if (given > 0) {
NEICPH.sendGiveItem(copyStack(typestack, given), false, false);
}
} else {
NEICPH.sendGiveItem(stack, infinite, true);
}
} else {
for (int given = 0; given < stack.stackSize; ) {
int qty = Math.min(stack.stackSize - given, stack.getMaxStackSize());
sendCommand(getStringSetting("command.item"), mc().thePlayer.getName(), Item.itemRegistry.getNameForObject(stack.getItem()), qty, stack.getItemDamage(), stack.hasTagCompound() ? stack.getTagCompound().toString() : "", Item.getIdFromItem(stack.getItem()));
given += qty;
}
}
}
Aggregations