本帖最后由 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的文本编辑器刚写完代码会自动把代码弄乱+各种阴间颜色,有解决的办法吗)
在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的文本编辑器刚写完代码会自动把代码弄乱+各种阴间颜色,有解决的办法吗)
已经搞定了
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){}
有什么更好的方法吗,感觉这样做不太好?
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 发表于 2022-11-1 13:41
已经搞定了
try {
Class _class = ClientPacketListener.class;
有了
level.sendPacketToServer()
你其实可以截图的
问一下1.19.2Forge注册packet的后面那三个参数是什么 没看懂官方文档 我不知怎么实例化后面那几个参数
ECHOLEE 发表于 2022-12-30 14:32
问一下1.19.2Forge注册packet的后面那三个参数是什么 没看懂官方文档 我不知怎么实例化后面那几个参数 ...
没事了摸到源码