Jump to content

[1.8]Double Jump


maikyy

Recommended Posts

So when working on my mod I suddenly had the brilliant idea of adding a double jump. so after some work I finally got it in but there is one little problem, i want to reset my fall height as soon as you jump for the second time, now the problem comes in that i don't really know where to exactly call the 'player.falldistance'

 

to start off here is what i got right now.

 

PlayerHandler.class

http://pastebin.com/nPr9Lz5D

(Don't worry about the 'EntityPlayer player = (EntityPlayer) event.entity;' I already removed it)

 

KeyHandler.class

http://pastebin.com/RqXK7PwA

 

And I have these two lines in my main mod class under the init

MinecraftForge.EVENT_BUS.register(new PlayerHandler());
FMLCommonHandler.instance().bus().register(new KeyHandler());

 

And another quick note, right now when I jump the jumpheight is dependend on when I jump if that makes any sense.

so when I jump for the first time and Immediatly jump again I can jump 3 blocks high, but when I jump and wait a little I can't even jump 1 block high with my second jump. so there must be something i did horribly wrong :P

obviously needed to SET velocity and not ADD velocity :P

 

Edit:

Oh lol I just found out that I really did mess something up because my minecraft client was running in the background and as soon as another entity jumps my game crashes :P

I'm dutch so expect terrible grammar and mistakes :D

Link to comment
Share on other sites

Nononono

 

Just do player.onGround = true

 

whenever the player jump method is called or something and then they can jump again

 

So you mean where I have:

@SubscribeEvent
public void OnKeyInput(KeyInputEvent event)
{
	if(!FMLClientHandler.instance().isGUIOpen(GuiChat.class))
	{
		if(Minecraft.getMinecraft().gameSettings.keyBindJump.isPressed())
		{
			if(PlayerHandler.isJumping && !PlayerHandler.isDoubleJumping && PlayerHandler.canDoubleJump)
			{
				Minecraft.getMinecraft().thePlayer.setVelocity(0.0F, 0.5F, 0.0F);
				Minecraft.getMinecraft().thePlayer.fallDistance = 0.0F;
				PlayerHandler.isDoubleJumping = true;
			}
		}
	}
}

 

because if I check for anything to do with the player here It crashes as soon as I jump again. That is basicly how I started it out, at first I had something like this in here:

public static boolean isDoubleJumping;
EntityPlayer EntityPlayer;
EntityPlayer player = EntityPlayer;

if(player.onground) {
   isDoubleJumping = false;
}

@SubscribeEvent
public void OnKeyInput(KeyInputEvent event)
{
if(!FMLClientHandler.instance().isGUIOpen(GuiChat.class))
{
	if(Minecraft.getMinecraft().gameSettings.keyBindJump.isPressed())
	{
		if(!player.onground && !isDoubleJumping)
		{
			player.setVelocity(0.0F, 0.5F, 0.0F);
			player.fallDistance = 0.0F;
			isDoubleJumping = true;
		}
	}
}
}

 

But that just kept throwing errors at me so that's why I do it the other way now because that seemed to kind of work :P

I'm dutch so expect terrible grammar and mistakes :D

Link to comment
Share on other sites

Don't set onGround to true unless the player is on the ground.

 

Your trouble is caused because you are setting fall distance on the CLIENT, but the player's fall distance on the SERVER is what results in the player taking damage.

 

You need to send a packet telling the server that your player is trying to double-jump and let the server say, 'okay, s/he can do that, and now I'm resetting fallDistance'.

Link to comment
Share on other sites

Don't set onGround to true unless the player is on the ground.

 

Your trouble is caused because you are setting fall distance on the CLIENT, but the player's fall distance on the SERVER is what results in the player taking damage.

 

You need to send a packet telling the server that your player is trying to double-jump and let the server say, 'okay, s/he can do that, and now I'm resetting fallDistance'.

 

Thanks, that makes sense now you say that. well ,Time to go and learn how to deal with packets :P

I'm dutch so expect terrible grammar and mistakes :D

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.