- check_circle Functions
- 3,295 views, 3 today
- 216 downloads, 0 today
7
Dynamic Worldborder Datapack
This datapack allows you to change the size and center of the worldborder based on a scoreboard value! This is a powerful utility that could be used for many different projects without much/any modification. See below for documentation:
The pack will automatically change the size of the worldborder when it detects that the "set" size has been altered.
You CAN manually set the border as well! The pack will only alter the worldborder size when the score is changed. This flexibility allows for you to mix hardcoded, preset size values with a dynamic system, for example. Border size changes take effect instantly. Smooth border expansion and contraction can be emulated by adding a small value to the border size on a clock, but this isn't a perfect solution obviously.
To recenter the border, you must alter one or both of the center values, before manually calling the function.
Unfortunately, the destination of the new worldborder center must be loaded!
Feel free to modify, reverse engineer, use in your projects, etc., but please do not redistribute without credit!
This datapack allows you to change the size and center of the worldborder based on a scoreboard value! This is a powerful utility that could be used for many different projects without much/any modification. See below for documentation:
Altering Worldborder Size
/scoreboard players set .wb_set igt.dywb ####
#### = Desired Size
#### = Desired Size
Altering Worldborder Center Location
/scoreboard players set .cx igt.dywb ####
/scoreboard players set .cz igt.dywb ####
/function igt.dywb:recenter_border
#### = X/Z Values of Desired Center
/scoreboard players set .cz igt.dywb ####
/function igt.dywb:recenter_border
#### = X/Z Values of Desired Center
The pack will automatically change the size of the worldborder when it detects that the "set" size has been altered.
You CAN manually set the border as well! The pack will only alter the worldborder size when the score is changed. This flexibility allows for you to mix hardcoded, preset size values with a dynamic system, for example. Border size changes take effect instantly. Smooth border expansion and contraction can be emulated by adding a small value to the border size on a clock, but this isn't a perfect solution obviously.
To recenter the border, you must alter one or both of the center values, before manually calling the function.
Unfortunately, the destination of the new worldborder center must be loaded!
Feel free to modify, reverse engineer, use in your projects, etc., but please do not redistribute without credit!
Compatibility | Minecraft 1.19 |
Tags |
1 Update Logs
Update #1 : by Igtarr 01/15/2023 9:00:27 pmJan 15th, 2023
Fixed bug that occurred when manually setting the size of the WB
Improved Implementation - efficiency increased from O(n) to O(1)
Improved Implementation - efficiency increased from O(n) to O(1)
5809276
119
Create an account or sign in to comment.
One thing I noted is that you are using a loop function to resize the world border.
I think you can get rid of it by using binary coding. What I mean is to consider the expansion amount as a sum of powers of 2 (14 = 8*1 + 4*1 + 2*1 + 1*0). This way, you just need to do
execute if score dir WBscore matches 1 if score resize WBscore matches 2^i.. run worldborder add 2^i
and you repeat it for i going from 0 up to 25 and that should cover all existing cases. It will probably take less commands than a loop in base 10.execute if score dir WBscore matches -1 if score resize WBscore matches 2^i.. run worldborder add -2^i
execute if score resize WBscore matches 2^i.. run scoreboard players remove resize WBscore 2^i
I was also able to remove the dir variable entirely with the following header before the binary encoding
worldborder set 1
scoreboard players remove .wb_set igt.dywb 1
execute if score .wb_set matches 2^i.. run worldborder add 2^i
.
.
etc.