Skip to content

Commit d828508

Browse files
committed
fix: add vanilla block entities to chunk entries map when loading sections
1 parent 6833d7b commit d828508

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/main/java/net/hollowcube/polar/StreamingPolarLoader.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.hollowcube.polar;
22

33
import com.github.luben.zstd.Zstd;
4+
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
45
import it.unimi.dsi.fastutil.objects.Object2IntMap;
56
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
67
import net.minestom.server.MinecraftServer;
@@ -9,6 +10,7 @@
910
import net.minestom.server.coordinate.CoordConversion;
1011
import net.minestom.server.instance.InstanceContainer;
1112
import net.minestom.server.instance.Section;
13+
import net.minestom.server.instance.block.Block;
1214
import net.minestom.server.network.NetworkBuffer;
1315
import net.minestom.server.utils.validate.Check;
1416
import net.minestom.server.world.biome.Biome;
@@ -131,7 +133,7 @@ private void readChunk(@NotNull NetworkBuffer buffer, int minSection, int maxSec
131133
// Load block data
132134
synchronized (chunk) {
133135
for (int sectionY = minSection; sectionY <= maxSection; sectionY++) {
134-
readSection(buffer, chunk.getSection(sectionY));
136+
readSection(buffer, chunk.getSection(sectionY), sectionY, chunkEntries);
135137
}
136138

137139
// Load block entities
@@ -168,7 +170,7 @@ private void readChunk(@NotNull NetworkBuffer buffer, int minSection, int maxSec
168170
}
169171
}
170172

171-
private void readSection(@NotNull NetworkBuffer buffer, @NotNull Section section) {
173+
private void readSection(@NotNull NetworkBuffer buffer, @NotNull Section section, int sectionY, @Nullable Int2ObjectMap<Block> chunkEntires) {
172174
if (buffer.read(BOOLEAN)) return; // Empty section
173175

174176
int[] blockPalette = readBlockPalette(buffer);
@@ -188,7 +190,15 @@ private void readSection(@NotNull NetworkBuffer buffer, @NotNull Section section
188190
for (int z = 0; z < CHUNK_SECTION_SIZE; z++) {
189191
for (int x = 0; x < CHUNK_SECTION_SIZE; x++) {
190192
int index = y * CHUNK_SECTION_SIZE * CHUNK_SECTION_SIZE + z * CHUNK_SECTION_SIZE + x;
191-
section.blockPalette().set(x, y, z, blockPalette[blockData[index]]);
193+
int blockStateId = blockPalette[blockData[index]];
194+
section.blockPalette().set(x, y, z, blockStateId);
195+
196+
// Vanilla block entities must be tracked in the chunk entries so they are sent to the client.
197+
var block = Block.fromStateId(blockStateId);
198+
if (chunkEntires != null && block.registry().isBlockEntity()) {
199+
int chunkY = sectionY * CHUNK_SECTION_SIZE + y;
200+
chunkEntires.putIfAbsent(CoordConversion.chunkBlockIndex(x, chunkY, z), block);
201+
}
192202
}
193203
}
194204
}

0 commit comments

Comments
 (0)