mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2025-07-13 21:20:12 +02:00
Modified dimension registry and join packet
This commit is contained in:
parent
a439aa9847
commit
b08eea13e0
@ -308,8 +308,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
|||||||
joinGame.setWorldName("minecraft:world");
|
joinGame.setWorldName("minecraft:world");
|
||||||
joinGame.setWorldNames("minecraft:world");
|
joinGame.setWorldNames("minecraft:world");
|
||||||
joinGame.setHashedSeed(0);
|
joinGame.setHashedSeed(0);
|
||||||
joinGame.setDimensionCodec(server.getDimensionRegistry().getCodec());
|
joinGame.setDimensionRegistry(server.getDimensionRegistry());
|
||||||
joinGame.setDimension(server.getDimensionRegistry().getDefaultDimension());
|
|
||||||
|
|
||||||
PacketPlayerAbilities playerAbilities = new PacketPlayerAbilities();
|
PacketPlayerAbilities playerAbilities = new PacketPlayerAbilities();
|
||||||
playerAbilities.setFlyingSpeed(0.0F);
|
playerAbilities.setFlyingSpeed(0.0F);
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package ru.nanit.limbo.protocol.packets.play;
|
package ru.nanit.limbo.protocol.packets.play;
|
||||||
|
|
||||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
|
||||||
import ru.nanit.limbo.protocol.ByteMessage;
|
import ru.nanit.limbo.protocol.ByteMessage;
|
||||||
import ru.nanit.limbo.protocol.PacketOut;
|
import ru.nanit.limbo.protocol.PacketOut;
|
||||||
import ru.nanit.limbo.protocol.registry.Version;
|
import ru.nanit.limbo.protocol.registry.Version;
|
||||||
import ru.nanit.limbo.world.Dimension;
|
import ru.nanit.limbo.world.DimensionRegistry;
|
||||||
|
|
||||||
public class PacketJoinGame implements PacketOut {
|
public class PacketJoinGame implements PacketOut {
|
||||||
|
|
||||||
@ -13,8 +12,7 @@ public class PacketJoinGame implements PacketOut {
|
|||||||
private int gameMode = 2;
|
private int gameMode = 2;
|
||||||
private int previousGameMode = -1;
|
private int previousGameMode = -1;
|
||||||
private String[] worldNames;
|
private String[] worldNames;
|
||||||
private CompoundBinaryTag dimensionCodec;
|
private DimensionRegistry dimensionRegistry;
|
||||||
private Dimension dimension;
|
|
||||||
private String worldName;
|
private String worldName;
|
||||||
private long hashedSeed;
|
private long hashedSeed;
|
||||||
private int maxPlayers;
|
private int maxPlayers;
|
||||||
@ -44,12 +42,8 @@ public class PacketJoinGame implements PacketOut {
|
|||||||
this.worldNames = worldNames;
|
this.worldNames = worldNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDimensionCodec(CompoundBinaryTag dimensionCodec) {
|
public void setDimensionRegistry(DimensionRegistry dimensionRegistry) {
|
||||||
this.dimensionCodec = dimensionCodec;
|
this.dimensionRegistry = dimensionRegistry;
|
||||||
}
|
|
||||||
|
|
||||||
public void setDimension(Dimension dimension) {
|
|
||||||
this.dimension = dimension;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWorldName(String worldName) {
|
public void setWorldName(String worldName) {
|
||||||
@ -90,7 +84,7 @@ public class PacketJoinGame implements PacketOut {
|
|||||||
|
|
||||||
if (version.fromTo(Version.V1_8, Version.V1_9_1)) {
|
if (version.fromTo(Version.V1_8, Version.V1_9_1)) {
|
||||||
msg.writeByte(gameMode);
|
msg.writeByte(gameMode);
|
||||||
msg.writeByte(dimension.getId());
|
msg.writeByte(dimensionRegistry.getDefaultDimension().getId());
|
||||||
msg.writeByte(0); // Difficulty
|
msg.writeByte(0); // Difficulty
|
||||||
msg.writeByte(maxPlayers);
|
msg.writeByte(maxPlayers);
|
||||||
msg.writeString("flat"); // Level type
|
msg.writeString("flat"); // Level type
|
||||||
@ -99,7 +93,7 @@ public class PacketJoinGame implements PacketOut {
|
|||||||
|
|
||||||
if (version.fromTo(Version.V1_9_2, Version.V1_13_2)) {
|
if (version.fromTo(Version.V1_9_2, Version.V1_13_2)) {
|
||||||
msg.writeByte(gameMode);
|
msg.writeByte(gameMode);
|
||||||
msg.writeInt(dimension.getId());
|
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
|
||||||
msg.writeByte(0); // Difficulty
|
msg.writeByte(0); // Difficulty
|
||||||
msg.writeByte(maxPlayers);
|
msg.writeByte(maxPlayers);
|
||||||
msg.writeString("flat"); // Level type
|
msg.writeString("flat"); // Level type
|
||||||
@ -108,7 +102,7 @@ public class PacketJoinGame implements PacketOut {
|
|||||||
|
|
||||||
if (version.fromTo(Version.V1_14, Version.V1_14_4)) {
|
if (version.fromTo(Version.V1_14, Version.V1_14_4)) {
|
||||||
msg.writeByte(gameMode);
|
msg.writeByte(gameMode);
|
||||||
msg.writeInt(dimension.getId());
|
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
|
||||||
msg.writeByte(maxPlayers);
|
msg.writeByte(maxPlayers);
|
||||||
msg.writeString("flat"); // Level type
|
msg.writeString("flat"); // Level type
|
||||||
msg.writeVarInt(viewDistance);
|
msg.writeVarInt(viewDistance);
|
||||||
@ -117,7 +111,7 @@ public class PacketJoinGame implements PacketOut {
|
|||||||
|
|
||||||
if (version.fromTo(Version.V1_15, Version.V1_15_2)) {
|
if (version.fromTo(Version.V1_15, Version.V1_15_2)) {
|
||||||
msg.writeByte(gameMode);
|
msg.writeByte(gameMode);
|
||||||
msg.writeInt(dimension.getId());
|
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
|
||||||
msg.writeLong(hashedSeed);
|
msg.writeLong(hashedSeed);
|
||||||
msg.writeByte(maxPlayers);
|
msg.writeByte(maxPlayers);
|
||||||
msg.writeString("flat"); // Level type
|
msg.writeString("flat"); // Level type
|
||||||
@ -127,12 +121,11 @@ public class PacketJoinGame implements PacketOut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (version.fromTo(Version.V1_16, Version.V1_16_1)) {
|
if (version.fromTo(Version.V1_16, Version.V1_16_1)) {
|
||||||
msg.writeBoolean(isHardcore);
|
|
||||||
msg.writeByte(gameMode);
|
msg.writeByte(gameMode);
|
||||||
msg.writeByte(previousGameMode);
|
msg.writeByte(previousGameMode);
|
||||||
msg.writeStringsArray(worldNames);
|
msg.writeStringsArray(worldNames);
|
||||||
msg.writeCompoundTag(dimensionCodec);
|
msg.writeCompoundTag(dimensionRegistry.getOldCodec());
|
||||||
msg.writeInt(dimension.getId());
|
msg.writeString(dimensionRegistry.getDefaultDimension().getName());
|
||||||
msg.writeString(worldName);
|
msg.writeString(worldName);
|
||||||
msg.writeLong(hashedSeed);
|
msg.writeLong(hashedSeed);
|
||||||
msg.writeByte(maxPlayers);
|
msg.writeByte(maxPlayers);
|
||||||
@ -148,8 +141,8 @@ public class PacketJoinGame implements PacketOut {
|
|||||||
msg.writeByte(gameMode);
|
msg.writeByte(gameMode);
|
||||||
msg.writeByte(previousGameMode);
|
msg.writeByte(previousGameMode);
|
||||||
msg.writeStringsArray(worldNames);
|
msg.writeStringsArray(worldNames);
|
||||||
msg.writeCompoundTag(dimensionCodec);
|
msg.writeCompoundTag(dimensionRegistry.getCodec());
|
||||||
msg.writeCompoundTag(dimension.getData());
|
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension().getData());
|
||||||
msg.writeString(worldName);
|
msg.writeString(worldName);
|
||||||
msg.writeLong(hashedSeed);
|
msg.writeLong(hashedSeed);
|
||||||
msg.writeVarInt(maxPlayers);
|
msg.writeVarInt(maxPlayers);
|
||||||
|
@ -53,8 +53,8 @@ public final class LimboServer {
|
|||||||
|
|
||||||
Logger.setLevel(config.getDebugLevel());
|
Logger.setLevel(config.getDebugLevel());
|
||||||
|
|
||||||
dimensionRegistry = new DimensionRegistry();
|
dimensionRegistry = new DimensionRegistry(this);
|
||||||
dimensionRegistry.load(this, config.getDimensionType());
|
dimensionRegistry.load(config.getDimensionType());
|
||||||
connections = new Connections();
|
connections = new Connections();
|
||||||
|
|
||||||
ClientConnection.initPackets(this);
|
ClientConnection.initPackets(this);
|
||||||
|
@ -5,10 +5,12 @@ import net.kyori.adventure.nbt.CompoundBinaryTag;
|
|||||||
public class Dimension {
|
public class Dimension {
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
|
private final String name;
|
||||||
private final CompoundBinaryTag data;
|
private final CompoundBinaryTag data;
|
||||||
|
|
||||||
public Dimension(int id, CompoundBinaryTag data) {
|
public Dimension(int id, String name, CompoundBinaryTag data) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,6 +18,10 @@ public class Dimension {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public CompoundBinaryTag getData() {
|
public CompoundBinaryTag getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -12,29 +12,34 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public final class DimensionRegistry {
|
public final class DimensionRegistry {
|
||||||
|
|
||||||
|
private final LimboServer server;
|
||||||
|
|
||||||
private Dimension defaultDimension;
|
private Dimension defaultDimension;
|
||||||
|
|
||||||
private CompoundBinaryTag codec;
|
private CompoundBinaryTag codec;
|
||||||
|
private CompoundBinaryTag oldCodec;
|
||||||
|
|
||||||
|
public DimensionRegistry(LimboServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
public CompoundBinaryTag getCodec() {
|
public CompoundBinaryTag getCodec() {
|
||||||
return codec;
|
return codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CompoundBinaryTag getOldCodec() {
|
||||||
|
return oldCodec;
|
||||||
|
}
|
||||||
|
|
||||||
public Dimension getDefaultDimension() {
|
public Dimension getDefaultDimension() {
|
||||||
return defaultDimension;
|
return defaultDimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load(LimboServer server, String def) throws IOException {
|
public void load(String def) throws IOException {
|
||||||
InputStream in = server.getClass().getResourceAsStream("/dimension_codec.snbt");
|
codec = readCodecFile("/dimension/codec_new.snbt");
|
||||||
|
// On 1.16-1.16.1 different codec format
|
||||||
|
oldCodec = readCodecFile("/dimension/codec_old.snbt");
|
||||||
|
|
||||||
if(in == null)
|
|
||||||
throw new FileNotFoundException("Cannot find dimension registry file");
|
|
||||||
|
|
||||||
String data = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
|
|
||||||
.lines()
|
|
||||||
.collect(Collectors.joining("\n"));
|
|
||||||
|
|
||||||
codec = TagStringIO.get().asCompound(data);
|
|
||||||
ListBinaryTag dimensions = codec.getCompound("minecraft:dimension_type").getList("value");
|
ListBinaryTag dimensions = codec.getCompound("minecraft:dimension_type").getList("value");
|
||||||
|
|
||||||
CompoundBinaryTag overWorld = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(0)).get("element");
|
CompoundBinaryTag overWorld = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(0)).get("element");
|
||||||
@ -43,18 +48,33 @@ public final class DimensionRegistry {
|
|||||||
|
|
||||||
switch (def.toLowerCase()) {
|
switch (def.toLowerCase()) {
|
||||||
case "overworld":
|
case "overworld":
|
||||||
defaultDimension = new Dimension(0, overWorld);
|
defaultDimension = new Dimension(0, "minecraft:overworld", overWorld);
|
||||||
break;
|
break;
|
||||||
case "nether":
|
case "nether":
|
||||||
defaultDimension = new Dimension(-1, nether);
|
defaultDimension = new Dimension(-1, "minecraft:nether", nether);
|
||||||
break;
|
break;
|
||||||
case "the_end":
|
case "the_end":
|
||||||
defaultDimension = new Dimension(1, theEnd);
|
defaultDimension = new Dimension(1, "minecraft:the_end", theEnd);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
defaultDimension = new Dimension(1, theEnd);
|
defaultDimension = new Dimension(1, "minecraft:the_end", theEnd);
|
||||||
Logger.warning("Undefined dimension type: '%s'. Using THE_END as default", def);
|
Logger.warning("Undefined dimension type: '%s'. Using THE_END as default", def);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CompoundBinaryTag readCodecFile(String resPath) throws IOException {
|
||||||
|
InputStream in = server.getClass().getResourceAsStream(resPath);
|
||||||
|
|
||||||
|
if(in == null)
|
||||||
|
throw new FileNotFoundException("Cannot find dimension registry file");
|
||||||
|
|
||||||
|
return TagStringIO.get().asCompound(streamToString(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String streamToString(InputStream in) {
|
||||||
|
return new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
|
||||||
|
.lines()
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
86
src/main/resources/dimension/codec_old.snbt
Normal file
86
src/main/resources/dimension/codec_old.snbt
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
{
|
||||||
|
"dimension": [
|
||||||
|
{
|
||||||
|
name: "minecraft:overworld",
|
||||||
|
id: 0,
|
||||||
|
piglin_safe: 0b,
|
||||||
|
natural: 1b,
|
||||||
|
ambient_light: 0.0f,
|
||||||
|
infiniburn: "minecraft:infiniburn_overworld",
|
||||||
|
respawn_anchor_works: 0b,
|
||||||
|
has_skylight: 1b,
|
||||||
|
bed_works: 1b,
|
||||||
|
shrunk: 0,
|
||||||
|
effects: "minecraft:overworld",
|
||||||
|
has_raids: 1b,
|
||||||
|
min_y: 0,
|
||||||
|
height: 256,
|
||||||
|
logical_height: 256,
|
||||||
|
coordinate_scale: 1.0d,
|
||||||
|
ultrawarm: 0b,
|
||||||
|
has_ceiling: 0b
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "minecraft:overworld_caves",
|
||||||
|
id: 1,
|
||||||
|
piglin_safe: 0b,
|
||||||
|
natural: 1b,
|
||||||
|
shrunk: 0,
|
||||||
|
ambient_light: 0.0f,
|
||||||
|
infiniburn: "minecraft:infiniburn_overworld",
|
||||||
|
respawn_anchor_works: 0b,
|
||||||
|
has_skylight: 1b,
|
||||||
|
bed_works: 1b,
|
||||||
|
effects: "minecraft:overworld",
|
||||||
|
has_raids: 1b,
|
||||||
|
min_y: 0,
|
||||||
|
height: 256,
|
||||||
|
logical_height: 256,
|
||||||
|
coordinate_scale: 1.0d,
|
||||||
|
ultrawarm: 0b,
|
||||||
|
has_ceiling: 1b
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "minecraft:the_nether",
|
||||||
|
id: 2,
|
||||||
|
piglin_safe: 1b,
|
||||||
|
natural: 0b,
|
||||||
|
shrunk: 0,
|
||||||
|
ambient_light: 0.1f,
|
||||||
|
infiniburn: "minecraft:infiniburn_nether",
|
||||||
|
respawn_anchor_works: 1b,
|
||||||
|
has_skylight: 0b,
|
||||||
|
bed_works: 0b,
|
||||||
|
effects: "minecraft:the_nether",
|
||||||
|
fixed_time: 18000L,
|
||||||
|
has_raids: 0b,
|
||||||
|
min_y: 0,
|
||||||
|
height: 256,
|
||||||
|
logical_height: 128,
|
||||||
|
coordinate_scale: 8.0d,
|
||||||
|
ultrawarm: 1b,
|
||||||
|
has_ceiling: 1b
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "minecraft:the_end",
|
||||||
|
id: 3,
|
||||||
|
piglin_safe: 0b,
|
||||||
|
natural: 0b,
|
||||||
|
ambient_light: 0.0f,
|
||||||
|
infiniburn: "minecraft:infiniburn_end",
|
||||||
|
respawn_anchor_works: 0b,
|
||||||
|
has_skylight: 0b,
|
||||||
|
shrunk: 0,
|
||||||
|
bed_works: 0b,
|
||||||
|
effects: "minecraft:the_end",
|
||||||
|
fixed_time: 6000L,
|
||||||
|
has_raids: 1b,
|
||||||
|
min_y: 0,
|
||||||
|
height: 256,
|
||||||
|
logical_height: 256,
|
||||||
|
coordinate_scale: 1.0d,
|
||||||
|
ultrawarm: 0b,
|
||||||
|
has_ceiling: 0b
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user