Spawncreature and creaturetype

Discussion in 'Plugin Development' started by KaBob, Feb 17, 2011.

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

    KaBob

    I started working on a spawnmob feature for my personal mod, but I noticed two major issues with the spawncreature function. The first is that there is no creaturetype for giant, monster or slime so I can't spawn them. The second is that theres no apparent way to spawn something like a skeleton riding a spider.

    Is there some work around for either of these issues, or do I just need to keep waiting?

    It's also giving me issues with spawning anything other than cow, pig, squid, chicken and sheep. They appear for one split second and then vanish. edit: oddly enough, they don't dissapear in my nether world.
     
  2. Offline

    robin0van0der0v

    Do you have spawn-monsters on in your server.properties file? :p
     
  3. Offline

    Edward Hand

    Giants and slimes are both buggy. You don't want them. I have no idea what mob you think a 'monster' is.

    I found the code in the server source for putting skeletons on spiders:

    Code:
    if (((paramEntityLiving instanceof EntitySpider)) && (paramWorld.l.nextInt(100) == 0)) {
           EntitySkeleton localEntitySkeleton = new EntitySkeleton(paramWorld);
           localEntitySkeleton.c(paramFloat1, paramFloat2, paramFloat3, paramEntityLiving.yaw, 0.0F);
           paramWorld.a(localEntitySkeleton);
           localEntitySkeleton.e(paramEntityLiving);
    }
    translation:

    Randomly every 1 time out of 100:
    make a new skeleton
    put it in the same place as the spider
    add skeleton to the world
    attach skeleton to spider
    end

    The first 3 bits inside the if statement you can do with bukkit classes, so just use them for that. You just need the attachment function. That Entity.e method just calls setPassengerOf so...

    Use the following:

    Code:
    ((CraftEntity)theSkeleton).getHandle().setPassengerOf(((CraftEntity)theSpider).getHandle())
    As far as I can tell, there's no reason why it has to be spiders and skeletons either. You could have creepers riding cows if you wanted to. Let us know how you get on.
     
  4. Offline

    KaBob

    Ah yes, it turns out I had disabled spawn-monsters in a failed attempt to remove the ghasts during testing. I feel silly, but it working in the nether confused me =p
    As for monster, back with hmod I was able to do "/spawnmob monster" which was just an aggressive player. I'm aware of the giant/slime glitches but I do want them =p Luckily they added slime today, so now I just have to wait on giant and monster if it actually exists.
    Thank you for the passenger code =D I thought I had seen set passenger somewhere but when I looked I couldn't find it anywhere.
    Anyway, I got it spawning mobs even though it still refuses to spawn ghasts and slimes. Other than that, I can spawn everything else and set passenger for everything that works. I even made my character ride a creeper (it didnt end well... =p).
     
  5. Offline

    darknesschaos

    I want that code now. I soooo want cows mounted with skeles!
     
  6. Offline

    Edward Hand

    Screenies plox! ^_^
     
  7. Offline

    KaBob

    Example riding code:
    m1=event.getEntity().getWorld().spawnCreature(event.getLocation(),CreatureType.PIG);
    m2=event.getEntity().getWorld().spawnCreature(event.getLocation(),CreatureType.SKELETON);
    ((CraftEntity)m2).getHandle().setPassengerOf(((CraftEntity)m1).getHandle());

    You can replace either m1 or m2 with a player in the final line, theoretically you might be able to ride other players but I haven't tried that.

    I'm having another issue now though, I want to make it so some natural spawned mobs are replaced with pigzombies but I don't know how to tell if its a natural spawn or one generated by /spawnmob. Is there some way to tell through the creaturespawn event?
     
  8. Offline

    Edward Hand

    The spawnCreature function returns a reference to the creature that gets spawned. If you keep track of all of the creatures spawned artificially, you can check whether individual mobs are natural or not.
     
  9. Offline

    KaBob

    I did some digging and found a solution! =D
    Throwable t =new Throwable();
    StackTraceElement[] elements = t.getStackTrace();
    System.out.println(elements[5].toString());
    Put that in the creature spawn event and it will give different text depending on if its a natural spawn or an artificial one.
    Anyway, does anybody know why slimes and ghasts cant spawn? Or a way to spawn giants?
     
Thread Status:
Not open for further replies.

Share This Page