Anyone found a decent way to change mob speeds?

Discussion in 'Plugin Development' started by dxwarlock, Jun 20, 2012.

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

    dxwarlock

    I've poured over the threads I can find (there is quite a few) of how to actually change a mobs speed, while still allowing it to move as it normal would and attack, just faster.

    But trying to piece together the snippets of code from them, and mesh them into a working class seems beyond what I currently understand of some of the events and calls they are using to do it.

    Does anyone have any examples of how to achieve this?
    What I'm attempting to do is speed up zombies at night. which sounds simple...

    But cant seem to get the part I need for once I find its night, and it a zombie....to actually speed him up :)
     
  2. Offline

    Njol

  3. Offline

    dxwarlock

    hmm perhaps 'bb' is the wrong field?

    I got:
    Code:java
    1.  
    2. (snippet)
    3. static {
    4. entitySpeed.setAccessible(true);
    5. }
    6. @EventHandler
    7. public void SpeedMobs(CreatureSpawnEvent evt)
    8. {
    9. try {
    10. entitySpeed.set(((CraftEntity) evt.getEntity()).getHandle(), 0.6f);
    11. e.printStackTrace();
    12. }
    13. }
    14. }
    15.  

    and it doesn't complain of any errors..

    but the static field I initialize does:
    (snippet)
    Code:java
    1.  
    2. public class Lis implements Listener
    3. {
    4. private static Field entitySpeed = net.minecraft.server.Entity.class.getField("bb");
    5.  


    with: Unhandled exception, no such field.
    I have both bukkit and craftbukkit in the jars
    and I doing it wrong?

    (to save from editing and loosing the code formatting)
    even tried
    net.minecraft.server.EntityLiving.class.getField("bb");

    this is the whole class, remaking it to clean up my other code to do things out of it and make a starting base to work with:
    Code:java
    1.  
    2. package me.dx.seasons.plugin;
    3.  
    4. import java.lang.reflect.Field;
    5.  
    6. import org.bukkit.craftbukkit.entity.CraftEntity;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.CreatureSpawnEvent;
    10.  
    11. public class test implements Listener
    12. {
    13. private static Field entitySpeed = net.minecraft.server.EntityLiving.class.getField("bb");
    14. static {
    15. entitySpeed.setAccessible(true);
    16. }
    17. Main plugin;
    18. public test(Main plugin)
    19. {
    20. this.plugin = plugin;
    21. }
    22. @EventHandler
    23. public void SpeedMobs(CreatureSpawnEvent evt)
    24. {
    25. try {
    26. entitySpeed.set(((CraftEntity) evt.getEntity()).getHandle(), 0.6f);
    27. e.printStackTrace();
    28. }
    29. }
    30. }
    31.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  4. At least EntityLiving should have the 'bb' field (just looked at the repo), not sure about the entity class.
     
  5. Offline

    dxwarlock

    yea I've tried EntityLiving and Entity (both from net.minecraft.server, not bukkit) and both give me that error :\

    I see it on the repo also in EntityLiving:
    protected float bb = 0.7F;

    and Entity.class has;
    public Entity[] bb() {
    return null;
    }

    so maybe Im calling it wrong? not sure.
     
  6. It's nothing to do with Entity classes whatsoever, it's basically telling you that you got an exception type that needs to be caught somewhere.
    Most reflection methods throw non-RuntimeExceptions on failure, so you have to catch them, which you can't do when directly assigning it to a declared field.

    Put it in a method (or the static { }) initializer and surround it with try/catch, and you're good.
     
  7. Offline

    dxwarlock

    ahh thank you :)
    thought I needed to initialize it outside the method..

    so like so?
    Code:java
    1.  
    2. package me.dx.seasons.plugin;
    3.  
    4. import java.lang.reflect.Field;
    5.  
    6. import org.bukkit.craftbukkit.entity.CraftEntity;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.CreatureSpawnEvent;
    10.  
    11. public class test implements Listener
    12. {
    13. Main plugin;
    14. public test(Main plugin)
    15. {
    16. this.plugin = plugin;
    17. }
    18. @EventHandler
    19. public void SpeedMobs(CreatureSpawnEvent evt)
    20. {
    21. try {
    22. Field entitySpeed = null;
    23. try {
    24. entitySpeed = net.minecraft.server.EntityLiving.class.getField("bb");
    25. e.printStackTrace();
    26. }
    27. entitySpeed.setAccessible(true);
    28. entitySpeed.set(((CraftEntity) evt.getEntity()).getHandle(), 0.6f);
    29. e.printStackTrace();
    30. }
    31. }
    32. }
    33.  


    Think this is best left alone, its too far beyond my knowledge without harassing people for more help :)
    Tried all the ways above that I could think of, and getting errors on spawn..
    even tried making my own SpeedZombie class, that extends EntityMonster..but get null exception, as Im not sure how to add my custom class to the server entity list

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page