File tree Expand file tree Collapse file tree
src/main/java/dev/latvian/mods/klib/codec Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212import net .minecraft .commands .arguments .TimeArgument ;
1313import net .minecraft .util .StringRepresentable ;
1414
15+ import java .net .URI ;
1516import java .time .Instant ;
1617import java .util .ArrayList ;
1718import java .util .Arrays ;
@@ -125,6 +126,20 @@ static <T> Codec<List<T>> listOrSelf(Codec<T> elementCodec) {
125126
126127 Codec <Instant > INSTANT = KLibCodecs .or (ISO_INSTANT , UINT64_INSTANT );
127128
129+ Codec <URI > URI = Codec .STRING .flatXmap (string -> {
130+ try {
131+ return DataResult .success (new java .net .URI (string ));
132+ } catch (Exception ex ) {
133+ return DataResult .error (() -> "Invalid URI: " + string );
134+ }
135+ }, uri -> {
136+ try {
137+ return DataResult .success (uri .toString ());
138+ } catch (Exception ex ) {
139+ return DataResult .error (() -> "Invalid URI: " + uri );
140+ }
141+ });
142+
128143 static <E > Codec <E > anyEnumCodec (E [] enumValues , Function <E , String > nameGetter ) {
129144 var map = new HashMap <String , E >(enumValues .length );
130145
You can’t perform that action at this time.
0 commit comments