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.setWorldNames("minecraft:world");
|
||||
joinGame.setHashedSeed(0);
|
||||
joinGame.setDimensionCodec(server.getDimensionRegistry().getCodec());
|
||||
joinGame.setDimension(server.getDimensionRegistry().getDefaultDimension());
|
||||
joinGame.setDimensionRegistry(server.getDimensionRegistry());
|
||||
|
||||
PacketPlayerAbilities playerAbilities = new PacketPlayerAbilities();
|
||||
playerAbilities.setFlyingSpeed(0.0F);
|
||||
|
@ -1,10 +1,9 @@
|
||||
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;
|
||||
import ru.nanit.limbo.world.Dimension;
|
||||
import ru.nanit.limbo.world.DimensionRegistry;
|
||||
|
||||
public class PacketJoinGame implements PacketOut {
|
||||
|
||||
@ -13,8 +12,7 @@ public class PacketJoinGame implements PacketOut {
|
||||
private int gameMode = 2;
|
||||
private int previousGameMode = -1;
|
||||
private String[] worldNames;
|
||||
private CompoundBinaryTag dimensionCodec;
|
||||
private Dimension dimension;
|
||||
private DimensionRegistry dimensionRegistry;
|
||||
private String worldName;
|
||||
private long hashedSeed;
|
||||
private int maxPlayers;
|
||||
@ -44,12 +42,8 @@ public class PacketJoinGame implements PacketOut {
|
||||
this.worldNames = worldNames;
|
||||
}
|
||||
|
||||
public void setDimensionCodec(CompoundBinaryTag dimensionCodec) {
|
||||
this.dimensionCodec = dimensionCodec;
|
||||
}
|
||||
|
||||
public void setDimension(Dimension dimension) {
|
||||
this.dimension = dimension;
|
||||
public void setDimensionRegistry(DimensionRegistry dimensionRegistry) {
|
||||
this.dimensionRegistry = dimensionRegistry;
|
||||
}
|
||||
|
||||
public void setWorldName(String worldName) {
|
||||
@ -90,7 +84,7 @@ public class PacketJoinGame implements PacketOut {
|
||||
|
||||
if (version.fromTo(Version.V1_8, Version.V1_9_1)) {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(dimension.getId());
|
||||
msg.writeByte(dimensionRegistry.getDefaultDimension().getId());
|
||||
msg.writeByte(0); // Difficulty
|
||||
msg.writeByte(maxPlayers);
|
||||
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)) {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeInt(dimension.getId());
|
||||
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
|
||||
msg.writeByte(0); // Difficulty
|
||||
msg.writeByte(maxPlayers);
|
||||
msg.writeString("flat"); // Level type
|
||||
@ -108,7 +102,7 @@ public class PacketJoinGame implements PacketOut {
|
||||
|
||||
if (version.fromTo(Version.V1_14, Version.V1_14_4)) {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeInt(dimension.getId());
|
||||
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
|
||||
msg.writeByte(maxPlayers);
|
||||
msg.writeString("flat"); // Level type
|
||||
msg.writeVarInt(viewDistance);
|
||||
@ -117,7 +111,7 @@ public class PacketJoinGame implements PacketOut {
|
||||
|
||||
if (version.fromTo(Version.V1_15, Version.V1_15_2)) {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeInt(dimension.getId());
|
||||
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
|
||||
msg.writeLong(hashedSeed);
|
||||
msg.writeByte(maxPlayers);
|
||||
msg.writeString("flat"); // Level type
|
||||
@ -127,12 +121,11 @@ public class PacketJoinGame implements PacketOut {
|
||||
}
|
||||
|
||||
if (version.fromTo(Version.V1_16, Version.V1_16_1)) {
|
||||
msg.writeBoolean(isHardcore);
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(previousGameMode);
|
||||
msg.writeStringsArray(worldNames);
|
||||
msg.writeCompoundTag(dimensionCodec);
|
||||
msg.writeInt(dimension.getId());
|
||||
msg.writeCompoundTag(dimensionRegistry.getOldCodec());
|
||||
msg.writeString(dimensionRegistry.getDefaultDimension().getName());
|
||||
msg.writeString(worldName);
|
||||
msg.writeLong(hashedSeed);
|
||||
msg.writeByte(maxPlayers);
|
||||
@ -148,8 +141,8 @@ public class PacketJoinGame implements PacketOut {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(previousGameMode);
|
||||
msg.writeStringsArray(worldNames);
|
||||
msg.writeCompoundTag(dimensionCodec);
|
||||
msg.writeCompoundTag(dimension.getData());
|
||||
msg.writeCompoundTag(dimensionRegistry.getCodec());
|
||||
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension().getData());
|
||||
msg.writeString(worldName);
|
||||
msg.writeLong(hashedSeed);
|
||||
msg.writeVarInt(maxPlayers);
|
||||
|
@ -53,8 +53,8 @@ public final class LimboServer {
|
||||
|
||||
Logger.setLevel(config.getDebugLevel());
|
||||
|
||||
dimensionRegistry = new DimensionRegistry();
|
||||
dimensionRegistry.load(this, config.getDimensionType());
|
||||
dimensionRegistry = new DimensionRegistry(this);
|
||||
dimensionRegistry.load(config.getDimensionType());
|
||||
connections = new Connections();
|
||||
|
||||
ClientConnection.initPackets(this);
|
||||
|
@ -5,10 +5,12 @@ import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
public class Dimension {
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final CompoundBinaryTag data;
|
||||
|
||||
public Dimension(int id, CompoundBinaryTag data) {
|
||||
public Dimension(int id, String name, CompoundBinaryTag data) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@ -16,6 +18,10 @@ public class Dimension {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CompoundBinaryTag getData() {
|
||||
return data;
|
||||
}
|
||||
|
@ -12,29 +12,34 @@ import java.util.stream.Collectors;
|
||||
|
||||
public final class DimensionRegistry {
|
||||
|
||||
private final LimboServer server;
|
||||
|
||||
private Dimension defaultDimension;
|
||||
|
||||
private CompoundBinaryTag codec;
|
||||
private CompoundBinaryTag oldCodec;
|
||||
|
||||
public DimensionRegistry(LimboServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public CompoundBinaryTag getCodec() {
|
||||
return codec;
|
||||
}
|
||||
|
||||
public CompoundBinaryTag getOldCodec() {
|
||||
return oldCodec;
|
||||
}
|
||||
|
||||
public Dimension getDefaultDimension() {
|
||||
return defaultDimension;
|
||||
}
|
||||
|
||||
public void load(LimboServer server, String def) throws IOException {
|
||||
InputStream in = server.getClass().getResourceAsStream("/dimension_codec.snbt");
|
||||
public void load(String def) throws IOException {
|
||||
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");
|
||||
|
||||
CompoundBinaryTag overWorld = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(0)).get("element");
|
||||
@ -43,18 +48,33 @@ public final class DimensionRegistry {
|
||||
|
||||
switch (def.toLowerCase()) {
|
||||
case "overworld":
|
||||
defaultDimension = new Dimension(0, overWorld);
|
||||
defaultDimension = new Dimension(0, "minecraft:overworld", overWorld);
|
||||
break;
|
||||
case "nether":
|
||||
defaultDimension = new Dimension(-1, nether);
|
||||
defaultDimension = new Dimension(-1, "minecraft:nether", nether);
|
||||
break;
|
||||
case "the_end":
|
||||
defaultDimension = new Dimension(1, theEnd);
|
||||
defaultDimension = new Dimension(1, "minecraft:the_end", theEnd);
|
||||
break;
|
||||
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);
|
||||
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