Search in sources :

Example 1 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe in project LogisticsPipes by RS485.

the class LogisticsPowerProviderTileEntity method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    pauseRequesting = false;
    if (!init) {
        if (MainProxy.isClient(getWorld())) {
            LogisticsHUDRenderer.instance().add(this);
        }
        init = true;
    }
    double globalRequest = orders.values().stream().reduce(Double::sum).orElse(0.0);
    if (globalRequest > 0) {
        double fullfillRatio = Math.min(1, Math.min(internalStorage, getMaxProvidePerTick()) / globalRequest);
        if (fullfillRatio > 0) {
            for (Entry<Integer, Double> order : orders.entrySet()) {
                double toSend = order.getValue() * fullfillRatio;
                if (toSend > internalStorage) {
                    toSend = internalStorage;
                }
                IRouter destinationRouter = SimpleServiceLocator.routerManager.getRouter(order.getKey());
                if (destinationRouter != null && destinationRouter.getPipe() != null) {
                    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(this);
                    outerTiles: for (AdjacentTileEntity adjacent : worldCoordinates.getAdjacentTileEntities().collect(Collectors.toList())) {
                        if (adjacent.tileEntity instanceof LogisticsTileGenericPipe) {
                            if (((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof CoreRoutedPipe) {
                                if (((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).stillNeedReplace()) {
                                    continue;
                                }
                                IRouter sourceRouter = ((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getRouter();
                                if (sourceRouter != null) {
                                    outerRouters: for (ExitRoute exit : sourceRouter.getDistanceTo(destinationRouter)) {
                                        if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                                            for (IFilter filter : exit.filters) {
                                                if (filter.blockPower()) {
                                                    continue outerRouters;
                                                }
                                            }
                                            CoreRoutedPipe pipe = sourceRouter.getPipe();
                                            if (pipe != null && pipe.isInitialized()) {
                                                pipe.container.addLaser(adjacent.direction.getOpposite(), 1, getLaserColor(), true, true);
                                            }
                                            sendPowerLaserPackets(sourceRouter, destinationRouter, exit.exitOrientation, exit.exitOrientation != adjacent.direction);
                                            internalStorage -= toSend;
                                            handlePower(destinationRouter.getPipe(), toSend);
                                            break outerTiles;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    orders.clear();
    if (MainProxy.isServer(worldObj)) {
        if (internalStorage != lastUpdateStorage) {
            updateClients();
            lastUpdateStorage = internalStorage;
        }
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ExitRoute(logisticspipes.routing.ExitRoute) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Example 2 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe in project LogisticsPipes by RS485.

the class CoordinatesPacket method getTileOrPipe.

@SuppressWarnings("unchecked")
public </**
	 * Retrieves tileEntity or CoreUnroutedPipe at packet coordinates if any.
	 *
	 * @param world
	 * @param clazz
	 * @return TileEntity
	 */
T> T getTileOrPipe(World world, Class<T> clazz) {
    if (world == null) {
        targetNotFound("World was null");
        return null;
    }
    if (!world.blockExists(getPosX(), getPosY(), getPosZ())) {
        targetNotFound("Couldn't find " + clazz.getName());
        return null;
    }
    final TileEntity tile = world.getTileEntity(getPosX(), getPosY(), getPosZ());
    if (tile != null) {
        if (clazz.isAssignableFrom(tile.getClass())) {
            return (T) tile;
        }
        if (tile instanceof LogisticsTileGenericPipe) {
            if (((LogisticsTileGenericPipe) tile).pipe != null && clazz.isAssignableFrom(((LogisticsTileGenericPipe) tile).pipe.getClass())) {
                return (T) ((LogisticsTileGenericPipe) tile).pipe;
            }
            targetNotFound("Couldn't find " + clazz.getName() + ", found pipe with " + tile.getClass());
            return null;
        }
    } else {
        targetNotFound("Couldn't find " + clazz.getName());
        return null;
    }
    targetNotFound("Couldn't find " + clazz.getName() + ", found " + tile.getClass());
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe)

Example 3 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe in project LogisticsPipes by RS485.

the class RequestChassiOrientationPacket method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    LogisticsTileGenericPipe pipe = this.getPipe(player.worldObj);
    if (pipe == null || !(pipe.pipe instanceof PipeLogisticsChassi)) {
        return;
    }
    MainProxy.sendPacketToPlayer(PacketHandler.getPacket(ChassiOrientationPacket.class).setDir(((PipeLogisticsChassi) pipe.pipe).getPointedOrientation()).setPosX(getPosX()).setPosY(getPosY()).setPosZ(getPosZ()), player);
}
Also used : PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe)

Example 4 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe in project LogisticsPipes by RS485.

the class ProviderPipeIncludePacket method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    final LogisticsTileGenericPipe pipe = this.getPipe(player.worldObj);
    if (pipe == null) {
        return;
    }
    if (!(pipe.pipe instanceof PipeItemsProviderLogistics)) {
        return;
    }
    final PipeItemsProviderLogistics providerPipe = (PipeItemsProviderLogistics) pipe.pipe;
    providerPipe.setFilterExcluded(!providerPipe.isExcludeFilter());
    MainProxy.sendPacketToPlayer(PacketHandler.getPacket(ProviderPipeInclude.class).setInteger(providerPipe.isExcludeFilter() ? 1 : 0).setPosX(getPosX()).setPosY(getPosY()).setPosZ(getPosZ()), player);
}
Also used : LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ProviderPipeInclude(logisticspipes.network.packets.modules.ProviderPipeInclude) PipeItemsProviderLogistics(logisticspipes.pipes.PipeItemsProviderLogistics)

Example 5 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe in project LogisticsPipes by RS485.

the class ProviderPipeInclude method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    final LogisticsTileGenericPipe pipe = this.getPipe(player.worldObj);
    if (pipe == null) {
        return;
    }
    if (!(pipe.pipe instanceof PipeItemsProviderLogistics)) {
        return;
    }
    ((PipeItemsProviderLogistics) pipe.pipe).setFilterExcluded(getInteger() == 1);
    if (FMLClientHandler.instance().getClient().currentScreen instanceof GuiProviderPipe) {
        ((GuiProviderPipe) FMLClientHandler.instance().getClient().currentScreen).refreshInclude();
    }
}
Also used : LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) GuiProviderPipe(logisticspipes.gui.GuiProviderPipe) PipeItemsProviderLogistics(logisticspipes.pipes.PipeItemsProviderLogistics)

Aggregations

LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)115 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)47 TileEntity (net.minecraft.tileentity.TileEntity)45 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)21 EnumFacing (net.minecraft.util.EnumFacing)15 ArrayList (java.util.ArrayList)14 List (java.util.List)12 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)10 BlockPos (net.minecraft.util.math.BlockPos)10 World (net.minecraft.world.World)9 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)9 HashMap (java.util.HashMap)8 LinkedList (java.util.LinkedList)8 PipeBlockRequestTable (logisticspipes.pipes.PipeBlockRequestTable)8 LogisticsPowerJunctionTileEntity (logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity)7 MainProxy (logisticspipes.proxy.MainProxy)7 ExitRoute (logisticspipes.routing.ExitRoute)7 PipeLogisticsChassi (logisticspipes.pipes.PipeLogisticsChassi)6 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)6