aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl3/config/v3/ReadonlyConfigEntry.java
blob: c38853b345ac05c9e517859eda14f2b1b08a0d86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package dev.isxander.yacl3.config.v3;

import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.RecordBuilder;
import org.jetbrains.annotations.ApiStatus;

import java.util.function.Consumer;
import java.util.function.UnaryOperator;

@ApiStatus.Experimental
public interface ReadonlyConfigEntry<T> {
    String fieldName();

    T get();

    ReadonlyConfigEntry<T> modifyGet(UnaryOperator<T> modifier);
    default ReadonlyConfigEntry<T> onGet(Consumer<T> consumer) {
        return this.modifyGet(v -> {
            consumer.accept(v);
            return v;
        });
    }

    <R> RecordBuilder<R> encode(DynamicOps<R> ops, RecordBuilder<R> recordBuilder);
    <R> boolean decode(R encoded, DynamicOps<R> ops);
}