package mc.nbt.codec.vanilla; import lombok.Getter; import lombok.RequiredArgsConstructor; import mc.nbt.TypeTag; import java.util.stream.Stream; @RequiredArgsConstructor @Getter public enum CodecEnum { END(TypeTag.END, new TagEndCodec()), BYTE(TypeTag.BYTE, new TagByteCodec()), SHORT(TypeTag.SHORT, new TagShortCodec()), INT(TypeTag.INT, new TagIntCodec()), LONG(TypeTag.LONG, new TagLongCodec()), FLOAT(TypeTag.FLOAT, new TagFloatCodec()), DOUBLE(TypeTag.DOUBLE, new TagDoubleCodec()), BYTE_ARRAY(TypeTag.BYTE_ARRAY, new TagByteArrayCodec()), STRING(TypeTag.STRING, new TagStringCodec()), LIST(TypeTag.LIST, new TagListCodec()), COMPOUND(TypeTag.COMPOUND, new TagCompoundCodec()), INT_ARRAY(TypeTag.INT_ARRAY, new TagIntArrayCodec()), LONG_ARRAY(TypeTag.LONG_ARRAY, new TagLongArrayCodec()); public static CodecEnum valueOfTypeTag(TypeTag typeTag) { return Stream.of(CodecEnum.values()) .filter(codecEnum -> codecEnum.getTypeTag() == typeTag) .findFirst() .orElseThrow(() -> new RuntimeException("Codec for " + typeTag.name() + " not found")); } private final TypeTag typeTag; private final Codec codec; }