Spawn Entities

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

  1. Offline

    CompuIves

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Is it already possible to spawn entities? I searched for it, but didn't find anything :S.
  2. Offline

    eisental

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    CompuIves

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Ok, thanks for the reaction. Will spawning living entities be possible in the future?
  4. Offline

    MadMichi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  5. Offline

    CompuIves

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I asked the maker of BukkitMon how he did that, and this was his reaction:
  6. Offline

    NathanWolf

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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:
    EntityLiving e = null;
    CraftPlayer craftPlayer = (CraftPlayer)player;
    CraftWorld craftWorld = (CraftWorld)craftPlayer.getWorld();
    World world = craftWorld.getHandle();
    e = new EntitySheep(world);
    e.getBukkitEntity().teleportTo(location);
    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

    MadMichi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    CompuIves

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Wow! That's great to see! Thank you for this example code :D.
  9. Offline

    NathanWolf

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    MadMichi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I would love to contribute to bukkit directly, but i'm so sure my programming style would cause them headaches ^^
  11. Offline

    NathanWolf

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    :) 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

    GDorn

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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:
                EntityLiving e = null;
                CraftPlayer craftPlayer = (CraftPlayer)player;
                CraftWorld craftWorld = (CraftWorld)craftPlayer.getWorld();
                net.minecraft.server.World mworld = (net.minecraft.server.World)(craftWorld.getHandle());
                e = new EntitySheep(mworld);
                e.getBukkitEntity().teleportTo(loc);
                mworld.a(e);
    
  13. Offline

    oliverw92

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I don't know about anyone else - but i have found that if you turn mobs off in server.properties, 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

    spoonikle

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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:
    EntityLiving e = null
    CraftPlayer craftPlayer = (CraftPlayer)player;
    CraftWorld craftWorld = (CraftWorld)craftPlayer.getWorld();
    World world = craftWorld.getHandle();
    e = new EntitySquid(world);
    e.getBukkitEntity().teleportTo(player.getLocation());
    world.a(e);
    how could i add to the location data to move it 1 block behind the player?
  15. Offline

    Edward Hand

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code:
    e.getBukkitEntity().teleportTo(location);
    Is the key line for doing that. Just replace 'location' with 'craftPlayer.getLocation()';
  16. Offline

    spoonikle

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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. Offline

    NathanWolf

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Actually, you should update Bukkit!

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

    See World.spawnCreature, and CreatureType.
  18. Offline

    spoonikle

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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?

Share This Page