public record EnvironmentAttributeValue(EnvironmentAttribute<?> attribute) implements ContextIntProvider, EnvironmentAttributeProvider {
12
private static final Codec<EnvironmentAttribute<?>> ATTRIBUTE_CODEC = EnvironmentAttributes.CODEC
13
.validate(
14
attribute -> attribute.type().toInt() == null ? DataResult.error(() -> attribute + " cannot be converted to an integer") : 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 int getIntUnsafe(final LootContext context) throws ArithmeticException {
25
return getAsInt(context, this.attribute);
26
}
27
28
private static <Value> int getAsInt(final LootContext context, final EnvironmentAttribute<Value> attribute) {
29
Value value = context.getLevel().environmentAttributes().getValue(context, attribute);
30
return attribute.type().toInt(value);
31
}
32
}
33
Decompiled Minecraft 26.3 source of EnvironmentAttributeValue (net/minecraft/world/level/storage/loot/providers/number/ints/EnvironmentAttributeValue.java) with Mojang official mappings, stored verbatim on the site.