#(JustinS) Prevent items from changing slots when inventory swapping

188 messages · Page 1 of 1 (latest)

cursive vapor
#

Whenever I swap between two inventories, all the items get organized from slot 1-the rest. If I have an item in slot 5 and an item in slot 9, they both end up in slot 1 and 2, respectively. How can I prevent this from happening? I don't see an option to keep their positions in the docs

hazy spruceBOT
#

(JustinS) Prevent items from changing slots when inventory swapping

hazy spruceBOT
#

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.

shy prairie
#

i.e if you set an inventory using a list, do like dirt|air|air|stone|air|stone

cursive vapor
#

Im swapping inventories though

#

not setting

#

let me send the script

#

I dont think its possible with swap

shy prairie
#
- if !<player.has_flag[force_inv_open]>:
  - ...
- else if <player.has_flag[force_inv_open]>:
  - ...

a more straightforward and concise approach would be that

- if <player.has_flag[force_inv_open]>:
  - ...
- else:
  - ...

(tho note the conditions are inverted, i.e. what is now in the else block would be switched to the if block)

cursive vapor
#

I can just keep the ! and change it to else so it doesnt get converted

shy prairie
#

- flag <player> force_inv_open:true you can easily replace with - flag <player> force_inv_open (when the flag is only toggled, never checked for a value, it's "cleaner")

#

(also true is the default value when setting a value-less flag)

cursive vapor
#

It didnt get highlighted in the editor so I thought that might not work

#

but good to know

shy prairie
#

- ratelimit <player> 0.05s
that's just the complicated version of - ratelimit <player> 1t

#

(ticks are valid durations in denizen)

cursive vapor
#

Ill keep forgetting how much 1 tick is lol

shy prairie
#

1/20th of a second

#

as in, 0.05s

cursive vapor
#

alr

shy prairie
#

it's also the "smallest relevant duration" in minecraft as it's the updating rate of the game

#

i.e. i'm not sure there is much things you can do at a sub-tick rate

#

take that with a grain of salt tho

cursive vapor
#

Right, so now... how can I fix my inventory

shy prairie
#

lmao

#

we're not done yet 😮‍💨

cursive vapor
#

oh boy...

shy prairie
#

on player right clicks * with:force_powers:

#

!e right clicks

candid muralBOT
# shy prairie !e right clicks
Group

Player

**WARNING**

this event may in some cases double-fire, requiring usage of the 'ratelimit' command (like 'ratelimit <player> 1t') to prevent doubling actions.

Event Lines

player right clicks <entity>

Switches

with:<item> to only process the event when the player is holding a specified item.
type:<entity> to only run if the entity clicked matches the entity input.

Triggers

when a player right clicks on an entity.

Has Player

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

Context

<context.entity> returns the EntityTag the player is clicking on.
<context.item> returns the ItemTag the player is clicking with.
<context.hand> returns "offhand" or "mainhand" to indicate which hand was used to fire the event. ...
<context.click_position> returns a LocationTag of the click position (as a world-less vector, rela...

Has Known Location

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

Cancellable

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

shy prairie
#

!e clicks block

candid muralBOT
# shy prairie !e clicks block
Group

Player

**WARNING**

this event may in some cases double-fire, requiring usage of the 'ratelimit' command (like 'ratelimit <player> 1t') to prevent doubling actions.

Event Lines

player (right|left) clicks <block>

Switches

with:<item> to only process the event if a specified item was held.
using:hand/off_hand/either_hand to only process the event if the specified hand was used to click.
type:<material> to only run if the block clicked matches the material input.

Triggers

when a player clicks on a block or in the air.

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 is clicking with.
<context.location> returns the LocationTag the player is clicking on.
<context.relative> returns a LocationTag of the air block in front of the clicked block.
<context.click_type> returns an ElementTag of the Spigot API click type <@link url https://hub.spi...
<context.hand> returns an ElementTag of the used hand.

Has Known Location

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

Cancellable

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

shy prairie
#

which of the two do you want to run

cursive vapor
#

the first one

idle sparrowBOT
cursive vapor
#

it should also change when right clicking entities

#

or anything else

shy prairie
#

you want the inventories to be swapped after any right click regardless of what the user is actually clicking ?

cursive vapor
#

well

#

the only exception I dont want it to switch is when riding a camel or horse (right clicking it)

#

but I couldnt find a way to easily filter that

#

same for boats

#

but it should run when right clicking any other entity that doesnt cause any other event

shy prairie
#

!t vehicle

candid muralBOT
# shy prairie !t vehicle
Cannot Specify Searched Tag

Multiple possible tags: <EntityTag.vehicle>, <EntityTag.is_inside_vehicle>.

shy prairie
#

^

#

oh no i missread that

#

ye ok so you want to trigger the event only if it isn't actually used for something else

#

i'm assuming i.e. opening a chest or other clickable block wouldn't trigger it

cursive vapor
#

yeah

#

Perhaps I can split it in two seperate events: 1 checks for entity and 1 for blocks
If the entity is a vehicle. don't do anything
If the block is a container don't do anything

shy prairie
#

just checked but couldn't find any particular preset list of entities and blocks that "do things"

#

so you have to perform some kind of check

cursive vapor
#

the only time entities do anything when right clicked is when theyre vehicles right

cursive vapor
#

but its flagged with with:force_powers so....

#

it wont be run that often

shy prairie
#

i also assume you're getting a warning after a reload mentionning your event being "possibly matched by multiple events"

cursive vapor
#

what

shy prairie
#

Event forcepower_input_script.events.on player right clicks * with:force_powers is matched to multiple ScriptEvents: PlayerClicksBlock, PlayerRightClicksEntity

#

something like that

cursive vapor
shy prairie
#

do a reload and check the logs

#

i actually wonder if you get the warning or not

cursive vapor
shy prairie
#

ex reload

cursive vapor
#

whats the issue with that though

shy prairie
#

ye exactly

#

that's not an issue, that's for your information

#

it warns you that this script is likely to run with both entities and blocks, thus some logic might break

cursive vapor
#

aha

shy prairie
#

you replace the single event by two

on player right clicks block with:force_powers:
on player right clicks entity with:force_powers:
#

then, you can validate the block isn't a container in the first and a vehicle in the second

#

since i couldn't find any easy way to check whether the block is interactive, you might want to hard code a list of exluded blocks

#

!l matchable

candid muralBOT
# shy prairie !l matchable

Script events have a variety of matchable object inputs, and the range of inputs they accept may not always be obvious.
For example, an event might be "player clicks <block>"... what can "<block>" be filled with?

"<block>" usually indicates that a LocationTag and/or MaterialTag will be matched against.
This means you can specify any valid block material name, like "stone" or "air", like "on player clicks stone:" (will only run the event if the player is clicking stone)
You can also use a catch-all such as "block", like "on player clicks block:" (will always run the event when the player clicks anything/anywhere)
You can also use some more complicated matchables such as "vanilla_tagged:", like "on player clicks vanilla_tagged:mineable/axe:" (will run if the block is mineable with axes)
(Fo...

Group

Object System

shy prairie
#

wrong one

#

!l Advanced Object Matching

candid muralBOT
# shy prairie !l Advanced Object Matching

Script event lines often include specific 'matchable' keywords.
For example, while you can write "on player breaks block:" as a script event line,
you can also instead write "on player breaks stone:" to listen to a much more specific event.
This is general in-line matching.
This is made available to avoid needing to do things like "- if <context.material.name> == stone"
just to validate whether an event is even relevant to you.

Of course, there are times when you want to more than one specific thing to be handled by the event, so what do you do?
The Denizen script event system provides a few 'advanced' options to get more detailed matching.

One option is to use wildcards.
For example, there are several 'log' materials, such as 'oak_log', 'birch_log', and more for the rest of the tree typ...

Group

Object System

cursive vapor
#

Ill just only do containers. and harvestables. if they right click a noteblock or comparator or door, Ill just run it like normally

candid muralBOT
shy prairie
#

in the end you should just make a first iteration with a working script and tweak+improve from there

shy prairie
cursive vapor
#

yoooo

#

amazing

shy prairie
#

Some blocks such as piston heads and stairs are considered interactable.

cursive vapor
#

thats good bcs we'll probably have a sit plugin for stairs

azure plume
#

Yea it be wonky

shy prairie
#

ex narrate <server.material_types.filter[is_interactable].parse[name]>

cursive vapor
#

So I just gotta do:

            - if <context.location.block.material.is_interactable>:
                - stop```
#

oof thats a lot

shy prairie
#

it might or might not be what you need

#

maybe you'd be better off using matchers with a specific list of blocks

cursive vapor
#

Cant I just make a list with those and check if it's NOT that

#

the rest is all good

shy prairie
#

i mean you can do whatever you want

cursive vapor
#

Can I do something like <list[A|B|*_C|D]>?

#

Because I dont want fences to count

#

so *_fence

shy prairie
#

if <[material].is_interactable> && !( stone|dirt contains <[material]> )

#

!l operator

candid muralBOT
# shy prairie !l operator

An operator is a tool for comparing values, used by commands like !command if, !command while, !command waituntil, ... and tags like !tag ObjectTag.is.than

Available Operators include:
"Equals" is written as "==" or "equals".
"Does not equal" is written as "!=".
"Is more than" is written as ">" or "more".
"Is less than" is written as "<" or "less".
"Is more than or equal to" is written as ">=" or "or_more".
"Is less than or equal to" is written as "<=" or "or_less".
"does this list or map contain" is written as "contains". For example, "- if a|b|c contains b:" or "- if [a=1;b=2] contains b:"
"is this in the list or map" is written as "in". For example, "- if b in a|b|c:", or "- if [a=1;b=2] contains b:"
"does this object or text match an advanced matcher" is wr...

Group

Comparables

shy prairie
#

would be stone|dirt not contains <[material]> instead of !( stone|dirt contains <[material]> ) then ? tias

cursive vapor
#

what about stone|dirt|*_fence|pumpkin not contains <[material]>

#

The *_fence is what Im asking

shy prairie
#

in that context you better off using matches than contains ye, so <[material]> matches stone|dirt|*_fence|pumpkin

cursive vapor
#

👍 Ill give it a try

#

How do I check if an entity is a vehicle?

#

including boats, horses, camels

#

I cant find any tags for it

#

I found entitytag.vehicle but thats not it

shy prairie
#

any entity can be one

cursive vapor
#

oh right

#

fuck

#

Ill just only check if they right click players

#

it should still work then

#

this feels unnatural on player right clicks player with:force_powers:

shy prairie
#

i mean you can always make a list of entities "vanilla ridable" and negate it

#

on player right clicks !horse|*_boat|cart|etc:

cursive vapor
#

no bcs we'll have custom mobs

#

and idk if we might have ridable horses

#

so Ill just leave it out for now

#

can always change it

cursive vapor
#

!logs

candid muralBOT
# cursive vapor !logs
Info: logs

Please post your full latest log file.

Background Info: One of the most helpful tools to identifying the source of a problem is your server logs file! Logs contain all sorts of important information like server and plugin versions, any error messages, and a lot more important information (More Info).

How To: Your log can be found in the logs folder within your server folder. The most recent log is a text file labeled latest.log. To get help using these logs, please open that file in a text editor and copy all of the text, then open https://paste.denizenscript.com/New/Log and paste the text into the box on the page. Then click "Submit" and copy the URL and paste that back into this channel.

Please do not upload the file to Discord or to other pastebin services, use the log pastebin linked above.

cursive vapor
#

logs ^

ionic olive
#

!debug

candid muralBOT
# ionic olive !debug
Info: debug

If you need help with a script issue, one of the most powerful tools Denizen has to offer is full debug output. This is displaying in your console whenever scripts are running until you turn debug off. To share a debug log quickly and easily with helpers, simply run the command /denizen debug -r in-game to begin recording, then run through the part of the script you need help with, then run the command /denizen submit. This will give you a link to a paste of the debug log, which you can then copy/paste back to us!

ionic olive
#

!tag locationtag.block

candid muralBOT
# ionic olive !tag locationtag.block

Returns the location of the block this location is on,
i.e. returns a location without decimals or direction.
Note that you almost never actually need this tag. This does not "get the block", this just rounds coordinates down.
If you have this in a script, it is more likely to be a mistake than actually needed.
Consider using !tag LocationTag.round_down instead.

Group

math

Returns

LocationTag

ionic olive
#

!tag is_interactable

candid muralBOT
ionic olive
#

Invalid context ID 'location'! this context tag failed

#

are you sure you didn't click out into the air?

cursive vapor
#

with a location?

#

otherwise Ill just filter it out

ionic olive
#

if you click into the sky, you could possibly be clicking nothing and the tag just fails, i'd check and see if that makes the difference

cursive vapor
#

alright

ionic olive
#

this context can fail

cursive vapor
#

wait but

#

how can I check if the block is air

#

if I cant even get the block, because its air

ionic olive
#

you could instead just check if it's truthy

#

air, void_air, cave_air, and invalid will return false

cursive vapor
#

check what?

ionic olive
#

the location or the material

cursive vapor
#

yeah but isnt that what's giving the error?

#

cant get the location because it's null?

#

ohh I can check if the location is null

ionic olive
#

yeah

cursive vapor
#

let me try

#

I think that fixed it

#

Funny how like 5 things were fixed/changed but none were related to the original question lol

ionic olive
#

oops c:

#

what's the new updated script that you're using now ?

cursive vapor
#

let me read the question again I forgot what the original question was

ionic olive
#

it looks like you had an issue with slot placement for items between inventories

#

i'd ask if you're excluding air somehow, but an updated script would help better first

cursive vapor
ionic olive
#

!command inventory

candid muralBOT
# ionic olive !command inventory
Group

item

Syntax

inventory [open/close/copy/move/swap/set/keep/exclude/fill/clear/update/adjust <mechanism>:<value>/flag <name>(:<action>)[:<value>] (expire:<time>)] (destination:<inventory>) (origin:<inventory>/<item>|...) (slot:<slot>)

Short Description

Edits the inventory of a player, NPC, or chest.

Description

Use this command to edit the state of inventories.
By default, the destination inventory is the current attached player's inventory.

If you are copying, swapping, removing from (including via "keep" and "exclude"), adding to, moving, or filling inventories,
you'll need both destination and origin inventories.

Origin inventories may be specified as a list of ItemTags, but destinations must be actual InventoryTags.

Using "open", "clear", or "update" only require a destination.
"Update" also req...

ionic olive
#

an MCVE of the swap subcommand might be a quick check to look at;
can you create two inventories with air space between them, swap them, and then narrate their inventory_contents?

#

!mechanism contents

candid muralBOT
# ionic olive !mechanism contents
Cannot Specify Searched Mechanism

Multiple possible mechanisms: InventoryTag.contents, ItemTag.sign_contents, LocationTag.sign_contents, ItemTag.inventory_contents, EntityTag.inventory_contents.

#
Possible Confusion

Did you mean to search for command quests?

ionic olive
#

i can't remember what the actual rough dirty mechanism is but something like this
/ex note as:test1 <inventory[generic[contents=stone|air|air|sand]]>
/ex note as:test2 <inventory[generic[contents=dirt|air|air|glass]]>
/ex inventory swap destination:test1 origin:test2
/ex narrate <inventory[test1].contents>
/ex narrate <inventory[test2].contents>

#

or in a task script ofc

ionic olive
#

!mcve

candid muralBOT
# ionic olive !mcve
Info: mcve

Please create a Minimal, Complete, and Verifiable Example of the problem you're reporting.
Minimal: contains nothing other than the part that's broken (and bare minimum structure).
Complete: contains everything needed to demonstrate the issue.
Verifiable: Anybody should be able to throw it on their own server and see the problem happen for themselves, without any needed tinkering.

ionic olive
#

goes along with my comment in #1243514046989471745 as well

cursive vapor
#

Thanks for the help everyone, got this fixed (in a different thread)