#Specific item in main hand gives potion effect
22 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
You sure you tried everything you possibly could to fix your issue? Perhaps not.
Make sure you have searched for issues similar to yours in #1047320998199955458 before posting. They might have the answer to your problem!
You sure you tried everything you possibly could to fix your issue? Perhaps not.
Make sure you have searched for issues similar to yours in #1047320998199955458 before posting. They might have the answer to your problem!
[➤](#1156581326351245373 message)
How do I get the main hand item of players with PlayerEvents.tick?
Btw i find that e.player.level.time does not work in 1.20
The following is my script for your reference
PlayerEvents.tick(e => {
if (e.player.stages.has('expert_locked')) {
if (e.player.level.time % 100 == 0) {
let heldItem = e.entity.getHeldItem(MAIN_HAND).id;
if (heldItem.hasTag('stage:expert_locked')) {
e.player.potionEffects.add('minecraft:slowness', 5, 255)
}
}
}
});
this doesn't seem to have helped unfortunately
PlayerEvents.tick(e => {
if(e.player.age % 20) return;
if(e.player.mainHandItem.id != 'modid:idk') return;
e.player.potionEffects.add('minecraft:speed', 20, 0, true, false);
})
not sure how much you know about kjs, need some explanation about this?
sure
the age means how long the player has been in this world, it increases every tick
and the % means dividing exactly.
so if we want to make the player tick event more performant, we want the check of e.player.mainHandItem.id lesser.
so the e.player.age % 20 here acts as a gate keeper, making the checks below execute once per 20 ticks
it equals if(event.player.age % 20 != 0)
mhm
so basically, every 20 ticks it checks the main hand and applies the effect if it is in the hand
yup
yeah, figured lol
it would probably be awful with 400+ mods too
