1

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.)

4
  • Does the first command work? I don't immediately see any issues with it.
    – MBraedley
    Mar 30, 2021 at 15:55
  • 1
    Yes, but the issue here is the second command. I need to make a hole beside where they were tp'ed, but if I run the tp command first, then they won't be in the overworld anymore, so the hole won't be made. Remember, there is a dimension tag in the @a nbt tag part. But, if I run the hole command first, the chunks won't be loaded and the hole with fail.
    – Korogue
    Mar 30, 2021 at 16:08
  • 1
    I thought that was the case, it just wasn't really clear in your question.
    – MBraedley
    Mar 30, 2021 at 16:13
  • Sorry, it was on the 1. and 2.
    – Korogue
    Mar 30, 2021 at 16:14

2 Answers 2

4

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.

3
  • 1
    Thank you so much!!! Scoreboards confused me for several months already, I suppose I didn't really research it
    – Korogue
    Apr 1, 2021 at 1:18
  • @Korogue No problem, glad I could help! Scoreboards are definitely quite intimidating to get into.They're extremely useful for watching player actions and just managing data for commands. Good luck :) Apr 1, 2021 at 1:46
  • @Korogue Execute is probably the most important command to learn these days, and it seems you're well on your way there, but the scoreboard is still probably the second most important set of commands, even if it is mostly for edge cases these days. Having said that, this is probably possible to do without scoreboards and instead using functions. (I recommend learning functions as well, they provide elegant solutions to some common command block problems.)
    – MBraedley
    Apr 1, 2021 at 12:47
0

The function-based alternative

Currently untested, be sure to report any bugs. Should work in theory though.

As you will see, it's much simpler than using scoreboards, but requires you to modify your world files. I'm using netherwarp as namespace and warp_to_roof as function name, but you can change those - just use lower snake case, I haven't experimented with hyphens but camel case definitely won't work.

First of all, create a folder in your world's datapacks folder. Insert a simple pack.mcmeta (you can copy that from any resourcepack or datapack that works with 1.16.5), and then create the folder structure data/netherwarp/functions. There, you need the file warp_to_roof.mcfunction with the following content:

/execute in minecraft:the_nether run tp @s ~ 129 ~
/fill ~15 129 ~15 ~25 112 ~25 air

Then, you simply need to run /execute as @a[nbt={SelectedItem:{id:"warped_pressure_plate"}, Dimension:"minecraft:overworld"}] at @s run mcfunction run netherwarp:warp_to_roof.

While already putting this in a datapack, might as well put the triggering command in a loop.mcfunction and add a data/minecraft/tags/functions/tick.json with the following content:

{
    "values": [
        "netherwarp:loop"
    ]
}

This will automatically run the command every game tick. Don't worry about performance, datapacks are much more resource-efficient than command blocks.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .