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;
}
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);
}
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;
}
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;
}
Aggregations