[1.7+] Making a custom MOB! [EASY]

Discussion in 'Resources' started by mrgreen33gamer, Oct 5, 2014.

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

    mrgreen33gamer

    Hello, I have seen a lot of posts and people trying to make their own custom mob WITHOUT trying to override the original mob. Well, this is your LUCKY DAY!

    ATTENTION: Read along in the post to get the best results!

    Let's thank Jogy34 for making most of this possible!
    Alrighty. Let's get started!

    First off, you are gonna want to create a simple class. This will be the Mother Class where we create our mob!

    Code:java
    1.  
    2. package this.is.your.package;
    3.  
    4. import net.minecraft.server.v1_7_R1.EntitySkeleton;
    5. import net.minecraft.server.v1_7_R1.World;
    6.  
    7. public class CustomSkeleton extends EntitySkeleton{
    8.  
    9. public CustomSkeleton(World world) {
    10. super(world);
    11.  
    12. }
    13. }
    14.  


    We will add more stuff to the class above ^^^ later.

    Alrighty! That's about the basic. Next you need to register the entity into the CraftWorld and into the server.

    Make a NEW class and call it: EntityRegister.

    Code:java
    1.  
    2. package com.mrgreen33gamer.test;
    3.  
    4. import java.lang.reflect.Field;
    5. import java.util.Map;
    6.  
    7. public class EntityRegister {
    8.  
    9.  
    10. protected static Field mapStringToClassField, mapClassToStringField, mapClassToIdField, mapStringToIdField;
    11.  
    12. static
    13. {
    14. try
    15. {
    16. mapStringToClassField = net.minecraft.server.v1_7_R1.EntityTypes.class.getDeclaredField("c");
    17. mapClassToStringField = net.minecraft.server.v1_7_R1.EntityTypes.class.getDeclaredField("d");
    18. //mapIdtoClassField = net.minecraft.server.v1_7_R1.EntityTypes.class.getDeclaredField("e");
    19. mapClassToIdField = net.minecraft.server.v1_7_R1.EntityTypes.class.getDeclaredField("f");
    20. mapStringToIdField = net.minecraft.server.v1_7_R1.EntityTypes.class.getDeclaredField("g");
    21.  
    22. mapStringToClassField.setAccessible(true);
    23. mapClassToStringField.setAccessible(true);
    24. //mapIdToClassField.setAccessible(true);
    25. mapClassToIdField.setAccessible(true);
    26. mapStringToIdField.setAccessible(true);
    27. }
    28. catch(Exception e) {e.printStackTrace();}
    29. }
    30.  
    31. @SuppressWarnings({ "rawtypes", "unchecked" })
    32. protected static void addCustomEntity(Class entityClass, String name, int id)
    33. {
    34. if (mapStringToClassField == null || mapStringToIdField == null || mapClassToStringField == null || mapClassToIdField == null)
    35. {
    36. return;
    37. }
    38. else
    39. {
    40. try
    41. {
    42. Map mapStringToClass = (Map) mapStringToClassField.get(null);
    43. Map mapStringToId = (Map) mapStringToIdField.get(null);
    44. Map mapClasstoString = (Map) mapClassToStringField.get(null);
    45. Map mapClassToId = (Map) mapClassToIdField.get(null);
    46.  
    47. mapStringToClass.put(name, entityClass);
    48. mapStringToId.put(name, Integer.valueOf(id));
    49. mapClasstoString.put(entityClass, name);
    50. mapClassToId.put(entityClass, Integer.valueOf(id));
    51.  
    52. mapStringToClassField.set(null, mapStringToClass);
    53. mapStringToIdField.set(null, mapStringToId);
    54. mapClassToStringField.set(null, mapClasstoString);
    55. mapClassToIdField.set(null, mapClassToId);
    56. }
    57. catch (Exception e)
    58. {
    59. e.printStackTrace();
    60. }
    61. }
    62. }
    63. }
    64.  


    Okay. Now that you have that class maken, we need to register our entity. Goto your main class, with the onEnable, and put this into the onEnable{} method:

    Code:java
    1.  
    2. EntityRegister.addCustomEntity(CustomSkeleton.class, "Custom Skeleton", 51);
    3. // ^ Custom Mob Class ^ Just a basic name ^ ID
    4. // THE ID OF THE MOB HAS TO MATCH THE REAL ID OF A MINECRAFT MOB.
    5. // IN this case. The ID for the skeleton is 51.
    6. //Here is a link to the enums:
    7. // [url]http://jd.bukkit.org/rb/doxygen/da/d7e/enumorg_1_1bukkit_1_1entity_1_1CreatureType.html[/url]
    8.  


    Alrighty. You have basically finished all that there needs to be for the mob! Next you want to SPAWN the custom mob into the world!

    This is a simple method that allows you to spawn your custom mob into the world:
    Code:java
    1.  
    2. public void spawnCustomSkeleton(Location loc){
    3. net.minecraft.server.v1_7_R1.World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
    4. CustomSkeleton customSkeleton = new CustomSkeleton(nmsWorld);
    5. customSkeleton.setPosition(loc.getX(), loc.getY(), loc.getZ());
    6. nmsWorld.addEntity(customSkeleton);
    7. }
    8.  


    Now. You can put this in a command form or event form. Here is a command form example:
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    3.  
    4. if(label.equalsIgnoreCase("SpawnMyMob")){
    5. if(sender instanceof Player){
    6. Player player = (Player)sender;
    7. spawnCustomSkeleton(player.getLocation());
    8. }else{
    9. sender.sendMessage("Only players can perform this action!");
    10. }
    11. }
    12. return false
    13. }
    14.  


    I WILL MAKE ANOTHER POST FOR GoalFinders and how to make your mob do custom stuff!

    There you go! Simple as that. I hope you guys enjoyed this!

    Most Credit goes to: Jogy34

    Also, check out my YouTube :D! Thanks!

    ~mrgreen33gamer | Leava like if this helped :3!
     
    ChipDev, shohouku and Skionz like this.
  2. Offline

    Skionz

    mrgreen33gamer Looks good! I have never actually made a custom mob so this will come in handy.
     
  3. Offline

    mrgreen33gamer

    Skionz Thanks for the post and the positive response :D! I hope this does help you. It helped me!
     
  4. Offline

    xTrollxDudex

    How does this have anything to do with NBT...?

    Also, why would you set the values again after putting into the map?
     
  5. Offline

    mrgreen33gamer

    xTrollxDudex Yeah I see your point on both. I was planning on adding GoalFinders and some other stuff that had to do with NBT. But I guess I didn't. Thanks for that! And in what part are you trying to tell me with the maps?
     
  6. Offline

    ChipDev

    Just use Citizens to make the world better :p
     
  7. Offline

    xTrollxDudex

    Code:
               mapStringToClass.put(name, entityClass);
               mapStringToId.put(name, Integer.valueOf(id));
               mapClasstoString.put(entityClass, name);
               mapClassToId.put(entityClass, Integer.valueOf(id));
     
               mapStringToClassField.set(null, mapStringToClass);
               mapStringToIdField.set(null, mapStringToId);
               mapClassToStringField.set(null, mapClasstoString);
               mapClassToIdField.set(null, mapClassToId);
    1/2 of this is redundant
     
  8. mrgreen33gamer I have no idea what makes you think that this stuff has anything todo with Named Binary Tags (besides saving them to a file).
     
  9. Offline

    d3v1n302418

    I'm pretty sure he meant NMS.
     
  10. Offline

    mrgreen33gamer

    d3v1n302418 Yeah. I am stupid

    ChipDev People don't want to use an external jar file because it's just another hassle to worry about and pretty much, this is my opinion, I think that most people like to keep their coding in 1 thing without extending it the file to another file.

    CaptainBern soz. I meant NMS.

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

    Ozeir

    Okay. Now that you have that class maken, we need to register our entity.
    maken has to be made :p Grammar nazi sorry.
    You're dutch right? XD
     
  12. Offline

    shohouku

    This is great... I would really want to know how to add GoalFinders...
     
  13. Offline

    mrgreen33gamer

    shohouku Ask me what kind of Mob you want. And I will give you the goalfinders.
     
  14. Offline

    shohouku

    I just figured it out, like about a day ago :p
    Thanks anyways! I'm loving this...
     
  15. Offline

    shohouku

    mrgreen33gamer

    Did the NMS max health method change?

    Because this doesn't work

    Code:java
    1. AttributeInstance attributes = customWolf.getAttributeInstance(GenericAttributes.maxHealth);
    2. attributes.setValue(20.0D);


    Edit: I solved it by setting the entity's max health.
     
Thread Status:
Not open for further replies.

Share This Page