mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2026-02-11 03:16:14 +01:00
Chunk packet. Counting players and kicking if too many
This commit is contained in:
@@ -120,6 +120,27 @@ public class ByteMessage extends ByteBuf {
|
||||
}
|
||||
}
|
||||
|
||||
public void writeVarIntArray(int[] array) {
|
||||
writeVarInt(array.length);
|
||||
for (int i : array) {
|
||||
writeVarInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCompoundTagArray(CompoundBinaryTag[] compoundTags) {
|
||||
try {
|
||||
ByteBufOutputStream stream = new ByteBufOutputStream(buf);
|
||||
|
||||
writeVarInt(compoundTags.length);
|
||||
|
||||
for (CompoundBinaryTag tag : compoundTags){
|
||||
BinaryTagIO.writeDataOutput(tag, stream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new EncoderException("Cannot write NBT CompoundTag");
|
||||
}
|
||||
}
|
||||
|
||||
public CompoundBinaryTag readCompoundTag() {
|
||||
try {
|
||||
return BinaryTagIO.readDataInput(new ByteBufInputStream(buf));
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package ru.nanit.limbo.protocol.packets.play;
|
||||
|
||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
import ru.nanit.limbo.protocol.ByteMessage;
|
||||
import ru.nanit.limbo.protocol.PacketOut;
|
||||
import ru.nanit.limbo.protocol.registry.Version;
|
||||
|
||||
public class PacketChunkData implements PacketOut {
|
||||
|
||||
private int chunkX;
|
||||
private int chunkZ;
|
||||
private boolean fullChunk;
|
||||
private int primaryBitMask;
|
||||
private CompoundBinaryTag heightMaps;
|
||||
private int[] biomes;
|
||||
private byte[] data;
|
||||
private CompoundBinaryTag[] blockEntities;
|
||||
|
||||
public void setChunkX(int chunkX) {
|
||||
this.chunkX = chunkX;
|
||||
}
|
||||
|
||||
public void setChunkZ(int chunkZ) {
|
||||
this.chunkZ = chunkZ;
|
||||
}
|
||||
|
||||
public void setFullChunk(boolean fullChunk) {
|
||||
this.fullChunk = fullChunk;
|
||||
}
|
||||
|
||||
public void setPrimaryBitMask(int primaryBitMask) {
|
||||
this.primaryBitMask = primaryBitMask;
|
||||
}
|
||||
|
||||
public void setHeightMaps(CompoundBinaryTag heightMaps) {
|
||||
this.heightMaps = heightMaps;
|
||||
}
|
||||
|
||||
public void setBiomes(int[] biomes) {
|
||||
this.biomes = biomes;
|
||||
}
|
||||
|
||||
public void setData(byte[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setBlockEntities(CompoundBinaryTag[] blockEntities) {
|
||||
this.blockEntities = blockEntities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteMessage msg, Version version) {
|
||||
msg.writeInt(chunkX);
|
||||
msg.writeInt(chunkZ);
|
||||
msg.writeBoolean(fullChunk);
|
||||
msg.writeVarInt(primaryBitMask);
|
||||
msg.writeCompoundTag(heightMaps);
|
||||
|
||||
if (fullChunk){
|
||||
msg.writeVarIntArray(biomes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
msg.writeBytesArray(data);
|
||||
msg.writeCompoundTagArray(blockEntities);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package ru.nanit.limbo.protocol.packets.play;
|
||||
|
||||
import ru.nanit.limbo.protocol.ByteMessage;
|
||||
import ru.nanit.limbo.protocol.Packet;
|
||||
import ru.nanit.limbo.protocol.registry.Version;
|
||||
|
||||
public class PacketKeepAlive implements Packet {
|
||||
|
||||
private long id;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteMessage msg, Version version) {
|
||||
msg.writeLong(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteMessage msg, Version version) {
|
||||
this.id = msg.readLong();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class PacketPlayerPositionAndLook implements PacketOut {
|
||||
private double z;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private byte flags = 0x01;
|
||||
private byte flags = 0x08;
|
||||
private int teleportId;
|
||||
|
||||
public void setX(double x) {
|
||||
|
||||
@@ -3,9 +3,7 @@ package ru.nanit.limbo.protocol.registry;
|
||||
import ru.nanit.limbo.protocol.Packet;
|
||||
import ru.nanit.limbo.protocol.packets.*;
|
||||
import ru.nanit.limbo.protocol.packets.login.*;
|
||||
import ru.nanit.limbo.protocol.packets.play.PacketJoinGame;
|
||||
import ru.nanit.limbo.protocol.packets.play.PacketPlayerPositionAndLook;
|
||||
import ru.nanit.limbo.protocol.packets.play.PacketUpdateViewPos;
|
||||
import ru.nanit.limbo.protocol.packets.play.*;
|
||||
import ru.nanit.limbo.protocol.packets.status.PacketStatusPing;
|
||||
import ru.nanit.limbo.protocol.packets.status.PacketStatusRequest;
|
||||
import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse;
|
||||
@@ -38,9 +36,12 @@ public enum State {
|
||||
},
|
||||
PLAY(3){
|
||||
{
|
||||
clientBound.register(Version.V1_16_4, 0x20, PacketChunkData::new);
|
||||
clientBound.register(Version.V1_16_4, 0x24, PacketJoinGame::new);
|
||||
clientBound.register(Version.V1_16_4, 0x34, PacketPlayerPositionAndLook::new);
|
||||
clientBound.register(Version.V1_16_4, 0x40, PacketUpdateViewPos::new);
|
||||
clientBound.register(Version.V1_16_4, 0x1F, PacketKeepAlive::new);
|
||||
serverBound.register(Version.V1_16_4, 0x1F, PacketKeepAlive::new);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user