Skip to content

Commit 0edd85c

Browse files
authored
Use molang to fix falling leaves & firework particles' color (#5522)
* Use molang to fix firework particle color * Fix leaf particle color
1 parent 3c51e46 commit 0edd85c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelParticlesTranslator.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
2929
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.BlockParticleData;
30+
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.ColorParticleData;
3031
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.DustParticleData;
3132
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.ItemParticleData;
3233
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.Particle;
@@ -174,6 +175,33 @@ public void translate(GeyserSession session, ClientboundLevelParticlesPacket pac
174175
return packet;
175176
};
176177
}
178+
case FIREWORK -> {
179+
int dimensionId = DimensionUtils.javaToBedrock(session);
180+
return (position) -> {
181+
SpawnParticleEffectPacket particlePacket = new SpawnParticleEffectPacket();
182+
particlePacket.setIdentifier("minecraft:sparkler_emitter");
183+
particlePacket.setDimensionId(dimensionId);
184+
particlePacket.setPosition(position);
185+
particlePacket.setMolangVariablesJson(Optional.of("[{ \"name\": \"variable.color\", \"value\": { \"type\": \"member_array\", \"value\": [{\"name\": \".r\", \"value\": { \"type\": \"float\", \"value\": 1.0}},{\"name\": \".g\", \"value\": {\"type\": \"float\", \"value\": 1.0}},{\"name\": \".b\", \"value\": {\"type\": \"float\", \"value\": 1.0}},{\"name\": \".a\", \"value\": {\"type\": \"float\", \"value\": 1.0}}]}}]"));
186+
return particlePacket;
187+
};
188+
}
189+
case TINTED_LEAVES -> {
190+
int dimensionId = DimensionUtils.javaToBedrock(session);
191+
ColorParticleData data = (ColorParticleData) particle.getData();
192+
int rgbData = data.getColor();
193+
float red = ((rgbData >> 16) & 0xFF) / 255f;
194+
float green = ((rgbData >> 8) & 0xFF) / 255f;
195+
float blue = (rgbData & 0xFF) / 255f;
196+
return (position) -> {
197+
SpawnParticleEffectPacket particlePacket = new SpawnParticleEffectPacket();
198+
particlePacket.setIdentifier("minecraft:biome_tinted_leaves_particle");
199+
particlePacket.setDimensionId(dimensionId);
200+
particlePacket.setPosition(position);
201+
particlePacket.setMolangVariablesJson(Optional.of("[{ \"name\": \"variable.color\", \"value\": { \"type\": \"member_array\", \"value\": [{\"name\": \".r\", \"value\": { \"type\": \"float\", \"value\": " + red + "}},{\"name\": \".g\", \"value\": {\"type\": \"float\", \"value\": " + green + "}},{\"name\": \".b\", \"value\": {\"type\": \"float\", \"value\": " + blue + "}}]}}]"));
202+
return particlePacket;
203+
};
204+
}
177205
default -> {
178206
ParticleMapping particleMapping = Registries.PARTICLES.get(particle.getType());
179207
if (particleMapping == null) { //TODO ensure no particle can be null

0 commit comments

Comments
 (0)