From 0bb18d26b053fe96e554f444f26fe467b7adecad Mon Sep 17 00:00:00 2001 From: OnlyBMan <27742182+OnlyBMan@users.noreply.github.com> Date: Wed, 5 Feb 2020 22:02:23 -0500 Subject: [PATCH] Load biome definitions only once instead of everytime a new player joins --- .../network/session/GeyserSession.java | 21 +++---------------- .../org/geysermc/connector/utils/Toolbox.java | 18 ++++++++++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index b873db90f..f4835863c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -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); diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index b90aa2352..d2beb8074 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -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 ITEMS = new ArrayList<>(); public static ListTag BLOCKS; + public static CompoundTag BIOMES; public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); public static final Int2ObjectMap 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");