#how do i make item interactions work?

1 messages · Page 1 of 1 (latest)

supple kettle
#

i have made these 2 command blocks that open and close the door by using the /clone command. and now that i got that sorted, i wonder how i can activate them.

i was thinking only by standing in a curtain radius while holding a trial key, does the door open (switches to tthe open varent) while playing the open door sound effect .

i know this is possible as seen a friend do it. i just wanna know how he did it

toxic wigeon
#

here is what you should do:

  1. check if the player is close to the door, this can be done using if entity @s[distance=..5] to check for example if the current entity is within 5 block of the position the command is being executed (se execute it a the door)
  2. check if the player is holding a trial key, you can use execute if items for this https://minecraft.wiki/w/Commands/execute#ifunlessitems

try to put all of this together in one execute command that runs the clone command when it finishes

Minecraft Wiki

Executes another command but allows changing the executor, changing the position and angle it is executed at, adding preconditions, and storing its result.

supple kettle
#

or do i use a chain command?

supple kettle
#

execute if entity @p[distance=2] run execute if items entity Seatomato1 hotbar.* minecraft:trial_key run setblock -8 -30 26 minecraft:redstone_block

#

would this work?

toxic wigeon
#

yea you don't even need run execute

supple kettle
#

what do i need

toxic wigeon
#

you (almost) never need run execute, you can just remove it if you see it

supple kettle
#

then

#

how do i do it

toxic wigeon
#

remove the run execute

supple kettle
#

execute if entity @p[distance=2] if items entity Seatomato1 hotbar.* minecraft:trial_key run setblock -8 -30 26 minecraft:redstone_block?

toxic wigeon
#

yup looks good to me
do you always want to check for the specific player Seatomato1?

supple kettle
#

execute if entity @p[distance=2] if items entity @p hotbar.* minecraft:trial_key run setblock -8 -30 26 minecraft:redstone_block

toxic wigeon
#

and also you're checking if the distance is exactly 2 instead of checking if it is within 2 blocks, you can do ..2

toxic wigeon
supple kettle
#

and how do i get it to deleate the key when it is being used?

toxic wigeon
#

that way if there is a player closer but doesn't have the key the one that has the key but is a little further away can still make the door open

supple kettle
#

how do i get it to run multaple commands? like playsound, or clear item

toxic wigeon
supple kettle
#

wait

#

what if i want to change the way it works? like instead of being in a curtain radius i have to press a button

#

or in this case (the door knob)

toxic wigeon
#

you can use an advancement to detect the player using a button and runs a function as a reward. In that function you revoke the advancement (so it can be triggered again) and check if the player is close enough to the door and has the item

supple kettle
#

advancements?

toxic wigeon
#

yea datapacks can add advancements to the actual advancements tab but they are also very useful for detecting certain player events like pressing a button. When the player gets the advancement, we can run a reward function as the player

#

don't worry the player won't notice anything since we can make the advancement completely invisible for them

supple kettle
#

ok, i think i got it, though i have another door that can be opend without a key. and it dosent seem to work?

#

execute if entity @p[distance=..2] run setblock -8 -30 26 minecraft:redstone_block

toxic wigeon
#

you aren't checking for the key item

supple kettle
#

what

toxic wigeon
#

so in your execute command:

  1. run the command as all the players. this will create multiple copies of the command (under the hood) that each run for a player. @s now refers to this current player
  2. check if this current player is holding the key item you want to check
  3. run the command at the door position
  4. check if the current player is also close enough @s

if you're using the advancement method, you don't need to run this as all the players but instead run this in the reward function of the advancement. In this function @s is already the player who clicked the button but this will run at the world spawn so you still have to run the command positioned at the door