Skip to content

Commit

Permalink
Merge pull request #1 from BoomEaro/feature/1.18.2
Browse files Browse the repository at this point in the history
Feature/1.18.2
  • Loading branch information
vic256 authored Apr 2, 2022
2 parents 9269751 + dc6f85f commit cc51a9f
Show file tree
Hide file tree
Showing 10 changed files with 2,157 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public final class PacketSnapshots {
public static PacketSnapshot PACKET_TITLE_LEGACY_SUBTITLE;
public static PacketSnapshot PACKET_TITLE_LEGACY_TIMES;


private PacketSnapshots() { }

public static void initPackets(LimboServer server) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/ru/nanit/limbo/protocol/PacketSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public void encode() {
Map<Integer, Version> hashes = new HashMap<>();

for (Version version : Version.values()) {
if (version.equals(Version.UNDEFINED)) continue;

ByteMessage encodedMessage = ByteMessage.create();
packet.encode(encodedMessage, version);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void encode(ByteMessage msg, Version version) {

if (version.fromTo(Version.V1_8, Version.V1_9_1)) {
msg.writeByte(gameMode);
msg.writeByte(dimensionRegistry.getDefaultDimension().getId());
msg.writeByte(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeByte(0); // Difficulty
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
Expand All @@ -110,7 +110,7 @@ public void encode(ByteMessage msg, Version version) {

if (version.fromTo(Version.V1_9_2, Version.V1_13_2)) {
msg.writeByte(gameMode);
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
msg.writeInt(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeByte(0); // Difficulty
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
Expand All @@ -119,7 +119,7 @@ public void encode(ByteMessage msg, Version version) {

if (version.fromTo(Version.V1_14, Version.V1_14_4)) {
msg.writeByte(gameMode);
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
msg.writeInt(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
msg.writeVarInt(viewDistance);
Expand All @@ -128,7 +128,7 @@ public void encode(ByteMessage msg, Version version) {

if (version.fromTo(Version.V1_15, Version.V1_15_2)) {
msg.writeByte(gameMode);
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
msg.writeInt(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeLong(hashedSeed);
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
Expand All @@ -142,7 +142,7 @@ public void encode(ByteMessage msg, Version version) {
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getOldCodec());
msg.writeString(dimensionRegistry.getDefaultDimension().getName());
msg.writeString(dimensionRegistry.getDefaultDimension_1_16().getName());
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeByte(maxPlayers);
Expand All @@ -158,8 +158,8 @@ public void encode(ByteMessage msg, Version version) {
msg.writeByte(gameMode);
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getCodec());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension().getData());
msg.writeCompoundTag(dimensionRegistry.getCodec_1_16());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension_1_16().getData());
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeVarInt(maxPlayers);
Expand All @@ -175,8 +175,14 @@ public void encode(ByteMessage msg, Version version) {
msg.writeByte(gameMode);
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getCodec());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension().getData());
if (version.moreOrEqual(Version.V1_18_2)) {
msg.writeCompoundTag(dimensionRegistry.getCodec_1_18_2());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension_1_18_2().getData());
}
else {
msg.writeCompoundTag(dimensionRegistry.getCodec_1_16());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension_1_16().getData());
}
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeVarInt(maxPlayers);
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/ru/nanit/limbo/protocol/registry/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ public enum State {
map(0x0E, V1_13, V1_13_2),
map(0x0F, V1_14, V1_15_2),
map(0x10, V1_16, V1_16_4),
map(0x0F, V1_17, V1_18)
map(0x0F, V1_17, V1_18_2)
);

clientBound.register(PacketDeclareCommands::new,
map(0x11, V1_13, V1_14_4),
map(0x12, V1_15, V1_15_2),
map(0x11, V1_16, V1_16_1),
map(0x10, V1_16_2, V1_16_4),
map(0x12, V1_17, V1_18)
map(0x12, V1_17, V1_18_2)
);
clientBound.register(PacketJoinGame::new,
map(0x01, V1_8, V1_8),
Expand All @@ -101,15 +101,15 @@ public enum State {
map(0x26, V1_15, V1_15_2),
map(0x25, V1_16, V1_16_1),
map(0x24, V1_16_2, V1_16_4),
map(0x26, V1_17, V1_18)
map(0x26, V1_17, V1_18_2)
);
clientBound.register(PacketPluginMessage::new,
map(0x19, V1_13, V1_13_2),
map(0x18, V1_14, V1_14_4),
map(0x19, V1_15, V1_15_2),
map(0x18, V1_16, V1_16_1),
map(0x17, V1_16_2, V1_16_4),
map(0x18, V1_17, V1_18)
map(0x18, V1_17, V1_18_2)
);
clientBound.register(PacketPlayerAbilities::new,
map(0x39, V1_8, V1_8),
Expand All @@ -120,7 +120,7 @@ public enum State {
map(0x32, V1_15, V1_15_2),
map(0x31, V1_16, V1_16_1),
map(0x30, V1_16_2, V1_16_4),
map(0x32, V1_17, V1_18)
map(0x32, V1_17, V1_18_2)
);
clientBound.register(PacketPlayerPositionAndLook::new,
map(0x08, V1_8, V1_8),
Expand All @@ -131,7 +131,7 @@ public enum State {
map(0x36, V1_15, V1_15_2),
map(0x35, V1_16, V1_16_1),
map(0x34, V1_16_2, V1_16_4),
map(0x38, V1_17, V1_18)
map(0x38, V1_17, V1_18_2)
);
clientBound.register(PacketKeepAlive::new,
map(0x00, V1_8, V1_8),
Expand All @@ -141,21 +141,21 @@ public enum State {
map(0x21, V1_15, V1_15_2),
map(0x20, V1_16, V1_16_1),
map(0x1F, V1_16_2, V1_16_4),
map(0x21, V1_17, V1_18)
map(0x21, V1_17, V1_18_2)
);
clientBound.register(PacketChatMessage::new,
map(0x02, V1_8, V1_8),
map(0x0F, V1_9, V1_12_2),
map(0x0E, V1_13, V1_14_4),
map(0x0F, V1_15, V1_15_2),
map(0x0E, V1_16, V1_16_4),
map(0x0F, V1_17, V1_18)
map(0x0F, V1_17, V1_18_2)
);
clientBound.register(PacketBossBar::new,
map(0x0C, V1_9, V1_14_4),
map(0x0D, V1_15, V1_15_2),
map(0x0C, V1_16, V1_16_4),
map(0x0D, V1_17, V1_18)
map(0x0D, V1_17, V1_18_2)
);
clientBound.register(PacketPlayerInfo::new,
map(0x38, V1_8, V1_8),
Expand All @@ -166,7 +166,7 @@ public enum State {
map(0x34, V1_15, V1_15_2),
map(0x33, V1_16, V1_16_1),
map(0x32, V1_16_2, V1_16_4),
map(0x36, V1_17, V1_18)
map(0x36, V1_17, V1_18_2)
);
clientBound.register(PacketTitleLegacy::new,
map(0x45, V1_8, V1_11_1),
Expand All @@ -179,15 +179,15 @@ public enum State {
);
clientBound.register(PacketTitleSetTitle::new,
map(0x59, V1_17, V1_17_1),
map(0x5A, V1_18, V1_18)
map(0x5A, V1_18, V1_18_2)
);
clientBound.register(PacketTitleSetSubTitle::new,
map(0x57, V1_17, V1_17_1),
map(0x58, V1_18, V1_18)
map(0x58, V1_18, V1_18_2)
);
clientBound.register(PacketTitleTimes::new,
map(0x5A, V1_17, V1_17_1),
map(0x5B, V1_18, V1_18)
map(0x5B, V1_18, V1_18_2)
);
clientBound.register(PacketPlayerListHeader::new,
map(0x47, V1_8, V1_8),
Expand All @@ -200,7 +200,7 @@ public enum State {
map(0x54, V1_15, V1_15_2),
map(0x53, V1_16, V1_16_4),
map(0x5E, V1_17, V1_17_1),
map(0x5F, V1_18, V1_18)
map(0x5F, V1_18, V1_18_2)
);
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ru/nanit/limbo/protocol/registry/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public enum Version {
// 1.16.5 has same protocol number
V1_17(755),
V1_17_1(756),
V1_18(757);
V1_18(757),
// 1.18.1 has same protocol number
V1_18_2(758);

private static final Map<Integer, Version> VERSION_MAP;
private static final Version MAX;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ru/nanit/limbo/util/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
public final class Colors {

private static final char CHAR_FROM = '&';
private static final char CHAR_TO = '§';
private static final char CHAR_TO = '\u00a7';

private Colors() {}
private Colors() {
}

public static String of(String text) {
if (text == null) return null;
Expand Down
44 changes: 28 additions & 16 deletions src/main/java/ru/nanit/limbo/world/dimension/DimensionRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,52 +31,64 @@ public final class DimensionRegistry {

private final LimboServer server;

private Dimension defaultDimension;
private Dimension defaultDimension_1_16;
private Dimension defaultDimension_1_18_2;

private CompoundBinaryTag codec;
private CompoundBinaryTag codec_1_16;
private CompoundBinaryTag codec_1_18_2;
private CompoundBinaryTag oldCodec;

public DimensionRegistry(LimboServer server) {
this.server = server;
}

public CompoundBinaryTag getCodec() {
return codec;
public CompoundBinaryTag getCodec_1_16() {
return codec_1_16;
}

public CompoundBinaryTag getCodec_1_18_2() {
return codec_1_18_2;
}

public CompoundBinaryTag getOldCodec() {
return oldCodec;
}

public Dimension getDefaultDimension() {
return defaultDimension;
public Dimension getDefaultDimension_1_16() {
return defaultDimension_1_16;
}

public Dimension getDefaultDimension_1_18_2() {
return defaultDimension_1_18_2;
}

public void load(String def) throws IOException {
codec = readCodecFile("/dimension/codec_new.snbt");
codec_1_16 = readCodecFile("/dimension/codec_1_16.snbt");
codec_1_18_2 = readCodecFile("/dimension/codec_1_18_2.snbt");
// On 1.16-1.16.1 different codec format
oldCodec = readCodecFile("/dimension/codec_old.snbt");

ListBinaryTag dimensions = codec.getCompound("minecraft:dimension_type").getList("value");
defaultDimension_1_16 = getDefaultDimension(def, codec_1_16);
defaultDimension_1_18_2 = getDefaultDimension(def, codec_1_18_2);
}

private Dimension getDefaultDimension(String def, CompoundBinaryTag tag) {
ListBinaryTag dimensions = tag.getCompound("minecraft:dimension_type").getList("value");

CompoundBinaryTag overWorld = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(0)).get("element");
CompoundBinaryTag nether = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(2)).get("element");
CompoundBinaryTag theEnd = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(3)).get("element");

switch (def.toLowerCase()) {
case "overworld":
defaultDimension = new Dimension(0, "minecraft:overworld", overWorld);
break;
return new Dimension(0, "minecraft:overworld", overWorld);
case "nether":
defaultDimension = new Dimension(-1, "minecraft:nether", nether);
break;
return new Dimension(-1, "minecraft:nether", nether);
case "the_end":
defaultDimension = new Dimension(1, "minecraft:the_end", theEnd);
break;
return new Dimension(1, "minecraft:the_end", theEnd);
default:
defaultDimension = new Dimension(1, "minecraft:the_end", theEnd);
Logger.warning("Undefined dimension type: '%s'. Using THE_END as default", def);
break;
return new Dimension(1, "minecraft:the_end", theEnd);
}
}

Expand Down
File renamed without changes.
Loading

0 comments on commit cc51a9f

Please sign in to comment.