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;
}
}
}
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;
}
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);
}
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);
}
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();
}
}
Aggregations