Environment attribute API for adding custom attribute layers#5201
Environment attribute API for adding custom attribute layers#5201FoxSamu wants to merge 4 commits intoFabricMC:26.1from
Conversation
|
BTW, I couldn't get the client test to run because some other API's test failed and I did not see a way to run the client test only for this specific API. However, I did see the test working while I was looking through the client tests (the sky was purple, as modded by the client test). |
|
The idea is good, but I think the design should be changed to be more flexible and in-line with other Fabric API code. I am imagining a static registry that works much like |
I noticed the toposort abilities, I though of somehow making a phased I'll see if I can make it somehow work in the way that you described. |
|
|
|
I believe I agree with marker objects as well. |
|
Yeah I implemented it with marker objects now in a local project (since working directly in the fabric api project is pretty slow and tough to test). It seems to do well, but I think it is a bit confusing that now you have to call two or three functions to register layers in the correct order: AttributeLayerRegistry.registerLayerProvider(ID, ModEnvironmentAttributes::setupLayers);
AttributeLayerRegistry.addLayerOrdering(ID, AttributeLayerProvider.WEATHER);I did make it so that, unless a defined layer dependency prevents it, the sorter prefers to put vanilla layers before modded layers. This is probably the most preferred use. Nevertheless, I find it a bit confusing that it's method calls. Will push the code to the PR tomorrow. |
...1/src/main/java/net/fabricmc/fabric/api/environment/attribute/v1/AttributeLayerPosition.java
Outdated
Show resolved
Hide resolved
|
These changes look good but the terminology seems to be inconsistent. I think "layer" should exclusively refer to |
I would then rather stick with the name "provider" - it provides layers to the system - and then interpret the vanilla phases as providers too (despite those just being markers). I also doubted if I should name it
I think plural is better since a single vanilla provider provides layers that interpolate between a multitude of things. One layer handles dimensions, another does biomes, and so on and so forth. But it's not a big deal to me to change it to singular, it just feels a bit off. |
This might be a little far-fetched, but with Minecraft's introduction of environment attributes comes an intricate system of attribute layers that interpolate and modify the environment attributes throughout different environments. This PR suggests a new API that lets mod developers add custom layers to this system.
To give some background, Minecraft creates an
EnvironmentAttributeSystemfor eachLevel, bothClientLevelandServerLevelget one, and the setup is pretty much the same for both. TheEnvironmentAttributeSystemis built with a builder (EnvironmentAttributeSystem.Builder), which is fed throughEnvironmentAttributeSystem.addDefaultLayers(Builder, Level)to register Minecraft's attribute layers that deliver pretty much all logic:That code looks something like this:
This system is very modular, and could be easily extended by mods using a simple mixin (presumably Mojang did this by design). I thought it might be nice to have this accessible through the Fabric API, hence I'm submitting this PR that adds just that. I created a new API,
fabric-environment-attributes-v0, which supplies several events that allow inserting attribute layers before, after or in between Minecraft's layers.So say I want to add a layer that sits between the dimension layer and biome layer that makes clouds red, I could do the following:
This code overrides the cloud colors defined by dimensions, but biomes, timelines and weather can in turn override the red cloud color I provided.
To clarify, this is not the same as
DimensionEvents.MODIFY_ATTRIBUTES. The dimension event allows modifying the attributes of a dimension type (which should still remain a proper API since it's much less convoluted and has a different purpose). Meanwhile, attribute layers define the actual logic that Minecraft uses to interpolate and override attributes. This would, for example, allow for creating custom weather that modifies environment attributes temporarily through a custom weather layer.