3

I have created a datapack where players can use /trigger brainage_minigames:toggle_minigames to toggle back and forth between playing regularly on the server and playing in a dimension specifically for minigames.

When the player uses the command while in any dimension but the minigame dimension, it will spawn a marker at their location (with their UUID stored in the data tag) with a specific tag, and then teleport them to the minigame dimension. When the player uses the command while in the minigame dimension, it will teleport them to their marker (based on the previously stored UUID) and then kill the marker.

I can already see several pitfalls that I will most likely encounter because of this approach, such as duplicate markers being spawned if the player leaves the dimension without using /trigger, or no markers being available if /kill @e is run for whatever reason.

Because of this, I would like to transition from using markers to using storage. The only problem stopping me from using storage is that Dimension NBT is only stored for the player, meaning I seemingly have no way of implementing this approach.

However, there is one datapack I found created by Vanilla Addons (https://vanillatweaks.net/share#E2zQSV) that is somehow able to do this. It seems part of the solution is using a loot table to summon an item with ID minecraft:stone and then using the function copy_nbt to copy Dimension NBT from somewhere.

This datapack appears to be extremely complicated and I am having trouble understanding it - if someone could point me in the right direction I would greatly appreciate it.

1
  • I got a little lost in your question. You mention "...transition from using markers to using storage." What exactly do you mean by storage? And what approach would be impossible? Besides, you Marker approach wouldn't work not because of a possible /kill @e, but because the entity would be unloaded. You'd need to store those coordinates on a scoreboard instead.
    – BunnyMerz
    Apr 1, 2023 at 20:05

1 Answer 1

2

TLDR: Store the position into a scoreboard and then use one of the methods described here to get the player back there.


The vanillatweaks datapack you linked has to be so complicated because it accounts for every possible dimension in existence, including custom ones. It might also need to account for possible multiple homes per player, all of which is irrelevant for you.

If you want a solution that is specifically tailored for your personal server, you can do it a lot easier than that.

And yes, your solution indeed has several pitfalls, most notably probably the fact that entities that are in unloaded chunks cannot be teleported to, as they cannot be selected using @e.


If I understand your problem correctly, you need something that teleports players from and to a minigame dimension through a trigger command. And that is also the only way to get to said dimension.

This means you're limited to a single "return" location that you need to store for every player, which includes the dimension and the coordinates. Because you know what dimensions exist in your world, you can easily store the dimensions in a scoreboard and teleport based on that. Here is an example assuming you only have the vanilla dimensions on top of your minigame one.

first, the setup:

scoreboard objectives add x dummy
scoreboard objectives add y dummy
scoreboard objectives add z dummy

scoreboard objectives add dim dummy

Next, how to store the current position

execute store result score @s x run data get entity @s Pos[0]
execute store result score @s y run data get entity @s Pos[1]
execute store result score @s z run data get entity @s Pos[2]

# for the dimensions, just check if the player is in that dimension.
execute at @s in minecraft:overworld if entity @s[distance=..1] run scoreboard players set @s dim 1
execute at @s in minecraft:the_nether if entity @s[distance=..1] run scoreboard players set @s dim 2
execute at @s in minecraft:the_end if entity @s[distance=..1] run scoreboard players set @s dim 3

# tp them to the custom dimension
execute in <dimension name> run tp @s <coordinates>

Lastly, how to return to the correct position. I'll use multiple functions here to make it easier and more failproof.

go_back.mcfunction

tag @s add target

# summons an entity in the required dimension and executes the function as the entity
execute if score @s dim matches 1 in minecraft:overworld summon marker run function namespace:to_score
execute if score @s dim matches 2 in minecraft:the_nether summon marker run function namespace:to_score
execute if score @s dim matches 3 in minecraft:the_end summon marker run function namespace:to_score

tag @s remove target

to_score.mcfunction

# changes the position of the entity to be the previously scored position
execute store result entity @s Pos[0] double 1 run scoreboard players get @p[tag=target] x
execute store result entity @s Pos[1] double 1 run scoreboard players get @p[tag=target] y
execute store result entity @s Pos[2] double 1 run scoreboard players get @p[tag=target] z

# tp player to marker entity
tp @p[tag=target] @s

# remove marker entity 
kill @s

You must log in to answer this question.

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