Solved Making hostile mobs passive (as in creative)

Discussion in 'Plugin Development' started by RAFA_GATO_FOFO, May 22, 2014.

Thread Status:
Not open for further replies.
  1. Hey guys,

    I was wondering if any of you knew how to make hostile mobs friendly/passive.

    I don't even know if there's a way to do that using a Bukkit method or if I need to use ProtocolLib (since I never used PLib before).

    I don't want to set the difficulty to peaceful because this would prevent mobs from spawning. I want them to spawn, but not be aggressive.

    Anyway if you've got an idea please post below. And refrain yourselves from posting "ermagerd u ask for spunfid, no code nub". None of my code is helpful to this matter.

    Thanks in advance.
     
  2. Offline

    xTigerRebornx

  3. xTigerRebornx Oh I must've missed that event when browsing the javadoc. I'll take a look and post results in a bit.

    EDIT:

    That event works fine for every mob except Spiders. They're the only ones still being aggressive.

    Here's what I've got:
    Code:java
    1. @EventHandler
    2. public void onEntityTarget(EntityTargetLivingEntityEvent event){
    3. if (event.getTarget() instanceof LivingEntity){
    4. event.setCancelled(true);
    5. }
    6. }
     
  4. Offline

    rsod

    RAFA_GATO_FOFO this will also prevent friendly mobs following you, like cows will not follow you wnen you holding wheat. Also it will disable mobs interaction between themselves.
    1) check if a target instanceof Player
    2) Check if entity that targeted player instanceof Monster (org.bukkit.Entity.Monster - all mobs that could attack a player)
     
  5. rsod
    Right, didn't think about right away but that still doesn't fix the spiders aggro...
    Show Spoiler
    Code:java
    1. @EventHandler
    2. public void onEntityTarget(EntityTargetLivingEntityEvent event){
    3. if (event.getTarget() instanceof Player){
    4. if (event.getEntity() instanceof Monster){
    5. event.setCancelled(true);
    6. return;
    7. }
    8. }
    9. }
     
  6. Offline

    rsod

  7. rsod
    Using the EntityTargetEvent works. Thanks for the help!
     
  8. Offline

    rsod

    Actually this bug is here for 2 years and still not fixed
     
Thread Status:
Not open for further replies.

Share This Page