Search in sources :

Example 11 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class LogisticsRenderPipe method renderSolids.

private void renderSolids(CoreUnroutedPipe pipe, double x, double y, double z, float partialTickTime) {
    GL11.glPushMatrix();
    float light = pipe.container.getWorldObj().getLightBrightness(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
    int count = 0;
    for (LPTravelingItem item : pipe.transport.items) {
        CoreUnroutedPipe lPipe = pipe;
        double lX = x;
        double lY = y;
        double lZ = z;
        float lItemYaw = item.getYaw();
        if (count >= LogisticsRenderPipe.MAX_ITEMS_TO_RENDER) {
            break;
        }
        if (item.getItemIdentifierStack() == null) {
            continue;
        }
        if (item.getContainer().xCoord != lPipe.container.xCoord || item.getContainer().yCoord != lPipe.container.yCoord || item.getContainer().zCoord != lPipe.container.zCoord) {
            continue;
        }
        if (item.getPosition() > lPipe.transport.getPipeLength() || item.getPosition() < 0) {
            continue;
        }
        float fPos = item.getPosition() + item.getSpeed() * partialTickTime;
        if (fPos > lPipe.transport.getPipeLength() && item.output != ForgeDirection.UNKNOWN) {
            CoreUnroutedPipe nPipe = lPipe.transport.getNextPipe(item.output);
            if (nPipe != null) {
                fPos -= lPipe.transport.getPipeLength();
                lX -= lPipe.getX() - nPipe.getX();
                lY -= lPipe.getY() - nPipe.getY();
                lZ -= lPipe.getZ() - nPipe.getZ();
                lItemYaw += lPipe.transport.getYawDiff(item);
                lPipe = nPipe;
                item = item.renderCopy();
                item.input = item.output;
                item.output = ForgeDirection.UNKNOWN;
            } else {
                continue;
            }
        }
        DoubleCoordinates pos = lPipe.getItemRenderPos(fPos, item);
        if (pos == null) {
            continue;
        }
        double boxScale = lPipe.getBoxRenderScale(fPos, item);
        double itemYaw = (lPipe.getItemRenderYaw(fPos, item) - lPipe.getItemRenderYaw(0, item) + lItemYaw) % 360;
        double itemPitch = lPipe.getItemRenderPitch(fPos, item);
        double itemYawForPitch = lPipe.getItemRenderYaw(fPos, item);
        ItemStack itemstack = item.getItemIdentifierStack().makeNormalStack();
        doRenderItem(itemstack, pipe.container.getWorldObj(), lX + pos.getXCoord(), lY + pos.getYCoord(), lZ + pos.getZCoord(), light, 0.75F, boxScale, itemYaw, itemPitch, itemYawForPitch, partialTickTime);
        count++;
    }
    count = 0;
    double dist = 0.135;
    DoubleCoordinates pos = new DoubleCoordinates(0.5, 0.5, 0.5);
    CoordinateUtils.add(pos, ForgeDirection.SOUTH, dist);
    CoordinateUtils.add(pos, ForgeDirection.EAST, dist);
    CoordinateUtils.add(pos, ForgeDirection.UP, dist);
    for (Pair<ItemIdentifierStack, Pair<Integer, Integer>> item : pipe.transport._itemBuffer) {
        if (item == null || item.getValue1() == null) {
            continue;
        }
        ItemStack itemstack = item.getValue1().makeNormalStack();
        doRenderItem(itemstack, pipe.container.getWorldObj(), x + pos.getXCoord(), y + pos.getYCoord(), z + pos.getZCoord(), light, 0.25F, 0, 0, 0, 0, partialTickTime);
        count++;
        if (count >= 27) {
            break;
        } else if (count % 9 == 0) {
            CoordinateUtils.add(pos, ForgeDirection.SOUTH, dist * 2.0);
            CoordinateUtils.add(pos, ForgeDirection.EAST, dist * 2.0);
            CoordinateUtils.add(pos, ForgeDirection.DOWN, dist);
        } else if (count % 3 == 0) {
            CoordinateUtils.add(pos, ForgeDirection.SOUTH, dist * 2.0);
            CoordinateUtils.add(pos, ForgeDirection.WEST, dist);
        } else {
            CoordinateUtils.add(pos, ForgeDirection.NORTH, dist);
        }
    }
    GL11.glPopMatrix();
}
Also used : CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LPTravelingItem(logisticspipes.transport.LPTravelingItem) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) ItemStack(net.minecraft.item.ItemStack) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Pair(logisticspipes.utils.tuples.Pair)

Example 12 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class RequestTreeNode method getCrafters.

