Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions fabric-environment-attributes-v1/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version = getSubprojectVersion(project)

moduleDependencies(project, [
'fabric-api-base',
'fabric-lifecycle-events-v1'
])

testDependencies(project, [
':fabric-resource-loader-v1',
':fabric-client-gametest-api-v1'
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.api.environment.attribute.v1;

import net.minecraft.resources.Identifier;
import net.minecraft.world.attribute.EnvironmentAttributeLayer;
import net.minecraft.world.attribute.EnvironmentAttributeSystem;
import net.minecraft.world.level.Level;

/**
* Provides {@link EnvironmentAttributeLayer}s to an {@link EnvironmentAttributeSystem}. You may register custom
* {@link AttributeLayerProvider} implementations using {@link AttributeLayerRegistry#registerLayerProvider}.
*
* <p>
* Attribute layers can be ordered relative to vanilla's layers or other modded layers using
* {@link AttributeLayerRegistry#addLayerOrdering}. The order defines which layers override which other layers: layers
* that come first in the ordering are overriden by layers that come later in the ordering. For example, in vanilla,
* biome layers come after dimension layers, since biome-local attributes override dimension-global attributes.
* </p>
*
* <p>
* Minecraft adds layers in four phases: dimension-global attributes, then biome-local attributes, then
* timeline-interpolated attributes, and finally some hardcoded weather attributes. Each of these phases, as well modded
* layer providers, are associated with an identifier that can be sorted against.
* </p>
*/
public interface AttributeLayerProvider {
/**
* Identifier associated to vanilla's dimension attribute layers.
*/
Identifier DIMENSION = Identifier.withDefaultNamespace("dimensions");

/**
* Identifier associated to vanilla's biome attribute layers.
*/
Identifier BIOMES = Identifier.withDefaultNamespace("biomes");

/**
* Identifier associated to vanilla's timeline attribute layers.
*/
Identifier TIMELINES = Identifier.withDefaultNamespace("timelines");

/**
* Identifier associated to vanilla's weather attribute layers.
*/
Identifier WEATHER = Identifier.withDefaultNamespace("weather");

/**
* The identifier associated to the first vanilla phase. Currently, that is {@link #DIMENSION}.
* This constant exists purely for compatibility: if Minecraft ever adds another layer before its dimension phase,
* then this constant is updated.
*/
Identifier FIRST_VANILLA_PHASE = DIMENSION;

/**
* The identifier associated to the last vanilla phase. Currently, that is {@link #WEATHER}.
* This constant exists purely for compatibility: if Minecraft ever adds another layer after its weather phase,
* then this constant is updated.
*/
Identifier LAST_VANILLA_PHASE = WEATHER;

/**
* Called to add attribute layers to an {@link EnvironmentAttributeSystem.Builder} for the given {@link Level}.
* This is called both on the client and on the server for every {@link Level} that is created.
*
* @param systemBuilder The {@link EnvironmentAttributeSystem.Builder} to add layers to.
* @param level The {@link Level} that the environment attribute system is being created for.
*/
void addAttributeLayers(EnvironmentAttributeSystem.Builder systemBuilder, Level level);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.api.environment.attribute.v1;

import org.jspecify.annotations.NullMarked;

import net.minecraft.resources.Identifier;

import net.fabricmc.fabric.impl.environment.attribute.AttributeLayerRegistryImpl;

@NullMarked
public class AttributeLayerRegistry {
/**
* Register a {@link AttributeLayerProvider}. If a layer with the given identifier already exists, an exception
* is thrown.
*
* @param id The identifier of the layer provider. This can be ordered against by other layer providers.
* @param layer The layer provider to register.
*/
public static void registerLayerProvider(Identifier id, AttributeLayerProvider layer) {
AttributeLayerRegistryImpl.registerLayerProvider(id, layer);
}

/**
* Declares that the layer provider with the first identifier should activate before the layer provider with the
* second identifier. Unless this causes a cyclic dependency, the two layer providers are guaranteed to activate in
* said order. You may use this to order your layer provider against vanilla phases using any of the constants in
* {@link AttributeLayerProvider}. If both layer identifiers are the same, then an exception is thrown.
*
* @param firstLayer The ID of the layer that should activate earlier.
* @param secondLayer The ID of the layer that should activate later.
*/
public static void addLayerOrdering(Identifier firstLayer, Identifier secondLayer) {
AttributeLayerRegistryImpl.addLayerOrdering(firstLayer, secondLayer);
}
}
Loading
Loading