feat: add environment attribute system

This commit is contained in:
Zoe Gidiere committed 2026-11-09 16:34:50 -07:00
1 parent 8a940f7e1f
commit 4e37c361ea
127 files changed
+9022 -19

No files matched your search

+3 -1
View File
@@ -17,7 +17,9 @@ dependencies {
shadedImplementation("ch.qos.logback", "logback-classic", Versions.CLI.logback)
// Addon class loaders find minecraft-attributes on the test class path first; its entrypoint needs the manifest addon API.
testImplementation(project(":common:addons:minecraft-attributes"))
testImplementation(project(":common:addons:manifest-addon-loader"))
}
tasks.withType<Jar> {
@@ -0,0 +1,410 @@
package com.dfsek.terra.cli;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.OptionalDouble;
import java.util.Set;
import java.util.stream.Stream;
import com.dfsek.terra.addons.attribute.minecraft.AmbientParticle;
import com.dfsek.terra.addons.attribute.minecraft.AmbientSounds;
import com.dfsek.terra.addons.attribute.minecraft.MinecraftAttributes;
import com.dfsek.terra.addons.attribute.minecraft.Music;
import com.dfsek.terra.addons.attribute.minecraft.SoundRef;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.api.properties.Context;
import com.dfsek.terra.api.properties.Properties;
import com.dfsek.terra.api.properties.PropertyKey;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.registry.key.TagKey;
import com.dfsek.terra.api.util.generic.either.Either;
import com.dfsek.terra.api.world.attribute.Attribute;
import com.dfsek.terra.api.world.attribute.AttributeEntry;
import com.dfsek.terra.api.world.attribute.AttributeHandle;
import com.dfsek.terra.api.world.attribute.AttributeKey;
import com.dfsek.terra.api.world.attribute.AttributeMap;
import com.dfsek.terra.api.world.attribute.AttributeParents;
import com.dfsek.terra.api.world.attribute.Operation;
import com.dfsek.terra.api.world.attribute.PackAttributes;
import com.dfsek.terra.api.world.attribute.schedule.AttributeSchedule;
import com.dfsek.terra.api.world.attribute.schedule.ScheduleTrack;
import com.dfsek.terra.api.world.attribute.value.Color;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.config.pack.ConfigPackImpl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class AttributePackTest {
private static volatile AttributeParents parents = AttributeParents.NONE;
private static final AttributeParents FORWARDING = new AttributeParents() {
@Override
public <T> @Nullable AttributeEntry<T> biomeOrNull(Biome biome, Attribute<T> attribute) {
return parents.biomeOrNull(biome, attribute);
}
@Override
public <T> @Nullable AttributeEntry<T> packOrNull(PackAttributes pack, Attribute<T> attribute) {
return parents.packOrNull(pack, attribute);
}
};
private static CLIPlatform platform;
private static AttributeHandle handle;
private static ConfigPack pack;
@BeforeAll
static void setUp() throws Exception {
platform = new CLIPlatform() {
@Override
public AttributeParents getAttributeParents() {
return FORWARDING;
}
};
platform.getEventManager().callEvent(new PlatformInitializationEvent());
handle = platform.getAttributeHandle();
pack = load();
}
@AfterEach
void resetParents() {
parents = AttributeParents.NONE;
}
private static Path fixture() throws URISyntaxException {
return Path.of(AttributePackTest.class.getResource("/packs/attribute-test/pack.yml").toURI()).getParent();
}
private static ConfigPack load() throws Exception {
return new ConfigPackImpl(fixture(), platform);
}
private static Biome biome(ConfigPack pack, String id) {
return pack.getRegistry(Biome.class).getByID(id).orElseThrow(() -> new AssertionError("No biome " + id));
}
private static PackAttributes packAttributes(ConfigPack pack) {
return handle.pack(pack).orElseThrow(() -> new AssertionError("No PackAttributes on " + pack.getID()));
}
private static AttributeMap biomeEntries(ConfigPack pack, String id) {
return packAttributes(pack).biomeEntries(biome(pack, id));
}
private static Registry<Attribute<?>> attributes(ConfigPack pack) {
return pack.getRegistry(Attribute.REGISTRY_TYPE);
}
private static <T> Attribute<T> attribute(AttributeKey<T> key) {
return key.lookup(attributes(pack)).orElseThrow(() -> new AssertionError("No attribute " + key));
}
@SuppressWarnings("unchecked")
private static List<String> warnings(PackAttributes attributes) throws ReflectiveOperationException {
return (List<String>) attributes.getClass().getMethod("warnings").invoke(attributes);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private static List<String> biomeWarnings(String biome) throws ReflectiveOperationException {
Class<?> type = packAttributes(pack).getClass().getClassLoader()
.loadClass("com.dfsek.terra.addons.attribute.BiomeAttributeEntries");
PropertyKey<?> key = Context.create((Class) type.asSubclass(Properties.class));
Object entries = biome(pack, biome).getContext().get(key);
Method warnings = type.getDeclaredMethod("warnings");
warnings.setAccessible(true);
return (List<String>) warnings.invoke(entries);
}
private static <T> T declared(String biome, AttributeKey<T> key) {
AttributeEntry<T> entry = biomeEntries(pack, biome).get(key).orElseThrow(() -> new AssertionError(biome + " has no " + key));
assertEquals(Operation.OVERRIDE, entry.operation());
@SuppressWarnings("unchecked")
T value = (T) entry.argument();
return value;
}
private static AttributeMap overrides(Object... keysAndValues) {
AttributeMap.Builder builder = AttributeMap.builder();
for(int i = 0; i < keysAndValues.length; i += 2) put(builder, (AttributeKey<?>) keysAndValues[i], keysAndValues[i + 1]);
return builder.build();
}
@SuppressWarnings("unchecked")
private static <T> void put(AttributeMap.Builder builder, AttributeKey<T> key, Object value) {
builder.put(key, AttributeEntry.override((T) value));
}
private static Stream<Arguments> declaredEntries() {
Color child = Color.parseRgb("#a0b0c0");
Color base = Color.parseRgb("#405060");
Color white = Color.parseRgb("#ffffff");
Color shared = Color.parseRgb("#0a0b0c");
return Stream.of(
Arguments.of("PLAIN", overrides()),
Arguments.of("CHILD", overrides(MinecraftAttributes.VISUAL_FOG_COLOR, child, MinecraftAttributes.VISUAL_SKY_COLOR, base,
MinecraftAttributes.BIOME_TEMPERATURE, 0.8f)),
Arguments.of("NULLED", overrides(MinecraftAttributes.VISUAL_FOG_COLOR, child, MinecraftAttributes.BIOME_TEMPERATURE, 0.8f)),
Arguments.of("META", overrides(MinecraftAttributes.VISUAL_FOG_COLOR, white, MinecraftAttributes.VISUAL_SKY_COLOR, shared,
MinecraftAttributes.BIOME_DOWNFALL, 0.25f)),
Arguments.of("META_CHILD", overrides(MinecraftAttributes.VISUAL_FOG_COLOR, white, MinecraftAttributes.VISUAL_SKY_COLOR,
shared, MinecraftAttributes.BIOME_DOWNFALL, 0.75f, MinecraftAttributes.BIOME_WATER_COLOR,
Color.parseRgb("#112233"))));
}
@ParameterizedTest(name = "{0}")
@MethodSource("declaredEntries")
void declaredEntriesFollowInheritanceAndMeta(String biome, AttributeMap expected) throws ReflectiveOperationException {
assertEquals(expected, biomeEntries(pack, biome));
assertEquals(List.of(), biomeWarnings(biome));
}
@Test
void metaInsideValues() throws ReflectiveOperationException {
Music music = declared("EXPR", MinecraftAttributes.AUDIO_BACKGROUND_MUSIC).defaultMusic().orElseThrow();
assertEquals(RegistryKey.parse("minecraft:music.game"), music.sound().id());
assertEquals(12000, music.minDelay());
assertEquals(24000, music.maxDelay());
AttributeEntry<Float> fog = biomeEntries(pack, "EXPR").get(MinecraftAttributes.VISUAL_WATER_FOG_END_DISTANCE).orElseThrow();
assertEquals(Operation.MULTIPLY, fog.operation());
assertEquals(0.5f, fog.argument());
assertEquals(48f, packAttributes(pack).resolve(attribute(MinecraftAttributes.VISUAL_WATER_FOG_END_DISTANCE),
biome(pack, "EXPR")));
AmbientSounds sounds = declared("EXPR", MinecraftAttributes.AUDIO_AMBIENT_SOUNDS);
assertEquals(RegistryKey.parse("minecraft:ambient.cave"), sounds.loop().orElseThrow().id());
AmbientSounds.Mood mood = sounds.mood().orElseThrow();
assertEquals(RegistryKey.parse("minecraft:ambient.cave"), mood.sound().id());
assertEquals(6000, mood.tickDelay());
assertEquals(8, mood.blockSearchExtent());
assertEquals(2.0, mood.offset());
assertEquals(List.of(
new AmbientSounds.Additions(new SoundRef(RegistryKey.parse("minecraft:ambient.crimson_forest.additions"),
OptionalDouble.empty()), 0.0111),
new AmbientSounds.Additions(new SoundRef(RegistryKey.parse("minecraft:ambient.basalt_deltas.additions"),
OptionalDouble.empty()), 0.5)), sounds.additions());
AmbientParticle particle = declared("EXPR", MinecraftAttributes.VISUAL_AMBIENT_PARTICLES).get(0);
assertEquals(0.025f, particle.probability(), 1e-6f);
Map<?, ?> body = (Map<?, ?>) particle.particle().value();
assertEquals(Map.of("type", "minecraft:dust", "color", List.of(1.0, 0.0, 0.0), "scale", 1.0), body);
assertEquals(List.of(), biomeWarnings("EXPR"));
}
@Test
void chainedReferenceResolvesOnce() throws ReflectiveOperationException {
assertTrue(biomeEntries(pack, "CHAIN").isEmpty());
List<String> warnings = biomeWarnings("CHAIN");
assertEquals(2, warnings.size(), warnings.toString());
for(String key : List.of("minecraft:visual/sky_color", "minecraft:visual/fog_color")) {
String warning = warnings.stream().filter(w -> w.contains("\"" + key + "\"")).findFirst()
.orElseThrow(() -> new AssertionError(warnings.toString()));
assertTrue(warning.contains("got \"$meta.yml:sky-hex\""), warning);
}
}
@Test
void tectonicErrorBecomesWarning() throws ReflectiveOperationException {
assertEquals(overrides(MinecraftAttributes.VISUAL_FOG_COLOR, Color.parseRgb("#123456")), biomeEntries(pack, "EXPR_BAD"));
List<String> warnings = biomeWarnings("EXPR_BAD");
assertEquals(2, warnings.size(), warnings.toString());
String missingKey = warnings.stream().filter(w -> w.contains("\"minecraft:visual/fog_start_distance\"")).findFirst()
.orElseThrow(() -> new AssertionError(warnings.toString()));
assertTrue(missingKey.contains("No such key no-such-key"), missingKey);
String malformed = warnings.stream().filter(w -> w.contains("\"minecraft:visual/sky_fog_end_distance\"")).findFirst()
.orElseThrow(() -> new AssertionError(warnings.toString()));
assertTrue(malformed.contains("\"EXPR_BAD\""), malformed);
assertTrue(malformed.contains("meta reference \"2 * 6000\" must have the form file:key"), malformed);
assertFalse(malformed.contains("java."), malformed);
assertFalse(malformed.contains("Exception"), malformed);
}
@Test
void badEntryIsSkippedWithWarning() throws ReflectiveOperationException {
assertEquals(overrides(MinecraftAttributes.VISUAL_FOG_COLOR, Color.parseRgb("#00ff00")), biomeEntries(pack, "BAD"));
assertEquals(List.of("Pack \"ATTRIBUTE_TEST\", config \"BAD\": attribute \"minecraft:visual/sky_color\" skipped: "
+ "expected a color like \"#rrggbb\", got \"not a colour\""), biomeWarnings("BAD"));
}
@Test
void packLevelFields() throws ReflectiveOperationException {
PackAttributes attributes = packAttributes(pack);
assertEquals(overrides(MinecraftAttributes.VISUAL_WATER_FOG_END_DISTANCE, 96f, MinecraftAttributes.GAMEPLAY_FAST_LAVA, true),
attributes.entries());
assertEquals(true, attributes.resolvePack(attribute(MinecraftAttributes.GAMEPLAY_FAST_LAVA)));
assertEquals(Map.of("vanilla", RegistryKey.parse("minecraft:overworld"),
"vanilla-generation", RegistryKey.parse("minecraft:overworld")), attributes.parents());
assertEquals(List.of(Either.right(TagKey.parse("#minecraft:in_overworld"))), attributes.scheduleRefs());
assertEquals(List.of(), warnings(attributes));
}
@Test
void scheduleDefinitionLoads() {
PackAttributes attributes = packAttributes(pack);
assertEquals(Set.of(RegistryKey.parse("terra:test_cycle")), attributes.scheduleDefinitions().keySet());
AttributeSchedule definition = attributes.scheduleDefinitions().get(RegistryKey.parse("terra:test_cycle"));
assertEquals(RegistryKey.parse("minecraft:overworld"), definition.clock());
assertEquals(24000, definition.periodTicks().orElseThrow());
ScheduleTrack<?> track = definition.tracks().get(attribute(MinecraftAttributes.VISUAL_SKY_COLOR));
assertEquals(Operation.OVERRIDE, track.operation());
assertEquals(2, track.keyframes().size());
assertEquals(Color.parseRgb("#000000"), track.keyframes().get(0).argument());
assertEquals(12000, track.keyframes().get(1).ticks());
assertEquals(Color.parseRgb("#ffffff"), track.keyframes().get(1).argument());
}
@Test
void resolveWithoutParents() {
PackAttributes attributes = packAttributes(pack);
Biome plain = biome(pack, "PLAIN");
Attribute<Boolean> precipitation = attribute(MinecraftAttributes.BIOME_HAS_PRECIPITATION);
assertNull(attributes.biomeEntryOrNull(precipitation, plain));
assertEquals(precipitation.defaultValue(), attributes.resolve(precipitation, plain));
Attribute<Float> temperature = attribute(MinecraftAttributes.BIOME_TEMPERATURE);
assertNull(attributes.biomeEntryOrNull(temperature, plain));
assertEquals(0.5f, attributes.resolve(temperature, plain));
Attribute<Color> sky = attribute(MinecraftAttributes.VISUAL_SKY_COLOR);
assertNull(attributes.biomeEntryOrNull(sky, biome(pack, "NULLED")));
assertEquals(sky.defaultValue(), attributes.resolve(sky, biome(pack, "NULLED")));
assertEquals(81.6f, attributes.resolve(attribute(MinecraftAttributes.VISUAL_WATER_FOG_END_DISTANCE), biome(pack, "FOGGY")),
1e-4f);
}
@Test
void layersApplyInOrder() {
PackAttributes attributes = packAttributes(pack);
Biome child = biome(pack, "CHILD");
parents = new AttributeParents() {
@Override
@SuppressWarnings("unchecked")
public <T> @Nullable AttributeEntry<T> biomeOrNull(Biome biome, Attribute<T> attribute) {
if(biome != child) return null;
AttributeKey<T> key = attribute.key();
if(key == MinecraftAttributes.VISUAL_WATER_FOG_END_DISTANCE) return (AttributeEntry<T>) AttributeEntry.override(50f);
if(key == MinecraftAttributes.VISUAL_FOG_COLOR) return (AttributeEntry<T>) AttributeEntry.override(Color.rgb(0x111111));
return null;
}
@Override
@SuppressWarnings("unchecked")
public <T> @Nullable AttributeEntry<T> packOrNull(PackAttributes pack, Attribute<T> attribute) {
assertEquals(RegistryKey.parse("minecraft:overworld"), pack.parents().get("vanilla"));
AttributeKey<T> key = attribute.key();
if(key == MinecraftAttributes.VISUAL_WATER_FOG_END_DISTANCE) return (AttributeEntry<T>) AttributeEntry.override(40f);
if(key == MinecraftAttributes.VISUAL_SKY_FOG_END_DISTANCE) return (AttributeEntry<T>) AttributeEntry.override(30f);
return null;
}
};
Attribute<Float> waterFogEnd = attribute(MinecraftAttributes.VISUAL_WATER_FOG_END_DISTANCE);
Attribute<Float> skyFogEnd = attribute(MinecraftAttributes.VISUAL_SKY_FOG_END_DISTANCE);
assertEquals(50f, attributes.resolve(waterFogEnd, child));
assertEquals(Color.parseRgb("#a0b0c0"), attributes.resolve(attribute(MinecraftAttributes.VISUAL_FOG_COLOR), child));
assertEquals(30f, attributes.resolve(skyFogEnd, biome(pack, "PLAIN")));
assertEquals(96f, attributes.resolve(waterFogEnd, biome(pack, "PLAIN")));
assertEquals(96f, attributes.resolvePack(waterFogEnd));
assertEquals(30f, attributes.resolvePack(skyFogEnd));
}
@Test
void columnsAreIdenticalAcrossLoads() throws Exception {
Map<String, Map<AttributeKey<?>, AttributeEntry<?>>> first = null;
for(int i = 0; i < 20; i++) {
ConfigPack loaded = load();
Map<String, Map<AttributeKey<?>, AttributeEntry<?>>> columns = columns(loaded);
assertFalse(columns.get("CHILD").isEmpty());
if(first == null) first = columns;
else assertEquals(first, columns, "Load " + i + " differs");
}
}
private static Map<String, Map<AttributeKey<?>, AttributeEntry<?>>> columns(ConfigPack loaded) {
PackAttributes attributes = packAttributes(loaded);
Map<String, Map<AttributeKey<?>, AttributeEntry<?>>> columns = new HashMap<>();
loaded.getRegistry(Biome.class).forEach((key, biome) -> {
Map<AttributeKey<?>, AttributeEntry<?>> row = new HashMap<>();
AttributeMap declared = attributes.biomeEntries(biome);
for(Attribute<?> attribute : attributes(loaded).entries()) {
AttributeEntry<?> entry = attributes.biomeEntryOrNull(attribute, biome);
assertEquals(declared.get(attribute.key()).orElse(null), entry, biome.getID() + " " + attribute.key());
if(entry != null) row.put(attribute.key(), entry);
}
assertEquals(declared.keys(), row.keySet(), biome.getID());
columns.put(biome.getID(), row);
});
return columns;
}
@Test
void resolveAllocatesNothing() {
PackAttributes attributes = packAttributes(pack);
Biome child = biome(pack, "CHILD");
Biome plain = biome(pack, "PLAIN");
Attribute<Color> fogColor = attribute(MinecraftAttributes.VISUAL_FOG_COLOR);
Attribute<Boolean> precipitation = attribute(MinecraftAttributes.BIOME_HAS_PRECIPITATION);
Attribute<Boolean> fastLava = attribute(MinecraftAttributes.GAMEPLAY_FAST_LAVA);
com.sun.management.ThreadMXBean threads = (com.sun.management.ThreadMXBean) ManagementFactory.getThreadMXBean();
long thread = Thread.currentThread().threadId();
int sink = 0;
for(int i = 0; i < 100_000; i++) sink += reads(attributes, child, plain, fogColor, precipitation, fastLava);
long before = threads.getThreadAllocatedBytes(thread);
for(int i = 0; i < 10_000; i++) sink += reads(attributes, child, plain, fogColor, precipitation, fastLava);
long allocated = threads.getThreadAllocatedBytes(thread) - before;
assertTrue(sink != 0);
assertTrue(allocated < 1024, allocated + " bytes allocated");
}
private static int reads(PackAttributes attributes, Biome child, Biome plain, Attribute<Color> fogColor,
Attribute<Boolean> precipitation, Attribute<Boolean> fastLava) {
int hash = System.identityHashCode(attributes.resolve(fogColor, child));
hash += attributes.resolve(precipitation, plain) ? 1 : 2;
hash += attributes.resolvePack(fastLava) ? 1 : 2;
hash += attributes.biomeEntryOrNull(fogColor, child) == null ? 0 : 1;
return hash;
}
@Test
void scheduleIdsAreChecked() throws Exception {
PackAttributes attributes = packAttributes(new ConfigPackImpl(scheduleFixture(), platform));
assertEquals(List.of(Either.right(TagKey.parse("#minecraft:in_overworld"))), attributes.scheduleRefs());
assertEquals(Set.of(RegistryKey.parse("mypack:seasons"), RegistryKey.parse("mypack:dropping")),
attributes.scheduleDefinitions().keySet());
List<String> warnings = warnings(attributes);
assertEquals(List.of(
"Pack \"SCHEDULE_TEST\": schedule \"seasons\" skipped: schedule IDs must include a namespace, e.g. \"mypack:seasons\"",
"Pack \"SCHEDULE_TEST\": schedule \"#mypack:tagged\" skipped: schedule IDs must not be tags"),
warnings.stream().filter(w -> w.contains("skipped: schedule IDs")).toList());
assertEquals(4, warnings.size(), warnings.toString());
assertTrue(warnings.contains("Pack \"SCHEDULE_TEST\": schedule \"mypack:dropping\" track \"minecraft:visual/moon_phase\" "
+ "dropped: modifier add is not valid for minecraft:visual/moon_phase"), warnings.toString());
assertTrue(warnings.stream().anyMatch(w -> w.startsWith("Pack \"SCHEDULE_TEST\": schedule \"mypack:not valid\" skipped: ")),
warnings.toString());
}
private static Path scheduleFixture() throws URISyntaxException {
return Path.of(AttributePackTest.class.getResource("/packs/schedule-test/pack.yml").toURI()).getParent();
}
}
@@ -0,0 +1,56 @@
package com.dfsek.terra.cli;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.api.properties.Context;
import com.dfsek.terra.api.properties.Properties;
import com.dfsek.terra.api.properties.PropertyKey;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.structure.feature.Feature;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
import com.dfsek.terra.config.pack.ConfigPackImpl;
import static org.junit.jupiter.api.Assertions.assertEquals;
class FeatureStagePackTest {
private static ConfigPack pack;
@BeforeAll
static void setUp() throws Exception {
CLIPlatform platform = new CLIPlatform();
platform.getEventManager().callEvent(new PlatformInitializationEvent());
Path fixture = Path.of(FeatureStagePackTest.class.getResource("/packs/feature-stage-test/pack.yml").toURI()).getParent();
pack = new ConfigPackImpl(fixture, platform);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Map<String, List<String>> featuresByStage(Biome biome) throws ReflectiveOperationException {
GenerationStage stage = pack.getStages().getFirst();
Class<?> biomeFeatures = stage.getClass().getClassLoader()
.loadClass("com.dfsek.terra.addons.generation.feature.config.BiomeFeatures");
PropertyKey<?> key = Context.create((Class) biomeFeatures.asSubclass(Properties.class));
Object properties = biome.getContext().get(key);
Map<Object, List<Feature>> features = (Map<Object, List<Feature>>) biomeFeatures.getMethod("getFeatures").invoke(properties);
Map<String, List<String>> byId = new HashMap<>();
features.forEach((s, list) -> byId.put(((StringIdentifiable) s).getID(), list.stream().map(Feature::getID).toList()));
return byId;
}
@Test
void dottedStageIdReadsNestedPath() throws ReflectiveOperationException {
Biome plain = pack.getRegistry(Biome.class).getByID("PLAIN").orElseThrow();
Map<String, List<String>> features = featuresByStage(plain);
assertEquals(List.of("ROCK"), features.get("nested.stage"));
assertEquals(List.of("ROCK"), features.get("flat"));
}
}
@@ -0,0 +1,7 @@
id: BAD
type: BIOME
extends: GROUND
attributes:
minecraft:visual/fog_color: "#00ff00"
minecraft:visual/sky_color: "not a colour"
@@ -0,0 +1,9 @@
id: BASE
type: BIOME
abstract: true
extends: GROUND
attributes:
minecraft:visual/fog_color: "#102030"
minecraft:visual/sky_color: "#405060"
terra:biome/temperature: 0.8
@@ -0,0 +1,11 @@
# A reference to a reference is followed once, at the top level and nested alike, as for a @Meta String field: both entries
# get the literal "$meta.yml:sky-hex", which is not a colour, and are skipped with a warning.
id: CHAIN
type: BIOME
extends: GROUND
attributes:
minecraft:visual/sky_color: "$meta.yml:chained-color"
minecraft:visual/fog_color:
modifier: override
argument: "$meta.yml:chained-color"
@@ -0,0 +1,6 @@
id: CHILD
type: BIOME
extends: BASE
attributes:
minecraft:visual/fog_color: "#a0b0c0"
@@ -0,0 +1,31 @@
# Meta features inside attribute values: number expressions, "${file:key}" interpolation, "$file:key" references and "<<" includes
# at every depth of a value, including a modifier argument and an opaque particle body.
id: EXPR
type: BIOME
extends: GROUND
attributes:
minecraft:audio/background_music:
default:
sound: minecraft:music.game
min_delay: "2 * 6000"
max_delay: "${meta.yml:music-delay} * 4"
minecraft:visual/water_fog_end_distance:
modifier: multiply
argument: "$meta.yml:fog-scale"
minecraft:audio/ambient_sounds:
loop: "$meta.yml:cave-loop"
mood:
"<<":
- meta.yml:cave-mood
tick_delay: "3000 * 2"
additions:
- "<< meta.yml:cave-additions"
- sound: minecraft:ambient.basalt_deltas.additions
tick_chance: 0.5
minecraft:visual/ambient_particles:
- particle:
"<<":
- meta.yml:particle-options
type: "minecraft:${meta.yml:particle-name}"
probability: "1 / 40"
@@ -0,0 +1,11 @@
# Config preprocessing errors inside attribute values: each warns once for its entry, and the other entries still load.
id: EXPR_BAD
type: BIOME
extends: GROUND
attributes:
minecraft:visual/fog_color: "#123456"
minecraft:visual/fog_start_distance: "${meta.yml:no-such-key} * 2"
minecraft:visual/sky_fog_end_distance:
modifier: add
argument: "${2 * 6000}"
@@ -0,0 +1,8 @@
id: FOGGY
type: BIOME
extends: GROUND
attributes:
minecraft:visual/water_fog_end_distance:
modifier: multiply
argument: 0.85
@@ -0,0 +1,14 @@
# Terrain and palette shared by every fixture biome, kept apart from BASE so that only BASE's children inherit its attributes.
id: GROUND
type: BIOME
abstract: true
vanilla: minecraft:plains
terrain:
sampler:
type: CONSTANT
value: 0
palette:
- BLOCK:minecraft:stone: 319
@@ -0,0 +1,8 @@
# Extends META, so META's meta include is expanded while it is an inherited layer. The water colour is a "$file:key" meta value.
id: META_CHILD
type: BIOME
extends: META
attributes:
terra:biome/downfall: 0.75
terra:biome/water_color: $meta.yml:shared-water-color
@@ -0,0 +1,8 @@
id: META
type: BIOME
extends: GROUND
attributes:
"<<":
- meta.yml:shared-attributes
minecraft:visual/fog_color: "#ffffff"
@@ -0,0 +1,6 @@
id: NULLED
type: BIOME
extends: CHILD
attributes:
minecraft:visual/sky_color: null
@@ -0,0 +1,3 @@
id: PLAIN
type: BIOME
extends: GROUND
@@ -0,0 +1,22 @@
shared-attributes:
minecraft:visual/fog_color: "#010203"
minecraft:visual/sky_color: "#0a0b0c"
terra:biome/downfall: 0.25
shared-water-color: "#112233"
music-delay: 6000
fog-scale: 0.5
cave-loop: minecraft:ambient.cave
cave-mood:
sound: minecraft:ambient.cave
block_search_extent: 8
offset: 2.0
cave-additions:
- sound: minecraft:ambient.crimson_forest.additions
tick_chance: 0.0111
particle-name: dust
particle-options:
color: [1.0, 0.0, 0.0]
scale: 1.0
night-sky: "#000000"
chained-color: "$meta.yml:sky-hex"
sky-hex: "#0a0b0c"
@@ -0,0 +1,43 @@
id: ATTRIBUTE_TEST
version: 1.0.0
author: Terra contributors
generator: NOISE_3D
vanilla: minecraft:overworld
vanilla-generation: minecraft:overworld
addons:
biome-provider-single: "1.+"
chunk-generator-noise-3d: "1.+"
config-attributes: "1.+"
config-biome: "1.+"
config-noise-function: "1.+"
config-palette: "1.+"
language-yaml: "1.+"
minecraft-attributes: "1.+"
palette-block-shortcut: "1.+"
biomes:
type: SINGLE
biome: PLAIN
attributes:
minecraft:visual/water_fog_end_distance: 96
minecraft:gameplay/fast_lava: true
minecraft:visual/fog_color: null
schedules:
- "#minecraft:in_overworld"
schedule-definitions:
terra:test_cycle:
clock: minecraft:overworld
period_ticks: "20 * 60 * 20"
tracks:
minecraft:visual/sky_color:
keyframes:
- ticks: 0
value: "$meta.yml:night-sky"
- ticks: "6000 * 2"
value: "#ffffff"
@@ -0,0 +1,19 @@
id: PLAIN
type: BIOME
vanilla: minecraft:plains
terrain:
sampler:
type: CONSTANT
value: 0
palette:
- BLOCK:minecraft:stone: 319
features:
nested:
stage:
- ROCK
flat:
- ROCK
@@ -0,0 +1,15 @@
id: ROCK
type: FEATURE
distributor:
type: "NO"
locator:
type: SURFACE
range: 0
structures:
distribution:
type: CONSTANT
value: 0
structures: BLOCK:minecraft:stone
@@ -0,0 +1,30 @@
id: FEATURE_STAGE_TEST
version: 1.0.0
author: Terra contributors
generator: NOISE_3D
addons:
biome-provider-single: "1.+"
chunk-generator-noise-3d: "1.+"
config-biome: "1.+"
config-distributors: "1.+"
config-feature: "1.+"
config-locators: "1.+"
config-noise-function: "1.+"
config-palette: "1.+"
generation-stage-feature: "1.+"
language-yaml: "1.+"
palette-block-shortcut: "1.+"
structure-block-shortcut: "1.+"
biomes:
type: SINGLE
biome: PLAIN
# A dotted stage ID reads a nested path in biome configs: "nested.stage" reads features.nested.stage.
stages:
- id: nested.stage
type: FEATURE
- id: flat
type: FEATURE
@@ -0,0 +1,12 @@
id: PLAIN
type: BIOME
vanilla: minecraft:plains
terrain:
sampler:
type: CONSTANT
value: 0
palette:
- BLOCK:minecraft:stone: 319
@@ -0,0 +1,49 @@
id: SCHEDULE_TEST
version: 1.0.0
author: Terra contributors
generator: NOISE_3D
vanilla: minecraft:overworld
vanilla-generation: minecraft:overworld
addons:
biome-provider-single: "1.+"
chunk-generator-noise-3d: "1.+"
config-attributes: "1.+"
config-biome: "1.+"
config-noise-function: "1.+"
config-palette: "1.+"
language-yaml: "1.+"
minecraft-attributes: "1.+"
palette-block-shortcut: "1.+"
biomes:
type: SINGLE
biome: PLAIN
schedules: "#minecraft:in_overworld"
schedule-definitions:
mypack:seasons:
clock: minecraft:overworld
period_ticks: 24000
tracks:
minecraft:visual/sky_color:
keyframes:
- ticks: 0
value: "#000000"
seasons:
clock: minecraft:overworld
"#mypack:tagged":
clock: minecraft:overworld
"mypack:not valid":
clock: minecraft:overworld
mypack:dropping:
clock: minecraft:overworld
tracks:
minecraft:visual/moon_phase:
modifier: add
keyframes:
- ticks: 0
value: full_moon