Create custom mob

Discussion in 'Spigot Plugin Development' started by PeteDoesNothing, Feb 14, 2018 at 9:18 PM.

  1. Hello,

    I'm trying to create a plugin that adds some new monsters.

    Sadly I'm stuck right at the beginning..

    I had a look at the Javadocs but still can't get my head around it.

    What I thought was the process:
    1. Create new Implementation of `org.bukkit.entity.monster`.
    2. override some methods and add custom behaviour there and stuff like filename of the texture
    3. Register that new monster somewhere
    4. Finish
    But now all entities seem to be interfaces. Where is the implemented logic?

    I hope someone can give me a starting point.

    Thanks in adance :)

    regards
     
  2. CraftZombie/CraftCreeper/etc. Internally, it's what the server uses.

    Not exactly qualified for this, but NMS is also a route, since those implementations are version-dependent, as well.
     
  3. Code (Text):
    public boolean onCommand(CommandSender sender, Command cmd, String label, String [] args){
            if(cmd.getLabel().equalsIgnoreCase("mob")){
                if(sender instanceof Player){
                   
                    LivingEntity mob = (LivingEntity)p.getWorld().spawnEntity(p.getLocation(), EntityType.ZOMBIE);
                    Zombie z = (Zombie)mob;
                   
                    z.setCustomName("§cZombie Custom");
                    z.setCustomNameVisible(true);
                    z.setBaby(false); // zombie is babye? = false
                    z.setHealth(50);
                   
                    sender.sendMessage("§6§lMOBS: §fMob custom spawned!");
                }
            }
     
  4. Very inflexible, this only creates 'custom mobs' in the sense that data you can set with the native Bukkit API is modified, which I'm not entirely sure is all that the OP wants. Also, you have no centralized structure of where you're getting the data from, so it'd be horrible to maintain in the future.

    Additionally, you used 'getLabel' from Command, which is not recommended - use cmd.getName, as this helps you put in aliases easier down the line.
     
  5. So the spigot API itself does not offer a way to add your own entities?

    I believe then 'extending' an already there entity would also be okay for start.

    Follow ups on that:

    How do I change the texture of my extended pig?

    Where do I change the behaviour if sunlight hits the entity?
     
  6. There's only so much the API can do; As of yet, there's no way to change the texture other than resource packs, and that's... for all pigs. Yikes.

    Probably something to do with how the entity ticks. I'm not familiar with custom mobs myself, but there's plenty of custom NMS mob tutorials out there.

    With all that being said, I'm no expert in NMS mobs, so take what I say with a grain of salt.

    The reason that the API is so limited is because it can only use what resources it's given, not create new ones (unless it's, for example, sending packets to change a player's skin using a URL or whatnot).
     
  7. Thanks already for the answers. Already cleared some misconceptions of mine.

    Now I'm wondering if something like this should consist of a client and a server side of the mod.

    I mean, the client needs to know for example where to look for textures and stuff, but the server also needs to know about the entity because he for example needs to add it correctly to my worldsave.

    Also eg. ZombieEntity is in `net.minecraft.client` and not the server package.

    Am I right with that assumption?
     
  8. I've not done client side modding, but I would assume so, yes.

    I've gotta be honest, though, I'm not entirely sure modding both client/server is so supported in Spigot - there are other APIs though... just from what I've seen, ends up with a pretty... dead server?

    The API encourages us to test our limits, though - do what we can with what we have, and a lot of it is impressive - look at Hypixel, I mean sheesh!

    But, yeah, I'm relatively sure that if you're creating a 'custom' entity meaning any changes in texturing that's not global, models, all that - you'll want both client/server mods.
     
  9. Basically that's how entities work:
    - in net.minecraft.server.version_number (nms) there are the vanilla entity classes with the logic and everything about how an entity interacts with the world (e.g. EntityZombie)
    - in org.bukkit.entity there are the entity interfaces used by the bukkit api, one for each vanilla entity (e.g. Zombie)
    - in org.bukkit.craftbukkit.version_number.entity there are the craft entites classes, which are wrappers of the vanilla entities that implement the interfaces used by the bukkit api (e.g. CraftZombie)

    So, if you want to create a custom entity with a custom behaviour you need to:
    1) Create a class that extends a nms entity class in which you override the methods you need in order to create your custom entity logic
    2) (Optional) Create a craft entity wrapper for your custom entity that implements an interface like the bukkit api does
    3) Register your entity using the id of a vanilla entity, so that the client renders that texture (you can't use ids that don't exists, so you can't assign a custom texture to your entity)

    How to practically do these steps is explained in some tutorials. If you can't find one or if they are outdated (probably) I can make a new one.

    PS: I took for granted that you want to create a plugin and not a mod. Otherwise some things about what I said will change, obviously.
     
    #9 Grimerlin, Feb 14, 2018 at 11:58 PM
    Last edited: Feb 15, 2018 at 12:04 AM
    • Informative Informative x 1
  10. Mainly the entity type id would change to a custom one that is registered in the client too.
     
  11. Okay, I think instead of asking for a solution, I should have described my problem in the first post.

    Problem:
    I have a private spigot server and I play with my son. He always fantasizes about new mobs added to the game. Because I know some Java I thought I can give it a try.

    As said, we play on a spigot server with some plugins installed, but nothing crazy. Clients are using Forge.

    While adding a new mob, I don't want to loose an existing one. Though customizing an already existing one with changing texture via texture pack and stuff wouldn't be viable for me (since the vanilla mob will be gone after that).

    For a better understanding, this is the rough idea for the first mob:
    A zombie-like creature with our own texture, that has the additional behaviour, instead of burning in direct sunlight, he will freeze and if hit with a pickaxe drops two stoneblocks. If that is too complicated, we could also transform the mob in two stone blocks if hit by direct sunlight.

    I don't really care if it will be a mod or a server plugin, since I have total control over the clients anyway.

    So I guess now to do this, I need to have a client side mod, that the minecraft client knows about the mob. And a server side plugin, that the server knows what to do with this weird entityId, he doesn't know about. Right?

    thanks already for the responses :)
     
  12. Minecraft Forge mods work so that they can be both client-side and server-side. You just put the mod.jar file in the server folder and in the client folder and voilà.
    How all this work and how to create a mod can be found in many tutorials, just google it.

    I experimented a bit creating a custom entity and model using minecraft forge long time ago and it wasn't very hard, just follow the steps on the tutorials.
    In your case it will be even easier because you will be extending the vanilla zombie so a lot of things will be the same, like the model and the rendering stuff, except that you will assign to it your texture.png file and slightly change the AI.

    Good luck!
     

Share This Page