Skip to content

Commit

Permalink
Add compatibility for Modern Beta on Fabric/Quilt.
Browse files Browse the repository at this point in the history
- Modern Beta biomes can now be replaced (direct replacement only)
  • Loading branch information
gniftygnome committed Jan 12, 2024
1 parent 75acaa5 commit bcfef15
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 6 deletions.
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ allprojects {
maven {
url = 'https://maven.minecraftforge.net/'
}

// for Modern Beta
exclusiveContent {
forRepository {
maven {
url "https://cursemaven.com"
}
}
filter {
includeGroup "curse.maven"
}
}
}

tasks.withType(JavaCompile).configureEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.terraformersmc.biolith.api.compat;

import com.terraformersmc.biolith.impl.compat.BiolithCompat;

/**
* <p>
* BiolithCompats can be used to check whether Biolith has enabled a compatibility mode.
* </p>
* <p>
* For example:
* </p>
* <pre>{@code
* if (BiolithCompats.isCompatEnabled(BiolithCompats.MODERN_BETA)) {
* BiomePlacement.replaceOverworld(ModernBetaBiomeKeys.BETA_FOREST, FOREST_A, 0.4D);
* BiomePlacement.replaceOverworld(ModernBetaBiomeKeys.BETA_FOREST, FOREST_B, 0.4D);
* }
* }</pre>
*/
@SuppressWarnings("unused")
public enum BiolithCompats {
MODERN_BETA,
TERRABLENDER,
VANILLA;

public static boolean isCompatEnabled(BiolithCompats compat) {
return switch (compat) {
case MODERN_BETA -> BiolithCompat.COMPAT_MODERN_BETA;
case TERRABLENDER -> BiolithCompat.COMPAT_TERRABLENDER;
case VANILLA -> true;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.terraformersmc.biolith.api.compat;

import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.world.biome.Biome;

/**
* <p>
* Copies of the registry keys of Modern Beta's biomes. These keys can be used to
* target Modern Beta biomes with Biolith's replacement noise, without depending on
* Modern Beta when building. Modern Beta biomes can be replaced, but they cannot
* be placed or targeted with sub-biome matchers.
* </p>
* <p>
* For example, to replace 20% of "Beta Forest" with "Forest A" and 20% with "Forest B":
* </p>
* <pre>{@code
* if (BiolithCompats.isCompatEnabled(BiolithCompats.MODERN_BETA)) {
* BiomePlacement.replaceOverworld(ModernBetaBiomeKeys.BETA_FOREST, FOREST_A, 0.4D);
* BiomePlacement.replaceOverworld(ModernBetaBiomeKeys.BETA_FOREST, FOREST_B, 0.4D);
* }
* }</pre>
*/
@SuppressWarnings("unused")
public class ModernBetaBiomeKeys {
public static final RegistryKey<Biome> BETA_FOREST = keyOf("beta_forest");
public static final RegistryKey<Biome> BETA_SHRUBLAND = keyOf("beta_shrubland");
public static final RegistryKey<Biome> BETA_DESERT = keyOf("beta_desert");
public static final RegistryKey<Biome> BETA_SAVANNA = keyOf("beta_savanna");
public static final RegistryKey<Biome> BETA_PLAINS = keyOf("beta_plains");
public static final RegistryKey<Biome> BETA_SEASONAL_FOREST = keyOf("beta_seasonal_forest");
public static final RegistryKey<Biome> BETA_RAINFOREST = keyOf("beta_rainforest");
public static final RegistryKey<Biome> BETA_SWAMPLAND = keyOf("beta_swampland");
public static final RegistryKey<Biome> BETA_TAIGA = keyOf("beta_taiga");
public static final RegistryKey<Biome> BETA_TUNDRA = keyOf("beta_tundra");
public static final RegistryKey<Biome> BETA_ICE_DESERT = keyOf("beta_ice_desert");

public static final RegistryKey<Biome> BETA_OCEAN = keyOf("beta_ocean");
public static final RegistryKey<Biome> BETA_LUKEWARM_OCEAN = keyOf("beta_lukewarm_ocean");
public static final RegistryKey<Biome> BETA_WARM_OCEAN = keyOf("beta_warm_ocean");
public static final RegistryKey<Biome> BETA_COLD_OCEAN = keyOf("beta_cold_ocean");
public static final RegistryKey<Biome> BETA_FROZEN_OCEAN = keyOf("beta_frozen_ocean");

public static final RegistryKey<Biome> BETA_SKY = keyOf("beta_sky");

public static final RegistryKey<Biome> PE_FOREST = keyOf("pe_forest");
public static final RegistryKey<Biome> PE_SHRUBLAND = keyOf("pe_shrubland");
public static final RegistryKey<Biome> PE_DESERT = keyOf("pe_desert");
public static final RegistryKey<Biome> PE_SAVANNA = keyOf("pe_savanna");
public static final RegistryKey<Biome> PE_PLAINS = keyOf("pe_plains");
public static final RegistryKey<Biome> PE_SEASONAL_FOREST = keyOf("pe_seasonal_forest");
public static final RegistryKey<Biome> PE_RAINFOREST = keyOf("pe_rainforest");
public static final RegistryKey<Biome> PE_SWAMPLAND = keyOf("pe_swampland");
public static final RegistryKey<Biome> PE_TAIGA = keyOf("pe_taiga");
public static final RegistryKey<Biome> PE_TUNDRA = keyOf("pe_tundra");
public static final RegistryKey<Biome> PE_ICE_DESERT = keyOf("pe_ice_desert");

public static final RegistryKey<Biome> PE_OCEAN = keyOf("pe_ocean");
public static final RegistryKey<Biome> PE_LUKEWARM_OCEAN = keyOf("pe_lukewarm_ocean");
public static final RegistryKey<Biome> PE_WARM_OCEAN = keyOf("pe_warm_ocean");
public static final RegistryKey<Biome> PE_COLD_OCEAN = keyOf("pe_cold_ocean");
public static final RegistryKey<Biome> PE_FROZEN_OCEAN = keyOf("pe_frozen_ocean");

public static final RegistryKey<Biome> ALPHA = keyOf("alpha");
public static final RegistryKey<Biome> ALPHA_WINTER = keyOf("alpha_winter");

public static final RegistryKey<Biome> INFDEV_611 = keyOf("infdev_611");
public static final RegistryKey<Biome> INFDEV_420 = keyOf("infdev_420");
public static final RegistryKey<Biome> INFDEV_415 = keyOf("infdev_415");
public static final RegistryKey<Biome> INFDEV_227 = keyOf("infdev_227");

public static final RegistryKey<Biome> INDEV_NORMAL = keyOf("indev_normal");
public static final RegistryKey<Biome> INDEV_HELL = keyOf("indev_hell");
public static final RegistryKey<Biome> INDEV_PARADISE = keyOf("indev_paradise");
public static final RegistryKey<Biome> INDEV_WOODS = keyOf("indev_woods");

private static RegistryKey<Biome> keyOf(String name) {
return RegistryKey.of(RegistryKeys.BIOME, Identifier.of("modern_beta", name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ public BiolithDescribeCommand.DescribeBiomeData getBiomeData(int x, int y, int z
subBiomeRequest.biome());
}

// For Modern Beta and any other similar direct-only schemes.
public RegistryEntry<Biome> getDirectReplacement(int x, int y, int z, RegistryEntry<Biome> biomeEntry) {
RegistryKey<Biome> biomeKey = biomeEntry.getKey().orElseThrow();

// select phase one -- direct replacements
if (replacementRequests.containsKey(biomeKey)) {
ReplacementRequest request = replacementRequests.get(biomeKey).selectReplacement(getLocalNoise(x, y, z));

if (request != null) {

if (!request.biome().equals(VANILLA_PLACEHOLDER)) {
biomeEntry = request.biomeEntry();
}
}
}

return biomeEntry;
}

public abstract void writeBiomeEntries(Consumer<Pair<MultiNoiseUtil.NoiseHypercube, RegistryEntry<Biome>>> parameters);

public abstract void writeBiomeParameters(Consumer<Pair<MultiNoiseUtil.NoiseHypercube, RegistryKey<Biome>>> parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ private static int atBlockPos(CommandContext<ServerCommandSource> context, Block
}
MultiNoiseUtil.MultiNoiseSampler noise = world.getChunkManager().getNoiseConfig().getMultiNoiseSampler();

// Describe Modern Beta worldgen if it's active.
if (BiolithCompat.COMPAT_MODERN_BETA) {
int mbStatus = Services.PLATFORM.describeModernBeta(context, biomeX, biomeY, biomeZ, world, biomeSource, biomeEntries, noise);
if (mbStatus != 0) {
/*
* mbStatus == 0 means Modern Beta although present is not generating this world
* Other values are the return value from our MB compat describe functionality
* (meaning, for better or worse, describe is done)
*/
return mbStatus;
}
}

/*
* Gather data
*/
Expand Down Expand Up @@ -214,7 +227,7 @@ private static int atBlockPos(CommandContext<ServerCommandSource> context, Block
return 1;
}

private static MutableText textFromFittestNodes(BiolithFittestNodes<RegistryEntry<Biome>> fittestNodes) {
public static MutableText textFromFittestNodes(BiolithFittestNodes<RegistryEntry<Biome>> fittestNodes) {
MutableText text = textFromBiome(fittestNodes.ultimate());

if (fittestNodes.penultimate() != null) {
Expand All @@ -227,15 +240,15 @@ private static MutableText textFromFittestNodes(BiolithFittestNodes<RegistryEntr
return text;
}

private static MutableText textFromBiome(MultiNoiseUtil.SearchTree.TreeLeafNode<RegistryEntry<Biome>> leafNode) {
public static MutableText textFromBiome(MultiNoiseUtil.SearchTree.TreeLeafNode<RegistryEntry<Biome>> leafNode) {
return textFromBiome(leafNode.value.getKey().orElseThrow());
}

private static MutableText textFromBiome(RegistryEntry<Biome> biome) {
public static MutableText textFromBiome(RegistryEntry<Biome> biome) {
return textFromBiome(biome.getKey().orElseThrow());
}

private static MutableText textFromBiome(RegistryKey<Biome> biome) {
public static MutableText textFromBiome(RegistryKey<Biome> biome) {
return Text.translatable(biome.getValue().toTranslationKey("biome"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

public class BiolithCompat {
public static final boolean COMPAT_DATAGEN = System.getProperty("fabric-api.datagen") != null;
public static final boolean COMPAT_MODERN_BETA = Services.PLATFORM.isModLoaded("modern_beta");
public static final boolean COMPAT_TERRABLENDER = Services.PLATFORM.isModLoaded("terrablender");

public static void init() {
if (COMPAT_MODERN_BETA) {
Biolith.LOGGER.info("Enabling Biolith's Modern Beta compatibility layer.");
}
if (COMPAT_TERRABLENDER) {
Biolith.LOGGER.info("Enabling Biolith's TerraBlender compatibility layer.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.terraformersmc.biolith.impl.platform.services;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.terraformersmc.biolith.impl.compat.TerraBlenderCompat;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
import org.apache.commons.lang3.function.TriFunction;

import java.nio.file.Path;
Expand Down Expand Up @@ -49,6 +55,22 @@ default String getEnvironmentName() {
*/
Path getConfigDir();

/**
* Sends the biolith describe output for Modern Beta biome sources.
*
* @param context Command context
* @param biomeX Biome X position
* @param biomeY Biome Y position
* @param biomeZ Biome Z position
* @param world ServerWorld containing the position
* @param biomeSource Relevant biome source
* @param biomeEntries Biome entries if any
* @return 0 to pass; otherwise the command return value
*/
default int describeModernBeta(CommandContext<ServerCommandSource> context, int biomeX, int biomeY, int biomeZ, ServerWorld world, BiomeSource biomeSource, MultiNoiseUtil.Entries<RegistryEntry<Biome>> biomeEntries, MultiNoiseUtil.MultiNoiseSampler noise) {
return 0;
}

/**
* Gets the current platform's implementation of TerraBlenderCompat.
*
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/biolith/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"biolith.command.describe.header": "biome values",
"biolith.command.describe.biome.vanilla": "Vanilla/data biome: ",
"biolith.command.describe.biome.terrablender": "TerraBlender biome: ",
"biolith.command.describe.biome.modern_beta": "Modern Beta biome: ",
"biolith.command.describe.biome.replacement": "Replacement biome: ",
"biolith.command.describe.biome.sub": "Sub-biome selected: ",
"biolith.command.describe.biome.nearest": "nearest: ",
Expand Down
7 changes: 5 additions & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ dependencies {
common(project(path: ":common", configuration: "namedElements")) { transitive = false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive = false }

// Terraform Surfaces API for OpenSimplexNoise
//include(modImplementation("com.terraformersmc.terraform-api:terraform-surfaces-api-v1:${rootProject.terraform_surfaces_api_version}"))

// TerraBlender so we can use its API
modCompileOnly "com.github.glitchfiend:TerraBlender-fabric:${rootProject.terrablender_version}"

// Terraform Surfaces API for OpenSimplexNoise
//include(modImplementation("com.terraformersmc.terraform-api:terraform-surfaces-api-v1:${rootProject.terraform_surfaces_api_version}"))
// Modern Beta so we can target it with mixins
modCompileOnly "curse.maven:modern_beta-410423:4836942"
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.terraformersmc.biolith.impl.compat;

import com.mojang.brigadier.context.CommandContext;
import com.terraformersmc.biolith.impl.Biolith;
import com.terraformersmc.biolith.impl.biome.BiolithFittestNodes;
import com.terraformersmc.biolith.impl.biome.BiomeCoordinator;
import com.terraformersmc.biolith.impl.biome.DimensionBiomePlacement;
import com.terraformersmc.biolith.impl.commands.BiolithDescribeCommand;
import mod.bespectacled.modernbeta.world.biome.ModernBetaBiomeSource;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.util.MultiNoiseUtil;

import static com.terraformersmc.biolith.impl.commands.BiolithDescribeCommand.textFromBiome;

public class ModernBetaCompatFabric {
public static int describe(CommandContext<ServerCommandSource> context, int biomeX, int biomeY, int biomeZ, ServerWorld world, BiomeSource biomeSource, MultiNoiseUtil.Entries<RegistryEntry<Biome>> biomeEntries, MultiNoiseUtil.MultiNoiseSampler noise) {
if (!(biomeSource instanceof ModernBetaBiomeSource)) {
return 0;
}

RegistryEntry<Biome> original = ((ModernBetaBiomeSource) biomeSource).getBiomeProvider().getBiome(biomeX, biomeY, biomeZ);
BiolithFittestNodes<RegistryEntry<Biome>> fittestNodes = new BiolithFittestNodes<>(new MultiNoiseUtil.SearchTree.TreeLeafNode<>(DimensionBiomePlacement.OUT_OF_RANGE, original), 0, null, Integer.MAX_VALUE);

double replacementNoise = BiomeCoordinator.OVERWORLD.getLocalNoise(biomeX, biomeY, biomeZ);
int replacementScale = Biolith.getConfigManager().getGeneralConfig().getOverworldReplacementScale();

BiolithDescribeCommand.DescribeBiomeData describeBiomeData = BiomeCoordinator.OVERWORLD.getBiomeData(biomeX, biomeY, biomeZ, new MultiNoiseUtil.NoiseValuePoint(0,0,0,0,0,0), fittestNodes);

String worldTranslationKey = world.getRegistryKey().getValue().toTranslationKey();

context.getSource().sendMessage(Text.literal("§nBiolith ")
.append(Text.translatable(worldTranslationKey).formatted(Formatting.UNDERLINE))
.append(Text.literal("§n ("))
.append(Text.translatable("biolith.command.describe.biome.scale").formatted(Formatting.UNDERLINE))
.append(Text.literal("§n: " + replacementScale + ") "))
.append(Text.translatable("biolith.command.describe.header").formatted(Formatting.UNDERLINE)));

context.getSource().sendMessage(Text.literal(String.format("§6BR§r:%+05.3f", replacementNoise)));

context.getSource().sendMessage(Text.translatable("biolith.command.describe.biome.modern_beta")
.append(textFromBiome(original)));

if (describeBiomeData.replacementBiome() != null) {
context.getSource().sendMessage(Text.translatable("biolith.command.describe.biome.replacement")
.append(textFromBiome(describeBiomeData.replacementBiome()))
.append(Text.literal("\n "))
.append(describeBiomeData.lowerBiome() == null ?
Text.translatable("biolith.command.describe.biome.none") :
textFromBiome(describeBiomeData.lowerBiome()))
.append(Text.literal(" < "))
.append(textFromBiome(describeBiomeData.replacementBiome()))
.append(Text.literal(" < "))
.append(describeBiomeData.higherBiome() == null ?
Text.translatable("biolith.command.describe.biome.none") :
textFromBiome(describeBiomeData.higherBiome()))
.append(Text.literal(String.format("\n %+05.3f < %+05.3f < %+05.3f ",
describeBiomeData.replacementRange().x,
replacementNoise,
describeBiomeData.replacementRange().y))));
}

return 1;
}
}
Loading

0 comments on commit bcfef15

Please sign in to comment.