For Developers - Viola-Siemens/Tetrachord-Lib GitHub Wiki

Quick Start

To begin with, add tetrachord lib to dependencies in build.gradle. You can use cursemaven, modrinth maven or github packages.

Examples:

CurseMaven:

repositories {
//...
    maven {
        url "https://cursemaven.com"
        content {
            includeGroup "curse.maven"
        }
    }
//...
}
dependencies {
//...
    implementation fg.deobf("curse.maven:tetrachordlib-980149:5142799")   //v1.18+1.0.1
//...
}

Modrinth:

repositories {
//...
    maven {
        name = "Modrinth"
        url = "https://api.modrinth.com/maven"
        content {
            includeGroup "maven.modrinth"
        }
    }
//...
}
dependencies {
//...
    implementation fg.deobf("maven.modrinth:tetrachordlib:1.18+1.0.1")
//...
}

GitHub Packages:

repositories {
//...
    maven {
        name = "Github Packages"
        url = uri("https://maven.pkg.github.com/Viola-Siemens/Tetrachord-Lib")
        credentials {
            username System.getenv("GITHUB_USERNAME")
            password System.getenv("GITHUB_TOKEN")
        }
    }
//...
}
dependencies {
//...
    implementation fg.deobf("com.hexagram2021.tetrachordlib:tetrachordlib:1.18+1.0.1")
//...
}

What is ...?

KD Tree

Wiki of KD Tree

The KD Tree is a data structure utilized in high-dimensional spaces for the storage and organization of k-dimensional data points. Functioning as a binary tree, each node within the KD Tree represents a k-dimensional data point and is partitioned according to the feature values (dimensions) of the data point. KD trees are particularly well-suited for conducting range queries and nearest neighbor searches within high-dimensional datasets, and they can also contribute to optimizing data retrieval within the Minecraft world.

Segment Tree

Wiki of Segment Tree

The Segment Tree is a data structure utilized for handling range updates and queries. It divides a segment into smaller subsections and organizes them hierarchically in a tree structure. Segment trees are efficient for updating and querying data ranges. In the context of a Minecraft world represented as a 3D tensor, employing a segment tree can greatly improve performance when frequent range updates and queries are involved.

Use a data structure in your mod

KD Tree

Here's some useful API for you to work with a KD Tree:

KDTree$newLinkedKDTree(int dimensionSize)

This function is equal to new LinkedKDTree(int dimensionSize). It creates a KD Tree with size dimensionSize for you.

size and isEmpty

This two functions show how many k-dimensional points are added in the KD Tree and if the tree is empty.

clear

Remove all nodes from the KD Tree.

build

Build a balanced KD Tree from an array. All previous nodes will be removed.

insert and remove

Insert a node into or remove a node from the KD Tree. It may damage balance of the tree, but after a few operations, the tree will rebalance itself.

getDimensionSize

Get the dimension size of the KD Tree. The dimension size is the only parameter you used to construct the KD Tree.

preDfs, inDfs, postDfs and bfs

Visit the binary tree in preorder, in-order, postorder and level order.

findClosest and findFarthest

Find the closest or farthest k-dimensional point with target in this KD Tree. This only takes: $$O(n^\frac{k-1}{k})$$

Segment Tree

Let's take the example of SegmentTree2D, here's some useful API for you to work with it:

edit(T delta, int beginX, int endX, int beginY, int endY)

Edit an area of value, for example, add delta or set to delta - it depends on the edit rule.

query(int beginX, int endX, int beginY, int endY)

Query the combination of an area, for example, sum or max value - it depends on the edit rule.

visit(int beginX, int endX, int beginY, int endY, VisitConsumer consumer)

Visit an area and consume all the values.

SegmentTree2D$newArrayQuadSegmentTree2D

Create a 2D array quad segment tree. You can get prefab edit rules in EditRules.

Examples

Improved "No Hostiles Around Campfire"

Improved "Ore Blocks Near Beacon Increase Xp Drop"