From 90e6ebc1bed9c3a262fbe8d9c093655bffb531f5 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 5 Nov 2019 18:55:59 -0600 Subject: [PATCH] More work on 1.13 --- .../geysermc/connector/GeyserConnector.java | 2 ++ .../network/session/GeyserSession.java | 30 +++++++++++++++---- .../java/JavaJoinGameTranslator.java | 23 ++++++++------ .../org/geysermc/connector/utils/BiValue.java | 12 -------- .../geysermc/connector/utils/SkinUtils.java | 13 +++++--- .../org/geysermc/connector/utils/Toolbox.java | 27 +++++------------ 6 files changed, 57 insertions(+), 50 deletions(-) delete mode 100644 connector/src/main/java/org/geysermc/connector/utils/BiValue.java diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index b294ed34..67c0b709 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -50,6 +50,7 @@ import org.geysermc.connector.plugin.GeyserPluginLoader; import org.geysermc.connector.plugin.GeyserPluginManager; import org.geysermc.connector.thread.PingPassthroughThread; import org.geysermc.connector.utils.FileUtils; +import org.geysermc.connector.utils.Toolbox; import java.io.File; import java.io.IOException; @@ -128,6 +129,7 @@ public class GeyserConnector implements Connector { logger.setDebug(config.isDebugMode()); + Toolbox.init(); TranslatorsInit.start(); commandMap = new GeyserCommandMap(this); 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 63547416..b0ff126d 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 @@ -43,6 +43,7 @@ import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; import com.nukkitx.protocol.bedrock.data.GameRule; +import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import com.nukkitx.protocol.bedrock.packet.TextPacket; @@ -57,7 +58,9 @@ import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.inventory.PlayerInventory; import org.geysermc.connector.network.session.cache.*; import org.geysermc.connector.network.translators.Registry; +import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.utils.Toolbox; +import org.geysermc.connector.world.chunk.ChunkPosition; import java.net.InetSocketAddress; import java.util.UUID; @@ -119,14 +122,33 @@ public class GeyserSession implements Player { } public void connect(RemoteServer remoteServer) { - // This has to be sent first so the player actually joins startGame(); - this.remoteServer = remoteServer; if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) { connector.getLogger().info("Attempting to login using offline mode... authentication is disabled."); authenticate(authenticationData.getName()); } + + Vector3f pos = Vector3f.ZERO; + int chunkX = pos.getFloorX() >> 4; + int chunkZ = pos.getFloorZ() >> 4; + for (int x = -3; x < 3; x++) { + for (int z = -3; z < 3; z++) { + LevelChunkPacket data = new LevelChunkPacket(); + data.setChunkX(chunkX + x); + data.setChunkZ(chunkZ + z); + data.setSubChunksLength(0); + data.setData(TranslatorsInit.EMPTY_LEVEL_CHUNK_DATA); + upstream.sendPacket(data); + } + } + + PlayStatusPacket playStatusPacket = new PlayStatusPacket(); + playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN); + upstream.sendPacket(playStatusPacket); + + System.out.println("play status sent"); + System.out.println(playerEntity.getPosition()); } public void authenticate(String username) { @@ -299,9 +321,5 @@ public class GeyserSession implements Player { startGamePacket.setItemEntries(Toolbox.ITEMS); startGamePacket.setVanillaVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion()); upstream.sendPacket(startGamePacket); - - PlayStatusPacket playStatusPacket = new PlayStatusPacket(); - playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN); - upstream.sendPacket(playStatusPacket); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java index 3c5a45bf..11644a08 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java @@ -26,10 +26,17 @@ package org.geysermc.connector.network.translators.java; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; -import com.nukkitx.protocol.bedrock.packet.*; +import com.nukkitx.math.vector.Vector3i; +import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; +import com.nukkitx.protocol.bedrock.packet.ChunkRadiusUpdatedPacket; +import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; +import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; + import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.world.chunk.ChunkPosition; public class JavaJoinGameTranslator extends PacketTranslator { @@ -38,16 +45,14 @@ public class JavaJoinGameTranslator extends PacketTranslator 32) session.setRenderDistance(32); // <3 u ViaVersion but I don't like crashing clients x) - ChunkRadiusUpdatedPacket packet1 = new ChunkRadiusUpdatedPacket(); - packet1.setRadius(session.getRenderDistance()); - session.getUpstream().sendPacket(packet1); + ChunkRadiusUpdatedPacket chunkRadiusPacket = new ChunkRadiusUpdatedPacket(); + chunkRadiusPacket.setRadius(session.getRenderDistance()); + session.getUpstream().sendPacket(chunkRadiusPacket); session.setSpawned(true); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/BiValue.java b/connector/src/main/java/org/geysermc/connector/utils/BiValue.java deleted file mode 100644 index 6ea88c4e..00000000 --- a/connector/src/main/java/org/geysermc/connector/utils/BiValue.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.geysermc.connector.utils; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@AllArgsConstructor(access = AccessLevel.PUBLIC) -@Getter -public class BiValue { - private F f; - private S s; -} diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java index 66d6f9ec..9bca433c 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java @@ -27,7 +27,7 @@ public class SkinUtils { profile.getIdAsString(), SkinProvider.getCachedSkin(profile.getId()).getSkinData(), SkinProvider.getCachedCape(data.getCapeUrl()).getCapeData(), - "geometry.humanoid.custom" + (data.isAlex() ? "Slim" : ""), + getLegacySkinGeometry("geometry.humanoid.custom" + (data.isAlex() ? "Slim" : "")), "" ); } @@ -40,7 +40,7 @@ public class SkinUtils { profile.getIdAsString(), SkinProvider.STEVE_SKIN, SkinProvider.EMPTY_CAPE.getCapeData(), - "geometry.humanoid", + getLegacySkinGeometry("geometry.humanoid"), "" ); } @@ -48,7 +48,7 @@ public class SkinUtils { public static PlayerListPacket.Entry buildEntryManually(UUID uuid, String username, long geyserId, String skinId, byte[] skinData, byte[] capeData, String geometryName, String geometryData) { - SerializedSkin serializedSkin = SerializedSkin.of(skinId, ImageData.of(skinData), ImageData.of(capeData), geometryName, geometryData, true); + SerializedSkin serializedSkin = SerializedSkin.of(skinId, ImageData.of(32, 64, skinData), ImageData.of(32, 64, capeData), geometryName, geometryData, true); PlayerListPacket.Entry entry = new PlayerListPacket.Entry(uuid); entry.setName(username); @@ -56,6 +56,7 @@ public class SkinUtils { entry.setSkin(serializedSkin); entry.setXuid(""); entry.setPlatformChatId(""); + entry.setTeacher(false); return entry; } @@ -122,7 +123,7 @@ public class SkinUtils { entity.getUuid().toString(), skin.getSkinData(), cape.getCapeData(), - "geometry.humanoid.custom" + (data.isAlex() ? "Slim" : ""), + getLegacySkinGeometry("geometry.humanoid.custom" + (data.isAlex() ? "Slim" : "")), "" ); @@ -145,4 +146,8 @@ public class SkinUtils { }); }); } + + private static String getLegacySkinGeometry(String geometryName) { + return "{\"geometry\" :{\"default\" :\"" + geometryName + "\"}}"; + } } 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 2d84249b..0b895c34 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -20,13 +20,13 @@ import java.util.*; public class Toolbox { - public static final Collection ITEMS; + public static final Collection ITEMS = new ArrayList<>(); public static ListTag BLOCKS; - public static final TIntObjectMap ITEM_ENTRIES; - public static final TIntObjectMap BLOCK_ENTRIES; + public static final TIntObjectMap ITEM_ENTRIES = new TIntObjectHashMap<>(); + public static final TIntObjectMap BLOCK_ENTRIES = new TIntObjectHashMap<>(); - static { + public static void init() { 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"); @@ -67,13 +67,10 @@ public class Toolbox { e.printStackTrace(); } - List startGameEntries = new ArrayList<>(); for (Map entry : startGameItems) { - startGameEntries.add(new StartGamePacket.ItemEntry((String) entry.get("name"), (short) ((int) entry.get("id")))); + ITEMS.add(new StartGamePacket.ItemEntry((String) entry.get("name"), (short) ((int) entry.get("id")))); } - ITEMS = startGameEntries; - InputStream itemStream = Toolbox.class.getClassLoader().getResourceAsStream("items.json"); ObjectMapper itemMapper = new ObjectMapper(); Map> items = new HashMap<>(); @@ -84,16 +81,12 @@ public class Toolbox { ex.printStackTrace(); } - TIntObjectMap itemEntries = new TIntObjectHashMap<>(); int itemIndex = 0; - for (Map.Entry> itemEntry : items.entrySet()) { - itemEntries.put(itemIndex, new ItemEntry(itemEntry.getKey(), itemIndex, (int) itemEntry.getValue().get("bedrock_id"), (int) itemEntry.getValue().get("bedrock_data"))); + ITEM_ENTRIES.put(itemIndex, new ItemEntry(itemEntry.getKey(), itemIndex, (int) itemEntry.getValue().get("bedrock_id"), (int) itemEntry.getValue().get("bedrock_data"))); itemIndex++; } - ITEM_ENTRIES = itemEntries; - InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("blocks.json"); ObjectMapper blockMapper = new ObjectMapper(); Map> blocks = new HashMap<>(); @@ -104,20 +97,16 @@ public class Toolbox { ex.printStackTrace(); } - TIntObjectMap blockEntries = new TIntObjectHashMap<>(); int blockIndex = 0; - for (Map.Entry> itemEntry : blocks.entrySet()) { if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) { GeyserLogger.DEFAULT.debug("Mapping " + itemEntry.getValue().get("bedrock_identifier") + " was not found for bedrock edition!"); - blockEntries.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, 248, 0)); // update block + BLOCK_ENTRIES.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, 248, 0)); // update block } else { - blockEntries.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, blockIdToIdentifier.get(itemEntry.getValue().get("bedrock_identifier")), (int) itemEntry.getValue().get("bedrock_data"))); + BLOCK_ENTRIES.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, blockIdToIdentifier.get(itemEntry.getValue().get("bedrock_identifier")), (int) itemEntry.getValue().get("bedrock_data"))); } blockIndex++; } - - BLOCK_ENTRIES = blockEntries; } } \ No newline at end of file