• 欢迎加入MineBBS QQ讨论群:点击查看所有的官方讨论群
  • 我们将于近期对服务器进行迁移,服务可能中断至多2日。请各位安排好自己的访问计划,造成不便敬请谅解!
  • MineBBS入站考试已经上线!想要成为【正式会员】解锁更多功能吗?快来参与吧!【点我去看】

问题 编写坐骑插件改怎么让他飞行

luo_xue

【Lv:2】

正式会员
注册
2025/11/08
消息
53
金粒
3,125.72金粒
我想写一个坐骑插件,让坐骑可以载人飞行,试了好多办法都不行,请教一下有没有什么方法或者什么插件来辅助
游戏版本是1.12.2,paper核心
 
内容版权许可
作者保留一切权利,禁止转载
领取红包用户
北之 Wan_Nian 黎 渊 漫心
继承NMS实体,比如FlyPig extends EntityPig
重写public void a(float f, float f1, float f2)
[MD] ```java @Override public void a(float strafe, float vertical, float forward) { if (this.isVehicle() && this.passengers != null && !this.passengers.isEmpty()) { EntityLiving rider = (EntityLiving) this.passengers.get(0); Field bd = EntityLiving.class.getDeclaredField("bd");bd.setAccessible(true); boolean riderJumping = bd.getBoolean(rider); if(riderJumping) { this.motY = 1D; this.move(EnumMoveType.SELF, this.motX, this.motY, this.motZ); } } } ``` [/MD]

你也可以依赖ProtocolLib,监听PacketType.Play.Client.STEER_VEHICLE包,
packet.getBooleans().read(0)获取玩家是否跳跃
player.getVehicle().setVelocity(new Vector(0,1,0));
 
最后编辑:
继承NMS实体,比如FlyPig extends EntityPig
重写public void a(float f, float f1, float f2)
[MD] ```java @Override public void a(float strafe, float vertical, float forward) { if (this.isVehicle() && this.passengers != null && !this.passengers.isEmpty()) { EntityLiving rider = (EntityLiving) this.passengers.get(0); Field bd = EntityLiving.class.getDeclaredField("bd");bd.setAccessible(true); boolean riderJumping = bd.getBoolean(rider); if(riderJumping) { this.motY = 1D; this.move(EnumMoveType.SELF, this.motX, this.motY, this.motZ); } } } ``` [/MD]

你也可以依赖ProtocolLib,监听PacketType.Play.Client.STEER_VEHICLE包,
packet.getBooleans().read(0)获取玩家是否跳跃
player.getVehicle().setVelocity(new Vector(0,1,0));
使用后,坐骑虽然是飞行状态,但是只能很慢的滑动,在地面上也是很慢的滑动,走路都是直接没有了,也无法往高处飞,这是为什么
 
使用后,坐骑虽然是飞行状态,但是只能很慢的滑动,在地面上也是很慢的滑动,走路都是直接没有了,也无法往高处飞,这是为什么
[MD] ```java ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(Tianren.plugin, PacketType.Play.Client.STEER_VEHICLE) { @Override public void onPacketReceiving(PacketEvent event) { PacketContainer packet = event.getPacket(); float forward = packet.getFloat().read(1); float strafe = packet.getFloat().read(0); boolean isJumping = packet.getBooleans().read(0); double speed = 0.5D; double ascentSpeed = 0.5D; Player player = event.getPlayer(); Entity vehicle = player.getVehicle(); Vector direction = player.getEyeLocation().getDirection(); Vector moveVector = new Vector(0, 0, 0); if (forward != 0 || strafe != 0) { moveVector = direction.clone().multiply(Math.signum(forward) * speed); moveVector.add(new Vector(direction.getZ(), 0, -direction.getX()).normalize().multiply(Math.signum(strafe)* speed)); } moveVector.setY(vehicle.getVelocity().getY()*0.9); if(isJumping) moveVector.setY(ascentSpeed); vehicle.setVelocity(moveVector); } }); ``` [/MD]
 

在线管理成员

在线会员

  • 小小的子沐呀
  • 黎 渊
  • 小安鱼
  • doge777
后退
顶部 底部