- Added drainFluidContainer() and getContainerCapacity() helper methods.

This commit is contained in:
zarathul 2014-07-29 23:16:32 +02:00
parent 7170a8c4c6
commit 7a1de8c13d

View file

@ -226,6 +226,81 @@ public abstract class FluidContainerRegistry
return null;
}
/**
* Attempts to empty a full container.
*
* @param container
* ItemStack representing the full container.
* @return Empty container if successful, otherwise null.
*/
public static ItemStack drainFluidContainer(ItemStack container)
{
if (container == null)
{
return null;
}
FluidContainerData data = containerFluidMap.get(new ContainerKey(container));
if (data != null)
{
return data.emptyContainer.copy();
}
return null;
}
/**
* Determines the capacity of a full container.
*
* @param container
* The full container.
* @return The containers capacity, or 0 if the ItemStack does not represent
* a registered container.
*/
public static int getContainerCapacity(ItemStack container)
{
return getContainerCapacity(null, container);
}
/**
* Determines the capacity of a container.
*
* @param fluid
* FluidStack containing the type of fluid the capacity should be
* determined for (ignored for full containers).
* @param container
* The container (full or empty).
* @return The containers capacity, or 0 if the ItemStack does not represent
* a registered container or the FluidStack is not registered with
* the empty container.
*/
public static int getContainerCapacity(FluidStack fluid, ItemStack container)
{
if (container == null)
{
return 0;
}
FluidContainerData data = containerFluidMap.get(new ContainerKey(container));
if (data != null)
{
return data.fluid.amount;
}
if (fluid != null)
{
data = filledContainerMap.get(new ContainerKey(container, fluid));
if (data != null)
{
return data.fluid.amount;
}
}
return 0;
}
/**
* Determines if a container holds a specific fluid.
*/