1

Help with commandblocks - easier way to do all this?grid_on

Le_Beholder 9/23/23 12:56 pm
490
9/26/2023 8:28 pm
Greetings peoples, I have a conundrum.
I have been working on an ambitious skyblock adventure map for a month now, and plan to add a feature that lets the player reset his progress inside the map without having to delete and replace the world file.
The way I've chosen to go about this is by using a long series of command blocks that fill a 5 map square around the island with air, and then generating a new skyblock via structure block at then end of that chain.

However, I've come to realize this method is long as it is meticulous.
for each chunk I have measured and found I need three command blocks, one normal and two chain, in order to use "/fill" with air the entire volume of the chunk in three sections.
to do this for a whole single map area, I would need a total of 48 command blocks for every map.
since I've designated the adventure maps area as a 5x5 map area, that would be 1200 command blocks in total, each single command block running the fill command for its section of a chunk.

It is alot. and so my question: is there an easier method to do this besides numbingly placing and then coding 1200 commandblocks? like a Redstone machine that runs a sort of "for loop" coding for this?

I would appreciate any advice, thanks in advance.



Posted by
Le_Beholder
Level 5 : Apprentice Crafter
3

  Have something to say?

JoinSign in

11

-ghost-
09/23/2023 3:03 pm
Level 25 : Expert Ranger
history
The answer is found in datapacks and the scoreboard. (Datapacks are preferred in these situations because there is no danger of their being unloaded.) This allows you to create recursive functions, which can fill the entire map with a single function call. Example:

e:load (runs on pack load)
scoreboard objectives add data dummy

scoreboard players set reset.x data 0
scoreboard players set reset.y data 0
scoreboard players set num data 0



e:reset (call with /function e:reset)
#Set the x and y values to 0
execute if score num data matches 0 run scoreboard players set reset.x data 0
execute if score num data matches 0 run scoreboard players set reset.y data 0

#Initialize a marker
execute if score num data matches 0 summon marker run tag @s add -marker
#Send it to the corner of the reset area with the lowest X and Z cooordinates (Y doesn't matter)
execute if score num data matches 0 run teleport @e[type=marker,tag=-marker] 0 0 0

#Fill the current section, may not be quite right
execute at @e[type=marker,tag=-marker] run fill ~ -64 ~ ~16 64 ~16 air
execute at @e[type=marker,tag=-marker] run fill ~ 64 ~ ~16 192 ~16 air
execute at @e[type=marker,tag=-marker] run fill ~ 192 ~ ~16 320 ~16 air

#Move the marker to the next section
teleport @e[type=marker,tag=-marker] ~16 ~ ~16

#Increment counters
scoreboard players add reset.x data 1
#The check here is for how wide you want the target area to be, in this case 3 chunks
execute if score reset.x data matches 3 run scoreboard players add reset.y data 1
execute if score reset.x data matches 3 run scoreboard players set reset.x data 0

#Loop unless chunk (2,4) has been reached.
execute if score reset.x data matches 2 if score reset.y data matches 3 run scoreboard players set reset.done data 1
execute unless score reset.done data matches 1 run function e:reset
execute if score reset.done data matches 1 run scoreboard players set reset.done data 0
execute if score reset.done data matches 1 run kill @e[type=marker,tag=-marker]
2
Le_Beholder
09/24/2023 1:44 am
Level 5 : Apprentice Crafter
history
alright. i have learned how to make data packs and functions now.
so there must be something wrong with this code, because ive run a debug on it, and it cannot detect that marker entity..
im also not sure if i set up the scoreboard correctly, because its trying to run these commands 36,000 or so times..

i replaced the air parts with lime wool, and no chunk sized pillars of lime wool showed up either.
worse still, everytime i run /reload more than once after each function call, it lags out my world from running any other commands and takes up alot of processing on my pc, i have to shut down java with taskmanager each time.

I think my 1200 commandblock method, albeit monotonous, would at least accomplish something..
1
-ghost-
09/26/2023 10:34 am
Level 25 : Expert Ranger
I'm guessing it's a problem with my code that keeps it from breaking correctly. I also think that the fill commands may be overloading, because I couldn't immediately determine the limit.

To fix the former, replace the last 3 lines of the function above with this:
execute if score reset.done data matches 1 run kill @e[type=marker,tag=-marker]
execute if score reset.done data matches 1 run scoreboard players set num data 0
execute if score reset.done data matches 1 run scoreboard players set reset.done data 0
1
Le_Beholder
09/26/2023 4:22 pm
Level 5 : Apprentice Crafter
I'll see if these work, I still like your concept though! ive been playing around with it, parsing it out in command blocks.
the fill coords were a bit off, but I've found you just need to subtract one from each coord to get the actual volume of the chunk section, as even though its 16x16 blocks per chunk, the math makes the numbers start from 0. it's weird that way :P

and instead of using marker, I've been using an armor_stand tagged "coord" which helps me visualize it better.

as for teleporting it relative to itself for each position, which i got stuck on at first, I've discovered @s is a useful tool:
" execute as <target> at @s run tp ^ ^ ^1 "
as your line: " execute if score num data matches 0 run teleport @e[type=marker,tag=-marker] 0 0 0 "
wasnt working. @s actually uses the current position and direction of the entity when called.

thats all ive got to in my research thus far, I'm still willing to give your code a shot. especially since ive realized I would have to place not 1200 command blocks, but 4800 of them...
1
-ghost-
09/26/2023 4:41 pm
Level 25 : Expert Ranger
Excellent. That seems strange considering the syntax of the teleport command, but it may be related to the below issue.

Another problem I've noticed is where the marker gets moved to the next chunk. I absentmindedly just sent it in a long diagonal line instead of a rectangle. As a result, replace the line
teleport @e[type=marker,tag=-marker] ~16 ~ ~16
with
scoreboard players operation tmp.x data = reset.x data
scoreboard players operation tmp.y data = reset.y data
, and add these lines right before the "#Loop until..." line
execute if score reset.x data > tmp.x data run teleport @e[type=marker,tag=-marker] ~16 ~ ~
execute if score reset.y data > tmp.y data run teleport @e[type=marker,tag=-marker] ~ ~ ~16
(substituting the marker entity you're using).
1
Le_Beholder
09/26/2023 5:05 pm
Level 5 : Apprentice Crafter
history
btw, i tried replying with my edited version but idk how to add code boxes in these forums.

also when i add back in the line to redo the loop,
" execute unless score reset.done data matches 1 run function e:reset "

it soft crashes my game .. the marker also isnt being deleted after for some reason..

edit:
"(substituting the marker entity you're using)."
lol whoops
1

Welcome