Skip to content

A utility library for Minecraft modding that provides cross-version compatibility APIs.

License

Notifications You must be signed in to change notification settings

StellariumMC/Knit

Repository files navigation

Knit

A utility library for Minecraft modding that provides cross-version compatibility APIs. Knit is a fork of Deftu's OmniCore library, designed to work across multiple Minecraft versions and mod loaders.

Features

  • Command system - Powerful DSL for building commands using Brigadier
  • Event bus - Simple and efficient event system
  • Input handling - Unified keyboard and mouse APIs
  • Text components - Easy text formatting and manipulation
  • Screen API - Simplified GUI creation
  • Utility functions - Number formatting, string operations, and more

Versions

Maven Central Version

Maven Central Version Maven Central Version

Maven Central Version Maven Central Version Maven Central Version

Maven Central Version Maven Central Version Maven Central Version

Maven Central Version Maven Central Version Maven Central Version

Maven Central Version

Installation

Adding Knit to your project:

Gradle (Kotlin DSL)

repositories {
    mavenCentral()
}

dependencies {
    // Replace VERSION and MINECRAFT_VERSION with your target versions
    modImplementation("xyz.meowing:knit-MINECRAFT_VERSION-LOADER:VERSION")
}

For example, for Minecraft 1.20.1 on Fabric:

modImplementation("xyz.meowing:knit-1.20.1-fabric:110")

Usage Examples

Commands

Create commands with an intuitive DSL:

object Command : Commodore("mycommand", "alias") {
    init {
        literal("param") {
            runs { name: String ->
                KnitChat.fakeMessage("Hello, $name!")
            }
        }

        literal("param2") {
            runs { x: Float, y: Float, z: Float ->
                println("$x, $y, $z")
            }
        }
        
        runs { 
            println("no parameters passed!")
        }
    }
}

// Register the command
command.register(dispatcher)

Events

Register event handlers with priority support:

val eventBus = EventBus()

class MyCustomEvent : CancellableEvent()

eventBus.register<MyCustomEvent> { event ->
    println("Event fired: $event")
    if (someCondition) {
        event.cancel() // If using CancellableEvent
    }
}

// Post events
eventBus.post(MyCustomEvent())

Text Components

Build formatted chat messages easily:

val message = KnitText
    .literal("Hello world!")
    .onHover("!dlrow olleH")
    .onClick(ClickEvent.RunCommand("/explode"))
    .toVanilla()

KnitChat.fakeMessage(message)

val message = buildText {
    text("Click here") {
        blue()
        bold()
        underlined()
        onClick("https://example.com")
        onHover("Opens example.com")
    }
    text(" to visit our website!") {
        gray()
    }
}

KnitChat.fakeMessage(message.toVanilla())

Screen Creation

Create custom screens:

class MyScreen : KnitScreen("My Custom Screen") {
    override fun onInitGui() {
        // Initialize your screen
    }
    
    override fun onRender(mouseX: Int, mouseY: Int, deltaTicks: Float) {
        // Render your screen
    }
    
    override fun onMouseClick(mouseX: Int, mouseY: Int, button: Int) {
        // Handle mouse clicks
    }
    
    override fun onMouseMove(mouseX: Int, mouseY: Int) {
        // cool stuff
    }
    
    override fun onKeyType(typedChar: Char, keyCode: Int, scanCode: Int) {
        // Handle keyboard input
    }
}

Utilities

Format numbers and strings:

val abbreviated = 1_500_000.abbreviate() // "1.5M"
val withCommas = 1500000.formatWithCommas() // "1,500,000"
val camelCase = "hello world".toCamelCase() // "helloWorld"

Input Handling

Check keyboard and mouse state:

if (KnitKeys.KEY_SPACE.isPressed) {
    println("Space bar is pressed!")
}

if (KnitMouseButtons.LEFT.isPressed) {
    val x = KnitMouse.Scaled.x
    val y = KnitMouse.Scaled.y
    println("Left mouse button pressed at ($x, $y)")
}

License

Knit is licensed under the GNU General Public License v3.0. See LICENSE for more information.

Credits

  • Deftu - Original OmniCore library
  • Stivais - Commodore command system
  • StellariumMC - Knit fork and maintenance

The command system (xyz.meowing.knit.api.command package) contains modified code from the Commodore library by Stivais.

About

A utility library for Minecraft modding that provides cross-version compatibility APIs.

Resources

License

Stars

Watchers

Forks