GiantNuker Posted September 4, 2017 Posted September 4, 2017 Hi, I'm working on a mod to give players wings. This is my code to add velocity(have not added in any checks(aka is player wearing wings) to code yet.) @Override public IMessage onMessage(PacketWingStateChange message, MessageContext ctx) { // This is the player the packet was sent to the server from EntityPlayerMP serverPlayer = ctx.getServerHandler().player; // Execute the action on the main server thread by adding it as a scheduled task //WingsPacketHandler.INSTANCE.sendTo(new PacketWingStateChange(FlightState.NULL), serverPlayer); float yaw = serverPlayer.rotationYaw; float pitch = serverPlayer.rotationPitch; float f = 1.0F; double motionX = (double)(-MathHelper.sin(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI) * f); double motionZ = (double)(MathHelper.cos(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI) * f); double motionY = (double)(-MathHelper.sin((pitch) / 180.0F * (float)Math.PI) * f); System.out.println("pitch:" + pitch); System.out.println("yaw:" + yaw); System.out.println("motX:" + motionX + " motY:" + motionY + " motZ:" + motionZ); serverPlayer.getServerWorld().addScheduledTask(() -> { serverPlayer.addVelocity(motionX, motionY, motionZ); }); // No response packet return null; } Packets work - here's a log sample: Quote ... [09:37:35] [Netty Server IO #1/INFO]: [STDOUT]: pitch:27.900019 [09:37:35] [Netty Server IO #1/INFO]: [STDOUT]: yaw:239.40019 [09:37:35] [Netty Server IO #1/INFO]: [STDOUT]: motX:0.7606768012046814 motY:-0.46792641282081604 motZ:-0.4499063193798065 ... Player does not move at all. This code is supposed to be used when player is 'flapping' thier wings, it should add velocity in the direction the're looking. Thanks for the help! Note: all the comments are from the docs(copy and paste ) Quote
Draco18s Posted September 4, 2017 Posted September 4, 2017 You're reaching across threads here. See the warning: http://mcforge.readthedocs.io/en/latest/networking/simpleimpl/ Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
GiantNuker Posted September 4, 2017 Author Posted September 4, 2017 2 hours ago, Draco18s said: You're reaching across threads here. See the warning: http://mcforge.readthedocs.io/en/latest/networking/simpleimpl/ But 2 hours ago, GiantNuker said: serverPlayer.getServerWorld().addScheduledTask(() -> { serverPlayer.addVelocity(motionX, motionY, motionZ); }); I'm not changing anything on the Packet thread. It was reading the information right though. Quote
GiantNuker Posted September 4, 2017 Author Posted September 4, 2017 2 minutes ago, diesieben07 said: You are still reading yaw and pitch on the network thread. Players do not have motion on the server. The client just sends a new position every tick. so - set velocity on the client? Quote
GiantNuker Posted September 4, 2017 Author Posted September 4, 2017 6 minutes ago, diesieben07 said: Yes, player movement is completely client-side, the server only validates that the player is not doing something stupid. Thanks!!!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.