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

    xGamingDudex

    Hi again, have looked a bit around and din't find any thing, except that I tried broadcasting the target of the zombie on every tick and found out that though the zombie din't go after the target the bat was still the target.
     
  2. Offline

    Jacek

    I'm just guessing really but I think there is a limit on how far a entity will attempt to move. It could be that the bat is so far away that the path finding can't find a way to get there in the maximum number of steps.
     
  3. Offline

    pasow

  4. Offline

    brandonHD

    How can I spawn one of the new mob and customize it so it won't move?
     
  5. Offline

    pasow

  6. Offline

    RingOfStorms

    If you're just doing pathfindergoals, and nothing else you should not use a custom entity class. If you can, avoid making one at all costs, as it can create many complications down the road. Instead you should simply use reflection and edit the normal mob after it has been spawned. By doing this, you won't overwrite the "vanilla" or spawn-egg mobs with your custom, and only the ones you want will be changed,
     
  7. Offline

    brandonHD

    ok! Could you give an example on how I would do this with an Ender Dragon?
     
  8. Offline

    pasow



    and how exactly do I use reflection???
    The way you described seems to be the simplest and most natural way to do it, but how exactly could this be achieved?
    Because I want an entity to move to a given location.
     
  9. Offline

    RingOfStorms

    LOL no I can't :3 - I can do it with any mob but that. For enderdragon you'll have to make a custom entity, as it does not use pathfinders, you'll have to rewrite the c() function. I'm looking into a way of applying pathfindergoals to the dragon, but haven't really done anything with it yet. I already did pigmen (They don't use pathfindergoals either, unless u do something to them), but it was way easier with them.
     
    Jacek likes this.
  10. Offline

    SgtPunishment

    Okay, I've read a couple of pages of this topic, and I have no idea what I'm doing LOL has anyone got an updated version of Jacek 's code from the first post? I'm trying to make my own custom zombie but apparently a lot of stuff has changed.

    EDIT: I have read every post in this thread now, and I'm lost at the whole process, mainly because I don't know what the new values are in 1.5.2, and the following code;

    Code:java
    1.  
    2. net.minecraft.server.v1_5_R3.World mcWorld = ((CraftWorld) world)
    3. .getHandle();
    4. net.minecraft.server.v1_5_R3.Entity mcEntity = (((CraftEntity) entity)
    5. .getHandle());
    6.  


    Doesn't work as CraftWorld and CraftEntity aren't working, and I can't seem to find them (Using Craftbukkit 1_5_R3)
     
  11. Offline

    pasow


    well, the easiest thing to do is go on here: https://github.com/Bukkit/mc-dev/tree/master/net/minecraft/server
    and look up the classes that you need (in your case it would be the EntityZombie class)
    Then you make your own class which you call whatever your new Zombie will be called and put "extends EntityZombie" behind it. Next you just copy the code from the EntityZombie class and paste it in your class. Now you need to adjust the parts of it that you want to change and your ready to go!
    (the main difficulty here is finding out which part does what and how it does it. :p)

    Also, the craftworld worked fine on my code. :/
     
  12. Offline

    SgtPunishment

    Okay, I've uploaded the class files I'm trying to work with... following this thread this is what I have so far...

    Main class file
    UberZombie class file (replacement)

    Now, the errors I'm having are in the main class file on lines 110 and 111 and on lines 107 as well 114 I am having deprecation issues.

    As per pasow 's suggestion, I have copied a chunk out of the original class file and pasted it into my own, with some amendments, e.g; I doubled the speed the zombie moves by and reduced it's health as a test... but I cannot compile until the errors (Lines 110/111) are resolved.

    Can anyone help me with those errors?
     
  13. Offline

    Jacek

  14. Offline

    pasow


    1.
    Everything that's called Creature is deprecated (outdated)
    Use Entity instead ;) (like EntityType() or SpawnEntity())

    2.
    In your UberZombie class I would leave out the whole pathfinder/target-goal setting, since you're not changing it anyways and you cant change it like that.

    3.
    I dont know why the CraftWorld isnt working for you. I'll try again to see how I did it and tell you if I find out anything.
     
  15. Offline

    Rprrr

    Could anyone help me?

    I'm trying to create a custom giant entity (faster, stronger, et cetera). However, there is no source code available for the 'EntityGiantZombie'. I've created my own entity giant zombie, and I'm fine with spawning it - the point is, I don't know how to speed it up. I've tried customizing the pathfindergoals for it, but that just doesn't work - because I can not find the source code for it @ GitHub / the internet, I don't really have an idea of what to do know.

    Perhaps Jacek knows what do?
     
  16. Offline

    SgtPunishment

    https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/EntityGiantZombie.java


    this.bI I believe is the speed


    I have done step one, all the deprecated errors have gone... but the CraftWorld / CraftEntity errors are still around, I have removed the pathfinding stuff because as you said, I can't change it like that (I read somewhere I need to cancel them (remove them) before defining new ones)

    I've updated the files in my gitHub

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
    pasow likes this.
  17. Offline

    Rprrr

  18. Offline

    SgtPunishment

    I managed to figure out the issue... but now I have no idea if my edited zombies are spawning instead of the default ones... anyway to tell? I have updated my github with the most recent source code
     
  19. Offline

    Ivan

    Dude I've had the same issue xD. I had zombies spawning with diamond armor all around the world, and I owned a factions PVP Server. Gf economy...
     
  20. Offline

    SgtPunishment

    Ivan I have decreased zombies health by 10, doubled their speed (I think) and attempted to prevent them from burning in the daytime, also tried changing the overworld skeletons to their wither cousins... With no luck...
     
  21. Offline

    Ivan

    Is this about the zombies spawning regularly? Or is this another question
     
  22. Offline

    SgtPunishment

    Using this tutorial I should of replaced all zombies with my edited version... But I have no idea how to tell if I have or not
     
  23. Offline

    RingOfStorms

    Learn some more Java basics first :3
     
  24. Offline

    SgtPunishment

    Not very helpful thank you
     
  25. Offline

    pasow

    SgtPunishment

    if their health would be half, you could kill them with 2 hits with a diamond sword i think.
    try it out :)
     
  26. Offline

    SgtPunishment

    I've tried it, still 3-4 hits with diamond sword, I've actually created a thread in the plugin development section, so I wouldn't spam this topic anymore.
     
  27. Offline

    WafflesYumyum

    Hm, whenever I try to spawn this Silverfish, any clients nearby crash! (NameHolder is extending EntitySilverfish)

    Here's my event:
    Code:
    @EventHandler
        public void onCreatureSpawn(CreatureSpawnEvent e){
            if (e.isCancelled()) return;
     
            Location location = e.getLocation();
            Entity entity = e.getEntity();
            EntityType creatureType = e.getEntityType();
            World world = location.getWorld();
     
            net.minecraft.server.v1_5_R3.World mcWorld = ((CraftWorld) world).getHandle();
            net.minecraft.server.v1_5_R3.Entity mcEntity = (((CraftEntity) entity).getHandle());
     
            if (creatureType == EntityType.SILVERFISH && mcEntity instanceof NameHolder == false){
                NameHolder nh = new NameHolder(mcWorld);
     
                nh.setPosition(location.getX(), location.getY(), location.getZ());
     
                mcWorld.removeEntity((net.minecraft.server.v1_5_R3.EntitySilverfish) mcEntity);
                mcWorld.addEntity(nh, SpawnReason.CUSTOM);
     
                return;
            }
        }
    And the NameHolder class is just default:
    Code:
    public class NameHolder extends EntitySilverfish{
     
        public NameHolder(World arg0) {
            super(arg0);
        }
    Any idea what's causing this to crash? The server itself is having no problem, just the clients.
     
  28. Offline

    Jacek

    @WafflesYumyumDid you get the entity ID wrong ? That's one thing i've done a few times that causes client crashing.
     
  29. Offline

    WafflesYumyum

    D'oh! I actually missed the entire section of code inside the onEnable() method. Thanks for putting me on the right path by mention that "entity ID" thing!
     
  30. Offline

    hawkfalcon

    Jacek

    How would I make mobs able to break blocks? :eek:
     
Thread Status:
Not open for further replies.

Share This Page