From 21495abddb274491f1adca92bea5af9731f832b9 Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Sun, 6 Oct 2024 09:05:38 +0200 Subject: [PATCH] start dimension --- .../data/vampirism/dimension/underworld.json | 10 +++ .../vampirism/dimension_type/underworld.json | 24 +++++++ .../vampirism/core/ModDimensions.java | 46 +++++++++++++ .../vampirism/core/ModRegistries.java | 4 +- .../vampirism/core/RegistryManager.java | 1 + .../dimension/UnderworldBiomeSource.java | 67 +++++++++++++++++++ 6 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/generated/resources/data/vampirism/dimension/underworld.json create mode 100644 src/generated/resources/data/vampirism/dimension_type/underworld.json create mode 100644 src/main/java/de/teamlapen/vampirism/core/ModDimensions.java create mode 100644 src/main/java/de/teamlapen/vampirism/world/dimension/UnderworldBiomeSource.java diff --git a/src/generated/resources/data/vampirism/dimension/underworld.json b/src/generated/resources/data/vampirism/dimension/underworld.json new file mode 100644 index 000000000..435318c49 --- /dev/null +++ b/src/generated/resources/data/vampirism/dimension/underworld.json @@ -0,0 +1,10 @@ +{ + "type": "vampirism:underworld", + "generator": { + "type": "minecraft:noise", + "biome_source": { + "type": "vampirism:underworld" + }, + "settings": "minecraft:end" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/vampirism/dimension_type/underworld.json b/src/generated/resources/data/vampirism/dimension_type/underworld.json new file mode 100644 index 000000000..5497158a0 --- /dev/null +++ b/src/generated/resources/data/vampirism/dimension_type/underworld.json @@ -0,0 +1,24 @@ +{ + "ambient_light": 0.0, + "bed_works": false, + "coordinate_scale": 1.0, + "effects": "minecraft:the_end", + "fixed_time": 6000, + "has_ceiling": false, + "has_raids": false, + "has_skylight": false, + "height": 256, + "infiniburn": "#minecraft:infiniburn_end", + "logical_height": 256, + "min_y": 0, + "monster_spawn_block_light_limit": 0, + "monster_spawn_light_level": { + "type": "minecraft:uniform", + "max_inclusive": 7, + "min_inclusive": 0 + }, + "natural": false, + "piglin_safe": false, + "respawn_anchor_works": false, + "ultrawarm": false +} \ No newline at end of file diff --git a/src/main/java/de/teamlapen/vampirism/core/ModDimensions.java b/src/main/java/de/teamlapen/vampirism/core/ModDimensions.java new file mode 100644 index 000000000..a68c91da9 --- /dev/null +++ b/src/main/java/de/teamlapen/vampirism/core/ModDimensions.java @@ -0,0 +1,46 @@ +package de.teamlapen.vampirism.core; + +import com.mojang.serialization.MapCodec; +import de.teamlapen.vampirism.REFERENCE; +import de.teamlapen.vampirism.api.util.VResourceLocation; +import de.teamlapen.vampirism.world.dimension.UnderworldBiomeSource; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.worldgen.BootstrapContext; +import net.minecraft.resources.ResourceKey; +import net.minecraft.tags.BlockTags; +import net.minecraft.util.valueproviders.UniformInt; +import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.dimension.BuiltinDimensionTypes; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.dimension.LevelStem; +import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; +import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; + +import java.util.OptionalLong; + +public class ModDimensions { + + public static final ResourceKey UNDERWORLD = ResourceKey.create(Registries.DIMENSION_TYPE, VResourceLocation.mod("underworld")); + public static final ResourceKey UNDERWORLD_STEM = ResourceKey.create(Registries.LEVEL_STEM, VResourceLocation.mod("underworld")); + public static final DeferredRegister> BIOME_SOURCES = DeferredRegister.create(Registries.BIOME_SOURCE, REFERENCE.MODID); + + public static final DeferredHolder, MapCodec> UNDERWORLD_BIOME_SOURCE = BIOME_SOURCES.register("underworld", () -> UnderworldBiomeSource.CODEC); + + static void register(IEventBus bus) { + BIOME_SOURCES.register(bus); + } + static void bootstrapTypes(BootstrapContext context) { + context.register(UNDERWORLD, new DimensionType(OptionalLong.of(6000), false, false, false, false, 1.0, false, false, 0, 256, 256, BlockTags.INFINIBURN_END, BuiltinDimensionTypes.END_EFFECTS, 0f, new DimensionType.MonsterSettings(false, false, UniformInt.of(0,7), 0))); + } + + static void bootstrapLevels(BootstrapContext 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(NoiseGeneratorSettings.END)))); + } + +} diff --git a/src/main/java/de/teamlapen/vampirism/core/ModRegistries.java b/src/main/java/de/teamlapen/vampirism/core/ModRegistries.java index 9f05ab6bf..e6f6c7e45 100644 --- a/src/main/java/de/teamlapen/vampirism/core/ModRegistries.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModRegistries.java @@ -58,7 +58,9 @@ public class ModRegistries { .add(TASK, ModTasks::createTasks) .add(SKILL_NODE, ModSkills::createSkillNodes) .add(SKILL_TREE, ModSkills::createSkillTrees) - .add(Registries.ENCHANTMENT, ModEnchantments::createEnchantments); + .add(Registries.ENCHANTMENT, ModEnchantments::createEnchantments) + .add(Registries.DIMENSION_TYPE, ModDimensions::bootstrapTypes) + .add(Registries.LEVEL_STEM, ModDimensions::bootstrapLevels); static void registerRegistries(NewRegistryEvent event) { event.register(SKILLS); diff --git a/src/main/java/de/teamlapen/vampirism/core/RegistryManager.java b/src/main/java/de/teamlapen/vampirism/core/RegistryManager.java index 2d2338dc4..58a409cca 100644 --- a/src/main/java/de/teamlapen/vampirism/core/RegistryManager.java +++ b/src/main/java/de/teamlapen/vampirism/core/RegistryManager.java @@ -69,6 +69,7 @@ public void setupRegistries() { ModDataComponents.register(eventBus); ModArmorMaterials.register(eventBus); ModFactions.register(eventBus); + ModDimensions.register(eventBus); } @SubscribeEvent diff --git a/src/main/java/de/teamlapen/vampirism/world/dimension/UnderworldBiomeSource.java b/src/main/java/de/teamlapen/vampirism/world/dimension/UnderworldBiomeSource.java new file mode 100644 index 000000000..dfa81bea7 --- /dev/null +++ b/src/main/java/de/teamlapen/vampirism/world/dimension/UnderworldBiomeSource.java @@ -0,0 +1,67 @@ +package de.teamlapen.vampirism.world.dimension; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import de.teamlapen.vampirism.core.ModBiomes; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderGetter; +import net.minecraft.core.QuartPos; +import net.minecraft.core.SectionPos; +import net.minecraft.resources.RegistryOps; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.biome.Climate; +import net.minecraft.world.level.levelgen.DensityFunction; + +import java.util.stream.Stream; + +public class UnderworldBiomeSource extends BiomeSource { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(inst -> { + return inst.group( + RegistryOps.retrieveElement(ModBiomes.VAMPIRE_FOREST)) + .apply(inst, inst.stable(UnderworldBiomeSource::new)); + }); + + private final Holder biome; + + public UnderworldBiomeSource(HolderGetter biomeGetter) { + this.biome = biomeGetter.getOrThrow(ModBiomes.VAMPIRE_FOREST); + } + + private UnderworldBiomeSource(Holder biome) { + this.biome = biome; + } + + @Override + protected MapCodec codec() { + return CODEC; + } + + @Override + protected Stream> collectPossibleBiomes() { + return Stream.of(this.biome); + } + + @Override + public Holder getNoiseBiome(int x, int y, int z, Climate.Sampler sampler) { + int i = QuartPos.toBlock(x); + int j = QuartPos.toBlock(y); + int k = QuartPos.toBlock(z); + int l = SectionPos.blockToSectionCoord(i); + int i1 = SectionPos.blockToSectionCoord(k); + if ((long)l * (long)l + (long)i1 * (long)i1 <= 4096L) { + return this.biome; + } else { + int j1 = (SectionPos.blockToSectionCoord(i) * 2 + 1) * 8; + int k1 = (SectionPos.blockToSectionCoord(k) * 2 + 1) * 8; + double d0 = sampler.erosion().compute(new DensityFunction.SinglePointContext(j1, j, k1)); + if (d0 > 0.25) { + return this.biome; + } else if (d0 >= -0.0625) { + return this.biome; + } else { + return this.biome; + } + } + } +}