Skip to content

Commit 2ad3b5b

Browse files
committed
fix(custom-biome): use null for blank biome colors
1 parent 5b3a751 commit 2ad3b5b

4 files changed

Lines changed: 72 additions & 70 deletions

File tree

main/src/main/java/me/outspending/biomesapi/biome/CustomBiome.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.bukkit.NamespacedKey;
1313
import org.bukkit.block.Biome;
1414
import org.jetbrains.annotations.NotNull;
15+
import org.jetbrains.annotations.Nullable;
1516

1617
/**
1718
* This interface represents a custom biome in the BiomesAPI.
@@ -78,7 +79,7 @@ public interface CustomBiome {
7879
* @since 0.0.1
7980
*/
8081
@AsOf("0.0.1")
81-
int getFogColor();
82+
@Nullable Integer getFogColor();
8283

8384
/**
8485
* Returns the water color of the CustomBiome.
@@ -96,7 +97,7 @@ public interface CustomBiome {
9697
* @since 0.0.1
9798
*/
9899
@AsOf("0.0.1")
99-
int getWaterFogColor();
100+
@Nullable Integer getWaterFogColor();
100101

101102
/**
102103
* Returns the sky color of the CustomBiome.
@@ -105,7 +106,7 @@ public interface CustomBiome {
105106
* @since 0.0.1
106107
*/
107108
@AsOf("0.0.1")
108-
int getSkyColor();
109+
@Nullable Integer getSkyColor();
109110

110111
/**
111112
* Returns the foliage color of the CustomBiome.
@@ -114,7 +115,7 @@ public interface CustomBiome {
114115
* @since 0.0.1
115116
*/
116117
@AsOf("0.0.1")
117-
int getFoliageColor();
118+
@Nullable Integer getFoliageColor();
118119

119120
/**
120121
* Returns the grass color of the CustomBiome.
@@ -123,7 +124,7 @@ public interface CustomBiome {
123124
* @since 0.0.1
124125
*/
125126
@AsOf("0.0.1")
126-
int getGrassColor();
127+
@Nullable Integer getGrassColor();
127128

128129
/**
129130
* Returns the dry foliage color of the CustomBiome.
@@ -132,7 +133,7 @@ public interface CustomBiome {
132133
* @since 1.0.2
133134
*/
134135
@AsOf("1.0.2")
135-
int getDryFoliageColor();
136+
@Nullable Integer getDryFoliageColor();
136137

137138
/**
138139
* Returns the GrassColorModifier of the CustomBiome.
@@ -177,8 +178,8 @@ public interface CustomBiome {
177178
* @param fogColor the fog color of the CustomBiome
178179
* @since 0.0.5
179180
*/
180-
@AsOf("0.0.5")
181-
void setFogColor(int fogColor);
181+
@AsOf("1.1.0")
182+
void setFogColor(@Nullable Integer fogColor);
182183

183184
/**
184185
* Sets the water color of the CustomBiome.
@@ -195,44 +196,44 @@ public interface CustomBiome {
195196
* @param waterFogColor the water fog color of the CustomBiome
196197
* @since 0.0.5
197198
*/
198-
@AsOf("0.0.5")
199-
void setWaterFogColor(int waterFogColor);
199+
@AsOf("1.1.0")
200+
void setWaterFogColor(@Nullable Integer waterFogColor);
200201

201202
/**
202203
* Sets the sky color of the CustomBiome.
203204
*
204205
* @param skyColor the sky color of the CustomBiome
205206
* @since 0.0.5
206207
*/
207-
@AsOf("0.0.5")
208-
void setSkyColor(int skyColor);
208+
@AsOf("1.1.0")
209+
void setSkyColor(@Nullable Integer skyColor);
209210

210211
/**
211212
* Sets the foliage color of the CustomBiome.
212213
*
213214
* @param foliageColor the foliage color of the CustomBiome
214215
* @since 0.0.5
215216
*/
216-
@AsOf("0.0.5")
217-
void setFoliageColor(int foliageColor);
217+
@AsOf("1.1.0")
218+
void setFoliageColor(@Nullable Integer foliageColor);
218219

