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

    InfamousSheep

    Does anyone know the constructor name for Primed TNT? Thanks in advance.
     
  2. Offline

    Garris0n

    Constructor...name? What is a constructor name? The class is EntityTNTPrimed, if that's what you meant.
     
    TeeePeee likes this.
  3. Offline

    ToastHelmi

    how to prevent spawning custom entities by using egs
     
  4. Offline

    TwoPointDuck

    ToastHelmi
    Code:
    private static void a(Class paramClass, String paramString, int paramInt) {
            try {
                ((Map) getPrivateStatic(EntityTypes.class, "d")).put(paramClass, paramString);
                ((Map) getPrivateStatic(EntityTypes.class, "f")).put(paramClass, Integer.valueOf(paramInt));
            } catch (Exception exc) {
                // Unable to register the new class.
            }
        }
    Just replace your current method with that, don't ask me why that works though.

    Also a question. When my mobs are reloaded through chunk unload-load they become custom mobs. I have made it so they are not automatically custom mobs, but the chunk refreshing still forces them to be special. Is there a way to disable this without having to iterate through them every time the chunk loads?

    ALSO: Since this is NMS, how would I go about listening to events where my custom mobs are involved?
     
  5. Offline

    InfamousSheep

    No, I mean this:
    Code:
    PRIMEDTNT("PrimedTnt", 20, EntityType.PRIMED_TNT, EntityTNTPrimed.class, CustomEntityTNT.class);
    There is an error under "PRIMEDTNT"
     
  6. Offline

    Garris0n

    You don't actually have to do that, it's just for convenience. And I can't tell you how to fix the error if I have no idea what it is.
     
  7. Offline

    TeeePeee

    TwoPointDuck
    There won't be an easy way to prevent this (that I know of) save listening for the entity spawn event, checking if the reason is a chunk load and spawning in the normal mob with NMS. I'm on my mobile so I'll try to format properly *fingerscrossed*

    <syntax=java>@EventHandler
    private void onSpawn(EntitySpawnEvent e) {
    if(e.getSpawnReason() != SpawnReason.CHUNK_LOAD) { return; }
    net.minecraft.server.v1_7_R1.World world = ((CraftWorld)e.getLocation().getWorld()).getHandle();
    // Do a switch or get the constructor by name to only replace your custom ones.
    switch(e.getEntityType()) {
    case ZOMBIE: net.minecraft.server.v1_7_R1.EntityZombie z = new net.minecraft.server.v1_7_R1.EntityZombie(world);
    z.setLocation(e.getLocation().getX(), e.getLocation().getY(), e.getLocation().getZ());
    world.addEntity(z);
    break;
    default: break;
    }
    }</syntax>

    Keep in mind that was all written in the forum window on my iPad so there may be serious issues with method names.

    All other events are fired as usual (ie. you can still listen for entity damage events and see if the entity is an instanceof your custom entity).

    InfamousSheep
    You probably didn't put a comma before it.

    ZOMBIE("", 0, null, null, null), PRIMEDTNT("", 0, null, null, null);
    ZOMBIE("", 0, null, null, null); PRIMEDTNT("", 0, null, null, null);

    Notice the comma delimiter rather than the semicolon.
     
  8. Offline

    InfamousSheep

    Nope, I already checked that :l
     
  9. Offline

    TeeePeee

  10. Offline

    InfamousSheep

    "The constructor CustomEntityType(String, int, EntityType, Class<EntityTNTPrimed>, Class<CustomEntityTNT>) is undefined"
     
  11. Offline

    TwoPointDuck

    TeeePeee

    Ye thanks on that. But any other event doesn't work yet.

    Code:
    @EventHandler
        public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event){
            if(!(event.getEntity() instanceof CustomEntityCow))return;
            CustomEntityCow cust = (CustomEntityCow) event.getEntity();
        }
    If I punch my CustomEntityCow it returns. Great tutorial btw :)
     
  12. Offline

    Garris0n

    TwoPointDuck Because e.getEntity() is a CraftEntity, not an NMS entity.
    Code:Java
    1. ((CraftEntity) event.getEntity).getHandle() instanceof CustomEntityCow
     
  13. Offline

    TeeePeee

    InfamousSheep
    The constructor for CustomEntityType requires a class that extends EntityInsentient. Replace all <? extends EntityInsentient> with <? extends Entity>
     
  14. Offline

    Voltex

    Thanks so much for this! Jacek's tutorial was pretty scary, but this tutorial really explained everything carefully.
     
  15. Offline

    ToastHelmi

    TeeePeee

    is ist posible to have multible CustomEntity from the same EntityType
     
  16. Offline

    TeeePeee

    ToastHelmi
    Yup! Minecraft doesn't use the bukkit EntityType, it only uses the classes, name and ID. The EntityType is just there for ease of reading and gettability.
     
  17. Offline

    DonyorM

  18. Offline

    ToastHelmi

    TeeePeee
    so i only do this??

    Code:java
    1. ZOMBIE("Zombie", 54, EntityType.ZOMBIE, EntityZombie.class, CustomEntityZombie.class), ZOMBIE2("Zombie", 54, EntityType.ZOMBIE, EntityZombie2.class, CustomEntityZombie.class));


    or what

    and if so how does it decide whitch of the custom entity will be spawned
     
  19. Offline

    TwoPointDuck

    ToastHelmi TeeePeee

    Personally having problems with this.

    Here is what I tried:
    Code:
    ZombieHostile("ZombieHostile", 54, EntityType.ZOMBIE, EntityZombie.class, CustomEntityHostileZombie.class),
        ZombiePassive("ZombiePassive", 54, EntityType.ZOMBIE, EntityZombie.class, CustomEntityPassiveZombie.class);
    And yeah, this is throwing up crazy errors in the console since my initiation for the CustomEntity___Zombie all have extra (whatchamacallit).
     
  20. Offline

    TeeePeee

    ToastHelmi TwoPointDuck

    Sorry, I should have clarified.

    You can have two enum entries with the same EntityType entries. But you can't have two of the same mobs.

    Code:java
    1. ZOMBIE("Zombie", 54, EntityType.ZOMBIE, EntityZombie.class, CustomZombie.class), OTHER_ZOMBIE("Skeleton", skeletonID, EntityType.ZOMBIE, EntitySkeleton.class, CustomSkeleton.class);

    works.

    Code:java
    1. ZOMBIE("Zombie", 54, EntityType.ZOMBIE, EntityZombie.class, CustomZombie.class), OTHER_ZOMBIE("Zombie", 54, EntityType.ZOMBIE, EntityZombie.class, CustomSkeleton.class);

    does not work.

    You can't have copies of Minecraft mobs xP Only one version may exist.
     
  21. Offline

    TwoPointDuck

    TeeePeee

    Makes sense, now I have to write my own pathfinders q.q

    EDIT: Also, whats the pathfinder for targetting things that attack it?
     
  22. Offline

    macguy8

    I can't seem to find the ID for an egg. Anyone?
     
  23. Offline

    TeeePeee

  24. Offline

    macguy8

    I mean to override an egg
     
  25. Offline

    TeeePeee

    macguy8
    I'm not 100% sure but as they don't spawn naturally and aren't shot by any non-player entities, they don't have a listing in EntityTypes. Just listen in on the interact event with an egg in hand, cancel it and make Player#launchProjectile(new CustomEntityEgg.class)
     
  26. Offline

    Elimnator

    How do I spawn my custom entity?

    Also how can I tell what events I need to override if I want to stop all player interactions?
     
  27. Offline

    GreySwordz

    How can I disable the natural spawning of my custom entity and instead spawn it in a command?
     
  28. Offline

    TeeePeee

    Elimnator
    Your custom entity will spawn naturally but you can also use
    Code:java
    1. CustomEntitySomething entity = new CustomEntitySomething(someWorld);
    2. entity.setLocation(someLocation);
    3. someWorld.addEntity(entity);


    You'll have to check out the source of the entity in question on the NMS source on GitHub to check what does what.

    Sorry for the double post but I'm on my mobile.
    GreySwordz
    See Garris0n 's post on page 3 about which fields to register (I believe d and f). Eg. In the CustomEntityTypes#a() method, remove everything but the fields containing "d" and "f" (check on the values) and it should not spawn naturally.

    Use the code from my post immediately above this to spawn in the mob forcefully.

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

    GreySwordz

    TeeePeee Thanks for the reply.

    I'm trying to override some of the attributes of an EntityChicken, and to do so, I see that I must override the method aC(). However, when I attempt to do so, I get an error saying that I can't have a return type of void, which is what it is in the source.

    What am I missing here?
    EDIT: Looks like I had an outdated version of craftbukkit, so that's fixed.

    The current problem is that when I give the chicken more health:
    Code:
            this.getAttributeInstance(GenericAttributes.a).setValue(20D);
    It works fine, but when I try to give it some damage:
    Code:
    this.getAttributeInstance(GenericAttributes.e).setValue(10D);
    I get a NullPointerException. I suspect this is because the GenericAttribute e is not defined for EntityChicken s, but I have no clue how to combat this.
     
  30. Offline

    TeeePeee

    GreySwordz
    Before you try to set the value of the attribute, if it isn't normal for the mob to have it:
    1.7.5: this.bb().b(GenericAttributes.<attribute>);
    1.7.2: this.bc().b(GenericAttributes.<attribute>);

    Just run that immediately before setting the value of the attribute and you should be good!
     
Thread Status:
Not open for further replies.

Share This Page