[Tutorial] Register your custom entities [NMS][Reflection]

Discussion in 'Resources' started by bigteddy98, Apr 18, 2014.

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

    bigteddy98

    This resource is no longer availabe.
     
  2. Question (not related to this really): Is there a way to make EntitySkeleton version proof? :/

    Although, nice!
     
  3. Offline

    bigteddy98

    I don't think there is. The first problem you will have is that you have to extend EntitySkeleton, which requires you to import it. The second problem are the method names, they most likely will change every nms update. You could make multiple classes for every version and let the registerEntity() method fully depend on reflection, but you will have to add a new class every version anyway (example you have a V1.7_R1_CustomSkeleton and a V1.7_R2_CustomSkeleton).

    - BigTeddy98, Sander.
     
    KingFaris11 likes this.
  4. Offline

    ArthurMaker

    I WANT MOAARR REZOURSES FROM YA

    impregnate me, bigteddy98, u sexy
     
  5. Offline

    ZeusAllMighty11

    Any idea why I can't spawn any custom mobs? It says 'Method not found exception' and points to the constructor, but the only thing in the constructor is super(world)
     
  6. Offline

    bigteddy98

    Could you please post the full error log + the CB version you are running?
     
  7. Offline

    ZeusAllMighty11

  8. Offline

    bigteddy98

    Hmm, can you post your NaziZombie class? I don't really know whats going wrong here.
    Edit: Or send it in PM, if you don't want to make it public.
     
  9. Offline

    ZeusAllMighty11

    bigteddy98

    There's nothing in the class, really.. That's why this error makes absolutely no sense.

    Code:
    public class NaziZombie extends EntityZombie
    {
        public NaziZombie(World nmsWorld){ super(nmsWorld); }
    }
     
  10. Offline

    bigteddy98

    Your error is on this line in NMS:
    Code:java
    1. if (localClass != null) localEntity = (Entity)localClass.getConstructor(new Class[] { World.class }).newInstance(new Object[] { paramWorld });

    At the moment I am unable to reproduce this error, because the constructor does exists. When are you registering your entity? It doesn't seem like you're doing it in your onEnable, can you try that?
     
  11. Offline

    ZeusAllMighty11

    I already am registering the entity when the plugin enables, and unregistering when the plugin disables.


    For the record, this code runs fine prior to 1.7.9
     
  12. Offline

    bigteddy98

    Okay, I guess the error occures when the zombie is being spawned, I am trying to spawn a custom Zombie myself right now.
    What do you mean? Has it worked before? Have you manage to get it working?
     
  13. Offline

    ZeusAllMighty11

    bigteddy98


    I have used almost the exact same code in 1.7.2 builds, and it worked without this issue. No, it still will not work in the 1.7.9 version.
     
  14. Offline

    bigteddy98

    Are you doing 1.7_R3 imports everywhere? (sounds stupid, but that's the only thing I can imagine why your constructor can't be found).
     
  15. Offline

    ZeusAllMighty11

  16. Offline

    bigteddy98

    I will try spawning a custom zombie myself, I will let you know when I've got it working.

    I have spawned a custom zombie without any problems. I guess you are doing something wrong, don't know what. Can you send the full code, including onEnable, classes and imports. ZeusAllMighty11

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

    ZeusAllMighty11

    bigteddy98


    Can you post your entire code? I've already shown you what I have. There's nothing else aside from registering the entities.
     
  18. Offline

    bigteddy98

  19. Offline

    ArthurMaker

    bigteddy98
    So yea, I'm doing a custom EnderSignal and I kind need ur help.
    EntityEnderSignal does not extends EntityInsentient. Is there any problem if I change
    Code:java
    1. public void registerEntity(String name, int id, Class<? extends EntityInsentient> nmsClass, Class<? extends EntityInsentient> customClass) {

    to this?
    Code:java
    1. public void registerEntity(String name, int id, Class<EntityEnderSignal> nmsClass, Class<CataOlhosEntity> customClass) {

    "CataOlhosEntity" is my custom EnderSignal class.
     
  20. Offline

    Ultimate_n00b

    Then you don't need to register it.
     
  21. Offline

    ArthurMaker


    Really?! Oh, that is great xD
    Thanks!
     
  22. Offline

    bensku

    Why to register entity? I have used custom fireballs in 1.7.2 builds and they worked fine without any registering.
     
  23. Offline

    bigteddy98

    Fireballs don't extend EntityInsentient. All entities which extend EntityInsentient require to be registered, otherwise they will crash the client while spawning.
     
  24. Offline

    XvBaseballkidvX

    bigteddy98 Is it possible to register more than one entity of the same type? Like if I wanted to have an "Easy Sheep" and a "Super Mega Delta Force Sheep" would the one that I register last overwrite the one I registered before? (I hope I explained that well enough...)

    Also, is there a way I could just spawn in my entity without overriding the default entity?

    bigteddy98 I did some testing and I can register more than one entity of the same type c:
    Thank you so much for this tutorial it has helped me immensely!

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

    bigteddy98

    I think it doesn't, although I highly advise you using this version. That one works better for you, because that one doesn't change the natural spawned mobs too (this one does).
     
  26. Offline

    Plo124

    bigteddy98
    Sorry if this is really obvious, but how do I then spawn the zombie into the world, at given co-ords, outside the CustomEntityZombie class.
     
  27. Offline

    XvBaseballkidvX

    Plo124

    Code:java
    1. public void spawnCustomZombie(Location loc){
    2. YourZombie z = new YourZombie(((CraftWorld)loc.getWorld()).getHandle());
    3. z.setPosition(loc.getX(), loc.getY(), loc.getZ());
    4. ((CraftWorld)loc.getWorld()).getHandle().addEntity(z);
    5. }
     
    bigteddy98 likes this.
  28. Offline

    ShadowHammer12

    Any Ideas on how I could make the method that spawns the entity return an actual entity and not the custom entity. I would like the general entity for capabilities such as potion effects. Here is my current code for the method.
    Code:java
    1. public SkeletalHead spawnSkeletalHead(Location loc){
    2. SkeletalHead entity = new SkeletalHead(((CraftWorld)loc.getWorld()).getHandle());
    3. entity.setPosition(loc.getX(), loc.getY(), loc.getZ());
    4. ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
    5. return entity;
    6. }

    I would Like something like this, but when I attempt to cast it to an Entity it tells me an internal error happened in server chat.
    Code:java
    1. public Entity spawnSkeletalHead(Location loc){
    2. SkeletalHead entity = new SkeletalHead(((CraftWorld)loc.getWorld()).getHandle());
    3. entity.setPosition(loc.getX(), loc.getY(), loc.getZ());
    4. ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
    5. return (Entity) entity;
    6. }
     
  29. Offline

    bigteddy98

    Exactly! ;)
     
    XvBaseballkidvX likes this.
  30. Offline

    ShadowHammer12

    I just found the fix,
    Code:java
    1. public Entity spawnSkeletalHead(Location loc){
    2. SkeletalHead entity = new SkeletalHead(((CraftWorld)loc.getWorld()).getHandle());
    3. entity.setPosition(loc.getX(), loc.getY(), loc.getZ());
    4. ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
    5. Entity ent = entity.getBukkitEntity();
    6. return ent;
    7. }


    But now I encountered a separate problem. Whenever I try to use an event listener to see if the custom mob dies, it never works. I tested it by removing the if statement, therefore triggering whenever I kill any entity, and it works for all of them except my custom one.
    Code:java
    1. @EventHandler
    2. public void OnKill(EntityDeathEvent e){
    3. Entity entity = e.getEntity();
    4. Location entLoc = entity.getLocation();
    5.  
    6. net.minecraft.server.v1_7_R3.Entity mcEntity = (((CraftEntity) entity).getHandle());
    7.  
    8. if(mcEntity instanceof SkeletalHead == true){
    9. FireWork.shootFirework(entLoc);
    10. }
    11. }

    The shoot Firework method is custom, and I would like to trigger it whenever the custom entity is killed.
     
Thread Status:
Not open for further replies.

Share This Page