Solved Not sure if this is a bug or I'm just being stupid

Discussion in 'Plugin Development' started by YoFuzzy3, Apr 26, 2013.

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


    I don't often come here but this is just annoying me. I'd rather not share all my code so basically for my SuperCraftBros plugin I want to make throwable pokeballs, got all that working but they don't want to spawn the mob. I'm trying to do it neatly by getting the id of the entity from the item, as the spawn egg's damage value is also the same id as the spawnable entity. I've put in debug and it's definitely getting the right entity id's.

    1. world.spawnEntity(pokeball.getLocation(), EntityType.fromId(itemInHand.getDurability()));

    Any help be appreciated, thanks.
  2. Offline


    world.spawnEntity(pokeball.getLocation(), itemInHand.getType());
    getType() returns the EntityType of the item. Did you even try to search the docs?
  3. Offline


    getType() on an ItemStack returns a Material, you need an EntityType for spawnEntity().

    I also tried the following and it doesn't work so I have no idea what's going on.
    1. SpawnEgg egg = (SpawnEgg) itemInHand.getData();
    2. world.spawnEntity(pokeball.getLocation(), egg.getSpawnedType());

    Just had a look at CraftBukkit's source code and it turns out using the spawnEntity() function it triggers it with SpawnReason.CUSTOM. I had another event cancelling all SpawnReason's but SpawnReason.SPAWNER_EGG. So I changed that event and it works now. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page