Solved Custom Mob Spawner Help

Discussion in 'Plugin Development' started by austinv11, May 6, 2014.

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

    austinv11

    I was wondering if there is a way I could set a mob spawner to spawn entities through entity ids. So, for example, I get the entity id of a dropped item, and set the spawner to spawn exact copies of said item.
     
  2. Offline

    garbagemule

    You can do it by EntityType (check CreatureSpawner). I'm not quite sure what you are trying to accomplish exactly. If you want to spawn different kinds of mobs based on dropped spawn eggs or something like that, you can just get the spawned type from the SpawnEgg, and then set it as the spawned type of the CreatureSpawner.

    If you want to spawn items instead of mobs, it might be a bit more involved. You may be able to do it by setting the spawned type to DROPPED_ITEM, but I'm not sure how you'd go about specifying the Material. Have a play around with it and report back with what you've tried :)
     
  3. Offline

    austinv11

    Yeah, I want to be able to spawn an entity inheriting all the attributes of a given entity through an entity id, not just for dropped items, there's no method made for this, but I was wondering if there's a way to do it through metadata or anything similar
     
  4. Offline

    Garris0n

    Just use EntityType, magic numbers are bad.
     
  5. Offline

    garbagemule

    Garris0n
    Did you read his last post? The entity ID he's talking about is not the magic numbers you're thinking of, it's an ID that uniquely identifies the exact entity, not e.g. an item ID.

    austinv11
    Have you tried seeing what happens if you set the spawner's type to DROPPED_ITEM? I honestly think your best bet is to fake it by setting the delay of the spawner to some high value (it looks a bit like there are enforced minimum and a maximum values in the server code, but I only skimmed it), and then starting a repeating task lower than that value, that constantly refreshes the delay (the delay seems to be "time left" until the next entity spawns), and then spawns the item you want by calling dropItemNaturally() on the World instance. That way, an actual entity will never spawn from the spawner, but from your code, and it allows you to spawn virtually anything you want. It's a bit more involved (as mentioned previously), but it'll get the job done.

    Happy hacking!
     
  6. Offline

    Garris0n

  7. Offline

    garbagemule

    Garris0n
    This class seems to have no Bukkit equivalent, so there is really no point in using it. My suggestion is not only more extensible and flexible, it's also much more reliable (no nms hacks).
     
  8. Offline

    austinv11

    I can try that out, however, I also want to be able to spawn other custom entities, like mobs with potion effects, etc
     
  9. Offline

    Garris0n

    I didn't say it had a Bukkit equivalent. I'm also not saying I have a problem with your answer, I'm just saying that is how you would actually do it in case somebody actually wants to make some sort of spawner "cloning" system or whatever. Your method is good for avoiding NMS, but if you actually want to use NMS (or actually want the spawner to be real for any reason, such as mapmaking) that is how you'd do it.
     
  10. Offline

    garbagemule

    I see no reason why that wouldn't be possible. It may involve a bit of "parsing" (grabbing the potion effects and equipment off of the mobs and storing them in a wrapper class), but it's perfectly doable.

    Heh, I didn't say you said it had an equivalent, and I didn't insinuate you having a problem with my answer :) As with anything, though, nms should be a last resort, and it probably would be in the case of map making, although the existing map editing tools will probably be of more use than manually walking around, spawning custom entities, and then storing them.
     
    Garris0n likes this.
Thread Status:
Not open for further replies.

Share This Page