#Stacking effects

19 messages · Page 1 of 1 (latest)

slim swallow
#

I tried looking everywhere, but couldn't find anything on this matter.
Can you stack effect timers with KubeJS, instead of reseting the timer?
A good example would be getting hunger effect from rotten flesh. Instead of the effect timer resetting, how could I make it, so the timer would stack?

devout emberBOT
#

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

lusty steeple
#

You could use event.player.getActiveEffects() and then use that information combined with ItemEvents.foodEaten to apply hunger with the remaining duration + your extended duration```js
ItemEvents.foodEaten("minecraft:rotten_flesh", event => {

})

slim swallow
#

How could apply this to a more broader scene? For example to extend all effect durations, not just hunger from rotten flesh.
Or at least to not have to check for each and every possible sources of said effects, but rather the effects themselves. Otherwise the work would be just overwhelming.

coral crater
#

what are you planning?

#

like a "extend all current effects potion"?

lusty steeple
#

Oh shoot thats 1.16

slim swallow
pallid iris
#

im pretty sure theres an actual example of this

#

sec

sturdy coyoteBOT
#

[Quote ➤](#archived-example-scripts message) Script to extend effect durations from a food when eating it for multiple times, duration calculation can be limited to give a more balanced gameplay:

onEvent("item.food_eaten", event => {
    let foodProperties = event.item.item.foodProperties;
    foodProperties.effects.forEach(pair => {
        let effectInstance = pair.getFirst()
        let chance = pair.getSecond()

        if (Math.random() < chance) {
            let current = effectInstance.duration + event.player.potionEffects.getDuration(effectInstance.effect);
            event.player.potionEffects.add(effectInstance.effect, current, effectInstance.amplifier, effectInstance.ambient, effectInstance.visible)
        }
    })
})
lusty steeple
#

Startup Script:

ForgeEvents.onEvent('net.minecraftforge.event.entity.living.MobEffectEvent$Added', event => {
    let oldPotEffect = event.getOldEffectInstance()
    let potEffect = event.getEffectInstance()
    let entity = event.getEntity()
    console.log(oldPotEffect)
    console.log(potEffect)
    console.log(entity)
})

No idea if this works but it may give you some useful information about the effects that are being applied

slim swallow
#

Yeah I would have never figured these out my own lol.
I will have a look at all of these, see what I can make of them.

pallid iris
slim swallow
#

What about effects from potions? I mean, if I were to target that specifically.

pallid iris
#

hm

#

id assume itd be pretty similar though youd have to maybe use the forge event above