Solved change max health of mob

Discussion in 'Spigot Plugin Development' started by Lukinhasl157, Feb 1, 2020.

  1. Code (Java):
    @EventHandler
        public void blockBreak(BlockBreakEvent event) {
            if (event.getBlock().getType().equals(Material.MOSSY_COBBLESTONE)) {
                Block block = event.getBlock();
                block.getLocation().getWorld().strikeLightning(block.getLocation());
             
                PigZombie pigZombie = (PigZombie) block.getWorld().spawnEntity(block.getLocation(), EntityType.PIG_ZOMBIE);
             
                pigZombie.setMaxHealth(1024);
                pigZombie.setCustomName(ChatColor.GOLD + "PigZombie Boss ");
                pigZombie.setCustomNameVisible(true);
            }
        }
     
    #1 Lukinhasl157, Feb 1, 2020
    Last edited by a moderator: Feb 1, 2020
  2. md_5

    Administrator Developer

    What is your problem?

    Hint: You didn't call setHealth to update the mob's actual health
     
    • Agree Agree x 1
  3. Choco

    Moderator

    Another problem being that this is done with attributes in more recent versions of the API. Additionally, @OP, please use [CODE=java][/CODE] tags to insert code into a thread and make your thread more descriptive than just a block of code. Content to read in your actual thread will be significantly more useful.

    https://hub.spigotmc.org/javadocs/s...#getAttribute-org.bukkit.attribute.Attribute-
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/attribute/Attribute.html#GENERIC_MAX_HEALTH
    https://hub.spigotmc.org/javadocs/s...ifier-org.bukkit.attribute.AttributeModifier-
     
    • Agree Agree x 1
    • Winner Winner x 1
  4. what?
     
  5. is this giving an error? if so, go to spigot.yml to change the max health.

    Also, just as @md_5 said, you need to actually set the health. You're just only setting the max health instead of changing the actual health of the mob.
     
  6. you are a fucking genius
     
  7. yes, I realized this almost now when I was reviewing the code
     
  8. how to mark as solved?
     
  9. another question, is there a life limit on setMaxHealth?
     
  10. md_5

    Administrator Developer

    Yes it's either 1024 or 2048, controlled by a setting in spigot.yml
     
    • Agree Agree x 1
  11. thx
     
  12. Top right next to unwatch thread there's options where you can edit the title and uncheck the open box to close the thread as well