Skip to content

Commit

Permalink
Merge pull request #545 from n90p/mc-1.20
Browse files Browse the repository at this point in the history
Support for 1.20
  • Loading branch information
mircokroon authored Jun 19, 2023
2 parents 59117cb + 975ea6f commit 3ac64f2
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If you run into any problems, check the [FAQ](https://github.com/mircokroon/mine

### Requirements
- Java 17 or higher
- Minecraft version 1.12.2+ // 1.13.2+ // 1.14.1+ // 1.15.2+ // 1.16.2+ // 1.17+ // 1.18+ // 1.19.3+
- Minecraft version 1.12.2+ // 1.13.2+ // 1.14.1+ // 1.15.2+ // 1.16.2+ // 1.17+ // 1.18+ // 1.19.3+ // 1.20+

### Command-line
[Download](https://github.com/mircokroon/minecraft-world-downloader/releases/latest/download/world-downloader.jar) the cross-platform `world-downloader.jar` and run it using the command-line:
Expand Down
1 change: 1 addition & 0 deletions src/main/java/config/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum Version {
V1_18(757, 2860),
V1_19(759, 3105),
V1_19_3(761, 3218),
V1_20(763, 3463),
ANY(0, 0);

public final int dataVersion;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/game/data/chunk/ChunkFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void clear() {
*/
private static Chunk getVersionedChunk(int dataVersion, CoordinateDim2D chunkPos) {
return VersionReporter.select(dataVersion, Chunk.class,
Option.of(Version.V1_20, () -> new Chunk_1_20(chunkPos, dataVersion)),
Option.of(Version.V1_18, () -> new Chunk_1_18(chunkPos, dataVersion)),
Option.of(Version.V1_17, () -> new Chunk_1_17(chunkPos, dataVersion)),
Option.of(Version.V1_16, () -> new Chunk_1_16(chunkPos, dataVersion)),
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/game/data/chunk/version/Chunk_1_16.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void writeBiomes(PacketBuilder packet) {

@Override
public void updateBlocks(Coordinate3D pos, DataTypeProvider provider) {
provider.readBoolean();
parseLightEdgesTrusted(provider);

int count = provider.readVarInt();
Collection<Coordinate3D> toUpdate = new ArrayList<>();
Expand All @@ -68,15 +68,27 @@ public void updateBlocks(Coordinate3D pos, DataTypeProvider provider) {

@Override
public void updateLight(DataTypeProvider provider) {
boolean isTrusted = provider.readBoolean();
parseLightEdgesTrusted(provider);

super.updateLight(provider);
}


/**
* Versions < 1.20 include a boolean for lighting data on edges, removed later
*/
void parseLightEdgesTrusted(DataTypeProvider provider) {
provider.readBoolean();
}

void writeLightEdgesTrusted(PacketBuilder packet) {
packet.writeBoolean(true);
}

@Override
protected PacketBuilder buildLightPacket() {
PacketBuilder packet = super.buildLightPacket();
packet.writeBoolean(true);
writeLightEdgesTrusted(packet);
return packet;
}
}
2 changes: 1 addition & 1 deletion src/main/java/game/data/chunk/version/Chunk_1_17.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void writeLightToPacket(PacketBuilder packet) {

@Override
public void updateLight(DataTypeProvider provider) {
boolean isTrusted = provider.readBoolean();
parseLightEdgesTrusted(provider);

BitSet skyLightMask = provider.readBitSet();
BitSet blockLightMask = provider.readBitSet();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/game/data/chunk/version/Chunk_1_18.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public PacketBuilder toPacket() {
// we don't include block entities - these chunks will be far away so they shouldn't be rendered anyway
packet.writeVarInt(0);

packet.writeBoolean(true);
writeLightEdgesTrusted(packet);
writeLightToPacket(packet);

return packet;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/game/data/chunk/version/Chunk_1_20.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package game.data.chunk.version;

import game.data.coordinates.CoordinateDim2D;
import packets.DataTypeProvider;
import packets.builder.PacketBuilder;

public class Chunk_1_20 extends Chunk_1_18 {
public Chunk_1_20(CoordinateDim2D location, int version) {
super(location, version);
}

/**
* Trusted edges parameter for lighting on chunk edges was removed in 1.20
*/
@Override
void parseLightEdgesTrusted(DataTypeProvider provider) {

}

@Override
void writeLightEdgesTrusted(PacketBuilder packet) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public ClientBoundGamePacketHandler_1_19(ConnectionManager connectionManager) {
replacement.copy(provider, STRING, LONG);
}

replacement.copyRemainder(provider);

getConnectionManager().getEncryptionManager().sendImmediately(replacement);
return false;
});
Expand Down
39 changes: 39 additions & 0 deletions src/main/resources/protocol-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,45 @@
"0x31": "UseItemOn",
"0x32": "UseItem"
}
},
"763": {
"version": "1.20",
"dataVersion": 3463,
"clientBound": {
"0x01": "AddEntity",
"0x03": "AddPlayer",
"0x08": "BlockEntityData",
"0x0a": "BlockUpdate",
"0x11": "ContainerClose",
"0x12": "ContainerSetContent",
"0x1e": "ForgetLevelChunk",
"0x24": "LevelChunkWithLight",
"0x27": "LightUpdate",
"0x28": "Login",
"0x29": "MapItemData",
"0x2b": "MoveEntityPos",
"0x2c": "MoveEntityPosRot",
"0x30": "OpenScreen",
"0x3e": "RemoveEntities",
"0x41": "Respawn",
"0x43": "SectionBlocksUpdate",
"0x4f": "SetChunkCacheRadius",
"0x52": "SetEntityData",
"0x55": "SetEquipment",
"0x64": "SystemChat",
"0x68": "TeleportEntity"
},
"serverBound": {
"0x0c": "ContainerClose",
"0x10": "Interact",
"0x14": "MovePlayerPos",
"0x15": "MovePlayerPosRot",
"0x16": "MovePlayerRot",
"0x18": "MoveVehicle",
"0x29": "SetCommandBlock",
"0x31": "UseItemOn",
"0x32": "UseItem"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void bestMatch() {
versions.put(757, "1.18");
versions.put(758, "1.18");
versions.put(761, "1.19.3");
versions.put(763, "1.20");

versions.forEach((k, v) -> {
assertThat(pvh.getProtocolByProtocolVersion(k).getVersion()).isEqualTo(v);
Expand Down

0 comments on commit 3ac64f2

Please sign in to comment.