Fix ChunkData including "fake" Block Entities (#556)

This commit is contained in:
Gatt 2021-12-27 19:45:15 +11:00 committed by TheMode
parent 90e88dc6e7
commit b8d51df58e

View File

@ -15,11 +15,15 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
public record ChunkData(@NotNull NBTCompound heightmaps, byte @NotNull [] data,
@NotNull Map<Integer, Block> blockEntities) implements Writeable {
public ChunkData {
blockEntities = Map.copyOf(blockEntities);
blockEntities = blockEntities.entrySet()
.stream()
.filter((entry) -> entry.getValue().registry().isBlockEntity())
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
}
public ChunkData(BinaryReader reader) {
@ -41,7 +45,6 @@ public record ChunkData(@NotNull NBTCompound heightmaps, byte @NotNull [] data,
final int index = entry.getKey();
final Block block = entry.getValue();
final var registry = block.registry();
if (!registry.isBlockEntity()) continue;
final Point point = ChunkUtils.getBlockPosition(index, 0, 0);
@ -50,7 +53,6 @@ public record ChunkData(@NotNull NBTCompound heightmaps, byte @NotNull [] data,
writer.writeVarInt(registry.blockEntityId());
NBTCompound resultNbt;
// Append handler tags
final BlockHandler handler = block.handler();