#How to double entity base health?

42 messages · Page 1 of 1 (latest)

dense arch
#

Looking to get a list of all living entities so I can double their health but cant find a way to get the list of those entities

brave hedgeBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

dense arch
#

How to double entity base health?

#

okay got the list using alembic and a little ai help to clean it up

#

now I dont really know how to get base hp of a mod so I can double it

rain relic
#

entity.maxHealth *= 2 in common cases

#

are you using entityjs

dense arch
#

Ye

#

I want to double their base max health

#

I had a script to double it on spawn but that had a weird interactions sometimes

rain relic
#
EntityJSEvents.attributes(e => {
    e.modify('minecraft:zombie', attribute => {
        const default_health = attribute.defaultValues.get('minecraft:generic.max_health');
        attribute.add('minecraft:generic.max_health', default_health*2);
  })
})

i guess

dense arch
#

[15:00:15] [ERROR] ! entities.js#4: Error in 'EntityJSEvents.attributes': TypeError: Cannot call method "get" of undefined

#

Weird

rain relic
dense arch
rain relic
#
EntityJSEvents.attributes(e => {
    e.getAttributes('minecraft:zombie').get('minecraft:generic.max_health').defaultValue
})
dense arch
#

oh yeah I had no idea how to filter for max health thank you!

#

there is another issue tho

#
1) entities.js#3: Error in 'EntityJSEvents.attributes': Cannot convert minecraft:generic.max_health to java.lang.Integer```
#

did it output the name of the attribute instead of the value?

#
EntityJSEvents.attributes(e => {
    const default_health = e.getAttributes('minecraft:zombie').get('minecraft:generic.max_health').defaultValue
    e.modify('minecraft:zombie', attribute => {
       
        attribute.add('minecraft:generic.max_health', default_health*2);
  })
})
rain relic
#
e.getAttributes('minecraft:zombie').filter(a => a.descriptionId == 'minecraft:generic.max_health').defaultValue
dense arch
#

lmao this set every zombie to one health

#

how did that happend

#
EntityJSEvents.attributes(e => {
    let default_health = e.getAttributes('minecraft:zombie').filter(a => a.descriptionId == 'minecraft:generic.max_health').defaultValue
    console.log("debuging"+default_health)
    e.modify('minecraft:zombie', attribute => {
        attribute.add('minecraft:generic.max_health', default_health*2);
    })
})
#

[18:18:17] [Render thread/INFO]: entities.js#4: debugingundefined

#

seems like it still not a number lol

mint wharf
#

@dense arch something like this js EntityJSEvents.attributes(event => { event.getAllTypes().forEach(entity => { event.modify(entity, a => { event.getAttributes(entity).forEach(attribute => { if (attribute.descriptionId == "attribute.name.generic.max_health") { a.add(attribute, attribute.defaultValue * 2) } }) }) }) })

#

should iterate over all entities which have health

dense arch
#

is it possible that it quadruples animal health because there is also a baby version of them?

#

weirdly zombies do have 53 hp but maybe its some mode interaction

mint wharf
#

the calculations should be after their base attributes to babies

#

the baby health is calculated based off the base attributes registered on startup

mint wharf
#

though i think thats only for horses ect

dense arch
#

okay thats no big deal gonna check if this:

EntityJSEvents.attributes(event => {
    event.getAllTypes().forEach(entity => {
        if(!entity.isPlayer()){
            event.modify(entity, a => {
                event.getAttributes(entity).forEach(attribute => {
                    if (attribute.descriptionId == "attribute.name.generic.max_health") {
                        a.add(attribute, attribute.defaultValue * 2)
                    }
                })
            })
        }})      
})

Works for excluding a player

#

well it does not

#

how else could I do it?

mint wharf
#

you want something like this js let EntityTypes = Java.loadClass("net.minecraft.world.entity.EntityType") EntityJSEvents.attributes(event => { event.getAllTypes().forEach(entity => { event.modify(entity, a => { if (entity == EntityTypes.PLAYER) return event.getAttributes(entity).forEach(attribute => { if (attribute.descriptionId == "attribute.name.generic.max_health") { a.add(attribute, attribute.defaultValue * 2) } }) }) }) })

dense arch
#

works perfectly! Thank you so much ❤️