Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.