#(cyrulean) the 'player click_type clicks item in inventory' event is not very fun to work with

83 messages · Page 1 of 1 (latest)

lean garden
#

i'm trying to lock a specific item in a specific slot, so that it cannot be moved.
i was told that this event is the right way to do so, but the way the context is provided makes it near impossible for me to check for every way you can move the item around.
you can click on the item
you can hover on the item and use F, or use a hotbar key (which you need to check for seperately)
you can also hover on a completely different slot and then use F or a hotbar key that corresponds to where the item is, and there's no context for old_item or old_slot or anything, so for the swapping items, i have to check that the click type was SWAP, and then manually check both the offhand slot and whatever slot was hovered. or I have to check that a hotbar key was pressed, and then manually check the slot at the hotbar key, and the actual slot being clicked. And if i'm hovering over the offhand slot, and then I press the hotbar key, that's a whole different thing.

am I doing this wrong?

native hedgeBOT
#

(cyrulean) the 'player click_type clicks item in inventory' event is not very fun to work with

#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
You can block this bot if you don't want to see these messages, I won't mind.
<@&525394568410038282>

golden tinsel
#

!e clicks in inventory

tacit oracleBOT
# golden tinsel !e clicks in inventory
Group

Player

Event Lines

player (<click_type>) clicks (<item>) in <inventory>

Switches

with:<item> to only process the event if a specified cursor item was used.
in_area:<area> replaces the default 'in:<area>' for this event.
action:<action> to only process the event if a specified action occurred.
slot:<slot> to only process the event if a specified slot or slot_type was clicked. For slot input options, see !language Slot Inputs.

Triggers

when a player clicks in an inventory. Note that you likely will also want to listen to !event player drags in inventory.

Has Player

Always. - this adds switches flagged:<flag name> + permission:<node>, in addition to the <player> link.

Context

<context.item> returns the ItemTag the player has clicked on.
<context.inventory> returns the InventoryTag (the 'top' inventory, regardless of which slot was clicked).
<context.clicked_inventory> returns the InventoryTag that was clicked in.
<context.cursor_item> returns the item the Player is clicking with.
<context.click> returns an ElementTag with the name of the click type. Click type list: <@link url...
<context.slot_type> returns an ElementTag with the name of the slot type that was clicked. Slot ty...
<context.slot> returns an ElementTag with the number of the slot that was clicked.
<context.raw_slot> returns an ElementTag with the raw number of the slot that was clicked.
<context.is_shift_click> returns true if 'shift' was used while clicking.
<context.action> returns the inventory_action. See <@link language Inventory Actions>.
... and 1 more.

Determine

ItemTag to set the current item for the event.

Has Known Location

True - this adds switches in:<area> + location_flagged:<flag name>.

Cancellable

True - this adds <context.cancelled> and determines cancelled + cancelled:false.

golden tinsel
#

You can use the generic event here and the slot switch to lock the item in place. That means:

on player clicks in inventory slot:2:
- determine cancelled

for swapping items, can cancel the swaps item event:

on player swaps item offhand:your_item_here:
- determine cancelled
#

You might need some more logic, depending on your use case.

lean garden
#

the 2 blocks on either side of it will spread and dissapear at the same time
this is exactly what I mean, the 2 events you show does not cover all the possibilities.
The first event does not cover if you hover over the 3rd slot and then press 2 on your hotbar

#

The player swaps item also does not cover typing F while you have your inventory open

lone flint
#

that does anything? o-0

#

did not know that

lean garden
#

it's near impossible to cover all of these options without a lot of janky logic and edge case covering because of the way context is provided in this event

lone flint
#

!e drags in inventory

tacit oracleBOT
# lone flint !e drags in inventory
Group

Player

Event Lines

player drags in inventory player drags (<item>) (in <inventory>)

Switches

in_area:<area> replaces the default 'in:<area>' for this event.
drag_type:<type> to only run the event if the given drag type (SINGLE or EVEN) was used.

Triggers

when a player drags in an inventory (that is, clicks and then holds the mouse button down while moving the mouse across multiple slots).

Has Player

Always. - this adds switches flagged:<flag name> + permission:<node>, in addition to the <player> link.

Context

<context.item> returns the ItemTag the player has dragged.
<context.inventory> returns the InventoryTag (the 'top' inventory, regardless of which slot was clicked).
<context.clicked_inventory> returns the InventoryTag that was clicked in.
<context.slots> returns a ListTag of the slot numbers dragged through.
<context.raw_slots> returns a ListTag of the raw slot numbers dragged through.
<context.drag_type> returns either SINGLE or EVEN depending on whether the player used their left or right mouse button.

Has Known Location

True - this adds switches in:<area> + location_flagged:<flag name>.

Cancellable

True - this adds <context.cancelled> and determines cancelled + cancelled:false.

lone flint
#

^ this one is the number key one iirc?

#

you are right that it's super janky though

lean garden
#

this doesn't cover anything important because using hotbar / F keys don't trigger this event

#

the drag one

golden tinsel
#

clicks in inventory covers F and number keys

lean garden
#

yes but it isn't covered by slot:2

split gazelleBOT
lean garden
#

you have to manually check the context.click because the event does not provide context on what slot typing a hotbar key or the F key will change

lone flint
#

does <context.item> just return air in that case?

lean garden
#

yep

#

and the context.slot turns the slot you are hovering, there's no context about the slot that changes based on what key you press

lone flint
#

<context.hotbar_button> returns an ElementTag of the button pressed as a number, or 0 if no number button was pressed.
?

#

presumebly that's ^ the slot that's changing

#

am i misunderstanding

lean garden
#

yes you have to check for that

lone flint
#

I guess I don't know what you're asking for?

#

it's fairly easy to do, is there a change you're looking to see here?

#

you appear to already know how to accompish what you're looking for

golden tinsel
lean garden
#

it's basically "check the item at context.slot, and then check context.click to see whether it was pressing F or a hotbar key, if it's a hotbar key check the item at the slot the hotbar key corresponds to, if it's F, then check the item in the offhand slot

#

which means you have to do on player clicks in inventory and use a bunch of if statements

golden tinsel
lean garden
#

you can't just select the right event and cancel it

#

exactly!!

#

oh and not to mention you still have to check for on player swaps

lone flint
#

because slot: of course is checking for the slot that the action occured on

#

is this a feature request to make it also include the slot that the action affected?

lean garden
#

it's a feature request to improve the way switches and context is provided in the clicks in inventory event so it's easier to specify what you want to change

lone flint
#

if you can summarize the changes you want to see more specifically, i'll swap this thread to a feature request so the devs see it

lean garden
#

maybe something like context.affected_slots that gets every slot that changes when clicking, and then some like impacts: switch that as long as any change happens to the item that matches in there it will hit

willow currentBOT
#
Changed to Feature

Thread is now a Feature thread. This indicates a request for a new feature to the plugin, that both (A) does not already exist and (B) reasonably can be added. If you are unsure whether this applies, use </helpthread:1028674284870180883> to change back to a normal help thread.

lone flint
#

definitely was not clear to me what you were asking based on your original message

#

seemed like you didn't know how to check for those things

lean garden
#

got it

#

currently, the player clicks in inventory event is difficult to work with due to the way context and switches are provided

if you have
on player clicks dirt in inventory and cancel that, you can still move dirt around by using the hotbar keys
because slot: is checking for the slot that the action occured on

this makes selecting for the correct event to listen and cancel impossible, and requires many different checks and if statements inside of a global event to do what you want

if you want to lock an item in a slot, you need to check context.slot, the click_type and whether it is swap or hotbar key, then check what hotbar key was pressed, or check the offhand if the click type is swap

i propose refactoring context provision to show all items and slots affected.
i also propose making it possible to match all items or slots affected in the event name that aren't directly from context.item or .slot

golden tinsel
#

I mean technically all fyou need is an additional if that checks for the number key

#
        on player clicks in PLAYER:
        - if <context.slot> == 3:
            - determine cancelled
        - if <context.click> == number_key && <context.hotbar_button> == 3:
            - determine cancelled
#

for the inventory part

lone flint
#

no need for the first part of that second if

#

it just returns 0 if it's not a hotbar click

golden tinsel
#

smart inquisitor

#

so if <context.slot> == 3 || <context.hotbar_button == 3: then aye?

#

@lean garden ^

lean garden
#

the point is i don't want to read a global event to catch this

#

this also needs to work with items regardless of which slot it's in (including the offhand)

golden tinsel
#

even with switches you're listening to the InventoryClickEvent, denizen just won't fire the script queue if it won't matches the switches specified

midnight skiff
#

A big part of the reason that event / inventories in general are that way is because that's how Minecraft/Spigot does it

#

I.e. having on player clicks dirt fire for a player using the number keys on an empty slot to move dirt from their hotbar wouldn't make sense, as they aren't clicking dirt - they're clicking air which also moves a dirt

midnight skiff
#

I will also say, if this is something that's coming up in your scripts frequently, you can make yourselves a

#

!c customevent

tacit oracleBOT
# midnight skiff !c customevent
Group

core

Syntax

customevent [id:<id>] (context:<map>)

Short Description

Fires a custom world script event.

Description

Fires a custom world script event.

Input is an ID (the name of your custom event, choose a constant name to use), and an optional MapTag of context data.

Linked data (player, npc, ...) is automatically sent across to the event.

Use with !event custom event

midnight skiff
#

To fit your specific needs

#

Which is the nice thing about programming in general, even if what you specifically need isn't built-in, you can use existing features to make something that fits your needs and makes your other work simpler and easier

willow currentBOT
#
Changed to Help/Support

Thread is now a Help/Support thread. A helper will check your thread when available.

midnight skiff
#

And also

#

!e player inventory slot changes

tacit oracleBOT
# midnight skiff !e player inventory slot changes
Required Plugins or Platforms

Paper

Group

Paper

Event Lines

player inventory slot changes

Switches

from:<item> to only process the event if the previous item in the slot matches the specified item.
to:<item> to only process the event if the new item in the slot matches the specified item.
slot:<slot> to only process the event if a specific slot was clicked. For slot input options, see !language Slot Inputs.

Triggers

when the item in a slot of a player's inventory changes.
Note that this fires for every item in the player's inventory when they join.

Has Player

Always. - this adds switches flagged:<flag name> + permission:<node>, in addition to the <player> link.

Context

<context.new_item> returns an ItemTag of the new item in the slot.
<context.old_item> returns an ItemTag of the previous item in the slot.
<context.slot> returns an ElementTag(Number) of the slot that was changed.
<context.raw_slot> returns an ElementTag(Number) of the raw number of the slot that was changed.

Has Known Location

True - this adds switches in:<area> + location_flagged:<flag name>.

midnight skiff
#

This event is also a thing, although it isn't generally as useful since you can't easily cancel the entire thing

willow currentBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@lean garden