Interface MapBuilder<Type>

Type Parameters:
Type - the type to encode.
All Superinterfaces:
Function<MapHasher<Type>,MapHasher<Type>>, UnaryOperator<MapHasher<Type>>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface MapBuilder<Type> extends UnaryOperator<MapHasher<Type>>
MapBuilders can be used to define map-like structures to encode a MapBuilder using a MapHasher.
  • Method Details

    • cast

      default <Casted> MapBuilder<Casted> cast()
      Casts this map builder to a MapBuilder. This cast is done unsafely, only use this if you are sure the object being encoded is of the type being cast to!
      Type Parameters:
      Casted - the type to cast to.
    • unit

      static <Type> MapBuilder<Type> unit()
      Returns a map builder that doesn't contain anything.
      Type Parameters:
      Type - the type to encode.
    • dispatch

      static <Type, Dispatched> MapBuilder<Dispatched> dispatch(MinecraftHasher<Type> typeHasher, Function<Dispatched,Type> typeExtractor, Function<Type,MapBuilder<Dispatched>> hashDispatch)
      Delegates to dispatch(String, MinecraftHasher, Function, Function), uses "type" as the typeKey.
      See Also:
    • dispatch

      static <Type, Dispatched> MapBuilder<Dispatched> dispatch(String typeKey, MinecraftHasher<Type> typeHasher, Function<Dispatched,Type> typeExtractor, Function<Type,MapBuilder<Dispatched>> mapDispatch)
      Creates a map builder that dispatches a MapBuilder from a MapBuilder using typeExtractor, puts this as the typeKey key in the map using the given typeHasher, and uses a MapBuilder provided by mapDispatch to build the rest of the map.

      This can be used to create map builders that build an abstract type or interface into a map with different keys depending on the type.

      Type Parameters:
      Type - the type of the typeKey.
      Dispatched - the type of the new map builder.
      Parameters:
      typeKey - the key to store the MapBuilder in.
      typeHasher - the hasher used to encode the MapBuilder.
      typeExtractor - the function that extracts a MapBuilder from a MapBuilder.
      mapDispatch - the function that provides a MapBuilder based on a MapBuilder.
    • inlineNbtMap

      static <Type> Function<org.cloudburstmc.nbt.NbtMap,MapBuilder<Type>> inlineNbtMap()
      Returns a function that creates a map builder from an NBT map. The builder simply adds all keys from the NBT map.

      Can be used with MapHasher.accept(Function, Function) to inline an NBT map into a map builder, together with other keys.

      Type Parameters:
      Type - the type to encode.