Home - MinecraftPhi/MinecraftPhi-modules GitHub Wiki

Minecraft Phi - Shared Utilities for Minecraft Datapacks

Phi is a library of utilities for minecraft datapacks that intends to unify data storage and manipulation in minecraft 1.14+

Phi is split into multiple optional modules that each add some piece of functionality. There are plans to create a transpiler with direct support for Phi to ease the use of various advanced features.

Setup

Each module contains a datapack that can be added to the datapacks folder of your world. In the future some modules will not be able to be downloaded from the repo as they will require the transpiler, however for now all modules are currently distributable, meaning they are already in the standard datapack format.

Upon loading the world, or on /reload, players will be prompted to complete the setup by clicking on the message, which will show every 5 seconds until the setup is complete. This can only be done by operators, and causes the chunk at block (-30000000, 1600) to be force loaded (chunk -1875000, 100), in every dimension.

Usage

Phi adds 4 blocks to the world for various uses that are shared between datapacks:

  • (-30000000 0 1600): A jukebox with an item in it
  • (-30000000 0 1601): A command block running a function tag
  • (-30000000 0 1602): A yellow shulker box
  • (-30000000 0 1603): A sign

Some bedrock is also placed directly above these blocks to protect them.
These blocks must not be destroyed by any datapack, at any point, for any reason.
The rest of the chunk, from y=2 and above, is freely available for any use by datapacks. However, these blocks can not be expected to remain untouched by other datapacks, this area is for temporary storage only.

Storage

Phi uses command NBT storage for storing data that cannot be stored in a score. Each module uses storage phi.<module>, meaning each module uses a separate file on disk, making cleanup simpler and reducing the performance impact of accessing storage. Note that this is NOT phi:<module> which would put all modules into a single file on disk.

The following <namespace>:<key> pairs are used in phi:

  • phi.<module>:temp, parameters and return values of functions, not expected to last beyond the current function call
  • phi.<module>:global, long term storage of non-score values

Jukebox

The jukebox located at (-30000000 0 1600) is for data storage. It contains an item with a tag tag. Use of the jukebox is not recommended, it is kept for backwards compatibility only. All uses of the jukebox have been moved to storage.

All accesses to the jukebox data should be in the form:

RecordItem.tag.<namespace>...

Where <namespace> is your namespace being used in your datapack(s). This is done to prevent conflicts between datapacks.
The ... can be any NBT path, anything within this is completely under the control of your datapack.

This block is used for storing any data that cannot be stored on the scoreboard, e.g. strings like enchantment ids, or entire NBT compounds like items. However, it is recommended to still use the scoreboard whenever possible, because the scoreboard is more performant.

Command Block

The command block at (-30000000 0 1601) is a repeating command block running a function tag. Each dimension runs a different tag:

  • Overworld: #phi.core:overworld_bp_tick
  • The Nether: #phi.core:nether_bp_tick
  • The End: #phi.core:end_bp_tick

Each of these tags also contains the tag #phi.core:dimension_bp_tick by default, and as such this tag will run multiple times in one tick, once for each dimension. These function tags can be hooked into by a datapack to run functions after entity summoning is completed for the current tick.
These command blocks must never be modified.

Yellow Shulker Box

The shulker box at (-30000000 0 1602) is used for player inventory manipulation. This involves copying the player's inventory to the shulker box, manipulating the data in the shulker box, then using a custom loot table combined with /loot to put the items back in the player's inventory.

The shulker box must be a yellow shulker box, not any other colours, as the loot table is specifically overriding the yellow shulker box mined loot table

Usage of this is described in player inventory manipulation

Sign

The sign at (-30000000 0 1603) is used for resolving advanced JSON text components to be copied into text components that only allow formatting and text. Just apply the json text to the sign using whatever method you wish, and then copy the result to another location using

data modify ... set from block -30000000 0 1603 Text1

Phi also uses an entity with the UUID of ec-0-0-0-1, for various utilities. At the end of every tick it will make sure the entity is in the loaded chunk, and has not been killed. DO NOT kill this entity, Phi and many datapacks using Phi rely on this entity existing. If you do kill this entity, it will be summoned again at the end of the tick, so everything should recover in one tick, but things may glitch or fail while this entity is dead.

Function Tag Hooks

Phi supplies some function tags to hook into certain events in the lifecycle of the game

On Load

  • #phi.core:load: runs once on world load and on /reload. This runs after Phi creates the shared objectives, but may run before the Phi forceloaded chunks are loaded.
  • #phi.core:full_load: runs once after all Phi forceloaded chunks are actually loaded and ready to be used
  • #phi.core:initiated: runs only once, the first time all Phi forceloaded chunks are loaded, and never runs again, even after a world load or /reload. The only way to make it run again is by running phi.core:resetup
  • #phi.core:overworld_load, #phi.core:the_nether_load, #phi.core:the_end_load: runs once on world load or on /reload after the chunk in the associated dimension is loaded. Runs in the associated dimension
  • #phi.core:dimension_load: runs 3 times on world load or /reload, once for each Phi chunk as it becomes loaded

Each tick

  • #phi.core:tick: runs once each tick, but only if all Phi chunks are loaded
  • #phi.core:overworld_tick, #phi.core:the_nether_tick, #phi.core:the_end_tick: runs once each tick, in the associated dimension, but only if the Phi chunk in the associated dimension is loaded
  • #phi.core:dimension_tick: runs up to 3 times each tick, once in each dimension, but only if the Phi chunk in that dimension is loaded
  • #phi.core:tick_end: runs once each tick, at the latest time in the tick possible. Only runs if all Phi chunks are loaded. Exact timing of when this occurs may change as new techniques are found to make it run later in the tick.
  • #phi.core:overworld_bp_tick, #phi.core:the_nether_bp_tick, #phi.core:the_end_bp_tick: runs once each tick, during block processing, in the Phi chunk in the associated dimension, but only if the associated chunk is loaded. Block processing occurs after entity processing, which can come in handy for manipulating entities in the same tick they are spawned. Since the Phi chunks are so far away from the origin these tags are likely to run after most other block processing has already occurred, however, this is not guaranteed
  • #phi.core:dimension_bp_tick: runs up to 3 times each tick, once in each dimension, but only if the Phi chunk in that dimension is loaded. Runs during block processing for the associated dimension

Modules

⚠️ **GitHub.com Fallback** ⚠️