I did a double jump code but it only works sometimes
Can someone tell me what I did wrong?
It works but not all the time.
private static HashMap<String, Integer> jumps = new HashMap<String, Integer>();
private static int keyvalue;
public static void jump(EntityPlayer p) {
int x = p.getPosition().getX();
int y = p.getPosition().getY();
int z = p.getPosition().getZ();
World world = p.getEntityWorld();
BlockPos pos = new BlockPos(x, y - 1, z);
if (world.getBlockState(pos).getBlock() instanceof BlockAir) {
if (jumps.get(p.getName()) == 1 && p.motionY < 0.07 ) {
p.setVelocity(0.0F, 1.0F, 0.0F);
System.out.println("aaaa: " + jumps.get(p.getName()));
jumps.put(p.getName(), jumps.get(p.getName()) + 1);
System.out.println("bbbb: " + jumps.get(p.getName()));
} else if(jumps.get(p.getName()) >= 2) {
}
}
if (!(world.getBlockState(pos).getBlock() instanceof BlockAir)) {
jumps.put(p.getName(), 0);
// System.out.println("cccc: " + jumps.get(p.getName()));
}
}
@SubscribeEvent
public static void getKeyJump(LivingJumpEvent e) {
if (e.getEntity() instanceof EntityPlayer) {
EntityPlayer p = (EntityPlayer) e.getEntity();
int key = Keyboard.getEventKey();
keyvalue = key;
jumps.put(p.getName(), 1);
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void a(PlayerTickEvent e) {
EntityPlayer p = (EntityPlayer) e.player;
if (Keyboard.isKeyDown(keyvalue)) {
jump(p);
}
}