use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class PipeFluidProvider method getAvailableFluids.
@Override
public Map<FluidIdentifier, Integer> getAvailableFluids() {
Map<FluidIdentifier, Integer> map = new HashMap<>();
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
boolean fallback = true;
if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
if (handler instanceof ISpecialTankAccessHandler) {
fallback = false;
Map<FluidIdentifier, Long> tmp = ((ISpecialTankAccessHandler) handler).getAvailableLiquid(pair.getValue1());
for (Entry<FluidIdentifier, Long> entry : tmp.entrySet()) {
if (map.containsKey(entry.getKey())) {
long addition = ((long) map.get(entry.getKey())) + entry.getValue();
map.put(entry.getKey(), addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
} else {
map.put(entry.getKey(), entry.getValue() > Integer.MAX_VALUE ? Integer.MAX_VALUE : entry.getValue().intValue());
}
}
}
}
if (fallback) {
FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
if (tanks != null) {
for (FluidTankInfo tank : tanks) {
if (tank == null) {
continue;
}
FluidStack liquid;
if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
FluidIdentifier ident = FluidIdentifier.get(liquid);
if (((IFluidHandler) pair.getValue1()).canDrain(pair.getValue2().getOpposite(), liquid.getFluid())) {
if (((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), 1, false) != null) {
if (map.containsKey(ident)) {
long addition = ((long) map.get(ident)) + tank.fluid.amount;
map.put(ident, addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
} else {
map.put(ident, tank.fluid.amount);
}
}
}
}
}
}
}
}
Map<FluidIdentifier, Integer> result = new HashMap<>();
//Reduce what has been reserved, add.
for (Entry<FluidIdentifier, Integer> fluid : map.entrySet()) {
int remaining = fluid.getValue() - getFluidOrderManager().totalFluidsCountInOrders(fluid.getKey());
if (remaining < 1) {
continue;
}
result.put(fluid.getKey(), remaining);
}
return result;
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class PipeItemsInvSysConnector method inventoryConnected.
private boolean inventoryConnected() {
for (int i = 0; i < 6; i++) {
ForgeDirection dir = ForgeDirection.values()[i];
DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(this), dir);
TileEntity tile = p.getTileEntity(getWorld());
if (tile instanceof IInventory && this.container.canPipeConnect(tile, dir)) {
return true;
}
}
return false;
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class LPBCTileGenericPipe method updateEntity_LP.
@Override
@SneakyThrows({ NoSuchFieldException.class, SecurityException.class, IllegalArgumentException.class, IllegalAccessException.class, NoSuchMethodException.class, InvocationTargetException.class })
public void updateEntity_LP() {
//Make sure we still have the same TE values
xCoord = lpPipe.xCoord;
yCoord = lpPipe.yCoord;
zCoord = lpPipe.zCoord;
if (attachPluggables) {
attachPluggables = false;
// Attach callback
PipePluggable[] pluggables = ReflectionHelper.getPrivateField(PipePluggable[].class, SideProperties.class, "pluggables", sideProperties);
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
if (pluggables[i] != null) {
pipe.eventBus.registerHandler(pluggables[i]);
pluggables[i].onAttachedPipe(this, ForgeDirection.getOrientation(i));
}
}
notifyBlockChanged();
}
if (!BlockGenericPipe.isValid(pipe)) {
return;
}
pipe.updateEntity();
boolean recheckThisPipe = false;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
PipePluggable p = getPipePluggable(direction);
if (p != null) {
p.update(this, direction);
//Check Gate for ActionChanges
if (p instanceof GatePluggable && lpPipe.isRoutingPipe()) {
if (!activeActions.containsKey(direction)) {
activeActions.put(direction, new ArrayList<>());
}
if (!listEquals(activeActions.get(direction), pipe.gates[direction.ordinal()].activeActions)) {
activeActions.get(direction).clear();
activeActions.get(direction).addAll(pipe.gates[direction.ordinal()].activeActions);
lpPipe.getRoutingPipe().triggerConnectionCheck();
recheckThisPipe = true;
}
} else if (activeActions.containsKey(direction)) {
activeActions.remove(direction);
}
if (p instanceof RobotStationPluggable) {
if (((RobotStationPluggable) p).getStation() != null && ((RobotStationPluggable) p).getStation().robotTaking() != null && ((RobotStationPluggable) p).getStation().robotTaking().getBoard() instanceof LogisticsRoutingBoardRobot) {
((RobotStationPluggable) p).getStation().robotTaking().getBoard().cycle();
}
}
}
}
if (recheckThisPipe) {
LPRobotConnectionControl.instance.checkAll(worldObj);
}
if (worldObj.isRemote) {
if (resyncGateExpansions) {
ReflectionHelper.invokePrivateMethod(Object.class, TileGenericPipe.class, this, "syncGateExpansions", new Class[] {}, new Object[] {});
}
return;
}
if (blockNeighborChange) {
//ReflectionHelper.invokePrivateMethod(Object.class, TileGenericPipe.class, this, "computeConnections", new Class[]{}, new Object[]{});
pipe.onNeighborBlockChange(0);
blockNeighborChange = false;
refreshRenderState = true;
}
if (refreshRenderState) {
refreshRenderState();
refreshRenderState = false;
}
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class EnderIOHyperCubeConnection method getConnections.
@Override
public List<TileEntity> getConnections(TileEntity tile) {
boolean onlyOnePipe = false;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(tile), direction);
TileEntity canidate = p.getTileEntity(tile.getWorldObj());
if (canidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(tile, canidate, direction)) {
if (onlyOnePipe) {
onlyOnePipe = false;
break;
} else {
onlyOnePipe = true;
}
}
}
if (!onlyOnePipe || !SimpleServiceLocator.enderIOProxy.isSendAndReceive(tile)) {
return new ArrayList<>(0);
}
List<? extends TileEntity> connections = SimpleServiceLocator.enderIOProxy.getConnectedHyperCubes(tile);
List<TileEntity> list = new ArrayList<>();
for (TileEntity connected : connections) {
if (!SimpleServiceLocator.enderIOProxy.isSendAndReceive(connected)) {
continue;
}
LogisticsTileGenericPipe pipe = null;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(connected), direction);
TileEntity canidate = p.getTileEntity(tile.getWorldObj());
if (canidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(connected, canidate, direction)) {
if (pipe != null) {
pipe = null;
break;
} else {
pipe = (LogisticsTileGenericPipe) canidate;
}
}
}
if (pipe != null && pipe.pipe instanceof CoreRoutedPipe) {
list.add(pipe);
}
}
if (list.size() == 1) {
return list;
} else {
return new ArrayList<>(0);
}
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class ItemAmountPipeSign method spread.
private void spread(Map<ItemIdentifier, Integer> availableItems, BitSet set) {
// Improve performance by updating a wall of Amount pipe signs all at once
IRouter router = pipe.getRouter();
if (set.get(router.getSimpleID()))
return;
set.set(router.getSimpleID());
for (ExitRoute exit : router.getIRoutersByCost()) {
// Only when the signs are in one wall. To not spread to far.
if (exit.distanceToDestination > 2)
break;
if (!exit.filters.isEmpty())
continue;
if (set.get(exit.destination.getSimpleID()))
continue;
if (exit.connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && exit.connectionDetails.contains(PipeRoutingConnectionType.canRouteTo)) {
CoreRoutedPipe cachedPipe = exit.destination.getCachedPipe();
if (cachedPipe != null) {
List<Pair<ForgeDirection, IPipeSign>> pipeSigns = cachedPipe.getPipeSigns();
pipeSigns.stream().filter(signPair -> signPair != null && signPair.getValue2() instanceof ItemAmountPipeSign).forEach(signPair -> ((ItemAmountPipeSign) signPair.getValue2()).updateStats(availableItems, set));
}
}
}
}
Aggregations