Package net.commoble.exmachina.internal.util

# Class CodecHelper

java.lang.Object
net.commoble.exmachina.internal.util.CodecHelper

public final class CodecHelper extends Object
codec utils

## Field Summary

Fields
Modifier and Type
Field
Description
`static final net.minecraft.network.codec.StreamCodec<io.netty.buffer.ByteBuf,net.minecraft.world.level.block.state.BlockState>`
`BLOCKSTATE_STREAM_CODEC`
StreamCodec for BlockStates

## Method Summary

Modifier and Type
Method
Description
`static <T> com.mojang.serialization.Codec<T>`
`dispatch(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<com.mojang.serialization.MapCodec<? extends T>>> registryKey, Function<? super T,? extends com.mojang.serialization.MapCodec<? extends T>> typeCodec)`
Helper to make a dispatch codec for a custom forge registry of codecs.
`static <K, V> com.mojang.serialization.Codec<Map<K,V>>`
`pairListMap(com.mojang.serialization.Codec<K> keyCodec, com.mojang.serialization.Codec<V> valueCodec)`
Creates a codec which encodes a Map as a list of pairs, averting unboundedMap's requirement that key codecs are string-serializable.
`static <T> com.mojang.serialization.Codec<List<T>>`
`singleOrPluralCodec(com.mojang.serialization.Codec<T> codec)`
Creates a list codec that serializes as a single object when size == 1

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

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

## Field Details

### BLOCKSTATE_STREAM_CODEC

public static final net.minecraft.network.codec.StreamCodec<io.netty.buffer.ByteBuf,net.minecraft.world.level.block.state.BlockState> BLOCKSTATE_STREAM_CODEC
StreamCodec for BlockStates

## Method Details

### dispatch

public static <T> com.mojang.serialization.Codec<T> dispatch(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<com.mojang.serialization.MapCodec<? extends T>>> registryKey, Function<? super T,? extends com.mojang.serialization.MapCodec<? extends T>> typeCodec)
Helper to make a dispatch codec for a custom forge registry of codecs.

Type Parameters:
  `T` - Type of the element to be loaded from json
Parameters:
  `registryKey` - ResourceKey for a Registry of sub-codecs.
  `typeCodec` - Function to retrieve the codec for a given json-loaded element
Returns:
  dispatch codec to load instances of T

### pairListMap

public static <K, V> com.mojang.serialization.Codec<Map<K,V>> pairListMap(com.mojang.serialization.Codec<K> keyCodec, com.mojang.serialization.Codec<V> valueCodec)
Creates a codec which encodes a Map as a list of pairs, averting unboundedMap's requirement that key codecs are string-serializable. Maps/lists created are mutable.

Type Parameters:
  `K` - Type of the map keys
  `V` - Type of the map values
Parameters:
  `keyCodec` - Key serializer
  `valueCodec` - Value serializer
Returns:
  Codec which encodes a Map as a list of pairs

### singleOrPluralCodec

public static <T> com.mojang.serialization.Codec<List<T>> singleOrPluralCodec(com.mojang.serialization.Codec<T> codec)
Creates a list codec that serializes as a single object when size == 1

Type Parameters:
  `T` - Type of the thing to serialize
Parameters:
  `codec` - Codec for the singular object
Returns:
  Codec which serializes a list of the things, unless the list only has one thing in it, in which cases it serializes the single value