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.
To work with the mod you should add the following to your buildscript:
repositories {
maven {
name = "Gegy"
url = uri("https://maven.gegy.dev")
}
}
dependencies {
/* Stuff */
// For now only this line is needed, in the future this should evolve into separate API and runtime JARs.
modImplementation("dev.lambdaurora.lambdynamiclights:lambdynamiclights-runtime:<version>")
}
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 item 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 light up underwater, there's JSON files to write!
The JSONs are located in <namespace>:dynamiclights/item/<file>.json
.
The format is simple:
match
- The item predicate to match the affected items.luminance
- Can either be:- a number between
0
and15
, which corresponds to the luminance value. - an object with a type and arguments, which can be:
{ "type": "block", "block": "<block identifier>" }
to copy the luminance value of the specified block.{ "type": "block_self" }
to copy the luminance value of the block already associated with the matched item.
- a number between
water_sensitive
(Optional) -true
if the item doesn't emit light when submerged in water, orfalse
otherwise.silence_error
(Optional) -true
to silence any kind of runtime error from the item light source, this is heavily discouraged unless you know what you're doing as you will not be made aware of errors!
Errors will still be logged if in a development environment or if thelambdynamiclights.resource.force_log_errors
property is set totrue
.
{
"match": {
"items": "minecraft:fire_charge"
},
"luminance": 10,
"water_sensitive": true
}
{
"match": {
"items": "minecraft:lava_bucket"
},
"luminance": {
"type": "block",
"block": "minecraft:lava"
},
"water_sensitive": true
}
{
"match": {
"items": "minecraft:nether_star"
},
"luminance": 8
}
{
"match": {
"items": [
"minecraft:torch",
"minecraft:redstone_torch",
"minecraft:soul_torch"
]
},
"luminance": {
"type": "block_self"
},
"water_sensitive": true
}