forked from BLOCKFANTASY/LOOHP-Limbo
Minecraft 1.20.6
This commit is contained in:
@@ -99,6 +99,7 @@ import com.loohp.limbo.network.protocol.packets.ServerboundLoginAcknowledgedPack
|
||||
import com.loohp.limbo.player.Player;
|
||||
import com.loohp.limbo.player.PlayerInteractManager;
|
||||
import com.loohp.limbo.player.PlayerInventory;
|
||||
import com.loohp.limbo.registry.RegistryCustom;
|
||||
import com.loohp.limbo.utils.BungeecordAdventureConversionUtils;
|
||||
import com.loohp.limbo.utils.CheckedBiConsumer;
|
||||
import com.loohp.limbo.utils.CustomStringUtils;
|
||||
@@ -397,6 +398,7 @@ public class ClientConnection extends Thread {
|
||||
}
|
||||
break;
|
||||
case LOGIN:
|
||||
case TRANSFER:
|
||||
state = ClientState.LOGIN;
|
||||
ServerProperties properties = Limbo.getInstance().getServerProperties();
|
||||
|
||||
@@ -515,7 +517,7 @@ public class ClientConnection extends Thread {
|
||||
break;
|
||||
}
|
||||
|
||||
PacketLoginOutLoginSuccess success = new PacketLoginOutLoginSuccess(uuid, username);
|
||||
PacketLoginOutLoginSuccess success = new PacketLoginOutLoginSuccess(uuid, username, false);
|
||||
sendPacket(success);
|
||||
|
||||
player = new Player(this, username, uuid, Limbo.getInstance().getNextEntityId(), Limbo.getInstance().getServerProperties().getWorldSpawn(), new PlayerInteractManager());
|
||||
@@ -539,7 +541,7 @@ public class ClientConnection extends Thread {
|
||||
inetAddress = InetAddress.getByName(data.getIpAddress());
|
||||
forwardedSkin = data.getSkinResponse();
|
||||
|
||||
PacketLoginOutLoginSuccess success = new PacketLoginOutLoginSuccess(data.getUuid(), data.getUsername());
|
||||
PacketLoginOutLoginSuccess success = new PacketLoginOutLoginSuccess(data.getUuid(), data.getUsername(), false);
|
||||
sendPacket(success);
|
||||
|
||||
player = new Player(this, data.getUsername(), data.getUuid(), Limbo.getInstance().getNextEntityId(), Limbo.getInstance().getServerProperties().getWorldSpawn(), new PlayerInteractManager());
|
||||
@@ -557,7 +559,7 @@ public class ClientConnection extends Thread {
|
||||
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
channel.close();
|
||||
clientSocket.close();
|
||||
state = ClientState.DISCONNECTED;
|
||||
@@ -567,8 +569,22 @@ public class ClientConnection extends Thread {
|
||||
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
|
||||
ClientboundRegistryDataPacket registryDataPacket = new ClientboundRegistryDataPacket(Limbo.getInstance().getDimensionRegistry().getCodec());
|
||||
sendPacket(registryDataPacket);
|
||||
ClientboundRegistryDataPacket registryDataPacket1 = new ClientboundRegistryDataPacket(RegistryCustom.WORLDGEN_BIOME);
|
||||
sendPacket(registryDataPacket1);
|
||||
ClientboundRegistryDataPacket registryDataPacket2 = new ClientboundRegistryDataPacket(RegistryCustom.CHAT_TYPE);
|
||||
sendPacket(registryDataPacket2);
|
||||
ClientboundRegistryDataPacket registryDataPacket3 = new ClientboundRegistryDataPacket(RegistryCustom.TRIM_PATTERN);
|
||||
sendPacket(registryDataPacket3);
|
||||
ClientboundRegistryDataPacket registryDataPacket4 = new ClientboundRegistryDataPacket(RegistryCustom.TRIM_MATERIAL);
|
||||
sendPacket(registryDataPacket4);
|
||||
ClientboundRegistryDataPacket registryDataPacket5 = new ClientboundRegistryDataPacket(RegistryCustom.WOLF_VARIANT);
|
||||
sendPacket(registryDataPacket5);
|
||||
ClientboundRegistryDataPacket registryDataPacket6 = new ClientboundRegistryDataPacket(RegistryCustom.DIMENSION_TYPE);
|
||||
sendPacket(registryDataPacket6);
|
||||
ClientboundRegistryDataPacket registryDataPacket7 = new ClientboundRegistryDataPacket(RegistryCustom.DAMAGE_TYPE);
|
||||
sendPacket(registryDataPacket7);
|
||||
ClientboundRegistryDataPacket registryDataPacket8 = new ClientboundRegistryDataPacket(RegistryCustom.BANNER_PATTERN);
|
||||
sendPacket(registryDataPacket8);
|
||||
|
||||
ClientboundFinishConfigurationPacket clientboundFinishConfigurationPacket = new ClientboundFinishConfigurationPacket();
|
||||
sendPacket(clientboundFinishConfigurationPacket);
|
||||
@@ -587,7 +603,7 @@ public class ClientConnection extends Thread {
|
||||
worldSpawn = spawnEvent.getSpawnLocation();
|
||||
World world = worldSpawn.getWorld();
|
||||
|
||||
PacketPlayOutLogin join = new PacketPlayOutLogin(player.getEntityId(), false, Limbo.getInstance().getWorlds(), (byte) properties.getMaxPlayers(), 8, 8, properties.isReducedDebugInfo(), true, false, world.getEnvironment(), world, 0, properties.getDefaultGamemode(), false, true, 0);
|
||||
PacketPlayOutLogin join = new PacketPlayOutLogin(player.getEntityId(), false, Limbo.getInstance().getWorlds(), properties.getMaxPlayers(), 8, 8, properties.isReducedDebugInfo(), true, false, world.getEnvironment(), world, 0, properties.getDefaultGamemode(), false, true, 0, false);
|
||||
sendPacket(join);
|
||||
Limbo.getInstance().getUnsafe().a(player, properties.getDefaultGamemode());
|
||||
|
||||
@@ -861,7 +877,7 @@ public class ClientConnection extends Thread {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@
|
||||
|
||||
package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.registry.Registry;
|
||||
import com.loohp.limbo.registry.BuiltInRegistries;
|
||||
import com.loohp.limbo.utils.BitsUtils;
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import com.loohp.limbo.world.Environment;
|
||||
@@ -247,7 +247,7 @@ public class ClientboundLevelChunkWithLightPacket extends PacketOut {
|
||||
int z = each.getInt("z") % 16;
|
||||
output.writeByte(((x & 15) << 4) | (z & 15));
|
||||
output.writeShort(y);
|
||||
Integer id = Registry.BLOCK_ENTITY_TYPE.getId(Key.key(chunk.getBlockStateAt(x, y, z).getString("Name")));
|
||||
Integer id = BuiltInRegistries.BLOCK_ENTITY_TYPE.getId(Key.key(chunk.getBlockStateAt(x, y, z).getString("Name")));
|
||||
DataTypeIO.writeVarInt(output, id == null ? -1 : id);
|
||||
DataTypeIO.writeTag(output, each);
|
||||
}
|
||||
|
||||
+21
-6
@@ -19,23 +19,27 @@
|
||||
|
||||
package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.registry.RegistryCustom;
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
public class ClientboundRegistryDataPacket extends PacketOut {
|
||||
|
||||
private final CompoundTag dimensionCodec;
|
||||
private final RegistryCustom registry;
|
||||
|
||||
public ClientboundRegistryDataPacket(CompoundTag dimensionCodec) {
|
||||
this.dimensionCodec = dimensionCodec;
|
||||
public ClientboundRegistryDataPacket(RegistryCustom registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public CompoundTag getDimensionCodec() {
|
||||
return dimensionCodec;
|
||||
public RegistryCustom getRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,7 +49,18 @@ public class ClientboundRegistryDataPacket extends PacketOut {
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getConfigurationOut().get(getClass()));
|
||||
|
||||
DataTypeIO.writeTag(output, dimensionCodec);
|
||||
DataTypeIO.writeString(output, registry.getIdentifier().asString(), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeVarInt(output, registry.getEntries().size());
|
||||
for (Map.Entry<Key, CompoundTag> entry : registry.getEntries().entrySet()) {
|
||||
DataTypeIO.writeString(output, entry.getKey().asString(), StandardCharsets.UTF_8);
|
||||
CompoundTag data = entry.getValue();
|
||||
if (data == null) {
|
||||
output.writeBoolean(false);
|
||||
} else {
|
||||
output.writeBoolean(true);
|
||||
DataTypeIO.writeTag(output, data);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
@@ -115,6 +115,8 @@ public abstract class Packet {
|
||||
Class<? extends Packet> type = getClass();
|
||||
if (handshakeIn.containsValue(type)) {
|
||||
return ClientConnection.ClientState.HANDSHAKE;
|
||||
} else if (statusIn.containsValue(type) || statusOut.containsKey(type)) {
|
||||
return ClientConnection.ClientState.STATUS;
|
||||
} else if (loginIn.containsValue(type) || loginOut.containsKey(type)) {
|
||||
return ClientConnection.ClientState.LOGIN;
|
||||
} else if (configurationIn.containsValue(type) || configurationOut.containsKey(type)) {
|
||||
@@ -122,7 +124,7 @@ public abstract class Packet {
|
||||
} else if (playIn.containsValue(type) || playOut.containsKey(type)) {
|
||||
return ClientConnection.ClientState.PLAY;
|
||||
} else {
|
||||
throw new IllegalStateException("This packet is not registered!");
|
||||
throw new IllegalStateException("This packet of class " + type + " is not registered!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,10 @@ public class PacketHandshakingIn extends PacketIn {
|
||||
|
||||
public enum HandshakeType {
|
||||
STATUS(1),
|
||||
LOGIN(2);
|
||||
LOGIN(2),
|
||||
TRANSFER(3);
|
||||
|
||||
int networkId;
|
||||
private final int networkId;
|
||||
|
||||
HandshakeType(int networkId) {
|
||||
this.networkId = networkId;
|
||||
|
||||
+11
-4
@@ -29,12 +29,14 @@ import java.util.UUID;
|
||||
|
||||
public class PacketLoginOutLoginSuccess extends PacketOut {
|
||||
|
||||
private UUID uuid;
|
||||
private String username;
|
||||
private final UUID uuid;
|
||||
private final String username;
|
||||
private final boolean strictErrorHandling;
|
||||
|
||||
public PacketLoginOutLoginSuccess(UUID uuid, String username) {
|
||||
public PacketLoginOutLoginSuccess(UUID uuid, String username, boolean strictErrorHandling) {
|
||||
this.uuid = uuid;
|
||||
this.username = username;
|
||||
this.strictErrorHandling = strictErrorHandling;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
@@ -44,7 +46,11 @@ public class PacketLoginOutLoginSuccess extends PacketOut {
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
|
||||
public boolean isStrictErrorHandling() {
|
||||
return strictErrorHandling;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serializePacket() throws IOException {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
@@ -54,6 +60,7 @@ public class PacketLoginOutLoginSuccess extends PacketOut {
|
||||
DataTypeIO.writeUUID(output, uuid);
|
||||
DataTypeIO.writeString(output, username, StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeVarInt(output, 0);
|
||||
output.writeBoolean(strictErrorHandling);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.registry.RegistryCustom;
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import com.loohp.limbo.utils.GameMode;
|
||||
import com.loohp.limbo.world.Environment;
|
||||
@@ -36,7 +37,7 @@ public class PacketPlayOutLogin extends PacketOut {
|
||||
private final int entityId;
|
||||
private final boolean isHardcore;
|
||||
private final List<World> worlds;
|
||||
private final byte maxPlayers;
|
||||
private final int maxPlayers;
|
||||
private final int viewDistance;
|
||||
private final int simulationDistance;
|
||||
private final boolean reducedDebugInfo;
|
||||
@@ -49,8 +50,9 @@ public class PacketPlayOutLogin extends PacketOut {
|
||||
private final boolean isDebug;
|
||||
private final boolean isFlat;
|
||||
private final int portalCooldown;
|
||||
private final boolean enforcesSecureChat;
|
||||
|
||||
public PacketPlayOutLogin(int entityId, boolean isHardcore, List<World> worlds, byte maxPlayers, int viewDistance, int simulationDistance, boolean reducedDebugInfo, boolean enableRespawnScreen, boolean doLimitedCrafting, Environment dimension, World world, long hashedSeed, GameMode gamemode, boolean isDebug, boolean isFlat, int portalCooldown) {
|
||||
public PacketPlayOutLogin(int entityId, boolean isHardcore, List<World> worlds, int maxPlayers, int viewDistance, int simulationDistance, boolean reducedDebugInfo, boolean enableRespawnScreen, boolean doLimitedCrafting, Environment dimension, World world, long hashedSeed, GameMode gamemode, boolean isDebug, boolean isFlat, int portalCooldown, boolean enforcesSecureChat) {
|
||||
this.entityId = entityId;
|
||||
this.isHardcore = isHardcore;
|
||||
this.worlds = worlds;
|
||||
@@ -67,6 +69,7 @@ public class PacketPlayOutLogin extends PacketOut {
|
||||
this.isDebug = isDebug;
|
||||
this.isFlat = isFlat;
|
||||
this.portalCooldown = portalCooldown;
|
||||
this.enforcesSecureChat = enforcesSecureChat;
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
@@ -81,7 +84,7 @@ public class PacketPlayOutLogin extends PacketOut {
|
||||
return worlds;
|
||||
}
|
||||
|
||||
public byte getMaxPlayers() {
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
@@ -133,6 +136,10 @@ public class PacketPlayOutLogin extends PacketOut {
|
||||
return portalCooldown;
|
||||
}
|
||||
|
||||
public boolean isEnforcesSecureChat() {
|
||||
return enforcesSecureChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serializePacket() throws IOException {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
@@ -151,7 +158,7 @@ public class PacketPlayOutLogin extends PacketOut {
|
||||
output.writeBoolean(reducedDebugInfo);
|
||||
output.writeBoolean(enableRespawnScreen);
|
||||
output.writeBoolean(doLimitedCrafting);
|
||||
DataTypeIO.writeString(output, world.getEnvironment().getKey().toString(), StandardCharsets.UTF_8);
|
||||
DataTypeIO.writeVarInt(output, RegistryCustom.DIMENSION_TYPE.indexOf(world.getEnvironment().getKey()));
|
||||
DataTypeIO.writeString(output, Key.key(world.getName()).toString(), StandardCharsets.UTF_8);
|
||||
output.writeLong(hashedSeed);
|
||||
output.writeByte((byte) gamemode.getId());
|
||||
@@ -160,6 +167,7 @@ public class PacketPlayOutLogin extends PacketOut {
|
||||
output.writeBoolean(isFlat);
|
||||
output.writeBoolean(false);
|
||||
DataTypeIO.writeVarInt(output, portalCooldown);
|
||||
output.writeBoolean(enforcesSecureChat);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.registry.Registry;
|
||||
import com.loohp.limbo.registry.BuiltInRegistries;
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -60,7 +60,7 @@ public class PacketPlayOutOpenWindow extends PacketOut {
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
|
||||
DataTypeIO.writeVarInt(output, containerId);
|
||||
DataTypeIO.writeVarInt(output, Registry.MENU_REGISTRY.getId(type));
|
||||
DataTypeIO.writeVarInt(output, BuiltInRegistries.MENU_REGISTRY.getId(type));
|
||||
DataTypeIO.writeComponent(output, title);
|
||||
|
||||
return buffer.toByteArray();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package com.loohp.limbo.network.protocol.packets;
|
||||
|
||||
import com.loohp.limbo.registry.RegistryCustom;
|
||||
import com.loohp.limbo.utils.DataTypeIO;
|
||||
import com.loohp.limbo.utils.GameMode;
|
||||
import com.loohp.limbo.world.Environment;
|
||||
@@ -35,18 +36,16 @@ import java.nio.charset.StandardCharsets;
|
||||
public class PacketPlayOutRespawn extends PacketOut {
|
||||
|
||||
private Environment dimension;
|
||||
private String worldName;
|
||||
private CompoundTag dimensionCodec;
|
||||
private World world;
|
||||
private long hashedSeed;
|
||||
private GameMode gamemode;
|
||||
private boolean isDebug;
|
||||
private boolean isFlat;
|
||||
private boolean copyMetaData;
|
||||
|
||||
public PacketPlayOutRespawn(World world, CompoundTag dimensionCodec, long hashedSeed, GameMode gamemode, boolean isDebug, boolean isFlat, boolean copyMetaData) {
|
||||
public PacketPlayOutRespawn(World world, long hashedSeed, GameMode gamemode, boolean isDebug, boolean isFlat, boolean copyMetaData) {
|
||||
this.dimension = world.getEnvironment();
|
||||
this.dimensionCodec = dimensionCodec;
|
||||
this.worldName = Key.key(world.getName()).toString();
|
||||
this.world = world;
|
||||
this.hashedSeed = hashedSeed;
|
||||
this.gamemode = gamemode;
|
||||
this.isDebug = isDebug;
|
||||
@@ -54,16 +53,12 @@ public class PacketPlayOutRespawn extends PacketOut {
|
||||
this.copyMetaData = copyMetaData;
|
||||
}
|
||||
|
||||
public CompoundTag getDimensionCodec() {
|
||||
return dimensionCodec;
|
||||
}
|
||||
|
||||
public Environment getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
public String getWorldName() {
|
||||
return worldName;
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public long getHashedSeed() {
|
||||
@@ -92,16 +87,9 @@ public class PacketPlayOutRespawn extends PacketOut {
|
||||
|
||||
DataOutputStream output = new DataOutputStream(buffer);
|
||||
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||
CompoundTag tag = null;
|
||||
ListTag<CompoundTag> list = dimensionCodec.getCompoundTag("minecraft:dimension_type").getListTag("value").asCompoundTagList();
|
||||
for (CompoundTag each : list) {
|
||||
if (each.getString("name").equals(dimension.getKey().toString())) {
|
||||
tag = each.getCompoundTag("element");
|
||||
break;
|
||||
}
|
||||
}
|
||||
DataTypeIO.writeTag(output, tag != null ? tag : list.get(0));
|
||||
DataTypeIO.writeString(output, worldName, StandardCharsets.UTF_8);
|
||||
|
||||
DataTypeIO.writeVarInt(output, RegistryCustom.DIMENSION_TYPE.indexOf(world.getEnvironment().getKey()));
|
||||
DataTypeIO.writeString(output, Key.key(world.getName()).toString(), StandardCharsets.UTF_8);
|
||||
output.writeLong(hashedSeed);
|
||||
output.writeByte((byte) gamemode.getId());
|
||||
output.writeByte((byte) gamemode.getId());
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.loohp.limbo.utils.DataTypeIO;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketPlayOutSetSlot extends PacketOut {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user