Updated specific locations to be searchable, take a look at Las Vegas as an example.

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
Command Block: If player holds specific item, /kill blocks?
Post Flair (click to view more posts with a particular flair)
Post Body

Hello!

So I am making an inn / hotel and I want the room doors to be locked, unless the player has a key (name tag) in his inventory. Since you can't lock doors, I figured I could place some barrier blocks in front, so the door can't be reached to right-click it.

Now I set up command blocks with [Repeat] and [Always Active] to check for this.The first line I put is

/execute if entity @p[nbt=!{SelectedItem:{id:"minecraft:name_tag",Count:1b,tag:{display:{Name:'{"text":"Room 3"}'}}}}]

So is there a way to add these to the same command, or how would I do this best?

/kill @e[type=minecraft:barrier,x=-31,y=68,z=712]
/kill @e[type=minecraft:barrier,x=-31,y=69,z=712]

Also, in case somebody had a key and lost it, how would I go about replacing the barrier blocks smartest?

* * * * * * * * * * * * * * * * * * * * * *

It took me a whiiile to test out things, but after removing and changing (based on input below) certain arguments from the code, I managed to find the

Solution!

Command Block #1: Repeat, Unconditional, Always Active

/execute if entity @p[nbt={SelectedItem:{tag:{display:{Name:'{"text":"Room 3"}'}}}}] run fill -31 68 712 -31 69 712 air

Command Block #2: Repeat, Unconditional, Always Active

/execute unless entity @p[nbt={SelectedItem:{tag:{display:{Name:'{"text":"Room 3"}'}}}}] run fill -31 68 712 -31 69 712 barrier

Thanks so much!

Author
Account Strength
100%
Account Age
10 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,618
Link Karma
738
Comment Karma
732
Profile updated: 2 days ago
Posts updated: 3 weeks ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago