Solved [NMS] Custom Skeleton, Crashing Client

Discussion in 'Plugin Development' started by Lorinthio, Apr 13, 2014.

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

    Lorinthio

    Hey guys, I've been getting into custom mobs and have hit a brick wall and I'm not sure how to proceed or what I'm doing wrong.

    Currently I'm at the point to where the creature event fires to spawn the custom mob, and it crashes clients connected. Giving a single line error

    "client lost connection: Internal Exception: java.io.IOException: an existing connection was forcibly closed by the remote host"

    SpawnerSkeleton.class
    Code:java
    1.  
    2. public class SpawnerSkeleton extends EntitySkeleton {
    3.  
    4. public SpawnerSkeleton(World world) {
    5. super(world);
    6.  
    7.  
    8. try {
    9. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    10. bField.setAccessible(true);
    11. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    12. cField.setAccessible(true);
    13. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    14. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    15. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    16. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    17. } catch (Exception exc) {
    18. exc.printStackTrace();
    19. }
    20. //this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
    21. //this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
    22. //this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
    23. //this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
    24. //this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
    25.  
    26. }
    27.  
    28. @Override
    29. protected void aD() {
    30. super.aD();
    31. }
    32. }


    Codesnippet in Listener(Error points within this code block)
    Code:java
    1.  
    2. public void onEntitySpawn(CreatureSpawnEvent event){
    3. Entity entity = event.getEntity();
    4. if(event.getSpawnReason().equals(SpawnReason.CUSTOM)){
    5. Location location = event.getLocation();
    6. World world = location.getWorld();
    7.  
    8. net.minecraft.server.v1_7_R1.World mcWorld = ((CraftWorld) world).getHandle();
    9. net.minecraft.server.v1_7_R1.Entity mcEntity = (((CraftEntity) entity).getHandle());
    10. if(event.getEntity() instanceof Skeleton){
    11. SpawnerSkeleton ss = new SpawnerSkeleton(mcWorld);
    12.  
    13. Location loc = event.getLocation();
    14. double x = loc.getX();
    15. double y = loc.getY();
    16. double z = loc.getZ();
    17. mcWorld.removeEntity((net.minecraft.server.v1_7_R1.EntitySkeleton) mcEntity);
    18. mcWorld.addEntity(ss, SpawnReason.REINFORCEMENTS);
    19. entity = (Entity) ss.getBukkitEntity();
    20. ss.setPosition(x, y, z);
    21. }
    22. }
    23. }
    24. }
     
  2. Offline

    Lorinthio

    If I remember correctly I'm allowed a bump every 24 hours... so bump!

    Please help =)
     
  3. Offline

    RawCode

    If I remember correctly You are allowed to add debug messages to your code and allowed to provide code with matching line numbers.
     
  4. Offline

    MoeMix

    Lorinthio
    So you added the entity to the world...great! But where do you want it to be? :p
    you have to use the .setPosition method which you would then pass in the X, Y, and Z coordinates as the parameters.

    Thus, you would have to add this line of code:
    Code:java
    1. ss.setPosition(x, y, z);
     
  5. Offline

    Lorinthio

    Ah yeah, im not sure why thats not in there. I had that line in there before but, it was still producing the same result. But ill put it in and try, thanks for replying!
     
  6. Offline

    Garris0n

    Or at least post the full stack trace.
     
    skyrimfan1 likes this.
  7. Offline

    Lorinthio

    Alright I got that put in and updated my post to the new problem I'm having, the mob spawn event is crashing clients connected with the error

    "client lost connection: Internal Exception: java.io.IOException: an existing connection was forcibly closed by the remote host"

    thats all the console gives me


    The client gives this stack
    Code:
    java.lang.NullPointerException: Unexpected error
        at net.minecraft.client.network.NetHandlerPlayClient.func_147281_a(NetHandlerPlayClient.java:766)
        at net.minecraft.network.play.server.S0FPacketSpawnMob.func_148833_a(SourceFile:97)
        at net.minecraft.network.play.server.S0FPacketSpawnMob.func_148833_a(SourceFile:15)
        at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:211)
        at net.minecraft.client.multiplayer.PlayerControllerMP.func_78765_e(PlayerControllerMP.java:294)
        at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1587)
        at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:953)
        at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:870)
        at net.minecraft.client.main.Main.main(SourceFile:103)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
        at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
     
  8. Offline

    MoeMix

    Lorinthio
    You locations must be null? Post the section of the code where you are spawning the entity.
     
  9. Offline

    Lorinthio

    Thats in the second code block. The location, x, y, z are getting the location from the event and using those for spawning it in
     
  10. Offline

    Garris0n

    The entity is registered, right?
     
  11. Offline

    Lorinthio

  12. Offline

    perwin

    I followed the same tutorial and I have the same problem, MC client also crashes when I use /reload command.
     
  13. Offline

    Lorinthio

    Ok cool im not alone. I thought i was crazy for the past week

    Alright I have fixed the problem with spawning them. Now the problem I have, is that the mobs are invisible until I relog, is this a fixable problem? Also, I'm getting the following warning...
    Code:
    [00:11:58] [Server thread/WARN]: Wrong location for SpawnerSkeleton['[Lvl.2] Skeleton'/7490, l='world', x=3.00, y=71.00, z=-5.00] in world 'world'!
    [00:11:58] [Server thread/WARN]: Entity is at 3.0,-5.0 (chunk 0,-1) but was stored in chunk 0,0
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  14. Offline

    Garris0n

    I don't know if it's relevant and I'm too tired to actually check, but perhaps you could try setting the position before adding it to the world.
     
    Lorinthio likes this.
  15. Offline

    Lorinthio

    I'll try it now thanks

    YES! Thank you so much! That was all it took. Now it works perfect! Marking as solved!

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

    Garris0n

    I can't really say I expected that, but alright.
     
Thread Status:
Not open for further replies.

Share This Page