Interface GenericSource
- All Known Subinterfaces:
GenericPeripheral
LuaFunction
functions.
Unlike normal objects (IDynamicLuaObject
or IPeripheral
), methods do not target this object but
accept their target as the first parameter. This allows you to inject methods onto objects you do not own, as well as
declaring methods for a specific "trait" (for instance, a Forge capability or Fabric block lookup interface).
Currently, the "generic peripheral" system is incompatible with normal peripherals. Peripherals explicitly provided
by capabilities/the block lookup API take priority. Block entities which use this system are given a peripheral name
determined by their id, rather than any peripheral provider, though additional types may be provided by overriding
GenericPeripheral.getType()
.
Example
public class FurnacePeripheral implements GenericPeripheral {
@Override
public String id() {
return new ResourceLocation(ExampleMod.MOD_ID, "furnace").toString();
}
@LuaFunction(mainThread = true)
public int getBurnTime(AbstractFurnaceBlockEntity furnace) {
// Don't do it this way! Use an access widener/transformer to access the "litTime" field instead.
return furnace.saveWithoutMetadata().getInt("BurnTime");
}
}
New capabilities (those not built into Forge) must be explicitly registered using the loader-specific API.
-
Method Summary
-
Method Details
-
id
String id()A unique identifier for this generic source.While this can return an arbitrary string, it's recommended that this is formatted the same was as Minecraft's resource locations/identifiers, so is of the form
"mod_id:source_id"
.- Returns:
- This source's identifier.
-