Skip to content

Dimension Registration

Monika Carpenter edited this page Nov 24, 2023 · 5 revisions

In limlib, registering a dimension has never been easier! First, get familiar with the Registrar. Then come back.

Limlib World

To create a new dimension, you have to register a LimlibWorld inside your registrar class. Which might look something like this:

public class MyRegistrar implements LimlibRegistrar {
	
	public static final Identifier MY_WORLD_ID = new Identifier("modid", "myworld");

	public static final LimlibWorld MY_WORLD =
	new LimlibWorld(
	() -> new DimensionType(...),
	(registry) -> 
		new DimensionOptions(
			registry.get(RegistryKeys.DIMENSION_TYPE)
			.getHolder(RegistryKey
				.of(RegistryKeys.DIMENSION_TYPE, MY_WORLD_ID))
			.get(),
		new MyChunkGenerator(
			new FixedBiomeSource(registry
						.get(RegistryKeys.BIOME)
						.getHolder(MyBiome.MY_BIOME)
						.get())
	)));

	// This is to access our world more easily
	public static final RegistryKey<World> MY_WORLD_KEY = RegistryKey.of(RegistryKeys.WORLD, MY_WORLD_ID);

	@Override
	public void registerHooks() {
		...
		LimlibWorld.LIMLIB_WORLD.register(
			RegistryKey.of(LimlibWorld.LIMLIB_WORLD_KEY, MY_WORLD_ID),
			MY_WORLD,
			Lifecycle.stable()
		);
		
		LimlibRegistryHooks.hook(RegistryKeys.BIOME, (infoLookup, registryKey, registry) -> {
			RegistryEntryLookup<PlacedFeature> features = infoLookup.getRegistryInfo(RegistryKeys.PLACED_FEATURE).get().entryLookup();
			RegistryEntryLookup<ConfiguredCarver<?>> carvers = infoLookup.getRegistryInfo(RegistryKeys.CONFIGURED_CARVER).get().entryLookup();

			registry.add(MyBiome.MY_BIOME, MyBiome.create(features, carvers), Lifecycle.stable());
		});
	}

}

To do this, you also need to specify several properties, which will be explained below.

Dimension Type

This defines the functional properties of the world (its height, if beds work, the ambient light, etc.)

More info on dimension types can be found on the Minecraft wiki's Custom Dimension Type page.

Biome Source

This defines how biomes are generated in the world. Most liminal dimensions will only need one biome, so a FixedBiomeSource is recommended. You must define your biome source as an argument to your ChunkGenerator.

Biome

The biome of the world mostly defines aesthetic properties of the world, like fog and water color. It also technically defines how biomes are carved and how features are placed, but in limlib one usually moves that responsability to the ChunkGenerator, so all is good.

Here's some boilerplate to set up a custom biome:

public class MyBiome {

	public static final RegistryKey<Biome> MY_BIOME = RegistryKey.of(RegistryKeys.BIOME, MY_WORLD_ID);

	public static Biome create(RegistryEntryLookup<PlacedFeature> features, RegistryEntryLookup<ConfiguredCarver<?>> carvers) {
		Biome.Builder biome = new Biome.Builder();

		SpawnSettings.Builder spawnSettings = new SpawnSettings.Builder();

		GenerationSettings.LookupBackedBuilder generationSettings = new GenerationSettings.LookupBackedBuilder(features, carvers);

		BiomeEffects.Builder biomeEffects = new BiomeEffects.Builder();
		// (your effects here)
		BiomeEffects effects = biomeEffects.build();

		biome.spawnSettings(spawnSettings.build());
		biome.generationSettings(generationSettings.build());
		biome.effects(effects);

		// (biome weather related settings here)

		return biome.build();
	}

}

More info on biomes can be found on the Minecraft wiki's Custom Biome page.

Effects

Limlib has some extra features that come along with dimension registration.

Sound Effects

Sound Effects include reverb, distortion, and mainly dimension wide music.

public static final SoundEffects MY_SOUND_EFFECTS = new SoundEffects(
	Optional.of(
		new StaticReverbEffect.Builder()
			.setDecayTime(20.0F)
			.build()),
	Optional.empty(),
	Optional.of(new MusicSound(MySoundEvents.MY_MUSIC, 3000, 8000, true)));

Skybox

A hook to render a custom skybox

public static final Skybox MY_SKYBOX = new TexturedSkybox(new Identifier("modid:textures/sky/my_skybox"));

DimensionEffects

Vanillas builtin dimension visual effects; fog color, cloud height, bright or dark lighting, etc

public static final DimensionEffects MY_DIMENSION_EFFECTS = new StaticDimensionEffects(
	/* Cloud Height, empty for No Clouds */ Optional.empty(),
	/* Alternate Sky Color */ false,
	/* Sky Type; NONE, NORMAL, END */ "NONE",
	/* Brighten Lighting */ true,
	/* Darkened */ false,
	/* Thick Fog */ false,
	/* Sky Shading */ 1.0F);

Post Processors

A post processing shader effect

public static final PostEffect MY_POST_EFFECT = new StaticPostEffect(new Identifier("modid:my_post_effect"));

Registering

You have to register these things as well, inside of a hook.

public class MyRegistrar implements LimlibRegistrar {

	...

	@Override
	public void registerHooks() {
		...
		LimlibRegistryHooks.hook(SoundEffects.SOUND_EFFECTS_KEY,
			(infoLookup, registryKey, registry) -> registry.register(
				RegistryKey.of(SoundEffects.SOUND_EFFECTS_KEY, new Identifier("modid:mysoundeffects")),
				MY_SOUND_EFFECTS,
				Lifecycle.stable()));

		LimlibRegistryHooks.hook(Skybox.SKYBOX_KEY,
			(infoLookup, registryKey, registry) -> registry.register(
				RegistryKey.of(Skybox.SKYBOX_KEY, new Identifier("modid:myskybox")),
				MY_SKYBOX,
				Lifecycle.stable()));

		LimlibRegistryHooks.hook(DimensionEffects.DIMENSION_EFFECTS_KEY,
			(infoLookup, registryKey, registry) -> registry.register(
				RegistryKey.of(DimensionEffects.DIMENSION_EFFECTS_KEY, new Identifier("modid:mydimensioneffects")),
				MY_DIMENSION_EFFECTS,
				Lifecycle.stable()));

		LimlibRegistryHooks.hook(PostEffect.POST_EFFECT_KEY,
			(infoLookup, registryKey, registry) -> registry.register(
				RegistryKey.of(PostEffect.POST_EFFECT_KEY, new Identifier("modid:myposteffect")),
				MY_POST_EFFECT,
				Lifecycle.stable()));
	}

}