219220
/**
220221
* Sets the grass color of the CustomBiome.
221222
*
222223
* @param grassColor the grass color of the CustomBiome
223224
* @since 0.0.5
224225
*/
225-
@AsOf("0.0.5")
226-
void setGrassColor(int grassColor);
226+
@AsOf("1.1.0")
227+
void setGrassColor(@Nullable Integer grassColor);
227228

228229
/**
229230
* Sets the dry foliage color of the CustomBiome.
230231
*
231232
* @param dryFoliageColor the dry foliage color of the CustomBiome
232233
* @since 1.0.2
233234
*/
234-
@AsOf("1.0.2")
235-
void setDryFoliageColor(int dryFoliageColor);
235+
@AsOf("1.1.0")
236+
void setDryFoliageColor(@Nullable Integer dryFoliageColor);
236237

237238
/**
238239
* Sets the GrassColorModifier of the CustomBiome.
@@ -327,12 +328,12 @@ class Builder {
327328

328329
private int waterColor = 0xF54927; // Meadow biome default water color
329330

330-
private int fogColor = -1;
331-
private int waterFogColor = -1;
332-
private int skyColor = -1;
333-
private int foliageColor = -1;
334-
private int grassColor = -1;
335-
private int dryFoliageColor = -1;
331+
private @Nullable Integer fogColor = -1;
332+
private @Nullable Integer waterFogColor = -1;
333+
private @Nullable Integer skyColor = -1;
334+
private @Nullable Integer foliageColor = -1;
335+
private @Nullable Integer grassColor = -1;
336+
private @Nullable Integer dryFoliageColor = -1;
336337

337338
private GrassColorModifier grassColorModifier = GrassColorModifier.NONE;
338339
private ParticleRenderer particleRenderer = ParticleRenderer.EMPTY;
@@ -362,8 +363,8 @@ private String formatHex(@NotNull String color) {
362363
* @since 0.0.1
363364
*/
364365
@AsOf("1.0.2")
365-
private int parseHex(@NotNull String color) {
366-
if (color.isEmpty()) return 0;
366+
private @Nullable Integer parseHex(@NotNull String color) {
367+
if (color.isEmpty()) return null;
367368
return Integer.parseInt(formatHex(color), 16);
368369
}
369370

main/src/main/java/me/outspending/biomesapi/biome/CustomBiomeImpl.java

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.bukkit.NamespacedKey;
1515
import org.bukkit.block.Biome;
1616
import org.jetbrains.annotations.NotNull;
17+
import org.jetbrains.annotations.Nullable;
1718

1819
/**
1920
* This class represents a custom biome implementation.
@@ -33,12 +34,12 @@ public final class CustomBiomeImpl implements CustomBiome {
3334
private int waterColor = 0xF54927;
3435

3536
// Optional Colors
36-
private int fogColor = -1;
37-
private int waterFogColor = -1;
38-
private int skyColor = -1;
39-
private int foliageColor = -1;
40-
private int grassColor = -1;
41-
private int dryFoliageColor = -1;
37+
private Integer fogColor;
38+
private Integer waterFogColor;
39+
private Integer skyColor;
40+
private Integer foliageColor;
41+
private Integer grassColor;
42+
private Integer dryFoliageColor;
4243

4344
// Optional Settings
4445
private GrassColorModifier grassColorModifier = GrassColorModifier.NONE;
@@ -47,15 +48,15 @@ public final class CustomBiomeImpl implements CustomBiome {
4748

4849
private WrappedEnvironmentAttributeMap environmentAttributeMap = WrappedEnvironmentAttributeMap.EMPTY;
4950

50-
@AsOf("0.0.2")
51+
@AsOf("1.1.0")
5152
public CustomBiomeImpl(
5253
@NotNull BiomeResourceKey resourceKey,
5354
@NotNull BiomeSettings settings,
5455

55-
int fogColor,
56+
@Nullable Integer fogColor,
5657
int waterColor,
57-
int waterFogColor,
58-
int skyColor,
58+
@Nullable Integer waterFogColor,
59+
@Nullable Integer skyColor,
5960

6061
@NotNull ParticleRenderer particleRenderer
6162
) {
@@ -70,17 +71,17 @@ public CustomBiomeImpl(
7071
this.blockReplacements = new BlockReplacement[0];
7172
}
7273

73-
@AsOf("0.0.2")
74+
@AsOf("1.1.0")
7475
public CustomBiomeImpl(
7576
@NotNull BiomeResourceKey resourceKey,
7677
@NotNull BiomeSettings settings,
7778

78-
int fogColor,
79+
@Nullable Integer fogColor,
7980
int waterColor,
80-
int waterFogColor,
81-
int skyColor,
82-
int foliageColor,
83-
int grassColor,
81+
@Nullable Integer waterFogColor,
82+
@Nullable Integer skyColor,
83+
@Nullable Integer foliageColor,
84+
@Nullable Integer grassColor,
8485

8586
@NotNull ParticleRenderer particleRenderer
8687
) {
@@ -90,18 +91,18 @@ public CustomBiomeImpl(
9091
this.blockReplacements = new BlockReplacement[0];
9192
}
9293

93-
@AsOf("1.0.2")
94+
@AsOf("1.1.0")
9495
public CustomBiomeImpl(
9596
@NotNull BiomeResourceKey resourceKey,
9697
@NotNull BiomeSettings settings,
9798

98-
int fogColor,
99+
@Nullable Integer fogColor,
99100
int waterColor,
100-
int waterFogColor,
101-
int skyColor,
102-
int foliageColor,
103-
int grassColor,
104-
int dryFoliageColor,
101+
@Nullable Integer waterFogColor,
102+
@Nullable Integer skyColor,
103+
@Nullable Integer foliageColor,
104+
@Nullable Integer grassColor,
105+
@Nullable Integer dryFoliageColor,
105106

106107
@NotNull GrassColorModifier grassColorModifier,
107108
@NotNull ParticleRenderer particleRenderer,
@@ -139,7 +140,7 @@ public CustomBiomeImpl(
139140
}
140141

141142
@Override
142-
public int getFogColor() {
143+
public Integer getFogColor() {
143144
return fogColor;
144145
}
145146

@@ -149,26 +150,26 @@ public int getWaterColor() {
149150
}
150151

151152
@Override
152-
public int getWaterFogColor() {
153+
public Integer getWaterFogColor() {
153154
return waterFogColor;
154155
}
155156

156157
@Override
157-
public int getSkyColor() {
158+
public Integer getSkyColor() {
158159
return skyColor;
159160
}
160161

161162
@Override
162-
public int getFoliageColor() {
163+
public Integer getFoliageColor() {
163164
return foliageColor;
164165
}
165166

166167
@Override
167-
public int getGrassColor() {
168+
public Integer getGrassColor() {
168169
return grassColor;
169170
}
170171

171-
public int getDryFoliageColor() {
172+
public Integer getDryFoliageColor() {
172173
return dryFoliageColor;
173174
}
174175

@@ -193,7 +194,7 @@ public GrassColorModifier getGrassColorModifier() {
193194
}
194195

195196
@Override
196-
public void setFogColor(int fogColor) {
197+
public void setFogColor(@Nullable Integer fogColor) {
197198
this.fogColor = fogColor;
198199
}
199200

@@ -203,26 +204,26 @@ public void setWaterColor(int waterColor) {
203204
}
204205

205206
@Override
206-
public void setWaterFogColor(int waterFogColor) {
207+
public void setWaterFogColor(@Nullable Integer waterFogColor) {
207208
this.waterFogColor = waterFogColor;
208209
}
209210

210211
@Override
211-
public void setSkyColor(int skyColor) {
212+
public void setSkyColor(@Nullable Integer skyColor) {
212213
this.skyColor = skyColor;
213214
}
214215

215216
@Override
216-
public void setFoliageColor(int foliageColor) {
217+
public void setFoliageColor(@Nullable Integer foliageColor) {
217218
this.foliageColor = foliageColor;
218219
}
219220

220221
@Override
221-
public void setGrassColor(int grassColor) {
222+
public void setGrassColor(@Nullable Integer grassColor) {
222223
this.grassColor = grassColor;
223224
}
224225

225-
public void setDryFoliageColor(int dryFoliageColor) {
226+
public void setDryFoliageColor(@Nullable Integer dryFoliageColor) {
226227
this.dryFoliageColor = dryFoliageColor;
227228
}
228229

main/src/main/java/me/outspending/biomesapi/registry/CustomBiomeRegistry.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ public void register(@NotNull CustomBiome biome) {
8181
.generationSettings(BiomeGenerationSettings.EMPTY);
8282

8383
// TODO: Replace with WrappedEnvironmentAttributeMap in the future
84-
if (biome.getFogColor() != -1) {
84+
if (biome.getFogColor() != null) {
8585
biomeBuilder.setAttribute(EnvironmentAttributes.FOG_COLOR, biome.getFogColor());
8686
}
87-
if (biome.getSkyColor() != -1) {
87+
if (biome.getSkyColor() != null) {
8888
biomeBuilder.setAttribute(EnvironmentAttributes.SKY_COLOR, biome.getWaterColor());
8989
}
90-
if (biome.getWaterFogColor() != -1) {
90+
if (biome.getWaterFogColor() != null) {
9191
biomeBuilder.setAttribute(EnvironmentAttributes.WATER_FOG_COLOR, biome.getWaterFogColor());
9292
}
9393

@@ -151,13 +151,13 @@ public void modify(@NotNull CustomBiome customBiome) {
151151
.set(EnvironmentAttributes.AMBIENT_PARTICLES, particles);
152152

153153
// TODO: Replace with WrappedEnvironmentAttributeMap in the future
154-
if (customBiome.getFogColor() != -1) {
154+
if (customBiome.getFogColor() != null) {
155155
environmentAttributeMapBuilder.set(EnvironmentAttributes.FOG_COLOR, customBiome.getFogColor());
156156
}
157-
if (customBiome.getSkyColor() != -1) {
157+
if (customBiome.getSkyColor() != null) {
158158
environmentAttributeMapBuilder.set(EnvironmentAttributes.SKY_COLOR, customBiome.getSkyColor());
159159
}
160-
if (customBiome.getWaterFogColor() != -1) {
160+
if (customBiome.getWaterFogColor() != null) {
161161
environmentAttributeMapBuilder.set(EnvironmentAttributes.WATER_FOG_COLOR, customBiome.getWaterFogColor());
162162
}
163163
WrappedEnvironmentAttributeMap wrappedAttributeMap = customBiome.getEnvironmentAttributeMap();

main/src/main/java/me/outspending/biomesapi/registry/handlers/SpecialEffectsHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public void handle(BiomeSpecialEffects value, @NotNull Biome.BiomeBuilder builde
2020
@Override
2121
public BiomeSpecialEffects build(@NotNull CustomBiome biome) {
2222
BiomeSpecialEffects.Builder builder = new BiomeSpecialEffects.Builder();
23-
if (biome.getFoliageColor() != -1) {
23+
if (biome.getFoliageColor() != null) {
2424
builder.foliageColorOverride(biome.getFoliageColor());
2525
}
2626

27-
if (biome.getGrassColor() != -1) {
27+
if (biome.getGrassColor() != null) {
2828
builder.grassColorOverride(biome.getGrassColor());
2929
}
3030

31-
if (biome.getDryFoliageColor() != -1) {
31+
if (biome.getDryFoliageColor() != null) {
3232
builder.dryFoliageColorOverride(biome.getDryFoliageColor());
3333
}
3434

0 commit comments

Comments
 (0)