Search in sources :

Example 1 with LongFluidStack

use of com.cjm721.overloaded.storage.LongFluidStack in project Overloaded by CJ-MC-Mods.

the class LongFluidStorage method drain.

/**
     * Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
     *
     * @param resource FluidStack representing the Fluid and maximum amount of fluid to be drained.
     * @param doDrain  If false, drain will only be simulated.
     * @return FluidStack representing the Fluid and amount that was (or would have been, if
     * simulated) drained.
     */
@Nullable
@Override
public FluidStack drain(@Nonnull FluidStack resource, boolean doDrain) {
    LongFluidStack result = take(new LongFluidStack(resource, resource.amount), doDrain);
    if (result.amount == 0L) {
        return null;
    }
    FluidStack toReturn = resource.copy();
    toReturn.amount = (int) result.amount;
    return toReturn;
}
Also used : LongFluidStack(com.cjm721.overloaded.storage.LongFluidStack) LongFluidStack(com.cjm721.overloaded.storage.LongFluidStack) FluidStack(net.minecraftforge.fluids.FluidStack) Nullable(javax.annotation.Nullable)

Example 2 with LongFluidStack

use of com.cjm721.overloaded.storage.LongFluidStack in project Overloaded by CJ-MC-Mods.

the class LongFluidStorage method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound compound) {
    FluidStack fluidStack = compound.hasKey("Fluid") ? FluidStack.loadFluidStackFromNBT(compound.getCompoundTag("Fluid")) : null;
    long amount = compound.hasKey("Count") ? compound.getLong("Count") : 0L;
    this.storedFluid = new LongFluidStack(fluidStack, amount);
}
Also used : LongFluidStack(com.cjm721.overloaded.storage.LongFluidStack) LongFluidStack(com.cjm721.overloaded.storage.LongFluidStack) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 3 with LongFluidStack

use of com.cjm721.overloaded.storage.LongFluidStack in project Overloaded by CJ-MC-Mods.

the class LongFluidStorage method drain.

/**
     * Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
     * <p/>
     * This method is not Fluid-sensitive.
     *
     * @param maxDrain Maximum amount of fluid to drain.
     * @param doDrain  If false, drain will only be simulated.
     * @return FluidStack representing the Fluid and amount that was (or would have been, if
     * simulated) drained.
     */
@Nullable
@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
    LongFluidStack result = take(new LongFluidStack(null, maxDrain), doDrain);
    if (result.amount == 0L) {
        return null;
    }
    FluidStack toReturn = result.fluidStack.copy();
    toReturn.amount = (int) result.amount;
    return toReturn;
}
Also used : LongFluidStack(com.cjm721.overloaded.storage.LongFluidStack) LongFluidStack(com.cjm721.overloaded.storage.LongFluidStack) FluidStack(net.minecraftforge.fluids.FluidStack) Nullable(javax.annotation.Nullable)

Example 4 with LongFluidStack

use of com.cjm721.overloaded.storage.LongFluidStack in project Overloaded by CJ-MC-Mods.

the class BlockInfiniteTank method onBlockActivated.

@Override
public boolean onBlockActivated(@Nonnull World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        ItemStack heldItem = playerIn.getHeldItem(hand);
        if (heldItem.isEmpty() && hand == EnumHand.MAIN_HAND) {
            LongFluidStack storedFluid = ((TileInfiniteTank) worldIn.getTileEntity(pos)).getStorage().getFluidStack();
            if (storedFluid == null || storedFluid.fluidStack == null) {
                playerIn.sendStatusMessage(new TextComponentString("Fluid: EMPTY"), false);
            } else {
                playerIn.sendStatusMessage(new TextComponentString(String.format("Fluid: %s Amount %,d", storedFluid.fluidStack.getLocalizedName(), storedFluid.amount)), false);
            }
        } else {
            TileEntity te = worldIn.getTileEntity(pos);
            if (te != null && te instanceof TileInfiniteTank) {
                IFluidHandler handler = te.getCapability(FLUID_HANDLER_CAPABILITY, side);
                // FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), te.getCapability(FLUID_HANDLER_CAPABILITY, facing), playerIn);
                FluidActionResult result = FluidUtil.interactWithFluidHandler(heldItem, handler, playerIn);
                if (result.isSuccess())
                    playerIn.setHeldItem(hand, result.getResult());
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LongFluidStack(com.cjm721.overloaded.storage.LongFluidStack) TileInfiniteTank(com.cjm721.overloaded.block.tile.infinity.TileInfiniteTank) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

LongFluidStack (com.cjm721.overloaded.storage.LongFluidStack)4 FluidStack (net.minecraftforge.fluids.FluidStack)3 Nullable (javax.annotation.Nullable)2 TileInfiniteTank (com.cjm721.overloaded.block.tile.infinity.TileInfiniteTank)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1