Record Class WrappedItemFluidContainer

java.lang.Object
java.lang.Record
earth.terrarium.botarium.common.fluid.impl.WrappedItemFluidContainer
Record Components:
stack - The item stack.
container - The wrapped fluid container. Botarium provides a default implementation for this with SimpleFluidContainer.
All Implemented Interfaces:
FluidContainer, ItemFluidContainer, Serializable, Updatable, net.minecraft.world.Clearable

public record WrappedItemFluidContainer(net.minecraft.world.item.ItemStack stack, FluidContainer container) extends Record implements ItemFluidContainer, Updatable
Represents a wrapped fluid container for an item. This class implements the FluidContainer interface and the Updatable interface. It delegates fluid-related operations to the wrapped fluid container, and updates the item when the fluid is changed.
  • Constructor Details

    • WrappedItemFluidContainer

      public WrappedItemFluidContainer(net.minecraft.world.item.ItemStack stack, FluidContainer container)
      Creates an instance of a WrappedItemFluidContainer record class.
      Parameters:
      stack - the value for the stack record component
      container - the value for the container record component
  • Method Details

    • insertFluid

      public long insertFluid(FluidHolder fluid, boolean simulate)
      Description copied from interface: FluidContainer
      Inserts a FluidHolder into the container.
      Specified by:
      insertFluid in interface FluidContainer
      Parameters:
      fluid - The FluidHolder to be inserted into the container.
      simulate - If true, the container will not be modified.
      Returns:
      The amount of fluid that was added to the container.
    • internalInsert

      public long internalInsert(FluidHolder fluids, boolean simulate)
      Description copied from interface: FluidContainer
      An internal version of FluidContainer.insertFluid(FluidHolder, boolean) that is used by mod authors looking to directly interact with their own containers.

      You should not call this method for other mod's containers, instead use FluidContainer.insertFluid(FluidHolder, boolean).

      Specified by:
      internalInsert in interface FluidContainer
    • extractFluid

      public FluidHolder extractFluid(FluidHolder fluid, boolean simulate)
      Description copied from interface: FluidContainer
      Extracts a FluidHolder from the container.
      Specified by:
      extractFluid in interface FluidContainer
      Parameters:
      fluid - The FluidHolder to be extracted from the container.
      simulate - If true, the container will not be modified.
      Returns:
      The FluidHolder that was extracted from the container.
    • internalExtract

      public FluidHolder internalExtract(FluidHolder fluid, boolean simulate)
      Description copied from interface: FluidContainer
      An internal version of FluidContainer.extractFluid(FluidHolder, boolean) that is used by mod authors looking to directly interact with their own containers.

      You should not call this method for other mod's containers, instead use FluidContainer.extractFluid(FluidHolder, boolean).

      Specified by:
      internalExtract in interface FluidContainer
    • setFluid

      public void setFluid(int slot, FluidHolder fluid)
      Description copied from interface: FluidContainer
      Sets a given FluidHolder to a slot in the container.
      Specified by:
      setFluid in interface FluidContainer
      Parameters:
      slot - The slot to set the fluid in.
      fluid - The FluidHolder to set in the slot.
    • getFluids

      public List<FluidHolder> getFluids()
      Specified by:
      getFluids in interface FluidContainer
      Returns:
      A List of FluidHolder in the container.
    • getSize

      public int getSize()
      Specified by:
      getSize in interface FluidContainer
      Returns:
      The amount of slots in the container.
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface FluidContainer
      Returns:
      Weather or not the container is empty.
    • copy

      public FluidContainer copy()
      Specified by:
      copy in interface FluidContainer
      Returns:
      A copy of the container.
    • getTankCapacity

      public long getTankCapacity(int tankSlot)
      Specified by:
      getTankCapacity in interface FluidContainer
      Parameters:
      tankSlot - The slot to get the capacity of.
      Returns:
      The capacity of the given slot.
    • fromContainer

      public void fromContainer(FluidContainer container)
      Description copied from interface: FluidContainer
      Sets the container to the same values as the given container.
      Specified by:
      fromContainer in interface FluidContainer
      Parameters:
      container - The container to copy the fluids from.
    • extractFromSlot

      public long extractFromSlot(FluidHolder fluidHolder, FluidHolder toInsert, Runnable snapshot)
      Description copied from interface: FluidContainer
      Extracts a fluid from one FluidHolder into another.
      Specified by:
      extractFromSlot in interface FluidContainer
      Parameters:
      fluidHolder - The FluidHolder to extract from.
      toInsert - The FluidHolder to insert into. With amount clamped between 0-fluid.getFluidAmount().
      snapshot - A runnable that will be called before the extraction happens.
      Returns:
      The amount of fluid that was extracted.
    • allowsInsertion

      public boolean allowsInsertion()
      Specified by:
      allowsInsertion in interface FluidContainer
      Returns:
      Weather can be inserted into.
    • allowsExtraction

      public boolean allowsExtraction()
      Specified by:
      allowsExtraction in interface FluidContainer
      Returns:
      Weather can be extracted from.
    • createSnapshot

      public FluidSnapshot createSnapshot()
      Specified by:
      createSnapshot in interface FluidContainer
      Returns:
      A FluidSnapshot of the given state of the FluidContainer.
    • readSnapshot

      public void readSnapshot(FluidSnapshot snapshot)
      Description copied from interface: FluidContainer
      Sets the FluidContainer with the given state of FluidSnapshot.
      Specified by:
      readSnapshot in interface FluidContainer
      Parameters:
      snapshot - The FluidSnapshot to set the FluidContainer to.
    • isFluidValid

      public boolean isFluidValid(int slot, FluidHolder fluidHolder)
      Specified by:
      isFluidValid in interface FluidContainer
      fluidHolder - The FluidHolder to check if can be inserted into.
      Returns:
      Weather the given FluidHolder can be inserted into.
    • getContainerItem

      public net.minecraft.world.item.ItemStack getContainerItem()
      Specified by:
      getContainerItem in interface ItemFluidContainer
      Returns:
      The ItemStack that is used as container item for this fluid container.
    • deserialize

      public void deserialize(net.minecraft.nbt.CompoundTag nbt)
      Description copied from interface: Serializable
      Deserializes the information of an object from a CompoundTag.
      Specified by:
      deserialize in interface Serializable
      Parameters:
      nbt - The CompoundTag to deserialize from.
    • serialize

      public net.minecraft.nbt.CompoundTag serialize(net.minecraft.nbt.CompoundTag nbt)
      Description copied from interface: Serializable
      Serializes the information of an object to a CompoundTag.
      Specified by:
      serialize in interface Serializable
      Parameters:
      nbt - The CompoundTag to serialize to.
      Returns:
      The CompoundTag that was passed in but with the information of the object serialized added to it.
    • update

      public void update()
      Description copied from interface: Updatable
      Called when the operation has been completed and the data has been updated.
      Specified by:
      update in interface Updatable
    • clearContent

      public void clearContent()
      Specified by:
      clearContent in interface net.minecraft.world.Clearable
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • stack

      public net.minecraft.world.item.ItemStack stack()
      Returns the value of the stack record component.
      Returns:
      the value of the stack record component
    • container

      public FluidContainer container()
      Returns the value of the container record component.
      Returns:
      the value of the container record component