Minecraft Data Packs / Technology

DPlib Datapack Library

  • check_circle Functions
  • check_circle Predicates
  • 2,465 views, 1 today
  • 45 downloads, 0 today
  • 6
  • 5
  • 5
Z0rillac's Avatar Z0rillac
Level 47 : Master Carrot
32

Datapack library

DPlib is a function library for datapack developed in mcfunction. It is designed so that you can directly include the module you want in your datapack, without worrying about performance or compatibility and without creating dependencies. It is designed for performance and simplicity, it can be used in any datapack requiring simple or complex functions while being as fast as possible.

This library contains:
  • dplib.math
    - Number-theoretic and representation
    - Power and logarithm
    - Trigonometry
    - RNG and LCG
    - Other various functions
  • dplib.datetime
    - Real world date and time
    - Local time
    - Time and duration calculation
    - Time conversion
  • dplib.threading
    - Code threading with contextual entities
    - Hierarchical threading
    - Scoreboard ID
  • dplib.benchmark
    - Benchmarking for development only

How it works


You just need to import the module(s) you need (they work independently) into the data folder of your datapack, you then need to load it by executing this command at the beginning of your datapack load file :
function dplib.<module>:loadYou may also need to tick the module, if so add this to the beginning of your tick file :
function dplib.<module>:tickTo ensure proper de-installation, you must include this line in the uninstallation file :
function dplib.<module>:uninstallIn general, the input scoreboard for parameters is `dplib.<module>.in` and the output scoreboard is `dplib.<module>.in`. The automatically managed variables are in `dplib.<module>.main`

For example, you can calculate how far away the nearest cow is:
# Puts the player's coordinates in parameters of the function
execute as Someone store result score $x1 dplib.math.in run data get entity @s Pos[​0]
execute as Someone store result score $y1 dplib.math.in run data get entity @s Pos[​1]
execute as Someone store result score $z1 dplib.math.in run data get entity @s Pos[​2]
# Puts the nearest cow coordinates in parameters of the function
execute at Someone as @e[​sort=nearest,type=cow,limit=1] store result score $x2 dplib.math.in run data get entity @s Pos[​0]
execute at Someone as @e[​sort=nearest,type=cow,limit=1] store result score $y2 dplib.math.in run data get entity @s Pos[​1]
execute at Someone as @e[​sort=nearest,type=cow,limit=1] store result score $z2 dplib.math.in run data get entity @s Pos[​2]
# Calculates the distance using a tool provided by this library
function dplib.math:tools/distance
# Displays the result above the player's hotbar
title Someone actionbar [{"text":"Nearest Cow : ","color":"red"},{"score":{"name":"$out","objective":"dplib.math.out"},"color":"yellow"},{"text":"m","color":"yellow"}]


Or you can simply get the real world timestamp live:

scoreboard players get unix_timestamp dplib.datetime.main
This library is made to be used with Data-pack Helper Plus extension, it is easier to find the functions thanks to the auto completion provided by the extension and a library of aliases.

The complete documentation can be found here.

It is advisable to credit the project :
This datapack uses DPlib
https://github.com/Z0rillac/DPlib
CompatibilityMinecraft 1.20
Tags

2 Update Logs

Update v1.2.1 : by Z0rillac 06/13/2023 10:01:49 amJun 13th, 2023

Changelog

  • Added an icon if DPlib is used as a dependency.
  • Fix the dplib.threading documentation. Some terms were still in the old version.
  • Fix of dplib.threading:hierarchy/set_chilf_of and dplib.threading:hierarchy/set_parent_of, the target was not setting up.
LOAD MORE LOGS

Create an account or sign in to comment.

2
06/13/2023 2:40 pm
Level 68 : High Grandmaster Bear
Silabear
Silabear's Avatar
How do you get the date? I understand how to get time, but for date?
1
06/14/2023 9:47 amhistory
Level 47 : Master Carrot
Z0rillac
Z0rillac's Avatar
When you place a player's head with a skullowner nbt, the server creates an nbt with a signature (probably related to a microsoft or mojang security) in base64 and an nbt with the player's skin and other info like the player's name and timestamp, all also encoded in base64. All you have to do is decode the few characters containing the timestamp. You can then convert this timestamp using a timestamp to datetime function.
One problem is that getting the timestamp this way is only done once per minecraft account per month. The timestamp is therefore get on loading and automatically updated every second with local time. That's why the timestamp is updated every tick, and why you don't need to call any functions to get it, but only get it from a scoreboard, and why there's a huge 1Mb file containing 8192 minecraft accounts, in the hope that nobody reloads their world more than 270 times a day.

And if you're just looking to get that value because I may have misstated it in the doc, here you go:

scoreboard players operation $timestamp dplib.datetime.in = unix_timestamp dplib.datetime.main
function dplib.datetime:conversion/timestamp_to_datetime

and you can display it like this

tellraw @a ["",{"text":"year = "},{"score":{"name":"$year","objective":"dplib.datetime.out"}},{"text":"\nmonth = "},{"score":{"name":"$month","objective":"dplib.datetime.out"}},{"text":"\ndate = "},{"score":{"name":"$date","objective":"dplib.datetime.out"}},{"text":"\nhour = "},{"score":{"name":"$hour","objective":"dplib.datetime.out"}},{"text":"\nminutes = "},{"score":{"name":"$minutes","objective":"dplib.datetime.out"}},{"text":"\nseconds = "},{"score":{"name":"$seconds","objective":"dplib.datetime.out"}}]
https://github.com/Z0rillac/DPlib/blob/main/data/dplib.datetime/DOCS.md#dplibdatetimeconversiontimestamp_to_datetime
1
06/14/2023 10:00 am
Level 47 : Master Carrot
Z0rillac
Z0rillac's Avatar
And if you think it's cool, can you star it on github, I'd like more people to take an interest in it considering the time I'm spending on it.
2
04/11/2023 8:59 am
Level 57 : Grandmaster uwu
amandin
amandin's Avatar
that is just amazing. i wonder if you can calculate sine and cosine with it
1
04/11/2023 9:19 am
Level 47 : Master Carrot
Z0rillac
Z0rillac's Avatar
You can ! There is documentation implemented in the code and on the GitHub page that tells you how.Note that a very big new version allowing faster more precise math, more efficient threading, random benchmarking is currently in development.I recommend that you download the pack on the project's GitHub page instead of the one on the planet Minecraft page, because the one on the GitHub page is not finished but much more complete, and corresponds to a new code architecture divided in modules that you will have to use for the next versions of dplib. I also recommend that you check very often if new versions or new commits of the library are released because dplib is currently in an important phase of development.
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome