Make mobs stationary

Discussion in 'Plugin Development' started by glasseater, Jan 16, 2015.

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

    glasseater

    Hey bukkit,

    So, I am working on a plugin that involves mobs. However, I am having a problem making them stationary (so players can't push them) I have tried using remoteenitites, but it is out of date. Are there any others that I can use to use the NMS code? Thanks everyone for reading!

    - Glass
     
  2. Offline

    Dsi_Mario

    Give them slowness 10 or above.
     
  3. Offline

    glasseater

    @Dsi_Mario Yea, but its kinda buggy looking. With that you can still move it then it gets tp'd back. I was looking for something more along the lines of you can't move it at all.
     
  4. Offline

    Leo38638

  5. Offline

    glasseater

    @Leo38638 Man, that is kinda confusing. Is there away to do it without NMS? Other than what @Dsi_Mario said?
     
  6. Offline

    griffjack

    I would Use NMS.
     
  7. Offline

    Antybarrel

    I have used NMS before. I can't think of any way other than NMS to easly change the behavour of mobs.
     
    Last edited by a moderator: Jan 16, 2015
  8. Offline

    glasseater

    @Antybarrel Can you help me on the thread? That way if other people are stuck, they can use this ;)
     
  9. Offline

    Antybarrel

    @glasseater sure I'm free now if u still need help. How far you got?
     
  10. Offline

    glasseater

    @Antybarrel Well, not far :( I was about to resort to adding a potion effect but you can see the particles. Any ideas?
    Thanks!
     
  11. Offline

    Antybarrel

    @glasseater You still want to use NMS or do you wan't to scratch that and just go down the potion effect route?
     
  12. Offline

    glasseater

    @Antybarrel I mean, I think I would prefer NMS for better results
     
  13. Offline

    Antybarrel

  14. Offline

    glasseater

    @Antybarrel Ok, so I did that and I should change the Zombie to a villager?
     
  15. Offline

    ChipDev

    2 Great ways!

    Without NMS:
    Make it ride a WitherSkull
    NMS:
    Speed.
     
  16. Offline

    glasseater

  17. Offline

    Antybarrel

    @glasseater ^^^

    Yea you do, the first "Zombie" you change to villager quite simple the id 54 needs to be changed to the
    villager id which is 120
    Code:
    ZOMBIE("Zombie", 54, EntityType.ZOMBIE, EntityZombie.class, CustomEntityZombie.class);
    
    VILLAGER("Villager", 120, EntityType.VILLAGER, EntityVillager.class, CustomEntityVillager.class);
    
    After this you now need to make your 'CustomEntityVillager.class'
     
  18. Offline

    glasseater

    @Antybarrel Would I use the CustomEntityZombie class?
     
  19. Offline

    Antybarrel

    @glasseater No, unless you want to customise the zombie too. You can also delete the ZOMBIE line as well if you havn't done already. All you need to do is make a blank class name CustomEntityVillager.class.
     
  20. Offline

    glasseater

  21. Offline

    Antybarrel

    @glasseater Have you got your blank CustomEntityVillager.class open.

    Code:
    public class CustomEntityVillager extends EntityVillager {
    
        public CustomEntityVillager(World world) {
        super(world);
    
        try {
            Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
            bField.setAccessible(true);
            Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
            cField.setAccessible(true);
            bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
            bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
            cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
            cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
            } catch (Exception exc) {
            exc.printStackTrace();
            }
    
    
        }
    
    }
    
    Oh make sure you have
    import java.lang.reflect.Field;
    Imported



    EDIT: I forgot! Also you will need to register and unregister these mobs in your onEnable and onDisable

    Code:
    public void onEnable(){
       
             CustomEntityType.registerEntities();
           
        }
       
        public void onDisable(){
            CustomEntityType.unregisterEntities();
            // Very important make sure you unregister
        }
     
    Last edited by a moderator: Jan 16, 2015
  22. Offline

    glasseater

  23. Offline

    Antybarrel

    @glasseater Can I see the whole class?

    Make sure these are imported.
    Code:
    import java.lang.reflect.Field;
    import org.bukkit.craftbukkit.v1_7_R3.util.UnsafeList;
    import net.minecraft.server.v1_7_R3.EntityVillager;
    import net.minecraft.server.v1_7_R3.PathfinderGoalSelector;
    import net.minecraft.server.v1_7_R3.World;
    

    The imports can vary depending on what verison of craftbukkit you are using.
     
  24. Offline

    glasseater

    @Antybarrel
    Code:
    import java.lang.reflect.Field;
    
    import org.bukkit.craftbukkit.v1_7_R3.util.UnsafeList;
    import net.minecraft.server.v1_7_R3.EntityVillager;
    import net.minecraft.server.v1_7_R3.PathfinderGoalSelector;
    import net.minecraft.server.v1_7_R3.World;
    
    import org.bukkit.World;
    import org.bukkit.craftbukkit.v1_7_R1.util.UnsafeList;
    
    public class CustomEntityVillager {
    
    
    public CustomEntityVillager(World world) {
    super(world);
    
    try {
        Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
        bField.setAccessible(true);
        Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
        cField.setAccessible(true);
        bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
        bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
        cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
        cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
        } catch (Exception exc) {
        exc.printStackTrace();
        }
    
    
    }
    
    }
     
  25. Offline

    Antybarrel

    @glasseater You might be getting errors if you havn't Referenced the Craftbukkit also it looks like your using v1.7_R1 so you will have to change that verison on the imports.

    Try this:

    Code:
    import java.lang.reflect.Field;
    
    import org.bukkit.craftbukkit.v1_7_R1.util.UnsafeList;
    import net.minecraft.server.v1_7_R1.EntityVillager;
    import net.minecraft.server.v1_7_R1.PathfinderGoalSelector;
    import net.minecraft.server.v1_7_R1.World;
    
    
    
    public class CustomEntityVillager extends EntityVillager {
    
        public CustomEntityVillager(World world) {
        super(world);
       
        try {
            Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
            bField.setAccessible(true);
            Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
            cField.setAccessible(true);
            bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
            bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
            cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
            cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
            } catch (Exception exc) {
            exc.printStackTrace();
            }
       
    
        }
       
       
    
       
       
       
    }
     
  26. Offline

    glasseater

    @Antybarrel Ok, I changed the imports. What do you mean "Reference Craftbukkit"?
     
  27. Offline

    Antybarrel

  28. Offline

    glasseater

  29. Offline

    Antybarrel

    @glasseater Ok, if you right click your project, click properties, java build path.
    Then Click libraries and if you already have it there it should say something like craftbukkit-1.7 etc

    If not, You need to click add external jars then locate your craftbukkit.jar server that you are running.
     
  30. Offline

    glasseater

Thread Status:
Not open for further replies.

Share This Page