Aurora crystal mountains

This commit is contained in:
paulevsGitch 2020-10-07 15:34:04 +03:00
parent 64f4285fbb
commit 91a2848bb5
10 changed files with 110 additions and 14 deletions

View file

@ -11,6 +11,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.Heightmap;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.chunk.Chunk;
@ -18,6 +19,7 @@ import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.BiomeRegistry;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.registry.StructureRegistry;
import ru.betterend.util.MHelper;
@ -65,6 +67,7 @@ public class MountainPiece extends BasePiece {
int sz = chunkPos.getStartZ();
Mutable pos = new Mutable();
Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE_WG);
for (int x = 0; x < 16; x++) {
int px = x + sx;
int px2 = px - center.getX();
@ -78,22 +81,69 @@ public class MountainPiece extends BasePiece {
if (dist < r2) {
pos.setZ(z);
dist = 1 - (float) Math.pow(dist / r2, 0.3);
int minY = world.getTopY(Type.WORLD_SURFACE_WG, px, pz);
int minY = map.get(x, z);
if (minY > 56) {
float maxY = dist * height * getHeightClamp(world, 8, px, pz);
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;
maxY += minY;
//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);
}*/
}
}
}
}
}
}
map = chunk.getHeightmap(Type.WORLD_SURFACE);
// Big crystals
int count = (map.get(8, 8) - 80) / 7;
count = MathHelper.clamp(count, 0, 8);
for (int i = 0; i < count; i++) {
int radius = MHelper.randRange(2, 3, random);
float fill = MHelper.randRange(0F, 1F, random);
int x = MHelper.randRange(radius, 15 - radius, random);
int z = MHelper.randRange(radius, 15 - radius, random);
int y = map.get(x, z);
if (y > 80) {
pos.set(x, y, z);
if (chunk.getBlockState(pos.down()).getBlock() == Blocks.END_STONE) {
int height = MHelper.floor(radius * MHelper.randRange(1.5F, 3F, random) + (y - 80) * 0.3F);
crystal(chunk, pos, radius, height, fill, random);
}
}
}
// Small crystals
count = (map.get(8, 8) - 80) / 2;
count = MathHelper.clamp(count, 4, 8);
for (int i = 0; i < count; i++) {
int radius = MHelper.randRange(1, 2, random);
float fill = random.nextBoolean() ? 0 : 1;
int x = MHelper.randRange(radius, 15 - radius, random);
int z = MHelper.randRange(radius, 15 - radius, random);
int y = map.get(x, z);
if (y > 80) {
pos.set(x, y, z);
if (chunk.getBlockState(pos.down()).getBlock() == Blocks.END_STONE) {
int height = MHelper.floor(radius * MHelper.randRange(1.5F, 3F, random) + (y - 80) * 0.3F);
crystal(chunk, pos, radius, height, fill, random);
}
}
}
return true;
}
@ -137,4 +187,33 @@ public class MountainPiece extends BasePiece {
int maxZ = MHelper.floor(center.getZ() + radius + 1);
this.boundingBox = new BlockBox(minX, minZ, maxX, maxZ);
}
private void crystal(Chunk chunk, BlockPos pos, int radius, int height, float fill, Random random) {
Mutable mut = new Mutable();
int max = MHelper.floor(fill * radius + radius + 0.5F);
height += pos.getY();
Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE);
int coefX = MHelper.randRange(-1, 1, random);
int coefZ = MHelper.randRange(-1, 1, random);
for (int x = -radius; x <= radius; x++) {
mut.setX(x + pos.getX());
if (mut.getX() >= 0 && mut.getX() < 16) {
int ax = Math.abs(x);
for (int z = -radius; z <= radius; z++) {
mut.setZ(z + pos.getZ());
if (mut.getZ() >= 0 && mut.getZ() < 16) {
int az = Math.abs(z);
if (ax + az < max) {
int minY = map.get(mut.getX(), mut.getZ()) - MHelper.randRange(3, 7, random);
int h = coefX * x + coefZ * z + height;
for (int y = minY; y < h; y++) {
mut.setY(y);
chunk.setBlockState(mut, BlockRegistry.AURORA_CRYSTAL.getDefaultState(), false);
}
}
}
}
}
}
}
}