use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class AuritisTreeFeature method place.
@Override
@SuppressWarnings("deprecation")
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
WorldGenLevel level = featurePlaceContext.level();
BlockPos center = featurePlaceContext.origin();
Random random = featurePlaceContext.random();
if (!EdenBlocks.AURITIS_SAPLING.canSurvive(EdenBlocks.AURITIS_SAPLING.defaultBlockState(), level, center)) {
return false;
}
BlockState log = EdenBlocks.AURITIS_MATERIAL.getBlock(WoodenComplexMaterial.BLOCK_LOG).defaultBlockState();
BlockState bark = EdenBlocks.AURITIS_MATERIAL.getBlock(WoodenComplexMaterial.BLOCK_BARK).defaultBlockState();
BlockState leaves = EdenBlocks.AURITIS_LEAVES.defaultBlockState();
BlockState moss = EdenBlocks.EDEN_MOSS.defaultBlockState();
boolean natural = featurePlaceContext.config() != null;
boolean hasMax = false;
MutableBlockPos pos = center.mutable();
for (Direction dir : BlocksHelper.HORIZONTAL) {
pos.set(center).move(dir);
int h = hasMax ? random.nextInt(2) : random.nextInt(3);
if (!hasMax) {
hasMax = h == 2;
}
for (int i = -1; i <= h; i++) {
pos.setY(center.getY() + i);
if (canReplace(level.getBlockState(pos))) {
BlocksHelper.setWithoutUpdate(level, pos, i == h ? bark : log);
if (natural && i == h && random.nextInt(4) > 0) {
pos.setY(pos.getY() + 1);
if (canReplace(level.getBlockState(pos))) {
BlocksHelper.setWithoutUpdate(level, pos, moss);
}
}
}
}
}
pos.set(center);
BlocksHelper.setWithoutUpdate(level, pos, log);
int h = MHelper.randRange(7, 10, random);
for (int i = 1; i < h; i++) {
pos.setY(center.getY() + i);
if (canReplace(level.getBlockState(pos))) {
BlocksHelper.setWithoutUpdate(level, pos, log);
} else {
return true;
}
}
int count = MHelper.randRange(3, 5, random);
float angle = (float) Math.PI * 2 * random.nextFloat();
float deltaAngle = (float) Math.PI * 2 / count;
makeCanopy(level, pos, leaves, natural, random);
for (int i = 0; i < count; i++) {
float delta = MHelper.randRange(0.3F, 0.6F, random);
float dx = (float) Math.sin(angle) * delta;
float dz = (float) Math.cos(angle) * delta;
angle += deltaAngle;
int length = (int) MHelper.randRange(h * 0.3F, h * 0.7F, random);
if (length == 0) {
break;
}
pos.setY(center.getY() + h - length - random.nextInt(3));
makeBranch(level, pos, dx, dz, length, bark, leaves, moss, natural, random);
}
return true;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class AuritisTreeFeature method makeBranch.
private void makeBranch(WorldGenLevel level, BlockPos pos, float dx, float dz, int length, BlockState bark, BlockState leaves, BlockState moss, boolean natural, Random random) {
MutableBlockPos mut = pos.mutable();
float px = 0.5F;
float pz = 0.5F;
int maxMoss = length >> 1;
for (int i = 0; i < length; i++) {
px += dx;
pz += dz;
mut.setX(Mth.floor((double) pos.getX() + px));
mut.setZ(Mth.floor((double) pos.getZ() + pz));
mut.setY(pos.getY() + i);
if (canReplace(level.getBlockState(mut))) {
BlocksHelper.setWithoutUpdate(level, mut, bark);
if (natural && i < maxMoss && random.nextBoolean()) {
mut.setY(mut.getY() + 1);
if (level.getBlockState(mut).isAir()) {
BlocksHelper.setWithoutUpdate(level, mut, moss);
}
}
}
}
makeCanopy(level, mut, leaves, natural, random);
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class CaveGenerator method carve.
public static void carve(ChunkAccess chunkAccess, InterpolationCell cellTerrain) {
int minX = chunkAccess.getPos().getMinBlockX();
int minZ = chunkAccess.getPos().getMinBlockZ();
int minY = chunkAccess.getMinBuildHeight();
int maxY = chunkAccess.getMaxBuildHeight();
final float[] buffer9 = new float[9];
final float[] buffer27 = new float[27];
Random random = new Random();
final int maxCell = (maxY - minY) / 8 + 1;
final BlockPos origin = new BlockPos(minX, minY, minZ);
TerrainGenerator generator = MultiThreadGenerator.getTerrainGenerator();
InterpolationCell cellSparse = new InterpolationCell(generator, 4, (maxY - minY) / 16 + 1, 16, 16, new BlockPos(minX - 16, minY, minZ - 16));
InterpolationCell cellVoronoi = new InterpolationCell(p -> getTunelNoise(p, buffer27, random), 5, (maxY - minY) / 4 + 1, 4, 4, origin);
InterpolationCell cellBigCave = new InterpolationCell(p -> getBigCaveNoise(cellSparse, p), 3, maxCell, 8, 8, origin);
InterpolationCell cellPillars = new InterpolationCell(p -> getPillars(p, seed, buffer9, random), 5, (maxY - minY) / 4 + 1, 4, 4, origin);
MutableBlockPos pos = new MutableBlockPos();
int maxCheck = maxY - 16;
for (byte x = 0; x < 16; x++) {
pos.setX(x);
for (byte z = 0; z < 16; z++) {
pos.setZ(z);
byte index = 0;
float[] accumulation = new float[8];
int max = chunkAccess.getHeight(Types.WORLD_SURFACE_WG, x, z) - 10;
for (short y = (short) max; y > minY; y--) {
if (y < maxCheck) {
float heightNoise = cellTerrain.get(pos.setY(y + 10), true);
if (heightNoise <= 0) {
continue;
}
if (y > 8) {
heightNoise = cellTerrain.get(pos.setY(y - 8), true);
if (heightNoise <= 0) {
continue;
}
}
}
pos.setY(y);
if (chunkAccess.getBlockState(pos).getBlock() == Blocks.STONE) {
float noise = cellVoronoi.get(pos, true);
accumulation[index++] = noise;
if (index >= accumulation.length) {
index = 0;
}
float average = 0;
for (byte i = 0; i < accumulation.length; i++) {
noise = MHelper.max(noise, accumulation[i]);
average += accumulation[i];
}
noise = (noise + (average / accumulation.length)) * 0.5F - 0.9F;
float cellValue = cellTerrain.get(pos, true);
noise = -smoothUnion(-noise, cellValue + 0.5F, 1.1F);
float bigCave = 0;
if (noise < 0.1F) {
bigCave = cellBigCave.get(pos, true);
noise = -smoothUnion(-noise, -bigCave, 0.1F);
}
if (noise > -0.1F) {
float pillars = cellPillars.get(pos, true);
noise = smoothUnion(noise, pillars, 0.1F);
}
if (noise > 0) {
chunkAccess.setBlockState(pos, CAVE_AIR, false);
int py = pos.getY();
pos.setY(py + 1);
}
}
}
}
}
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class AquatusFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
WorldGenLevel level = featurePlaceContext.level();
BlockPos center = featurePlaceContext.origin();
Random random = featurePlaceContext.random();
int side = MHelper.randRange(1, 3, random);
int min = -(side >> 1);
int max = side + min;
MutableBlockPos pos = new MutableBlockPos();
for (int x = min; x < max; x++) {
pos.setX(center.getX() + x);
for (int z = min; z < max; z++) {
pos.setZ(center.getZ() + z);
pos.setY(center.getY() - 1);
if (!isTerrain(level.getBlockState(pos))) {
return false;
}
pos.setY(center.getY());
if (!canReplace(level.getBlockState(pos))) {
return false;
}
}
}
int minDec = min - 1;
pos.setY(center.getY() + 2);
for (int x = minDec; x <= max; x++) {
pos.setX(center.getX() + x);
for (int z = minDec; z <= max; z++) {
if (x != minDec || x != max || z != minDec || z != max) {
pos.setZ(center.getZ() + z);
if (!canReplace(level.getBlockState(pos))) {
return false;
}
}
}
}
BlockState roots = EdenBlocks.AQUATUS_ROOTS.defaultBlockState().setValue(BlockStateProperties.UP, false);
BlockState leaves = EdenBlocks.AQUATUS_ROOTS.defaultBlockState().setValue(BlockStateProperties.UP, true);
BlockState block = EdenBlocks.AQUATUS_BLOCK.defaultBlockState();
BlockState water = Blocks.WATER.defaultBlockState();
for (int x = min; x < max; x++) {
pos.setX(center.getX() + x);
for (int z = min; z < max; z++) {
pos.setZ(center.getZ() + z);
pos.setY(center.getY());
setBlock(level, pos, roots);
pos.setY(center.getY() + 1);
setBlock(level, pos, block);
pos.setY(center.getY() + 2);
setBlock(level, pos, water);
}
}
for (int i = min; i < max; i++) {
pos.setZ(center.getZ() + i);
pos.setX(center.getX() + minDec);
pos.setY(center.getY() + 1);
setBlock(level, pos, leaves);
pos.setY(center.getY() + 2);
setBlock(level, pos, block);
pos.setX(center.getX() + max);
pos.setY(center.getY() + 1);
setBlock(level, pos, leaves);
pos.setY(center.getY() + 2);
setBlock(level, pos, block);
pos.setX(center.getX() + i);
pos.setZ(center.getZ() + minDec);
pos.setY(center.getY() + 1);
setBlock(level, pos, leaves);
pos.setY(center.getY() + 2);
setBlock(level, pos, block);
pos.setZ(center.getZ() + max);
pos.setY(center.getY() + 1);
setBlock(level, pos, leaves);
pos.setY(center.getY() + 2);
setBlock(level, pos, block);
}
return true;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class VolvoxFeature method makeSphere.
private void makeSphere(WorldGenLevel level, BlockPos center, float radius, float fill, BlockState wall, BlockState water, List<BlockPos> positions) {
double r21 = (double) radius * (double) radius;
MutableBlockPos pos = new MutableBlockPos();
double r22 = (double) (radius - 1) * (double) (radius - 1);
int min = Mth.floor(-radius);
int max = Mth.floor(radius + 1);
int waterY = (int) Mth.lerp(fill, min, max);
for (int x = min; x <= max; x++) {
int sqrX = x * x;
pos.setX(center.getX() + x);
for (int y = min; y <= max; y++) {
int sqrY = y * y;
pos.setY(center.getY() + y);
for (int z = min; z <= max; z++) {
int sqrZ = z * z;
int d = sqrX + sqrY + sqrZ;
if (d <= r21) {
pos.setZ(center.getZ() + z);
if (d >= r22) {
if (level.getBlockState(pos).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(level, pos, wall);
if (positions != null) {
positions.add(pos.immutable());
}
}
} else if (y < waterY && level.getBlockState(pos).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(level, pos, water);
}
}
}
}
}
}
Aggregations