Minecraft Data Packs / Server Utility

Dynamic Worldborder (with Scoreboards!)

  • check_circle Functions
  • 3,288 views, 1 today
  • 216 downloads, 0 today
  • 5
  • 4
  • 2
Igtarr's Avatar Igtarr
Level 36 : Artisan Engineer
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:
Altering Worldborder Size
/scoreboard players set .wb_set igt.dywb ####

#### = 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

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!
CompatibilityMinecraft 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)

Create an account or sign in to comment.

Lordphenex
01/10/2023 7:28 am
Level 40 : Master Miner
Lordphenex's Avatar
That's a great datapack that can be useful for server owners !

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
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
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.
3
Igtarr
01/15/2023 9:06 pm
Level 36 : Artisan Engineer
Igtarr's Avatar
Thank you! I circled a solution similar to this before I ended up going for the O(n) implementation, though I admit yours is better. Datapack has been updated to be more efficient as described above!

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.
4
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome