Search in sources :

Example 1 with ILPTEInformation

use of logisticspipes.asm.te.ILPTEInformation in project LogisticsPipes by RS485.

the class TEControl method handleBlockUpdate.

public static void handleBlockUpdate(final World world, final LPWorldInfo info, int x, int y, int z) {
    if (info.getWorldTick() < 5) {
        return;
    }
    final DoubleCoordinates pos = new DoubleCoordinates(x, y, z);
    if (info.getUpdateQueued().contains(pos)) {
        return;
    }
    if (!pos.blockExists(world)) {
        return;
    }
    final TileEntity tile = pos.getTileEntity(world);
    if (SimpleServiceLocator.enderIOProxy.isBundledPipe(tile)) {
        QueuedTasks.queueTask(() -> {
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile instanceof LogisticsTileGenericPipe) {
                    ((LogisticsTileGenericPipe) nextTile).scheduleNeighborChange();
                }
            }
            return null;
        });
    }
    if (tile == null || ((ILPTEInformation) tile).getObject() == null) {
        return;
    }
    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile) || SimpleServiceLocator.specialtileconnection.isType(tile)) {
        info.getUpdateQueued().add(pos);
        QueuedTasks.queueTask(() -> {
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile != null && ((ILPTEInformation) nextTile).getObject() != null) {
                    for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) nextTile).getObject().changeListeners)) {
                        listener.pipeModified(pos);
                    }
                }
            }
            for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) tile).getObject().changeListeners)) {
                listener.pipeModified(pos);
            }
            info.getUpdateQueued().remove(pos);
            return null;
        });
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ArrayList(java.util.ArrayList) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 2 with ILPTEInformation

use of logisticspipes.asm.te.ILPTEInformation in project LogisticsPipes by RS485.

the class TEControl method validate.

public static void validate(final TileEntity tile) {
    final World world = tile.getWorldObj();
    if (world == null) {
        return;
    }
    if (!MainProxy.isServer(world)) {
        return;
    }
    if (tile.getClass().getName().startsWith("net.minecraft.tileentity")) {
        return;
    }
    final DoubleCoordinates pos = new DoubleCoordinates(tile);
    if (pos.getXInt() == 0 && pos.getYInt() <= 0 && pos.getZInt() == 0) {
        return;
    }
    if (SimpleServiceLocator.pipeInformationManager.isPipe(tile, false, ConnectionPipeType.UNDEFINED) || SimpleServiceLocator.specialtileconnection.isType(tile)) {
        ((ILPTEInformation) tile).setObject(new LPTileEntityObject());
        ((ILPTEInformation) tile).getObject().initialised = LPTickHandler.getWorldInfo(world).getWorldTick();
        if (((ILPTEInformation) tile).getObject().initialised < 5) {
            return;
        }
        QueuedTasks.queueTask(() -> {
            if (!SimpleServiceLocator.pipeInformationManager.isPipe(tile, true, ConnectionPipeType.UNDEFINED)) {
                return null;
            }
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile != null && ((ILPTEInformation) nextTile).getObject() != null) {
                    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(nextTile)) {
                        SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(nextTile).refreshTileCacheOnSide(dir.getOpposite());
                    }
                    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
                        SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(tile).refreshTileCacheOnSide(dir);
                        SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(tile).refreshTileCacheOnSide(dir.getOpposite());
                    }
                    for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) nextTile).getObject().changeListeners)) {
                        listener.pipeAdded(pos, dir.getOpposite());
                    }
                }
            }
            return null;
        });
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) LPTileEntityObject(logisticspipes.asm.te.LPTileEntityObject) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 3 with ILPTEInformation

use of logisticspipes.asm.te.ILPTEInformation in project LogisticsPipes by RS485.

the class TEControl method invalidate.

public static void invalidate(final TileEntity tile) {
    final World world = tile.getWorldObj();
    if (world == null) {
        return;
    }
    if (!MainProxy.isServer(world)) {
        return;
    }
    if (tile instanceof LogisticsTileGenericPipe && ((LogisticsTileGenericPipe) tile).isRoutingPipe()) {
        return;
    }
    if (((ILPTEInformation) tile).getObject() != null) {
        QueuedTasks.queueTask(() -> {
            DoubleCoordinates pos = new DoubleCoordinates(tile);
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile != null && ((ILPTEInformation) nextTile).getObject() != null) {
                    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(nextTile)) {
                        SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(nextTile).refreshTileCacheOnSide(dir.getOpposite());
                    }
                }
            }
            for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) tile).getObject().changeListeners)) {
                listener.pipeRemoved(pos);
            }
            return null;
        });
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 4 with ILPTEInformation

use of logisticspipes.asm.te.ILPTEInformation in project LogisticsPipes by RS485.

the class TDDuctInformationProvider method acceptItem.

