Skip to content

Commit 99fa586

Browse files
committed
feat(environment-api): Implement necessary components
1 parent 18d4db2 commit 99fa586

28 files changed

Lines changed: 934 additions & 431 deletions

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
val isSnapshot: Boolean = project.hasProperty("snapshot") || System.getProperty("snapshot")?.toBoolean() == true
11-
val stable = "1.0.1"
11+
val stable = "1.1.0"
1212

1313
allprojects {
1414
apply(plugin = "java")

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

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import com.google.common.base.Preconditions;
44
import me.outspending.biomesapi.wrapper.BiomeSettings;
5-
import me.outspending.biomesapi.wrapper.GrassColorModifier;
5+
import me.outspending.biomesapi.wrapper.environment.GrassColorModifier;
66
import me.outspending.biomesapi.annotations.AsOf;
77
import me.outspending.biomesapi.packet.data.BlockReplacement;
88
import me.outspending.biomesapi.registry.BiomeResourceKey;
99
import me.outspending.biomesapi.renderer.ParticleRenderer;
10+
import me.outspending.biomesapi.wrapper.environment.attribute.WrappedEnvironmentAttributeMap;
1011
import org.bukkit.Color;
1112
import org.bukkit.NamespacedKey;
1213
import org.bukkit.block.Biome;
@@ -16,11 +17,11 @@
1617
* This interface represents a custom biome in the BiomesAPI.
1718
* It provides methods to retrieve and modify the properties of the custom biome.
1819
*
19-
* @version 1.0.2
20+
* @version 1.1.0
2021
* @since 0.0.1
2122
* @author Outspending
2223
*/
23-
@AsOf("1.0.2")
24+
@AsOf("1.1.0")
2425
public interface CustomBiome {
2526

2627
/**
@@ -160,6 +161,16 @@ public interface CustomBiome {
160161
@AsOf("0.0.6")
161162
@NotNull BlockReplacement[] getBlockReplacements();
162163

164+
165+
/**
166+
* Returns the WrappedEnvironmentAttributeMap of the CustomBiome.
167+
*
168+
* @return the WrappedEnvironmentAttributeMap of the CustomBiome
169+
* @since 1.1.0
170+
*/
171+
@AsOf("1.1.0")
172+
@NotNull WrappedEnvironmentAttributeMap getEnvironmentAttributeMap();
173+
163174
/**
164175
* Sets the fog color of the CustomBiome.
165176
*
@@ -251,6 +262,16 @@ public interface CustomBiome {
251262
@AsOf("0.0.6")
252263
void setBlockReplacements(@NotNull BlockReplacement... blockReplacements);
253264

265+
266+
/**
267+
* Sets the WrappedEnvironmentAttributeMap of the CustomBiome.
268+
*
269+
* @param environmentAttributeMap the WrappedEnvironmentAttributeMap of the CustomBiome
270+
* @since 1.1.0
271+
*/
272+
@AsOf("1.1.0")
273+
void setEnvironmentAttributeMap(@NotNull WrappedEnvironmentAttributeMap environmentAttributeMap);
274+
254275
/**
255276
* Returns a new Builder instance with the properties of the CustomBiome.
256277
*
@@ -314,8 +335,10 @@ class Builder {
314335
private int dryFoliageColor = 0;
315336

316337
private GrassColorModifier grassColorModifier = GrassColorModifier.NONE;
317-
private ParticleRenderer particleRenderer = null;
338+
private ParticleRenderer particleRenderer = ParticleRenderer.EMPTY;
318339
private BlockReplacement[] blockReplacements = new BlockReplacement[0];
340+
private WrappedEnvironmentAttributeMap environmentAttributeMap = WrappedEnvironmentAttributeMap.EMPTY;
341+
319342

320343
/**
321344
* Formats a hexadecimal color string by removing the leading '#' if present.
@@ -359,6 +382,7 @@ public Builder(@NotNull CustomBiome biome) {
359382
this.grassColorModifier = biome.getGrassColorModifier();
360383
this.particleRenderer = biome.getParticleRenderer();
361384
this.blockReplacements = biome.getBlockReplacements();
385+
this.environmentAttributeMap = biome.getEnvironmentAttributeMap();
362386
}
363387

364388
/**
@@ -597,13 +621,27 @@ public Builder(@NotNull CustomBiome biome) {
597621
return this;
598622
}
599623

624+
625+
/**
626+
* This method sets the environment attribute map property of the CustomBiome.
627+
*
628+
* @param environmentAttributeMap The environment attribute map of the custom biome.
629+
* @since 1.1.0
630+
* @return The Builder object, for chaining method calls.
631+
*/
632+
@AsOf("1.1.0")
633+
public @NotNull Builder environmentAttributeMap(@NotNull WrappedEnvironmentAttributeMap environmentAttributeMap) {
634+
this.environmentAttributeMap = environmentAttributeMap;
635+
return this;
636+
}
637+
600638
/**
601639
* This method creates a new CustomBiome object with the properties set in the Builder.
602640
*
603641
* @since 0.0.1
604642
* @return a new CustomBiome object.
605643
*/
606-
@AsOf("1.0.2")
644+
@AsOf("1.1.0")
607645
public @NotNull CustomBiome build() {
608646
Preconditions.checkArgument(resourceKey != null, "Resource key must be set");
609647
Preconditions.checkArgument(settings != null, "Settings must be set");
@@ -620,7 +658,8 @@ public Builder(@NotNull CustomBiome biome) {
620658
dryFoliageColor,
621659
grassColorModifier,
622660
particleRenderer,
623-
blockReplacements
661+
blockReplacements,
662+
environmentAttributeMap
624663
);
625664
}
626665

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import io.papermc.paper.registry.RegistryAccess;
44
import io.papermc.paper.registry.RegistryKey;
55
import me.outspending.biomesapi.wrapper.BiomeSettings;
6-
import me.outspending.biomesapi.wrapper.GrassColorModifier;
6+
import me.outspending.biomesapi.wrapper.environment.GrassColorModifier;
77
import me.outspending.biomesapi.annotations.AsOf;
88
import me.outspending.biomesapi.packet.data.BlockReplacement;
99
import me.outspending.biomesapi.registry.BiomeRegistry;
1010
import me.outspending.biomesapi.registry.BiomeResourceKey;
1111
import me.outspending.biomesapi.renderer.ParticleRenderer;
12+
import me.outspending.biomesapi.wrapper.environment.attribute.WrappedEnvironmentAttributeMap;
1213
import net.minecraft.resources.Identifier;
1314
import org.bukkit.NamespacedKey;
1415
import org.bukkit.block.Biome;
@@ -18,10 +19,10 @@
1819
* This class represents a custom biome implementation.
1920
*
2021
* @author Outspending
21-
* @version 0.0.24
22+
* @version 1.1.0
2223
* @since 0.0.2
2324
*/
24-
@AsOf("0.0.24")
25+
@AsOf("1.1.0")
2526
public final class CustomBiomeImpl implements CustomBiome {
2627

2728
// Required Settings
@@ -44,6 +45,8 @@ public final class CustomBiomeImpl implements CustomBiome {
4445
private ParticleRenderer particleRenderer;
4546
private BlockReplacement[] blockReplacements;
4647

48+
private WrappedEnvironmentAttributeMap environmentAttributeMap;
49+
4750
@AsOf("0.0.2")
4851
public CustomBiomeImpl(
4952
@NotNull BiomeResourceKey resourceKey,
@@ -102,14 +105,16 @@ public CustomBiomeImpl(
102105

103106
@NotNull GrassColorModifier grassColorModifier,
104107
@NotNull ParticleRenderer particleRenderer,
105-
@NotNull BlockReplacement[] blockReplacements
108+
@NotNull BlockReplacement[] blockReplacements,
109+
@NotNull WrappedEnvironmentAttributeMap environmentAttributeMap
106110
) {
107111
this(resourceKey, settings, fogColor, waterColor, waterFogColor, skyColor, particleRenderer);
108112
this.foliageColor = foliageColor;
109113
this.grassColor = grassColor;
110114
this.dryFoliageColor = dryFoliageColor;
111115
this.grassColorModifier = grassColorModifier;
112116
this.blockReplacements = blockReplacements;
117+
this.environmentAttributeMap = environmentAttributeMap;
113118
}
114119

115120
@Override
@@ -182,6 +187,11 @@ public GrassColorModifier getGrassColorModifier() {
182187
return blockReplacements;
183188
}
184189

190+
@Override
191+
public @NotNull WrappedEnvironmentAttributeMap getEnvironmentAttributeMap() {
192+
return environmentAttributeMap;
193+
}
194+
185195
@Override
186196
public void setFogColor(int fogColor) {
187197
this.fogColor = fogColor;
@@ -231,6 +241,11 @@ public void setBlockReplacements(@NotNull BlockReplacement[] blockReplacements)
231241
this.blockReplacements = blockReplacements;
232242
}
233243

244+
@Override
245+
public void setEnvironmentAttributeMap(@NotNull WrappedEnvironmentAttributeMap environmentAttributeMap) {
246+
this.environmentAttributeMap = environmentAttributeMap;
247+
}
248+
234249
@Override
235250
public Builder toBuilder() {
236251
return new Builder(this);
@@ -266,6 +281,7 @@ public boolean isSimilar(@NotNull CustomBiome otherBiome) {
266281
return false;
267282
}
268283
}
284+
if (!this.environmentAttributeMap.equals(otherBiome.getEnvironmentAttributeMap())) return false;
269285
return true;
270286
}
271287
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.base.Preconditions;
44
import me.outspending.biomesapi.nms.BiomeLock;
5+
import me.outspending.biomesapi.registry.handlers.AttributeMapHandler;
56
import me.outspending.biomesapi.wrapper.BiomeSettings;
67
import me.outspending.biomesapi.annotations.AsOf;
78
import me.outspending.biomesapi.biome.BiomeHandler;
@@ -11,6 +12,7 @@
1112
import me.outspending.biomesapi.registry.handlers.ParticleRendererHandler;
1213
import me.outspending.biomesapi.registry.handlers.SpecialEffectsHandler;
1314
import me.outspending.biomesapi.renderer.ParticleRenderer;
15+
import me.outspending.biomesapi.wrapper.environment.attribute.WrappedEnvironmentAttributeMap;
1416
import net.minecraft.core.Registry;
1517
import net.minecraft.resources.Identifier;
1618
import net.minecraft.world.attribute.EnvironmentAttributeMap;
@@ -38,6 +40,7 @@ public class CustomBiomeRegistry implements BiomeRegistry {
3840

3941
private static final SpecialEffectsHandler SPECIAL_EFFECTS_HANDLER = new SpecialEffectsHandler();
4042
private static final ParticleRendererHandler RENDERER_HANDLER = new ParticleRendererHandler();
43+
private static final AttributeMapHandler ATTRIBUTE_MAP_HANDLER = new AttributeMapHandler();
4144

4245
//private static final String MINECRAFT_NAMESPACE = "minecraft";
4346

@@ -78,9 +81,7 @@ public void register(@NotNull CustomBiome biome) {
7881
.generationSettings(BiomeGenerationSettings.EMPTY)
7982
.setAttribute(EnvironmentAttributes.FOG_COLOR, biome.getFogColor())
8083
.setAttribute(EnvironmentAttributes.SKY_COLOR, biome.getSkyColor())
81-
.setAttribute(EnvironmentAttributes.WATER_FOG_COLOR, biome.getWaterColor())
82-
// TODO: rest of the biome settings should be added to the api
83-
;
84+
.setAttribute(EnvironmentAttributes.WATER_FOG_COLOR, biome.getWaterColor());
8485

8586
// Create a new Biome object with the settings and colors from the CustomBiome object
8687
BiomeSpecialEffects effects = SPECIAL_EFFECTS_HANDLER.build(biome);
@@ -89,13 +90,18 @@ public void register(@NotNull CustomBiome biome) {
8990
ParticleRenderer particleRenderer = biome.getParticleRenderer();
9091
RENDERER_HANDLER.handle(particleRenderer, biomeBuilder);
9192

93+
WrappedEnvironmentAttributeMap wrappedAttributeMap = biome.getEnvironmentAttributeMap();
94+
ATTRIBUTE_MAP_HANDLER.handle(wrappedAttributeMap, biomeBuilder);
95+
9296
// Register the new Biome object to the biome registry
9397
Biome createdBiome = biomeBuilder.build();
9498

9599
if (!registry.containsKey(resourceLocation)) {
96100
Registry.register(registry, resourceLocation, createdBiome);
97101
}
98102

103+
System.out.println(createdBiome.getAttributes());
104+
99105
// Add the custom biome to the list of registered biomes
100106
BiomeHandler.getRegisteredBiomes().add(biome);
101107
});
@@ -144,6 +150,9 @@ public void modify(@NotNull CustomBiome customBiome) {
144150

145151
BiomeSpecialEffects specialEffects = SPECIAL_EFFECTS_HANDLER.build(customBiome);
146152

153+
WrappedEnvironmentAttributeMap wrappedAttributeMap = customBiome.getEnvironmentAttributeMap();
154+
ATTRIBUTE_MAP_HANDLER.apply(wrappedAttributeMap, environmentAttributeMap);
155+
147156
// Time to reflect
148157
try {
149158
Field climateSettingsField = Biome.class.getDeclaredField("climateSettings");
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package me.outspending.biomesapi.registry.handlers;
2+
3+
import me.outspending.biomesapi.biome.CustomBiome;
4+
import me.outspending.biomesapi.registry.BuilderHandler;
5+
import me.outspending.biomesapi.wrapper.environment.attribute.WrappedEnvironmentAttributeMap;
6+
import net.minecraft.world.attribute.EnvironmentAttributeMap;
7+
import net.minecraft.world.level.biome.Biome;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
public class AttributeMapHandler implements BuilderHandler<Biome.BiomeBuilder, WrappedEnvironmentAttributeMap> {
12+
13+
@Override
14+
public void handle(WrappedEnvironmentAttributeMap value, Biome.@NotNull BiomeBuilder key) {
15+
if (value == null || value.empty()) return;
16+
17+
18+
value.applyToBiomeBuilder(key);
19+
}
20+
21+
22+
public void apply(WrappedEnvironmentAttributeMap wrappedEnvironmentAttributeMap, EnvironmentAttributeMap attributeMap) {
23+
if (wrappedEnvironmentAttributeMap == null || wrappedEnvironmentAttributeMap.empty()) return;
24+
25+
wrappedEnvironmentAttributeMap.applyToMap(attributeMap);
26+
}
27+
28+
29+
@Override
30+
public @Nullable WrappedEnvironmentAttributeMap build(@NotNull CustomBiome biome) {
31+
return null;
32+
}
33+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraft.world.level.biome.Biome;
88
import org.jetbrains.annotations.Contract;
99
import org.jetbrains.annotations.NotNull;
10+
import org.jetbrains.annotations.Nullable;
1011

1112
import java.util.ArrayList;
1213
import java.util.List;
@@ -38,7 +39,7 @@ public List<net.minecraft.world.attribute.AmbientParticle> create(ParticleRender
3839
}
3940

4041
@Override
41-
public ParticleRenderer build(@NotNull CustomBiome biome) {
42+
public @Nullable ParticleRenderer build(@NotNull CustomBiome biome) {
4243
return null;
4344
}
4445
}

main/src/main/java/me/outspending/biomesapi/renderer/BiomeParticle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package me.outspending.biomesapi.renderer;
22

33
import me.outspending.biomesapi.annotations.AsOf;
4-
import me.outspending.biomesapi.wrapper.AmbientParticle;
4+
import me.outspending.biomesapi.wrapper.environment.AmbientParticle;
55
import net.minecraft.core.particles.*;
66

77
/**

main/src/main/java/me/outspending/biomesapi/renderer/ParticleRenderer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package me.outspending.biomesapi.renderer;
22

33
import me.outspending.biomesapi.annotations.AsOf;
4-
import me.outspending.biomesapi.wrapper.AmbientParticle;
4+
import me.outspending.biomesapi.wrapper.environment.AmbientParticle;
55
import org.jetbrains.annotations.NotNull;
66

77
import java.util.HashMap;
@@ -21,6 +21,7 @@
2121
@AsOf("0.0.8")
2222
public record ParticleRenderer(@NotNull Map<@NotNull AmbientParticle, @NotNull Float> ambientParticles) {
2323

24+
public static final ParticleRenderer EMPTY = new ParticleRenderer(Map.of());
2425

2526
/**
2627
* Creates a new ParticleRenderer with the given ambient particles and their corresponding probabilities.

main/src/main/java/me/outspending/biomesapi/renderer/VisualElements.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package me.outspending.biomesapi.renderer;
22

3-
import me.outspending.biomesapi.wrapper.AmbientParticle;
4-
import me.outspending.biomesapi.wrapper.MoonPhase;
5-
import me.outspending.biomesapi.wrapper.WrappedEnvironmentAttribute;
3+
import me.outspending.biomesapi.wrapper.environment.AmbientParticle;
4+
import me.outspending.biomesapi.wrapper.environment.MoonPhase;
5+
import me.outspending.biomesapi.wrapper.environment.attribute.WrappedEnvironmentAttribute;
66
import net.minecraft.core.particles.ParticleOptions;
77
import net.minecraft.world.attribute.EnvironmentAttributeMap;
88
import net.minecraft.world.attribute.EnvironmentAttributes;

main/src/main/java/me/outspending/biomesapi/wrapper/BiomeSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.outspending.biomesapi.wrapper;
22

33
import me.outspending.biomesapi.annotations.AsOf;
4+
import me.outspending.biomesapi.wrapper.environment.BiomeTempModifier;
45
import org.jetbrains.annotations.NotNull;
56
import org.jetbrains.annotations.Range;
67

0 commit comments

Comments
 (0)