[API] Meta Mobs - Epic Custom Mobs [V.0.2]

Discussion in 'Resources' started by Jogy34, May 4, 2014.

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

    Jogy34

    A while ago, I ran into the problem in one of my plugins where I wanted to add in new worlds with new dangers and new entities. I got fairly deep into custom entity creation in the normal NMS way but that ended up being fairly boring where I would just use the same shell for every entity but make it do different things. Instead I wanted to make it more exciting. I decided that I wanted to use entities like Lego's and construct scary, powerful, awesome monstrosities that players could battle or interact with. So I came up with Meta Mobs.

    Meta Mobs is a plugin that allows plugin developers to link into it to be able to do just this (of course you're welcome to just import all of the code into your own plugin... but it is a lot of code). To show you an example of what I'm talking about... I'll just leave this here:
    [​IMG]
    (That's a giant next to it for size comparison)

    So now on to how exactly you use this.

    To start off with, the most basic part of a MetaMob, are MetaMobPieces. The MetaMobPieces are used for shells of Follower Entities whose only job is to keep their relative position to the base entity. The most basic of these are retrieved from the MetaMobPieceEnum which contains most of the basic entities with invisible versions of them (used for spacing reasons). There are a few entities that need special parameters, these use MetaMobPieceConstructors. The pieces that use these currently are falling blocks and items however you can use these for any additional entities that you desire.

    The next step to creating your Meta Mob is to create a blueprint. A BluePrint takes in a three dimensional array of IMetaMobPiece's (Currently MetaMobPieceEnum and MetaMobPieceConstructor are allowed), the main mob Z, and main mob X in the array.

    The three dimensional array of IMetaMobPiece's is used to construct the actual mob. The array is built where every new first segment of the array is a new Y coordinate, every new second segment is a new Z coordinate, and every new third segment is a new X coordinate over. It is done this way for conceptual purposes. For instance:
    Code:java
    1.  
    2. IMetaMobPiece[][][] blueprintArray =
    3. {{{MetaMobPieceEnum.PIG, MetaMobPieceEnum.PIG, MetaMobPieceEnum.PIG},
    4. {MetaMobPieceEnum.PIG, MetaMobPieceEnum.PIG, MetaMobPieceEnum.PIG}}};
    5.  

    That would correspond to a MetaMob that is (initially) 2 in the Z direction, 3 in the X direction and 1 in the Y direction. All follower mobs will keep their relative angle with the main mob. If you want a portion or an entire section to be blank, null is a viable use for this.

    The main mob will always be on the bottom of the mob and then will correspond to the Z and X coordinates given.

    Additional parameters that you can send in are the width offset and height offset. These will adjust how far spread apart the entities are how far up to go when no entity is present below. If there is an entity below then the new entity will start riding it.

    So now that you've made your blueprint, you can start spawning your MetaMobs. a MetaMob takes in a BluePrint, a Location, and the amount of life that you want it to have. The BluePrint will be used to construct the MetaMob. The location will be where the main entity is spawned, and the life is how much life you want it to have. The life parameter is so that you can hit it anywhere and it will still take damage.

    If you want your MetaMob to be controlled by your own custom entity or a different entity than what you chose at the position for you main entity it is possible. In addition to all of the other things, you just have to send in your new entity's class, constructor parameter types, and constructor parameters.

    Now to put this all together for you:
    Code:java
    1.  
    2. //Creating the IMetaMobPiece array
    3. MetaMobPieceBlockConstructor goldBlock = new MetaMobPieceBlockConstructor(Material.GOLD_BLOCK, 0);
    4. MetaMobPieceItemConstructor goldIngot = new MetaMobPieceItemConstructor(Material.GOLD_INGOT);
    5. IMetaMobPiece[][] layer =
    6. {{goldBlock, goldIngot, goldBlock},
    7. {goldIngot, MetaMobPieceEnum.BLAZE, goldIngot},
    8. {goldBlock, goldIngot, goldBlock}};
    9. IMetaMobPiece[][][] tower = {layer, layer, layer, layer, layer, layer, layer, layer, layer};
    10.  
    11. //Creating the BluePrint
    12. BluePrint blazeTower = new BluePrint(tower, 1, 1, 0.8, 0.8);
    13.  
    14. //Spawning the MetaMob
    15. try
    16. {
    17. new MetaMob(blazeTower, player.getLocation(), 50.0, EntityCow.class, new Class<?>[] {World.class}, ((CraftWorld) player.getWorld()).getHandle());
    18. }
    19. catch(Exception e) {e.printStackTrace();}
    20.  
    21. The try/catch block is needed in case something fails in the MetaMob creation.
    22.  

    Result:
    [​IMG]

    One other thing that you can do now that you've got your MetaMob is you can add a health bar to it. This can easily be done with the simple call:
    Code:java
    1. metaMob.addHealthBar(y, z, x, name);

    The y, z, and x correspond to the relative coordinates around the main entity. The health bar is made of a wither so once it drops below half health you will get the wither shimmer effect. The name is what you want it to appear as on the boss bar. An example of this is in the creeper picture above.

    If you want your MetaMob to drop loot when it is killed you simply do the following:
    Code:java
    1.  
    2. //This will end up indirectly calling the dropDeathLoot() method of your main entity
    3. //so to customize what is actually dropped you have to override this method in your own custom entity
    4. metaMob.setDropMainDeathLoot(true);
    5.  


    I'm not explaining all of the logic behind the code as it would take way to long but I would be willing to explain specific parts of it if you ask in the comments.

    To use this either link into the plugin and put it as a dependency or take the code and transfer it into your own plugin but, again, I warn you that it is a lot of code.

    Here's the code: https://bitbucket.org/Jogy34/meta-mobs/src
    And here's the plugin: http://dev.bukkit.org/bukkit-plugins/meta-mobs/

    I would love to see anyone's creations with this.

    V.0.2 Changes:
    • Made the spawn reason for any Meta Mob 'CUSTOM'
    • Added the ability to make a Meta Mob drop their main entity's loot upon death
    My Other Things:
    Xern-Utilities
    Custom Entity tutorial

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
    Goblom, mrCookieSlime, Assist and 2 others like this.
  2. Offline

    BungeeTheCookie

    Jogy34
    You're scaring me with those pictures.
     
  3. Offline

    Jogy34

    **[Insert Evil Grin Here]**
     
    Windy Day and BungeeTheCookie like this.
  4. Offline

    BungeeTheCookie

    Jogy34 You see. I'd like to know everything. There is no use in coding a library and giving it to the public if you are not willing to explain everything or at least right some documentation. Please, onward!

    Jogy34
    Also, can you post ALL of your code for creating that massive crazy looking creeper thing?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  5. Offline

    Jogy34

    I think the biggest functionality thing that didn't explain was that you can add a healthbar, which was lazy of me as that would only have taken a few sentences to explain. I didn't want to explain all of the code behind it because it was already extremely long and would have taken at least 4 times that much room to explain all of the logic behind all of the code.

    And the code for the massive creeper can be found in the code already. It's in the main class. If you look at the plugin page you can see that under the command section there are a bunch of command for spawning 'test' mobs and the massive creeper is part of that.

    Here's the main class if you want to look through the code yourself though, It is slightly spread apart but the creation of the creeper blueprint is towards the top of the onEnable() method and spawning it in the onCommand() at line 210.
     
  6. Offline

    BungeeTheCookie

    Alrighty. Thank you very much! Alright, so new MetaMob() creates a new Entity, although it is not really an Entity but the MetaMob functions and has the attributes like the entity specified in the constructor? If so, can you use a custom entity class that extends a net.minecraft.server Entity or whatever, register that, and use that for the MetaMob?
     
  7. Offline

    Jogy34


    From above /\ /\ /\:
    I give the example of the MetaMob constructor with the normal EntityCow from NMS code but you can easily replace that with your own custom entity. There's also an example of this in the actual code with my Dalek prototype. The custom entity is the SkeletonDalek and I tried extending from MetaMob for the Dalek Meta Mob (MetaDalek) so everything corresponding to that is in there.
     
  8. Offline

    BungeeTheCookie

    Oh wow. I missed that. thank you!
     
  9. Offline

    BungeeTheCookie

    Im just gunna bump this so others can see
     
    ArthurMaker likes this.
  10. Offline

    Quaro

    Any video?
     
Thread Status:
Not open for further replies.

Share This Page