Spawn Entities

Discussion in 'Plugin Development' started by CompuIves, Jan 22, 2011.

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


    Is it already possible to spawn entities? I searched for it, but didn't find anything :S.
  2. Offline


    You can use World.spawnArrow / World.spawnBoat / World.spawnMinecart
    which are also Entities but you're probably talking about living entities, which doesn't seem to be possible.
  3. Offline


    Ok, thanks for the reaction. Will spawning living entities be possible in the future?
  4. Offline


  5. Offline


    I asked the maker of BukkitMon how he did that, and this was his reaction:
  6. There is no way to do it in the Bukkit API (yet), but if you're not shy about digging into CraftBukkit (and minecraft-server itself), you can. Check out the "familiar" spell in my spells plugin- here's a snippet:

    Code (Text):
    1. EntityLiving e = null;
    2. CraftPlayer craftPlayer = (CraftPlayer)player;
    3. CraftWorld craftWorld = (CraftWorld)craftPlayer.getWorld();
    4. World world = craftWorld.getHandle();
    5. e = new EntitySheep(world);
    6. e.getBukkitEntity().teleportTo(location);
    7. world.a(e);
    That last bit is really the only missing part from the API- it's (I'm assuming) the Minecraft world command that adds an entity to the world.
  7. Offline


    Awesome! Thank you for these informations :D
    Do i have to include the craftbukkit.jar to use these methods?

    [EDIT] Found it out myself ;)
    Thanks again!
  8. Offline


    Wow! That's great to see! Thank you for this example code :D.
  9. Glad I could help!

    You seem to have figured it out, but yes you have to link to CraftBukkit.jar to do this. And maybe minecraft_server.jar, too?
    --- merged: Jan 24, 2011 1:31 AM ---
    And, of course, the disclaimer here is the usual "this isn't the Bukkit way to do it, it means your plugin is now tied to CraftBukkit", etc. Hopefully they'll add a spawn() function to World that does this soon.

    If I'm feeling industrious, I'll add it and request a pull.
  10. Offline


    I would love to contribute to bukkit directly, but i'm so sure my programming style would cause them headaches ^^
  11. :) Something like this, in theory, would be really simple- just a quick add to World and CraftWorld with that one little bit of code.
  12. Offline


    The multiworld code has changed this snippet very slightly, as craftWorld.getHandle() returns a WorldServer object, not a World object.

    This works for me:
    Code (Text):
    2.             EntityLiving e = null;
    3.             CraftPlayer craftPlayer = (CraftPlayer)player;
    4.             CraftWorld craftWorld = (CraftWorld)craftPlayer.getWorld();
    5.             net.minecraft.server.World mworld = (net.minecraft.server.World)(craftWorld.getHandle());
    6.             e = new EntitySheep(mworld);
    7.             e.getBukkitEntity().teleportTo(loc);
    8.             mworld.a(e);
  13. Offline


    I don't know about anyone else - but i have found that if you turn mobs off in, the above methods of spawning mobs no longer work since the minecraft server deletes it straight after it spawns. Anyone got any ideas on how to get around this?
  14. Offline


    this will allow me to spawn an living entity? how would i make the entity spawn on the player attached to the event that calls it, or better yet, behind the player?

    would this make a squid spawn on the players location?
    Code (Text):
    1. EntityLiving e = null
    2. CraftPlayer craftPlayer = (CraftPlayer)player;
    3. CraftWorld craftWorld = (CraftWorld)craftPlayer.getWorld();
    4. World world = craftWorld.getHandle();
    5. e = new EntitySquid(world);
    6. e.getBukkitEntity().teleportTo(player.getLocation());
    7. world.a(e);
    how could i add to the location data to move it 1 block behind the player?
  15. Offline

    Edward Hand

    Code (Text):
    1. e.getBukkitEntity().teleportTo(location);
    Is the key line for doing that. Just replace 'location' with 'craftPlayer.getLocation()';
  16. Offline


    so event.getPlayer().getLocation() wont work?

    if all goes well, the plug-in 'BigCatch' will have a 3.3333% chance of catching a squid, and 0.3333 chance of snagging a skeleton or zombie.
  17. Actually, you should update Bukkit!

    My original advice is outdated- it's in the API now ;)

    See World.spawnCreature, and CreatureType.
  18. Offline


    how do i specify the location?

    how new is this? a few days? ill be sure to update my API, but wouldn't that make my plug-in not work for older craft Bukkit builds or no?
Thread Status:
Not open for further replies.

Share This Page