How to spawn a wolf that can not die?

Discussion in 'Plugin Development' started by Banjer_HD, Nov 17, 2015.

Thread Status:
Not open for further replies.
  1. Hello,
    How to spawn a wolf that can't die?
    This is what i have so far:
    Code:
    Wolf w = (Wolf) targetP.getWorld().spawnEntity(targetP.getLocation(), EntityType.WOLF);
    
    Thank you in advance!
     
  2. Offline

    Zombie_Striker

    @Banjer_HD
    You can set it's heal extremely high, or you can store it somewhere (give it a metadata tag or put it into List or Config) and have an event that checks if the entity was damaged. If it was damaged, you would cancel it.
     
  3. How did pet plugins like EchoPet this?
     
  4. Offline

    FabeGabeMC

  5. Offline

    Scimiguy

    @Zombie_Striker
    It's actually more effective to just give the wolf Resistance 5 for a sufficiently high duration @Banjer_HD
     
  6. Offline

    Koobaczech

    This is super simple! OPTION 1 set no damage ticks real high. OPTION 2 Put wolf in a hash map and check in a listener for damage to it and cancel it. FYI wolf won't survive server resets, unloading of chunks and automatic entity killing. Again check for the entity and cancel necessary events!
    Code:
    /* Option 1 */
    Wolf Wolf = (Wolf) p.getWorld().spawnEntity(l, EntityType.WOLF);
    Wolf.setNoDamageTicks(999999);
    
    /* Option 2 */
    //Make class that implements listener
    //Create wolf
    Wolf Wolf = (Wolf) p.getWorld().spawnEntity(l, EntityType.WOLF);
    //put entity in a hash map!!
    
    //Handle damage event
    @EventHandler(priority = EventPriority.Whatever)
    public void Entitydamageev(EntityDamageEvent e) {
            if (hashmap.containsValue(e.getEntity()))
                e.setCancelled(true);
    }
    
     
  7. Offline

    teej107

    I like that option. If you set the no damage ticks to the integer's max value, it would last for 1,242 full days.
     
  8. @Koobaczech why would you use a map if you could simply put its uuid in a set? also to save it from chunkunload i think there should be a method called smth like setRemoveOnFarAway(false); as far as i remember it will be respawned with the same uuid when the chunk reloads. And for a serverrestart or a pluginreload you could save its location to the config and on reloading you could search for a wolf near by this location and if you find it go with that then. not 100% save that you will get the same wolf this way but 80% should be in i guess. for preventing damage i d store the uuid of the mob in a hashset and listen for an entitydamagevent and cancel it, if the entitys uuid is contained in the set.

    this way only moment the wolf can die is when the plugin is disabled. @teej107 if you set the no damage ticks it will survive ages, even when your plugin is turned off. except for you reset them when you disable the plugin of course. but this is some extra work i wouldnt care about since you d have to run some cycling process which pushes the no damage ticks up again and resets it when the plugin gets disabled.
     
  9. Offline

    CoolDude53

    @Shmobi entity UUIDs are not unique within the same entitytype.
     
  10. @CoolDude53 my mistake then, thanks for correcting me. then either store the wolf or its hashcode in a set or add some sort of an identificator to it like a costum displayname or smth :)
     
Thread Status:
Not open for further replies.

Share This Page