forked from GeyserMC/Geyser
Merge branch 'master' of https://github.com/GeyserMC/Geyser into feature/direct-block-mapping
Conflicts: connector/src/main/java/org/geysermc/connector/utils/Toolbox.java
This commit is contained in:
commit
f9cd88eaa2
7 changed files with 68 additions and 6 deletions
|
@ -34,7 +34,6 @@ Please note, Geyser is **not** (currently) a plugin. Watch the video below or ta
|
||||||
- Sounds
|
- Sounds
|
||||||
- Block Particles
|
- Block Particles
|
||||||
- Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities))
|
- Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities))
|
||||||
- Biome Colors
|
|
||||||
- Some Entity Flags
|
- Some Entity Flags
|
||||||
- Proper Movement
|
- Proper Movement
|
||||||
- Support to be Ran as a Plugin ([`plugin`](https://github.com/GeyserMC/Geyser/tree/plugin))
|
- Support to be Ran as a Plugin ([`plugin`](https://github.com/GeyserMC/Geyser/tree/plugin))
|
||||||
|
|
|
@ -41,6 +41,8 @@ import com.nukkitx.math.vector.Vector2f;
|
||||||
import com.nukkitx.math.vector.Vector2i;
|
import com.nukkitx.math.vector.Vector2i;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
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.nbt.tag.CompoundTag;
|
||||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||||
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
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.session.AuthData;
|
||||||
import org.geysermc.api.window.FormWindow;
|
import org.geysermc.api.window.FormWindow;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
|
import org.geysermc.connector.console.GeyserLogger;
|
||||||
import org.geysermc.connector.entity.PlayerEntity;
|
import org.geysermc.connector.entity.PlayerEntity;
|
||||||
import org.geysermc.connector.inventory.PlayerInventory;
|
import org.geysermc.connector.inventory.PlayerInventory;
|
||||||
import org.geysermc.connector.network.session.cache.*;
|
import org.geysermc.connector.network.session.cache.*;
|
||||||
|
@ -61,6 +64,7 @@ import org.geysermc.connector.network.translators.block.BlockTranslator;
|
||||||
import org.geysermc.connector.utils.ChunkUtils;
|
import org.geysermc.connector.utils.ChunkUtils;
|
||||||
import org.geysermc.connector.utils.Toolbox;
|
import org.geysermc.connector.utils.Toolbox;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -131,9 +135,9 @@ public class GeyserSession implements Player {
|
||||||
|
|
||||||
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
|
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
|
||||||
|
|
||||||
BiomeDefinitionListPacket biomePacket = new BiomeDefinitionListPacket();
|
BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket();
|
||||||
biomePacket.setTag(CompoundTag.EMPTY);
|
biomeDefinitionListPacket.setTag(Toolbox.BIOMES);
|
||||||
upstream.sendPacket(biomePacket);
|
upstream.sendPacket(biomeDefinitionListPacket);
|
||||||
|
|
||||||
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
|
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
|
||||||
entityPacket.setTag(CompoundTag.EMPTY);
|
entityPacket.setTag(CompoundTag.EMPTY);
|
||||||
|
|
|
@ -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 io.netty.buffer.Unpooled;
|
||||||
import org.geysermc.api.Geyser;
|
import org.geysermc.api.Geyser;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
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.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.utils.ChunkUtils;
|
import org.geysermc.connector.utils.ChunkUtils;
|
||||||
import org.geysermc.connector.world.chunk.ChunkSection;
|
import org.geysermc.connector.world.chunk.ChunkSection;
|
||||||
|
@ -74,7 +75,9 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
||||||
section.writeToNetwork(byteBuf);
|
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
|
byteBuf.writeByte(0); // Border blocks - Edu edition only
|
||||||
VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now
|
VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,6 @@ public class ChunkUtils {
|
||||||
public static final class ChunkData {
|
public static final class ChunkData {
|
||||||
public ChunkSection[] sections;
|
public ChunkSection[] sections;
|
||||||
|
|
||||||
public byte[] biomes = new byte[256];
|
|
||||||
public byte[] blockEntities = new byte[0];
|
public byte[] blockEntities = new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,14 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.nukkitx.nbt.NbtUtils;
|
||||||
|
import com.nukkitx.nbt.stream.NBTInputStream;
|
||||||
|
import com.nukkitx.nbt.tag.CompoundTag;
|
||||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import org.geysermc.connector.GeyserConnector;
|
||||||
|
import org.geysermc.connector.console.GeyserLogger;
|
||||||
import org.geysermc.connector.network.translators.item.ItemEntry;
|
import org.geysermc.connector.network.translators.item.ItemEntry;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -40,12 +45,29 @@ import java.util.*;
|
||||||
public class Toolbox {
|
public class Toolbox {
|
||||||
|
|
||||||
public static final ObjectMapper JSON_MAPPER = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
|
public static final ObjectMapper JSON_MAPPER = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
|
||||||
|
public static CompoundTag BIOMES;
|
||||||
|
|
||||||
public static final Collection<StartGamePacket.ItemEntry> ITEMS = new ArrayList<>();
|
public static final Collection<StartGamePacket.ItemEntry> ITEMS = new ArrayList<>();
|
||||||
|
|
||||||
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
|
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
/* Load biomes */
|
||||||
|
InputStream biomestream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/biome_definitions.dat");
|
||||||
|
if (biomestream == null) {
|
||||||
|
throw new AssertionError("Unable to find bedrock/biome_definitions.dat");
|
||||||
|
}
|
||||||
|
|
||||||
|
CompoundTag biomesTag;
|
||||||
|
|
||||||
|
try (NBTInputStream biomenbtInputStream = NbtUtils.createNetworkReader(biomestream)){
|
||||||
|
biomesTag = (CompoundTag) biomenbtInputStream.readTag();
|
||||||
|
BIOMES = biomesTag;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
GeyserLogger.DEFAULT.warning("Failed to get biomes from biome definitions, is there something wrong with the file?");
|
||||||
|
throw new AssertionError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
/* Load item palette */
|
/* Load item palette */
|
||||||
InputStream stream = getResource("bedrock/items.json");
|
InputStream stream = getResource("bedrock/items.json");
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue