TransWikia.com

How to do this: (Long Question)

Arqade Asked on July 26, 2021

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

2 Answers

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.

Correct answer by hyper-neutrino on July 26, 2021

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.

Answered by Egor Hans on July 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP