Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minecraft 1.21 bugfixes #677

Merged
merged 4 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/config/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum Version {
V1_20_2(764, 3578),
V1_20_4(765, 3698),
V1_20_6(766, 3839),
V1_21(767, 3953),
ANY(0, 0);

public final int dataVersion;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/game/data/RenderDistanceExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public void updatePlayerPos(Coordinate2D newPos) {
if (this.extendedDistance == 0) {
return;
}
// TODO: for 1.21, fix client unable to read chunk data packets generated by downloader for some reason
if (Config.versionReporter().isAtLeast(Version.V1_21)) {
return;
}


int dist = this.extendedDistance;
if (oldPos.isInRangeChebyshev(newChunkPos, 1)) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/game/data/WorldManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@ public Set<Coordinate2D> sendChunksToPlayer(Collection<Coordinate2D> desired) {
// send a packet with the chunk to the client
Chunk chunk = chunkBinary.toChunk(withDim);

// skip chunks loaded in an earlier version
if (chunk.getDataVersion() != Config.versionReporter().getDataVersion()) {
continue;
}

try {
PacketBuilder chunkData = chunk.toPacket();
PacketBuilder light = chunk.toLightPacket();
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/game/data/dimension/DimensionRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ private void readBiomes(ListTag biomeList) {
}

public Dimension getDimension(String name) {
return dimensions.get(name);
var dim = dimensions.get(name);

if (dim == null) {
System.out.println("Warning: Dimension " + name + " not found, using overworld");
return Dimension.OVERWORLD;
}

return dim;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/game/data/entity/specific/Villager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void updateTrades(List<VillagerTrade> trades, int villagerLevel, int vill
}

private void addTradeNbtTags(CompoundTag root) {
if (trades == null || trades.size() == 0) {
if (trades == null || trades.isEmpty()) {
return;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/game/data/villagers/VillagerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public void lastInteractedWith(DataTypeProvider provider) {
}

public void parseAndStoreVillagerTrade(DataTypeProvider provider) {
// TODO: villager trades cannot be saved since readSlot is broken in 1.20.2+ due to the
// new item components
if (Config.versionReporter().isAtLeast(Version.V1_20_2)) {
return;
}

if (lastInteractedWith == null) {
return; // This should be impossible
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/game/data/chunk/ChunkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private void testFor(int protocolVersion, String dataFile) throws IOException, C
biomeMap.put("minecraft:badlands", new Biome(0));
biomeMap.put("minecraft:forest", new Biome(1));
biomeMap.put("minecraft:river", new Biome(2));
biomeMap.put("minecraft:plains", new Biome(3));
when(codecMock.getBiomeRegistry()).thenReturn(new BiomeRegistry(biomeMap));
when(mock.getDimensionRegistry()).thenReturn(codecMock);

Expand Down Expand Up @@ -184,4 +185,9 @@ void chunk_1_17() throws IOException, ClassNotFoundException {
void chunk_1_19() throws IOException, ClassNotFoundException {
testFor(Version.V1_19.protocolVersion, "chunkdata_1_19");
}

@Test
void chunk_1_21() throws IOException, ClassNotFoundException {
testFor(Version.V1_21.protocolVersion, "chunkdata_1_21");
}
}
Binary file added src/test/resources/chunkdata_1_21
Binary file not shown.
Loading