Skip to content

Commit

Permalink
start dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Oct 6, 2024
1 parent cbd35ad commit 21495ab
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/generated/resources/data/vampirism/dimension/underworld.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "vampirism:underworld",
"generator": {
"type": "minecraft:noise",
"biome_source": {
"type": "vampirism:underworld"
},
"settings": "minecraft:end"
}
}
Original file line number Diff line number Diff line change
@@ -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
}
46 changes: 46 additions & 0 deletions src/main/java/de/teamlapen/vampirism/core/ModDimensions.java
Original file line number Diff line number Diff line change
@@ -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<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 DeferredRegister<MapCodec<? extends BiomeSource>> BIOME_SOURCES = DeferredRegister.create(Registries.BIOME_SOURCE, REFERENCE.MODID);

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);
}
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.END_EFFECTS, 0f, new DimensionType.MonsterSettings(false, false, UniformInt.of(0,7), 0)));
}

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(NoiseGeneratorSettings.END))));
}

}
4 changes: 3 additions & 1 deletion src/main/java/de/teamlapen/vampirism/core/ModRegistries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void setupRegistries() {
ModDataComponents.register(eventBus);
ModArmorMaterials.register(eventBus);
ModFactions.register(eventBus);
ModDimensions.register(eventBus);
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UnderworldBiomeSource> CODEC = RecordCodecBuilder.mapCodec(inst -> {
return inst.group(
RegistryOps.retrieveElement(ModBiomes.VAMPIRE_FOREST))
.apply(inst, inst.stable(UnderworldBiomeSource::new));
});

private final Holder<Biome> biome;

public UnderworldBiomeSource(HolderGetter<Biome> biomeGetter) {
this.biome = biomeGetter.getOrThrow(ModBiomes.VAMPIRE_FOREST);
}

private UnderworldBiomeSource(Holder<Biome> biome) {
this.biome = biome;
}

@Override
protected MapCodec<? extends BiomeSource> codec() {
return CODEC;
}

@Override
protected Stream<Holder<Biome>> collectPossibleBiomes() {
return Stream.of(this.biome);
}

@Override
public Holder<Biome> 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;
}
}
}
}

0 comments on commit 21495ab

Please sign in to comment.