Class FluidContainerRegistry

java.lang.Object
alexiil.mc.lib.attributes.fluid.FluidContainerRegistry

public final class FluidContainerRegistry extends Object
Maps Item instances to empty and full containers. This also handles registering more complex behaviour: for example a custom handler to fill a glass bottle with potions.
  • Method Details

    • mapContainer

      public static void mapContainer(net.minecraft.item.Item empty, net.minecraft.item.Item full, FluidVolume fluid)
      Directly maps a given Item as containing the given fluid, with another Item as the empty container. This is the most simple mapping possible: no NBT is used to store the fluid data, and is bi-directional: you can drain the fluid from the full item to get both the given fluid (and the empty item), and fill the empty item with the same amount of the given fluid to get the full item.
    • registerFillHandler

      public static void registerFillHandler(net.minecraft.item.Item empty, FluidKey fluid, FluidContainerRegistry.FluidFillHandler handler)
      Registers a custom fill handler for the given empty item, which always creates filled ItemStacks with different Items to the original. (In other words, this is single-directional: the filled item must expose GroupedFluidInv separately in order to be drained back to the empty Item).
    • registerFillHandler

      public static void registerFillHandler(net.minecraft.item.Item empty, FluidKey fluid, FluidAmount minimum, FluidAmount capacity, FluidContainerRegistry.FluidFillFunction fn)
      Registers a custom fill handler for the given empty item, which always creates filled ItemStacks with different Items to the original. (In other words, this is single-directional: the filled item must expose GroupedFluidInv separately in order to be drained back to the empty Item).
    • registerFillHandler

      public static void registerFillHandler(net.minecraft.item.Item empty, FluidFilter fluids, boolean isFilterSpecific, FluidContainerRegistry.FluidFillHandler handler)
      Registers a custom fill handler for the given empty item, which always creates filled ItemStacks with different Items to the original. (In other words, this is single-directional: the filled item must expose GroupedFluidInv separately in order to be drained back to the empty Item).
      Parameters:
      empty - The empty item to fill from
      fluids - The filter to test which fluids can be filled using this handler.
      isFilterSpecific - If true then this will take priority over Class based mappings.
      handler -
    • registerFillHandler

      public static void registerFillHandler(net.minecraft.item.Item empty, FluidFilter fluids, boolean isFilterSpecific, FluidAmount minimum, FluidAmount capacity, FluidContainerRegistry.FluidFillFunction fn)
    • registerFillHandler

      public static void registerFillHandler(net.minecraft.item.Item empty, FluidContainerRegistry.FluidFillHandler handler)
      Registers a custom fill handler for the given empty item, which always creates filled ItemStacks with different Items to the original. (In other words, this is single-directional: the filled item must expose GroupedFluidInv separately in order to be drained back to the empty Item).

      This variant applies to every FluidKey.

      Parameters:
      empty -
      handler -
    • registerFillHandler

      public static void registerFillHandler(net.minecraft.item.Item empty, FluidAmount minimum, FluidAmount capacity, FluidContainerRegistry.FluidFillFunction fn)
    • registerFillHandler

      public static void registerFillHandler(net.minecraft.item.Item empty, Class<?> keyClass, boolean matchSubclasses, FluidContainerRegistry.FluidFillHandler handler)
      Registers a custom fill handler for the given empty item, which always creates filled ItemStacks with different Items to the original. (In other words, this is single-directional: the filled item must expose GroupedFluidInv separately in order to be drained back to the empty Item).
      Parameters:
      empty - The empty item to fill from
      keyClass - The base class to test against.
      matchSubclasses - If true then subclasses of the given Class will also be matched.
      handler -
    • getFullContainersFor

      public static Set<net.minecraft.item.Item> getFullContainersFor(FluidKey fluid)
      Retrieves every Item that has been registered with mapContainer(Item, Item, FluidVolume) as a direct container that is full of the specified fluid.
      Returns:
      An unmodifiable view of the set of Items which contain the given FluidKey. (Which also updates as new entries are registered).
    • getEmptyContainers

      public static Set<net.minecraft.item.Item> getEmptyContainers()
      Retrieves every Item that has been registered as an empty container with mapContainer or any of the "register*" methods. (In other words a set of every item that is guaranteed to have a GroupedFluidInv as one of it's attributes).
      Returns:
      An unmodifiable view of the set of every Item which can have fluid filled into them, but are currently empty. (Which also updates as new entries are registered).
    • getFullContainers

      public static Set<net.minecraft.item.Item> getFullContainers()
      Retrieves every Item that has been registered with mapContainer(Item, Item, FluidVolume) as a direct container that is full.
      Returns:
      An unmodifiable view of the set of every Item which contain fluid. (Which also updates as new entries are registered).
    • getContainedFluid

      public static FluidVolume getContainedFluid(net.minecraft.item.Item item)
      Retrieves the FluidVolume contained by the given Item, if the item has been registered directly with mapContainer(Item, Item, FluidVolume). (In other words: this doesn't work for potions or other complex items that store fluid data in NBT).
      Returns:
      A copy of the contained FluidVolume, or an empty FluidVolume if the item hasn't been mapped.