Skip to content

Commit

Permalink
Clean up jump implementation and remove left click to jump
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 3, 2013
1 parent 075897c commit 04c4fdd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 45 deletions.
43 changes: 13 additions & 30 deletions src/main/java/net/citizensnpcs/trait/Controllable.java
Expand Up @@ -2,8 +2,6 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

import net.citizensnpcs.Settings.Setting;
Expand Down Expand Up @@ -241,7 +239,6 @@ private void jump() {

@Override
public void leftClick(PlayerInteractEvent event) {
jump();
}

@Override
Expand Down Expand Up @@ -283,23 +280,24 @@ private void updateSpeed(EntityLiving handle, float speedMod) {
newSpeed = 0.35D;
}

boolean shouldJump = false;
try {
if (JUMP_FIELD.getBoolean(handle.passenger)) {
if (handle.onGround && jumpTicks == 0) {
JUMP_METHOD.invoke(handle, (Object[]) null);
jumpTicks = 10;
}
} else {
jumpTicks = 0;
}
jumpTicks = Math.max(0, jumpTicks - 1);
if (JUMP_FIELD != null)
shouldJump = JUMP_FIELD.getBoolean(handle.passenger);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
if (shouldJump) {
if (handle.onGround && jumpTicks == 0) {
jump();
jumpTicks = 10;
}
} else {
jumpTicks = 0;
}
jumpTicks = Math.max(0, jumpTicks - 1);

if (newSpeed > oldSpeed && this.speed < 0.35D) {
this.speed = Math.min(0.35D, (this.speed + ((0.35D - this.speed) / 35.0D)));
Expand All @@ -325,22 +323,7 @@ public static interface MovementController {

private static final Map<EntityType, Class<? extends MovementController>> controllerTypes = Maps
.newEnumMap(EntityType.class);

private static Field JUMP_FIELD;
private static Method JUMP_METHOD = null;

static {
JUMP_FIELD = NMS.getField(EntityLiving.class, "bd");
JUMP_FIELD.setAccessible(true);
try {
JUMP_METHOD = EntityLiving.class.getDeclaredMethod("ba", (Class<?>[]) null);
JUMP_METHOD.setAccessible(true);
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
private static final Field JUMP_FIELD = NMS.getField(EntityLiving.class, "bd");

static {
controllerTypes.put(EntityType.BAT, AirController.class);
Expand Down
15 changes: 0 additions & 15 deletions src/main/resources/maps.yml

This file was deleted.

0 comments on commit 04c4fdd

Please sign in to comment.