diff --git a/src/main/java/net/minecraftforge/fluids/FluidContainerRegistry.java b/src/main/java/net/minecraftforge/fluids/FluidContainerRegistry.java index 779292b2d8..043267c186 100644 --- a/src/main/java/net/minecraftforge/fluids/FluidContainerRegistry.java +++ b/src/main/java/net/minecraftforge/fluids/FluidContainerRegistry.java @@ -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. */