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()
.
For example, the main CC: Tweaked mod defines a generic source for inventories, which works on IItemHandler
s:
public class InventoryMethods implements GenericSource {
\@LuaFunction( mainThread = true )
public int size(IItemHandler inventory) {
return inventory.getSlots();
}
// ...
}
New capabilities or block lookups (those not built into Forge/Fabric) 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.
-