Skip to content

Commit

Permalink
Fix REL_ENTITY_MOVE_LOOK not handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 17, 2023
1 parent e1df6bd commit 2292851
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,10 @@ public List<PacketContainer> buildSpawnPackets(Player player, DisplayParameters
var yaw = player.getYaw();

if (disguiseType == EntityType.PHANTOM)
pitch = (-player.getPitch() / 360f) * 256f;
pitch = -player.getPitch();

if (disguiseType == EntityType.ENDER_DRAGON)
{
var finalYaw = ((player.getYaw() + 180f) / 360f) * 256f;
yaw = (byte)finalYaw;
}
yaw = 180 + yaw;

//生成实体
var packetAdd = new ClientboundAddEntityPacket(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.comphenix.protocol.ProtocolLibrary;
import xiamomc.morph.MorphPluginObject;
import xiamomc.morph.backends.server.renderer.network.listeners.EquipmentPacketListener;
import xiamomc.morph.backends.server.renderer.network.listeners.MetaPacketListener;
import xiamomc.morph.backends.server.renderer.network.listeners.PlayerLookPacketListener;
import xiamomc.morph.backends.server.renderer.network.listeners.SpawnPacketHandler;
import xiamomc.morph.backends.server.renderer.network.listeners.*;
import xiamomc.pluginbase.Annotations.Initializer;

public class ProtocolHandler extends MorphPluginObject
{
private final SpawnPacketHandler morphPacketListener = new SpawnPacketHandler();
private final MetaPacketListener metaPacketListener = new MetaPacketListener();
private final EquipmentPacketListener equipmentPacketListener = new EquipmentPacketListener();
private final PlayerLookPacketListener playerLookPacketListener = new PlayerLookPacketListener();

public SpawnPacketHandler getPacketListener()
{
Expand All @@ -25,10 +25,10 @@ private void load()
var protocolMgr = ProtocolLibrary.getProtocolManager();

protocolMgr.addPacketListener(morphPacketListener);
protocolMgr.addPacketListener(new MetaPacketListener());
protocolMgr.addPacketListener(new EquipmentPacketListener());
protocolMgr.addPacketListener(new PlayerLookPacketListener());
protocolMgr.addPacketListener(new TestPacketListener());
protocolMgr.addPacketListener(metaPacketListener);
protocolMgr.addPacketListener(equipmentPacketListener);
protocolMgr.addPacketListener(playerLookPacketListener);
//protocolMgr.addPacketListener(new TestPacketListener());
}

private boolean disposed;
Expand All @@ -40,6 +40,9 @@ public void dispose()
var protocolMgr = ProtocolLibrary.getProtocolManager();

protocolMgr.removePacketListener(morphPacketListener);
protocolMgr.removePacketListener(metaPacketListener);
protocolMgr.removePacketListener(equipmentPacketListener);
protocolMgr.removePacketListener(playerLookPacketListener);
}
catch (Throwable t)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ public void onPacketSending(PacketEvent event)
{
var type = event.getPacketType();

if (type == PacketType.Play.Server.ENTITY_LOOK
|| type == PacketType.Play.Server.ENTITY_HEAD_ROTATION
|| type == PacketType.Play.Server.REL_ENTITY_MOVE
|| type == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK
|| type == PacketType.Play.Server.NAMED_SOUND_EFFECT
if (type == PacketType.Play.Server.NAMED_SOUND_EFFECT
|| type == PacketType.Play.Server.ENTITY_EFFECT
|| type == PacketType.Play.Server.BLOCK_CHANGE
|| type == PacketType.Play.Server.UPDATE_TIME)
{
return;
}

if (event.isCancelled())
return;

logger.info("SEND! type is '%s' handle is '%s'".formatted(event.getPacketType().name(), event.getPacket().getHandle()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public class EquipmentPacketListener extends ProtocolListener
@Resolved(shouldSolveImmediately = true)
private RenderRegistry registry;

@Override
public String getIdentifier()
{
return "equip_listener";
}

@Override
public void onPacketSending(PacketEvent event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class MetaPacketListener extends ProtocolListener
@Resolved(shouldSolveImmediately = true)
private RenderRegistry registry;

@Override
public String getIdentifier()
{
return "meta_listener";
}

@Override
public void onPacketSending(PacketEvent event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,29 @@

public class PlayerLookPacketListener extends ProtocolListener
{
@Override
public String getIdentifier()
{
return "look_move_listener";
}

@Override
public void onPacketSending(PacketEvent event)
{
var packetType = event.getPacketType();

var packet = event.getPacket();
//event.setCancelled(true);

//不要处理来自我们自己的包
if (packet.getMeta(PacketFactory.MORPH_PACKET_METAKEY).isPresent())
{
return;
}

if (packetType == PacketType.Play.Server.ENTITY_LOOK || packetType == PacketType.Play.Server.REL_ENTITY_MOVE)
if (packetType == PacketType.Play.Server.ENTITY_LOOK
|| packetType == PacketType.Play.Server.REL_ENTITY_MOVE
|| packetType == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK)
{
//PacketPlayOutEntity$PacketPlayOutEntityLook
var cast = (ClientboundMoveEntityPacket)packet.getHandle();
Expand Down Expand Up @@ -65,8 +76,6 @@ private void onTeleport(ClientboundTeleportEntityPacket packet, PacketEvent even
var yaw = packet.getyRot();
var pitch = packet.getxRot();

logger.info("Y " + yaw + " :: P"+ pitch );

var playerYaw = isDragon ? (sourcePlayer.getYaw() + 180f) : sourcePlayer.getYaw();
var finalYaw = (playerYaw / 360f) * 256f;
yaw = (byte)finalYaw;
Expand Down Expand Up @@ -94,8 +103,6 @@ private void onHeadRotation(ClientboundRotateHeadPacket packet, PacketEvent even

var headYaw = packet.getYHeadRot();

logger.info("HEADYAW " + headYaw);

if (watcher.getEntityType() == EntityType.ENDER_DRAGON)
{
var finalYaw = ((sourcePlayer.getYaw() + 180f) / 360f) * 256f;
Expand Down Expand Up @@ -137,8 +144,6 @@ private void onLookPacket(ClientboundMoveEntityPacket packet, PacketEvent event)

ClientboundMoveEntityPacket newPacket;

logger.info("FY " + finalYaw + " FP " + finalPitch);

if (event.getPacketType() == PacketType.Play.Server.ENTITY_LOOK)
{
newPacket = new ClientboundMoveEntityPacket.Rot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public abstract class ProtocolListener extends MorphPluginObject implements Pack
@Resolved(shouldSolveImmediately = true)
private PacketQueue packetQueue;

public abstract String getIdentifier();

protected PacketQueue getQueue()
{
return packetQueue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public class SpawnPacketHandler extends ProtocolListener
@Resolved(shouldSolveImmediately = true)
private RenderRegistry registry;

@Override
public String getIdentifier()
{
return "spawn_listener";
}

public SpawnPacketHandler()
{
registry.onRegister(this, ep ->
Expand Down

0 comments on commit 2292851

Please sign in to comment.