Interface Convertible

All Known Subinterfaces:
FixedFluidInv, FixedFluidInvView, FixedItemInv, FixedItemInv.CopyingFixedItemInv, FixedItemInv.ModifiableFixedItemInv, FixedItemInvView, LimitedFixedFluidInv, LimitedFixedItemInv
All Known Implementing Classes:
AbstractPartialFixedFluidInvView, AbstractPartialFixedItemInvView, CombinedFixedFluidInv, CombinedFixedFluidInvView, CombinedFixedItemInv, CombinedFixedItemInv.OfCopying, CombinedFixedItemInv.OfModifiable, CombinedFixedItemInvView, DelegatingFixedFluidInv, DelegatingFixedItemInv, DelegatingFixedItemInv.OfCopying, DelegatingFixedItemInv.OfModifiable, DirectFixedItemInv, EmptyFixedFluidInv, EmptyFixedItemInv, FixedInventoryVanillaWrapper, FixedInventoryViewVanillaWrapper, FixedSidedInventoryVanillaWrapper, FullFixedItemInv, JumboFixedFluidInv, MappedFixedFluidInv, MappedFixedFluidInvView, MappedFixedItemInv, MappedFixedItemInv.OfCopying, MappedFixedItemInv.OfModifiable, MappedFixedItemInvView, SimpleFixedFluidInv, SimpleFixedItemInv, SimpleLimitedFixedFluidInv, SimpleLimitedFixedItemInv, SimpleLimitedFixedItemInv.OfCopying, SimpleLimitedFixedItemInv.OfModifiable, SlotFixedItemInv, SubFixedFluidInv, SubFixedFluidInvView, SubFixedItemInv, SubFixedItemInv.OfCopying, SubFixedItemInv.OfModifiable, SubFixedItemInvView

public interface Convertible
Simple interface for converting this object into another Class. It is always a good idea to check to see if this object is an instance of the desired class before calling convertTo(Class), because it is not required that it return itself.

It is highly recommended that all objects which can be converted to are both documented in the class header, and exposed through a public "getter" method.

It is generally intended that converted instances (which do not just extend the base type, but instead convert to a completely different type) implement OpenWrapper to return this object.
For example FixedItemInv can be converted to GroupedItemInv (by default returning a GroupedItemInvFixedWrapper) which returns the original FixedItemInv from OpenWrapper.getWrapped().

  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    convertTo(Class<T> otherType)
    Attempts to provide a variant of this in the given class form.
    static <T> T
    getAs(Object obj, Class<T> clazz)
    Helper method for testing if the object is already an instance of the given class (if so returning it immediately), or if it is an instance of Convertible (if so returning convertTo(Class)), otherwise returning null.
    static <T> T
    offer(Class<T> clazz, Object obj)
    A helper method for convertTo(Class) to quickly write implementations that only return a single other object
    static <T> T
    offer(Class<T> clazz, Object... objects)
    A helper method for convertTo(Class) to quickly write implementations that return any of a few predefined objects.
  • Method Details

    • convertTo

      @Nullable <T> T convertTo(Class<T> otherType)
      Attempts to provide a variant of this in the given class form. This does not have to return "this" object if this is already an instance of the given class.

      Note: In order to be typesafe (and prevent crashes) it is recommended that you return Class.cast(Object) with the object you wish to return rather than just blindly cast to "T".

    • offer

      @Nullable static <T> T offer(Class<T> clazz, Object obj)
      A helper method for convertTo(Class) to quickly write implementations that only return a single other object
    • offer

      @Nullable static <T> T offer(Class<T> clazz, Object... objects)
      A helper method for convertTo(Class) to quickly write implementations that return any of a few predefined objects.
    • getAs

      @Nullable static <T> T getAs(Object obj, Class<T> clazz)
      Helper method for testing if the object is already an instance of the given class (if so returning it immediately), or if it is an instance of Convertible (if so returning convertTo(Class)), otherwise returning null.