Skip to content

Commit d9f4ff5

Browse files
authored
Merge pull request #2 from LumaLibre/feat/enhanced-particle-api
feat(enhanced-particle-api): improve the particle api
2 parents 2ad3b5b + 46b2291 commit d9f4ff5

26 files changed

Lines changed: 903 additions & 312 deletions

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

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import me.outspending.biomesapi.annotations.AsOf;
77
import me.outspending.biomesapi.packet.data.BlockReplacement;
88
import me.outspending.biomesapi.registry.BiomeResourceKey;
9-
import me.outspending.biomesapi.renderer.ParticleRenderer;
109
import me.outspending.biomesapi.wrapper.environment.attribute.WrappedEnvironmentAttributeMap;
10+
import me.outspending.biomesapi.wrapper.environment.particles.ParticleCatalog;
1111
import org.bukkit.Color;
1212
import org.bukkit.NamespacedKey;
1313
import org.bukkit.block.Biome;
@@ -149,9 +149,23 @@ public interface CustomBiome {
149149
*
150150
* @return the ParticleRenderer of the CustomBiome
151151
* @since 0.0.1
152+
* @deprecated use {@link #getParticleCatalog()} instead.
152153
*/
153154
@AsOf("0.0.1")
154-
ParticleRenderer getParticleRenderer();
155+
@Deprecated(forRemoval = true, since = "1.1.0")
156+
@SuppressWarnings("removal")
157+
default me.outspending.biomesapi.renderer.ParticleRenderer getParticleRenderer() {
158+
throw new UnsupportedOperationException("Use getParticleCatalog() instead.");
159+
}
160+
161+
/**
162+
* Returns the ParticleRenderer of the CustomBiome.
163+
*
164+
* @return the ParticleRenderer of the CustomBiome
165+
* @since 1.1.0
166+
*/
167+
@AsOf("1.1.0")
168+
ParticleCatalog getParticleCatalog();
155169

156170
/**
157171
* Returns the BlockReplacements of the CustomBiome.
@@ -248,10 +262,24 @@ public interface CustomBiome {
248262
* Sets the ParticleRenderer of the CustomBiome.
249263
*
250264
* @param particleRenderer the ParticleRenderer of the CustomBiome
251-
* @since 0.0.5
265+
* @since 0.0.1
266+
* @deprecated use {@link #setParticleCatalog(ParticleCatalog)} instead.
252267
*/
253-
@AsOf("0.0.5")
254-
void setParticleRenderer(@NotNull ParticleRenderer particleRenderer);
268+
@AsOf("0.0.1")
269+
@Deprecated(forRemoval = true, since = "1.1.0")
270+
@SuppressWarnings("removal")
271+
default void setParticleRenderer(@NotNull me.outspending.biomesapi.renderer.ParticleRenderer particleRenderer) {
272+
setParticleCatalog(ParticleCatalog.fromParticleRenderer(particleRenderer));
273+
}
274+
275+
/**
276+
* Sets the ParticleRenderer of the CustomBiome.
277+
*
278+
* @param particleCatalog the ParticleRenderer of the CustomBiome
279+
* @since 1.1.0
280+
*/
281+
@AsOf("1.1.0")
282+
void setParticleCatalog(@NotNull ParticleCatalog particleCatalog);
255283

256284
/**
257285
* Sets the BlockReplacements of the CustomBiome.
@@ -336,7 +364,7 @@ class Builder {
336364
private @Nullable Integer dryFoliageColor = -1;
337365

338366
private GrassColorModifier grassColorModifier = GrassColorModifier.NONE;
339-
private ParticleRenderer particleRenderer = ParticleRenderer.EMPTY;
367+
private ParticleCatalog particleCatalog = ParticleCatalog.EMPTY;
340368
private BlockReplacement[] blockReplacements = new BlockReplacement[0];
341369
private WrappedEnvironmentAttributeMap environmentAttributeMap = WrappedEnvironmentAttributeMap.EMPTY;
342370

@@ -394,7 +422,7 @@ public Builder(@NotNull CustomBiome biome) {
394422
this.grassColor = biome.getGrassColor();
395423
this.dryFoliageColor = biome.getDryFoliageColor();
396424
this.grassColorModifier = biome.getGrassColorModifier();
397-
this.particleRenderer = biome.getParticleRenderer();
425+
this.particleCatalog = biome.getParticleCatalog();
398426
this.blockReplacements = biome.getBlockReplacements();
399427
this.environmentAttributeMap = biome.getEnvironmentAttributeMap();
400428
}
@@ -612,12 +640,28 @@ public Builder(@NotNull CustomBiome biome) {
612640
* This method sets the particle renderer property of the CustomBiome.
613641
*
614642
* @param particleRenderer The particle renderer of the custom biome.
615-
* @version 0.0.1
643+
* @since 0.0.1
616644
* @return The Builder object, for chaining method calls.
645+
* @deprecated use {@link #particleCatalog(ParticleCatalog)} instead.
617646
*/
618647
@AsOf("0.0.1")
619-
public @NotNull Builder particleRenderer(@NotNull ParticleRenderer particleRenderer) {
620-
this.particleRenderer = particleRenderer;
648+
@Deprecated(forRemoval = true, since = "1.1.0")
649+
@SuppressWarnings("removal")
650+
public @NotNull Builder particleRenderer(@NotNull me.outspending.biomesapi.renderer.ParticleRenderer particleRenderer) {
651+
this.particleCatalog = ParticleCatalog.fromParticleRenderer(particleRenderer);
652+
return this;
653+
}
654+
655+
/**
656+
* This method sets the particle catalog property of the CustomBiome.
657+
*
658+
* @param particleCatalog The particle catalog of the custom biome.
659+
* @since 1.1.0
660+
* @return The Builder object, for chaining method calls.
661+
*/
662+
@AsOf("1.1.0")
663+
public @NotNull Builder particleCatalog(@NotNull ParticleCatalog particleCatalog) {
664+
this.particleCatalog = particleCatalog;
621665
return this;
622666
}
623667

@@ -671,7 +715,7 @@ public Builder(@NotNull CustomBiome biome) {
671715
grassColor,
672716
dryFoliageColor,
673717
grassColorModifier,
674-
particleRenderer,
718+
particleCatalog,
675719
blockReplacements,
676720
environmentAttributeMap
677721
);

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@
88
import me.outspending.biomesapi.packet.data.BlockReplacement;
99
import me.outspending.biomesapi.registry.BiomeRegistry;
1010
import me.outspending.biomesapi.registry.BiomeResourceKey;
11-
import me.outspending.biomesapi.renderer.ParticleRenderer;
1211
import me.outspending.biomesapi.wrapper.environment.attribute.WrappedEnvironmentAttributeMap;
12+
import me.outspending.biomesapi.wrapper.environment.particles.ParticleCatalog;
1313
import net.minecraft.resources.Identifier;
1414
import org.bukkit.NamespacedKey;
1515
import org.bukkit.block.Biome;
16+
import org.jetbrains.annotations.ApiStatus;
1617
import org.jetbrains.annotations.NotNull;
1718
import org.jetbrains.annotations.Nullable;
1819

20+
import java.util.Objects;
21+
1922
/**
2023
* This class represents a custom biome implementation.
2124
*
2225
* @author Outspending
2326
* @version 1.1.0
2427
* @since 0.0.2
2528
*/
29+
@ApiStatus.Internal
2630
@AsOf("1.1.0")
2731
public final class CustomBiomeImpl implements CustomBiome {
2832

@@ -43,7 +47,7 @@ public final class CustomBiomeImpl implements CustomBiome {
4347

4448
// Optional Settings
4549
private GrassColorModifier grassColorModifier = GrassColorModifier.NONE;
46-
private ParticleRenderer particleRenderer = ParticleRenderer.EMPTY;
50+
private ParticleCatalog particleCatalog = ParticleCatalog.EMPTY;
4751
private BlockReplacement[] blockReplacements = new BlockReplacement[0];
4852

4953
private WrappedEnvironmentAttributeMap environmentAttributeMap = WrappedEnvironmentAttributeMap.EMPTY;
@@ -58,11 +62,11 @@ public CustomBiomeImpl(
5862
@Nullable Integer waterFogColor,
5963
@Nullable Integer skyColor,
6064

61-
@NotNull ParticleRenderer particleRenderer
65+
@NotNull ParticleCatalog particleCatalog
6266
) {
6367
this.resourceKey = resourceKey;
6468
this.settings = settings;
65-
this.particleRenderer = particleRenderer;
69+
this.particleCatalog = particleCatalog;
6670

6771
this.fogColor = fogColor;
6872
this.waterColor = waterColor;
@@ -83,9 +87,9 @@ public CustomBiomeImpl(
8387
@Nullable Integer foliageColor,
8488
@Nullable Integer grassColor,
8589

86-
@NotNull ParticleRenderer particleRenderer
90+
@NotNull ParticleCatalog particleCatalog
8791
) {
88-
this(resourceKey, settings, fogColor, waterColor, waterFogColor, skyColor, particleRenderer);
92+
this(resourceKey, settings, fogColor, waterColor, waterFogColor, skyColor, particleCatalog);
8993
this.foliageColor = foliageColor;
9094
this.grassColor = grassColor;
9195
this.blockReplacements = new BlockReplacement[0];
@@ -105,11 +109,11 @@ public CustomBiomeImpl(
105109
@Nullable Integer dryFoliageColor,
106110

107111
@NotNull GrassColorModifier grassColorModifier,
108-
@NotNull ParticleRenderer particleRenderer,
112+
@NotNull ParticleCatalog particleCatalog,
109113
@NotNull BlockReplacement[] blockReplacements,
110114
@NotNull WrappedEnvironmentAttributeMap environmentAttributeMap
111115
) {
112-
this(resourceKey, settings, fogColor, waterColor, waterFogColor, skyColor, particleRenderer);
116+
this(resourceKey, settings, fogColor, waterColor, waterFogColor, skyColor, particleCatalog);
113117
this.foliageColor = foliageColor;
114118
this.grassColor = grassColor;
115119
this.dryFoliageColor = dryFoliageColor;
@@ -179,8 +183,8 @@ public GrassColorModifier getGrassColorModifier() {
179183
}
180184

181185
@Override
182-
public @NotNull ParticleRenderer getParticleRenderer() {
183-
return particleRenderer;
186+
public @NotNull ParticleCatalog getParticleCatalog() {
187+
return particleCatalog;
184188
}
185189

186190
@Override
@@ -233,8 +237,8 @@ public void setGrassColorModifier(@NotNull GrassColorModifier grassColorModifier
233237
}
234238

235239
@Override
236-
public void setParticleRenderer(@NotNull ParticleRenderer particleRenderer) {
237-
this.particleRenderer = particleRenderer;
240+
public void setParticleCatalog(@NotNull ParticleCatalog particleCatalog) {
241+
this.particleCatalog = particleCatalog;
238242
}
239243

240244
@Override
@@ -262,20 +266,20 @@ public void modify() {
262266
BiomeRegistry.newRegistry().modify(this);
263267
}
264268

265-
@Override
269+
@Override // TODO: cleanup
266270
public boolean isSimilar(@NotNull CustomBiome otherBiome) {
267271
if (this == otherBiome) return true;
268272
if (!this.resourceKey.equals(otherBiome.getResourceKey())) return false;
269273
if (!this.settings.equals(otherBiome.getSettings())) return false;
270-
if (this.fogColor != otherBiome.getFogColor()) return false;
274+
if (!Objects.equals(this.fogColor, otherBiome.getFogColor())) return false;
271275
if (this.waterColor != otherBiome.getWaterColor()) return false;
272-
if (this.waterFogColor != otherBiome.getWaterFogColor()) return false;
273-
if (this.skyColor != otherBiome.getSkyColor()) return false;
274-
if (this.foliageColor != otherBiome.getFoliageColor()) return false;
275-
if (this.grassColor != otherBiome.getGrassColor()) return false;
276-
if (this.dryFoliageColor != otherBiome.getDryFoliageColor()) return false;
276+
if (!Objects.equals(this.waterFogColor, otherBiome.getWaterFogColor())) return false;
277+
if (!Objects.equals(this.skyColor, otherBiome.getSkyColor())) return false;
278+
if (!Objects.equals(this.foliageColor, otherBiome.getFoliageColor())) return false;
279+
if (!Objects.equals(this.grassColor, otherBiome.getGrassColor())) return false;
280+
if (!Objects.equals(this.dryFoliageColor, otherBiome.getDryFoliageColor())) return false;
277281
if (!this.grassColorModifier.equals(otherBiome.getGrassColorModifier())) return false;
278-
if (!this.particleRenderer.equals(otherBiome.getParticleRenderer())) return false;
282+
if (!this.particleCatalog.equals(otherBiome.getParticleCatalog())) return false;
279283
if (this.blockReplacements.length != otherBiome.getBlockReplacements().length) return false;
280284
for (int i = 0; i < this.blockReplacements.length; i++) {
281285
if (!this.blockReplacements[i].equals(otherBiome.getBlockReplacements()[i])) {

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import me.outspending.biomesapi.biome.CustomBiome;
1010
import me.outspending.biomesapi.nms.NMS;
1111
import me.outspending.biomesapi.nms.NMSHandler;
12-
import me.outspending.biomesapi.registry.handlers.ParticleRendererHandler;
12+
import me.outspending.biomesapi.registry.handlers.ParticleCatalogHandler;
1313
import me.outspending.biomesapi.registry.handlers.SpecialEffectsHandler;
14-
import me.outspending.biomesapi.renderer.ParticleRenderer;
1514
import me.outspending.biomesapi.wrapper.environment.attribute.WrappedEnvironmentAttributeMap;
15+
import me.outspending.biomesapi.wrapper.environment.particles.ParticleCatalog;
1616
import net.minecraft.core.Registry;
1717
import net.minecraft.resources.Identifier;
1818
import net.minecraft.world.attribute.EnvironmentAttributeMap;
@@ -39,10 +39,9 @@
3939
public class CustomBiomeRegistry implements BiomeRegistry {
4040

4141
private static final SpecialEffectsHandler SPECIAL_EFFECTS_HANDLER = new SpecialEffectsHandler();
42-
private static final ParticleRendererHandler RENDERER_HANDLER = new ParticleRendererHandler();
42+
private static final ParticleCatalogHandler PARTICLE_CATALOG_HANDLER = new ParticleCatalogHandler();
4343
private static final AttributeMapHandler ATTRIBUTE_MAP_HANDLER = new AttributeMapHandler();
4444

45-
//private static final String MINECRAFT_NAMESPACE = "minecraft";
4645

4746
/**
4847
* This method registers a custom biome to a Minecraft server.
@@ -59,7 +58,6 @@ public class CustomBiomeRegistry implements BiomeRegistry {
5958
@SuppressWarnings("unchecked")
6059
public void register(@NotNull CustomBiome biome) {
6160
Preconditions.checkNotNull(biome, "biome cannot be null");
62-
//Preconditions.checkArgument(!biome.toNamespacedKey().namespace().equals(MINECRAFT_NAMESPACE), "Illegal namespace: %s", MINECRAFT_NAMESPACE);
6361

6462
BiomeLock.unlock(() -> {
6563

@@ -95,8 +93,8 @@ public void register(@NotNull CustomBiome biome) {
9593
BiomeSpecialEffects effects = SPECIAL_EFFECTS_HANDLER.build(biome);
9694
SPECIAL_EFFECTS_HANDLER.handle(effects, biomeBuilder);
9795

98-
ParticleRenderer particleRenderer = biome.getParticleRenderer();
99-
RENDERER_HANDLER.handle(particleRenderer, biomeBuilder);
96+
ParticleCatalog particleCatalog = biome.getParticleCatalog();
97+
PARTICLE_CATALOG_HANDLER.handle(particleCatalog, biomeBuilder);
10098

10199
WrappedEnvironmentAttributeMap wrappedAttributeMap = biome.getEnvironmentAttributeMap();
102100
ATTRIBUTE_MAP_HANDLER.handle(wrappedAttributeMap, biomeBuilder);
@@ -143,8 +141,8 @@ public void modify(@NotNull CustomBiome customBiome) {
143141

144142
// Rebuild biome components
145143
Biome.ClimateSettings climateSettings = new Biome.ClimateSettings(settings.hasPrecipitation(), settings.temperature(), settings.modifier().getModifier(), settings.downfall());
146-
ParticleRenderer particleRenderer = customBiome.getParticleRenderer();
147-
List<net.minecraft.world.attribute.AmbientParticle> particles = RENDERER_HANDLER.create(particleRenderer);
144+
ParticleCatalog particleCatalog = customBiome.getParticleCatalog();
145+
List<net.minecraft.world.attribute.AmbientParticle> particles = PARTICLE_CATALOG_HANDLER.create(particleCatalog);
148146

149147

150148
EnvironmentAttributeMap.Builder environmentAttributeMapBuilder = EnvironmentAttributeMap.builder()

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class AttributeMapHandler implements BuilderHandler<Biome.BiomeBuilder, W
1414
public void handle(WrappedEnvironmentAttributeMap value, Biome.@NotNull BiomeBuilder key) {
1515
if (value == null || value.empty()) return;
1616

17-
1817
value.applyToBiomeBuilder(key);
1918
}
2019

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.particles.ParticleCatalog;
6+
import net.minecraft.world.attribute.AmbientParticle;
7+
import net.minecraft.world.attribute.EnvironmentAttributes;
8+
import net.minecraft.world.level.biome.Biome;
9+
import org.jetbrains.annotations.Contract;
10+
import org.jetbrains.annotations.NotNull;
11+
import org.jetbrains.annotations.Nullable;
12+
13+
import java.util.List;
14+
15+
public class ParticleCatalogHandler implements BuilderHandler<Biome.BiomeBuilder, ParticleCatalog> {
16+
17+
@Override
18+
public void handle(ParticleCatalog value, @NotNull Biome.BiomeBuilder key) {
19+
if (value == null) return;
20+
21+
List<AmbientParticle> minecraftAmbientParticles = create(value);
22+
23+
key.setAttribute(EnvironmentAttributes.AMBIENT_PARTICLES, minecraftAmbientParticles);
24+
}
25+
26+
@Contract("null -> null")
27+
public List<net.minecraft.world.attribute.AmbientParticle> create(ParticleCatalog value) {
28+
if (value == null) return null;
29+
30+
return value.delegateParticles();
31+
}
32+
33+
@Override
34+
public @Nullable ParticleCatalog build(@NotNull CustomBiome biome) {
35+
return null;
36+
}
37+
}

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

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)