Solved [Help] Spawning Custom Entity

Discussion in 'Plugin Development' started by XvBaseballkidvX, May 12, 2014.

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

    XvBaseballkidvX

    Hello everyone!

    I have recently decided to dive into making Custom Entities... It has not been very fun ;-; The problem that I am having currently is that I can not spawn my custom entity.

    CustomEntity:
    Code:java
    1. import net.minecraft.server.v1_7_R3.*;
    2. import org.bukkit.craftbukkit.v1_7_R3.util.UnsafeList;
    3.  
    4. import java.lang.reflect.Field;
    5.  
    6. /**
    7. * Created by Josh on 5/12/14.
    8. */
    9.  
    10. public class EasySheep extends EntitySheep {
    11.  
    12.  
    13. public EasySheep(World world) {
    14. super(world);
    15. try {
    16. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    17. bField.setAccessible(true);
    18. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    19. cField.setAccessible(true);
    20. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    21. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    22. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    23. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    24. } catch (Exception exc) {
    25. exc.printStackTrace();
    26. }
    27.  
    28. this.a(0.9F, 1.3F);
    29. this.getNavigation().a(true);
    30. this.goalSelector.a(0, new PathfinderGoalFloat(this));
    31. this.goalSelector.a(4, new PathfinderGoalFollowParent(this, 1.1D));
    32. this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 6.0F));
    33. this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
    34. this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
    35. this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
    36. this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
    37. }
    38.  
    39.  
    40. @Override
    41. public void aC(){
    42. super.aC();
    43. this.bb().b(GenericAttributes.e);
    44. this.getAttributeInstance(GenericAttributes.a).setValue(20.0D); //Max Health
    45. this.getAttributeInstance(GenericAttributes.b).setValue(20.0D); //Follow Range
    46. this.getAttributeInstance(GenericAttributes.c).setValue(10.0D); //KnockBack resistance
    47. this.getAttributeInstance(GenericAttributes.d).setValue(0.4D); //Movement Speed
    48. this.getAttributeInstance(GenericAttributes.e).setValue(5.0D); //Attack damage
    49. }
    50.  
    51. @Override
    52. public boolean n(Entity entity) {
    53. float f = (float) this.getAttributeInstance(GenericAttributes.e).getValue();
    54. return entity.damageEntity(DamageSource.mobAttack(this), f);
    55. }
    56. }


    How I am trying to spawn it:
    Code:java
    1. public void spawnEasySheep(Location loc){
    2. EasySheep sheep = new EasySheep(((CraftWorld)loc.getWorld()).getHandle());
    3. sheep.setPosition(loc.getX(), loc.getY(), loc.getZ());
    4. ((CraftWorld)loc.getWorld()).getHandle().addEntity(sheep);
    5. }


    Whenever I try to spawn my "EasySheep" my client crashes.

    Here are some other ways I have tried to spawn the sheep in:
    Code:
    sheep.spawnIn(((CraftWorld)loc.getWorld()).getHandle());
     
    PacketPlayOutSpawnEntity e = new PacketPlayOutSpawnEntity(sheep, 1); //I sent the Packet to all online players
    Thank you for reading.
    Any and all help is much appreciated! :D
     
  2. Offline

    mazentheamazin

    XvBaseballkidvX
    Are there any errors in console or does it just not spawn?
     
  3. Offline

    XvBaseballkidvX

    mazentheamazin No errors in console, but when I try .addEntity(Entity e); it crashes my client with this error message: http://paste.ubuntu.com/7455499/

    When I try to spawn it using one of the other ways it just doesn't appear ._.
     
  4. Offline

    Kobting

    The only thing I could think of because I cant't tell how your setting the location in your code is that the location could be null?
     
  5. Offline

    XvBaseballkidvX

    Kobting I'm positive that my location is not returning null. If it did however I believe that it would show up in the console and not crash my client.

    SOLVED: Needed to register my entities to prevent client crashes.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page