Componency

Componency

A declarative GUI creation library built with/for Kotlin.

by
1.8K Downloads
fabricforgeneoforgelibrary
Rent Server with this Mod

About this Mod

Componency

A simple, declarative UI library built from the ground up for use in any environment.

wakatime


Discord Badge

Ko-Fi Badge
PayPal Badge
GH Sponsors Badge


Inspiration

Componency is roughly based on 3 other things:

I used concepts taken from all 3 of these projects to create a simple, declarative UI library that can be used in any environment.


Disclaimer

This library is primarily designed for Kotlin, though it does have some additional support for Java.

All the examples from here on out will be in Kotlin, but the library can be used in Java as well.


Set up

Repository

Groovy (.gradle)
maven {
    name = "Deftu Snapshots"
    url = "https://maven.deftu.dev/snapshots"
}
Kotlin (.gradle.kts)
maven(url = "https://maven.deftu.dev/snapshots") {
    name = "Deftu Snapshots"
}

Dependency

Repository badge

Groovy (.gradle)
modImplementation "dev.deftu:componency:<VERSION>"
Kotlin (.gradle.kts)
implementation("dev.deftu:componency:<VERSION>")

Usage

Engine

To use the library at all, you need to create your Componency engine. The engine is responsible for providing Componency with any data it needs and giving it the ability to interact with your rendering system of choice.

package com.example

import dev.deftu.componency.engine.Engine
import dev.deftu.componency.engine.InputEngine
import dev.deftu.componency.engine.RenderEngine
import java.awt.Color

class MyEngine : Engine {

    override val inputEngine: InputEngine by lazy {
        MyInputEngine()
    }

    override val renderEngine: RenderEngine by lazy {
        MyRenderEngine()
    }

}

class MyInputEngine : InputEngine {

    override val mouseX: Float = 0f

    override val mouseY: Float = 0f

}

class MyRenderEngine : RenderEngine {

    override val viewportWidth: Int = 0

    override val viewportHeight: Int = 0

    override val animationFps: Int = 144 // Recommended to be no more than 300

    override fun startFrame() {
        // Start rendering frame (apply any transformations, etc.)
    }

    override fun endFrame() {
        // End rendering frame (apply any transformations, etc.)
    }

    override fun fill(x1: Float, y1: Float, x2: Float, y2: Float, color: Color, radius: Float) {
        // Fill a rectangle with a color and a radius
    }

}

Your UI

Now that you have your engine set up, you can start creating your UI.

object Main {
    
    @JvmStatic
    fun main(args: Array<String>) {
        val engine = MyEngine()
        val ui = MyUI(engine)
        
        // Inside your render loop, you can simply call `ui.render()` to render your UI.
        ui.render() // (This is a placeholder for your actual render loop)
    }
    
}

class MyUI(engine: Engine) {
    
    // Common practice is to use a frame as your root component
    private val frame = FrameComponent().configure {
        // In Componency, we define properties inside their own scope when configuring.
        // The majority of the most commonly used properties have extension variables and functions to make them easier to access.
        properties {
            width = 100.percent
            height = 100.percent
        }
    }.makeRoot(engine) // Finally, we make the frame the root component of this UI by giving it the engine.
    
    private val box = RectangleComponent().configure {
        properties {
            x = 25.percent
            y = 25.percent
            width = 50.percent
            height = 50.percent
            color = Color.RED.asProperty
        }
    }.attachTo(frame) // We make the box a child of the frame.
    
    // From here, you can add more components to the frame or the box.

    // Finally, we provide an external means of rendering our frame.
    fun render() {
        frame.handleRender()
    }

}

Further examples

For more examples, you can check out the basic examples directory. (Java, Kotlin)

Or, if you'd like to implement for LWJGL3, you can check out the LWJGL3 example directory.

Setting up in Minecraft

Both modern and legacy Minecraft versions still require the user of the repository defined in the Set up section. The version number is the same for the Minecraft artifacts as it is for the main library.

Modern Minecraft (1.16.5 and above)

It's as simple as defining the dependency in your build script to use the Componency Minecraft engine in modern Minecraft versions.

Groovy (.gradle)
modImplementation "dev.deftu:componency-minecraft-<MINECRAFT VERSION>-<MOD LOADER>:<VERSION>"
Kotlin (.gradle.kts)
implementation("dev.deftu:componency-minecraft-<MINECRAFT VERSION>-<MOD LOADER>:<VERSION>")

