Solved Get player who spawned Entity

Discussion in 'Plugin Development' started by comniemeer, Jul 31, 2014.

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

    comniemeer

    Hello!
    I want to find out who (which player) spawned an entity with a SPAWNER_EGG (SpawnReason).
    After that I want to add this mob a metadata.
    Can somebody help me? Thanks in advance!
     
  2. Offline

    iMurder

    Best bet is by checking PlayerInteract event, check if it's clicking a block, cancel, remove the item and spawn the mob accordingly. (then apply such metadata)
    I can't think of any other ways you'd be able to achieve this to be honest.
     
  3. Offline

    comniemeer

    Ok, I have done that already, but when i try to spawn them, in some cases they glitch in walls (when I right click on the sides of walls).
    Is there a code that shows how I can spawn them like with the "vanilla" behavior?
     
  4. Offline

    blablubbabc

    You could store the last interact event (always overwriting the previously stored event) in some variable, let the player spawn the mob like normal with the spawn egg and on creature spawn event with spawn reason spawn_egg assume that the currently stored interact event was the one involved.
     
  5. Offline

    comniemeer

    Ok, thank you for the reply, but I got it working :)
    Code:java
    1. Entity entity = player.getWorld().spawnEntity(event.getClickedBlock().getRelative(event.getBlockFace()).getLocation().add(0.5, 0, 0.5), entityType);
     
Thread Status:
Not open for further replies.

Share This Page