mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 14:37:31 +02:00
Hardcode heightmap value to dimension height. (#481)
This commit is contained in:
parent
f640351777
commit
d89e5cf2ee
@ -16,10 +16,13 @@ import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||
import net.minestom.server.utils.ArrayUtils;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.Utils;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -173,6 +176,23 @@ public class DynamicChunk extends Chunk {
|
||||
packet.chunkZ = chunkZ;
|
||||
packet.sections = sectionMap.clone(); // TODO deep clone
|
||||
packet.entries = entries.clone();
|
||||
|
||||
// TODO: don't hardcode heightmaps
|
||||
// Heightmap
|
||||
int dimensionHeight = getInstance().getDimensionType().getHeight();
|
||||
int[] motionBlocking = new int[16 * 16];
|
||||
int[] worldSurface = new int[16 * 16];
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
motionBlocking[x + z * 16] = 0;
|
||||
worldSurface[x + z * 16] = dimensionHeight - 1;
|
||||
}
|
||||
}
|
||||
final int bitsForHeight = MathUtils.bitsToRepresent(dimensionHeight);
|
||||
packet.heightmapsNBT = new NBTCompound()
|
||||
.setLongArray("MOTION_BLOCKING", Utils.encodeBlocks(motionBlocking, bitsForHeight))
|
||||
.setLongArray("WORLD_SURFACE", Utils.encodeBlocks(worldSurface, bitsForHeight));
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
|
@ -34,11 +34,7 @@ public class ChunkDataPacket implements ServerPacket {
|
||||
|
||||
private static final byte CHUNK_SECTION_COUNT = 16;
|
||||
|
||||
/**
|
||||
* Heightmaps NBT, as read from raw packet data.
|
||||
* Only filled by #read, and unused at the moment.
|
||||
*/
|
||||
public NBTCompound heightmapsNBT;
|
||||
public NBTCompound heightmapsNBT = new NBTCompound();
|
||||
|
||||
public ChunkDataPacket() {
|
||||
}
|
||||
@ -73,24 +69,8 @@ public class ChunkDataPacket implements ServerPacket {
|
||||
writer.writeLong(value);
|
||||
}
|
||||
|
||||
// TODO: don't hardcode heightmaps
|
||||
// Heightmap
|
||||
int[] motionBlocking = new int[16 * 16];
|
||||
int[] worldSurface = new int[16 * 16];
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
motionBlocking[x + z * 16] = 4;
|
||||
worldSurface[x + z * 16] = 5;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
writer.writeNBT("",
|
||||
new NBTCompound()
|
||||
.setLongArray("MOTION_BLOCKING", Utils.encodeBlocks(motionBlocking, 9))
|
||||
.setLongArray("WORLD_SURFACE", Utils.encodeBlocks(worldSurface, 9))
|
||||
);
|
||||
}
|
||||
writer.writeNBT("", heightmapsNBT);
|
||||
|
||||
// Biomes
|
||||
if (biomes == null || biomes.length == 0) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.utils;
|
||||
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Internal
|
||||
@ -96,4 +97,9 @@ public final class MathUtils {
|
||||
public static double mod(final double a, final double b) {
|
||||
return (a % b + b) % b;
|
||||
}
|
||||
|
||||
public static int bitsToRepresent(int n) {
|
||||
Check.argCondition(n < 1, "n must be greater than 0");
|
||||
return Integer.SIZE - Integer.numberOfLeadingZeros(n);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ public class DimensionType {
|
||||
.ceilingEnabled(false)
|
||||
.fixedTime(null)
|
||||
.ambientLight(0.0f)
|
||||
.height(256)
|
||||
.logicalHeight(256)
|
||||
.infiniburn(NamespaceID.from("minecraft:infiniburn_overworld"))
|
||||
.build();
|
||||
|
Loading…
Reference in New Issue
Block a user