Skip to content

Environment Component Types

Environment Component Types are a special set of Components (like those found on ItemStacks) that are reserved for the parameters of the environment.

Component Formats

Temperature

Relative Humidity

  • {} components: Parent tag.
    • D thermoo:relative_humidity: A double value between 0 and 1 (inclusive).

Atmospheric Pressure

  • {} components: Parent tag.
    • D thermoo:atmospheric_pressure: A non-negative double value that stores the atmospheric pressure in millibars.

Defining Custom Component Types

Creating a new environment component type is just like creating a new item component type, except that you must register it to the registry ThermooRegistries.ENVIRONMENT_COMPONENT_TYPE. All component type objects should be immutable, and any operations on them should return a new instance. For this reason, it is recommended to use either primitive types, or record (in Java) or data (in Kotlin) classes to create your components.

You will need to register a Codec for your component type. The Fabric docs have a useful page on the subject if you are unfamiliar: https://docs.fabricmc.net/develop/codecs

Example

A dew point component type.

public record DewPointComponent(
        TemperatureRecord dewPoint
)  {
    public static final Codec<DewPointComponent> CODEC = RecordCodecBuilder.create(
            instance -> instance.group(
                    TemperatureRecord.CODEC
                            .fieldOf("dew_point")
                            .forGetter(DewPointComponent::dewPoint)
            ).apply(instance, DewPointComponent::new)
    );

    public static final DewPointComponent DEFAULT = new DewPointComponent(new TemperatureRecord(20));

    // usually this would go in its own EnvironmentComponentTypes-like class, but kept here as an example
    public static final DataComponentType<DewPointComponent> COMPONENT = DataComponentType.builder()
            .persistent(CODEC)
            .build();

    public static void initialize() {
        Registry.register(
                ThermooRegistries.ENVIRONMENT_COMPONENT_TYPE,
                ResourceLocation.fromNamespaceAndPath("example", "dew_point"),
                COMPONENT
        );
    }
}
data class DewPointComponent(
    val dewPoint: TemperatureRecord 
) {
    companion object {
        val CODEC: Codec<DewPointComponent> = RecordCodecBuilder.create { instance ->
            instance.group(
                TemperatureRecord.CODEC
                    .fieldOf("dew_point")
                    .forGetter(DewPointComponent::dewPoint)
            ).apply(instance, ::DewPointComponent)
        }

        val DEFAULT: DewPointComponent = DewPointComponent(20.C)

        // usually this would go in its own EnvironmentComponentTypes-like class, but kept here as an example
        val COMPONENT: DataComponentType<DewPointComponent> = DataComponentType.builder()
                .persistent(CODEC)
                .build()

        fun initialize() {
            Register.register(
                ThermooRegistries.ENVIRONMENT_COMPONENT_TYPE,
                ResourceLocation.fromNamespaceAndPath("example", "dew_point"),
                COMPONENT
            )
        }
    }
}