use of gregtech.common.inventory.IItemList in project GregTech by GregTechCE.
the class ItemListSlotWidget method extractItemStack.
private void extractItemStack(ItemStackKey itemStackKey, int amount, boolean isClient) {
InventoryPlayer inventory = gui.entityPlayer.inventory;
if (inventory.getItemStack().isEmpty()) {
if (!isClient) {
// on server, we try to extract from the network
IItemList itemList = gridWidget.getItemList();
int amountExtracted = itemList.extractItem(itemStackKey, amount, false);
if (amountExtracted > 0) {
ItemStack resultStack = itemStackKey.getItemStack();
resultStack.setCount(amountExtracted);
inventory.setItemStack(resultStack);
}
uiAccess.sendHeldItemUpdate();
} else {
// on client we assume we can extract as much items as user wishes
ItemStack itemStack = itemStackKey.getItemStack();
itemStack.setCount(amount);
inventory.setItemStack(itemStack);
}
}
}
use of gregtech.common.inventory.IItemList in project GregTech by GregTechCE.
the class ItemListSlotWidget method insertHeldItemStack.
// returns true if something actually happened
private boolean insertHeldItemStack(int button, boolean isClient) {
InventoryPlayer inventory = gui.entityPlayer.inventory;
int amountToInsert = button == 1 ? 1 : Integer.MAX_VALUE;
if (!inventory.getItemStack().isEmpty()) {
if (!isClient) {
// on server, we lookup item list to see how much we can actually insert
ItemStack heldItemStack = inventory.getItemStack();
IItemList itemList = gridWidget.getItemList();
int amountInserted = itemList.insertItem(new ItemStackKey(heldItemStack), Math.min(heldItemStack.getCount(), amountToInsert), false, InsertMode.LOWEST_PRIORITY);
heldItemStack.shrink(amountInserted);
uiAccess.sendHeldItemUpdate();
gui.entityPlayer.openContainer.detectAndSendChanges();
return amountInserted > 0;
} else {
// on client we assume we can insert full stack into the network
inventory.getItemStack().shrink(amountToInsert);
return true;
}
}
return false;
}
use of gregtech.common.inventory.IItemList in project GregTech by GregTechCE.
the class MetaTileEntityWorkbench method createItemListTab.
private AbstractWidgetGroup createItemListTab() {
WidgetGroup widgetGroup = new WidgetGroup();
widgetGroup.addWidget(new LabelWidget(5, 20, "gregtech.machine.workbench.storage_note_1"));
widgetGroup.addWidget(new LabelWidget(5, 30, "gregtech.machine.workbench.storage_note_2"));
CraftingRecipeResolver recipeResolver = getRecipeResolver();
IItemList itemList = recipeResolver == null ? null : recipeResolver.getItemSourceList();
widgetGroup.addWidget(new ItemListGridWidget(2, 45, 9, 5, itemList));
return widgetGroup;
}
Aggregations