Skip to content

Conversation

@roro1506HD
Copy link
Contributor

@roro1506HD roro1506HD commented Nov 29, 2025

First steps of the Environmental Attributes API, still WIP but any feedbacks are welcome!
Javadocs is not yet done, working on having an API that work and is good before


Edit 1: API getters has been added, snippet below is on how it works since there is no javadocs yet. Feedbacks are welcome as always!

// You can get an EnvironmentalAttribute object by calling this method using an EnvironmentalAttributeType.
// All EnvironmentalAttributeType can be found in EnvironmentalAttributeTypes.
// The returned EnvironmentalAttribute object will be tied to the world and the attribute type
EnvironmentalAttribute<Integer> skyColorAttribute = world.getEnvironmentalAttribute(EnvironmentalAttributeTypes.SKY_COLOR);

// Now that we have an attribute object, we can start getting its value on different scenarios!
// Please note that for any of the following methods, if the attribute type you're looking for is not found it will
// return the default value associated with the attribute type. You can get the default value of an attribute's type like this:
EnvironmentalAttributeTypes.SKY_COLOR.getDefaultValue();

// This method returns the non-positioned value of this attribute, this means biome variations will not be applied.
// Time and weather variation are still applied based on daytime, as well as world variations
skyColorAttribute.getGlobal();

// This method returns the positioned value of this attribute, this means world,
// biome, time (still daytime) and weather variations are all applied
skyColorAttribute.getPositioned(Position.block(0, 60, 0));

// This method returns the non-positioned value of this attribute at a specific time. Biome variations
// will not be applied, world and weather variations are applied and time variations are applied according to the provided time
skyColorAttribute.getTimed(6000L);

// If any of the above methods do not suit your needs, or you want more control about the options to get a value
// this method is for you. It takes in a context that has all options that can be applied to attributes.
skyColorAttribute.getValue(
    // All fields in this builder are Nullable. Passing null to a value will keep the vanilla one:
    // - For every field except position, it will fall back to the current world's value
    // - For position, it will stay null and will not apply biome variations
    EnvironmentalAttributeContext.builder()
        // Setting position to anything but null will enable biome variations for this lookup at the specified position
        .position(Position.block(0, 60, 0))

        // Setting time will make the lookup use the provided value for time variations
        .time(6000L)

        // Setting rainLevel will make the lookup use the provided value for weather variations
        // Rain level of 0.0 means no rain, rain level of 1.0 means raining. Any value in between is during weather transitions
        .rainLevel(0.6F)
        .raining(true) // Equivalent of .rainLevel(0.0F) when false, and .rainLevel(1.0F) when true

        // Setting thunderLevel will make the lookup use the provided value for weather variations
        // Thunder level of 0.0 means no thunder, thunder level of 1.0 means thundering. Any value in between is during weather transitions
        .thunderLevel(0.6F)
        .thundering(true) // Equivalent of .thunderLevel(0.0F) when false, and .thunderLevel(1.0F) when true

        .build()
);

@masmc05
Copy link
Contributor

masmc05 commented Nov 30, 2025

getEnvironmentalAttribute

I think getAttribute would be better, it can't be confused with entitiy attributes in this context and the ones who do confuse those will get it sorted with the parameter and return value's class name

And could you add a Block#getAttributeValue(EAType) to get the current value (even cached one) in a current position without having to go through building the whole context?

@roro1506HD
Copy link
Contributor Author

getEnvironmentalAttribute

I think getAttribute would be better, it can't be confused with entitiy attributes in this context and the ones who do confuse those will get it sorted with the parameter and return value's class name

And could you add a Block#getAttributeValue(EAType) to get the current value (even cached one) in a current position without having to go through building the whole context?

Since there are no other attributes on worlds we can easily rename to getAttributes. The main reason I named it that way was to make sure it's differenciated from entities attributes on first sight, but I'm fine with renaming it.

For the getter on Block, I agree that would be nice but I think I should make it use EnvironmentalAttribute#getPositioned and make getPositioned implemented server-side and use the cached value there, since getPositioned has no other options it makes no sense to invalidate cache at that point. I could also add some optimization on the context getter if the context has no options or just a position to prevent the cache from being invalidated too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

2 participants