Jump to content

How to get player position on an axis in 1.17.1


llynxfyre

Recommended Posts

Hello, I know I've been quite active here lately and I promise I'll get out of your hair once i can work out this final thing.

Essentially I'm looking for a way to get the player's Position on a specific axis and use its value in an if statement. I've experimented with classes vec3 and vec3i as the method getY() seemed promising, but i didn't know how to use it with the player and I had issues with the method being non-static. Any help would be appreciated. 

Link to comment
Share on other sites

	@SubscribeEvent
	public void whenGameMusicPlays(final PlaySoundEvent event) {	
		if (event.getName().equals("music.game") && ) { 
			ResourceLocation loc = new ResourceLocation(CaveMusic.MODID + ":" + "music.overworld.underground");
			SimpleSoundInstance MyPSR = new SimpleSoundInstance(
				loc, SoundSource.MUSIC, 1.0f, 1.0f, false, 0, SoundInstance.Attenuation.NONE, 0.0D, 0.0D, 0.0D, true);
			event.setResultSound(MyPSR);

essentially i tried a few combinations of vec3i, vec3, Player and getY() after the &&. I was essentially throwing spaghetti at the wall because i didn't know what i needed to use in 1.17.1. I want to be able to test if player's position on the Y axis is less than a certain value. I'm really sorry if this is a stupid question.

Link to comment
Share on other sites

6 hours ago, Luis_ST said:

you can get a Player in client Events via Minecraft.getInstance().player 

Note: this only works in client Events

doing minecraft.getinstance().player.position().y shows a warning of Resource leak: '<unassigned Closeable value>' is not closed at this location. What does getinstance.player actually do?

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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