Changing an Entities Speed

Discussion in 'Plugin Development' started by sablednah, May 13, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    sablednah

    I'm trying to get some entities to move faster and slower.

    I have a plugin that creates different variations of entities. I already have health, damage and various skills working fine. What I can't get working well is altering speed.

    I've tried applying speed potions - it plays the visual effect but doesn't effect movement.

    My recent attempt was to multiply the vector. This worked perfectly - however I have to run this every 2-3 ticks as the new pathfinder AI constant reworks the vectors.

    As you can guess this doesn't scale well. More than a few dozen entities being tracked and the server just locks up.

    So - am I missing a trick that will make this easier? Or am I going to have to delve into net.minecraft.server code? And if so how do I go about getting to the speed?
     
  2. Offline

    sablednah

  3. Offline

    Njol

    Alternatively you could use reflection to change every newly spawned mob's speed:
    Code:
    private static Field entitySpeed = net.minecraft.server.Entity.class.getField("bb");
    static {
    entitySpeed.setAccessible(true);
    }
     
    onSpawn:
    entitySpeed.set(((CraftEntity) event.getEntity()).getHandle(), 0.4f);
    Written from my head thus it might contain errors, e.g. you might have to change Entity.class to EntityLiving.class.
     
  4. does this method still apply for current CB?
     
  5. Offline

    macguy8

    xtremetom
    You'd have to get the v1_5_R2 or something like that in there also
     
  6. I have tried :

    Code:
                      try {
                          Field entitySpeed = null;
                          try {
                              entitySpeed = net.minecraft.server.v1_5_R2.Entity.class.getField("bb");
                          } catch (NoSuchFieldException | SecurityException ev) {
                              ev.printStackTrace();
                          }
                          entitySpeed.setAccessible(true);
                          entitySpeed.set(((CraftEntity) e.getEntity()).getHandle(), 1.6f);
                      } catch (IllegalArgumentException | IllegalAccessException ev) {
                          ev.printStackTrace();
                      }
    but returns "bb" doesnt exist.
    And printing outh the getFields() confirms this.

    EntityZombie has a bb field but doesnt seem to change the speed.
     
  7. Offline

    ZeusAllMighty11

  8. I need to step speed up more gradually than that
     
  9. Offline

    Rprrr

  10. bw spits out:

    java.lang.NoSuchFieldException: bw
     
Thread Status:
Not open for further replies.

Share This Page