private static List<Pair<ICraftingTemplate, List<IFilter>>> getCrafters(IResource iRequestType, List<ExitRoute> validDestinations) {
    List<Pair<ICraftingTemplate, List<IFilter>>> crafters = new ArrayList<>(validDestinations.size());
    for (ExitRoute r : validDestinations) {
        CoreRoutedPipe pipe = r.destination.getPipe();
        if (r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            if (pipe instanceof ICraft) {
                ICraftingTemplate craftable = ((ICraft) pipe).addCrafting(iRequestType);
                if (craftable != null) {
                    for (IFilter filter : r.filters) {
                        if (filter.isBlocked() == filter.isFilteredItem(craftable.getResultItem()) || filter.blockCrafting()) {
                            continue;
                        }
                    }
                    List<IFilter> list = new LinkedList<>();
                    list.addAll(r.filters);
                    crafters.add(new Pair<>(craftable, list));
                }
            }
        }
    }
    //		Collections.sort(crafters,new CraftingTemplate.PairPrioritizer());
    return crafters;
}
Also used : ICraft(logisticspipes.interfaces.routing.ICraft) IFilter(logisticspipes.interfaces.routing.IFilter) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) LinkedList(java.util.LinkedList) Pair(logisticspipes.utils.tuples.Pair)

Example 13 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class QueuedTasks method tickEnd.

