Minecraft Data Packs / Adventure

Perasha Utilities

  • check_circle Functions
  • 10,276 views, 0 today
  • 2,393 downloads, 0 today
  • 11
  • 10
  • 2
Perasha's Avatar Perasha
Level 46 : Master Engineer
This little pack provides some common functionality that I'll be using for future packs; you'll need it if you want to download my newer packs!

And if you'd like, feel free to use the pack for your own purposes as well, see more of that below :)

Technical Stuff

Here are the major little things that this pack includes, and why I've included them.

Trackloading is a method of making easier and more reliable use of /forceload. It's the biggest part of the utilities pack and the main reason I needed to create it; I am not copying the same code over and over again for new projects. It basically saves a location and marks it to forceload it, and keep it forceloaded.

I found out quickly that forceloaded chunks, for some reason or another, aren't really saved when a player exits their world, or a server is restarted. A player would have to forceload the same location, or manually walk over to it to be able to load the area again.

This isn't a problem if forceloaded locations are relatively close, but once you start getting a few hundred blocks away from the spawn, things start breaking down. There was originally a quick fix for this, that's much better described with Swifter1243''s video, but this is slightly broken as of now; putting in one coordinate that gets too far away puts the entity too far to further modify.

So, I eventually did use a bit of Swifter's method with saving an entity's coordinates to one that remains at the world center, and use those coordinates to find the entity I want, and we can do that with what I call "trackloading".

How it Works
When a region is marked to be forceloaded, it loads the chunks instantly. This means that we can teleport an entity there without losing it and being unable to edit it. So, we can make a marker, forceload a chunk ahead of it, teleport it there, and unload the previous chunk that it was in. It's kind of like laying down train tracks in front of you as your train is moving forward, and picking up the ones behind you.

So, to apply this, we have an entity which we want to make sure remains loaded. First, we save its location as scoreboard scores to an entity, a Save, that stays in the world center (We also make sure to give both of them unique ID's, so if our entity dies, we can kill its save). When the world is loaded, we look at the X and Z values that are saved, and start to head in one of the two directions. To save time, we can jump in halves, kind of like a binary search algorithm. Once we finish travelling in one direction, we start trackloading in the other direction, and once we reach the chunk, we /forceload the place where our loading marker is. And boom! Our region that's supposed to be forceloaded is properly loaded.

Let's say our destination is at x = 894 and z = -1207. Before we begin, we create an entity at the world origin, 0 0 0. Now, we can start with heading in the positive X direction. We can only jump in pre-defined distances, so we can't just /forceload ~894 ~. Otherwise, that same distance will be called every time we want to find a different location. So, instead, we can jump in multiples of 2; 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, up to 4096 for this particular datapack (because I've had to make a seperate function for each distance... maybe in the future that'll change? If we get new commands...). So, starting with the highest number, we compare our destination with a jump distance. If our jump distance is greater than our destination, we move on to the next lowest distance. For 894, the next lowest distance is 512, so we can /forceload ~512 ~ to lay down our first track, teleport our entity 512 blocks forward in the x direction, keeping track of how far we've gone by keeping a scoreboard, and unloading the chunk we were just at. Now we can compare our new distance to the destination, which is 382 blocks away. Since 256 is the next lowest jump, we forceload 256 blocks forward, teleport our marker, and unload the previous chunk again. Rinse and repeat until we can't teleport forward anymore! Once we do that in the X direction, we do it again for the Z, and boom! We've made it to our destination.

How to use it:
In your function, just add a line similar to this:
execute as @e[insert entity here] run function utility:trackload/save_location

And that's pretty much it! When you reload the world the pack will give you a loading message and another when it finishes.

Admittedly, the more datapacks that use this, the longer these loading times will be, until forceloaded regions persist through server resets.

The pack also includes a Counter, timer, and x,y, and z position scoreboards.

Out of the box, the pack is running a 3-tick timer; in the future I might also add several other timers, but for now I'm just keeping the one.

Other Functions
More functions will be added in time, but for now there's really only the get_coords function within the trackloading section; I use it for just trackloading, but you might be able to use it for other things as well! All it does is save an entity's position as scoreboard values.

CompatibilityMinecraft 1.13
toMinecraft 1.16

2 Update Logs

Update #2 : by Perasha 12/05/2020 2:06:53 pmDec 5th, 2020

Loading message should now say Perasha Utilities instead of KTarek utilities, with proper coloring

Create an account or sign in to comment.

05/15/2021 12:35 am
Level 1 : New Miner
R4P0SAOM4F1OS0's Avatar
(working now:})it is not working, i installed it with the second data pack together and it still didn't work (minecraft java 1.16.5)

I just used the "/function teleporter_unstall" and "_update after and worked
11/14/2020 4:20 am
Level 1 : New Miner
ruzgargamebro's Avatar
dude your datapacks are so usefull and great

for example your teleporter pack is was the datapack i wanted
Planet Minecraft


© 2010 - 2024