Portal islands

This commit is contained in:
Aleksey 2021-04-04 14:56:18 +03:00
parent fd093318c6
commit 6630ce0cab
6 changed files with 98 additions and 65 deletions

View file

@ -0,0 +1,69 @@
package ru.betterend.world.features;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.surfacebuilder.SurfaceConfig;
import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.sdf.SDF;
import ru.betterend.util.sdf.operator.SDFDisplacement;
import ru.betterend.util.sdf.operator.SDFTranslate;
import ru.betterend.util.sdf.primitive.SDFCappedCone;
public class BiomeIslandFeature extends DefaultFeature {
private static final Mutable CENTER = new Mutable();
private static final SDF ISLAND;
private static OpenSimplexNoise simplexNoise = new OpenSimplexNoise(412L);
private static BlockState topBlock = Blocks.GRASS_BLOCK.getDefaultState();
private static BlockState underBlock = Blocks.DIRT.getDefaultState();
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
Biome biome = world.getBiome(pos);
SurfaceConfig surfaceConfig = biome.getGenerationSettings().getSurfaceConfig();
BlockState topMaterial = surfaceConfig.getTopMaterial();
if (BlocksHelper.isFluid(topMaterial)) {
topBlock = ((TernarySurfaceConfig) surfaceConfig).getUnderwaterMaterial();
} else {
topBlock = topMaterial;
}
underBlock = surfaceConfig.getUnderMaterial();
simplexNoise = new OpenSimplexNoise(world.getSeed());
CENTER.set(pos);
ISLAND.fillRecursive(world, pos.down());
return true;
}
private static SDF createSDFIsland() {
SDF sdfCone = new SDFCappedCone().setRadius1(0).setRadius2(6).setHeight(4).setBlock(pos -> {
if (pos.getY() > CENTER.getY()) return AIR;
if (pos.getY() == CENTER.getY()) return topBlock;
return underBlock;
});
sdfCone = new SDFTranslate().setTranslate(0, -2, 0).setSource(sdfCone);
sdfCone = new SDFDisplacement().setFunction(pos -> {
float deltaX = Math.abs(pos.getX());
float deltaY = Math.abs(pos.getY());
float deltaZ = Math.abs(pos.getZ());
if (deltaY < 2.0f && (deltaX < 3.0f || deltaZ < 3.0F)) return 0.0f;
return (float) simplexNoise.eval(CENTER.getX() + pos.getX(),
CENTER.getY() + pos.getY(), CENTER.getZ() + pos.getZ());
}).setSource(sdfCone).setReplaceFunction(state -> BlocksHelper.isFluid(state) ||
state.getMaterial().isReplaceable());
return sdfCone;
}
static {
ISLAND = createSDFIsland();
}
}

View file

@ -114,7 +114,7 @@ public class EndFeature {
return new EndFeature(name, feature, GenerationStep.Feature.RAW_GENERATION, configured);
}
public static EndFeature makeFetureConfigured(String name, Feature<DefaultFeatureConfig> feature) {
public static EndFeature makeFeatureConfigured(String name, Feature<DefaultFeatureConfig> feature) {
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT);
return new EndFeature(name, feature, GenerationStep.Feature.RAW_GENERATION, configured);
}

View file

@ -1,47 +0,0 @@
package ru.betterend.world.features;
import java.util.Random;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.util.sdf.SDF;
import ru.betterend.util.sdf.operator.SDFDisplacement;
import ru.betterend.util.sdf.operator.SDFTranslate;
import ru.betterend.util.sdf.primitive.SDFCappedCone;
public class OverworldIslandFeature extends DefaultFeature {
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(412);
private static final Mutable CENTER = new Mutable();
private static final SDF ISLAND;
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
CENTER.set(pos);
ISLAND.fillRecursive(world, pos.down());
return true;
}
static {
SDF cone = new SDFCappedCone().setRadius1(0).setRadius2(6).setHeight(4).setBlock((pos) -> {
if (pos.getY() == CENTER.getY()) return Blocks.GRASS_BLOCK.getDefaultState();
if (pos.getY() == CENTER.getY() - 1) {
return Blocks.DIRT.getDefaultState();
} else if (pos.getY() == CENTER.getY() - Math.round(2.0 * Math.random())) {
return Blocks.DIRT.getDefaultState();
}
return Blocks.STONE.getDefaultState();
});
cone = new SDFTranslate().setTranslate(0, -3, 0).setSource(cone);
cone = new SDFDisplacement().setFunction((pos) -> {
return (float) NOISE.eval(CENTER.getX() + pos.getX(), CENTER.getY() + pos.getY(), CENTER.getZ() + pos.getZ());
}).setSource(cone).setReplaceFunction(state -> {
return state.isOf(Blocks.WATER) || state.getMaterial().isReplaceable();
});
ISLAND = cone;
}
}