Tutorial - How to Customize the Behaviour of a Mob or Entity

Discussion in 'Resources' started by Jacek, Jan 13, 2012.

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

    CookCreeperz

    Can you help me with the zombiee CorrieKay?
     
  2. Offline

    Jacek

    It hasn't

    Usually only when they change stuff to do with entities. the long names like goalSelector will never change since they are set by CraftBukkit and there is no reason to change them really. The onTick() function for entities always seems to be one of the ones with an underscore in it too so it's pretty easy to work out.
     
    CorrieKay likes this.
  3. Offline

    CookCreeperz

    Jacek, Could you help me wiht the zombies!?
     
  4. Offline

    p000ison

    heyho, i never worked before with reflection, but it seems to be pretty cool :p

    im only not sure if its possible to override private methods. If its not direct possible I would need to override an other public method, but to override this, I would need to override also other methods, because they are also not public or protected..

    k and my second question is if its possible to override fields. :p

    (^ This guy (p000ison) is a noob in reflection :p)
     
  5. Offline

    Jacek

    p000ison You can override a private method but you can't increase it's visibility so it has to stay private. You would be able to call the private method from the super class using reflection which might be helpful if you just want to add something.

    As for fields, I think if the class has a field with the same name, type and visibility as the parent it will take priority since that is the actual object. You would not need to do that though since you can just use the fields from the class you extended :s
     
  6. Offline

    Bradley Hilton

    What would be the best way to force a mob (say zombie) to move to a certain point and lose their goal or target?
     
  7. Offline

    Jacek

    You should never need to do that, I would try writing my own AI instead of trying to counter the default behaviour with Bukkit.
     
  8. Offline

    Bradley Hilton

    Hmm okay...
     
  9. Offline

    Derthmonuter

    I'm trying to write a plugin to make iron golems that are always aggressive towards players. Normally I was able to do this using damage(0, player); but recent changes in iron golem behavior have made them forgive the player after about three seconds, so this doesn't work anymore. I think that creating my own custom iron golem class is the only way I can get the result I need.

    My problem is detailed more here: http://forums.bukkit.org/threads/forcing-iron-golems-to-attack-players.102599/
    The iron golem class I think I need is here: https://github.com/Sleaker/mc-dev/blob/master/net/minecraft/server/EntityIronGolem.java

    What I was wondering, is this the proper way to go about this? Is this possible? And while I'm at it, does anyone have some experience regarding getting this type of behavior out of iron golems/what methods/fields I need to use? Thank you!
     
  10. Offline

    Bradley Hilton

    Jacek Quick question, I've tried to switch over to maven for automatically building my plugin but I get the message "package net.minecraft.server does not exist" when I try to build it. Any suggestions?
     
  11. Offline

    Jacek

    You need CraftBukkit instead of just Bukkit as your dependency. It also needs to have <scope>compile</scope>
     
  12. Offline

    Bradley Hilton

    So this?

    Code:
      <dependencies>
        <dependency>
          <groupId>org.bukkit</groupId>
          <artifactId>craftbukkit</artifactId>
          <version>1.3.2-R0.1</version>
          <scope>compile</scope>
        </dependency>
      </dependencies>
    
     
  13. Offline

    Jacek

    Yup.
     
  14. Offline

    NemesisMate

    Jacek, I have been looking your BloodMoon code and it's very helpful but I would like to ask you how can I make a pathfinder to make a mob go through a coordinate after it moves. So every time it moves to attack or doing anything it comes back to the marked place.

    I think it must be something like this to add the pathfinder once done but I have no idea about how to make it, I can't understand how pathfinders are coded:
    Code:
    PathfinderGoalMoveThroughMarkedPoint(this, speed, X, Z))
    (Sorry about my english... I'm not english and it's dificult sometimes to explain in that language)
     
  15. Offline

    Jacek

    NemesisMate No idea ... You would have to store the location when the mob targeted the player then tell it to move back there, probably easier using Bukkit events tbh.
     
  16. Offline

    NemesisMate


    I could try but I think I need pathfinders for what I want, I have to save the "origin" location, that I know but I don't know how to make the mob go to that location with a "PathfinderGoalMoveThroughLocation(this, location)".

    I think it must be similar to PathfinderGoalMoveThroughVillage() from EntityIronGolem but I can't find its source to take a look to its code, do you know where can I find it?
    ( I searched in: https://github.com/Bukkit/CraftBukkit/tree/master/src/main/java/net/minecraft/server and some other places; there are some pathfinders's code but not this one)

    Thanks for your help
     
  17. Jacek I've had great success with this custom mob class, and it works great.
    BUT, when i try to override a EntityMonster function inside my Zombie class, it doesn't seem to work. :mad:

    So what i'm trying to do:
    Make mobs spawn in daylight no matter light level.

    Inside the EntityMonster i find this:
    Code:
       
    protected boolean o() {
            int i = MathHelper.floor(this.locX);
            int j = MathHelper.floor(this.boundingBox.b);
            int k = MathHelper.floor(this.locZ);
     
            if (this.world.b(EnumSkyBlock.SKY, i, j, k) > this.random.nextInt(32)) {
                return false;
            } else {
                int l = this.world.getLightLevel(i, j, k);
     
                if (this.world.I()) {
                    int i1 = this.world.k;
     
                    this.world.k = 10;
                    l = this.world.getLightLevel(i, j, k);
                    this.world.k = i1;
                }
     
                return l <= this.random.nextInt(8);
            }
        }
     
        public boolean canSpawn() {
            return this.o() && super.canSpawn();
        }
    
    This basically say that when the light level is below 8, it won't spawn.

    But when i copy this code into my zombie class, and place an @Override infront and try and change it, it don't affect the game.
     
  18. Offline

    Jacek

    mollekake The problem is that you are calling super.canSpawn() as well so it will also be performing the check from EntityMonster, just remove that and it should more or less work as expected :)
     
  19. Jacek Thanks for the advice :)
    Although, it did not help :(
    This is what i got inside my custome mob class:
    Code:
        @Override
        protected boolean o() {
            int i = MathHelper.floor(this.locX);
            int j = MathHelper.floor(this.boundingBox.b);
            int k = MathHelper.floor(this.locZ);
     
            if (this.world.b(EnumSkyBlock.SKY, i, j, k) > this.random.nextInt(32)) {
                return true;  //Changed this from false to true
            } else {
                int l = this.world.getLightLevel(i, j, k);
     
                if (this.world.I()) {
                    int i1 = this.world.k;
     
                    this.world.k = 10;
                    l = this.world.getLightLevel(i, j, k);
                    this.world.k = i1;
                }
     
                return l <= this.random.nextInt(15);  //changed this from 8 to 15
            }
        }
    with the changes i made, it should return true no matter what, also for the sake of it, i just placed only "return true;" inside the function, but that didn't help either :(
     
  20. Offline

    Jacek

    Code:
        public boolean canSpawn() {
            return this.o() && super.canSpawn();
        }
    This needs to be just

    Code:
        public boolean canSpawn() {
            return this.o();
        }
    otherwise you still apply the spawning restrictions of the super class.
     
  21. Still don't work :(
    i just don't get why it won't :'(

    Does it got anything to do with the o() is a protected boolean? tried to make it public but don't make a difference

    out of ideas Jacek ?
     
  22. anyone know if i got to invoke the class even though it's not a mob class?
    I'm altering the EntityMonster class, and just testing some stuff, but it doesn't seem to affect the game very much.
     
  23. Offline

    NemesisMate

    @Jacek Here you say that is better using Bukkit events. I used some events to do other things but I can't find the move event. Maybe it was deleted from old versions (I don't know, is the first version I use) but I have no way to make a mob going to a specified location. I can make it teleport with this.setPosition(X,Y,Z), but I would like to make the mob move instead of teleporting.
    No idea about wich function could I use?
     
  24. Offline

    Jacek

    There is a move() method isn't there ? If not there is for the NMS entity so you could always try that ?
     
  25. Offline

    NemesisMate

    @Jacek yes, there is a move method... but that move method (move(double, double, double)) makes my mob disappear :S. I used the method like move(X,Y,Z), and move(X,Z,Y), but in both, the mob disapears. I have to use it in another way?
     
  26. Offline

    Jacek

    It might be that it takes the distance to move instead of the actual coordinates to move to, you might be making them move off the map :p I'm just guessing here.
     
  27. Offline

    NemesisMate

    Ok, Jacek, it taked the distance to move instead of the actual coordinates ( :) my fault) but that function "moves" the mob to that location (like teleporting it, so easier using setPosition ), what I really want is that the mob goes walking/running to that coordinates. I have been looking everywhere and I only find ways to teleport it but not to make the mob walk/run to the X,Y,Z that I want.
     
  28. Offline

    Jacek

    Ah okay, well maybe going back to pathfinders is the best way then. Or look how they move the mob and try to do that ? It's something like entity.getNavigation().move() ? Basically I have no idea :(
     
  29. Offline

    Clem

    Would it be possible to control a customized NPC without having to constantly update the class? I would like to have an AI that I/It can control as needs be (not pre-determined)

    -Thanks!
     
Thread Status:
Not open for further replies.

Share This Page