Skip to content

Commit

Permalink
Simplify Terrablender integration a lot. The Weald now seems to generate
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Dec 6, 2023
1 parent eb46302 commit 8af996b
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 182 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/violetmoon/quark/base/Quark.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.violetmoon.quark.integration.claim.IClaimIntegration;
import org.violetmoon.quark.integration.lootr.ILootrIntegration;
import org.violetmoon.quark.integration.lootr.LootrIntegration;
import org.violetmoon.quark.integration.terrablender.AbstractUndergroundBiomeHandler;
import org.violetmoon.quark.integration.terrablender.TerrablenderUndergroundBiomeHandler;
import org.violetmoon.quark.integration.terrablender.VanillaUndergroundBiomeHandler;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zetaimplforge.ForgeZeta;

Expand All @@ -37,6 +40,10 @@ public class Quark {
() -> LootrIntegration::new,
() -> ILootrIntegration.Dummy::new);

public static final AbstractUndergroundBiomeHandler TERRABLENDER_INTEGRATION = ZETA.modIntegration("terrablender",
() -> TerrablenderUndergroundBiomeHandler::new,
() -> VanillaUndergroundBiomeHandler::new);

public Quark() {
instance = this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,17 @@ public class GeneralConfig {

@Config(description = "Set to true to make the quark big worldgen features such as stone clusters generate as spheres rather than unique shapes. It's faster, but won't look as cool")
public static boolean useFastWorldgen = false;

@Config(description = "Used for terrablender integration")

@Config(description = "If 'true' and TerraBlender is present, Quark will add a TerraBlender region. The region will contain vanilla biomes and the Glimmering Weald.")
public static boolean terrablenderAddRegion = true;

@Config(description = "Quark will set this weight for its TerraBlender region.")
public static int terrablenderRegionWeight = 1;

@Config(description = "If 'true', Quark will modify the `minecraft:overworld` MultiNoiseBiomeSourceParamaterList preset, even when Terrablender is installed.\n" +
"This will have various knock-on effects but might make the Weald more common, or appear closer to modded biomes. Who knows?")
public static boolean terrablenderModifyVanillaAnyway = false;

@Config(description = "Set to false to stop quark from adding its own items to multi-requirement vanilla advancements")
public static boolean enableAdvancementModification = true;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void start() {
.subscribe(WoodSetHandler.class)
.subscribe(WorldGenHandler.class)
.subscribe(FuelHandler.class)
.subscribe(UndergroundBiomeHandler.class)
.subscribe(EntitySpawnHandler.class)
.subscribe(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.placement.HeightRangePlacement;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
Expand All @@ -43,8 +42,6 @@
import org.violetmoon.quark.base.config.Config;
import org.violetmoon.quark.base.handler.GeneralConfig;
import org.violetmoon.quark.base.handler.QuarkSounds;
import org.violetmoon.quark.base.handler.UndergroundBiomeHandler;
import org.violetmoon.quark.base.util.registryaccess.RegistryAccessUtil;
import org.violetmoon.quark.content.mobs.module.StonelingsModule;
import org.violetmoon.quark.content.world.block.GlowLichenGrowthBlock;
import org.violetmoon.quark.content.world.block.GlowShroomBlock;
Expand All @@ -66,7 +63,6 @@
@ZetaLoadModule(category = "world")
public class GlimmeringWealdModule extends ZetaModule {

private static final Climate.Parameter FULL_RANGE = Climate.Parameter.span(-1.0F, 1.0F);
public static final ResourceLocation BIOME_NAME = new ResourceLocation(Quark.MOD_ID, "glimmering_weald");
public static final ResourceKey<Biome> BIOME_KEY = ResourceKey.create(Registries.BIOME, BIOME_NAME);

Expand Down Expand Up @@ -157,8 +153,9 @@ public void postRegister(ZRegister.Post e) {
wmax = 2;
wmin = 1.55f;
}
UndergroundBiomeHandler.addUndergroundBiome(this, Climate.parameters(FULL_RANGE, FULL_RANGE, FULL_RANGE, FULL_RANGE,
Climate.Parameter.span(wmin, wmax), FULL_RANGE, 0F), BIOME_NAME);
Climate.Parameter FULL_RANGE = Climate.Parameter.span(-1.0F, 1.0F);
Quark.TERRABLENDER_INTEGRATION.registerUndergroundBiome(this, BIOME_NAME, Climate.parameters(FULL_RANGE, FULL_RANGE, FULL_RANGE, FULL_RANGE,
Climate.Parameter.span(wmin, wmax), FULL_RANGE, 0F));

Quark.ZETA.advancementModifierRegistry.addModifier(new AdventuringTimeModifier(this, ImmutableSet.of(BIOME_KEY))
.setCondition(() -> GeneralConfig.enableAdvancementModification));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.violetmoon.quark.integration.terrablender;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

import com.mojang.datafixers.util.Pair;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Climate;
import net.minecraft.world.level.biome.OverworldBiomeBuilder;
import org.violetmoon.zeta.module.ZetaModule;

public abstract class AbstractUndergroundBiomeHandler {

protected List<UndergroundBiomeDesc> undergroundBiomeDescs = new ArrayList<>(2);

public void registerUndergroundBiome(ZetaModule module, ResourceLocation id, Climate.ParameterPoint climate) {
registerUndergroundBiome(new UndergroundBiomeDesc(module, id, climate));
}

public void registerUndergroundBiome(UndergroundBiomeDesc desc) {
undergroundBiomeDescs.add(desc);
}

protected void addUndergroundBiomesTo(Consumer<Pair<Climate.ParameterPoint, ResourceKey<Biome>>> consumer) {
for(UndergroundBiomeDesc desc : undergroundBiomeDescs)
if(desc.module().enabled)
consumer.accept(Pair.of(desc.climateParameterPoint(), desc.resourceKey()));
}

/**
* This gets hooked up to the vanilla method OverworldBiomeBuilder#addUndergroundBiomes.
* Calling the Consumer will effectively, add biomes to the `minecraft:overworld` MultiNoiseBiomeSourceParameterList.Preset.
*/
public abstract void modifyVanillaOverworldPreset(OverworldBiomeBuilder builder, Consumer<Pair<Climate.ParameterPoint, ResourceKey<Biome>>> consumer);

public record UndergroundBiomeDesc(ZetaModule module, ResourceLocation id, Climate.ParameterPoint climateParameterPoint) {
public ResourceKey<Biome> resourceKey() {
return ResourceKey.create(Registries.BIOME, id);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.violetmoon.quark.integration.terrablender;

import java.util.function.Consumer;

import com.mojang.datafixers.util.Pair;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Climate;
import net.minecraft.world.level.biome.OverworldBiomeBuilder;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.handler.GeneralConfig;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.load.ZCommonSetup;
import terrablender.api.Region;
import terrablender.api.RegionType;
import terrablender.api.Regions;

public class TerrablenderUndergroundBiomeHandler extends AbstractUndergroundBiomeHandler {

public TerrablenderUndergroundBiomeHandler() {
Quark.LOG.info("Initializing TerraBlender underground biome compat");
Quark.ZETA.loadBus.subscribe(this);
}

@LoadEvent
public void commonSetup(ZCommonSetup event) {
event.enqueueWork(() -> {
if(undergroundBiomeDescs.isEmpty() || GeneralConfig.terrablenderAddRegion)
return; // No need to register a region.

Regions.register(new Region(Quark.asResource("biome_provider"), RegionType.OVERWORLD, GeneralConfig.terrablenderRegionWeight) {
@Override
public void addBiomes(Registry<Biome> registry, Consumer<Pair<Climate.ParameterPoint, ResourceKey<Biome>>> consumer) {
// Quark's region is the same as vanilla's, but with underground biomes added.
addModifiedVanillaOverworldBiomes(consumer, noModifications -> { });

// When we call TerraBlender's addModifiedVanillaOverworldBiomes...
// -> it calls terrablender ModifiedVanillaOverworldBuilder.build
// -> it calls vanilla OverworldBiomeBuilder.addBiomes
// -> it calls vanilla OverworldBiomeBuilder.addUndergroundBiomes
// -> it gets hooked by Quark's OverworldBiomeBuilderMixin
// -> it calls quark AbstractUndergroundBiomeHandler.modifyVanillaOverworldPreset.
// Therefore, if terrablenderModifyVanillaAnyway is enabled, we already called addUndergroundBiomesTo.
if(!GeneralConfig.terrablenderModifyVanillaAnyway)
addUndergroundBiomesTo(consumer);
}
});
});
}

@Override
public void modifyVanillaOverworldPreset(OverworldBiomeBuilder builder, Consumer<Pair<Climate.ParameterPoint, ResourceKey<Biome>>> consumer) {
if(GeneralConfig.terrablenderModifyVanillaAnyway)
addUndergroundBiomesTo(consumer);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.violetmoon.quark.integration.terrablender;

import java.util.function.Consumer;

import com.mojang.datafixers.util.Pair;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Climate;
import net.minecraft.world.level.biome.OverworldBiomeBuilder;

public class VanillaUndergroundBiomeHandler extends AbstractUndergroundBiomeHandler {

@Override
public void modifyVanillaOverworldPreset(OverworldBiomeBuilder builder, Consumer<Pair<Climate.ParameterPoint, ResourceKey<Biome>>> consumer) {
addUndergroundBiomesTo(consumer);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.violetmoon.quark.base.handler.UndergroundBiomeHandler;
import org.violetmoon.quark.base.Quark;

import com.mojang.datafixers.util.Pair;

Expand All @@ -20,7 +20,7 @@ public class OverworldBiomeBuilderMixin {

@Inject(method = "addUndergroundBiomes", at = @At("RETURN"))
public void addUndergroundBiomes(Consumer<Pair<Climate.ParameterPoint, ResourceKey<Biome>>> consumer, CallbackInfo info) {
UndergroundBiomeHandler.addUndergroundBiomes((OverworldBiomeBuilder) (Object) this, consumer);
Quark.TERRABLENDER_INTEGRATION.modifyVanillaOverworldPreset((OverworldBiomeBuilder) (Object) this, consumer);
}

}
Loading

0 comments on commit 8af996b

Please sign in to comment.