mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2026-02-11 03:16:14 +01:00
Send keep alive frequently. Removed unused packets. Moved initialization in server class
This commit is contained in:
@@ -27,6 +27,12 @@ public class ByteMessage extends ByteBuf {
|
||||
this.buf = buf;
|
||||
}
|
||||
|
||||
public byte[] toByteArray(){
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/* Minecraft protocol methods */
|
||||
|
||||
public int readVarInt() {
|
||||
@@ -127,6 +133,13 @@ public class ByteMessage extends ByteBuf {
|
||||
}
|
||||
}
|
||||
|
||||
public void writeLongArray(long[] array) {
|
||||
writeVarInt(array.length);
|
||||
for (long i : array) {
|
||||
writeLong(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCompoundTagArray(CompoundBinaryTag[] compoundTags) {
|
||||
try {
|
||||
ByteBufOutputStream stream = new ByteBufOutputStream(buf);
|
||||
@@ -1125,4 +1138,8 @@ public class ByteMessage extends ByteBuf {
|
||||
public boolean release(int decrement) {
|
||||
return buf.release(decrement);
|
||||
}
|
||||
|
||||
public static ByteMessage create(){
|
||||
return new ByteMessage(Unpooled.buffer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package ru.nanit.limbo.protocol.packets.play;
|
||||
|
||||
import ru.nanit.limbo.protocol.ByteMessage;
|
||||
import ru.nanit.limbo.protocol.PacketOut;
|
||||
import ru.nanit.limbo.protocol.registry.Version;
|
||||
|
||||
public class PacketUpdateViewPos implements PacketOut {
|
||||
|
||||
private int chunkX;
|
||||
private int chunkY;
|
||||
|
||||
public void setChunkX(int chunkX) {
|
||||
this.chunkX = chunkX;
|
||||
}
|
||||
|
||||
public void setChunkY(int chunkY) {
|
||||
this.chunkY = chunkY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteMessage msg, Version version) {
|
||||
msg.writeVarInt(chunkX);
|
||||
msg.writeVarInt(chunkY);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,8 @@ public enum State {
|
||||
HANDSHAKING(0){
|
||||
{
|
||||
serverBound.register(Version.getMinimal(), 0x00, PacketHandshake::new);
|
||||
|
||||
int[] i = new int[16 * 16 * 16];
|
||||
}
|
||||
},
|
||||
STATUS(1){
|
||||
@@ -36,12 +38,10 @@ 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);
|
||||
serverBound.register(Version.V1_16_4, 0x10, PacketKeepAlive::new);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user