Search in sources :

Example 1 with ITileEntityChangeListener

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

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

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

Aggregations

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