Posted September 20, 201510 yr Hi there, I want to create some Chat Commands for the Player to control his movement, e.g. /move -> player goes 1 step into viewing direction or /turnLeft -> player turns to 90° to the left. I have created a Actor.class, containing the move, turnLeft etc. methods. To perform the commands i used the EntityPlayer object given by the sender, using the command. This EntityPlayer object is called actor. To update the players position i used the method EntityPlayer.setPostionAndUpdate(int x, int y, int z); The problem is, that the player has to move into different direction depending on his viewingDirection. And here comes the trick because I don't know how to get the viewingDirection. Does anybody has an advice how I can access it? Hope this was clear enough to state out the problem I am facing. Edit: I've found out that we should use the Minecraft.getMinecraft().getRenderViewEntity()- method to access the viewingDirection from players, this method returns a entity-object. But I still don't know how to work with it. Can anybody help me?
September 21, 201510 yr Author I have now managed to create the /move command, the player knows walks 5 blocks towards north if the player is facing in that direction. Here is my Actor.class with the move()- Method: public class Actor { EntityPlayer actor; BlockPos actorPosition; public Actor(ICommandSender sender) { actor = (EntityPlayer) sender.getCommandSenderEntity(); } public void vor() { actorPosition = actor.getPosition(); // Yaw is direction left to right int yaw = (int) actor.rotationYaw; // Pitch is direction top to bottom int pitch = (int) actor.rotationPitch; // -224 to -135 == north if (yaw > -224 && yaw < -135) { actor.addChatComponentMessage(new ChatComponentTranslation("Facing North!")); // actor.setPositionAndRotation(actorPosition.getX(), // actorPosition.getY(), actorPosition.getZ() - 10, yaw, 0); actor.setPositionAndUpdate(actorPosition.getX(), actorPosition.getY(), actorPosition.getZ() - 5); } actor.addChatComponentMessage(new ChatComponentTranslation("pitch = " + pitch + " | yaw = " + yaw)); } public String getName() { return this.actor.getDisplayNameString(); } } Now I want to create the /turnLeft command, meaning if the player looks north, he should look towards west after the command. I figured out that the method EntityPlayer.setPositionAndRotation() should be the key, but when I run it, it does not update the player location. Can I somehow force the player to update his position?
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.