End Caves

This commit is contained in:
paulevsGitch 2020-10-09 10:46:54 +03:00
parent ae676cfc86
commit e3c402f13e
8 changed files with 184 additions and 31 deletions

View file

@ -0,0 +1,107 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.structure.StructureManager;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.BlockTagRegistry;
import ru.betterend.registry.StructureRegistry;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
public class CavePiece extends BasePiece {
private OpenSimplexNoise noise;
private BlockPos center;
private float radius;
public CavePiece(BlockPos center, float radius, int id) {
super(StructureRegistry.CAVE_PIECE, id);
this.center = center;
this.radius = radius;
this.noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
makeBoundingBox();
}
public CavePiece(StructureManager manager, CompoundTag tag) {
super(StructureRegistry.CAVE_PIECE, tag);
makeBoundingBox();
}
@Override
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int x1 = MHelper.max(this.boundingBox.minX, blockBox.minX);
int z1 = MHelper.max(this.boundingBox.minZ, blockBox.minZ);
int x2 = MHelper.min(this.boundingBox.maxX, blockBox.maxX);
int z2 = MHelper.min(this.boundingBox.maxZ, blockBox.maxZ);
int y1 = this.boundingBox.minY;
int y2 = this.boundingBox.maxY;
double hr = radius * 0.75;
double nr = radius * 0.25;
Mutable pos = new Mutable();
for (int x = x1; x <= x2; x++) {
int xsq = x - center.getX();
xsq *= xsq;
pos.setX(x);
for (int z = z1; z <= z2; z++) {
int zsq = z - center.getZ();
zsq *= zsq;
pos.setZ(z);
for (int y = y1; y <= y2; y++) {
int ysq = y - center.getY();
ysq *= 1.6;
ysq *= ysq;
pos.setY(y);
double r = noise.eval(x * 0.1, y * 0.1, z * 0.1) * nr + hr;
double r2 = r - 4.5;
double dist = xsq + ysq + zsq;
if (dist < r2 * r2) {
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, pos, AIR);
}
}
else if (dist < r * r) {
if (world.getBlockState(pos).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, pos, Blocks.END_STONE);
}
}
}
}
}
return true;
}
@Override
protected void toNbt(CompoundTag tag) {
tag.put("center", NbtHelper.fromBlockPos(center));
tag.putFloat("radius", radius);
}
@Override
protected void fromNbt(CompoundTag tag) {
center = NbtHelper.toBlockPos(tag.getCompound("center"));
radius = tag.getFloat("radius");
noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
}
private void makeBoundingBox() {
int minX = MHelper.floor(center.getX() - radius);
int minY = MHelper.floor(center.getY() - radius);
int minZ = MHelper.floor(center.getZ() - radius);
int maxX = MHelper.floor(center.getX() + radius + 1);
int maxY = MHelper.floor(center.getY() + radius + 1);
int maxZ = MHelper.floor(center.getZ() + radius + 1);
this.boundingBox = new BlockBox(minX, minY, minZ, maxX, maxY, maxZ);
}
}

View file

@ -87,18 +87,10 @@ public class MountainPiece extends BasePiece {
if (maxY > 0) {
maxY *= (float) noise.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F;
maxY *= (float) noise.eval(px * 0.1, pz * 0.1) * 0.1F + 0.8F;
//float rigid = Math.abs(1F - (float) noise.eval(px * 0.1, pz * 0.1)) * maxY / 20F - 0.5F;
maxY += minY;
//float surf = maxY - 3;
for (int y = minY; y < maxY; y++) {
pos.setY(y);
chunk.setBlockState(pos, Blocks.END_STONE.getDefaultState(), false);
/*if (y > surf && rigid > 0.5) {
chunk.setBlockState(pos, BlockRegistry.AURORA_CRYSTAL.getDefaultState(), false);
}
else {
chunk.setBlockState(pos, Blocks.END_STONE.getDefaultState(), false);
}*/
}
}
}
@ -147,6 +139,27 @@ public class MountainPiece extends BasePiece {
return true;
}
public int getProtoHeight(int px, int py, int pz) {
int px2 = px - center.getX();
px2 *= px2;
int pz2 = pz - center.getZ();
pz2 *= pz2;
float dist = px2 + pz2;
dist = 1 - (float) Math.pow(dist / r2, 0.3);
if (py > 56) {
float maxY = dist * height;
if (maxY > 0) {
maxY *= (float) noise.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F;
maxY *= (float) noise.eval(px * 0.1, pz * 0.1) * 0.1F + 0.8F;
return MHelper.floor(maxY + py * ((float) MathHelper.clamp((py - 57) / 7F, 0, 1)));
}
}
return py;
}
private int getHeight(StructureWorldAccess world, BlockPos pos) {
if (BiomeRegistry.getFromBiome(world.getBiome(pos)) != BiomeRegistry.END_HIGHLANDS) {
return -4;