use of org.spongepowered.api.extra.fluid.FluidStackSnapshot in project SpongeForge by SpongePowered.
the class ForgeFluidTankDataProcessor method set.
@Override
protected boolean set(TileEntity dataHolder, Map<Direction, List<FluidStackSnapshot>> value) {
for (EnumFacing enumFacing : EnumFacing.values()) {
final Direction direction = DirectionFacingProvider.getInstance().getKey(enumFacing).orElseThrow(() -> new IllegalArgumentException("Invalid EnumFacing: " + enumFacing));
if (dataHolder.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, enumFacing)) {
final IFluidHandler handler = dataHolder.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, enumFacing);
final IFluidTankProperties[] oldInfo = handler.getTankProperties();
if (oldInfo != null) {
for (IFluidTankProperties old : oldInfo) {
if (old != null && old.getContents() != null) {
handler.drain(old.getContents(), true);
}
}
}
for (FluidStackSnapshot snapshot : value.get(direction)) {
handler.fill(((net.minecraftforge.fluids.FluidStack) snapshot.createStack()), true);
}
}
}
return true;
}
use of org.spongepowered.api.extra.fluid.FluidStackSnapshot in project SpongeForge by SpongePowered.
the class ForgeFluidTankDataProcessor method getVal.
@Override
protected Optional<Map<Direction, List<FluidStackSnapshot>>> getVal(TileEntity dataHolder) {
Map<Direction, List<FluidStackSnapshot>> map = new HashMap<>();
for (EnumFacing facing : EnumFacing.values()) {
final Direction direction = DirectionFacingProvider.getInstance().getKey(facing).get();
if (dataHolder.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) {
final IFluidHandler handler = dataHolder.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing);
final IFluidTankProperties[] tankProperties = handler.getTankProperties();
if (tankProperties != null) {
ImmutableList.Builder<FluidStackSnapshot> snapshotBuilder = ImmutableList.builder();
for (IFluidTankProperties info : tankProperties) {
if (info != null && info.getContents() != null) {
final FluidStack drained = (FluidStack) handler.drain(info.getContents(), false);
if (drained != null) {
snapshotBuilder.add(drained.createSnapshot());
}
}
}
map.put(direction, snapshotBuilder.build());
}
}
}
return Optional.of(map);
}
Aggregations