xm94732568960
本帖最后由 xm94732568960 于 2022-11-1 12:08 编辑

在ClientTickEvent中怎么向服务端发包?不知道怎么获取到connection
Minecraft mc = Minecraft.getInstance();
Player player = mc.player;
(ServerPlayer player).connection.send(ServerboundInteractPacket.createAttackPacket(mc.crosshairPickEntity, true));
//这样写会崩游戏
mc.getConnection().send(ServerboundInteractPacket.createAttackPacket(mc.crosshairPickEntity, true));
//这样写也会崩游戏,客户端不能向自己发包(可恶啊,mcbbs的文本编辑器刚写完代码会自动把代码弄乱+各种阴间颜色,有解决的办法吗)

xm94732568960
已经搞定了
try {
           Class _class = ClientPacketListener.class;
           Field field = _class.getDeclaredField("connection");
           field.setAccessible(true);
           Connection connection = (Connection) field.get(mc.getConnection());
           connection.send(ServerboundInteractPacket.createAttackPacket(mc.crosshairPickEntity, true));
}catch (Exception e){}
有什么更好的方法吗,感觉这样做不太好?

xm94732568960
xm94732568960 发表于 2022-11-1 13:41
已经搞定了
try {
           Class _class = ClientPacketListener.class;

有了
level.sendPacketToServer()

teddyxlandlee
你其实可以截图的

ECHOLEE
问一下1.19.2Forge注册packet的后面那三个参数是什么 没看懂官方文档 我不知怎么实例化后面那几个参数

第一页 上一页 下一页 最后一页