Skip to content

Commit

Permalink
add underworld dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Jan 26, 2025
1 parent fd5aba9 commit aa8ab46
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"biome_source": {
"type": "vampirism:underworld"
},
"settings": "vampirism:noise"
"settings": "vampirism:underworld"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"ambient_light": 5.0,
"bed_works": false,
"coordinate_scale": 1.0,
"effects": "minecraft:overworld",
"effects": "vampirism:underworld",
"fixed_time": 6000,
"has_ceiling": false,
"has_raids": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"remove": [
"vampirism:underworld_vampire_forest"
],
"values": [
"#vampirism:has_faction/vampire"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"remove": [
"vampirism:underworld_vampire_forest"
],
"values": [
"#vampirism:has_faction/vampire"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"remove": [
"vampirism:underworld_vampire_forest"
],
"values": [
"#c:is_wasteland",
"#c:is_plateau",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"remove": [
"vampirism:underworld_vampire_forest"
],
"values": [
"#vampirism:has_faction/vampire"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "minecraft:old_blended_noise",
"smear_scale_multiplier": 4.0,
"xz_factor": 80.0,
"xz_scale": 0.25,
"y_factor": 160.0,
"y_scale": 0.25
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minecraft:add",
"argument1": {
"type": "vampirism:underworld"
},
"argument2": "vampirism:base_3d_noise"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"erosion": {
"type": "minecraft:cache_2d",
"argument": {
"type": "minecraft:end_islands"
"type": "vampirism:underworld"
}
},
"final_density": {
Expand Down Expand Up @@ -63,7 +63,7 @@
"argument2": {
"type": "minecraft:add",
"argument1": 23.4375,
"argument2": "minecraft:end/sloped_cheese"
"argument2": "vampirism:underworld"
}
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@
"argument2": {
"type": "minecraft:cache_2d",
"argument": {
"type": "minecraft:end_islands"
"type": "vampirism:underworld"
}
}
}
Expand All @@ -123,7 +123,7 @@
}
},
"lava": 0.0,
"ridges": 0.0,
"ridges": "minecraft:overworld/ridges",
"temperature": 0.0,
"vegetation": {
"type": "minecraft:shifted_noise",
Expand Down
99 changes: 45 additions & 54 deletions src/main/java/de/teamlapen/vampirism/core/ModDimensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.world.dimension.UnderworldBiomeSource;
import de.teamlapen.vampirism.world.dimension.UnderworldDensityFunction;
import de.teamlapen.vampirism.world.dimension.UnderworldEffects;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstrapContext;
Expand All @@ -18,8 +20,10 @@
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.*;
import net.minecraft.world.level.levelgen.synth.BlendedNoise;
import net.minecraft.world.level.levelgen.synth.NormalNoise;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.event.RegisterDimensionSpecialEffectsEvent;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;

Expand All @@ -28,34 +32,48 @@

public class ModDimensions {

public static final ResourceKey<DimensionType> UNDERWORLD = ResourceKey.create(Registries.DIMENSION_TYPE, VResourceLocation.mod("underworld"));
public static final ResourceKey<LevelStem> UNDERWORLD_STEM = ResourceKey.create(Registries.LEVEL_STEM, VResourceLocation.mod("underworld"));
public static final ResourceKey<Level> UNDERWORLD_LEVEL = ResourceKey.create(Registries.DIMENSION, UNDERWORLD_STEM.location());
public static final ResourceKey<NoiseGeneratorSettings> RULES = ResourceKey.create(Registries.NOISE_SETTINGS, VResourceLocation.mod("noise"));
public static final DeferredRegister<MapCodec<? extends BiomeSource>> BIOME_SOURCES = DeferredRegister.create(Registries.BIOME_SOURCE, REFERENCE.MODID);
private static final ResourceKey<DensityFunction> SLOPED_CHEESE_END = ResourceKey.create(Registries.DENSITY_FUNCTION, ResourceLocation.withDefaultNamespace("end/sloped_cheese"));
private static final ResourceKey<DensityFunction> SHIFT_X = ResourceKey.create(Registries.DENSITY_FUNCTION, ResourceLocation.withDefaultNamespace("shift_x"));
private static final ResourceKey<DensityFunction> SHIFT_Z = ResourceKey.create(Registries.DENSITY_FUNCTION, ResourceLocation.withDefaultNamespace("shift_z"));
public static final DeferredRegister<MapCodec<? extends DensityFunction>> DENSITY_FUNCTIONS = DeferredRegister.create(Registries.DENSITY_FUNCTION_TYPE, REFERENCE.MODID);

@SuppressWarnings("unused")
public static final DeferredHolder<MapCodec<? extends BiomeSource>, MapCodec<? extends BiomeSource>> UNDERWORLD_BIOME_SOURCE_CODEC = BIOME_SOURCES.register("underworld", () -> UnderworldBiomeSource.CODEC);
@SuppressWarnings("unused")
public static final DeferredHolder<MapCodec<? extends DensityFunction>, MapCodec<? extends DensityFunction>> UNDERWORLD_DENSITY_FUNCTION_CODEC = DENSITY_FUNCTIONS.register("underworld", UnderworldDensityFunction.CODEC::codec);

public static final ResourceKey<DimensionType> UNDERWORLD_DIMENSION_TYPE = ResourceKey.create(Registries.DIMENSION_TYPE, VResourceLocation.mod("underworld"));
public static final ResourceKey<LevelStem> UNDERWORLD_LEVEL_STEM = ResourceKey.create(Registries.LEVEL_STEM, VResourceLocation.mod("underworld"));
public static final ResourceKey<Level> UNDERWORLD_LEVEL = ResourceKey.create(Registries.DIMENSION, UNDERWORLD_LEVEL_STEM.location());
public static final ResourceKey<NoiseGeneratorSettings> UNDERWORLD_NOISE_GENERATOR = ResourceKey.create(Registries.NOISE_SETTINGS, VResourceLocation.mod("underworld"));
public static final ResourceKey<DensityFunction> UNDERWORLD_DENSITY_FUNCTION = ResourceKey.create(Registries.DENSITY_FUNCTION, VResourceLocation.mod("underworld"));
public static final ResourceKey<DensityFunction> BASE_3D_NOISE_UNDERWORLD = ResourceKey.create(Registries.DENSITY_FUNCTION, VResourceLocation.mod("base_3d_noise"));

public static final ResourceLocation UNDERWORLD_DIMENSION_SPECIAL_EFFECTS = VResourceLocation.mod("underworld");

public static final DeferredHolder<MapCodec<? extends BiomeSource>, MapCodec<? extends BiomeSource>> UNDERWORLD_BIOME_SOURCE = BIOME_SOURCES.register("underworld", () -> UnderworldBiomeSource.CODEC);

static void register(IEventBus bus) {
BIOME_SOURCES.register(bus);
DENSITY_FUNCTIONS.register(bus);
}
static void bootstrapTypes(BootstrapContext<DimensionType> context) {
context.register(UNDERWORLD, new DimensionType(OptionalLong.of(6000), false, false, false, false, 1.0, false, false, 0, 256, 256, BlockTags.INFINIBURN_END, BuiltinDimensionTypes.OVERWORLD_EFFECTS, 5f, new DimensionType.MonsterSettings(false, false, UniformInt.of(0,7), 0)));

static void bootstrapDimensionTypes(BootstrapContext<DimensionType> context) {
context.register(UNDERWORLD_DIMENSION_TYPE, new DimensionType(OptionalLong.of(6000), false, false, false, false, 1.0, false, false, 0, 256, 256, BlockTags.INFINIBURN_END, UNDERWORLD_DIMENSION_SPECIAL_EFFECTS, 5f, new DimensionType.MonsterSettings(false, false, UniformInt.of(0,7), 0)));
}

static void bootstrapLevelStem(BootstrapContext<LevelStem> context) {
context.register(UNDERWORLD_LEVEL_STEM, new LevelStem(context.lookup(Registries.DIMENSION_TYPE).getOrThrow(UNDERWORLD_DIMENSION_TYPE), new NoiseBasedChunkGenerator(new UnderworldBiomeSource(context.lookup(Registries.BIOME)), context.lookup(Registries.NOISE_SETTINGS).getOrThrow(UNDERWORLD_NOISE_GENERATOR))));
}

static void bootstrapLevels(BootstrapContext<LevelStem> context) {
var dimensionTypes = context.lookup(Registries.DIMENSION_TYPE);
var noiseSettings = context.lookup(Registries.NOISE_SETTINGS);
var biomes = context.lookup(Registries.BIOME);
context.register(UNDERWORLD_STEM, new LevelStem(dimensionTypes.getOrThrow(UNDERWORLD), new NoiseBasedChunkGenerator(new UnderworldBiomeSource(biomes), noiseSettings.getOrThrow(RULES))));
static void bootstrapNoise(BootstrapContext<NoiseGeneratorSettings> context) {
context.register(UNDERWORLD_NOISE_GENERATOR, new NoiseGeneratorSettings(new NoiseSettings(0,128,1,2), ModBlocks.DARK_STONE.get().defaultBlockState(), Blocks.AIR.defaultBlockState(), rute(context.lookup(Registries.DENSITY_FUNCTION), context.lookup(Registries.NOISE)), rule(), List.of(), 0, false, false, false, true));
}

static void bootstrapSource(BootstrapContext<NoiseGeneratorSettings> context) {
context.register(RULES, new NoiseGeneratorSettings(new NoiseSettings(0,128,1,2), ModBlocks.DARK_STONE.get().defaultBlockState(), Blocks.AIR.defaultBlockState(), rute(context.lookup(Registries.DENSITY_FUNCTION), context.lookup(Registries.NOISE)), rule(), List.of(), 0, false, false, false, true));
static void bootstrapDensityFunctions(BootstrapContext<DensityFunction> context) {
context.register(BASE_3D_NOISE_UNDERWORLD, BlendedNoise.createUnseeded(0.25, 0.25, 80.0, 160.0, 4.0));
context.register(UNDERWORLD_DENSITY_FUNCTION, DensityFunctions.add(new UnderworldDensityFunction(0), NoiseRouterData.getFunction(context.lookup(Registries.DENSITY_FUNCTION), BASE_3D_NOISE_UNDERWORLD)));
}

static void registerDimensionEffects(RegisterDimensionSpecialEffectsEvent event) {
event.register(UNDERWORLD_DIMENSION_SPECIAL_EFFECTS, new UnderworldEffects());
}

private static SurfaceRules.RuleSource rule() {
Expand All @@ -73,56 +91,29 @@ private static SurfaceRules.RuleSource rule() {
}

private static NoiseRouter rute(HolderGetter<DensityFunction> density, HolderGetter<NormalNoise.NoiseParameters> noise) {
DensityFunction densityfunction = DensityFunctions.cache2d(DensityFunctions.endIslands(0L));
DensityFunction densityfunction1 = postProcess(slideEnd(getFunction(density, SLOPED_CHEESE_END)));
DensityFunction erosion = DensityFunctions.cache2d(new UnderworldDensityFunction(0));
DensityFunction finalDensity = NoiseRouterData.postProcess(NoiseRouterData.slideEnd(NoiseRouterData.getFunction(density, UNDERWORLD_DENSITY_FUNCTION)));

DensityFunction densityfunction4 = getFunction(density, SHIFT_X);
DensityFunction densityfunction5 = getFunction(density, SHIFT_Z);
DensityFunction densityfunction7 = DensityFunctions.shiftedNoise2d(
densityfunction4, densityfunction5, 0.25, noise.getOrThrow(Noises.VEGETATION));
DensityFunction vegetationXShift = NoiseRouterData.getFunction(density, NoiseRouterData.SHIFT_X);
DensityFunction vegerationZShift = NoiseRouterData.getFunction(density, NoiseRouterData.SHIFT_Z);
DensityFunction vegetation = DensityFunctions.shiftedNoise2d(vegetationXShift, vegerationZShift, 0.25, noise.getOrThrow(Noises.VEGETATION));
return new NoiseRouter(
DensityFunctions.zero(),
DensityFunctions.zero(),
DensityFunctions.zero(),
DensityFunctions.zero(),
DensityFunctions.zero(),
densityfunction7,
vegetation,
DensityFunctions.zero(),
densityfunction,
erosion,
DensityFunctions.zero(),
DensityFunctions.zero(),
slideEnd(DensityFunctions.add(densityfunction, DensityFunctions.constant(-0.703125))),
densityfunction1,
NoiseRouterData.getFunction(density, NoiseRouterData.RIDGES),
NoiseRouterData.slideEnd(DensityFunctions.add(erosion, DensityFunctions.constant(-0.703125))),
finalDensity,
DensityFunctions.zero(),
DensityFunctions.zero(),
DensityFunctions.zero()
);
}

private static DensityFunction postProcess(DensityFunction densityFunction) {
DensityFunction densityfunction = DensityFunctions.blendDensity(densityFunction);
return DensityFunctions.mul(DensityFunctions.interpolated(densityfunction), DensityFunctions.constant(0.64)).squeeze();
}

private static DensityFunction slideEnd(DensityFunction densityFunction) {
return slideEndLike(densityFunction, 0, 128);
}

private static DensityFunction slideEndLike(DensityFunction densityFunction, int minY, int maxY) {
return slide(densityFunction, minY, maxY, 72, -184, -23.4375, 4, 32, -0.234375);
}

private static DensityFunction slide(
DensityFunction input, int minY, int maxY, int p_224447_, int p_224448_, double p_224449_, int p_224450_, int p_224451_, double p_224452_
) {
DensityFunction densityfunction1 = DensityFunctions.yClampedGradient(minY + maxY - p_224447_, minY + maxY - p_224448_, 1.0, 0.0);
DensityFunction $$9 = DensityFunctions.lerp(densityfunction1, p_224449_, input);
DensityFunction densityfunction2 = DensityFunctions.yClampedGradient(minY + p_224450_, minY + p_224451_, 0.0, 1.0);
return DensityFunctions.lerp(densityfunction2, p_224452_, $$9);
}

private static DensityFunction getFunction(HolderGetter<DensityFunction> densityFunctions, ResourceKey<DensityFunction> key) {
return new DensityFunctions.HolderHolder(densityFunctions.getOrThrow(key));
}

}
8 changes: 5 additions & 3 deletions src/main/java/de/teamlapen/vampirism/core/ModRegistries.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.core.Registry;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.core.registries.Registries;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.registries.DataPackRegistryEvent;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import net.neoforged.neoforge.registries.NewRegistryEvent;
Expand Down Expand Up @@ -59,9 +60,10 @@ public class ModRegistries {
.add(SKILL_NODE, ModSkills::createSkillNodes)
.add(SKILL_TREE, ModSkills::createSkillTrees)
.add(Registries.ENCHANTMENT, ModEnchantments::createEnchantments)
.add(Registries.DIMENSION_TYPE, ModDimensions::bootstrapTypes)
.add(Registries.LEVEL_STEM, ModDimensions::bootstrapLevels)
.add(Registries.NOISE_SETTINGS, ModDimensions::bootstrapSource)
.add(Registries.DIMENSION_TYPE, ModDimensions::bootstrapDimensionTypes)
.add(Registries.LEVEL_STEM, ModDimensions::bootstrapLevelStem)
.add(Registries.NOISE_SETTINGS, ModDimensions::bootstrapNoise)
.add(Registries.DENSITY_FUNCTION, ModDimensions::bootstrapDensityFunctions)
;

static void registerRegistries(NewRegistryEvent event) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/teamlapen/vampirism/core/ModStructures.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.holdersets.AndHolderSet;
import net.neoforged.neoforge.registries.holdersets.NotHolderSet;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.teamlapen.vampirism.entity.player.vampire.skills.VampireSkills;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.RegisterDimensionSpecialEffectsEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.registries.DataPackRegistryEvent;
import net.neoforged.neoforge.registries.datamaps.RegisterDataMapTypesEvent;
Expand Down Expand Up @@ -82,6 +83,11 @@ public void onRegisterDataMapTypes(RegisterDataMapTypesEvent event) {
ModDataMaps.registerDataMaps(event);
}

@SubscribeEvent
public void registerDimensionSpecialEffects(RegisterDimensionSpecialEffectsEvent event) {
ModDimensions.registerDimensionEffects(event);
}

public void registerModEventHandler() {
this.eventBus.addListener(ModEntities::onModifyEntityTypeAttributes);
this.eventBus.addListener(ModEntities::onRegisterEntityTypeAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected void addTags(HolderLookup.@NotNull Provider holderProvider) {
tag(ModBiomeTags.HasFaction.IS_FACTION_BIOME).addTags(ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME, ModBiomeTags.HasFaction.IS_HUNTER_BIOME);
tag(ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME).add(ModBiomes.VAMPIRE_FOREST, ModBiomes.UNDERWORLD_VAMPIRE_FOREST);
tag(ModBiomeTags.HasFaction.IS_HUNTER_BIOME);
tag(ModBiomeTags.HasStructure.VAMPIRE_ALTAR).addTags(Tags.Biomes.IS_WASTELAND, Tags.Biomes.IS_PLATEAU, Tags.Biomes.IS_RARE, Tags.Biomes.IS_SPOOKY, Tags.Biomes.IS_SWAMP, ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME);
tag(ModBiomeTags.HasStructure.VAMPIRE_ALTAR).addTags(Tags.Biomes.IS_WASTELAND, Tags.Biomes.IS_PLATEAU, Tags.Biomes.IS_RARE, Tags.Biomes.IS_SPOOKY, Tags.Biomes.IS_SWAMP, ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME).remove(ModBiomes.UNDERWORLD_VAMPIRE_FOREST);
tag(ModBiomeTags.HasStructure.HUNTER_OUTPOST_PLAINS).addTags(Tags.Biomes.IS_PLAINS, BiomeTags.IS_FOREST);
tag(ModBiomeTags.HasStructure.HUNTER_OUTPOST_DESERT).addTags(Tags.Biomes.IS_DESERT);
tag(ModBiomeTags.HasStructure.HUNTER_OUTPOST_VAMPIRE_FOREST).add(ModBiomes.VAMPIRE_FOREST);
Expand All @@ -47,9 +47,9 @@ protected void addTags(HolderLookup.@NotNull Provider holderProvider) {
tag(ModBiomeTags.NoSpawn.HUNTER).addTags(ModBiomeTags.HasFaction.IS_FACTION_BIOME);
tag(ModBiomeTags.HasSpawn.ADVANCED_HUNTER).addTags(BiomeTags.IS_OVERWORLD);
tag(ModBiomeTags.NoSpawn.ADVANCED_HUNTER).addTags(ModBiomeTags.HasFaction.IS_FACTION_BIOME);
tag(ModBiomeTags.HasStructure.VAMPIRE_HUT).addTags(ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME);
tag(ModBiomeTags.HasStructure.MOTHER).addTag(ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME);
tag(ModBiomeTags.HasStructure.CRYPT).addTag(ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME);
tag(ModBiomeTags.HasStructure.VAMPIRE_HUT).addTags(ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME).remove(ModBiomes.UNDERWORLD_VAMPIRE_FOREST);
tag(ModBiomeTags.HasStructure.MOTHER).addTag(ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME).remove(ModBiomes.UNDERWORLD_VAMPIRE_FOREST);
tag(ModBiomeTags.HasStructure.CRYPT).addTag(ModBiomeTags.HasFaction.IS_VAMPIRE_BIOME).remove(ModBiomes.UNDERWORLD_VAMPIRE_FOREST);
tag(Tags.Biomes.NO_DEFAULT_MONSTERS).add(ModBiomes.VAMPIRE_FOREST);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.teamlapen.vampirism.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
import net.minecraft.world.level.levelgen.DensityFunctions;
import net.minecraft.world.level.levelgen.synth.SimplexNoise;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(targets = "net.minecraft.world.level.levelgen.DensityFunctions$EndIslandDensityFunction")
public class DensityFunctionsMixin {

@Inject(method = "getHeightValue", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;clamp(FFF)F"), cancellable = true)
private static void s(SimplexNoise noise, int x, int z, CallbackInfoReturnable<Float> cir, @Local(ordinal = 0) float f) {
cir.setReturnValue(f);
}
}
Loading

0 comments on commit aa8ab46

Please sign in to comment.