Legacy Minecraft (1.12.2 and 1.8.9)

We require additional setup for legacy Minecraft versions, as we need to use a dependency management tweaker to ensure that the latest version of Componency is loaded.

Not only does it handle the version of the library, but it also forces Minecraft to use LWJGL 3 to load NanoVG and STB so that our engine can use both for rendering.

Additional instructions for use alongside other tweakers can be found inside the class file itself.

Groovy (.gradle)
dependencies {
    modImplementation "dev.deftu:componency-minecraft-<MINECRAFT VERSION>-<MOD LOADER>:<VERSION>"
    modImplementation "dev.deftu:componency-minecraft-tweaker-<MINECRAFT VERSION>-<MOD LOADER>:<VERSION>"
}

jar {
    manifest {
        attributes(
            "TweakClass": "dev.deftu.componency.minecraft.tweaker.ComponencyTweaker"
        )
    }
}
Kotlin (.gradle.kts)
dependencies {
    implementation("dev.deftu:componency-minecraft-<MINECRAFT VERSION>-<MOD LOADER>:<VERSION>")
    implementation("dev.deftu:componency-minecraft-tweaker-<MINECRAFT VERSION>-<MOD LOADER>:<VERSION>")
}

tasks.jar {
    manifest {
        attributes(
            "TweakClass" to "dev.deftu.componency.minecraft.tweaker.ComponencyTweaker"
        )
    }
}

Credits


Coming soon!

  • Debugger


This project is licensed under LGPL-3.0
© 2024 Deftu

Available Versions

[Forge 1.19.2] componency 0.3.0beta
MC 1.19.2forge
August 27, 2024
[Fabric 1.20.1] componency 0.3.0beta
MC 1.20.1fabric
August 27, 2024
[Fabric 1.20.2] componency 0.3.0beta
MC 1.20.2fabric
August 27, 2024
[Fabric 1.17.1] componency 0.3.0beta
MC 1.17.1fabric
August 27, 2024
[NeoForge 1.20.4] componency 0.3.0beta
MC 1.20.4neoforge
August 27, 2024

How to Install Componency on Your Server

1

Order Server

Order a Minecraft Java server with at least 3 GB RAM (4 GB recommended).

2

Set fabric Loader

In the panel under "Egg", select the fabric loader and matching Minecraft version (1.21).

3

Install Mod

Open the mod browser in the dashboard and search for "Componency". Click "Install" – done! Alternatively, upload the .jar via SFTP to the /mods folder.

Compatibility

Mod Loaders

fabricforgeneoforge

Minecraft Versions

1.21, 1.20.6, 1.20.4 (+9 more)

Server-side

Unsupported

Recommended RAM

4 GB(min. 3 GB)

Frequently Asked Questions

Componency server crashes on startup – what to do?

Most common cause: wrong fabric version or insufficient RAM. Check the server log (latest.log) for "OutOfMemoryError" or "Mixin" errors. With Mado Hosting: ensure at least 3 GB RAM is allocated and the loader matches the mod version (1.21). You can switch loaders with one click in the panel.

Is Componency compatible with fabric and forge and neoforge?

Componency officially supports fabric, forge, neoforge for Minecraft 1.21, 1.20.6, 1.20.4. Note: Forge and Fabric mods are NOT cross-compatible – pick one loader and stick with it. The Mado dashboard automatically detects incompatible loader combinations.

Server lagging with Componency – how to optimize performance?

Recommended RAM: 4 GB (per 8 players). Use /spark profiler to check if Componency consumes the most tick time. Common fixes: reduce server view-distance to 8-10, install "performant" or "starlight" as supplementary mods on Forge. With Mado Hosting, your server runs on NVMe SSDs with dedicated CPU cores for minimal latency.

Rent Modded Server

Install Componency with just one click on your server.

Recommended RAM
4 GBab €8/mo
Min. 3 GB | +1 GB pro 8 Spieler
Create Server Now
1-Click Mod Install
NVMe SSD Storage
DDoS Protection included

Details

License
GNU Lesser General Public License v3.0 or later
Server-side
Unsupported

Supported Versions

1.211.20.61.20.41.20.21.20.11.19.41.19.21.18.21.17.11.16.5+2 more