mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Add biomes
This commit is contained in:
parent
989312835f
commit
4dff067faa
5 changed files with 59 additions and 3 deletions
|
@ -41,6 +41,8 @@ import com.nukkitx.math.vector.Vector2f;
|
|||
import com.nukkitx.math.vector.Vector2i;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.NbtUtils;
|
||||
import com.nukkitx.nbt.stream.NBTInputStream;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
||||
|
@ -53,6 +55,7 @@ import org.geysermc.api.RemoteServer;
|
|||
import org.geysermc.api.session.AuthData;
|
||||
import org.geysermc.api.window.FormWindow;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.console.GeyserLogger;
|
||||
import org.geysermc.connector.entity.PlayerEntity;
|
||||
import org.geysermc.connector.inventory.PlayerInventory;
|
||||
import org.geysermc.connector.network.session.cache.*;
|
||||
|
@ -60,6 +63,7 @@ import org.geysermc.connector.network.translators.Registry;
|
|||
import org.geysermc.connector.utils.ChunkUtils;
|
||||
import org.geysermc.connector.utils.Toolbox;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -131,7 +135,22 @@ public class GeyserSession implements Player {
|
|||
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
|
||||
|
||||
BiomeDefinitionListPacket biomePacket = new BiomeDefinitionListPacket();
|
||||
biomePacket.setTag(CompoundTag.EMPTY);
|
||||
InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/biome_definitions.dat");
|
||||
if (stream == null) {
|
||||
throw new AssertionError("Unable to find bedrock/biome_definitions.dat");
|
||||
}
|
||||
|
||||
CompoundTag biomesTag;
|
||||
|
||||
NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream);
|
||||
try {
|
||||
biomesTag = (CompoundTag) nbtInputStream.readTag();
|
||||
biomePacket.setTag(biomesTag);
|
||||
nbtInputStream.close();
|
||||
} catch (Exception ex) {
|
||||
GeyserLogger.DEFAULT.warning("Failed to get biomes from biome definitions, is there something wrong with the file?");
|
||||
throw new AssertionError(ex);
|
||||
}
|
||||
upstream.sendPacket(biomePacket);
|
||||
|
||||
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package org.geysermc.connector.network.translators;
|
||||
import java.util.Arrays;
|
||||
|
||||
//Based off of ProtocolSupport's LegacyBiomeData.java https://github.com/ProtocolSupport/ProtocolSupport/blob/b2cad35977f3fcb65bee57b9e14fc9c975f71d32/src/protocolsupport/protocol/typeremapper/legacy/LegacyBiomeData.java
|
||||
//Array index formula by https://wiki.vg/Chunk_Format
|
||||
|
||||
public class BiomeTranslator {
|
||||
|
||||
public static byte[] toBedrockBiome(int[] biomeData) {
|
||||
byte[] bedrockData = new byte[256];
|
||||
if(biomeData == null) {
|
||||
return bedrockData;
|
||||
}
|
||||
|
||||
for (int z = 0; z < 16; z += 4) {
|
||||
for (int x = 0; x < 16; x += 4) {
|
||||
byte biomeId = biomeID(biomeData, x, z);
|
||||
fillArray(z, x, bedrockData, biomeId);
|
||||
fillArray(z + 1, x, bedrockData, biomeId);
|
||||
fillArray(z + 2, x, bedrockData, biomeId);
|
||||
fillArray(z + 3, x, bedrockData, biomeId);
|
||||
}
|
||||
}
|
||||
return bedrockData;
|
||||
}
|
||||
|
||||
protected static void fillArray(int z, int x, byte[] legacyBiomeData, int biomeId) {
|
||||
int offset = (z << 4) | x;
|
||||
Arrays.fill(legacyBiomeData, offset, offset + 4, (byte) biomeId);
|
||||
}
|
||||
|
||||
protected static byte biomeID(int[] biomeData, int x, int z) {
|
||||
return (byte) biomeData[((z >> 2) & 3) << 2 | ((x >> 2) & 3)];
|
||||
}
|
||||
}
|
|
@ -35,6 +35,7 @@ import io.netty.buffer.ByteBuf;
|
|||
import io.netty.buffer.Unpooled;
|
||||
import org.geysermc.api.Geyser;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.BiomeTranslator;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.utils.ChunkUtils;
|
||||
import org.geysermc.connector.world.chunk.ChunkSection;
|
||||
|
@ -74,7 +75,9 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
|||
section.writeToNetwork(byteBuf);
|
||||
}
|
||||
|
||||
byteBuf.writeBytes(chunkData.biomes); // Biomes - 256 bytes
|
||||
byte[] bedrockBiome = BiomeTranslator.toBedrockBiome(packet.getColumn().getBiomeData());
|
||||
|
||||
byteBuf.writeBytes(bedrockBiome); // Biomes - 256 bytes
|
||||
byteBuf.writeByte(0); // Border blocks - Edu edition only
|
||||
VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now
|
||||
|
||||
|
|
|
@ -131,7 +131,6 @@ public class ChunkUtils {
|
|||
public static final class ChunkData {
|
||||
public ChunkSection[] sections;
|
||||
|
||||
public byte[] biomes = new byte[256];
|
||||
public byte[] blockEntities = new byte[0];
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue