public record EnvironmentAttributeValue(EnvironmentAttribute<?> attribute) implements ContextFloatProvider, EnvironmentAttributeProvider {
12
private static final Codec<EnvironmentAttribute<?>> ATTRIBUTE_CODEC = EnvironmentAttributes.CODEC
13
.validate(
14
attribute -> attribute.type().toFloat() == null ? DataResult.error(() -> attribute + " cannot be converted to a float") : DataResult.success(attribute)
15
);
16
public static final MapCodec<EnvironmentAttributeValue> MAP_CODEC = EnvironmentAttributeProvider.mapCodec(ATTRIBUTE_CODEC, EnvironmentAttributeValue::new);
17
18
@Override
19
public MapCodec<EnvironmentAttributeValue> codec() {
20
return MAP_CODEC;
21
}
22
23
@Override
24
public float getFloatUnsafe(final LootContext context) {
Value value = context.getLevel().environmentAttributes().getValue(context, attribute);
30
return attribute.type().toFloat(value);
31
}
32
}
33
Decompiled Minecraft 26.3 source of EnvironmentAttributeValue (net/minecraft/world/level/storage/loot/providers/number/floats/EnvironmentAttributeValue.java) with Mojang official mappings, stored verbatim on the site.