#Stacking effects
19 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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 => {
})
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.
declaration: package: net.minecraftforge.event.entity.living, class: PotionEvent, class: PotionAddedEvent
Oh shoot thats 1.16
declaration: package: net.minecraftforge.event.entity.living, class: MobEffectEvent, class: Added
Just any effects to be stackable, instead of resetting their timers once the effect is applied again through any means.
(or only through specific events, if no such thing is possible)
[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)
}
})
})
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
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.
just make sure if you use prunos example to change the first line to 1.19 like so js ItemEvents.foodEaten(event => { or js ItemEvents.foodEaten("minecraft:rotten_flesh", event => { if you just wanted rotten flesh
What about effects from potions? I mean, if I were to target that specifically.