use of com.simibubi.create.foundation.fluid.SmartFluidTank in project Create by Creators-of-Create.
the class MountedFluidStorage method deserialize.
public static MountedFluidStorage deserialize(CompoundTag nbt) {
MountedFluidStorage storage = new MountedFluidStorage(null);
if (nbt == null)
return storage;
int capacity = nbt.getInt("Capacity");
storage.tank = new SmartFluidTank(capacity, storage::onFluidStackChanged);
storage.valid = true;
if (nbt.contains("Bottomless")) {
FluidStack providedStack = FluidStack.loadFluidStackFromNBT(nbt.getCompound("ProvidedStack"));
CreativeSmartFluidTank creativeSmartFluidTank = new CreativeSmartFluidTank(capacity, $ -> {
});
creativeSmartFluidTank.setContainedFluid(providedStack);
storage.tank = creativeSmartFluidTank;
return storage;
}
storage.tank.readFromNBT(nbt);
return storage;
}
use of com.simibubi.create.foundation.fluid.SmartFluidTank in project Create by Creators-of-Create.
the class ComparatorUtil method levelOfSmartFluidTank.
public static int levelOfSmartFluidTank(BlockGetter world, BlockPos pos) {
SmartFluidTankBehaviour fluidBehaviour = TileEntityBehaviour.get(world, pos, SmartFluidTankBehaviour.TYPE);
if (fluidBehaviour == null)
return 0;
SmartFluidTank primaryHandler = fluidBehaviour.getPrimaryHandler();
double fillFraction = (double) primaryHandler.getFluid().getAmount() / primaryHandler.getCapacity();
return fractionToRedstoneLevel(fillFraction);
}
use of com.simibubi.create.foundation.fluid.SmartFluidTank in project Create by Creators-of-Create.
the class MountedFluidStorage method addStorageToWorld.
public void addStorageToWorld(BlockEntity te) {
if (tank instanceof CreativeSmartFluidTank)
return;
LazyOptional<IFluidHandler> capability = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY);
IFluidHandler teHandler = capability.orElse(null);
if (!(teHandler instanceof SmartFluidTank))
return;
SmartFluidTank inv = (SmartFluidTank) teHandler;
inv.setFluid(tank.getFluid().copy());
}
use of com.simibubi.create.foundation.fluid.SmartFluidTank in project Create by Creators-of-Create.
the class MountedFluidStorage method updateFluid.
public void updateFluid(FluidStack fluid) {
tank.setFluid(fluid);
if (!(te instanceof FluidTankTileEntity))
return;
float fillState = tank.getFluidAmount() / (float) tank.getCapacity();
FluidTankTileEntity tank = (FluidTankTileEntity) te;
if (tank.getFluidLevel() == null)
tank.setFluidLevel(new InterpolatedChasingValue().start(fillState));
tank.getFluidLevel().target(fillState);
IFluidTank tankInventory = tank.getTankInventory();
if (tankInventory instanceof SmartFluidTank)
((SmartFluidTank) tankInventory).setFluid(fluid);
}
use of com.simibubi.create.foundation.fluid.SmartFluidTank in project Create by Creators-of-Create.
the class MountedFluidStorage method removeStorageFromWorld.
public void removeStorageFromWorld() {
valid = false;
if (te == null)
return;
IFluidHandler teHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).orElse(null);
if (!(teHandler instanceof SmartFluidTank))
return;
SmartFluidTank smartTank = (SmartFluidTank) teHandler;
tank.setFluid(smartTank.getFluid());
sendPacket = false;
valid = true;
}
Aggregations