@Override
public boolean acceptItem(LPTravelingItem item, TileEntity from) {
    if (item instanceof LPTravelingItemServer) {
        LPTravelingItemServer serverItem = (LPTravelingItemServer) item;
        int id = serverItem.getInfo().destinationint;
        if (id == -1) {
            id = SimpleServiceLocator.routerManager.getIDforUUID(serverItem.getInfo().destinationUUID);
        }
        IRouter destination = SimpleServiceLocator.routerManager.getRouter(id);
        if (destination == null) {
            return false;
        }
        RouteCache routes = duct.getCache(true);
        Iterable<Route> paramIterable = routes.outputRoutes;
        Route route = null;
        Object cache = null;
        Triplet<Integer, ItemIdentifier, Boolean> key = new Triplet<>(id, item.getItemIdentifierStack().getItem(), serverItem.getInfo()._transportMode == TransportMode.Active);
        if (duct instanceof ILPTEInformation && ((ILPTEInformation) duct).getObject() != null) {
            cache = ((ILPTEInformation) duct).getObject().getCacheHolder().getCacheFor(CacheTypes.Routing, key);
        }
        if (cache instanceof Route) {
            route = (Route) cache;
            if (!routes.outputRoutes.contains(route)) {
                route = null;
            }
        }
        if (route == null) {
            Pair<Double, Route> closesedConnection = null;
            List<DoubleCoordinates> visited = new ArrayList<>();
            visited.add(new DoubleCoordinates(from));
            for (Route localRoute1 : paramIterable) {
                if (localRoute1.endPoint instanceof LPItemDuct) {
                    LPItemDuct lpDuct = (LPItemDuct) localRoute1.endPoint;
                    double max = Integer.MAX_VALUE;
                    if (closesedConnection != null) {
                        max = closesedConnection.getValue1();
                    }
                    DoubleCoordinates pos = new DoubleCoordinates((TileEntity) lpDuct.pipe);
                    if (visited.contains(pos)) {
                        continue;
                    }
                    visited.add(pos);
                    double distance = lpDuct.pipe.getDistanceTo(id, ForgeDirection.getOrientation(localRoute1.pathDirections.get(localRoute1.pathDirections.size() - 1)).getOpposite(), item.getItemIdentifierStack().getItem(), serverItem.getInfo()._transportMode == TransportMode.Active, localRoute1.pathWeight, max, visited);
                    visited.remove(pos);
                    if (distance != Integer.MAX_VALUE && (closesedConnection == null || distance + localRoute1.pathDirections.size() < closesedConnection.getValue1())) {
                        closesedConnection = new Pair<>(distance + localRoute1.pathWeight, localRoute1);
                    }
                }
            }
            if (closesedConnection != null) {
                route = closesedConnection.getValue2();
            }
        }
        if (route != null) {
            if (duct instanceof ILPTEInformation && ((ILPTEInformation) duct).getObject() != null) {
                ((ILPTEInformation) duct).getObject().getCacheHolder().setCache(CacheTypes.Routing, key, route);
            }
            TravelingItem travelItem = new TravelingItem(item.getItemIdentifierStack().makeNormalStack(), duct, route.copy(), (byte) serverItem.output.ordinal(), (byte) 1);
            travelItem.lpRoutingInformation = serverItem.getInfo();
            duct.insertNewItem(travelItem);
            return true;
        }
    } else {
        return true;
    }
    return false;
}
Also used : ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) Triplet(logisticspipes.utils.tuples.Triplet) ArrayList(java.util.ArrayList) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRouter(logisticspipes.routing.IRouter) TravelingItem(cofh.thermaldynamics.duct.item.TravelingItem) LPTravelingItem(logisticspipes.transport.LPTravelingItem) RouteCache(cofh.thermaldynamics.multiblock.RouteCache) Route(cofh.thermaldynamics.multiblock.Route) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 5 with ILPTEInformation

use of logisticspipes.asm.te.ILPTEInformation in project LogisticsPipes by RS485.

the class ServerRouter method update.

@Override
public void update(boolean doFullRefresh, CoreRoutedPipe pipe) {
    if (connectionNeedsChecking == 2) {
        Info info = null;
        if (LPConstants.DEBUG) {
            info = StackTraceUtil.addTraceInformation(causedBy.toString());
        }
        boolean blockNeedsUpdate = checkAdjacentUpdate();
        if (blockNeedsUpdate) {
            updateLsa();
        }
        if (LPConstants.DEBUG) {
            info.end();
        }
    }
    if (connectionNeedsChecking == 1) {
        connectionNeedsChecking = 2;
    }
    handleQueuedTasks(pipe);
    updateInterests();
    if (doFullRefresh) {
        if (pipe.container instanceof ILPTEInformation && ((ILPTEInformation) pipe.container).getObject() != null) {
            if (!((ILPTEInformation) pipe.container).getObject().changeListeners.contains(localChangeListener)) {
                ((ILPTEInformation) pipe.container).getObject().changeListeners.add(localChangeListener);
            }
        }
        boolean blockNeedsUpdate = checkAdjacentUpdate();
        if (blockNeedsUpdate) {
            //updateAdjacentAndLsa();
            updateLsa();
        }
        ensureRouteTableIsUpToDate(false);
        return;
    }
    if (Configs.MULTI_THREAD_NUMBER > 0) {
        ensureRouteTableIsUpToDate(false);
    }
}
Also used : ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) Info(logisticspipes.utils.StackTraceUtil.Info)

Aggregations

ILPTEInformation (logisticspipes.asm.te.ILPTEInformation)5 ArrayList (java.util.ArrayList)4 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)4 ITileEntityChangeListener (logisticspipes.asm.te.ITileEntityChangeListener)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)2 World (net.minecraft.world.World)2 TravelingItem (cofh.thermaldynamics.duct.item.TravelingItem)1 Route (cofh.thermaldynamics.multiblock.Route)1 RouteCache (cofh.thermaldynamics.multiblock.RouteCache)1 LPTileEntityObject (logisticspipes.asm.te.LPTileEntityObject)1 IRouter (logisticspipes.routing.IRouter)1 LPTravelingItem (logisticspipes.transport.LPTravelingItem)1 LPTravelingItemServer (logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)1 Info (logisticspipes.utils.StackTraceUtil.Info)1 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)1 Triplet (logisticspipes.utils.tuples.Triplet)1