com.mojang.serialization.Lifecycle Java Examples
The following examples show how to use
com.mojang.serialization.Lifecycle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseMapCodec.java From DataFixerUpper with MIT License | 6 votes |
default <T> DataResult<Map<K, V>> decode(final DynamicOps<T> ops, final MapLike<T> input) { final ImmutableMap.Builder<K, V> read = ImmutableMap.builder(); final ImmutableList.Builder<Pair<T, T>> failed = ImmutableList.builder(); final DataResult<Unit> result = input.entries().reduce( DataResult.success(Unit.INSTANCE, Lifecycle.stable()), (r, pair) -> { final DataResult<K> k = keyCodec().parse(ops, pair.getFirst()); final DataResult<V> v = elementCodec().parse(ops, pair.getSecond()); final DataResult<Pair<K, V>> entry = k.apply2stable(Pair::of, v); entry.error().ifPresent(e -> failed.add(pair)); return r.apply2stable((u, p) -> { read.put(p.getFirst(), p.getSecond()); return u; }, entry); }, (r1, r2) -> r1.apply2stable((u1, u2) -> u1, r2) ); final Map<K, V> elements = read.build(); final T errors = ops.createMap(failed.build().stream()); return result.map(unit -> elements).setPartial(elements).mapError(e -> e + " missed input: " + errors); }
Example #2
Source File: ListCodec.java From DataFixerUpper with MIT License | 6 votes |
@Override public <T> DataResult<Pair<List<A>, T>> decode(final DynamicOps<T> ops, final T input) { return ops.getList(input).setLifecycle(Lifecycle.stable()).flatMap(stream -> { final ImmutableList.Builder<A> read = ImmutableList.builder(); final Stream.Builder<T> failed = Stream.builder(); // TODO: AtomicReference.getPlain/setPlain in java9+ final MutableObject<DataResult<Unit>> result = new MutableObject<>(DataResult.success(Unit.INSTANCE, Lifecycle.stable())); stream.accept(t -> { final DataResult<Pair<A, T>> element = elementCodec.decode(ops, t); element.error().ifPresent(e -> failed.add(t)); result.setValue(result.getValue().apply2stable((r, v) -> { read.add(v.getFirst()); return r; }, element)); }); final ImmutableList<A> elements = read.build(); final T errors = ops.createList(failed.build()); final Pair<List<A>, T> pair = Pair.of(elements, errors); return result.getValue().map(unit -> pair).setPartial(pair); }); }
Example #3
Source File: CompoundListCodec.java From DataFixerUpper with MIT License | 5 votes |
@Override public <T> DataResult<Pair<List<Pair<K, V>>, T>> decode(final DynamicOps<T> ops, final T input) { return ops.getMapEntries(input).flatMap(map -> { final ImmutableList.Builder<Pair<K, V>> read = ImmutableList.builder(); final ImmutableMap.Builder<T, T> failed = ImmutableMap.builder(); // TODO: AtomicReference.getPlain/setPlain in java9+ final MutableObject<DataResult<Unit>> result = new MutableObject<>(DataResult.success(Unit.INSTANCE, Lifecycle.experimental())); map.accept((key, value) -> { final DataResult<K> k = keyCodec.parse(ops, key); final DataResult<V> v = elementCodec.parse(ops, value); final DataResult<Pair<K, V>> readEntry = k.apply2stable(Pair::new, v); readEntry.error().ifPresent(e -> failed.put(key, value)); result.setValue(result.getValue().apply2stable((u, e) -> { read.add(e); return u; }, readEntry)); }); final ImmutableList<Pair<K, V>> elements = read.build(); final T errors = ops.createMap(failed.build()); final Pair<List<Pair<K, V>>, T> pair = Pair.of(elements, errors); return result.getValue().map(unit -> pair).setPartial(pair); }); }
Example #4
Source File: RegistryAccessor.java From multiconnect with MIT License | 4 votes |
@Accessor Lifecycle getLifecycle();
Example #5
Source File: UnboundedMapCodec.java From DataFixerUpper with MIT License | 4 votes |
@Override public <T> DataResult<Pair<Map<K, V>, T>> decode(final DynamicOps<T> ops, final T input) { return ops.getMap(input).setLifecycle(Lifecycle.stable()).flatMap(map -> decode(ops, map)).map(r -> Pair.of(r, input)); }
Example #6
Source File: RecordCodecBuilder.java From DataFixerUpper with MIT License | 4 votes |
public static <O, F> RecordCodecBuilder<O, F> stable(final F instance) { return point(instance, Lifecycle.stable()); }
Example #7
Source File: RecordCodecBuilder.java From DataFixerUpper with MIT License | 4 votes |
public static <O, F> RecordCodecBuilder<O, F> deprecated(final F instance, final int since) { return point(instance, Lifecycle.deprecated(since)); }
Example #8
Source File: RecordCodecBuilder.java From DataFixerUpper with MIT License | 4 votes |
public static <O, F> RecordCodecBuilder<O, F> point(final F instance, final Lifecycle lifecycle) { return new RecordCodecBuilder<>(o -> instance, o -> Encoder.<F>empty().withLifecycle(lifecycle), Decoder.unit(instance).withLifecycle(lifecycle)); }
Example #9
Source File: RecordCodecBuilder.java From DataFixerUpper with MIT License | 4 votes |
public <A> App<RecordCodecBuilder.Mu<O>, A> point(final A a, final Lifecycle lifecycle) { return RecordCodecBuilder.point(a, lifecycle); }