@SuppressWarnings({ "rawtypes" })
@SubscribeEvent
public void tickEnd(ServerTickEvent event) {
    if (event.phase != Phase.END) {
        return;
    }
    Callable call = null;
    while (!QueuedTasks.queue.isEmpty()) {
        synchronized (QueuedTasks.queue) {
            call = QueuedTasks.queue.removeFirst();
        }
        if (call != null) {
            try {
                call.call();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    MainProxy.proxy.tick();
    synchronized (LPTravelingItem.forceKeep) {
        Iterator<Pair<Integer, Object>> iter = LPTravelingItem.forceKeep.iterator();
        while (iter.hasNext()) {
            Pair<Integer, Object> pair = iter.next();
            pair.setValue1(pair.getValue1() - 1);
            if (pair.getValue1() < 0) {
                iter.remove();
            }
        }
    }
}
Also used : Callable(java.util.concurrent.Callable) Pair(logisticspipes.utils.tuples.Pair) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 14 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class ItemDisplay method renderItemArea.

public void renderItemArea(double zLevel) {
    GL11.glPushMatrix();
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    screen.drawRect(left, top, left + width, top + height, Color.GREY);
    tooltip = null;
    int ppi = 0;
    int panelxSize = 20;
    int panelySize = 20;
    int x = 2;
    int y = 2;
    ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
    int scaleX = scaledresolution.getScaledWidth();
    int scaleY = scaledresolution.getScaledHeight();
    int mouseX = Mouse.getX() * scaleX / mc.displayWidth - left;
    int mouseY = scaleY - Mouse.getY() * scaleY / mc.displayHeight - top;
    GL11.glTranslatef(left, top, 0.0F);
    if (!listbyserver) {
        int graphic = ((int) (System.currentTimeMillis() / 250) % 5);
        // GL11.glBindTexture(GL11.GL_TEXTURE_2D,
        // this.mc.renderEngine.getTexture());
        screen.getMC().renderEngine.bindTexture(ItemDisplay.TEXTURE);
        Tessellator tesselator = Tessellator.instance;
        tesselator.startDrawingQuads();
        int xPosition = (width / 2) - 50;
        int yPosition = 40;
        tesselator.addVertexWithUV(xPosition, yPosition + 100, zLevel, 0.04, 0.72 + (graphic * 0.03125));
        tesselator.addVertexWithUV(xPosition + 100, yPosition + 100, zLevel, 0.08, 0.72 + (graphic * 0.03125));
        tesselator.addVertexWithUV(xPosition + 100, yPosition, zLevel, 0.08, 0.69 + (graphic * 0.03125));
        tesselator.addVertexWithUV(xPosition, yPosition, zLevel, 0.04, 0.69 + (graphic * 0.03125));
        tesselator.draw();
    } else {
        RenderHelper.enableGUIStandardItemLighting();
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LIGHTING);
        for (ItemIdentifierStack itemIdentifierStack : _allItems) {
            ItemIdentifier item = itemIdentifierStack.getItem();
            if (search != null && !search.itemSearched(item)) {
                continue;
            }
            ppi++;
            if (ppi <= itemsPerPage * page) {
                continue;
            }
            if (ppi > itemsPerPage * (page + 1)) {
                break;
            }
            ItemStack itemstack = itemIdentifierStack.unsafeMakeNormalStack();
            // -2 on both, because field starts there (see black rect below)
            int realX = x - 2;
            int realY = y - 2;
            Pair<Integer, Integer> pair = new Pair<>(realX, realY);
            if (map.get(pair) != itemIdentifierStack) {
                map.put(pair, itemIdentifierStack);
            }
            if (mouseX >= realX && mouseX < realX + panelxSize && mouseY >= realY && mouseY < realY + panelySize) {
                screen.drawRect(x - 2, y - 2, x + panelxSize - 2, y + panelySize - 2, Color.BLACK);
                screen.drawRect(x - 1, y - 1, x + panelxSize - 3, y + panelySize - 3, Color.DARKER_GREY);
                tooltip = new Object[] { mouseX + left, mouseY + top, itemstack };
            }
            /*if (lastClickedx >= realX && lastClickedx < realX + panelxSize && lastClickedy >= realY && lastClickedy < realY + panelySize) {
					selectedItem = itemIdentifierStack;
					screen.drawRect(x - 2, y - 2, x + panelxSize - 2, y + panelySize - 2, Color.BLACK);
					screen.drawRect(x - 1, y - 1, x + panelxSize - 3, y + panelySize - 3, Color.LIGHTER_GREY);
					screen.drawRect(x, y, x + panelxSize - 4, y + panelySize - 4, Color.DARKER_GREY);
				}
				 */
            if (selectedItem == itemIdentifierStack) {
                screen.drawRect(x - 2, y - 2, x + panelxSize - 2, y + panelySize - 2, Color.BLACK);
                screen.drawRect(x - 1, y - 1, x + panelxSize - 3, y + panelySize - 3, Color.LIGHTER_GREY);
                screen.drawRect(x, y, x + panelxSize - 4, y + panelySize - 4, Color.DARKER_GREY);
                if (renderer != null) {
                    renderer.specialItemRendering(itemIdentifierStack.getItem(), x, y);
                }
            }
            // use GuiGraphics to render the ItemStacks
            ItemStackRenderer itemstackRenderer = new ItemStackRenderer(x, y, 100.0F, true, false, true);
            itemstackRenderer.setItemstack(itemstack).setDisplayAmount(DisplayAmount.HIDE_ONE);
            itemstackRenderer.renderInGui();
            x += panelxSize;
            if (x > width) {
                x = 2;
                y += panelySize;
            }
        }
        GL11.glEnable(GL11.GL_DEPTH_TEST);
    }
    GL11.glPopMatrix();
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Tessellator(net.minecraft.client.renderer.Tessellator) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) Pair(logisticspipes.utils.tuples.Pair) ItemStackRenderer(logisticspipes.utils.item.ItemStackRenderer)

Example 15 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class PipeTransportLogistics method resolveRoutedDestination.

public ForgeDirection resolveRoutedDestination(LPTravelingItemServer data) {
    ForgeDirection blocked = null;
    if (data.getDestinationUUID() == null) {
        ItemIdentifierStack stack = data.getItemIdentifierStack();
        ItemRoutingInformation result = getRoutedPipe().getQueuedForItemStack(stack);
        if (result != null) {
            data.setInformation(result);
            data.getInfo().setItem(stack);
            blocked = data.input.getOpposite();
        }
    }
    if (data.getItemIdentifierStack() != null) {
        getRoutedPipe().relayedItem(data.getItemIdentifierStack().getStackSize());
    }
    if (data.getDestination() >= 0 && !getRoutedPipe().getRouter().hasRoute(data.getDestination(), data.getTransportMode() == TransportMode.Active, data.getItemIdentifierStack().getItem()) && data.getBufferCounter() < MAX_DESTINATION_UNREACHABLE_BUFFER) {
        _itemBuffer.add(new Triplet<>(data.getItemIdentifierStack(), new Pair<>(_bufferTimeOut, data.getBufferCounter()), data));
        return null;
    }
    ForgeDirection value;
    if (getRoutedPipe().stillNeedReplace() || getRoutedPipe().initialInit()) {
        data.setDoNotBuffer(false);
        value = ForgeDirection.UNKNOWN;
    } else {
        value = getRoutedPipe().getRouteLayer().getOrientationForItem(data, blocked);
    }
    if (value == null && MainProxy.isClient(getWorld())) {
        return null;
    } else if (value == null) {
        LogisticsPipes.log.fatal("THIS IS NOT SUPPOSED TO HAPPEN!");
        return ForgeDirection.UNKNOWN;
    }
    if (value == ForgeDirection.UNKNOWN && !data.getDoNotBuffer() && data.getBufferCounter() < 5) {
        _itemBuffer.add(new Triplet<>(data.getItemIdentifierStack(), new Pair<>(_bufferTimeOut, data.getBufferCounter()), null));
        return null;
    }
    if (value != ForgeDirection.UNKNOWN && !getRoutedPipe().getRouter().isRoutedExit(value)) {
        if (!isItemExitable(data.getItemIdentifierStack())) {
            return null;
        }
    }
    data.resetDelay();
    return value;
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

Pair (logisticspipes.utils.tuples.Pair)27 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)13 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)11 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)11 ArrayList (java.util.ArrayList)10 List (java.util.List)9 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)8 Map (java.util.Map)7 IFilter (logisticspipes.interfaces.routing.IFilter)7 ExitRoute (logisticspipes.routing.ExitRoute)7 ItemStack (net.minecraft.item.ItemStack)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 HashMap (java.util.HashMap)6 LinkedList (java.util.LinkedList)6 Entry (java.util.Map.Entry)6 MainProxy (logisticspipes.proxy.MainProxy)6 IRouter (logisticspipes.routing.IRouter)6 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)6 IInventory (net.minecraft.inventory.IInventory)6 TileEntity (net.minecraft.tileentity.TileEntity)6