3030import com .flowpowered .math .vector .Vector3f ;
3131import com .flowpowered .math .vector .Vector3i ;
3232import com .github .steveice10 .mc .protocol .packet .ingame .server .ServerJoinGamePacket ;
33+ import com .nukkitx .nbt .CompoundTagBuilder ;
3334import com .nukkitx .nbt .NbtUtils ;
3435import com .nukkitx .nbt .stream .NBTOutputStream ;
3536import com .nukkitx .nbt .tag .CompoundTag ;
3839import com .nukkitx .protocol .bedrock .data .GameRule ;
3940import com .nukkitx .protocol .bedrock .packet .*;
4041import io .netty .buffer .ByteBuf ;
42+ import io .netty .buffer .ByteBufOutputStream ;
4143import io .netty .buffer .Unpooled ;
4244import org .geysermc .connector .utils .GeyserUtils ;
4345import org .geysermc .connector .utils .Toolbox ;
4446
4547import java .io .ByteArrayOutputStream ;
48+ import java .io .IOException ;
4649import java .util .HashMap ;
4750
4851public class TranslatorsInit {
52+ private static final CompoundTag EMPTY_TAG = CompoundTagBuilder .builder ().buildRootTag ();
53+ private static final byte [] EMPTY_LEVEL_CHUNK_DATA ;
54+
55+ static {
56+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream ()) {
57+ outputStream .write (new byte [258 ]); // Biomes + Border Size + Extra Data Size
58+
59+ try (NBTOutputStream stream = NbtUtils .createNetworkWriter (outputStream )) {
60+ stream .write (EMPTY_TAG );
61+ }
62+
63+ EMPTY_LEVEL_CHUNK_DATA = outputStream .toByteArray ();
64+ }catch (IOException e ) {
65+ throw new AssertionError ("Unable to generate empty level chunk data" );
66+ }
67+ }
68+
4969 public static void start () {
5070 addLoginPackets ();
5171 }
@@ -72,16 +92,16 @@ private static void addLoginPackets() {
7292 startGamePacket .setDifficulty (1 );
7393 startGamePacket .setDefaultSpawn (new Vector3i (0 , 0 , 0 ));
7494 startGamePacket .setAcheivementsDisabled (true );
75- startGamePacket .setTime (1300 );
95+ startGamePacket .setTime (0 );
7696 startGamePacket .setEduLevel (false );
7797 startGamePacket .setEduFeaturesEnabled (false );
7898 startGamePacket .setRainLevel (0 );
7999 startGamePacket .setLightningLevel (0 );
80- startGamePacket .setMultiplayerGame (false );
100+ startGamePacket .setMultiplayerGame (true );
81101 startGamePacket .setBroadcastingToLan (true );
82- startGamePacket .getGamerules ().add (( new GameRule ("showcoordinates" , true ) ));
83- startGamePacket .setPlatformBroadcastMode (GamePublishSetting .FRIENDS_OF_FRIENDS );
84- startGamePacket .setXblBroadcastMode (GamePublishSetting .FRIENDS_OF_FRIENDS );
102+ startGamePacket .getGamerules ().add (new GameRule <> ("showcoordinates" , true ));
103+ startGamePacket .setPlatformBroadcastMode (GamePublishSetting .PUBLIC );
104+ startGamePacket .setXblBroadcastMode (GamePublishSetting .PUBLIC );
85105 startGamePacket .setCommandsEnabled (true );
86106 startGamePacket .setTexturePacksRequired (false );
87107 startGamePacket .setBonusChestEnabled (false );
@@ -99,19 +119,13 @@ private static void addLoginPackets() {
99119 startGamePacket .setLevelId ("oerjhii" );
100120 startGamePacket .setWorldName ("world" );
101121 startGamePacket .setPremiumWorldTemplateId ("00000000-0000-0000-0000-000000000000" );
102- startGamePacket .setCurrentTick (1 );
103- startGamePacket .setEnchantmentSeed (1 );
122+ startGamePacket .setCurrentTick (0 );
123+ startGamePacket .setEnchantmentSeed (0 );
104124 startGamePacket .setMultiplayerCorrelationId ("" );
105125 startGamePacket .setCachedPalette (Toolbox .CACHED_PALLETE );
106126 startGamePacket .setItemEntries (Toolbox .ITEMS );
107127
108- session .getUpstream ().sendPacketImmediately (startGamePacket );
109-
110- BiomeDefinitionListPacket biomeDefListPacket = new BiomeDefinitionListPacket ();
111- session .getUpstream ().sendPacketImmediately (biomeDefListPacket );
112-
113- AvailableEntityIdentifiersPacket availableEntityPacket = new AvailableEntityIdentifiersPacket ();
114- session .getUpstream ().sendPacketImmediately (availableEntityPacket );
128+ session .getUpstream ().sendPacket (startGamePacket );
115129
116130 Vector3f pos = new Vector3f (0 , 0 , 0 );
117131
@@ -126,38 +140,9 @@ private static void addLoginPackets() {
126140 LevelChunkPacket data = new LevelChunkPacket ();
127141 data .setChunkX (chunkX + x );
128142 data .setChunkZ (chunkZ + z );
143+ data .setSubChunksLength (0 );
129144
130- ByteBuf buf = Unpooled .buffer ();
131-
132- data .setSubChunksLength (16 );
133-
134- for (int i = 0 ; i < 1 ; i ++) {
135- GeyserUtils .writeEmptySubChunk (buf );
136- }
137-
138- for (int i = 0 ; i < 256 ; i ++) {
139- buf .writeByte (0 );
140- }
141-
142- buf .writeZero (1 );
143-
144- VarInts .writeInt (buf , 0 );
145-
146- ByteArrayOutputStream s = new ByteArrayOutputStream ();
147-
148- NBTOutputStream stream = NbtUtils .createNetworkWriter (s );
149-
150- try {
151- stream .write (new CompoundTag ("" , new HashMap <>()));
152- s .close ();
153- stream .close ();
154- } catch (Exception e ) {
155- e .printStackTrace ();
156- }
157-
158- buf .writeBytes (s .toByteArray ());
159-
160- data .setData (new byte [0 ]);
145+ data .setData (EMPTY_LEVEL_CHUNK_DATA );
161146
162147 session .getUpstream ().sendPacketImmediately (data );
163148
0 commit comments