Solved Custom mob not working

Discussion in 'Plugin Development' started by NonameSL, Aug 29, 2014.

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

    NonameSL

    I am trying to create a custom zombie, but for some reason whenever I spawn it, minecraft crashes, and I have absolutely no idea why.
    My code:
    Code:java
    1. import net.minecraft.server.v1_7_R3.EntityZombie;
    2. import net.minecraft.server.v1_7_R3.PathEntity;
    3.  
    4. import org.bukkit.DyeColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.craftbukkit.v1_7_R3.CraftWorld;
    7. import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
    8.  
    9. public class NormalBotEntity extends EntityZombie{
    10.  
    11. private org.bukkit.World bworld;
    12. public NormalBotEntity(org.bukkit.World bworld) {
    13. super(((CraftWorld)bworld).getHandle());
    14. this.bworld=bworld;
    15. this.team=team;
    16.  
    17. }
    18. public void spawn(Location loc){
    19. teleport(loc);
    20. world.addEntity(this, SpawnReason.CUSTOM);
    21. }
    22. public Location getLocation(){
    23. return new Location(bworld, locX, locY, locZ);
    24. }
    25. public void teleport(Location to){
    26. this.setPosition(to.getX(), to.getY(), to.getZ());
    27. }
    28. public void move(Location to){
    29. to.add(0, to.getWorld().getHighestBlockYAt(to)-to.getY(), 0);
    30. world.a(this, (int)to.getX(), (int)to.getY(), (int)to.getZ(), 16.0F, true, false, false, true);
    31. PathEntity pf = world.a(this, (int)to.getX(), (int)to.getY(), (int)to.getZ(), 16.0F, true, false, false, true);
    32. this.setPathEntity(pf);
    33. }
    34.  
    35. }

    Minecraft crash log (I don't know if it's relevant but i'll post it anyways.)
    Code:
    Time: 18:55 29/08/14
    Description: Unexpected error
     
    java.lang.NullPointerException: Unexpected error
        at bjb.a(SourceFile:514)
        at fz.a(SourceFile:97)
        at fz.a(SourceFile:15)
        at ej.a(SourceFile:174)
        at bje.e(SourceFile:212)
        at bao.p(SourceFile:1306)
        at bao.ak(SourceFile:774)
        at bao.f(SourceFile:728)
        at net.minecraft.client.main.Main.main(SourceFile:148)
     
     
    A detailed walkthrough of the error, its code path and all known details is as follows:
    ---------------------------------------------------------------------------------------
     
    -- Head --
    Stacktrace:
        at bjb.a(SourceFile:514)
        at fz.a(SourceFile:97)
        at fz.a(SourceFile:15)
        at ej.a(SourceFile:174)
        at bje.e(SourceFile:212)
     
    -- Affected level --
    Details:
        Level name: MpServer
        All players: 1 total; [bjk['NonameSL'/119, l='MpServer', x=-225.04, y=5.62, z=-463.12]]
        Chunk stats: MultiplayerChunkCache: 441, 441
        Level seed: 0
        Level generator: ID 01 - flat, ver 0. Features enabled: false
        Level generator options:
        Level spawn location: World: (-141,4,-531), Chunk: (at 3,0,13 in -9,-34; contains blocks -144,0,-544 to -129,255,-529), Region: (-1,-2; contains chunks -32,-64 to -1,-33, blocks -512,0,-1024 to -1,255,-513)
        Level time: 8539115 game time, 168000 day time
        Level dimension: 0
        Level storage version: 0x00000 - Unknown?
        Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
        Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false
        Forced entities: 2 total; [bjk['NonameSL'/119, l='MpServer', x=-225.04, y=5.62, z=-463.12], wi['§9§k!!!§r§bServer Information§9§k!!!'/121, l='MpServer', x=-164.79, y=-443.71, z=-549.79]]
        Retry entities: 0 total; []
        Server brand: CraftBukkit
        Server type: Non-integrated multiplayer server
    Stacktrace:
        at bjf.a(SourceFile:289)
        at bao.b(SourceFile:1972)
        at bao.f(SourceFile:742)
        at net.minecraft.client.main.Main.main(SourceFile:148)
     
    -- System Details --
    Details:
        Minecraft Version: 1.7.10
        Operating System: Windows 8.1 (amd64) version 6.3
        Java Version: 1.7.0_60, Oracle Corporation
        Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
        Memory: 92030048 bytes (87 MB) / 180387840 bytes (172 MB) up to 1060372480 bytes (1011 MB)
        JVM Flags: 6 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx1G -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M
        AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
        IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
        Launched Version: 1.7.10
        LWJGL: 2.9.1
        OpenGL: GeForce GT 740M/PCIe/SSE2 GL version 4.4.0, NVIDIA Corporation
        GL Caps: Using GL 1.3 multitexturing.
    Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
    Anisotropic filtering is supported and maximum anisotropy is 16.
    Shaders are available because OpenGL 2.1 is supported.
     
        Is Modded: Probably not. Jar signature remains and client brand is untouched.
        Type: Client (map_client.txt)
        Resource Packs: []
        Current Language: English (US)
        Profiler Position: N/A (disabled)
        Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
        Anisotropic Filtering: Off (1)
    EDIT: Now the game crashes when I enter the server. T_T I guess the entity still exists.

    P.S: The entity 9§k!!!§r§bServer Information§9§k!!! that is in the forced entities list is a hologram.
     
  2. Offline

    FerusGrim

    We don't really offer support for NMS.
     
  3. Offline

    TheHandfish

    Why not?

    Any server errors?
     
  4. Offline

    Jimfutsu

    I have vague knowledge of NMS, but are you registering your entity?
     
  5. Offline

    FerusGrim

    TheHandfish
    I'm not sure of the reason for the rule, just know that it exists. I would imagine it's because it's not really developed by Bukkit.
     
  6. Offline

    TheHandfish

    It's in the CraftBukkit API code. :p I've never seen anyone give other uses trouble for using NMS. Would you mind citing the rule?
     
  7. Offline

    FerusGrim

    Should Bukkit also support org.snakeyaml.yaml? But sure, I'll go ahead and try to find the rule.

    TheHandfish
    If I may: http://puu.sh/bcTR1.png

    Edited: http://puu.sh/bcTZL.png
    But the admission _was_ with great reluctance. :p Carry on, I s'pose.

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

    TheHandfish

    He's talking about the IRC. That has nothing to do with the Bukkit Forums... I don't think you realize how many support questions, answers, and resources there have been for NMS, so there's no reason why it should change now.
     
    Feindbild likes this.
  9. Offline

    FerusGrim

    TheHandfish
    I realize my asshat-ness, fully.
    Check my edit. :)
     
  10. Offline

    TheHandfish

    It's alright. :p Perfectly fine.
     
  11. Offline

    AlphaRLee

    TheHandfish
    I'm not very good when it comes to helping with NMS (I'm using it, but I'm really lost reading it), but have you registered your entity? Or have you tried registering any other custom entities? Try registering a customized creeper for example, but don't modify anything in its behaviour. Comment the pointers that spawn custom zombies and try it out. To me, it looks like there's a problem registering your entity in your registering enum (or class or whatever you used), not your custom zombie class.
     
  12. Offline

    NonameSL

    No server errors.
     
  13. Offline

    NonameSL

    BUMP! Anyone?
     
  14. Offline

    PluginMaker

    It's the current version of bukkit/minecraft. There is something wierd about custom entities that will just crush the client. I'm having the same problem excactly.
    I looked into the source code but haven't found the bug yet. This is why I stopped developing my plugin at the moment. We will just have to wait for a fix.
    *just to be clear that this is a bug in minecraft:
    Code:java
    1. public class CustomEntityZombie extends EntityZombie
    2. {
    3.  
    4. public CustomEntityZombie (net.minecraft.server.v1_7_R3.World world)
    5. {
    6. super(world);
    7. }
    8. }


    Code:java
    1. EntityZombie zombie= new EntityZombie(world);
    2. world.addEntity(zombie);

    this will work fine.
    Code:java
    1. CustumEntityZombie zombie= new CustomEntityZombie(world);
    2. world.addEntity(zombie);

    this will make the player crash as long as the entity is spawned.
     
  15. Offline

    jpjunho

  16. Offline

    NonameSL

    jpjunho What is registering your entity? How do you do that? I am kinda new to mob creating.
    EDIT: I looked it up, is this called registering your entity?
    Code:java
    1. try{
    2. Method a = EntityTypes.class.getDeclaredMethod("a", new Class<?>[]{Class.class, String.class, int.class});
    3. a.setAccessible(true);
    4. a.invoke(null, /**CUSTOM CLASS*/,/**NAME*/, /**ID*/);
    5. }catch (Exception e){
    6. e.printStackTrace();
    7. }
     
  17. Offline

    Dudemister1999

    I am trying to accomplish the same thing.
    What I've done:
    Show Spoiler

    Code:java
    1. public void registerCustomEntities()
    2. {
    3. Field c;
    4. Field d;
    5. Field e;
    6. Field f;
    7. Field g;
    8.  
    9. Map cMap;
    10. Map dMap;
    11. Map eMap;
    12. Map fMap;
    13. Map gMap;
    14.  
    15. try
    16. {
    17. c = EntityTypes.class.getDeclaredField("c");
    18. c.setAccessible(true);
    19.  
    20. d = EntityTypes.class.getDeclaredField("d");
    21. d.setAccessible(true);
    22.  
    23. e = EntityTypes.class.getDeclaredField("e");
    24. e.setAccessible(true);
    25.  
    26. f = EntityTypes.class.getDeclaredField("f");
    27. f.setAccessible(true);
    28.  
    29. g = EntityTypes.class.getDeclaredField("g");
    30. g.setAccessible(true);
    31.  
    32. cMap = (Map)c.get(null);
    33. dMap = (Map)d.get(null);
    34. eMap = (Map)e.get(null);
    35. fMap = (Map)f.get(null);
    36. gMap = (Map)g.get(null);
    37.  
    38. for (DeadworksEntities entity : DeadworksEntities.values())
    39. {
    40. cMap.remove(entity.getClass());
    41. dMap.remove(entity.getName());
    42. eMap.remove(entity.getID());
    43. fMap.remove(entity.getClass());
    44. gMap.remove(entity.getName());
    45.  
    46. Method add = EntityTypes.class.getDeclaredMethod("a", new Class<?>[]{Class.class, String.class, int.class, int.class, int.class});
    47. add.setAccessible(true);
    48. add.invoke(null, entity.getCustomClass(), entity.getName(), entity.getID(), 44975, 7969893);
    49. }
    50.  
    51. for (BiomeBase biomeBase : BiomeBase.getBiomes())
    52. {
    53. if (biomeBase == null)
    54. {
    55. break;
    56. }
    57.  
    58. for (String field : new String[]{"as", "at", "au", "av"})
    59. {
    60. Field list = BiomeBase.class.getDeclaredField(field);
    61. list.setAccessible(true);
    62.  
    63. @SuppressWarnings("unchecked")
    64. List<BiomeMeta> mobList = (List<BiomeMeta>) list.get(biomeBase);
    65.  
    66. for (BiomeMeta meta : mobList)
    67. {
    68. for (DeadworksEntities entity : DeadworksEntities.values())
    69. {
    70. if (entity.getNMSClass().equals(meta.b))
    71. {
    72. meta.b = entity.getCustomClass();
    73. }
    74. }
    75. }
    76. }
    77. }
    78. }
    79. {
    80. ex.printStackTrace();
    81. }
    82. }



    The above code does not clear it, unfortunately.

    If you can figure out how to get the code above working, then your custom entity will be registered. (Note that the code is for 1.7.10)

    The issue is I cannot clear the old zombie code out of the map. And that is what causes the Minecraft crash, is adding a null entity to the world. It's null because it isn't registered. (EntityTypes, line 30: if (c.containsKey(paramString)) throw new IllegalArgumentException("ID is already registered: " + paramString);)

    So yes, remove the entity from the maps, and it's good. If you figure it out, we all figure it out and learn.
     
  18. Offline

    jpjunho

  19. Offline

    NonameSL

Thread Status:
Not open for further replies.

Share This Page