#Specific item in main hand gives potion effect

22 messages · Page 1 of 1 (latest)

rich edge
#

I'm trying to make an item that gives the Haste 2 effect while a specific item is being held in the main hand. I can't seem to figure it out.

Help would be very appreciated!

burnt ravineBOT
#

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

light tuskBOT
#

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!

light tuskBOT
#

[➤](#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)
            }
        }
    }
});
rich edge
#

this doesn't seem to have helped unfortunately

viral jackal
#
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?

rich edge
#

id say only the age part ig?

#

as for this script ill give it a shot

viral jackal
#

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)

rich edge
#

mhm

#

so basically, every 20 ticks it checks the main hand and applies the effect if it is in the hand

viral jackal
#

yup

rich edge
#

ah, gotchu

#

thanks a lot

viral jackal
#

or it would be laggy

rich edge
#

it would probably be awful with 400+ mods too