WeatherAttributes .java

net.minecraft.world.attribute.WeatherAttributes (class): members: WEATHER_ATTRIBUTES, addBuiltinLayers, WeatherAccess, weatherAccess, THUNDER, RAIN.

net.minecraft.world.attributeclass87 linescommon4.3 KB

API Surface (3)

void addBuiltinLayers(final EnvironmentAttributeSystem.Builder system, final WeatherAttributes.WeatherAccess weatherAccess)
float rainLevel()
float thunderLevel()

Fields & Constants (4)

RAIN
THUNDER
WEATHER_ATTRIBUTES
weatherAccess

Code Graph: Dependencies (8)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

WeatherAttributes.java87 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.attribute;
2
3
import com.google.common.collect.Sets;
4
import java.util.Set;
5
import net.minecraft.util.ARGB;
6
import net.minecraft.world.attribute.modifier.ColorModifier;
7
import net.minecraft.world.attribute.modifier.FloatModifier;
8
import net.minecraft.world.attribute.modifier.FloatWithAlpha;
9
import net.minecraft.world.level.Level;
10
import net.minecraft.world.timeline.Timelines;
11
12
public class WeatherAttributes {
13
	public static final EnvironmentAttributeMap RAIN = EnvironmentAttributeMap.builder()
14
		.modify(EnvironmentAttributes.SKY_COLOR, ColorModifier.BLEND_TO_GRAY_RGB, new ColorModifier.BlendToGray(0.6F, 0.75F))
15
		.modify(EnvironmentAttributes.FOG_COLOR, ColorModifier.MULTIPLY_RGB, ARGB.vector3fFromRGB24(ARGB.colorFromFloat(1.0F, 0.5F, 0.5F, 0.6F)))
16
		.modify(EnvironmentAttributes.CLOUD_COLOR, ColorModifier.BLEND_TO_GRAY_ARGB, new ColorModifier.BlendToGray(0.24F, 0.5F))
17
		.modify(EnvironmentAttributes.SKY_LIGHT_LEVEL, FloatModifier.ALPHA_BLEND, new FloatWithAlpha(4.0F, 0.3125F))
18
		.modify(EnvironmentAttributes.SKY_LIGHT_COLOR, ColorModifier.ALPHA_BLEND_RGB, ARGB.vector4fFromARGB32(ARGB.color(0.3125F, Timelines.NIGHT_SKY_LIGHT_COLOR)))
19
		.modify(EnvironmentAttributes.SKY_LIGHT_FACTOR, FloatModifier.ALPHA_BLEND, new FloatWithAlpha(0.24F, 0.3125F))
20
		.set(EnvironmentAttributes.STAR_BRIGHTNESS, 0.0F)
21
		.modify(EnvironmentAttributes.SUNRISE_SUNSET_COLOR, ColorModifier.MULTIPLY_ARGB, ARGB.vector4fFromARGB32(ARGB.colorFromFloat(1.0F, 0.5F, 0.5F, 0.6F)))
22
		.set(EnvironmentAttributes.BEES_STAY_IN_HIVE, true)
23
		.build();
24
	public static final EnvironmentAttributeMap THUNDER = EnvironmentAttributeMap.builder()
25
		.modify(EnvironmentAttributes.SKY_COLOR, ColorModifier.BLEND_TO_GRAY_RGB, new ColorModifier.BlendToGray(0.24F, 0.94F))
26
		.modify(EnvironmentAttributes.FOG_COLOR, ColorModifier.MULTIPLY_RGB, ARGB.vector3fFromRGB24(ARGB.colorFromFloat(1.0F, 0.25F, 0.25F, 0.3F)))
27
		.modify(EnvironmentAttributes.CLOUD_COLOR, ColorModifier.BLEND_TO_GRAY_ARGB, new ColorModifier.BlendToGray(0.095F, 0.94F))
28
		.modify(EnvironmentAttributes.SKY_LIGHT_LEVEL, FloatModifier.ALPHA_BLEND, new FloatWithAlpha(4.0F, 0.52734375F))
29
		.modify(
30
			EnvironmentAttributes.SKY_LIGHT_COLOR, ColorModifier.ALPHA_BLEND_RGB, ARGB.vector4fFromARGB32(ARGB.color(0.52734375F, Timelines.NIGHT_SKY_LIGHT_COLOR))
31
		)
32
		.modify(EnvironmentAttributes.SKY_LIGHT_FACTOR, FloatModifier.ALPHA_BLEND, new FloatWithAlpha(0.24F, 0.52734375F))
33
		.set(EnvironmentAttributes.STAR_BRIGHTNESS, 0.0F)
34
		.modify(EnvironmentAttributes.SUNRISE_SUNSET_COLOR, ColorModifier.MULTIPLY_ARGB, ARGB.vector4fFromARGB32(ARGB.colorFromFloat(1.0F, 0.25F, 0.25F, 0.3F)))
35
		.set(EnvironmentAttributes.BEES_STAY_IN_HIVE, true)
36
		.build();
37
	private static final Set<EnvironmentAttribute<?>> WEATHER_ATTRIBUTES = Sets.union(RAIN.keySet(), THUNDER.keySet());
38
39
	public static void addBuiltinLayers(final EnvironmentAttributeSystem.Builder system, final WeatherAttributes.WeatherAccess weatherAccess) {
40
		for (EnvironmentAttribute<?> attribute : WEATHER_ATTRIBUTES) {
41
			addLayer(system, weatherAccess, attribute);
42
		}
43
	}
44
45
	private static <Value> void addLayer(
46
		final EnvironmentAttributeSystem.Builder system, final WeatherAttributes.WeatherAccess weatherAccess, final EnvironmentAttribute<Value> attribute
47
	) {
48
		EnvironmentAttributeMap.Entry<Value, ?> rainEntry = RAIN.get(attribute);
49
		EnvironmentAttributeMap.Entry<Value, ?> thunderEntry = THUNDER.get(attribute);
50
		system.addTimeBasedLayer(attribute, (result, cacheTickId) -> {
51
			float thunderLevel = weatherAccess.thunderLevel();
52
			float rainLevel = weatherAccess.rainLevel() - thunderLevel;
53
			if (rainEntry != null && rainLevel > 0.0F) {
54
				Value rainValue = rainEntry.applyModifier(result);
55
				result = attribute.type().stateChangeLerp().apply(rainLevel, result, rainValue);
56
			}
57
58
			if (thunderEntry != null && thunderLevel > 0.0F) {
59
				Value thunderValue = thunderEntry.applyModifier(result);
60
				result = attribute.type().stateChangeLerp().apply(thunderLevel, result, thunderValue);
61
			}
62
63
			return result;
64
		});
65
	}
66
67
	public interface WeatherAccess {
68
		static WeatherAttributes.WeatherAccess from(final Level level) {
69
			return new WeatherAttributes.WeatherAccess() {
70
				@Override
71
				public float rainLevel() {
72
					return level.getRainLevel(1.0F);
73
				}
74
75
				@Override
76
				public float thunderLevel() {
77
					return level.getThunderLevel(1.0F);
78
				}
79
			};
80
		}
81
82
		float rainLevel();
83
84
		float thunderLevel();
85
	}
86
}
87

Decompiled Minecraft 26.3 source of WeatherAttributes (net/minecraft/world/attribute/WeatherAttributes.java) with Mojang official mappings, stored verbatim on the site.