#detecting player moving item from their inventory into a chest
1 messages · Page 1 of 1 (latest)
<@&1201956957406109788>
💬 While you wait, take this time to provide more context and details.
🙇 If nobody has answered you by <t:1750252060:t>, feel free to use the Summon Helpers button to ping our helper team.
✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve
Well there is an inventory_changed advancement
I don't remember if it can detect an item leaving your inventory vs moving within it
yeah i was looking at that but it only seems to work on something being added to your inventory instead of being removed
You could also detect whether the item is in their inv at all using /clear
If there isn't a specific method of dropping the item that you want
wouldn't that remove the item from the inventory if it was there though?
/clear @s item 0 returns success if there was an item and fail if there wasnt, but clears 0 of the item
there is a way for this but depending on what your ultimate goal is, this could be as easy as a few commands or as tedious as a few.. files or something ya know what i mean
what is your ultimate goal
is it one item only you are trying to detect, does it matter where that item is put or do you just wanna know if it was throw out of the player's inventory
thrown*
thrown as in moved since you said the player cant throw stuff
It's an item that I find using nbt data because I need to detect whether or not it has an encantment. currently I have
execute as @e[type=item, nbt={Item:{components:{"minecraft:enchantments":{levels:{"enchf:gluttony":1}}}}}] at @s run data modify entity @s Owner set from entity @p UUID
execute as @e[type=item, nbt={Item:{components:{"minecraft:enchantments":{levels:{"enchf:gluttony":1}}}}}] run data modify entity @s PickupDelay set value 0
to prevent someone from dropping the item but well, right now they can just move it into a chest and bypass it.
you dont need nbt data to detect it by the way but sure if it works
let me use my brain cells
oh
I can only think of the following:
Advancement that triggers when opening chests and other inventory containers using the minecraft:default_block_use
have it "save" inventory somehow and each tick reset the inventory.
not a neat or nice method but I guess it could work. this is assuming you have more than 1 item to restrict, the /clear can work for some items.
yea kind of the easiest option, but do you want the item to get deleted in case it was put in a chest or just returned to the inventory
i'd probably make it so if i have a chest gui open, the item is immovable, as in you can't pick it up with your cursor or move it with shift right click by doing checks similar to the ones done in custom guis
i think there is a scoreboard that detects whether a chest is open or not
yeah and this is the easy summary, but you would have to check if the player is still in the chest or not to revoke it at some point.
or something in your nbt actually
i havent touched datapacks in ages can u confirm quimoth
scoreboard would have the same issue, since when do you stop checking (there is no close chest gui statistic or event is there?)
nbt/score that outputs 1 as long as you have the chest gui open
yeah this seems good cause it won't conflict with the code for tryin gto drop the item
i know there is one for furnace and other workshops
you can try it and let us know how that goes then
maybe someone could give a smarter solution in the meantime
ye will def let ya know
good luck 🍀
Unfortunately we do not have the bedrock component that would make this super easy
in this case i think the easiest way is to just detect when you open the chest with advancements as quimoth said with "default_block_use", tag the player, and remove the tag only when the player moves (aka presses his movement keys)
btw i forgot to say this, if your goal is to make the item soulbound, in other words, only one certain player can have it in his inventory, that'd make stuff far simpler
but you'd have to compromise by allowing the player to put it in a chest
in this case you'd detect two things: if the item is on ground, you will teleport it to it's owner, if the item is in a wrong player's inventory, you will give it back to it's owner
but for chests and barrels, yea it'll just stay there
I don't know if soulbound is what I was looking for unfortunately
rip
so I got the advancement for detecting opening a chest or any other item open
I assume I need to make another advancement based on movement, however the issue I think I see happening is if it's just based on a keypress wouldn't that mean they could press a key to remove the tag before they exit out of the block?
those dont trigger if you are in gui i believe
ah ok, I can test it. what is the command to check for player movement?
subpredicate to check whether a key is pressed or not
you can check for all, if any is pressed you can do the rest
I assume I'd need to use minecraft:tick for this advnamcenet then right?
yup
you can base off something like this:
{
"criteria": {
"shmovin": {
"trigger": "minecraft:tick",
"conditions": {
"player": {
"type_specific": {
"type": "minecraft:player",
"input": {
"forward": true
}
}
}
}
},
"shmovin1": {
"trigger": "minecraft:tick",
"conditions": {
"player": {
"type_specific": {
"type": "minecraft:player",
"input": {
"backward": true
}
}
}
}
}
},
"shmovin3": {
// ..
},
"requirements": [
[
"shmovin",
"shmovin1",
".... etc",
]
]
}
the requirements part says "if any of those criterias are triggered grant the advancement"
and each criteria checks for a different key
there should be like 7 or 8 idk how many
do you know what the predicate is to check if a player has an advancement in an advancement?
also tick
tick, conditions, "player", "type_specific": type player, and from there there is an advancements field i believe
{
"criteria": {
"e": {
"trigger": "minecraft:tick",
"conditions": {
"player": {
"type_specific": {
"type": "minecraft:player",
"advancements": {
"adv path": true
}
}
}
}
}
}
is /item the right command to use for locking an item so it can't be moved?
there is no command to prevent moving items in java
in your case, you would need a combination of the clear and give commands.
clear for the chest/hopper etc. that receives the item(s)
give to ensure the player still has it.
technically what you want is not easy to support in java.
I'm probably doing this very wrong lol
rn since this happens every tick it just glitches out the game until the item dissapears
I think i could use data because the item would be a block however I havent used data very frequently yet so I'm not sure how to do that
what are you trying to do?
make it so that if someone puts a specific item in the chest/shulker... etc... from their inventory it deletes the item from the chest and gives it back to the player
i have the advancements that check for when a player has opened an inventory or not
you're on 1.21.5?
wait
oh I also have two functions which control whether or not the loop is running and to control resetting the enchantments
youre the summon-allies-with-a-goat-horn girlie
ye
I finished that, just waiting for modrinth to review it, I started workin on a new thing
rn I'm making an enchantment called gluttony
that u put on food
uh, it's a bit evil lol
okay well what do you mean by resetting the enchantments?
and what does your loop do?
oh sorry i mistpoke I meant achievements
advancements*
So for reference these are the advancements and functions that control whether or not the loop should toggle on/off based on whether or not someone is opening a chest
The loop is supposed to check to see if the food item that is enchanted with "gluttony" is put in a nearby chest or other item that accepts storage, and then delete that item, and put it in their inventory for as long as "gluttony_punish2true" achievement is granted to the player
I think I can use data get I'm just not very familiar with the data function yet
are you sure your loops work as intended?
rn the loop doesnt work
everything else does tho from what I can test
it triggers/disables the loop fine it seems
but like- i'm not sure if a loop is what you need here
a loop runs a function multiple times in the same tick for as long as a condition is met
ye
are you intending to run your function every tick for as long as the player has that container open?
yes
from what I was talkin about with some of the other ppl here I think that's the only way to get around some of the limitation of commands
okay could you show me punish2loop
then a loop isnt really what you need
this is what it used to be, which was a very bad idea to do lol
yeah so basically
this will run it like a lot of times
in one tick
you want it just once every tick as someone who has a container open
ohhhh
what i recommend is giving players who have a container open a tag and running your detect function as every player with that tag
so wait are u using that one advancement with inputs to reset the loop?
I need to specify this tag in namespace/tags right?
no i mean like a normal tag you give with tag @s add ...
oh ok
Ye so one advancement checks if the player has any item enchanted with the enchantment and opens a chest, the other enchantment checks if the player moves using any input (which would mean the player isn't in the chest anymore)
so in the true function just run tag @s add gluttony_punishing or something
and in the false just tag @s remove gluttony_punishing
and then I add the clear/give commands in the tick function right?
yeah hold on tho im thinking how you would detect it
yeah thats the main thing that stumped me
okay sooo basically the inventory_changed advancement does actually detect removing of items
wait really?
maybe we could use that
yeah just tested it
but not when you specify it apparently 😭
yeah the items condition I think on the wiki says it only talks about items that were added
I think you can use the data command to get info about the chest since the chest is placed on the ground I'm just not familiar enough with the data command yet to make it work
yeah thats a good idea i just wouldnt know how to select the chest
i feel like raycasting your way to the chest is kinda overkill here so im tinkering with something else lol
fair fair
okay f it lets raycast
yeah same here i've only thought about this never done it before
but its not that hard, so i think first you'll need a simple inventory_changed advancement that triggers another function without condition
actually i have no clue how you could possibly do this without it breaking
bc you can't remove one item from a chest
i think
only a specific type of item
acutally
its not possible to get an item with gluttony into a container right?
like at all?
Right now it is, I have it so you can't drop the item but rn it's possible to put into a container and I want to prevent that
well either you can't put it into the container or you put it in the container and then that's detected and it's removed from the container and you get given the item
yeah okay thats what we're gonna do
so actually you dont need that inventory_changed advancement
ok
just make a function called raycast
and another one called raycast_success or something
oh actually first you should make a block tag for all your containers
so in namespace/tags/block
"values": [
"chest",
"barrel"
]
}```
in there just place this json file name it like `container.json` or something and add all your containers
yup, did that
okay great!
now back to the raycast function
the raycast function should just be
execute unless block ~ ~ ~ #(your container tag) positioned ^ ^ ^1 run return run function (raycast)
function (raycast success)```
should be it
this will find the container and run the raycast success function at its location
thats basically all the raycast does
looks about right
yes okay i got it
so in your raycast_success function
execute unless data block ~ ~ ~ Items[].components."minecraft:enchantments".levels."enchf:gluttony" run return fail
thats your first line and basically it should only continue the function if it detects an item with that enchantment in the container
that makes sense ye
so afterwards i thought this would be easy, cause i thought you could simply remove it from the chest and give it to the player, but this doesnt take the item count into account yk?
so if they placed 2 of that something then they would only get one back
oh I didn't think about that
this is still possible by storing the count and running a macro with the slots data thats like $give @s $(id) $(count)
actually no
you'd probs want to use item replace from
so that you copy the item with all its data
you'd still need a macro to get the slot that its in and do something line container.$(slot) but its doable
given how the way the item works I'm not that opposed to it forces them to keep at least 1
one problem tho, i'm kind of in a hurry and i kind of need to go
Because otherwise, someone might for instance put a bunch of them in a dropper and fill the inventory with it to grief
ah no worries!
i mean thats something you can think about but it wouldnt be that hard to make it keep the count
okay well you do you and type it in here
i'll be back later, you can try and tinker it yourself a little
sounds good 🙂
i'll just ping you when im back is that fine?
sounds good!
okay see ya
@wooden abyss
hello again 🙂
I was tryina get it to work, and I think I got some of it working, rn I have this in my tick function
and then in success I have this
oh yeah one thing, you should add anchored eyes
right before run
very much needed for the raycast
what does anchored eyes do
oh and at @s is also important after as @a[...]
so basically normally running a command at the players position makes it run at their feet bc thats their actual position in the game
all we're doing is moving it to their eyes
ahhh good to know
so that when going forwards with ^ ^ ^1 in the raycast it will actually go to the block we're looking at and not one under it
So it should be this?
yeah just place at @s before anchored eyes
sounds good!
okay now for the raycast, i thought about it and the simplest way to do it is to summon an item at the player and copy all its data from the item in the container
we can't use give bc theres no way to copy data with give, it has different syntax
ye that's fair
and with the item command, we need to specify the exact slot that the item should go in, which we cant know
ohh yeah so summon fixes that b y just letting the player grab it
yup!
so now for your raycast_success
you've got
execute unless data block ~ ~ ~ Items[].components."minecraft:enchantments".levels."enchf:gluttony" run return fail
so this first line will just not even continue the code if the chest doesnt have an item with "enchf:gluttony"
so then we'll just want to summon the item at the player (remember the context rn is as player at chest so we need to specify at @s)
is it possible to specify this as the item not being an enchanted book?
yeah bc enchanted books dont use "minecraft:enchantments", they use "minecraft:stored_enchantments" or something like that
Ah ok ok
so it shouldnt do anything with those
now
execute at @s run summon item ~ ~ ~ {Item:{id:"emerald"},Tags:["temporary_item"]}
is your second line
emerald is obv just a placeholder, bc ive noticed the item doesnt even spawn if you dont specify an id
fair fair
now this is the part where the game is kinda dumb
``` will modify the temporary item's Item value FROM the chest's item that has the enchf:gluttony lvl 1 enchantment
basically its just not possible to select the item that has the enchantment, the level needs to be specified
does your enchantment have multiple levels?
yes there's 5
okay well its kinda dumb/sad/weird but you'll have to write this one line 5 times with all levels
bc you cant specify a wildcard like "enchf:gluttony":*
yeah
yeah for some reason only the predicate lets you specify just the enchantment, components needs a specified level
ikr its weird
anyway
so now we've copied the item from the container to the spawned item
all we need to do is delete it from the container
data remove block ~ ~ ~ Items[{components:{"minecraft:enchantments":{levels:{"minecraft:sharpness":1}}}}]
oops i used sharpness for testing
just replace that with your enchantment
and ofc here again you'll have to have 5 lines for all 5 levels
So I was trying to test it
and I opened up the anvil because you can store items in there and I needed to include things
it currently gives me infinite emeralds haha
oh wait
so I have one in my inventory I forgor about
but it's in my inventory not the chest
if I put it in the chest I start to get infinite cod
uhm i think the removal line is wrong
but yeah with the anvil it just adds infinite emerald
you added this right?
yeah
oh god lol
lmao
thats my bad for leaving in sharpness
anyway for your anvil problem i dont think its gonna work like at all
bc there is physically no way to detect items in anvils, crafting tables, etc
bc they dont actually have an inventory
theyre not even block entities so they dont even have data
ah i see
I can remove them from the lists which is probably wahts causing the issue
yeah
but what issue are you currently experiencing?
wait lemme go grab some strawberry cake
all gud, actually ur stuff works just fine I just had blocks in the tag I made for storage items like the crafting table which I didn't need, it's only if I try and do stuff with those that the glitch happens
yeah cause if you try to do data get block on like a crafting table, it just says its not a block entity
ahhh yeah fair
anything you can move with a piston isnt a block entity
ok this should be fine now
but there's 1 other glitch
this one might be difficult
so u know how basically the advancement to remove the tag involves pressing a movmeent key right?
So if I don't press any movement key after removing the inventory, and look away from the block, I will get infinite emeralds
-# btw you can just use "#shulker_boxes" for shulker boxes
oooh this is good to know thanks 🙂
oh!
hm i mean the input method is clever but it really sucks bc you can just close the container and not move and the code will still think that you're in the gui
i actually think ik what to do
man if only you could do functions in json
could make anotehr raycast
which detects if you aren't looking at the block and removes the tag
thats exactly what i thought of!
yeah we can just use our raycast
no need for a new one
so basically if you're not looking at a chest at all, the raycast will just hit the chain command block limit (which is actually a gamerule you can set) and apparently if it does at the end of the raycast when the limit is hit it ignores the "return" command
we know this bc its running your raycast_success
so basically if we just added execute unless block ~ ~ ~ #(your tag) run tag @s remove (your tag)
before the function raycast_success
it should work
also keep in mind #(your tag) is your block tag and (your tag) is the tag you gave the player
cant guarantee this will work tho bc functions get a little quirky when reaching the chain limit 
pog, also I need to relaunch game caused I accidnetly closed it out instead of going to title :c
ah unfrotunately it doesn't seem to work
oh wait im dumb
ofc it doesnt work
just try to add execute if block ~ ~ ~ #(your tag) run before the raycast_success
we need to actually not run the success if it didnt find a chest
(removing the tag from the player will not stop the function midway through)
Unfortunately now I can just put the thing in the inventory it seems
Removing the tag before success I think is preventing the function in tick from calling the raycast
its unless
no like
2nd line replace if with unless
and 3rd line do this
oh I understand now, the execute command to runthe function
or the execute line before the function
yeah looks about right
it works 😄
thats great!
i actually
dont think
you need the remove advancement and its function anymore
actually
keep it in
even tho it really doesnt matter that much, it will help performance
because we want to try to limit the time the raycast is running by as much as possible, so we want to have as many possibilities to cancel it
Quick question, this is more of a balancing thing, do you think it would be less cancer if I prevent this from happening until a player eats it?
OH MY GOD
oh god
Im a bit evil lol
one thing that i noticed lmao, this will currently run if the player eats ANYTHING while having an item with gluttony
is that intended?-
yup
OH-
Oh yes xd
Now, so long as you don't have keep inventory on, it's not a big deal because you can just /kill or whatever and get rid of it
however, if keepinventory is on...
thats insane
ok I made it so that you don't receive any of these negative effects unless you eat it
except for the not being able to drop it normally part to makes ure someone can't just run up and giv eother people it
they'd have to use something like a dropper and trick someone
thanks for helping me get this to work though 😄
Your question, #1384874705332473967 (detecting player moving item from their inventory into a chest), was resolved!
#1384874705332473967 message
8h13m
ahhh sorry to reopen but apparently this doesn't work in ver 1.21.5
yeah, i can imagine, i think they changed the enchantments component
should be an easy fix tho
what exactly was changed?
the enchantment itself works just fine, but the thing that doesnt work is the part that prevents you from dropping the item, and checking the chest
oh i've got it
yes they did change something
they removed the "levels" key
so instead of Items[].components."minecraft:enchantments".levels."enchf:gluttony its just Items[].components."minecraft:enchantments"."enchf:gluttony
you'll just have to remove any levels. and levels:{}
ahhh ok
There's 1 more bug
it's like the infinite emerald bug except now with infinite cursed food
infinite cursed food??
are you sure you've changed the last line of raycast_success?
oh wait nevermind I forgot to remove levels from part of it
it works now 🙂
sure! here ya go https://modrinth.com/user/ma1kawa11
thx! <3
goat horn summoning still under review atm :c
oh wait did they release 1.21.6 now? its on modrinth
lmao yeah one time one of my projects got unlisted bc they thought i didnt ask for permission before using someones assets
yup
oooh this means i will have to do updating ree
like officially 2 days ago but its taking a little for all the platforms
no breaking changes tho c:
just the cool new dialog feature thats gonna be a blessing for my chemistry datapack
ah cool so I don't even have to worry that's pog
OMG WAIT WHAT I JUST READ ONE OF THE CHANGES IS LIKE BLOCK MODELS ARE NO LONGER LIMITED TO MULTIPLES OF 22.5 DEGREES
okay i need to calm down
this is big for me lol
but yeah you probs wont have to struggle all too much for updating to 1.21.6
omg there's a /datapack command that's amazing
yeah i saw thatttt
yeah i read thru stuff it doens't look like anything ive made will break that's nice
yeah theres this guy conure u probs know him
he makes like "Why Your Datapack Broke in _" videos
No Tutorial Datapack this time, but I went ahead and just put that changelog I was using into the usual Drive folder!
https://drive.google.com/drive/folders/17h79rkR0QulQbeR--SPpC5So3vAU_1ga?usp=sharing
This video explains how to update a datapack specifically from version 1.21.5 to 1.21.6.
Trying to upgrade from an earlier version, or to a mor...
i watched this and it wasnt that bad lol
yeah lmao i learned enchantments from him
and also took some genius ideas from CloudWolf
Your question, #1384874705332473967 (detecting player moving item from their inventory into a chest), was resolved!
#1384874705332473967 message
8h56m
so um about that i may have found a way to detect this :) in every version after 1.13