Search in sources :

Example 26 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class LogisticsPowerProviderTileEntity method sendPowerLaserPackets.

private void sendPowerLaserPackets(IRouter sourceRouter, IRouter destinationRouter, ForgeDirection exitOrientation, boolean addBall) {
    if (sourceRouter == destinationRouter) {
        return;
    }
    LinkedList<Triplet<IRouter, ForgeDirection, Boolean>> todo = new LinkedList<>();
    todo.add(new Triplet<>(sourceRouter, exitOrientation, addBall));
    while (!todo.isEmpty()) {
        Triplet<IRouter, ForgeDirection, Boolean> part = todo.pollFirst();
        List<ExitRoute> exits = part.getValue1().getRoutersOnSide(part.getValue2());
        for (ExitRoute exit : exits) {
            if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                // Find only result (caused by only straight connections)
                int distance = part.getValue1().getDistanceToNextPowerPipe(exit.exitOrientation);
                CoreRoutedPipe pipe = part.getValue1().getPipe();
                if (pipe != null && pipe.isInitialized()) {
                    pipe.container.addLaser(exit.exitOrientation, distance, getLaserColor(), false, part.getValue3());
                }
                // Use new sourceRouter
                IRouter nextRouter = exit.destination;
                if (nextRouter == destinationRouter) {
                    return;
                }
                outerRouters: for (ExitRoute newExit : nextRouter.getDistanceTo(destinationRouter)) {
                    if (newExit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                        for (IFilter filter : newExit.filters) {
                            if (filter.blockPower()) {
                                continue outerRouters;
                            }
                        }
                        todo.addLast(new Triplet<>(nextRouter, newExit.exitOrientation, newExit.exitOrientation != exit.exitOrientation));
                    }
                }
            }
        }
    }
}
Also used : Triplet(logisticspipes.utils.tuples.Triplet) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) LinkedList(java.util.LinkedList) IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute)

Example 27 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class HUDAdvancedExtractor method renderContent.

@Override
public void renderContent(boolean shifted) {
    if (selected == 0) {
        Minecraft mc = FMLClientHandler.instance().getClient();
        ForgeDirection d = module.getSneakyDirection();
        mc.fontRenderer.drawString("Extract", -22, -22, 0);
        mc.fontRenderer.drawString("from:", -22, -9, 0);
        mc.fontRenderer.drawString(((d == ForgeDirection.UNKNOWN) ? "DEFAULT" : d.name()), -22, 18, 0);
    } else {
        Minecraft mc = FMLClientHandler.instance().getClient();
        GL11.glScalef(1.0F, 1.0F, -0.00001F);
        ItemStackRenderer.renderItemIdentifierStackListIntoGui(ItemIdentifierStack.getListFromInventory(module.getFilterInventory()), null, 0, -25, -32, 3, 9, 18, 18, 100.0F, DisplayAmount.NEVER, true, false, shifted);
        GL11.glScalef(1.0F, 1.0F, 1 / -0.00001F);
        if (module.areItemsIncluded()) {
            mc.fontRenderer.drawString("Included", -22, 25, 0);
        } else {
            mc.fontRenderer.drawString("Excluded", -22, 25, 0);
        }
    }
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Minecraft(net.minecraft.client.Minecraft)

Example 28 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class ChassiTransportLayer method stillWantItem.

@Override
public boolean stillWantItem(IRoutedItem item) {
    LogisticsModule module = _chassiPipe.getLogisticsModule();
    if (module == null) {
        _chassiPipe.notifyOfItemArival(item.getInfo());
        return false;
    }
    if (!_chassiPipe.isEnabled()) {
        _chassiPipe.notifyOfItemArival(item.getInfo());
        return false;
    }
    SinkReply reply = module.sinksItem(item.getItemIdentifierStack().getItem(), -1, 0, true, false);
    if (reply == null || reply.maxNumberOfItems < 0) {
        _chassiPipe.notifyOfItemArival(item.getInfo());
        return false;
    }
    if (reply.maxNumberOfItems > 0 && item.getItemIdentifierStack().getStackSize() > reply.maxNumberOfItems) {
        ForgeDirection o = _chassiPipe.getPointedOrientation();
        if (o == null || o == ForgeDirection.UNKNOWN) {
            o = ForgeDirection.UP;
        }
        item.split(reply.maxNumberOfItems, o);
    }
    return true;
}
Also used : SinkReply(logisticspipes.utils.SinkReply) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 29 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class PipeTransportLayer method itemArrived.

@Override
public ForgeDirection itemArrived(IRoutedItem item, ForgeDirection denyed) {
    if (item.getItemIdentifierStack() != null) {
        _trackStatistics.recievedItem(item.getItemIdentifierStack().getStackSize());
    }
    List<AdjacentTileEntity> adjacentEntities = new WorldCoordinatesWrapper(routedPipe.container).getConnectedAdjacentTileEntities(IPipeInformationProvider.ConnectionPipeType.ITEM).collect(Collectors.toList());
    LinkedList<ForgeDirection> possibleForgeDirection = new LinkedList<>();
    for (AdjacentTileEntity adjacent : adjacentEntities) {
        if (SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)) {
            continue;
        }
        if (_router.isRoutedExit(adjacent.direction)) {
            continue;
        }
        if (denyed != null && denyed.equals(adjacent.direction)) {
            continue;
        }
        CoreRoutedPipe pipe = _router.getPipe();
        if (pipe != null) {
            if (pipe.isLockedExit(adjacent.direction)) {
                continue;
            }
        }
        possibleForgeDirection.add(adjacent.direction);
    }
    if (possibleForgeDirection.size() != 0) {
        return possibleForgeDirection.get(routedPipe.getWorld().rand.nextInt(possibleForgeDirection.size()));
    }
    // 2nd prio, deliver to non-routed exit
    for (AdjacentTileEntity adjacent : adjacentEntities) {
        if (_router.isRoutedExit(adjacent.direction)) {
            continue;
        }
        CoreRoutedPipe pipe = _router.getPipe();
        if (pipe != null) {
            if (pipe.isLockedExit(adjacent.direction)) {
                continue;
            }
        }
        possibleForgeDirection.add(adjacent.direction);
    }
    if (possibleForgeDirection.size() == 0) {
        return null;
    }
    return possibleForgeDirection.get(routedPipe.getWorld().rand.nextInt(possibleForgeDirection.size()));
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) LinkedList(java.util.LinkedList) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Example 30 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class ModuleCrafterMK3 method tick.

