diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java index 0d3b8ef16..0fd8d849b 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java @@ -169,9 +169,10 @@ public class GeyserSpigotInjector extends GeyserInjector { * For the future, if someone wants to properly fix this - as of December 28, 2021, it happens on 1.16.5/1.17.1/1.18.1 EXCEPT Spigot 1.16.5 */ private void workAroundWeirdBug(GeyserBootstrap bootstrap) { + MinecraftProtocol protocol = new MinecraftProtocol(); LocalSession session = new LocalSession(bootstrap.getGeyserConfig().getRemote().getAddress(), bootstrap.getGeyserConfig().getRemote().getPort(), this.serverSocketAddress, - InetAddress.getLoopbackAddress().getHostAddress(), new MinecraftProtocol()); + InetAddress.getLoopbackAddress().getHostAddress(), protocol, protocol.createHelper()); session.connect(); } diff --git a/core/pom.xml b/core/pom.xml index b639827b6..6fe54f8d5 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -171,7 +171,7 @@ com.github.steveice10 packetlib - 2.1-SNAPSHOT + 3.0 compile diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index 18076763e..04e4727d0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -26,9 +26,7 @@ package org.geysermc.geyser.entity.type.living; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.Rotation; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -165,27 +163,27 @@ public class ArmorStandEntity extends LivingEntity { setFlag(EntityFlag.ADMIRING, (xd & 0x08) == 0x08); // Has no baseplate } - public void setHeadRotation(EntityMetadata entityMetadata) { + public void setHeadRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.MARK_VARIANT, EntityFlag.INTERESTED, EntityFlag.CHARGED, EntityFlag.POWERED, entityMetadata.getValue()); } - public void setBodyRotation(EntityMetadata entityMetadata) { + public void setBodyRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.VARIANT, EntityFlag.IN_LOVE, EntityFlag.CELEBRATING, EntityFlag.CELEBRATING_SPECIAL, entityMetadata.getValue()); } - public void setLeftArmRotation(EntityMetadata entityMetadata) { + public void setLeftArmRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.TRADE_TIER, EntityFlag.CHARGING, EntityFlag.CRITICAL, EntityFlag.DANCING, entityMetadata.getValue()); } - public void setRightArmRotation(EntityMetadata entityMetadata) { + public void setRightArmRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.MAX_TRADE_TIER, EntityFlag.ELDER, EntityFlag.EMOTING, EntityFlag.IDLING, entityMetadata.getValue()); } - public void setLeftLegRotation(EntityMetadata entityMetadata) { + public void setLeftLegRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.SKIN_ID, EntityFlag.IS_ILLAGER_CAPTAIN, EntityFlag.IS_IN_UI, EntityFlag.LINGERING, entityMetadata.getValue()); } - public void setRightLegRotation(EntityMetadata entityMetadata) { + public void setRightLegRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.HURT_DIRECTION, EntityFlag.IS_PREGNANT, EntityFlag.SHEARED, EntityFlag.STALKING, entityMetadata.getValue()); } @@ -200,13 +198,13 @@ public class ArmorStandEntity extends LivingEntity { * @param negativeZToggle the flag to set true if the Z value of rotation is negative * @param rotation the Java rotation value */ - private void onRotationUpdate(EntityData dataLeech, EntityFlag negativeXToggle, EntityFlag negativeYToggle, EntityFlag negativeZToggle, Rotation rotation) { + private void onRotationUpdate(EntityData dataLeech, EntityFlag negativeXToggle, EntityFlag negativeYToggle, EntityFlag negativeZToggle, Vector3f rotation) { // Indicate that rotation should be checked setFlag(EntityFlag.BRIBED, true); - int rotationX = MathUtils.wrapDegreesToInt(rotation.getPitch()); - int rotationY = MathUtils.wrapDegreesToInt(rotation.getYaw()); - int rotationZ = MathUtils.wrapDegreesToInt(rotation.getRoll()); + int rotationX = MathUtils.wrapDegreesToInt(rotation.getX()); + int rotationY = MathUtils.wrapDegreesToInt(rotation.getY()); + int rotationZ = MathUtils.wrapDegreesToInt(rotation.getZ()); // The top bit acts like binary and determines if each rotation goes above 100 // We don't do this for the negative values out of concerns of the number being too big int topBit = (Math.abs(rotationX) >= 100 ? 4 : 0) + (Math.abs(rotationY) >= 100 ? 2 : 0) + (Math.abs(rotationZ) >= 100 ? 1 : 0); diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java b/core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java index f3ccb0d2e..84838afc7 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.network.netty; import com.github.steveice10.packetlib.BuiltinFlags; +import com.github.steveice10.packetlib.codec.PacketCodecHelper; import com.github.steveice10.packetlib.packet.PacketProtocol; import com.github.steveice10.packetlib.tcp.*; import io.netty.bootstrap.Bootstrap; @@ -47,11 +48,13 @@ public final class LocalSession extends TcpSession { private final SocketAddress targetAddress; private final String clientIp; + private final PacketCodecHelper codecHelper; - public LocalSession(String host, int port, SocketAddress targetAddress, String clientIp, PacketProtocol protocol) { + public LocalSession(String host, int port, SocketAddress targetAddress, String clientIp, PacketProtocol protocol, PacketCodecHelper codecHelper) { super(host, port, protocol); this.targetAddress = targetAddress; this.clientIp = clientIp; + this.codecHelper = codecHelper; } @Override @@ -102,6 +105,11 @@ public final class LocalSession extends TcpSession { } } + @Override + public PacketCodecHelper getCodecHelper() { + return this.codecHelper; + } + // TODO duplicate code private void addHAProxySupport(ChannelPipeline pipeline) { InetSocketAddress clientAddress = getFlag(BuiltinFlags.CLIENT_PROXIED_ADDRESS); diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index f60af61b3..ff15dafc1 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -34,6 +34,7 @@ import com.github.steveice10.mc.auth.service.MojangAuthenticationService; import com.github.steveice10.mc.auth.service.MsaAuthenticationService; import com.github.steveice10.mc.protocol.MinecraftConstants; import com.github.steveice10.mc.protocol.MinecraftProtocol; +import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper; import com.github.steveice10.mc.protocol.data.ProtocolState; import com.github.steveice10.mc.protocol.data.UnexpectedEncryptionException; import com.github.steveice10.mc.protocol.data.game.MessageType; @@ -843,7 +844,8 @@ public class GeyserSession implements GeyserConnection, CommandSender { if (geyser.getBootstrap().getSocketAddress() != null) { // We're going to connect through the JVM and not through TCP downstream = new LocalSession(this.remoteAddress, this.remotePort, - geyser.getBootstrap().getSocketAddress(), upstream.getAddress().getAddress().getHostAddress(), this.protocol); + geyser.getBootstrap().getSocketAddress(), upstream.getAddress().getAddress().getHostAddress(), + this.protocol, this.downstream.getCodecHelper()); } else { downstream = new TcpClientSession(this.remoteAddress, this.remotePort, this.protocol); disableSrvResolving(); @@ -1737,4 +1739,8 @@ public class GeyserSession implements GeyserConnection, CommandSender { packet.setExtraData(-1); sendUpstreamPacket(packet); } + + public MinecraftCodecHelper getCodecHelper() { + return (MinecraftCodecHelper) this.downstream.getCodecHelper(); + } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java index 27bab75bb..a5c949c10 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java @@ -62,11 +62,11 @@ public class JavaLoginTranslator extends PacketTranslator dimensions = session.getDimensions(); dimensions.clear(); - JavaDimension.load(packet.getDimensionCodec(), dimensions); + JavaDimension.load(packet.getRegistry(), dimensions); Map chatTypes = session.getChatTypes(); chatTypes.clear(); - for (CompoundTag tag : JavaCodecEntry.iterateAsTag(packet.getDimensionCodec().get("minecraft:chat_type"))) { + for (CompoundTag tag : JavaCodecEntry.iterateAsTag(packet.getRegistry().get("minecraft:chat_type"))) { int id = ((IntTag) tag.get("id")).getValue(); CompoundTag element = tag.get("element"); CompoundTag chat = element.get("chat"); @@ -77,7 +77,7 @@ public class JavaLoginTranslator extends PacketTranslator> 4))]; try { - NetInput in = new StreamNetInput(new ByteArrayInputStream(packet.getChunkData())); + ByteBuf in = Unpooled.wrappedBuffer(packet.getChunkData()); for (int sectionY = 0; sectionY < chunkSize; sectionY++) { - ChunkSection javaSection = ChunkSection.read(in, biomeGlobalPalette); + ChunkSection javaSection = session.getCodecHelper().readChunkSection(in, biomeGlobalPalette); javaChunks[sectionY] = javaSection.getChunkData(); javaBiomes[sectionY] = javaSection.getBiomeData();