-
Notifications
You must be signed in to change notification settings - Fork 1
v3 features
Boxlin provides some utility functions and objects to existing code to make it more "Kotlin friendly". What it means is that Boxlin might for instance have a function for making using configuration values more friendly with the use of delegates. The aim is not to have Boxlin be a "core" mod that might introduce functions for rendering, a new configuration system, and so on.
The API for the configurations can be a hassle if you do not want to expose the raw instance of the config value. This can be fixed with Kotlin delegates giving you minimal effort to just hide the instance of the config value and having a configuration with the direct values to strings, booleans, etc.
This is a example in how you could create a configuration object.
import io.opencubes.boxlin.getValue
import io.opencubes.boxlin.setValue // If a delegate is declared with var
import net.minecraftforge.common.ForgeConfigSpec
object MyConfig {
private val builder = ForgeConfigSpec.Builder()
// Lazily build the config when it is needed
val spec: ForgeConfigSpec by lazy {
Machine // Init MyMachine config
builder.build()
}
val sayHello: Boolean by builder.define("sayHello", true)
object MyMachine {
init {
builder.push("myMachine")
}
val maxFE: Float by builder.define("maxFE", 1000.0f)
init {
builder.pop()
}
}
}Later when registering the config just reference MyConfig.spec.
If you are creating a proxy with the normal DistExecutor.runForDist you can run into a really verbose way of specifying it.
val proxy: IProxy = DistExecutor.runForDist(
{ Supplier { ClientProxy() } },
{ Supplier { ServerProxy() } }
)With a utility function with the same name runForDist you can shorten it to.
import io.opencubes.boxlin.runForDist
val proxy = runForDist(::ClientProxy, ::ServerProxy)And it will have the same effect as the one above.