Package commoble.databuddy.nbt

# Class NBTMapCodec<KEY,VALUE>

java.lang.Object
commoble.databuddy.nbt.NBTMapCodec<KEY,VALUE>

Type Parameters:
  `KEY` - the type of the Map's keys
  `VALUE` - the type of the Map's values

public class NBTMapCodec<KEY,VALUE> extends Object
Helper class for writing a Map into a CompoundTag

## Constructor Summary

Constructors
Constructor
Description
`NBTMapCodec(String name, BiConsumer<net.minecraft.nbt.CompoundTag,KEY> keyWriter, Function<net.minecraft.nbt.CompoundTag,KEY> keyReader, BiConsumer<net.minecraft.nbt.CompoundTag,VALUE> valueWriter, Function<net.minecraft.nbt.CompoundTag,VALUE> valueReader)`

## Method Summary

Modifier and Type
Method
Description
`Map<KEY,VALUE>`
`read(net.minecraft.nbt.CompoundTag nbt)`
Reconstructs and returns a Map<KEY,VALUE> from a CompoundTag If the nbt used was given by this.write(map), the map returned will be a reconstruction of the original Map
`net.minecraft.nbt.CompoundTag`
`write(Map<KEY,VALUE> map, net.minecraft.nbt.CompoundTag compound)`
Given a map and a CompoundTag, writes the map into the NBT The same CompoundTag can be given to this.read to retrieve that map

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### NBTMapCodec

public NBTMapCodec(String name, BiConsumer<net.minecraft.nbt.CompoundTag,KEY> keyWriter, Function<net.minecraft.nbt.CompoundTag,KEY> keyReader, BiConsumer<net.minecraft.nbt.CompoundTag,VALUE> valueWriter, Function<net.minecraft.nbt.CompoundTag,VALUE> valueReader)

Parameters:
  `name` - A unique identifier for the hashmap, allowing the map to be written into a CompoundTag alongside other data
  `keyWriter` - A function that, given a CompoundTag and a Key, writes that Key into the NBT
  `keyReader` - A function that, given a CompoundTag, returns the Key written in that NBT
  `valueWriter` - A function that, given a CompoundTag and a Value, writes that Value into the NBT
  `valueReader` - A Function that ,given a CompoundTag, returns the Value written in that NBT

## Method Details

### read

public Map<KEY,VALUE> read(net.minecraft.nbt.CompoundTag nbt)
Reconstructs and returns a Map<KEY,VALUE> from a CompoundTag If the nbt used was given by this.write(map), the map returned will be a reconstruction of the original Map

Parameters:
  `nbt` - The CompoundTag to read and construct the Map from
Returns:
  A Map that the data contained in the CompoundTag represents

### write

public net.minecraft.nbt.CompoundTag write(Map<KEY,VALUE> map, net.minecraft.nbt.CompoundTag compound)
Given a map and a CompoundTag, writes the map into the NBT The same CompoundTag can be given to this.read to retrieve that map

Parameters:
  `map` - A Map<KEY,VALUE>
  `compound` - A CompoundTag to write the map into
Returns:
  a CompoundTag that, when used as the argument to this.read(nbt), will cause that function to reconstruct and return a copy of the original map