Some Biome Work

This commit is contained in:
Frank 2022-06-24 10:58:44 +02:00
parent 02e43f9eb6
commit 1909aea351
13 changed files with 385 additions and 72 deletions

View file

@ -1,15 +1,22 @@
package org.betterx.betterend.world.biome.land;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.v2.levelgen.surface.SurfaceRuleBuilder;
import org.betterx.bclib.api.v2.levelgen.surface.rules.SwitchRuleSource;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.registry.EndStructures;
import org.betterx.betterend.world.biome.EndBiome;
import org.betterx.betterend.world.surface.SplitNoiseCondition;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.SurfaceRules;
import java.util.List;
public class CrystalMountainsBiome extends EndBiome.Config {
public CrystalMountainsBiome() {
@ -33,6 +40,20 @@ public class CrystalMountainsBiome extends EndBiome.Config {
public BlockState getTopMaterial() {
return EndBlocks.CRYSTAL_MOSS.defaultBlockState();
}
@Override
public SurfaceRuleBuilder surface() {
SurfaceRules.RuleSource surfaceBlockRule = new SwitchRuleSource(
new SplitNoiseCondition(),
List.of(
SurfaceRules.state(EndBlocks.END_MOSS.defaultBlockState()),
SurfaceRules.state(Blocks.END_STONE.defaultBlockState())
)
);
return super
.surface()
.rule(1, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, surfaceBlockRule));
}
};
}
}

View file

@ -1,15 +1,22 @@
package org.betterx.betterend.world.biome.land;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.v2.levelgen.surface.SurfaceRuleBuilder;
import org.betterx.bclib.api.v2.levelgen.surface.rules.SwitchRuleSource;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.registry.EndStructures;
import org.betterx.betterend.world.biome.EndBiome;
import org.betterx.betterend.world.surface.VerticalBandNoiseCondition;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.SurfaceRules;
import java.util.List;
public class PaintedMountainsBiome extends EndBiome.Config {
public PaintedMountainsBiome() {
@ -36,6 +43,18 @@ public class PaintedMountainsBiome extends EndBiome.Config {
public BlockState getTopMaterial() {
return EndBlocks.ENDSTONE_DUST.defaultBlockState();
}
public SurfaceRuleBuilder surface() {
SurfaceRules.RuleSource surfaceBlockRule = new SwitchRuleSource(
VerticalBandNoiseCondition.DEFAULT,
List.of(
SurfaceRules.state(Blocks.END_STONE.defaultBlockState()),
SurfaceRules.state(EndBlocks.FLAVOLITE.stone.defaultBlockState()),
SurfaceRules.state(EndBlocks.VIOLECITE.stone.defaultBlockState())
)
);
return SurfaceRuleBuilder.start().rule(9, surfaceBlockRule);
}
};
}
}

View file

@ -32,7 +32,7 @@ public abstract class FeatureBaseStructure extends Structure {
context.heightAccessor(),
context.randomState()
);
if (pos.getZ() >= 20) {
if (pos.getY() >= 10) {
return Optional.of(new Structure.GenerationStub(pos, (structurePiecesBuilder) -> {
generatePieces(structurePiecesBuilder, context);
}));
@ -58,46 +58,36 @@ public abstract class FeatureBaseStructure extends Structure {
LegacyRandomSource random = new LegacyRandomSource(chunkPos.x + chunkPos.z * 10387313);
Rotation blockRotation = Rotation.getRandom(random);
int i = 5;
int j = 5;
int offsetX = 5;
int offsetZ = 5;
if (blockRotation == Rotation.CLOCKWISE_90) {
i = -5;
offsetX = -5;
} else if (blockRotation == Rotation.CLOCKWISE_180) {
i = -5;
j = -5;
offsetX = -5;
offsetZ = -5;
} else if (blockRotation == Rotation.COUNTERCLOCKWISE_90) {
j = -5;
offsetZ = -5;
}
int k = chunkPos.getBlockX(7);
int l = chunkPos.getBlockZ(7);
int m = chunkGenerator.getFirstOccupiedHeight(
k,
l,
int blockX = chunkPos.getBlockX(7);
int blockZ = chunkPos.getBlockZ(7);
int minZ = Integer.MAX_VALUE;
BlockPos.MutableBlockPos result = new BlockPos.MutableBlockPos(blockX, Integer.MIN_VALUE, blockZ);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
int z = chunkGenerator.getFirstOccupiedHeight(
blockX + i * offsetX,
blockZ + j * offsetZ,
Heightmap.Types.WORLD_SURFACE_WG,
levelHeightAccessor,
rState
);
int n = chunkGenerator.getFirstOccupiedHeight(
k,
l + j,
Heightmap.Types.WORLD_SURFACE_WG,
levelHeightAccessor,
rState
);
int o = chunkGenerator.getFirstOccupiedHeight(
k + i,
l,
Heightmap.Types.WORLD_SURFACE_WG,
levelHeightAccessor,
rState
);
int p = chunkGenerator.getFirstOccupiedHeight(
k + i,
l + j,
Heightmap.Types.WORLD_SURFACE_WG,
levelHeightAccessor, rState
);
return new BlockPos(k, l, Math.min(Math.min(m, n), Math.min(o, p)));
if (z < minZ) {
result.set(blockX + i * offsetX, z, blockZ + j * offsetZ);
}
}
}
return result;
}
}

View file

@ -20,7 +20,7 @@ import net.minecraft.world.level.levelgen.structure.StructureType;
import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
public class PaintedMountainStructure extends FeatureBaseStructure {
private static final BlockState[] VARIANTS;
public static final BlockState[] VARIANTS;
public PaintedMountainStructure(StructureSettings s) {
super(s);
@ -46,9 +46,9 @@ public class PaintedMountainStructure extends FeatureBaseStructure {
float radius = MHelper.randRange(50, 100, random);
float height = radius * MHelper.randRange(0.4F, 0.6F, random);
int count = MHelper.floor(height * MHelper.randRange(0.1F, 0.35F, random) + 1);
BlockState[] slises = new BlockState[count];
BlockState[] slices = new BlockState[count];
for (int i = 0; i < count; i++) {
slises[i] = VARIANTS[random.nextInt(VARIANTS.length)];
slices[i] = VARIANTS[random.nextInt(VARIANTS.length)];
}
structurePiecesBuilder.addPiece(new PaintedMountainPiece(
new BlockPos(x, y, z),
@ -56,7 +56,7 @@ public class PaintedMountainStructure extends FeatureBaseStructure {
height,
random,
biome,
slises
slices
));
}

View file

@ -1,11 +1,10 @@
package org.betterx.betterend.world.structures.piece;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
import org.betterx.bclib.util.MHelper;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndStructures;
import org.betterx.betterend.util.GlobalState;
import org.betterx.betterend.world.biome.EndBiome;
import org.betterx.betterend.world.surface.SplitNoiseCondition;
import org.betterx.worlds.together.tag.v3.CommonBlockTags;
import net.minecraft.core.BlockPos;
@ -32,7 +31,7 @@ public class CrystalMountainPiece extends MountainPiece {
public CrystalMountainPiece(BlockPos center, float radius, float height, RandomSource random, Holder<Biome> biome) {
super(EndStructures.MOUNTAIN_PIECE, center, radius, height, random, biome);
top = EndBiome.findTopMaterial(biome.value()); //biome.getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
top = EndBlocks.CRYSTAL_MOSS.defaultBlockState(); //EndBiome.findTopMaterial(biome.value()); //biome.getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
}
public CrystalMountainPiece(StructurePieceSerializationContext type, CompoundTag tag) {
@ -42,7 +41,7 @@ public class CrystalMountainPiece extends MountainPiece {
@Override
protected void fromNbt(CompoundTag tag) {
super.fromNbt(tag);
top = EndBiome.findTopMaterial(BiomeAPI.getBiome(biomeID)); //BiomeAPI.getBiome(biomeID).getBiome().getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
//top = EndBiome.findTopMaterial(BiomeAPI.getBiome(biomeID)); //BiomeAPI.getBiome(biomeID).getBiome().getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
}
@Override
@ -79,9 +78,10 @@ public class CrystalMountainPiece extends MountainPiece {
continue;
}
pos.setY(minY);
while (!chunk.getBlockState(pos)
.is(CommonBlockTags.GEN_END_STONES) && pos.getY() > 56 && !chunk.getBlockState(
pos.below()).is(Blocks.CAVE_AIR)) {
while (!chunk.getBlockState(pos).is(CommonBlockTags.GEN_END_STONES)
&& pos.getY() > 56
&& chunk.getBlockState(pos.below()).is(Blocks.CAVE_AIR)
) {
pos.setY(pos.getY() - 1);
}
minY = pos.getY();
@ -94,18 +94,20 @@ public class CrystalMountainPiece extends MountainPiece {
maxY += center.getY();
int maxYI = (int) (maxY);
int cover = maxYI - 1;
boolean needCover = (noise1.eval(px * 0.1, pz * 0.1) + MHelper.randRange(
-0.4,
0.4,
random
) - (center.getY() + 14) * 0.1) > 0;
final double noise = SplitNoiseCondition.DEFAULT.getNoise(px, pz);
boolean needCover = noise > 0;
boolean needSurroundCover = noise > -0.2;
for (int y = minY - 1; y < maxYI; y++) {
pos.setY(y);
chunk.setBlockState(
pos,
needCover && y == cover ? top : Blocks.END_STONE.defaultBlockState(),
false
);
if (needCover && y == cover) {
chunk.setBlockState(pos, top, false);
} else {
chunk.setBlockState(pos, Blocks.END_STONE.defaultBlockState(), false);
if (needSurroundCover) {
chunk.setBlockState(pos.above(), Blocks.SCULK_VEIN.defaultBlockState(), false);
}
}
}
}
}
@ -124,7 +126,7 @@ public class CrystalMountainPiece extends MountainPiece {
int x = MHelper.randRange(radius, 15 - radius, random);
int z = MHelper.randRange(radius, 15 - radius, random);
int y = map.getFirstAvailable(x, z);
if (y > 80) {
if (y > 60) {
pos.set(x, y, z);
if (chunk.getBlockState(pos.below()).is(Blocks.END_STONE)) {
int height = MHelper.floor(radius * MHelper.randRange(1.5F, 3F, random) + (y - 80) * 0.3F);
@ -142,7 +144,7 @@ public class CrystalMountainPiece extends MountainPiece {
int x = MHelper.randRange(radius, 15 - radius, random);
int z = MHelper.randRange(radius, 15 - radius, random);
int y = map.getFirstAvailable(x, z);
if (y > 80) {
if (y > 20) {
pos.set(x, y, z);
if (chunk.getBlockState(pos.below()).getBlock() == Blocks.END_STONE) {
int height = MHelper.floor(radius * MHelper.randRange(1.5F, 3F, random) + (y - 80) * 0.3F);

View file

@ -24,7 +24,7 @@ import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
public class PaintedMountainPiece extends MountainPiece {
private BlockState[] slises;
private BlockState[] slices;
public PaintedMountainPiece(
BlockPos center,
@ -32,10 +32,10 @@ public class PaintedMountainPiece extends MountainPiece {
float height,
RandomSource random,
Holder<Biome> biome,
BlockState[] slises
BlockState[] slices
) {
super(EndStructures.PAINTED_MOUNTAIN_PIECE, center, radius, height, random, biome);
this.slises = slises;
this.slices = slices;
}
public PaintedMountainPiece(StructurePieceSerializationContext type, CompoundTag tag) {
@ -45,20 +45,20 @@ public class PaintedMountainPiece extends MountainPiece {
@Override
protected void addAdditionalSaveData(CompoundTag tag) {
super.addAdditionalSaveData(tag);
ListTag slise = new ListTag();
for (BlockState state : slises) {
slise.add(NbtUtils.writeBlockState(state));
ListTag slice = new ListTag();
for (BlockState state : slices) {
slice.add(NbtUtils.writeBlockState(state));
}
tag.put("slises", slise);
tag.put("slises", slice);
}
@Override
protected void fromNbt(CompoundTag tag) {
super.fromNbt(tag);
ListTag slise = tag.getList("slises", 10);
slises = new BlockState[slise.size()];
for (int i = 0; i < slises.length; i++) {
slises[i] = NbtUtils.readBlockState(slise.getCompound(i));
slices = new BlockState[slise.size()];
for (int i = 0; i < slices.length; i++) {
slices[i] = NbtUtils.readBlockState(slise.getCompound(i));
}
}
@ -110,8 +110,8 @@ public class PaintedMountainPiece extends MountainPiece {
) * 2 + 7);
for (int y = minY - 1; y < maxY; y++) {
pos.setY(y);
int index = MHelper.floor((y + offset) * 0.65F) % slises.length;
chunk.setBlockState(pos, slises[index], false);
int index = MHelper.floor((y + offset) * 0.65F) % slices.length;
chunk.setBlockState(pos, slices[index], false);
}
}
}

View file

@ -28,6 +28,16 @@ public class SplitNoiseCondition implements NumericProvider {
return noise > 0 ? 1 : 0;
}
public double getNoise(int x, int z) {
float noise = (float) NOISE.eval(x * 0.1, z * 0.1) + MHelper.randRange(
-0.2F,
0.2F,
MHelper.RANDOM_SOURCE
);
return noise;
}
@Override
public Codec<? extends NumericProvider> pcodec() {
return CODEC;

View file

@ -49,5 +49,11 @@ public class SulphuricSurfaceNoiseCondition implements NumericProvider {
BetterEnd.makeID("sulphuric_surf"),
SulphuricSurfaceNoiseCondition.CODEC
);
Registry.register(
NumericProvider.NUMERIC_PROVIDER,
BetterEnd.makeID("vertical_band"),
VerticalBandNoiseCondition.CODEC
);
}
}

View file

@ -0,0 +1,68 @@
package org.betterx.betterend.world.surface;
import org.betterx.bclib.interfaces.NumericProvider;
import org.betterx.bclib.mixin.common.SurfaceRulesContextAccessor;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.levelgen.Noises;
import net.minecraft.world.level.levelgen.synth.NormalNoise;
public class VerticalBandNoiseCondition implements NumericProvider {
public static final VerticalBandNoiseCondition DEFAULT = new VerticalBandNoiseCondition(
Noises.CLAY_BANDS_OFFSET,
4.0,
4.0,
6.0,
1.3
);
public static final Codec<VerticalBandNoiseCondition> CODEC = RecordCodecBuilder.create(instance -> instance
.group(
ResourceKey.codec(Registry.NOISE_REGISTRY).fieldOf("noise").forGetter(o -> o.noise),
Codec.DOUBLE.fieldOf("offset_scale").orElse(4.0).forGetter(o -> o.offsetScale),
Codec.DOUBLE.fieldOf("band_scale").orElse(4.0).forGetter(o -> o.bandScale),
Codec.DOUBLE.fieldOf("xz_scale").orElse(6.0).forGetter(o -> o.xzScale),
Codec.DOUBLE.fieldOf("y_scale").orElse(1.3).forGetter(o -> o.yScale)
)
.apply(instance, VerticalBandNoiseCondition::new));
private final ResourceKey<NormalNoise.NoiseParameters> noise;
private final double offsetScale;
private final double bandScale;
private final double xzScale;
private final double yScale;
public VerticalBandNoiseCondition(
ResourceKey<NormalNoise.NoiseParameters> noise,
double offsetScale,
double bandScale,
double xzScale,
double yScale
) {
this.noise = noise;
this.offsetScale = offsetScale;
this.bandScale = bandScale;
this.xzScale = xzScale;
this.yScale = yScale;
}
@Override
public int getNumber(SurfaceRulesContextAccessor context) {
final NormalNoise normalNoise = context.getRandomState().getOrCreateNoise(this.noise);
double offset = normalNoise.getValue(
(double) context.getBlockX() * xzScale,
context.getBlockY() * yScale * 10,
(double) context.getBlockZ() * xzScale
) * offsetScale;
return (int) (context.getBlockY() / bandScale + offset);
}
@Override
public Codec<? extends NumericProvider> pcodec() {
return CODEC;
}
}

View file

@ -0,0 +1,150 @@
{
"multipart": [
{
"apply": {
"model": "betterend:block/crystal_moss_cover"
},
"when": {
"north": "true"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover"
},
"when": {
"down": "false",
"east": "false",
"north": "false",
"south": "false",
"up": "false",
"west": "false"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"y": 90
},
"when": {
"east": "true"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"y": 90
},
"when": {
"down": "false",
"east": "false",
"north": "false",
"south": "false",
"up": "false",
"west": "false"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"y": 180
},
"when": {
"south": "true"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"y": 180
},
"when": {
"down": "false",
"east": "false",
"north": "false",
"south": "false",
"up": "false",
"west": "false"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"y": 270
},
"when": {
"west": "true"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"y": 270
},
"when": {
"down": "false",
"east": "false",
"north": "false",
"south": "false",
"up": "false",
"west": "false"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"x": 270
},
"when": {
"up": "true"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"x": 270
},
"when": {
"down": "false",
"east": "false",
"north": "false",
"south": "false",
"up": "false",
"west": "false"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"x": 90
},
"when": {
"down": "true"
}
},
{
"apply": {
"model": "betterend:block/crystal_moss_cover",
"uvlock": true,
"x": 90
},
"when": {
"down": "false",
"east": "false",
"north": "false",
"south": "false",
"up": "false",
"west": "false"
}
}
]
}

View file

@ -0,0 +1,41 @@
{
"ambientocclusion": false,
"textures": {
"particle": "betterend:block/crystal_moss_cover",
"cover": "betterend:block/crystal_moss_cover"
},
"elements": [
{
"from": [
0,
0,
0.1
],
"to": [
16,
16,
0.1
],
"faces": {
"north": {
"uv": [
0,
0,
16,
16
],
"texture": "#cover"
},
"south": {
"uv": [
0,
0,
16,
16
],
"texture": "#cover"
}
}
}
]
}

View file

@ -0,0 +1,6 @@
{
"animation": {
"frametime": 20,
"interpolate": true
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B