-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix AmbientParticle serialization, update to 1.4.2
- Loading branch information
1 parent
298768d
commit 1398ab0
Showing
8 changed files
with
83 additions
and
36 deletions.
There are no files selected for viewing
31 changes: 14 additions & 17 deletions
31
api/src/main/java/com/owen1212055/biomevisuals/api/types/biome/effect/AmbientParticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,42 @@ | ||
package com.owen1212055.biomevisuals.api.types.biome.effect; | ||
|
||
import com.google.gson.JsonObject; | ||
import org.bukkit.Particle; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class AmbientParticle { | ||
|
||
@NotNull | ||
private final Particle particle; | ||
@Nullable | ||
private final Object data; | ||
private final JsonObject particle; | ||
private final float probability; | ||
|
||
private AmbientParticle(@NotNull Particle particle, @Nullable Object data, float probability) { | ||
this.particle = particle; | ||
this.data = data; | ||
private AmbientParticle( @NotNull JsonObject particleData, float probability) { | ||
this.particle = particleData; | ||
this.probability = probability; | ||
} | ||
|
||
@NotNull | ||
public static AmbientParticle of(@NotNull Particle particle, float probability, @Nullable Object data) { | ||
return new AmbientParticle(particle, data, probability); | ||
public static AmbientParticle of(float probability, @NotNull JsonObject particleData) { | ||
return new AmbientParticle(particleData, probability); | ||
} | ||
|
||
@NotNull | ||
public static AmbientParticle of(@NotNull Particle particle, float probability) { | ||
return new AmbientParticle(particle, null, probability); | ||
public static AmbientParticle of(@NotNull Particle particle, float probability, @Nullable Object data) { | ||
return new AmbientParticle(ParticleDataSerializer.of().serialize(particle, data), probability); | ||
} | ||
|
||
@NotNull | ||
public Particle getParticle() { | ||
return particle; | ||
} | ||
|
||
@Nullable | ||
public Object getData() { | ||
return data; | ||
public static AmbientParticle of(@NotNull Particle particle, float probability) { | ||
return new AmbientParticle(ParticleDataSerializer.of().serialize(particle, null), probability); | ||
} | ||
|
||
public float getProbability() { | ||
return probability; | ||
} | ||
|
||
@NotNull | ||
public JsonObject getParticle() { | ||
return particle; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...main/java/com/owen1212055/biomevisuals/api/types/biome/effect/ParticleDataSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.owen1212055.biomevisuals.api.types.biome.effect; | ||
|
||
import com.google.gson.JsonObject; | ||
import org.bukkit.Particle; | ||
|
||
public interface ParticleDataSerializer { | ||
|
||
static ParticleDataSerializer of() { | ||
return ParticleDataSerializerProvider.INSTANCE; | ||
} | ||
|
||
JsonObject serialize(Particle particle, Object data); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...a/com/owen1212055/biomevisuals/api/types/biome/effect/ParticleDataSerializerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.owen1212055.biomevisuals.api.types.biome.effect; | ||
|
||
import java.util.ServiceLoader; | ||
|
||
class ParticleDataSerializerProvider { | ||
|
||
static final ParticleDataSerializer INSTANCE = ServiceLoader.load(ParticleDataSerializer.class, ParticleDataSerializer.class.getClassLoader()) | ||
.findFirst() | ||
.orElseThrow(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
nms/src/main/java/com/owen1212055/biomevisuals/nms/ParticleDataSerializerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.owen1212055.biomevisuals.nms; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.mojang.serialization.JsonOps; | ||
import com.owen1212055.biomevisuals.api.types.biome.effect.ParticleDataSerializer; | ||
import net.minecraft.core.particles.ParticleTypes; | ||
import org.bukkit.Particle; | ||
import org.bukkit.craftbukkit.v1_19_R3.CraftParticle; | ||
|
||
public class ParticleDataSerializerImpl implements ParticleDataSerializer { | ||
@Override | ||
public JsonObject serialize(Particle particle, Object data) { | ||
return (JsonObject) ParticleTypes.CODEC.encode(CraftParticle.toNMS(particle, data), JsonOps.INSTANCE, JsonOps.INSTANCE.empty()).get().orThrow(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...A-INF/services/com.owen1212055.biomevisuals.api.types.biome.effect.ParticleDataSerializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.owen1212055.biomevisuals.nms.ParticleDataSerializerImpl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: BiomeVisuals | ||
version: '1.4.1' | ||
version: '1.4.2' | ||
main: com.owen1212055.biomevisuals.Main | ||
api-version: 1.19 | ||
authors: [ Owen1212055 ] |