[Possible NMS] Disable Sun damage to mobs with Helmet?

Discussion in 'Plugin Development' started by valon750, Sep 1, 2014.

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

    valon750

    Whilst working on NMS, spawning custom entities and whatnot, I found out about a feature which was apparently added in 1.7, that being the durability loss to helmets, being worn by mobs whilst in direct sunlight.

    Of course if I'm looking to spawn mobs with armour, I'd like for them to keep said armour, however the restrictSun goal finder doesn't seem to be what I'm looking for, and .fireproof = true simply does as it says, without considering the durability loss.

    It's very possible (and most likely the case) that I'm missing the smallest little attribute, however I've not been able to come across it yet.

    So if anyone happens to know a solution (Perhaps there's an event called?), it'd be excellent if you could share it.
     
  2. Offline

    TheMintyMate

    Maybe you could instead do something like this:
    Code:
    @EventHandler
    public void entityonfire(EntityCombustEvent event){
    if (event.getEntity() instanceof /*mob*/){
    event.setCancelled(true);
    }
    }
    
    Hope this helped,
    - Minty
     
  3. Offline

    valon750

    TheMintyMate

    I was not aware of such an event, so this has helped a lot :)

    It's so strange as the fire tick is literally... a tick, I would of imagined I could setMaxFireTicks, however when creating the entity, the closest was setMaxAirTicks :/
     
    TheMintyMate likes this.
  4. Offline

    TheMintyMate

    Yeah :/ Well, I'm glad I could help :)

    - Minty
     
  5. Offline

    valon750

    TheMintyMate

    Who's an idiot? *points to self* this guy....!

    setMaxFireTicks isn't a thing, maxFireTicks however is a very real thing that should of come to mind.

    Edit: However, their helmets continue to lose durability, regardless of the change. -.-
     
  6. Offline

    xTigerRebornx

    TheMintyMate likes this.
  7. Offline

    valon750

    xTigerRebornx

    Would I be right in assuming I can simply override this method, removing the particular block regarding the casting of the helmet, then the check for if it's invincible?

    The ItemStack doesn't seem to be referenced anywhere else, so I believe it's a safe bet, however I'm just now heading off for the night, so won't be able to test until the morning :)
     
  8. Offline

    xTigerRebornx

    valon750 https://github.com/Bukkit/CraftBukk...a/net/minecraft/server/EntityZombie.java#L129
    Reference for ItemStack
    And no, you don't need to override anything
    https://github.com/Bukkit/CraftBukk...java/net/minecraft/server/ItemStack.java#L231
    Simply need to make that last part true, which means adding the boolean in the NMS ItemStack

    Something like:
    Code:
    getHandle() of Zombie
    get NMS ItemStack returned by getEquipment(4)
    modify getTag() of NMS ItemStack to be unbreakable
    ? - set equipment back (not sure if needed, shouldn't be)
     
  9. Offline

    valon750

    xTigerRebornx

    Conclusion, t'was simple as this, good sir.


    helmetFinal.tag.setBoolean("Unbreakable", true);

    Thanks for shining a light on the subject, much appreciated :)
     
  10. Offline

    ImaTimelord7

    @valon750 I have the exact same problem that you had, however the links in this chat are broken because of the DMCA takedown.. so I have no idea how to fix it, you said to use:
    but I am not sure where to put that, I tried this: (Its on the third line)
    Code:
        public ItemStack Helmet() {
            ItemStack Item = new ItemStack(Material.LEATHER_HELMET, 1);
            Item.tag.setBoolean("Unbreakable", true);
            Item.setDurability((short)-1);
            LeatherArmorMeta lam = (LeatherArmorMeta) Item.getItemMeta();
            lam.setColor(Color.BLUE);
            Item.setItemMeta(lam);
            ItemMeta meta = Item.getItemMeta();
            meta.setDisplayName(ChatColor.BLUE + "Helmet");
            ArrayList<String> lore = new ArrayList<String>();
            lore.add(ChatColor.DARK_PURPLE + "Tell an admin you have this item.");
            meta.setLore(lore);
            Item.setItemMeta(meta);
            return Item;}
    I obviously changed helmetFinal to Item was I supposed to do this?
    Otherwise where do I put it? Thanks in advance.
     
  11. Offline

    valon750

    @ImaTimelord7

    I'm currently unable to get to my computer to bring up the class file I used, however if you're still struggling in a few hours, I'll be able to give you the source you need :)

    Edit: looking back at your post, it sounds like you haven't actually tried that method. From memory, I added the unbreakable tag quite close to the end, before returning the ItsmStack, on the off chance that it was overridden for whatever reason.
     
  12. Offline

    ImaTimelord7

    @valon750 Thanks for getting back to me, I have now tried adding it to the end like:
    Code:
    meta.tag.setBoolean("Unbreakable", true);
            return Item;}
    But it still doesn't work.

    And I think it might be a good idea to tell you that the error is on .tag saying tag cannot be resolved or is not a field

    Thanks in advance.

    EDIT: In the code it has meta. and in my previous post it uses Item. I have tried both of these, and both return the same error.
     
  13. Offline

    Funergy

  14. Offline

    ImaTimelord7

    @valon750 Hey did you ever get your computer to work? Still struggling with that code ;\
    Thanks.
     
  15. Offline

    Funergy

Thread Status:
Not open for further replies.

Share This Page