Search in sources :

Example 1 with FluidStack

use of org.spongepowered.api.extra.fluid.FluidStack in project SpongeForge by SpongePowered.

the class MixinSpongeFluidStackBuilder method build.

@Overwrite
public FluidStack build() {
    checkNotNull(this.fluidType, "Fluidtype cannot be null!");
    checkState(this.volume >= 0, "Volume must be at least zero!");
    @Nullable NBTTagCompound compound = this.extra == null ? null : NbtTranslator.getInstance().translateData(this.extra);
    net.minecraftforge.fluids.FluidStack fluidStack = new net.minecraftforge.fluids.FluidStack((Fluid) this.fluidType, this.volume, compound);
    return (FluidStack) fluidStack;
}
Also used : FluidStack(org.spongepowered.api.extra.fluid.FluidStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Nullable(javax.annotation.Nullable) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with FluidStack

use of org.spongepowered.api.extra.fluid.FluidStack 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);
}
Also used : FluidStackSnapshot(org.spongepowered.api.extra.fluid.FluidStackSnapshot) HashMap(java.util.HashMap) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) ImmutableList(com.google.common.collect.ImmutableList) FluidStack(org.spongepowered.api.extra.fluid.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Direction(org.spongepowered.api.util.Direction) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Aggregations

FluidStack (org.spongepowered.api.extra.fluid.FluidStack)2 ImmutableList (com.google.common.collect.ImmutableList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 EnumFacing (net.minecraft.util.EnumFacing)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1 IFluidTankProperties (net.minecraftforge.fluids.capability.IFluidTankProperties)1 FluidStackSnapshot (org.spongepowered.api.extra.fluid.FluidStackSnapshot)1 Direction (org.spongepowered.api.util.Direction)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1