Search in sources :

Example 1 with LPTileEntityObject

use of logisticspipes.asm.te.LPTileEntityObject 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)

Aggregations

ArrayList (java.util.ArrayList)1 ILPTEInformation (logisticspipes.asm.te.ILPTEInformation)1 ITileEntityChangeListener (logisticspipes.asm.te.ITileEntityChangeListener)1 LPTileEntityObject (logisticspipes.asm.te.LPTileEntityObject)1 TileEntity (net.minecraft.tileentity.TileEntity)1 World (net.minecraft.world.World)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)1