You added a new entity that could emit light? You want that it dynamically emits light?
Then try the API of this mod!
Every time an entity is referenced it means either an entity or a block entity.
Block entity dynamic lighting is non-recommended if avoidable with block states.
If your entity re-implements tick without calling the super method the dynamic light handler will not work.
Any API calls should be done in the custom entrypoint.
To use the entrypoint, make a new class implementing DynamicLightsInitializer
,
add in your fabric.mod.json
this:
"entrypoints": {
"dynamiclights": [
"path.to.your.Class"
]
}
Once done, you can call the methods presented in the rest of this document in the method onInitializeDynamicLights
.
A dynamic light handler is an interface with different methods:
int getLuminance(T lightSource)
boolean isWaterSensitive(T lightSource)
- with defaultfalse
The returned value is between 0 and 15 which are luminance values, lightSource
is of the type of the entity and is the targeted entity.
The method is called for every entity matching the type at each tick.
That's where you register your handler!
Just call DynamicLightHandlers#registerDynamicLightHandler(EntityType<T>, DynamicLightHandler<T>)
or DynamicLightHandlers#registerDynamicLightHandler(BlockEntityType<T>, DynamicLightHandler<T>)
to register your handler!
If a handler is already registered for this entity, then it will merge the two handlers with a Math#max
handler.
And that's all! The mod will light up your entities following your handler.
registerDynamicLightHandler(EntityType.BLAZE, DynamicLightHandler.makeHandler(blaze -> 10, blaze -> true));
registerDynamicLightHandler(EntityType.ENDERMAN, entity -> {
int luminance = 0;
if (entity.getCarriedBlock() != null)
luminance = entity.getCarriedBlock().getLuminance();
return luminance;
});
registerDynamicLightHandler(EntityType.ITEM_FRAME, entity -> {
World world = entity.getEntityWorld();
return LambDynLights.getLuminanceFromItemStack(entity.getHeldItemStack(), !world.getFluidState(entity.getBlockPos()).isEmpty());
});
DynamicLightHandler#makeHandler
will transforms 2 functions into an handler.DynamicLightHandler#makeLivingEntityHandler
will merge the given handler with a basic handler for living entity which detects item light sources.DynamicLightHandler#makeCreeperEntityHandler
will optionally merge the given handler with a basic handler for creepers. May be useful for Creepers mod.LambDynLights#getLuminanceFromItemStack
will return the luminance value of the given item stack.
By default every items will emit the same amount of light as their assigned block if possible.
But for items that are not assigned to a block, or for items that should not lit up underwater, there's JSON files to write!
The JSONs are located in <modid>:dynamiclights/item/<file>.json
.
The format is simple:
item
- The identifier of the affected item.luminance
- Either a number between0
and15
and corresponds to the luminance value, or is a string with either a block identifier to get the luminance from or"block"
to use the default assigned block luminance value.water_sensitive
(Optional) -true
if the item doesn't emit light when submerged in water, elsefalse
.
{
"item": "minecraft:fire_charge",
"luminance": 10,
"water_sensitive": true
}
{
"item": "minecraft:lava_bucket",
"luminance": "minecraft:lava",
"water_sensitive": true
}
{
"item": "minecraft:nether_star",
"luminance": 8
}
{
"item": "minecraft:torch",
"luminance": "block",
"water_sensitive": true
}