forked from GeyserMC/Geyser
More work on 1.13
This commit is contained in:
parent
18c13067b8
commit
90e6ebc1be
6 changed files with 57 additions and 50 deletions
|
@ -50,6 +50,7 @@ import org.geysermc.connector.plugin.GeyserPluginLoader;
|
||||||
import org.geysermc.connector.plugin.GeyserPluginManager;
|
import org.geysermc.connector.plugin.GeyserPluginManager;
|
||||||
import org.geysermc.connector.thread.PingPassthroughThread;
|
import org.geysermc.connector.thread.PingPassthroughThread;
|
||||||
import org.geysermc.connector.utils.FileUtils;
|
import org.geysermc.connector.utils.FileUtils;
|
||||||
|
import org.geysermc.connector.utils.Toolbox;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -128,6 +129,7 @@ public class GeyserConnector implements Connector {
|
||||||
|
|
||||||
logger.setDebug(config.isDebugMode());
|
logger.setDebug(config.isDebugMode());
|
||||||
|
|
||||||
|
Toolbox.init();
|
||||||
TranslatorsInit.start();
|
TranslatorsInit.start();
|
||||||
|
|
||||||
commandMap = new GeyserCommandMap(this);
|
commandMap = new GeyserCommandMap(this);
|
||||||
|
|
|
@ -43,6 +43,7 @@ import com.nukkitx.math.vector.Vector3i;
|
||||||
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;
|
||||||
import com.nukkitx.protocol.bedrock.data.GameRule;
|
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.PlayStatusPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.TextPacket;
|
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.inventory.PlayerInventory;
|
||||||
import org.geysermc.connector.network.session.cache.*;
|
import org.geysermc.connector.network.session.cache.*;
|
||||||
import org.geysermc.connector.network.translators.Registry;
|
import org.geysermc.connector.network.translators.Registry;
|
||||||
|
import org.geysermc.connector.network.translators.TranslatorsInit;
|
||||||
import org.geysermc.connector.utils.Toolbox;
|
import org.geysermc.connector.utils.Toolbox;
|
||||||
|
import org.geysermc.connector.world.chunk.ChunkPosition;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -119,14 +122,33 @@ public class GeyserSession implements Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect(RemoteServer remoteServer) {
|
public void connect(RemoteServer remoteServer) {
|
||||||
// This has to be sent first so the player actually joins
|
|
||||||
startGame();
|
startGame();
|
||||||
|
|
||||||
this.remoteServer = remoteServer;
|
this.remoteServer = remoteServer;
|
||||||
if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) {
|
if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) {
|
||||||
connector.getLogger().info("Attempting to login using offline mode... authentication is disabled.");
|
connector.getLogger().info("Attempting to login using offline mode... authentication is disabled.");
|
||||||
authenticate(authenticationData.getName());
|
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) {
|
public void authenticate(String username) {
|
||||||
|
@ -299,9 +321,5 @@ public class GeyserSession implements Player {
|
||||||
startGamePacket.setItemEntries(Toolbox.ITEMS);
|
startGamePacket.setItemEntries(Toolbox.ITEMS);
|
||||||
startGamePacket.setVanillaVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion());
|
startGamePacket.setVanillaVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion());
|
||||||
upstream.sendPacket(startGamePacket);
|
upstream.sendPacket(startGamePacket);
|
||||||
|
|
||||||
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
|
|
||||||
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
|
||||||
upstream.sendPacket(playStatusPacket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,17 @@
|
||||||
package org.geysermc.connector.network.translators.java;
|
package org.geysermc.connector.network.translators.java;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
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.entity.PlayerEntity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
import org.geysermc.connector.world.chunk.ChunkPosition;
|
||||||
|
|
||||||
public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacket> {
|
public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacket> {
|
||||||
|
|
||||||
|
@ -38,16 +45,14 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
||||||
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
||||||
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
||||||
bedrockPacket.setPlayerPermission(1);
|
bedrockPacket.setPlayerPermission(1);
|
||||||
session.getUpstream().sendPacketImmediately(bedrockPacket);
|
session.getUpstream().sendPacket(bedrockPacket);
|
||||||
|
|
||||||
PlayStatusPacket playStatus = new PlayStatusPacket();
|
PlayStatusPacket playStatus = new PlayStatusPacket();
|
||||||
playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
|
playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
|
||||||
session.getUpstream().sendPacketImmediately(playStatus);
|
session.getUpstream().sendPacket(playStatus);
|
||||||
|
|
||||||
PlayerEntity entity = session.getPlayerEntity();
|
PlayerEntity entity = session.getPlayerEntity();
|
||||||
if (entity == null) return;
|
entity.setEntityId(packet.getEntityId());
|
||||||
|
|
||||||
session.getPlayerEntity().setEntityId(packet.getEntityId());
|
|
||||||
|
|
||||||
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
||||||
playerGameTypePacket.setGamemode(packet.getGameMode().ordinal());
|
playerGameTypePacket.setGamemode(packet.getGameMode().ordinal());
|
||||||
|
@ -62,9 +67,9 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
||||||
session.setRenderDistance(packet.getViewDistance() + 1); // +1 to be sure it includes every chunk
|
session.setRenderDistance(packet.getViewDistance() + 1); // +1 to be sure it includes every chunk
|
||||||
if (session.getRenderDistance() > 32) session.setRenderDistance(32); // <3 u ViaVersion but I don't like crashing clients x)
|
if (session.getRenderDistance() > 32) session.setRenderDistance(32); // <3 u ViaVersion but I don't like crashing clients x)
|
||||||
|
|
||||||
ChunkRadiusUpdatedPacket packet1 = new ChunkRadiusUpdatedPacket();
|
ChunkRadiusUpdatedPacket chunkRadiusPacket = new ChunkRadiusUpdatedPacket();
|
||||||
packet1.setRadius(session.getRenderDistance());
|
chunkRadiusPacket.setRadius(session.getRenderDistance());
|
||||||
session.getUpstream().sendPacket(packet1);
|
session.getUpstream().sendPacket(chunkRadiusPacket);
|
||||||
|
|
||||||
session.setSpawned(true);
|
session.setSpawned(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<F, S> {
|
|
||||||
private F f;
|
|
||||||
private S s;
|
|
||||||
}
|
|
|
@ -27,7 +27,7 @@ public class SkinUtils {
|
||||||
profile.getIdAsString(),
|
profile.getIdAsString(),
|
||||||
SkinProvider.getCachedSkin(profile.getId()).getSkinData(),
|
SkinProvider.getCachedSkin(profile.getId()).getSkinData(),
|
||||||
SkinProvider.getCachedCape(data.getCapeUrl()).getCapeData(),
|
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(),
|
profile.getIdAsString(),
|
||||||
SkinProvider.STEVE_SKIN,
|
SkinProvider.STEVE_SKIN,
|
||||||
SkinProvider.EMPTY_CAPE.getCapeData(),
|
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,
|
public static PlayerListPacket.Entry buildEntryManually(UUID uuid, String username, long geyserId,
|
||||||
String skinId, byte[] skinData, byte[] capeData,
|
String skinId, byte[] skinData, byte[] capeData,
|
||||||
String geometryName, String geometryData) {
|
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);
|
PlayerListPacket.Entry entry = new PlayerListPacket.Entry(uuid);
|
||||||
entry.setName(username);
|
entry.setName(username);
|
||||||
|
@ -56,6 +56,7 @@ public class SkinUtils {
|
||||||
entry.setSkin(serializedSkin);
|
entry.setSkin(serializedSkin);
|
||||||
entry.setXuid("");
|
entry.setXuid("");
|
||||||
entry.setPlatformChatId("");
|
entry.setPlatformChatId("");
|
||||||
|
entry.setTeacher(false);
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ public class SkinUtils {
|
||||||
entity.getUuid().toString(),
|
entity.getUuid().toString(),
|
||||||
skin.getSkinData(),
|
skin.getSkinData(),
|
||||||
cape.getCapeData(),
|
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 + "\"}}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,13 @@ import java.util.*;
|
||||||
|
|
||||||
public class Toolbox {
|
public class Toolbox {
|
||||||
|
|
||||||
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
|
public static final Collection<StartGamePacket.ItemEntry> ITEMS = new ArrayList<>();
|
||||||
public static ListTag<CompoundTag> BLOCKS;
|
public static ListTag<CompoundTag> BLOCKS;
|
||||||
|
|
||||||
public static final TIntObjectMap<ItemEntry> ITEM_ENTRIES;
|
public static final TIntObjectMap<ItemEntry> ITEM_ENTRIES = new TIntObjectHashMap<>();
|
||||||
public static final TIntObjectMap<BlockEntry> BLOCK_ENTRIES;
|
public static final TIntObjectMap<BlockEntry> BLOCK_ENTRIES = new TIntObjectHashMap<>();
|
||||||
|
|
||||||
static {
|
public static void init() {
|
||||||
InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/runtime_block_states.dat");
|
InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/runtime_block_states.dat");
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
throw new AssertionError("Unable to find bedrock/runtime_block_states.dat");
|
throw new AssertionError("Unable to find bedrock/runtime_block_states.dat");
|
||||||
|
@ -67,13 +67,10 @@ public class Toolbox {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<StartGamePacket.ItemEntry> startGameEntries = new ArrayList<>();
|
|
||||||
for (Map entry : startGameItems) {
|
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");
|
InputStream itemStream = Toolbox.class.getClassLoader().getResourceAsStream("items.json");
|
||||||
ObjectMapper itemMapper = new ObjectMapper();
|
ObjectMapper itemMapper = new ObjectMapper();
|
||||||
Map<String, Map<String, Object>> items = new HashMap<>();
|
Map<String, Map<String, Object>> items = new HashMap<>();
|
||||||
|
@ -84,16 +81,12 @@ public class Toolbox {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
TIntObjectMap<ItemEntry> itemEntries = new TIntObjectHashMap<>();
|
|
||||||
int itemIndex = 0;
|
int itemIndex = 0;
|
||||||
|
|
||||||
for (Map.Entry<String, Map<String, Object>> itemEntry : items.entrySet()) {
|
for (Map.Entry<String, Map<String, Object>> 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++;
|
itemIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ITEM_ENTRIES = itemEntries;
|
|
||||||
|
|
||||||
InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("blocks.json");
|
InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("blocks.json");
|
||||||
ObjectMapper blockMapper = new ObjectMapper();
|
ObjectMapper blockMapper = new ObjectMapper();
|
||||||
Map<String, Map<String, Object>> blocks = new HashMap<>();
|
Map<String, Map<String, Object>> blocks = new HashMap<>();
|
||||||
|
@ -104,20 +97,16 @@ public class Toolbox {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
TIntObjectMap<BlockEntry> blockEntries = new TIntObjectHashMap<>();
|
|
||||||
int blockIndex = 0;
|
int blockIndex = 0;
|
||||||
|
|
||||||
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
|
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
|
||||||
if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) {
|
if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) {
|
||||||
GeyserLogger.DEFAULT.debug("Mapping " + itemEntry.getValue().get("bedrock_identifier") + " was not found for bedrock edition!");
|
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 {
|
} 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++;
|
blockIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
BLOCK_ENTRIES = blockEntries;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue