fix: update from lighting fix 35 rebase

This commit is contained in:
mworzala 2024-04-30 11:43:39 -04:00 committed by Matt Worzala
parent bcffaefa1d
commit e1a4ea1d74
4 changed files with 23 additions and 21 deletions

View File

@ -1,5 +1,6 @@
package net.minestom.server.instance;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.minestom.server.Tickable;
import net.minestom.server.Viewable;
import net.minestom.server.coordinate.Point;
@ -21,7 +22,6 @@ import net.minestom.server.world.biomes.Biome;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.List;
import java.util.Set;
@ -106,7 +106,7 @@ public abstract class Chunk implements Block.Getter, Block.Setter, Biome.Getter,
public abstract @NotNull Heightmap motionBlockingHeightmap();
public abstract @NotNull Heightmap worldSurfaceHeightmap();
public abstract void loadHeightmapsFromNBT(NBTCompound heightmaps);
public abstract void loadHeightmapsFromNBT(CompoundBinaryTag heightmaps);
public @NotNull Section getSectionAt(int blockY) {
return getSection(ChunkUtils.getChunkCoordinate(blockY));

View File

@ -3,6 +3,7 @@ package net.minestom.server.instance;
import com.extollit.gaming.ai.path.model.ColumnarOcclusionFieldList;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.nbt.LongArrayBinaryTag;
import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Vec;
@ -10,7 +11,9 @@ import net.minestom.server.entity.Entity;
import net.minestom.server.entity.pathfinding.PFBlock;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockHandler;
import net.minestom.server.instance.heightmap.*;
import net.minestom.server.instance.heightmap.Heightmap;
import net.minestom.server.instance.heightmap.MotionBlockingHeightmap;
import net.minestom.server.instance.heightmap.WorldSurfaceHeightmap;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.CachedPacket;
import net.minestom.server.network.packet.server.SendablePacket;
@ -168,13 +171,13 @@ public class DynamicChunk extends Chunk {
}
@Override
public void loadHeightmapsFromNBT(NBTCompound heightmapsNBT) {
if (heightmapsNBT.contains(motionBlockingHeightmap().NBTName())) {
motionBlockingHeightmap().loadFrom(heightmapsNBT.getLongArray(motionBlockingHeightmap().NBTName()));
public void loadHeightmapsFromNBT(CompoundBinaryTag heightmapsNBT) {
if (heightmapsNBT.get(motionBlockingHeightmap().NBTName()) instanceof LongArrayBinaryTag array) {
motionBlockingHeightmap().loadFrom(array.value());
}
if (heightmapsNBT.contains(worldSurfaceHeightmap().NBTName())) {
worldSurfaceHeightmap().loadFrom(heightmapsNBT.getLongArray(worldSurfaceHeightmap().NBTName()));
if (heightmapsNBT.get(worldSurfaceHeightmap().NBTName()) instanceof LongArrayBinaryTag array) {
worldSurfaceHeightmap().loadFrom(array.value());
}
}
@ -258,7 +261,7 @@ public class DynamicChunk extends Chunk {
private @NotNull ChunkDataPacket createChunkPacket() {
final byte[] data;
final NBTCompound heightmapsNBT;
final CompoundBinaryTag heightmapsNBT;
synchronized (this) {
heightmapsNBT = getHeightmapNBT();
@ -310,12 +313,12 @@ public class DynamicChunk extends Chunk {
);
}
private NBTCompound getHeightmapNBT() {
private CompoundBinaryTag getHeightmapNBT() {
if (needsCompleteHeightmapRefresh) calculateFullHeightmap();
return NBT.Compound(Map.of(
motionBlocking.NBTName(), motionBlocking.getNBT(),
worldSurface.NBTName(), worldSurface.getNBT()
));
return CompoundBinaryTag.builder()
.putLongArray(motionBlocking.NBTName(), motionBlocking.getNBT())
.putLongArray(worldSurface.NBTName(), worldSurface.getNBT())
.build();
}
private void calculateFullHeightmap() {

View File

@ -114,6 +114,8 @@ public class AnvilLoader implements IChunkLoader {
// Block entities
loadBlockEntities(chunk, chunkData);
chunk.loadHeightmapsFromNBT(chunkData.getCompound("Heightmaps"));
} else {
LOGGER.warn("Skipping partially generated chunk at {}, {} with status {}", chunkX, chunkZ, status);
}

View File

@ -4,9 +4,6 @@ import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.block.Block;
import net.minestom.server.utils.MathUtils;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.collections.ImmutableLongArray;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTLongArray;
import static net.minestom.server.instance.Chunk.CHUNK_SIZE_X;
import static net.minestom.server.instance.Chunk.CHUNK_SIZE_Z;
@ -59,13 +56,13 @@ public abstract class Heightmap {
setHeightY(x, z, y);
}
public NBTLongArray getNBT() {
public long[] getNBT() {
final int dimensionHeight = chunk.getInstance().getDimensionType().getHeight();
final int bitsForHeight = MathUtils.bitsToRepresent(dimensionHeight);
return NBT.LongArray(encode(heights, bitsForHeight));
return encode(heights, bitsForHeight);
}
public void loadFrom(ImmutableLongArray data) {
public void loadFrom(long[] data) {
final int dimensionHeight = chunk.getInstance().getDimensionType().getHeight();
final int bitsPerEntry = MathUtils.bitsToRepresent(dimensionHeight);
@ -78,7 +75,7 @@ public abstract class Heightmap {
for (int i = 0; i < heights.length; i++) {
final int indexInContainer = i % entriesPerLong;
heights[i] = (short) ((int)(data.get(containerIndex) >> (indexInContainer * bitsPerEntry)) & entryMask);
heights[i] = (short) ((int)(data[containerIndex] >> (indexInContainer * bitsPerEntry)) & entryMask);
if (indexInContainer == maxPossibleIndexInContainer) containerIndex++;
}