Load biome definitions only once instead of everytime a new player joins

This commit is contained in:
OnlyBMan 2020-02-05 22:02:23 -05:00
parent 4dff067faa
commit 0bb18d26b0
2 changed files with 21 additions and 18 deletions

View File

@ -134,24 +134,9 @@ public class GeyserSession implements Player {
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
BiomeDefinitionListPacket biomePacket = new BiomeDefinitionListPacket();
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);
BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket();
biomeDefinitionListPacket.setTag(Toolbox.BIOMES);
upstream.sendPacket(biomeDefinitionListPacket);
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
entityPacket.setTag(CompoundTag.EMPTY);

View File

@ -31,6 +31,7 @@ import com.nukkitx.nbt.stream.NBTInputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.nbt.tag.ListTag;
import com.nukkitx.nbt.tag.Tag;
import com.nukkitx.protocol.bedrock.packet.BiomeDefinitionListPacket;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -47,11 +48,27 @@ public class Toolbox {
public static final Collection<StartGamePacket.ItemEntry> ITEMS = new ArrayList<>();
public static ListTag<CompoundTag> BLOCKS;
public static CompoundTag BIOMES;
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
public static final Int2ObjectMap<BlockEntry> BLOCK_ENTRIES = new Int2ObjectOpenHashMap<>();
public static void init() {
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);
}
InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/runtime_block_states.dat");
if (stream == null) {
throw new AssertionError("Unable to find bedrock/runtime_block_states.dat");
@ -69,6 +86,7 @@ public class Toolbox {
}
BLOCKS = blocksTag;
InputStream stream2 = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/items.json");
if (stream2 == null) {
throw new AssertionError("Items Table not found");