Interface MinecraftHasher<Type>

Type Parameters:
Type - the type this hasher hashes.
All Known Subinterfaces:
RegistryHasher<DirectType>
All Known Implementing Classes:
RegistryHasher.RegistryHasherWithDirectHasher
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 MinecraftHasher<Type>
Encodes an object into a HashCode using a MinecraftHashEncoder.

Hashers have been implemented for common types, such as all Java primitives, units (encodes an empty map), NBT maps and lists, Vector3i positions, Key resource locations and #-prefixed tags, UUIDs, and more types. Furthermore, in RegistryHasher more hashers can be found for more specific for Minecraft types, and ComponentHasher.COMPONENT hashes Components.

Most hashers are not created by implementing them directly, rather, they are built on top of other hashers, using various methods to manipulate and map them. Here are some commonly used ones:

On top of these there are more methods, as well as static helper methods in this class, to create hashers. One worth pointing out is mapBuilder(MapBuilder), which hashes an object into a map-like structure. Read the documentation there, on MapBuilder, and on MapHasher on how to use it.

As of right now, hashers are used to create hash codes for data components, which Minecraft requires to be sent in inventory transactions. You'll find all the hashers for data components in DataComponentHashers. In the future, hashers may be used elsewhere as well. If necessary, this system can even be refactored to write to different data structures, such as NBT or JSON files, as well.

When creating new hashers, please be sure to put them in the proper place:

  • Hashers that hash very generic types, or types that are used broadly across Minecraft (like key, UUID, game profile, etc.) belong here in MinecraftHasher.
  • Hashers that hash more specific types, are more complicated, or depend on a hasher in RegistryHasher, belong in RegistryHasher.
  • Hashers that hash components, and are used nowhere else, belong in DataComponentHashers.