@Override
public void tick() {
    super.tick();
    if (inv.isEmpty()) {
        return;
    }
    if (!_service.isNthTick(6)) {
        return;
    }
    //Add from internal buffer
    List<AdjacentTileEntity> crafters = locateCrafters();
    boolean change = false;
    for (AdjacentTileEntity adjacent : crafters) {
        for (int i = inv.getSizeInventory() - 1; i >= 0; i--) {
            ItemIdentifierStack slot = inv.getIDStackInSlot(i);
            if (slot == null) {
                continue;
            }
            ForgeDirection insertion = adjacent.direction.getOpposite();
            if (getUpgradeManager().hasSneakyUpgrade()) {
                insertion = getUpgradeManager().getSneakyOrientation();
            }
            ItemIdentifierStack toadd = slot.clone();
            toadd.setStackSize(Math.min(toadd.getStackSize(), toadd.getItem().getMaxStackSize()));
            if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
                toadd.setStackSize(Math.min(toadd.getStackSize(), ((IInventory) adjacent.tileEntity).getInventoryStackLimit()));
                ItemStack added = InventoryHelper.getTransactorFor(adjacent.tileEntity, adjacent.direction.getOpposite()).add(toadd.makeNormalStack(), insertion, true);
                slot.setStackSize(slot.getStackSize() - added.stackSize);
                if (added.stackSize != 0) {
                    change = true;
                }
            } else {
                _service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(toadd), adjacent.direction.getOpposite());
                slot.setStackSize(slot.getStackSize() - toadd.getStackSize());
                change = true;
            }
            if (slot.getStackSize() <= 0) {
                inv.clearInventorySlotContents(i);
            } else {
                inv.setInventorySlotContents(i, slot);
            }
        }
    }
    if (change) {
        inv.markDirty();
        _service.getCacheHolder().trigger(CacheTypes.Inventory);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Aggregations

ForgeDirection (net.minecraftforge.common.util.ForgeDirection)242 TileEntity (net.minecraft.tileentity.TileEntity)80 ItemStack (net.minecraft.item.ItemStack)47 ArrayList (java.util.ArrayList)29 Block (net.minecraft.block.Block)28 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)24 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)21 IInventory (net.minecraft.inventory.IInventory)19 FluidStack (net.minecraftforge.fluids.FluidStack)18 SideOnly (cpw.mods.fml.relauncher.SideOnly)17 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)17 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)16 HashMap (java.util.HashMap)12 Pair (logisticspipes.utils.tuples.Pair)11 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)10 World (net.minecraft.world.World)10 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)9 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)9 List (java.util.List)8