-
-
Notifications
You must be signed in to change notification settings - Fork 64
Addon Development: Operators
Operators in Integrated Dynamics are used to transform one or more values into a new value. These operators can be used from the Logic Programmer.
All operators implement the IOperator
interface.
Operator types are like blocks in Minecraft. They are only created once, and do not keep state by themselves.
The easiest way to create a new operator is by using the OperatorBuilder
.
If you want to use this builder, your main mod class MUST extend from ModBase
.
It is recommended to build your operators during Forge's RegistryEvent.NewRegistry
event.
The following shows an example of the builder usage:
@Mod(Reference.MOD_ID)
public class MyMod {
public MyMod() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegistriesCreate);
}
public void onRegistriesCreate(RegistryEvent.NewRegistry event) {
IOperatorRegistry registry = IntegratedDynamics._instance.getRegistryManager().getRegistry(IOperatorRegistry.class);
registry.register(OperatorBuilder
.forType(ValueTypes.CATEGORY_NUMBER)
.inputTypes(2, ValueTypes.CATEGORY_NUMBER)
.renderPattern(IConfigRenderPattern.INFIX)
.symbol("+")
.operatorName("addition")
.function(variables -> ValueTypes.CATEGORY_NUMBER.add(variables.getVariables()[0], variables.getVariables()[1]))
.build())
}
}
The builder itself is immutable, which means that you can save and reuse intermediary builder results, in case you want to create multiple similar operators.
More extensive examples can be found in Operators
. Reusable intermediary builders can be found in OperatorBuilders
.
Alternatively, if you want to create a new aspect without the builder, you can reuse the OperatorBase
from Integrated Dynamics. In this case, your main mod class MUST extend from ModBase
and you must override getMod
in your part type to refer to your mod instance.
When using the OperatorBuilder
, your language file must contain your part name as operator.<mod-id>.<operator-name>
.
For example:
"operator.integrateddynamics.addition": "Addition",
- For Modpack Creators
- For Addon Developers