File size: 1,912 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package net.minecraft.util.context;

import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import java.util.Set;

public class ContextKeySet {
    private final Set<ContextKey<?>> required;
    private final Set<ContextKey<?>> allowed;

    ContextKeySet(Set<ContextKey<?>> p_366050_, Set<ContextKey<?>> p_362785_) {
        this.required = Set.copyOf(p_366050_);
        this.allowed = Set.copyOf(Sets.union(p_366050_, p_362785_));
    }

    public Set<ContextKey<?>> required() {
        return this.required;
    }

    public Set<ContextKey<?>> allowed() {
        return this.allowed;
    }

    @Override
    public String toString() {
        return "["
            + Joiner.on(", ")
                .join(this.allowed.stream().map(p_369800_ -> (this.required.contains(p_369800_) ? "!" : "") + p_369800_.name()).iterator())
            + "]";
    }

    public static class Builder {
        private final Set<ContextKey<?>> required = Sets.newIdentityHashSet();
        private final Set<ContextKey<?>> optional = Sets.newIdentityHashSet();

        public ContextKeySet.Builder required(ContextKey<?> p_365799_) {
            if (this.optional.contains(p_365799_)) {
                throw new IllegalArgumentException("Parameter " + p_365799_.name() + " is already optional");
            } else {
                this.required.add(p_365799_);
                return this;
            }
        }

        public ContextKeySet.Builder optional(ContextKey<?> p_361328_) {
            if (this.required.contains(p_361328_)) {
                throw new IllegalArgumentException("Parameter " + p_361328_.name() + " is already required");
            } else {
                this.optional.add(p_361328_);
                return this;
            }
        }

        public ContextKeySet build() {
            return new ContextKeySet(this.required, this.optional);
        }
    }
}