use of logisticspipes.routing.order.LinkedLogisticsOrderList in project LogisticsPipes by RS485.
the class PipeItemsRequestLogistics method simulateRequest.
@Override
public SimulationResult simulateRequest(ItemStack wanted) {
final List<IResource> used = new ArrayList<>();
final List<IResource> missing = new ArrayList<>();
RequestTree.simulate(ItemIdentifier.get(wanted).makeStack(wanted.stackSize), this, new RequestLog() {
@Override
public void handleMissingItems(List<IResource> items) {
missing.addAll(items);
}
@Override
public void handleSucessfullRequestOf(IResource item, LinkedLogisticsOrderList parts) {
}
@Override
public void handleSucessfullRequestOfList(List<IResource> items, LinkedLogisticsOrderList parts) {
used.addAll(items);
}
});
List<ItemStack> usedList = new ArrayList<>(used.size());
List<ItemStack> missingList = new ArrayList<>(missing.size());
for (IResource e : used) {
if (e instanceof ItemResource) {
usedList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
} else if (e instanceof DictResource) {
usedList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
}
}
for (IResource e : missing) {
if (e instanceof ItemResource) {
missingList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
} else if (e instanceof DictResource) {
missingList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
}
}
SimulationResult r = new SimulationResult();
r.used = usedList;
r.missing = missingList;
return r;
}
use of logisticspipes.routing.order.LinkedLogisticsOrderList in project LogisticsPipes by RS485.
the class GuiRequestTable method drawGuiContainerBackgroundLayer.
@Override
public void drawGuiContainerBackgroundLayer(float f, int i, int j) {
for (GuiButton sycleButton : sycleButtons) {
sycleButton.visible = _table.targetType != null;
}
GuiGraphics.drawGuiBackGround(mc, guiLeft, guiTop, right - (showRequest ? 0 : 105), bottom, zLevel, true);
drawRect(guiLeft + 162, guiTop + 23, guiLeft + 182, guiTop + 43, Color.BLACK);
drawRect(guiLeft + 164, guiTop + 25, guiLeft + 180, guiTop + 41, Color.DARKER_GREY);
if (showRequest) {
mc.fontRenderer.drawString(_title, guiLeft + 180 + mc.fontRenderer.getStringWidth(_title) / 2, guiTop + 6, 0x404040);
itemDisplay.renderPageNumber(right - 47, guiTop + 6);
if (buttonList.get(9) instanceof GuiCheckBox && ((GuiCheckBox) buttonList.get(9)).getState()) {
mc.fontRenderer.drawString("Popup", guiLeft + 225, bottom - 56, 0x404040);
} else {
mc.fontRenderer.drawString("Popup", guiLeft + 225, bottom - 56, Color.getValue(Color.GREY));
}
itemDisplay.renderAmount(getStackAmount());
// SearchInput
search.drawTextBox();
itemDisplay.renderSortMode(right - 103, bottom - 52);
itemDisplay.renderItemArea(zLevel);
}
for (int x = 0; x < 9; x++) {
for (int y = 0; y < 3; y++) {
GuiGraphics.drawSlotBackground(mc, guiLeft + (x * 18) + 19, guiTop + (y * 18) + 79);
}
}
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
GuiGraphics.drawSlotBackground(mc, guiLeft + (x * 18) + 19, guiTop + (y * 18) + 14);
}
}
mc.fontRenderer.drawString("Sort:", guiLeft + 136, guiTop + 55, 0xffffff);
GuiGraphics.drawSlotBackground(mc, guiLeft + 100, guiTop + 32);
GuiGraphics.drawSlotBackground(mc, guiLeft + 163, guiTop + 50);
drawRect(guiLeft + 75, guiTop + 38, guiLeft + 95, guiTop + 43, Color.DARKER_GREY);
for (int a = 0; a < 10; a++) {
drawRect(guiLeft + 97 - a, guiTop + 40 - a, guiLeft + 98 - a, guiTop + 41 + a, Color.DARKER_GREY);
}
for (int a = 0; a < 15; a++) {
drawRect(guiLeft + 164 + a, guiTop + 51 + a, guiLeft + 166 + a, guiTop + 53 + a, Color.DARKER_GREY);
drawRect(guiLeft + 164 + a, guiTop + 65 - a, guiLeft + 166 + a, guiTop + 67 - a, Color.DARKER_GREY);
}
GuiGraphics.drawPlayerInventoryBackground(mc, guiLeft + 20, guiTop + 150);
for (final Entry<Integer, Pair<IResource, LinkedLogisticsOrderList>> entry : _table.watchedRequests.entrySet()) {
if (!handledExtention.get(entry.getKey())) {
handledExtention.set(entry.getKey());
extentionControllerLeft.addExtention(new GuiExtention() {
private Map<Pair<Integer, Integer>, IOrderInfoProvider> ordererPosition = new HashMap<>();
private int height;
private int width = 4;
private GuiButton localControlledButton;
@Override
public void renderForground(int left, int top) {
if (!_table.watchedRequests.containsKey(entry.getKey())) {
extentionControllerLeft.removeExtention(this);
if (isFullyExtended() && localControlledButton != null) {
buttonList.remove(localControlledButton);
localControlledButton = null;
orderIdForButton = -1;
}
return;
}
ordererPosition.clear();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
RenderHelper.enableGUIStandardItemLighting();
ItemStack stack;
IResource resource = entry.getValue().getValue1();
String s;
if (resource != null) {
stack = resource.getDisplayItem().makeNormalStack();
itemRender.renderItemAndEffectIntoGUI(stack, left + 5, top + 5);
itemRender.renderItemOverlayIntoGUI(mc.fontRenderer, stack, left + 5, top + 5, "");
s = TextUtil.getThreeDigitFormattedNumber(stack.getCount(), false);
} else {
s = "List";
}
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
itemRender.zLevel = 0.0F;
// Draw number
mc.fontRenderer.drawStringWithShadow(s, left + 22 - mc.fontRenderer.getStringWidth(s), top + 14, 16777215);
if (isFullyExtended()) {
if (localControlledButton == null || orderIdForButton != entry.getKey()) {
if (localControlledButton != null) {
buttonList.remove(localControlledButton);
}
localControlledButton = new SmallGuiButton(100, guiLeft - 35, guiTop + 10, 30, 10, "more");
buttonList.add(localControlledButton);
orderIdForButton = entry.getKey();
}
List<IOrderInfoProvider> list = entry.getValue().getValue2().getList();
calculateSize(left, top, list);
String ident = String.format("ID: %d", entry.getKey());
mc.fontRenderer.drawStringWithShadow(ident, left + 25, top + 7, 16777215);
int x = left + 6;
int y = top + 25;
for (IOrderInfoProvider order : list) {
stack = order.getAsDisplayItem().makeNormalStack();
if (stack.getCount() <= 0) {
continue;
}
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
RenderHelper.enableGUIStandardItemLighting();
itemRender.renderItemAndEffectIntoGUI(stack, x, y);
itemRender.renderItemOverlayIntoGUI(fontRenderer, stack, x, y, "");
s = TextUtil.getThreeDigitFormattedNumber(stack.getCount(), false);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
itemRender.zLevel = 0.0F;
// Draw number
mc.fontRenderer.drawStringWithShadow(s, x + 17 - mc.fontRenderer.getStringWidth(s), y + 9, 16777215);
ordererPosition.put(new Pair<>(x, y), order);
x += 18;
if (x > left + getFinalWidth() - 18) {
x = left + 6;
y += 18;
}
}
} else if (isExtending()) {
List<IOrderInfoProvider> list = entry.getValue().getValue2().getList();
calculateSize(left, top, list);
}
if (!isFullyExtended() && localControlledButton != null) {
buttonList.remove(localControlledButton);
localControlledButton = null;
orderIdForButton = -1;
}
RenderHelper.disableStandardItemLighting();
}
private void calculateSize(int left, int top, List<IOrderInfoProvider> list) {
int x = left + 6;
int y = 50;
int line = 1;
width = 4;
for (IOrderInfoProvider order : list) {
ItemStack stack = order.getAsDisplayItem().makeNormalStack();
if (stack.getCount() <= 0) {
continue;
}
if (line++ % (4 * 4) == 0) {
width++;
}
}
for (IOrderInfoProvider order : list) {
ItemStack stack = order.getAsDisplayItem().makeNormalStack();
if (stack.getCount() <= 0) {
continue;
}
x += 18;
if (x > left + getFinalWidth() - 18) {
x = left + 6;
y += 18;
}
}
height = y;
if (x == left + 6) {
height -= 18;
}
}
@Override
public int getFinalWidth() {
return Math.max(85, width * 18 + 8);
}
@Override
public int getFinalHeight() {
return Math.max(50, height);
}
@Override
public void handleMouseOverAt(int xPos, int yPos) {
if (isFullyExtended()) {
ordererPosition.keySet().stream().filter(key -> xPos >= key.getValue1() && xPos < key.getValue1() + 18 && yPos >= key.getValue2() && yPos < key.getValue2() + 18).forEach(key -> {
IOrderInfoProvider order = ordererPosition.get(key);
List<String> list = new ArrayList<>();
list.add(ChatColor.BLUE + "Request Type: " + ChatColor.YELLOW + order.getType().name());
list.add(ChatColor.BLUE + "Send to Router ID: " + ChatColor.YELLOW + order.getRouterId());
GuiGraphics.displayItemToolTip(new Object[] { xPos - 10, yPos, order.getAsDisplayItem().makeNormalStack(), true, list }, zLevel, guiLeft, guiTop, false);
});
} else if (entry.getValue() != null && entry.getValue().getValue1() != null && entry.getValue().getValue1().getDisplayItem() != null) {
List<String> list = new ArrayList<>();
list.add(ChatColor.BLUE + "Request ID: " + ChatColor.YELLOW + entry.getKey());
GuiGraphics.displayItemToolTip(new Object[] { xPos - 10, yPos, entry.getValue().getValue1().getDisplayItem().makeNormalStack(), true, list }, zLevel, guiLeft, guiTop, false);
}
}
});
}
}
super.renderExtentions();
}
use of logisticspipes.routing.order.LinkedLogisticsOrderList in project LogisticsPipes by RS485.
the class RequestTree method request.
public static boolean request(List<ItemIdentifierStack> items, IRequestItems requester, RequestLog log, EnumSet<ActiveRequestType> requestFlags, IAdditionalTargetInformation info) {
Map<IResource, Integer> messages = new HashMap<>();
RequestTree tree = new RequestTree(new ItemResource(new ItemIdentifierStack(ItemIdentifier.get(Item.getItemFromBlock(Blocks.STONE), 0, null), 0), requester), null, requestFlags, info);
boolean isDone = true;
for (ItemIdentifierStack stack : items) {
ItemIdentifier item = stack.getItem();
Integer count = messages.get(item);
if (count == null) {
count = 0;
}
count += stack.getStackSize();
ItemResource req = new ItemResource(stack, requester);
messages.put(req, count);
RequestTree node = new RequestTree(req, tree, requestFlags, info);
isDone = isDone && node.isDone();
}
if (isDone) {
LinkedLogisticsOrderList list = tree.fullFillAll();
if (log != null) {
log.handleSucessfullRequestOfList(RequestTreeNode.shrinkToList(messages), list);
}
return true;
} else {
if (log != null) {
tree.logFailedRequestTree(log);
}
return false;
}
}
use of logisticspipes.routing.order.LinkedLogisticsOrderList in project LogisticsPipes by RS485.
the class OrdererWatchPacket method readData.
@Override
public void readData(LPDataInput input) {
super.readData(input);
stack = ResourceNetwork.readResource(input);
orders = new LinkedLogisticsOrderList(input);
}
use of logisticspipes.routing.order.LinkedLogisticsOrderList in project LogisticsPipes by RS485.
the class PipeItemsRequestLogistics method performRequest.
@Override
public List<ItemStack> performRequest(ItemStack wanted) {
final List<IResource> missing = new ArrayList<>();
RequestTree.request(ItemIdentifier.get(wanted).makeStack(wanted.stackSize), this, new RequestLog() {
@Override
public void handleMissingItems(List<IResource> items) {
missing.addAll(items);
}
@Override
public void handleSucessfullRequestOf(IResource item, LinkedLogisticsOrderList parts) {
}
@Override
public void handleSucessfullRequestOfList(List<IResource> items, LinkedLogisticsOrderList parts) {
}
}, null);
List<ItemStack> missingList = new ArrayList<>(missing.size());
for (IResource e : missing) {
if (e instanceof ItemResource) {
missingList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
} else if (e instanceof DictResource) {
missingList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
}
}
return missingList;
}
Aggregations