Search in sources :

Example 1 with SmartFluidTank

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;
}
Also used : CreativeSmartFluidTank(com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) CreativeSmartFluidTank(com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank) SmartFluidTank(com.simibubi.create.foundation.fluid.SmartFluidTank)

Example 2 with SmartFluidTank

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);
}
Also used : SmartFluidTankBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour) SmartFluidTank(com.simibubi.create.foundation.fluid.SmartFluidTank)

Example 3 with SmartFluidTank

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());
}
Also used : CreativeSmartFluidTank(com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) CreativeSmartFluidTank(com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank) SmartFluidTank(com.simibubi.create.foundation.fluid.SmartFluidTank)

Example 4 with SmartFluidTank

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);
}
Also used : InterpolatedChasingValue(com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue) CreativeFluidTankTileEntity(com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity) FluidTankTileEntity(com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity) IFluidTank(net.minecraftforge.fluids.IFluidTank) CreativeSmartFluidTank(com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank) SmartFluidTank(com.simibubi.create.foundation.fluid.SmartFluidTank)

Example 5 with SmartFluidTank

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;
}
Also used : IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) CreativeSmartFluidTank(com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank) SmartFluidTank(com.simibubi.create.foundation.fluid.SmartFluidTank)

Aggregations

SmartFluidTank (com.simibubi.create.foundation.fluid.SmartFluidTank)5 CreativeSmartFluidTank (com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank)4 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)2 CreativeFluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity)1 FluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity)1 SmartFluidTankBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour)1 InterpolatedChasingValue (com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidTank (net.minecraftforge.fluids.IFluidTank)1