mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-01 00:10:19 +01:00
explosion packet fix, add bundle packet, rename tick rate packet to match wiki.vg (#103)
* packet fixes
* explosion packet touchup
(cherry picked from commit d576228655
)
This commit is contained in:
parent
6f6a54857e
commit
0bb237f737
@ -0,0 +1,26 @@
|
|||||||
|
package net.minestom.server.network.packet.server.play;
|
||||||
|
|
||||||
|
import net.minestom.server.network.ConnectionState;
|
||||||
|
import net.minestom.server.network.NetworkBuffer;
|
||||||
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
|
import net.minestom.server.utils.PacketUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public record BundlePacket() implements ServerPacket {
|
||||||
|
public BundlePacket(@NotNull NetworkBuffer reader) {
|
||||||
|
this();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(@NotNull NetworkBuffer writer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId(@NotNull ConnectionState state) {
|
||||||
|
return switch (state) {
|
||||||
|
case PLAY -> ServerPacketIdentifier.BUNDLE;
|
||||||
|
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -4,17 +4,85 @@ import net.minestom.server.network.ConnectionState;
|
|||||||
import net.minestom.server.network.NetworkBuffer;
|
import net.minestom.server.network.NetworkBuffer;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
|
import net.minestom.server.particle.Particle;
|
||||||
|
import net.minestom.server.sound.SoundEvent;
|
||||||
import net.minestom.server.utils.PacketUtils;
|
import net.minestom.server.utils.PacketUtils;
|
||||||
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import static net.minestom.server.network.NetworkBuffer.*;
|
import static net.minestom.server.network.NetworkBuffer.*;
|
||||||
|
|
||||||
public record ExplosionPacket(double x, double y, double z, float radius, byte @NotNull [] records,
|
public record ExplosionPacket(double x, double y, double z, float radius,
|
||||||
float playerMotionX, float playerMotionY, float playerMotionZ) implements ServerPacket {
|
byte @NotNull [] records,
|
||||||
|
float playerMotionX, float playerMotionY, float playerMotionZ,
|
||||||
|
@NotNull BlockInteraction blockInteraction,
|
||||||
|
int smallParticleId, byte @NotNull [] smallParticleData,
|
||||||
|
int largeParticleId, byte @NotNull [] largeParticleData,
|
||||||
|
@NotNull String soundName, boolean hasFixedSoundRange, float soundRange) implements ServerPacket {
|
||||||
|
private static @NotNull ExplosionPacket fromReader(@NotNull NetworkBuffer reader) {
|
||||||
|
double x = reader.read(DOUBLE), y = reader.read(DOUBLE), z = reader.read(DOUBLE);
|
||||||
|
float radius = reader.read(FLOAT);
|
||||||
|
byte[] records = reader.readBytes(reader.read(VAR_INT) * 3);
|
||||||
|
float playerMotionX = reader.read(FLOAT), playerMotionY = reader.read(FLOAT), playerMotionZ = reader.read(FLOAT);
|
||||||
|
BlockInteraction blockInteraction = BlockInteraction.values()[reader.read(VAR_INT)];
|
||||||
|
int smallParticleId = reader.read(VAR_INT);
|
||||||
|
byte[] smallParticleData = readParticleData(reader, Particle.fromId(smallParticleId));
|
||||||
|
int largeParticleId = reader.read(VAR_INT);
|
||||||
|
byte[] largeParticleData = readParticleData(reader, Particle.fromId(largeParticleId));
|
||||||
|
String soundName = reader.read(STRING);
|
||||||
|
boolean hasFixedSoundRange = reader.read(BOOLEAN);
|
||||||
|
float soundRange = hasFixedSoundRange ? reader.read(FLOAT) : 0;
|
||||||
|
return new ExplosionPacket(x, y, z, radius, records, playerMotionX, playerMotionY, playerMotionZ,
|
||||||
|
blockInteraction, smallParticleId, smallParticleData, largeParticleId, largeParticleData,
|
||||||
|
soundName, hasFixedSoundRange, soundRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte @NotNull [] readParticleData(@NotNull NetworkBuffer reader, Particle particle) {
|
||||||
|
//Need to do this because particle data isn't at the end of the packet
|
||||||
|
BinaryWriter writer = new BinaryWriter();
|
||||||
|
if (particle.equals(Particle.BLOCK) || particle.equals(Particle.BLOCK_MARKER) || particle.equals(Particle.FALLING_DUST) || particle.equals(Particle.SHRIEK)) {
|
||||||
|
writer.writeVarInt(reader.read(VAR_INT));
|
||||||
|
}
|
||||||
|
else if (particle.equals(Particle.VIBRATION)) {
|
||||||
|
writer.writeVarInt(reader.read(VAR_INT));
|
||||||
|
writer.writeBlockPosition(reader.read(BLOCK_POSITION));
|
||||||
|
writer.writeVarInt(reader.read(VAR_INT));
|
||||||
|
writer.writeFloat(reader.read(FLOAT));
|
||||||
|
writer.writeVarInt(reader.read(VAR_INT));
|
||||||
|
}
|
||||||
|
else if (particle.equals(Particle.SCULK_CHARGE)) {
|
||||||
|
writer.writeFloat(reader.read(FLOAT));
|
||||||
|
return writer.toByteArray();
|
||||||
|
}
|
||||||
|
else if (particle.equals(Particle.ITEM)) {
|
||||||
|
writer.writeItemStack(reader.read(ITEM));
|
||||||
|
}
|
||||||
|
else if (particle.equals(Particle.DUST_COLOR_TRANSITION)) {
|
||||||
|
for (int i = 0; i < 7; i++) writer.writeFloat(reader.read(FLOAT));
|
||||||
|
}
|
||||||
|
else if (particle.equals(Particle.DUST)) {
|
||||||
|
for (int i = 0; i < 4; i++) writer.writeFloat(reader.read(FLOAT));
|
||||||
|
}
|
||||||
|
|
||||||
|
return writer.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
public ExplosionPacket(@NotNull NetworkBuffer reader) {
|
public ExplosionPacket(@NotNull NetworkBuffer reader) {
|
||||||
this(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE),
|
this(fromReader(reader));
|
||||||
reader.read(FLOAT), reader.readBytes(reader.read(VAR_INT) * 3),
|
}
|
||||||
reader.read(FLOAT), reader.read(FLOAT), reader.read(FLOAT));
|
|
||||||
|
public ExplosionPacket(double x, double y, double z, float radius, byte @NotNull [] records,
|
||||||
|
float playerMotionX, float playerMotionY, float playerMotionZ) {
|
||||||
|
this(x, y, z, radius, records, playerMotionX, playerMotionY, playerMotionZ,
|
||||||
|
BlockInteraction.DESTROY, Particle.EXPLOSION.id(), new byte[] {},
|
||||||
|
Particle.EXPLOSION_EMITTER.id(), new byte[] {},
|
||||||
|
SoundEvent.ENTITY_GENERIC_EXPLODE.name(), false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExplosionPacket(@NotNull ExplosionPacket packet) {
|
||||||
|
this(packet.x, packet.y, packet.z, packet.radius, packet.records, packet.playerMotionX, packet.playerMotionY, packet.playerMotionZ,
|
||||||
|
packet.blockInteraction, packet.smallParticleId, packet.smallParticleData, packet.largeParticleId, packet.largeParticleData,
|
||||||
|
packet.soundName, packet.hasFixedSoundRange, packet.soundRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -28,6 +96,14 @@ public record ExplosionPacket(double x, double y, double z, float radius, byte @
|
|||||||
writer.write(FLOAT, playerMotionX);
|
writer.write(FLOAT, playerMotionX);
|
||||||
writer.write(FLOAT, playerMotionY);
|
writer.write(FLOAT, playerMotionY);
|
||||||
writer.write(FLOAT, playerMotionZ);
|
writer.write(FLOAT, playerMotionZ);
|
||||||
|
writer.write(VAR_INT, blockInteraction.ordinal());
|
||||||
|
writer.write(VAR_INT, smallParticleId);
|
||||||
|
writer.write(RAW_BYTES, smallParticleData);
|
||||||
|
writer.write(VAR_INT, largeParticleId);
|
||||||
|
writer.write(RAW_BYTES, largeParticleData);
|
||||||
|
writer.write(STRING, soundName);
|
||||||
|
writer.write(BOOLEAN, hasFixedSoundRange);
|
||||||
|
if (hasFixedSoundRange) writer.write(FLOAT, soundRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,4 +113,8 @@ public record ExplosionPacket(double x, double y, double z, float radius, byte @
|
|||||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum BlockInteraction {
|
||||||
|
KEEP, DESTROY, DESTROY_WITH_DECAY, TRIGGER_BLOCK
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import static net.minestom.server.network.NetworkBuffer.*;
|
import static net.minestom.server.network.NetworkBuffer.*;
|
||||||
|
|
||||||
public record TickStatePacket(float tickRate, boolean isFrozen) implements ServerPacket {
|
public record SetTickStatePacket(float tickRate, boolean isFrozen) implements ServerPacket {
|
||||||
|
|
||||||
public TickStatePacket(@NotNull NetworkBuffer reader) {
|
public SetTickStatePacket(@NotNull NetworkBuffer reader) {
|
||||||
this(reader.read(FLOAT), reader.read(BOOLEAN));
|
this(reader.read(FLOAT), reader.read(BOOLEAN));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user