[KJS7]The attribute effects granted by mob_effect require multiple applications to activate.
zChenX1 opened this issue · 7 comments
Minecraft Version
1.21.1
KubeJS Version
2101.7.1-build.181
Rhino Version
2101.2.7-build.74
Architectury Version
No install
Forge/Fabric Version
NeoForge 21.1.141
Describe your issue
### This bug reproduces every time the game is restarted, and I have not yet found a solution.
1.Register a mob_effect_register.js in the startup_scripts folder. In this case, I am using an effect that adds armor value.
2.Use the /effect give command to apply this effect.
3.Check your armor value with /attribute @s minecraft:generic.armor get. If the value remains 0 during the effect's duration, it means the effect is not working. Reapply the effect to yourself and check the armor value again to confirm it takes effect.
Code mob_effect_register.js:
StartupEvents.registry('mob_effect',event=> {
event.create('iron_skin')
.beneficial()
.color('#d1bcad')
.modifyAttribute('minecraft:generic.armor','kubejs:iron_skin',8,'add_value')
})
Code registry potion_bottle
let $MobEffectInstance = Java.loadClass('net.minecraft.world.effect.MobEffectInstance')
StartupEvents.registry('potion',event => {
event.create('iron_skin')
.addEffect(new $MobEffectInstance('kubejs:iron_skin',3600,0))
})
PS:This bug can also be identified by observing the tooltips. If the corresponding potion bottle does not display "When Applied: [Attribute]", it means the modification to the armor value has not taken effect.
https://github.com/user-attachments/assets/949005c4-3e96-4183-a215-9788aa6414d5
Crash report/logs
No response
I can confirm this is definitely an issue and I am really surprised it hasn't been addressed yet, since it has been 4.5 months since this issue was opened with no responses.
I have spent several hours trying to figure out a solution and while it's not the solution, it's a workaround that worked for me.
StartupEvents.registry('mob_effect', event => {
event.create('adrenaline_rush').beneficial()
.modifyAttribute('minecraft:generic.movement_speed', '9a17976b-33d4-41ca-8106-41e58fd3517f', 0.2, 'add_multiplied_base')
.modifyAttribute('minecraft:generic.attack_speed', '28cf2213-74f9-4d97-90c7-adf79282d285', 0.2, 'add_multiplied_base')
.modifyAttribute('minecraft:player.block_break_speed', 'a3af281d-c3f8-4e83-aec9-1e395e1fcd34', 0.2, 'add_multiplied_base')
.color(Color.RED)
})This works every time but what's strange is if I:
- Tab/indent every modifier under
event.createonce or - Have
.beneficial()anywhere belowevent.createor - Have everything on one line
...it doesn't work
Indents shouldn't affect how the code is executed, except it does. The examples provided on the KubeJS Wiki don't work either.
I spoke to SpicyMayo about this on the Discord server in a thread and we've both come to the conclusion it's a problem out of our control.
I can also verify that this issue exists, but unfortunately the workaround posted above does not seem to help.
Fixed on latest release of KubeJS Tweaks
StartupEvents.registry('mob_effect',event=> {
event.create('iron_skin')
.beneficial()
.color('#d1bcad')
.modifyAttribute('minecraft:generic.armor','kubejs:iron_skin',8,'add_value')
})
// You don't need to load class MobEffectInstance
StartupEvents.registry('potion',event => {
event.create('iron_skin')
.effect('kubejs:iron_skin',3600,0)
})You need to implement the following function at MobEffectBuilder class
@Override
public MobEffect createObject() {
return Util.make(new BasicMobEffect(this), effect -> effect.applyAttributeModifications()); // this method is private tho
}@pietro-lopes
I've installed KubeJS Tweaks (kubejstweaks-0.0.8-beta.jar) however the issue is still present when using your mob_effect example. Is there something else that I need to do?
StartupEvents.registry('mob_effect',event=> {
event.create('iron_skin')
.beneficial()
.color('#d1bcad')
.modifyAttribute('minecraft:generic.armor','kubejs:iron_skin',8,'add_value')
})Describe the exact steps you are doing to test
my tests were involving potions
Managed to reproduce it, please test with this version KubeJS Tweaks
Managed to reproduce it, please test with this version KubeJS Tweaks
Sorry for the late reply. At first glance the new version seems to have fixed the issue. Thanks!