-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathBiomeBuilder.java
More file actions
183 lines (157 loc) · 5.45 KB
/
Copy pathBiomeBuilder.java
File metadata and controls
183 lines (157 loc) · 5.45 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package fr.openmc.api.datapacks.builders;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import lombok.Getter;
import java.util.function.Consumer;
/**
* Exemple simple d'un biome:
* {
* "attributes": {},
* "carvers": [],
* "creature_spawn_probability": 0.03,
* "downfall": 0,
* "effects": {
* "foliage_color": "#9e814d",
* "grass_color": "#90814d",
* "water_color": "#3f76e4",
* "dry_foliage_color": "",
* "grass_color_modifier": "none"
* },
* "features": [],
* "has_precipitation": false,
* "spawn_costs": {},
* "spawners": {},
* "temperature": 2
* }
*/
public final class BiomeBuilder {
private JsonObject attributes = new JsonObject();
private final JsonArray carvers = new JsonArray();
@Getter
private final JsonObject effects = new JsonObject();
private final JsonArray features = new JsonArray();
private final JsonObject spawnCosts = new JsonObject();
private final JsonObject spawners = new JsonObject();
private String temperatureModifier = "none";
private Double creatureSpawnProbability = 0.03;
private Float downfall = 0.5f;
private Float temperatures = 0.5f;
private Boolean hasPrecipitation = true;
public BiomeBuilder attributes(EnvironnementAttributeBuilder builder) {
this.attributes = builder.getOutputData();
return this;
}
public BiomeBuilder carver(String id) {
this.carvers.add(id);
return this;
}
public BiomeBuilder features(JsonElement id) {
this.features.add(id);
return this;
}
public BiomeBuilder temperatureModifier(String id) {
this.temperatureModifier =id;
return this;
}
public BiomeBuilder creatureSpawnProbability(Double value) {
this.creatureSpawnProbability=value;
return this;
}
public BiomeBuilder downfall(Float value) {
this.downfall=value;
return this;
}
public BiomeBuilder effects(Consumer<JsonObject> builder) {
JsonObject obj = new JsonObject();
builder.accept(obj);
for (var entry : obj.entrySet()) {
this.effects.add(entry.getKey(), entry.getValue());
}
return this;
}
public BiomeBuilder waterColor(String color) {
this.effects.addProperty("water_color", color);
return this;
}
public BiomeBuilder grassColor(String color) {
this.effects.addProperty("grass_color", color);
return this;
}
public BiomeBuilder foliageColor(String color) {
this.effects.addProperty("foliage_color", color);
return this;
}
public BiomeBuilder dryFoliageColor(String color) {
this.effects.addProperty("dry_foliage_color", color);
return this;
}
public BiomeBuilder waterColor(Integer color) {
this.effects.addProperty("water_color", color);
return this;
}
public BiomeBuilder grassColor(Integer color) {
this.effects.addProperty("grass_color", color);
return this;
}
public BiomeBuilder foliageColor(Integer color) {
this.effects.addProperty("foliage_color", color);
return this;
}
public BiomeBuilder dryFoliageColor(Integer color) {
this.effects.addProperty("dry_foliage_color", color);
return this;
}
/**
* Set la grass color modifier
* @param id none, dark_forest, swamp
* @return le builder
*/
public BiomeBuilder grassColorModifier(String id) {
this.effects.addProperty("grass_color_modifier", id);
return this;
}
public BiomeBuilder spawnCosts(Consumer<JsonObject> builder) {
JsonObject obj = new JsonObject();
builder.accept(obj);
for (var entry : obj.entrySet()) {
this.spawnCosts.add(entry.getKey(), entry.getValue());
}
return this;
}
public BiomeBuilder spawnCosts(JsonObject spawnCosts) {
for (var entry : spawnCosts.entrySet()) {
this.spawnCosts.add(entry.getKey(), entry.getValue());
}
return this;
}
public BiomeBuilder spawners(JsonObject spawners) {
for (var entry : spawners.entrySet()) {
this.spawners.add(entry.getKey(), entry.getValue());
}
return this;
}
public BiomeBuilder temperatures(Float value) {
this.temperatures=value;
return this;
}
public BiomeBuilder hasPrecipitation(Boolean bool) {
this.hasPrecipitation=bool;
return this;
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
if (attributes != null) json.add("attributes", attributes);
if (temperatureModifier != null) json.addProperty("temperature_modifier", temperatureModifier);
if (creatureSpawnProbability != null) json.addProperty("creature_spawn_probability", creatureSpawnProbability);
if (carvers != null) json.add("carvers", carvers);
if (downfall != null) json.addProperty("downfall", downfall);
if (effects != null) json.add("effects", effects);
if (features != null) json.add("features", features);
if (hasPrecipitation != null) json.addProperty("has_precipitation", hasPrecipitation);
if (spawnCosts != null) json.add("spawn_costs", spawnCosts);
if (spawners != null) json.add("spawners", spawners);
if (temperatures != null) json.addProperty("temperature", temperatures);
return json;
}
}