aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/OreMixBuilder.java
blob: 86453ca0a8f34e11bf7b56f1b20d3831a16ef415 (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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package gregtech.common;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import galacticgreg.api.enums.DimensionDef;
import gregtech.api.enums.Materials;

public class OreMixBuilder {

    public static final String OW = "Overworld";
    public static final String NETHER = "Nether";
    public static final String THE_END = "TheEnd";
    public static final String TWILIGHT_FOREST = "Twilight Forest";
    public String oreMixName;
    public boolean enabledByDefault = true;
    public Map<String, Boolean> dimsEnabled = new HashMap<>();
    public int minY, maxY, weight, density, size;
    public Materials primary, secondary, between, sporadic, representative;
    public String localizedName;

    public OreMixBuilder name(String name) {
        this.oreMixName = name;
        return this;
    }

    public OreMixBuilder disabledByDefault() {
        this.enabledByDefault = false;
        return this;
    }

    public OreMixBuilder enableInDim(DimensionDef... dims) {
        for (DimensionDef dim : dims) {
            this.dimsEnabled.put(dim.modDimensionDef.getDimensionName(), true);
        }
        return this;
    }

    public OreMixBuilder enableInDim(String... dims) {
        for (String dim : dims) {
            this.dimsEnabled.put(dim, true);
        }
        return this;
    }

    public OreMixBuilder heightRange(int minY, int maxY) {
        this.minY = minY;
        this.maxY = maxY;
        return this;
    }

    public OreMixBuilder density(int density) {
        this.density = density;
        return this;
    }

    public OreMixBuilder weight(int weight) {
        this.weight = weight;
        return this;
    }

    public OreMixBuilder size(int size) {
        this.size = size;
        return this;
    }

    public OreMixBuilder primary(Materials primary) {
        this.primary = primary;
        if (representative == null || localizedName == null) {
            representative = primary;
            localizedName = primary.mLocalizedName;
        }
        return this;
    }

    public OreMixBuilder secondary(Materials secondary) {
        this.secondary = secondary;
        return this;
    }

    public OreMixBuilder inBetween(Materials between) {
        this.between = between;
        return this;
    }

    public OreMixBuilder sporadic(Materials sporadic) {
        this.sporadic = sporadic;
        return this;
    }

    /**
     * Sets the localized name for the ore mix based on the provided materials.
     * If more than one material is provided, their localized names are concatenated
     * with commas, last comma is replaced by "&".
     *
     * @param materials The materials to be used for localization. The first material
     *                  in the array will be used to represent to ore mix in GUI's.
     *                  If none are provided the {@link #primary} will be used.
     */
    public OreMixBuilder localize(Materials... materials) {
        if (materials.length > 1) {
            String localizedName = String.join(
                ", ",
                Arrays.stream(materials)
                    .map(material -> material.mLocalizedName)
                    .toArray(String[]::new));
            int index = localizedName.lastIndexOf(", ");
            if (index != -1) {
                localizedName = localizedName.substring(0, index) + " & " + localizedName.substring(index + 2);
            }
            this.localizedName = localizedName;
        } else {
            this.localizedName = materials[0].mLocalizedName;
        }
        this.representative = materials[0];
        return this;
    }
}