NMS How to override default Minecraft mobs

Discussion in 'Resources' started by TeeePeee, Jan 6, 2014.

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

    dajako

    Could you release the actual project file? I think it may help me slightly.
     
  2. Offline

    TeeePeee

    iiHeroo
    Glad to hear you've got it working :)
    dajako
    What project file? Simply copy the code from the original post into your own classes. The easiest way to test this is to make a brand new plugin as you normally would, add these files (and follow the instructions to register an entity) and run the server with the plugin.
     
  3. Offline

    iiHeroo



    So I'm trying to do the movement speed of the zombie, and if I put like 5.0D it seems like a player with speed walk at 50.0D, and when I put the regular speed that I found, 0.699999988079071D and it seemed to be going faster than even the average speed of the zombie by far.
     
  4. Offline

    TeeePeee

    iiHeroo
    As you can see here, the normal movement speed of a zombie is much lower than 0.699..., it's 0.230000... Also keep in mind that you can modify the speed of an entity by changing the modifier in the Pathfinder (such as this one) by changing the 1.0D modifier value to a different number.
     
  5. Offline

    iiHeroo


    oh, I was looking at the wrong link, thanks!
     
  6. Offline

    marwzoor

    TeeePeee

    You've had the time to look at the spider class yet? :) I really don't understand why it is acting so weird :O
     
  7. Offline

    MiniDigger

    TeeePeee Is there a why to override FallingBlockEntity. Your code seems to do nothing to them. It actually works for the Zombie. Here is my code http://pastebin.com/kPWvrrXs. Even the constructor don't get called....
     
  8. Offline

    TeeePeee

    So sorry, completely missed your post! I haven't look at it, sorry :(

    MiniDigger
    I'm not sure but I'll try to find out if I have the time. Until then, try spawning in a falling block directly using
    net.minecraft.server....Entity sand = new CustomEntityFallingSand(CraftWorld.getHandle());
    sand.setLocation(...);
    CraftWorld.getHandle().addEntity(sand);
     
  9. Offline

    MiniDigger

    TeeePeee that kindo worked but I get an NPE -.-
    Code:
    [00:36:02 INFO]: MiniDigger issued server command: /dev drei 25 1[/S]
    [S][00:36:02 INFO]: yep[/S]
    [S][00:36:02 INFO]: true[/S]
    [S][00:36:02 INFO]: ===========================[/S]
    [S][00:36:02 INFO]: modY 0.0[/S]
    [S][00:36:02 INFO]: modY 0.03999999910593033[/S]
    [S][00:36:02 ERROR]: Encountered an unexpected exception[/S]
    [S]net.minecraft.server.v1_7_R1.ReportedException: Ticking entity[/S]
    [S]    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:631) ~[craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) ~[craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:535) ~[craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:447) [craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]Caused by: java.lang.NullPointerException[/S]
    [S]    at net.minecraft.server.v1_7_R1.EntityFallingBlock.h(EntityFallingBlock.java:64) ~[craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    at eu.zonegames.api.entities.FloatingBlock.h(FloatingBlock.java:20) ~[?:?][/S]
    [S]    at net.minecraft.server.v1_7_R1.World.entityJoinedWorld(World.java:1331) ~[craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    at net.minecraft.server.v1_7_R1.World.playerJoinedWorld(World.java:1312) ~[craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    at net.minecraft.server.v1_7_R1.World.tickEntities(World.java:1200) ~[craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    at net.minecraft.server.v1_7_R1.WorldServer.tickEntities(WorldServer.java:480) ~[craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:627) ~[craftbukkit-1.7.2.jar:git-Bukkit-1.6.4-R2.0-9-g68d0e57-b2930jnks][/S]
    [S]    ... 4 more[/S]
    [S][00:36:02 ERROR]: This crash report has been saved to: C:\Users\Martin\git\zoneapi1\ZoneAPI\dist\.\crash-reports\crash-2014-03-11_00.36.02-server.txt
    [/S]
    Code:java
    1. package eu.zonegames.api.entities;
    Code:java
    1.  
    2.  
    3. [S]import net.minecraft.server.v1_7_R1.EntityFallingBlock;[/S]
    4. [S]import net.minecraft.server.v1_7_R1.World;[/S]
    5.  
    6. [S]public class FloatingBlock extends EntityFallingBlock {[/S]
    7.  
    8. [S]public FloatingBlock(World world) {[/S]
    9.  
    10. [S]super(world);[/S]
    11. [S]System.out.println("yep");[/S]
    12. [S]}[/S]
    13.  
    14. [S]@Override[/S]
    15. [S]public void h() {[/S]
    16. [S]System.out.println("===========================");[/S]
    17. [S]System.out.println("modY " + this.motY);[/S]
    18. [S]this.motY += 0.03999999910593033D;[/S]
    19. [S]System.out.println("modY " + this.motY);[/S]
    20. [S]super.h();[/S]
    21. [S]System.out.println("modY " + this.motY);[/S]
    22. [S]System.out.println("===========================");[/S]
    23. [S]}[/S]
    24.  
    25. [S]}[/S]

    Do I need to set some variables of EntityFallingBlock or why do I get an NPE?[/CODE][/S][/CODE]

    Actually fixed it myself by adding this.id = new BlockFalling(); to the constructor. No everything seems to work.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 25, 2016
  10. Offline

    ColaCraft

    (I made a thread for this question with no avail, so here goes...)

    How would I detect if the custom entity is walking into a block, or if a block is in the way?

    I have most of the code set up for what I want to do, besides finding the block itself.

    I want to zombie to destroy the block in front of him(/her?).

    Any ideas would be great... thanks.
     
  11. Offline

    Garris0n

    Look at EntityZombie and figure out what PathfinderGoalBreakDoor does.
     
  12. Offline

    ColaCraft

    I was thinking about doing that.. didn't know if I was going to have to create a new path finding goal or what.

    Thanks mate!
     
  13. Offline

    Omletowy

    My console result a lot of errors :c

    So, this is my error log:
    Code:
    [23:10:05 WARN]: java.lang.NoSuchMethodException: pl.themc.lom.entities.EntityMi
    nion.<init>(net.minecraft.server.v1_7_R1.World)
    [23:10:05 WARN]:        at java.lang.Class.getConstructor0(Unknown Source)
    [23:10:05 WARN]:        at java.lang.Class.getConstructor(Unknown Source)
    [23:10:05 WARN]:        at net.minecraft.server.v1_7_R1.SpawnerCreature.spawnEnt
    ities(SpawnerCreature.java:174)
    [23:10:05 WARN]:        at net.minecraft.server.v1_7_R1.WorldServer.doTick(World
    Server.java:188)
    [23:10:05 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.u(Minecr
    aftServer.java:657)
    [23:10:05 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.u(Dedica
    tedServer.java:273)
    [23:10:05 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.t(Minecr
    aftServer.java:560)
    [23:10:05 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.run(Mine
    craftServer.java:467)
    [23:10:05 WARN]:        at net.minecraft.server.v1_7_R1.ThreadServerApplication.
    run(SourceFile:617)
    It is repeat showing when I join the game by player when I leave the game error log stop repeating.

    Sorry for my bad english :/
     
  14. Offline

    TeeePeee

    Omletowy
    You didn't make a constructor in your EntityMinion class. Frankly, I'm surprised it even compiled...

    Code:java
    1. public EntityMinion(net.minecraft.server.v1_7_R1.World world) {
    2. super(world);
    3. // Your code here
    4. }
     
  15. Offline

    Omletowy

    TeeePeee
    You kidding me?
    Code:java
    1. package pl.themc.lom.entities;
    2.  
    3. import java.lang.reflect.Field;
    4.  
    5. import net.minecraft.server.v1_7_R1.EntityHuman;
    6. import net.minecraft.server.v1_7_R1.EntitySkeleton;
    7. import net.minecraft.server.v1_7_R1.EntityZombie;
    8. import net.minecraft.server.v1_7_R1.GenericAttributes;
    9. import net.minecraft.server.v1_7_R1.ItemStack;
    10. import net.minecraft.server.v1_7_R1.PathfinderGoalFloat;
    11. import net.minecraft.server.v1_7_R1.PathfinderGoalHurtByTarget;
    12. import net.minecraft.server.v1_7_R1.PathfinderGoalLookAtPlayer;
    13. import net.minecraft.server.v1_7_R1.PathfinderGoalMeleeAttack;
    14. import net.minecraft.server.v1_7_R1.PathfinderGoalMoveThroughVillage;
    15. import net.minecraft.server.v1_7_R1.PathfinderGoalMoveTowardsRestriction;
    16. import net.minecraft.server.v1_7_R1.PathfinderGoalNearestAttackableTarget;
    17. import net.minecraft.server.v1_7_R1.PathfinderGoalRandomLookaround;
    18. import net.minecraft.server.v1_7_R1.PathfinderGoalRandomStroll;
    19. import net.minecraft.server.v1_7_R1.PathfinderGoalSelector;
    20. import net.minecraft.server.v1_7_R1.World;
    21.  
    22. import org.bukkit.Color;
    23. import org.bukkit.Material;
    24. import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack;
    25. import org.bukkit.craftbukkit.v1_7_R1.util.UnsafeList;
    26. import org.bukkit.inventory.meta.LeatherArmorMeta;
    27. import org.bukkit.metadata.FixedMetadataValue;
    28.  
    29. import pl.themc.lom.Main;
    30. import pl.themc.lom.goals.PathFinderTower;
    31.  
    32. public class EntityMinion extends EntityZombie
    33. {
    34. public boolean go = false;
    35. private String team;
    36. private MinionType type;
    37. private String direction;
    38.  
    39. public EntityMinion(World world, String direction)
    40. {
    41. super(world);
    42. try
    43. {
    44. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    45. bField.setAccessible(true);
    46. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    47. cField.setAccessible(true);
    48. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    49. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    50. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    51. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    52. } catch (Exception exc) {
    53. exc.printStackTrace();
    54. }
    55.  
    56. this.direction = direction;
    57. this.getBukkitEntity().setMetadata("Minion", new FixedMetadataValue(Main.instance, true));
    58.  
    59. this.goalSelector.a(0, new PathfinderGoalFloat(this));
    60. this.goalSelector.a(1, new PathFinderTower(this, 0.7f));
    61. this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
    62. this.goalSelector.a(4, new PathfinderGoalMeleeAttack(this, EntitySkeleton.class, 1.0D, true));
    63. this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
    64. this.goalSelector.a(6, new PathfinderGoalMoveThroughVillage(this, 1.0D, false));
    65. this.goalSelector.a(7, new PathfinderGoalRandomStroll(this, 1.0D));
    66. this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
    67. this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
    68. this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
    69. this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
    70. this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntitySkeleton.class, 0, false));
    71. }
    72.  
    73. @Override
    74. protected void aD()
    75. {
    76. super.aD();
    77. this.getAttributeInstance(GenericAttributes.e).setValue(3.0D); // Original 2.0D
    78. this.getAttributeInstance(GenericAttributes.a).setValue(45.0D); // Original 20.0D
    79. }
    80.  
    81. public boolean shouldGo()
    82. {
    83. return go;
    84. }
    85.  
    86. public void setMinionType(MinionType type)
    87. {
    88. this.type = type;
    89. setEq(0, type.itemInHand);
    90. setBaby(type.isBaby);
    91. }
    92.  
    93. public MinionType getType()
    94. {
    95. return type;
    96. }
    97.  
    98. public String getDirection()
    99. {
    100. return direction;
    101. }
    102.  
    103. public void setTeam(String team)
    104. {
    105. this.team = team;
    106. Color color = null;
    107. if (team.equals("red")) color = Color.RED;
    108. if (team.equals("blue")) color = Color.BLUE;
    109. setEq(4, setItemColor(new org.bukkit.inventory.ItemStack(Material.LEATHER_HELMET), color));
    110. setEq(3, setItemColor(new org.bukkit.inventory.ItemStack(Material.LEATHER_CHESTPLATE), color));
    111. setEq(2, setItemColor(new org.bukkit.inventory.ItemStack(Material.LEATHER_LEGGINGS), color));
    112. setEq(1, setItemColor(new org.bukkit.inventory.ItemStack(Material.LEATHER_BOOTS), color));
    113. }
    114.  
    115. public String getTeam()
    116. {
    117. return team;
    118. }
    119.  
    120. private org.bukkit.inventory.ItemStack setItemColor(org.bukkit.inventory.ItemStack item, Color color)
    121. {
    122. LeatherArmorMeta meta = ((LeatherArmorMeta)item.getItemMeta());
    123. meta.setColor(color);
    124. item.setItemMeta(meta);
    125. return item;
    126. }
    127.  
    128. private void setEq(int slot, ItemStack item){
    129. setEquipment(slot, item);
    130. }
    131.  
    132. private void setEq(int slot, org.bukkit.inventory.ItemStack item){
    133. ItemStack cis = CraftItemStack.asNMSCopy(item);
    134. ItemStack itemStack = cis;
    135. setEquipment(slot, itemStack);
    136. }
    137.  
    138. public enum MinionType {
    139. tank(false, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.IRON_SWORD))),
    140. warrior(true, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.STONE_AXE))),
    141. archer(true, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.BOW)));
    142.  
    143. boolean isBaby;
    144. ItemStack itemInHand;
    145.  
    146. MinionType(boolean isBaby, ItemStack itemInHand)
    147. {
    148. this.isBaby = isBaby;
    149. this.itemInHand = itemInHand;
    150. }
    151. }
    152. }


    Edit
    Okay, I'm sorry I didn't know that I must put this when I have edited constructor..
     
  16. Offline

    MTN

    (double post from jaceks thread)
    If I understand this correctly:
    If I register CustomZombie (extends EntityZombie) it will automatically spawn everytime instead of regular zombies.... ?
    Can I just spawn one of these zombies without interferring with other plugins that might do the same?
    I want the default zombies and manually spawn CustomZombie, how can I do that?
     
  17. Offline

    TeeePeee

    MTN
    I'll be honest; I haven't really looked into what exactly the registerEntities method does - I just used Jaceks code and made it 1.7 ready. I believe, however, if you remove everything in CustomEntityTypes#registerEntities after a(...); it should prevent them from spawning naturally.

    Your registerEntities method would look like
    <syntax>public static void registerEntities() {
    a(...);
    }</syntax>

    Then you can just spawn them in by creating them like normal classes. CustomZombie z = new CustomZombie(((CraftWorld)world).getHandle()); Don't forget to set its location and use ((CraftWorld)world).getHandle().addEntity(z); to spawn it.
     
  18. Offline

    MTN


    Tested that and it does "naturally" spawn. Maybe not in biomes via natural spawning, but it definitly spawned my custom entity by using a spawn egg of the entity type.
     
  19. Offline

    Garris0n

  20. Offline

    MTN

  21. Offline

    Garris0n

    I believe you have to register 'd' and 'f', the rest are optional. 'e' will make it spawn instead of the mob you register it with, so if you register it with the Zombie's id it will spawn instead of zombies.
     
  22. Offline

    MTN

    I tried it with just f, works perfectly and I tried it: it is unlimeted, so I can create as much zombies as I want. The key of the map is the class and it just has to point to the right id, e.g. 91 for a sheep and it works!

    Thanks!
     
  23. Offline

    Garris0n

    Note that I'm not exactly sure what 'd' does, so you're better off registering it than discovering it did something important later.
     
  24. Offline

    TeeePeee

    Garris0n
    From what I can tell, it appears to be how Minecraft obtains the name of Mob Eggs (see here and here). Without registering the right name in 'd', the mob egg for the entity will not have a localized name.
     
    Garris0n likes this.
  25. Offline

    Squid_Boss

    TeeePeee When trying this with a villager, it didn't work at all, not even any errors. Here is what I did:
    CustomEntityType (open)

    Code:java
    1. public enum CustomEntityType {
    2.  
    3. VILLAGER("Villager", 120, EntityType.VILLAGER, EntityVillager.class, CustomEntityVillager.class);
    4.  
    5. private String name;
    6. private int id;
    7. private EntityType entityType;
    8. private Class<? extends EntityInsentient> nmsClass;
    9. private Class<? extends EntityInsentient> customClass;
    10.  
    11. private CustomEntityType(String name, int id, EntityType entityType, Class<? extends EntityInsentient> nmsClass, Class<? extends EntityInsentient> customClass) {
    12. this.name = name;
    13. this.id = id;
    14. this.entityType = entityType;
    15. this.nmsClass = nmsClass;
    16. this.customClass = customClass;
    17. }
    18.  
    19. public String getName() {
    20. return name;
    21. }
    22.  
    23. public int getID() {
    24. return id;
    25. }
    26.  
    27. public EntityType getEntityType() {
    28. return entityType;
    29. }
    30.  
    31. public Class<? extends EntityInsentient> getNMSClass() {
    32. return nmsClass;
    33. }
    34.  
    35. public Class<? extends EntityInsentient> getCustomClass() {
    36. return customClass;
    37. }
    38.  
    39. /**
    40.   * Register our entities.
    41.   */
    42. public static void registerEntities() {
    43. for (CustomEntityType entity : values())
    44. a(entity.getCustomClass(), entity.getName(), entity.getID());
    45.  
    46. // BiomeBase#biomes became private.
    47. BiomeBase[] biomes;
    48. try {
    49. biomes = (BiomeBase[]) getPrivateStatic(BiomeBase.class, "biomes");
    50. } catch (Exception exc) {
    51. // Unable to fetch.
    52. return;
    53. }
    54. for (BiomeBase biomeBase : biomes) {
    55. if (biomeBase == null)
    56. break;
    57.  
    58. // This changed names from J, K, L and M.
    59. for (String field : new String[] { "as", "at", "au", "av" })
    60. try {
    61. Field list = BiomeBase.class.getDeclaredField(field);
    62. list.setAccessible(true);
    63. @SuppressWarnings("unchecked")
    64. List<BiomeMeta> mobList = (List<BiomeMeta>) list.get(biomeBase);
    65.  
    66. // Write in our custom class.
    67. for (BiomeMeta meta : mobList)
    68. for (CustomEntityType entity : values())
    69. if (entity.getNMSClass().equals(meta.b))
    70. meta.b = entity.getCustomClass();
    71. } catch (Exception e) {
    72. e.printStackTrace();
    73. }
    74. }
    75. }
    76.  
    77. /**
    78.   * Unregister our entities to prevent memory leaks. Call on disable.
    79.   */
    80. @SuppressWarnings("rawtypes")
    81. public static void unregisterEntities() {
    82. for (CustomEntityType entity : values()) {
    83. // Remove our class references.
    84. try {
    85. ((Map) getPrivateStatic(EntityTypes.class, "d")).remove(entity.getCustomClass());
    86. } catch (Exception e) {
    87. e.printStackTrace();
    88. }
    89.  
    90. try {
    91. ((Map) getPrivateStatic(EntityTypes.class, "f")).remove(entity.getCustomClass());
    92. } catch (Exception e) {
    93. e.printStackTrace();
    94. }
    95. }
    96.  
    97. for (CustomEntityType entity : values())
    98. try {
    99. // Unregister each entity by writing the NMS back in place of the custom class.
    100. a(entity.getNMSClass(), entity.getName(), entity.getID());
    101. } catch (Exception e) {
    102. e.printStackTrace();
    103. }
    104.  
    105. // Biomes#biomes was made private so use reflection to get it.
    106. BiomeBase[] biomes;
    107. try {
    108. biomes = (BiomeBase[]) getPrivateStatic(BiomeBase.class, "biomes");
    109. } catch (Exception exc) {
    110. // Unable to fetch.
    111. return;
    112. }
    113. for (BiomeBase biomeBase : biomes) {
    114. if (biomeBase == null)
    115. break;
    116.  
    117. // The list fields changed names but update the meta regardless.
    118. for (String field : new String[] { "as", "at", "au", "av" })
    119. try {
    120. Field list = BiomeBase.class.getDeclaredField(field);
    121. list.setAccessible(true);
    122. @SuppressWarnings("unchecked")
    123. List<BiomeMeta> mobList = (List<BiomeMeta>) list.get(biomeBase);
    124.  
    125. // Make sure the NMS class is written back over our custom class.
    126. for (BiomeMeta meta : mobList)
    127. for (CustomEntityType entity : values())
    128. if (entity.getCustomClass().equals(meta.b))
    129. meta.b = entity.getNMSClass();
    130. } catch (Exception e) {
    131. e.printStackTrace();
    132. }
    133. }
    134. }
    135.  
    136. /**
    137.   * A convenience method.
    138.   * @param clazz The class.
    139.   * @param f The string representation of the private static field.
    140.   * @return The object found
    141.   * @throws Exception if unable to get the object.
    142.   */
    143. @SuppressWarnings("rawtypes")
    144. private static Object getPrivateStatic(Class clazz, String f) throws Exception {
    145. Field field = clazz.getDeclaredField(f);
    146. field.setAccessible(true);
    147. return field.get(null);
    148. }
    149.  
    150. /*
    151.   * Since 1.7.2 added a check in their entity registration, simply bypass it and write to the maps ourself.
    152.   */
    153. @SuppressWarnings({ "unchecked", "rawtypes" })
    154. private static void a(Class paramClass, String paramString, int paramInt) {
    155. try {
    156. ((Map) getPrivateStatic(EntityTypes.class, "c")).put(paramString, paramClass);
    157. ((Map) getPrivateStatic(EntityTypes.class, "d")).put(paramClass, paramString);
    158. ((Map) getPrivateStatic(EntityTypes.class, "e")).put(Integer.valueOf(paramInt), paramClass);
    159. ((Map) getPrivateStatic(EntityTypes.class, "f")).put(paramClass, Integer.valueOf(paramInt));
    160. ((Map) getPrivateStatic(EntityTypes.class, "g")).put(paramString, Integer.valueOf(paramInt));
    161. } catch (Exception exc) {
    162. // Unable to register the new class.
    163. }
    164. }
    165. }
    166.  


    CustomEntityVillager (open)

    Code:java
    1. public class CustomEntityVillager extends EntityVillager {
    2.  
    3. public CustomEntityVillager(World world, String name) {
    4. super(world);
    5. this.setCustomName(name);
    6. this.setCustomNameVisible(true);
    7. this.setProfession(2);
    8. this.getNavigation().b(false);
    9. this.getNavigation().a(false);
    10. }
    11.  
    12. protected void aD() {
    13. super.aD();
    14. this.getAttributeInstance(GenericAttributes.a).setValue(40000.0d);
    15. this.getAttributeInstance(GenericAttributes.d).setValue(0d);
    16. }
    17. }


    Command I used to spawn entity (open)

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("test")) {
    2. Player p = (Player) sender;
    3. CustomEntityVillager v = new CustomEntityVillager(((CraftWorld)p.getWorld()).getHandle(), "Derp");
    4. ((CraftWorld)p.getWorld()).getHandle().addEntity(v);
    5. v.setLocation(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), p.getLocation().getPitch(), p.getLocation().getYaw());
    6. }



    Not entirely sure if I spawned it in correctly, but if I did something wrong, at least I would expect errors, but I didn't get any when running the command. I have absolutely no idea what's wrong.
     
  26. Offline

    TeeePeee

    Squid_Boss
    When Minecraft spawns in mobs naturally, it gets the constructor with only a world parameter so you should add one just to be sure.

    I generally use setLocation before spawning the entity in. It may not make a difference but who knows. Also try reducing the 40000 param as it might cause problems (again, just speculation).

    The only other thing I can see is that the command might not be executing. Make sure the command is running and maybe try spawning in a villager with a spawn egg.
     
  27. Offline

    Squid_Boss

    Alright, I'll edit it respectively, and then see. :)

    TeeePeee Even when removing any edited attributes, and the custom name it still didn't spawn (I just had the basic constructor super(world); ) Not really sure what the issue is, because it's not because of anything I edited it with.

    EDIT: The command is definitely being executed, when putting a broadcast message inside the command with the custom spawn, the message get's broadcasted.

    DOUBLE EDIT: Yeap...mob spawning was disabled...that'll do it everytime >.<

    Also, you can add parameters to the constructor, works just as fine :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 25, 2016
  28. Offline

    TeeePeee

  29. Offline

    felixferr0w

    TeeePeee

    Wonderful, in-depth tutorial. :)
     
    TeeePeee likes this.
  30. Offline

    ToastHelmi

    nice tutorial

    EDIT: already done
     
Thread Status:
Not open for further replies.

Share This Page