Skip to content

v3 entry

ocpu edited this page Aug 10, 2020 · 3 revisions

Class

The class method is the "normal" way as this method reflects the Java entry point. If you plan on only using this method of entry you don't even need Boxlin. The instance of your mod retrieved from BoxlinContext.get().instance or casted to your class like BoxlinContext.get().instance<ExampleMod>().

import net.minecraftforge.fml.common.Mod

@Mod("examplemod")
class ExampleMod {
  init {
    // Your init code like registering event listeners
  }
}

Object

The object method has the advantage to the class method that the object is the instance of your mod. You can read up on objects here.

import net.minecraftforge.fml.common.Mod

@Mod("examplemod")
object ExampleMod {
  init {
    // Your init code like registering event listeners
  }
}

Function

With the function you do not even declare a class or object as a entry point it is just a function. This can give you a fully functional based start to your mod. The instance of your mod retrieved from BoxlinContext.get().instance.

import io.opencubes.boxlin.adapter.FunctionalMod

@FunctionalMod("examplemod")
fun exampleMod() {
  // Your init code like registering event listeners
}

Shorthands

There are various shorthands which make the example explicit. Like stripping away the string that defines the mod id in the annotation and getting the mod context as a parameter. (From the Getting Started example)

// Removed annotation string with id, but have to
// name the function as the mod id.
@FunctionalMod
// Set the receiver type to be the mod context so
// we can use it without the with function
fun BoxlinContext.example() {
  addListener<RegistryEvent.Register<Item>>() {
    println("REGISTER ITEMS WITH EVENT")
  }
  // Removed the listener = and replaced as only
  // the function
  addListener(::registerBlocks)
}

fun registerBlocks(event: RegistryEvent.Register<Block>) {
  println("REGISTER BLOCKS WITH EVENT")
}

Next up

  1. Getting Started
  2. All the Features

Clone this wiki locally