Package commoble.morered.util

# Class NBTListCodec<ENTRY,RAW>

java.lang.Object
commoble.morered.util.NBTListCodec<ENTRY,RAW>

Type Parameters:
  `ENTRY` - the data type in the actual java list, i.e. List<ENTRY>
  `RAW` - either a primitive or an NBT collection type, see ListTagType instances

public class NBTListCodec<ENTRY,RAW> extends Object
Helper class for converting lists or list-like collections of arbitrary data to NBT and back.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static interface`
`NBTListCodec.ListReader<T>`
Represents a function that takes a list NBT and an index and returns the object in the list at that index.
`static class`
`NBTListCodec.ListTagType<T>`

## Constructor Summary

Constructors
Constructor
Description
`NBTListCodec(String name, NBTListCodec.ListTagType<RAW> type, Function<ENTRY,RAW> elementWriter, Function<RAW,ENTRY> elementReader)`

## Method Summary

Modifier and Type
Method
Description
`List<ENTRY>`
`read(net.minecraft.nbt.CompoundTag compound)`
Reconstructs and returns a List<ENTRY> from a CompoundTag If the nbt used was given by this.write(list), the list returned will be a reconstruction of the original List
`net.minecraft.nbt.CompoundTag`
`write(List<ENTRY> list, net.minecraft.nbt.CompoundTag compound)`
Given a list and a CompoundTag,writes the contents of that list 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

### NBTListCodec

public NBTListCodec(String name, NBTListCodec.ListTagType<RAW> type, Function<ENTRY,RAW> elementWriter, Function<RAW,ENTRY> elementReader)

Parameters:
  `name` - A string to use as the field name when we write the list into existing nbt
  `type` - A ListTagType that describes how to get data out of the list and convert primitives to NBT
  `elementWriter` - A function that converts an entry instance to the intermediate raw type
  `elementReader` - A function that converts the raw instance back into an entry instance

## Method Details

### read

public List<ENTRY> read(net.minecraft.nbt.CompoundTag compound)
Reconstructs and returns a List<ENTRY> from a CompoundTag If the nbt used was given by this.write(list), the list returned will be a reconstruction of the original List

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

### write

public net.minecraft.nbt.CompoundTag write(List<ENTRY> list, net.minecraft.nbt.CompoundTag compound)
Given a list and a CompoundTag,writes the contents of that list into the NBT The same CompoundTag can be given to this.read to retrieve that map

Parameters:
  `list` - A List<ENTRY> to write into the nbt
  `compound` - A CompoundTag to write the list 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 list