3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-09-28 06:01:10 +02:00

Limit particle amount in LevelParticlesPacket (#4802)

Dieser Commit ist enthalten in:
AJ Ferguson 2024-06-28 22:55:36 -04:00 committet von GitHub
Ursprung ca2312c7f6
Commit 130b27203f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -60,6 +60,7 @@ import java.util.function.Function;
@Translator(packet = ClientboundLevelParticlesPacket.class) @Translator(packet = ClientboundLevelParticlesPacket.class)
public class JavaLevelParticlesTranslator extends PacketTranslator<ClientboundLevelParticlesPacket> { public class JavaLevelParticlesTranslator extends PacketTranslator<ClientboundLevelParticlesPacket> {
private static final int MAX_PARTICLES = 100;
@Override @Override
public void translate(GeyserSession session, ClientboundLevelParticlesPacket packet) { public void translate(GeyserSession session, ClientboundLevelParticlesPacket packet) {
@ -71,7 +72,8 @@ public class JavaLevelParticlesTranslator extends PacketTranslator<ClientboundLe
session.sendUpstreamPacket(particleCreateFunction.apply(position)); session.sendUpstreamPacket(particleCreateFunction.apply(position));
} else { } else {
Random random = ThreadLocalRandom.current(); Random random = ThreadLocalRandom.current();
for (int i = 0; i < packet.getAmount(); i++) { int amount = Math.min(MAX_PARTICLES, packet.getAmount());
for (int i = 0; i < amount; i++) {
double offsetX = random.nextGaussian() * (double) packet.getOffsetX(); double offsetX = random.nextGaussian() * (double) packet.getOffsetX();
double offsetY = random.nextGaussian() * (double) packet.getOffsetY(); double offsetY = random.nextGaussian() * (double) packet.getOffsetY();
double offsetZ = random.nextGaussian() * (double) packet.getOffsetZ(); double offsetZ = random.nextGaussian() * (double) packet.getOffsetZ();
@ -213,4 +215,4 @@ public class JavaLevelParticlesTranslator extends PacketTranslator<ClientboundLe
.putFloat("z", position.getZ()) .putFloat("z", position.getZ())
.build(); .build();
} }
} }