use of logisticspipes.utils.FluidIdentifier in project LogisticsPipes by RS485.
the class ModuleCrafter method addCrafting.
@Override
public ICraftingTemplate addCrafting(IResource toCraft) {
List<ItemIdentifierStack> stack = getCraftedItems();
if (stack == null) {
return null;
}
IReqCraftingTemplate template = null;
if (this.getUpgradeManager().isFuzzyUpgrade() && outputFuzzyFlags.getBitSet().nextSetBit(0) != -1) {
if (toCraft instanceof DictResource) {
for (ItemIdentifierStack craftable : stack) {
DictResource dict = new DictResource(craftable, null);
dict.loadFromBitSet(outputFuzzyFlags.getBitSet());
if (toCraft.matches(craftable.getItem(), IResource.MatchSettings.NORMAL) && dict.matches(((DictResource) toCraft).getItem(), IResource.MatchSettings.NORMAL) && dict.getBitSet().equals(((DictResource) toCraft).getBitSet())) {
template = new DictCraftingTemplate(dict, this, priority);
break;
}
}
}
} else {
for (ItemIdentifierStack craftable : stack) {
if (toCraft.matches(craftable.getItem(), IResource.MatchSettings.NORMAL)) {
template = new ItemCraftingTemplate(craftable, this, priority);
break;
}
}
}
if (template == null) {
return null;
}
IRequestItems[] target = new IRequestItems[9];
for (int i = 0; i < 9; i++) {
target[i] = this;
}
boolean hasSatellite = isSatelliteConnected();
if (!hasSatellite) {
return null;
}
if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
if (satelliteId != 0) {
IRouter r = getSatelliteRouter(-1);
if (r != null) {
IRequestItems sat = r.getPipe();
for (int i = 6; i < 9; i++) {
target[i] = sat;
}
}
}
} else {
for (int i = 0; i < 9; i++) {
if (advancedSatelliteIdArray[i] != 0) {
IRouter r = getSatelliteRouter(i);
if (r != null) {
target[i] = r.getPipe();
}
}
}
}
//Check all materials
for (int i = 0; i < 9; i++) {
ItemIdentifierStack resourceStack = getMaterials(i);
if (resourceStack == null || resourceStack.getStackSize() == 0) {
continue;
}
IResource req = null;
if (getUpgradeManager().isFuzzyUpgrade() && fuzzyCraftingFlagArray[i].getBitSet().nextSetBit(0) != -1) {
DictResource dict;
req = dict = new DictResource(resourceStack, target[i]);
dict.loadFromBitSet(fuzzyCraftingFlagArray[i].getBitSet());
} else {
req = new ItemResource(resourceStack, target[i]);
}
template.addRequirement(req, new CraftingChassieInformation(i, getPositionInt()));
}
int liquidCrafter = getUpgradeManager().getFluidCrafter();
IRequestFluid[] liquidTarget = new IRequestFluid[liquidCrafter];
if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
if (liquidSatelliteId != 0) {
IRouter r = getFluidSatelliteRouter(-1);
if (r != null) {
IRequestFluid sat = (IRequestFluid) r.getPipe();
for (int i = 0; i < liquidCrafter; i++) {
liquidTarget[i] = sat;
}
}
}
} else {
for (int i = 0; i < liquidCrafter; i++) {
if (liquidSatelliteIdArray[i] != 0) {
IRouter r = getFluidSatelliteRouter(i);
if (r != null) {
liquidTarget[i] = (IRequestFluid) r.getPipe();
}
}
}
}
for (int i = 0; i < liquidCrafter; i++) {
FluidIdentifier liquid = getFluidMaterial(i);
int amount = getFluidAmount()[i];
if (liquid == null || amount <= 0 || liquidTarget[i] == null) {
continue;
}
template.addRequirement(new FluidResource(liquid, amount, liquidTarget[i]), null);
}
if (getUpgradeManager().hasByproductExtractor() && getByproductItem() != null) {
template.addByproduct(getByproductItem());
}
return template;
}
use of logisticspipes.utils.FluidIdentifier in project LogisticsPipes by RS485.
the class PipeFluidBasic method sinkAmount.
@Override
public int sinkAmount(FluidStack stack) {
if (!guiOpenedBy.isEmpty()) {
//Don't sink when the gui is open
return 0;
}
FluidIdentifier ident = FluidIdentifier.get(stack);
if (filterInv.getStackInSlot(0) == null) {
return 0;
}
if (!ident.equals(FluidIdentifier.get(filterInv.getIDStackInSlot(0).getItem()))) {
return 0;
}
int onTheWay = this.countOnRoute(ident);
int freeSpace = -onTheWay;
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(true)) {
FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
freeSpace += ident.getFreeSpaceInsideTank((IFluidHandler) pair.getValue1(), pair.getValue2().getOpposite());
freeSpace += ident.getFreeSpaceInsideTank(tank);
if (freeSpace >= stack.amount) {
return stack.amount;
}
}
return freeSpace;
}
use of logisticspipes.utils.FluidIdentifier 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 logisticspipes.utils.FluidIdentifier in project LogisticsPipes by RS485.
the class BuildCraftTankHandler method getAvailableLiquid.
@Override
public Map<FluidIdentifier, Long> getAvailableLiquid(TileEntity tile) {
Map<FluidIdentifier, Long> map = new HashMap<>();
FluidTankInfo[] tanks = ((IFluidHandler) tile).getTankInfo(ForgeDirection.UNKNOWN);
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) tile).drain(ForgeDirection.UNKNOWN, 1, false) != null) {
if (map.containsKey(ident)) {
long addition = map.get(ident) + tank.fluid.amount;
map.put(ident, addition);
} else {
map.put(ident, (long) tank.fluid.amount);
}
}
}
}
return map;
}
use of logisticspipes.utils.FluidIdentifier in project LogisticsPipes by RS485.
the class LogisticsFluidManager method getAvailableFluid.
@Override
public TreeSet<ItemIdentifierStack> getAvailableFluid(List<ExitRoute> validDestinations) {
Map<FluidIdentifier, Integer> allAvailableItems = new HashMap<>();
for (ExitRoute r : validDestinations) {
if (r == null) {
continue;
}
if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
continue;
}
if (!(r.destination.getPipe() instanceof IProvideFluids)) {
continue;
}
IProvideFluids provider = (IProvideFluids) r.destination.getPipe();
Map<FluidIdentifier, Integer> allItems = provider.getAvailableFluids();
for (Entry<FluidIdentifier, Integer> liquid : allItems.entrySet()) {
Integer amount = allAvailableItems.get(liquid.getKey());
if (amount == null) {
allAvailableItems.put(liquid.getKey(), liquid.getValue());
} else {
long addition = ((long) amount) + liquid.getValue();
if (addition > Integer.MAX_VALUE) {
addition = Integer.MAX_VALUE;
}
allAvailableItems.put(liquid.getKey(), (int) addition);
}
}
}
TreeSet<ItemIdentifierStack> itemIdentifierStackList = allAvailableItems.entrySet().stream().map(item -> new ItemIdentifierStack(item.getKey().getItemIdentifier(), item.getValue())).collect(Collectors.toCollection(TreeSet::new));
return itemIdentifierStackList;
}
Aggregations