Minecraft – How to do this: (Long Question)

minecraft-commandsminecraft-java-edition

So, I have several commands down, and they are the slightest bit conflicting.

/execute as @a[nbt={SelectedItem:{id:"warped_pressure_plate"}}, Dimension:"minecraft:overworld"] in minecraft:the_nether run tp @s ~ 129 ~

/execute as @a[nbt={SelectedItem:{id:"warped_pressure_plate"}}, Dimension:"minecraft:overworld"] in minecraft:the_nether run fill ~15 129 ~15 ~25 112 ~25

Using repeating commands in command blocks, I want to make it so that if the player is holding a warped pressure plate, and if they are in the overworld, teleport them to the nether ceiling with the same coordinates. The thing is, that I want to fill in a hole in the nether ceiling 20 blocks away ONCE they enter the nether by using the warped pressure plate, but I've been thinking:

  1. If the person enters the nether first THEN the second command runs to make a hole, the second one doesn't do anything since the person isn't in the overworld anymore.
  2. If the command tries to break the ceiling first, then tp the player there, the ceiling breaking won't work until a player is there to load the chunks to generate the landscape. (even though the nether ceiling has literally nothing)

I can't do either, so how do y'all suggest I change my commands? Will it work if I just hook both of them up on the same loop so they run at the same exact time, or just turn both of them to repeating so they also run at the same time? (I can't test this stuff; please help.)

Best Answer

You can use the scoreboard.

For this, set a chain of four command blocks. If you want this to run as soon as the player selects the warped pressure plate, set all of them to Always Active, then set the first to Repeat and the rest to Chain. Make sure they are chained correctly, like so:

Command Block Chain

Then, for the commands.

Setup: create the scoreboard

Make a new scoreboard to store a variable:

/scoreboard objectives add test dummy

(rename the scoreboard objective to whatever you want; it doesn't matter, as long as you update its references in the commands as well)

Command 1: set all relevant players' score to 1 so they can be targeted

scoreboard players set @a[nbt={SelectedItem:{id:"minecraft:warped_pressure_plate"},Dimension:"minecraft:overworld"}] test 1

Command 2: teleport all relevant players

Now, I'm not sure if you want to teleport a player to the corresponding location relative to the command block or the player. I'm assuming player, otherwise you'd just create a static hole in the ceiling since the location wouldn't change, in which case, your first command doesn't actually work correctly. ~ targets relative to the command block's position, unless you change it. You can use at or positioned as to set it to a different entity, in this case, @s works since you are using execute as.

execute as @a[scores={test=1}] in minecraft:the_nether positioned as @s run tp ~ 129 ~

Basically, as every player who's been marked by the first command, this executes tp ~ 129 ~ in the nether relative to the position of the selected player.

Command 3: create the nether ceiling hole

execute as @a[scores={test=1},nbt={Dimension:"minecraft:the_nether"}] at @s run fill ~15 129 ~15 ~25 112 ~25 air

Again, you need to change the target location, otherwise it will create a hole in the overworld where the command block is. Note that above I used positioned as because I want to set the dimension to the nether using in minecraft:the_nether, but here, the player is already in the right dimension. Also, the dimension selector here is just as a safeguard to prevent the hole from being created in the overworld if teleporting lags.

Command 4: clean up

scoreboard players set @a[nbt={Dimension:"minecraft:the_nether"}] test 0

This just clears the scoreboard for anyone who's successfully teleported over so nothing weird happens.

Results

I tested this in Minecraft 1.16.5 on a Singleplayer world and when I select a warped pressure plate, it immediately teleports me into the Nether and creates a hole a bunch of blocks away in the ceiling. Nothing happens as long as I don't select the pressure plate, and if I move my location in the Overworld, my destination in the Nether updates as well.