So I've checked https://discord.com/channels/303440391124942858/1160209874878218370 , and improved my script.
But there's still a lingering question:
Is single listener always better than multiple listeners?
Here are three cases:
Case1: single listener with args and multiple ifs
const rc0 = {'diamond': '1', 'emerald': '2'}
const rc1 = ['gold_ingot', 'iron_ingot']
const rc_flat = Array.from(new Set([].concat(Object.keys(rc0), rc1, 'coal')));
ItemEvents.rightClicked(rc_flat, e => {
if(rc0[e.item.id]) {
//do something
};
if(rc1.contains(e.item.id)) {
//do something
};
});
Case2: single listener without args, but with multiple ifs
ItemEvents.rightClicked(e => {
if(rc0[e.item.id]) {
//do something
};
if(rc1.contains(e.item.id)) {
//do something
};
});
Case3: multiple listener with args and multiple ifs
ItemEvents.rightClicked(rc1, e => {
//do something
});
ItemEvents.rightClicked(Object.keys(rc0), e => {
//do something
});
Obviously case1 is faster than case2, but what about case1 and case2 compares to case3?