use of net.minecraftforge.fluids.FluidTank in project MinecraftForge by MinecraftForge.
the class CapabilityFluidHandler method register.
public static void register() {
CapabilityManager.INSTANCE.register(IFluidHandler.class, new DefaultFluidHandlerStorage<IFluidHandler>(), new Callable<IFluidHandler>() {
@Override
public IFluidHandler call() throws Exception {
return new FluidTank(Fluid.BUCKET_VOLUME);
}
});
CapabilityManager.INSTANCE.register(IFluidHandlerItem.class, new DefaultFluidHandlerStorage<IFluidHandlerItem>(), new Callable<IFluidHandlerItem>() {
@Override
public IFluidHandlerItem call() throws Exception {
return new FluidHandlerItemStack(new ItemStack(Items.BUCKET), Fluid.BUCKET_VOLUME);
}
});
}
use of net.minecraftforge.fluids.FluidTank in project LogisticsPipes by RS485.
the class PipeFluidSupplierMk2 method throttledUpdateEntity.
@Override
public void throttledUpdateEntity() {
if (!isEnabled()) {
return;
}
if (MainProxy.isClient(container.getWorld())) {
return;
}
super.throttledUpdateEntity();
if (dummyInventory.getStackInSlot(0) == null) {
return;
}
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
//@formatter:off
worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IFluidHandler).filter(adjacent -> SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>((IFluidHandler) adjacent.tileEntity, adjacent.direction)).forEach(fluidHandlerDirectionPair -> {
FluidTankInfo[] tankInfo = fluidHandlerDirectionPair.getValue1().getTankInfo(ForgeDirection.UNKNOWN);
if (tankInfo == null || tankInfo.length == 0) {
return;
}
Map<FluidIdentifier, Integer> wantFluids = new HashMap<>();
FluidIdentifier fIdent = FluidIdentifier.get(dummyInventory.getIDStackInSlot(0).getItem());
wantFluids.put(fIdent, amount);
HashMap<FluidIdentifier, Integer> haveFluids = new HashMap<>();
FluidTankInfo[] result = container.getTankInfo(ForgeDirection.UNKNOWN);
for (FluidTankInfo slot : result) {
if (slot == null || slot.fluid == null || slot.fluid.getFluidID() == 0 || !wantFluids.containsKey(FluidIdentifier.get(slot.fluid))) {
continue;
}
Integer liquidWant = haveFluids.get(FluidIdentifier.get(slot.fluid));
if (liquidWant == null) {
haveFluids.put(FluidIdentifier.get(slot.fluid), slot.fluid.amount);
} else {
haveFluids.put(FluidIdentifier.get(slot.fluid), liquidWant + slot.fluid.amount);
}
}
if (fluidHandlerDirectionPair.getValue2().ordinal() < ((PipeFluidTransportLogistics) transport).sideTanks.length) {
FluidTank centerTank = ((PipeFluidTransportLogistics) transport).sideTanks[fluidHandlerDirectionPair.getValue2().ordinal()];
if (centerTank != null && centerTank.getFluid() != null && wantFluids.containsKey(FluidIdentifier.get(centerTank.getFluid()))) {
Integer liquidWant = haveFluids.get(FluidIdentifier.get(centerTank.getFluid()));
if (liquidWant == null) {
haveFluids.put(FluidIdentifier.get(centerTank.getFluid()), centerTank.getFluid().amount);
} else {
haveFluids.put(FluidIdentifier.get(centerTank.getFluid()), liquidWant + centerTank.getFluid().amount);
}
}
}
FluidTank centerTank = ((PipeFluidTransportLogistics) transport).internalTank;
if (centerTank != null && centerTank.getFluid() != null && wantFluids.containsKey(FluidIdentifier.get(centerTank.getFluid()))) {
Integer liquidWant = haveFluids.get(FluidIdentifier.get(centerTank.getFluid()));
if (liquidWant == null) {
haveFluids.put(FluidIdentifier.get(centerTank.getFluid()), centerTank.getFluid().amount);
} else {
haveFluids.put(FluidIdentifier.get(centerTank.getFluid()), liquidWant + centerTank.getFluid().amount);
}
}
for (Entry<FluidIdentifier, Integer> liquidId : wantFluids.entrySet()) {
Integer haveCount = haveFluids.get(liquidId.getKey());
if (haveCount != null) {
liquidId.setValue(liquidId.getValue() - haveCount);
}
_requestedItems.entrySet().stream().filter(requestedItem -> requestedItem.getKey().equals(liquidId.getKey())).forEach(requestedItem -> liquidId.setValue(liquidId.getValue() - requestedItem.getValue()));
}
setRequestFailed(false);
for (FluidIdentifier need : wantFluids.keySet()) {
int countToRequest = wantFluids.get(need);
if (countToRequest < 1) {
continue;
}
if (_bucketMinimum.getAmount() != 0 && countToRequest < _bucketMinimum.getAmount()) {
continue;
}
if (!useEnergy(11)) {
break;
}
boolean success = false;
if (_requestPartials) {
countToRequest = RequestTree.requestFluidPartial(need, countToRequest, this, null);
if (countToRequest > 0) {
success = true;
}
} else {
success = RequestTree.requestFluid(need, countToRequest, this, null);
}
if (success) {
Integer currentRequest = _requestedItems.get(need);
if (currentRequest == null) {
_requestedItems.put(need, countToRequest);
} else {
_requestedItems.put(need, currentRequest + countToRequest);
}
} else {
setRequestFailed(true);
}
}
});
}
use of net.minecraftforge.fluids.FluidTank in project LogisticsPipes by RS485.
the class FluidRoutedPipe method enabledUpdateEntity.
@Override
public void enabledUpdateEntity() {
super.enabledUpdateEntity();
if (canInsertFromSideToTanks()) {
int validDirections = 0;
List<Pair<TileEntity, ForgeDirection>> list = getAdjacentTanks(true);
for (Pair<TileEntity, ForgeDirection> pair : list) {
if (pair.getValue1() instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) pair.getValue1()).pipe instanceof CoreRoutedPipe) {
continue;
}
}
FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
validDirections++;
if (tank.getFluid() == null) {
continue;
}
int filled = ((IFluidHandler) pair.getValue1()).fill(pair.getValue2().getOpposite(), tank.getFluid().copy(), true);
if (filled == 0) {
continue;
}
FluidStack drain = tank.drain(filled, true);
if (drain == null || filled != drain.amount) {
if (LPConstants.DEBUG) {
throw new UnsupportedOperationException("Fluid Multiplication");
}
}
}
if (validDirections == 0) {
return;
}
FluidTank tank = ((PipeFluidTransportLogistics) transport).internalTank;
FluidStack stack = tank.getFluid();
if (stack == null) {
return;
}
for (Pair<TileEntity, ForgeDirection> pair : list) {
if (pair.getValue1() instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) pair.getValue1()).pipe instanceof CoreRoutedPipe) {
continue;
}
}
FluidTank tankSide = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
stack = tank.getFluid();
if (stack == null) {
continue;
}
stack = stack.copy();
int filled = tankSide.fill(stack, true);
if (filled == 0) {
continue;
}
FluidStack drain = tank.drain(filled, true);
if (drain == null || filled != drain.amount) {
if (LPConstants.DEBUG) {
throw new UnsupportedOperationException("Fluid Multiplication");
}
}
}
}
}
use of net.minecraftforge.fluids.FluidTank in project ImmersiveEngineering by BluSunrize.
the class TileEntityAssembler method consumeItem.
public Optional<ItemStack> consumeItem(Object query, int querySize, ItemStack[] inventory, ArrayList<ItemStack> containerItems) {
FluidStack fs = query instanceof FluidStack ? (FluidStack) query : (query instanceof IngredientStack && ((IngredientStack) query).fluid != null) ? ((IngredientStack) query).fluid : null;
if (fs != null)
for (FluidTank tank : tanks) if (tank.getFluid() != null && tank.getFluid().containsFluid(fs)) {
tank.drain(fs.amount, true);
markDirty();
this.markContainingBlockForUpdate(null);
return Optional.absent();
}
Optional<ItemStack> ret = null;
for (int i = 0; i < inventory.length; i++) if (inventory[i] != null && Utils.stackMatchesObject(inventory[i], query, true)) {
int taken = Math.min(querySize, inventory[i].stackSize);
boolean doTake = true;
if (doTake) {
ret = Optional.of(inventory[i].splitStack(taken));
if (inventory[i].stackSize <= 0)
inventory[i] = null;
}
querySize -= taken;
if (querySize <= 0)
break;
}
if (query == null || querySize <= 0)
return ret;
return null;
}
Aggregations