package net.teamio.taam.util;

import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;

/**
 * Creative fluid handler that spawns infinite amounts of a given FluidStack.
 * Does not allow filling.
 * 
 * @author Oliver Kahrmann
 *
 */
public class FluidHandlerCreative implements IFluidHandler {

	public FluidStack template;

	private final IFluidTankProperties[] tankProperties = new IFluidTankProperties[] { new IFluidTankProperties() {

		@Override
		public FluidStack getContents() {
			return template.copy();
		}

		@Override
		public int getCapacity() {
			return 10000;
		}

		@Override
		public boolean canFillFluidType(FluidStack fluidStack) {
			return false;
		}

		@Override
		public boolean canFill() {
			return false;
		}

		@Override
		public boolean canDrainFluidType(FluidStack fluidStack) {
			return fluidStack != null && fluidStack.isFluidEqual(template);
		}

		@Override
		public boolean canDrain() {
			return true;
		}
	} };

	@Override
	public IFluidTankProperties[] getTankProperties() {
		return tankProperties;
	}

	@Override
	public int fill(FluidStack resource, boolean doFill) {
		return 0;
	}

	@Override
	public FluidStack drain(FluidStack resource, boolean doDrain) {
		if (template != null && template.isFluidEqual(resource)) {
			return resource;
		}
		return null;
	}

	@Override
	public FluidStack drain(int maxDrain, boolean doDrain) {
		if (template == null) {
			return null;
		}
		FluidStack cloned = template.copy();
		cloned.amount = maxDrain;
		return cloned;
	}

}
@@ -310,10 +310,9 @@
 .%0A *
- 
 %0A
+
  * @
@@ -334,19 +334,16 @@
 ahrmann%0A
- *%0A
  */%0Apubl
@@ -515,11 +515,9 @@
 es%5B%5D
- %7B 
+%7B
 new 
@@ -586,24 +586,62 @@
 ontents() %7B%0A
+%09%09%09if (template == null) return null;%0A
 %09%09%09return te
@@ -1087,17 +1087,16 @@
 ;%0A%09%09%7D%0A%09%7D
- 
 %7D;%0A%0A%09@Ov
@@ -1650,9 +1650,10 @@
 ed;%0A%09%7D%0A%0A
-
 %7D
+%0A

Fix NPE in FluidHandlerCreative (fixes #268)