Jump to content

Recommended Posts

Posted

Hey world of forge!

 

Me and a friend are doing a collaboration mod, and we need a double jump function to either work when the user presses space, or presses a different key, I know how to program in java 90%, but this is bugging me! I have the class that I want to use, and I know that it reads the key when I press it, but I don't know how to make the player double-jump without it sending the player extremely far up in the air, or not doing anything at all!

 

 

package megateam.megamanxrpg;

 

import java.util.EnumSet;

import java.util.Timer;

import java.util.TimerTask;

 

import net.minecraft.client.multiplayer.PlayerControllerMP;

import net.minecraft.client.settings.KeyBinding;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.src.ModLoader;

 

import org.lwjgl.input.Keyboard;

 

import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;

import cpw.mods.fml.common.TickType;

 

public class MyKeyHandler extends KeyHandler {

static KeyBinding myBinding = new KeyBinding("MyBind", Keyboard.KEY_B);

 

public int jumps = 0;

 

public MyKeyHandler() {

super(new KeyBinding[]{myBinding}, new boolean[]{false});

}

 

@Override

public String getLabel() {

return "mykeybindings";

}

 

@Override

public void keyDown(EnumSet<TickType> types, KeyBinding kb,

boolean tickEnd, boolean isRepeat) {

 

 

 

}

 

@Override

public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {

 

}

 

@Override

public EnumSet<TickType> ticks() {

return EnumSet.of(TickType.CLIENT);

 

}

}

 

 

All I need to know is how to change the player data to make the player jump twice. Thanks!

Posted

what if you make it so when the space bar is pressed the second time, the player stops and then jumps. that should work

 

But how do I stop the player in mid air?  I think that might work, but the player has to be on a block to be able to jump, so then how do I do that?

 

I've tried using player.posY = player.posY + 1, but that removes all velocity from the player, and if I use changePositionAndUpdate function, the player keeps their velocity, but it flings the player up too high.

Posted

In the past i've done things like this.

I did it in a player tick handler though, as at the time i couldn't get the tick handlers to work.

You can do something like this:


import java.util.EnumSet;

import org.lwjgl.input.Keyboard;

import net.minecraft.entity.player.EntityPlayer;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class MyPlayerHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
	playerTick((EntityPlayer)tickData[0]);
}

private boolean hasJumped = false;
private void playerTick(EntityPlayer player)
{

	if(Keyboard.isKeyDown(Keyboard.KEY_SPACE) &&
			(player.isJumping || player.isAirBorne) &&
			player.motionY < 0.07 && !hasJumped)  //Waaaaaay more checks than necessary
	{
		//checks for armour/abilities...
		player.addVelocity(0, 0.1, 0);
		hasJumped = true;
	}
	if(!player.isAirBorne)
		hasJumped = false;
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{

}

@Override
public EnumSet<TickType> ticks()
{
	return EnumSet.of(TickType.PLAYER);
}

@Override
public String getLabel()
{
	return "MyPlayerHandler";
}	

}

 

Register that in the common and client proxys using

TickRegistry.registerTickHandler(new MyPlayerHandler(), /*Side.SERVER in common proxy and Side.CLIENT in client proxy*/);

 

One thing to remember when you're working with speeds in minecraft is that the speed is m/tick which means they tend to be fairly small (normally <0.1) Also, tapping into vanilla key bindings (at least how i was doing it) caused the original ones to break, guessing that's why you used B, so this works if you want to use space

 

not tested in 1.5, but worked in 1.4.7

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.