- This library may only be used as a dependency in software projects.
- Modification is prohibited. (Pull Requests are allowed)
- This library is allowed to be repackaged, unmodified, into your own binaries for distribution.
- Repackaging as shown below with the Gradle Shadow plugin is allowed, and encouraged.
- Redistribution of this library as a standalone product is prohibited.
- Attribution is not required.
- ModDevGradle is recommended.
- (version 1.0.1 is being used for this example)
- The gradle shadow plugin is recommended.
plugins {
...
id 'net.neoforged.moddev' version "${mdg_version}"
id 'com.gradleup.shadow' version '8.3.3'
}
...
configurations {
shade
}
...
shadowJar {
archiveClassifier.set('')
configurations = [project.configurations.shade]
relocate 'tamaized.beanification', 'your.package.beanification'
}
...
repositories {
...
maven {
name 'Beanification'
url 'https://maven.tamaized.com/releases/'
}
}
...
dependencies {
...
def beanification = "tamaized:beanification:${project.minecraft_version}-${project.beanification_version}"
implementation beanification
shade beanification
testImplementation "${beanification}:tests"
testCompileOnly "${beanification}:test-sources"
}
...
build.dependsOn shadowJar
In your main @Mod
class
import tamaized.beanification.BeanContext;
import tamaized.beanification.Autowired;
import java.beans.beancontext.BeanContext;
@Mod("modid")
public class YourMod {
static {
// (Optional) Configure the BeanContext, must be called before #init
BeanContext.configure()
.configurableSettings().disableRenderer()
.configurableSettings().disableEntity();
// General Setup
BeanContext.init();
// This overload can be used instead to register beans directly
BeanContext.init(context -> {
context.register(YourComponent.class, new YourComponent());
context.register(YourComponent.class, "someName", new YourExtendedComponent());
});
}
@Autowired
private YourComponent yourComponent; // Injected at runtime, not actually null.
@Autowired("someName")
private YourComponent yourNamedComponent; // Will be an instance of YourExtendedComponent
public YourMod() {
// Enables @Autowired to function with non-static fields in the main @Mod class
BeanContext.enableMainModClassInjections();
}
}
For further details, view the javadoc for:
- Autowired
- Bean
- Component
- PostConstruct
- Configurable