-
-
Notifications
You must be signed in to change notification settings - Fork 62
Addon Development: Aspects
Aspects in Integrated Dynamics are responsible for reading values to a variable or writing to an external process based on a variable's value. Aspects are mainly used in reader and writer parts.
All aspects implement the IAspect
interface, with IAspectRead
and IAspectWrite
corresponding to respectively read and write aspects.
Aspect 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 aspect is by using the AspectBuilder
.
If you want to use this builder, your main mod class MUST extend from ModBase
.
This builder also takes care of aspect registration.
It is recommended to build your aspects 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) {
AspectBuilder
.forReadType(ValueTypes.BOOLEAN)
.byMod(IntegratedDynamics._instance)
.handle(dimPos -> dimPos.getWorld(true).getBlockState(dimPos.getBlockPos()).getBlock() != Blocks.AIR)
.handle(ValueTypeBoolean.ValueBoolean::of, "block")
.buildRead();
}
}
The builder itself is immutable, which means that you can save and reuse intermediary builder results, in case you want to create multiple similar aspects.
More extensive examples can be found in Aspects
. Reusable intermediary builders can be found in AspectReadBuilders
and AspectWriteBuilders
.
Alternatively, if you want to create a new aspect without the builder, you can reuse the AspectReadBase
and AspectWriteBase
from Integrated Dynamics. In this case, your main mod class MUST extend from ModBase
and you must override getMod
in your aspect type to refer to your mod instance.
When using the AspectBuilder
, your assets must be structured as follows:
Each aspect must have a variable item overlay model defined at the path assets/<mod-id>/models/assets/<read-or-write>/<value-name>/<aspect-name>.json
.
In the case of the aspect we built in the example above, the file assets/integrateddynamics/models/assets/read/boolean/block.json
could contain the following:
{
"parent": "item/generated",
"textures": {
"layer0": "integrateddynamics:aspect/read/boolean/block/block"
}
}
Your language file must contain your part name as aspect.<mod-id>.<read-or-write>.<value-name>.<aspect-name>
.
For example:
"aspect.integrateddynamics.read.boolean.block": "Has Block",
- For Modpack Creators
- For Addon Developers