mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-07-01 22:54:20 +00:00
chore: format Minecraft.World
This commit is contained in:
@@ -3,39 +3,38 @@
|
||||
#include "DungeonFeature.h"
|
||||
#include "../../Headers/net.minecraft.world.level.tile.h"
|
||||
|
||||
void DungeonFeature::addRoom(int xOffs, int zOffs, byteArray blocks, double xRoom, double yRoom, double zRoom)
|
||||
{
|
||||
addTunnel(xOffs, zOffs, blocks, xRoom, yRoom, zRoom, 1 + random->nextFloat() * 6, 0, 0, -1, -1, 0.5);
|
||||
void DungeonFeature::addRoom(int xOffs, int zOffs, byteArray blocks,
|
||||
double xRoom, double yRoom, double zRoom) {
|
||||
addTunnel(xOffs, zOffs, blocks, xRoom, yRoom, zRoom,
|
||||
1 + random->nextFloat() * 6, 0, 0, -1, -1, 0.5);
|
||||
}
|
||||
|
||||
void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale)
|
||||
{
|
||||
void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks,
|
||||
double xCave, double yCave, double zCave,
|
||||
float thickness, float yRot, float xRot,
|
||||
int step, int dist, double yScale) {
|
||||
double xMid = xOffs * 16 + 8;
|
||||
double zMid = zOffs * 16 + 8;
|
||||
|
||||
float yRota = 0;
|
||||
float xRota = 0;
|
||||
Random *random = new Random(this->random->nextLong());
|
||||
Random* random = new Random(this->random->nextLong());
|
||||
|
||||
if (dist <= 0)
|
||||
{
|
||||
if (dist <= 0) {
|
||||
int max = radius * 16 - 16;
|
||||
dist = max - random->nextInt(max / 4);
|
||||
}
|
||||
bool singleStep = false;
|
||||
|
||||
if (step == -1)
|
||||
{
|
||||
if (step == -1) {
|
||||
step = dist / 2;
|
||||
singleStep = true;
|
||||
}
|
||||
|
||||
|
||||
int splitPoint = random->nextInt(dist / 2) + dist / 4;
|
||||
bool steep = random->nextInt(6) == 0;
|
||||
|
||||
for (; step < dist; step++)
|
||||
{
|
||||
for (; step < dist; step++) {
|
||||
double rad = 1.5 + (Mth::sin(step * PI / dist) * thickness) * 1;
|
||||
double yRad = rad * yScale;
|
||||
|
||||
@@ -45,12 +44,9 @@ void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks, double xC
|
||||
yCave += xs;
|
||||
zCave += Mth::sin(yRot) * xc;
|
||||
|
||||
if (steep)
|
||||
{
|
||||
if (steep) {
|
||||
xRot *= 0.92f;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xRot *= 0.7f;
|
||||
}
|
||||
xRot += xRota * 0.1f;
|
||||
@@ -58,14 +54,18 @@ void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks, double xC
|
||||
|
||||
xRota *= 0.90f;
|
||||
yRota *= 0.75f;
|
||||
xRota += (random->nextFloat() - random->nextFloat()) * random->nextFloat() * 2;
|
||||
yRota += (random->nextFloat() - random->nextFloat()) * random->nextFloat() * 4;
|
||||
xRota += (random->nextFloat() - random->nextFloat()) *
|
||||
random->nextFloat() * 2;
|
||||
yRota += (random->nextFloat() - random->nextFloat()) *
|
||||
random->nextFloat() * 4;
|
||||
|
||||
|
||||
if (!singleStep && step == splitPoint && thickness > 1)
|
||||
{
|
||||
addTunnel(xOffs, zOffs, blocks, xCave, yCave, zCave, random->nextFloat() * 0.5f + 0.5f, yRot - PI / 2, xRot / 3, step, dist, 1.0);
|
||||
addTunnel(xOffs, zOffs, blocks, xCave, yCave, zCave, random->nextFloat() * 0.5f + 0.5f, yRot + PI / 2, xRot / 3, step, dist, 1.0);
|
||||
if (!singleStep && step == splitPoint && thickness > 1) {
|
||||
addTunnel(xOffs, zOffs, blocks, xCave, yCave, zCave,
|
||||
random->nextFloat() * 0.5f + 0.5f, yRot - PI / 2,
|
||||
xRot / 3, step, dist, 1.0);
|
||||
addTunnel(xOffs, zOffs, blocks, xCave, yCave, zCave,
|
||||
random->nextFloat() * 0.5f + 0.5f, yRot + PI / 2,
|
||||
xRot / 3, step, dist, 1.0);
|
||||
return;
|
||||
}
|
||||
if (!singleStep && random->nextInt(4) == 0) continue;
|
||||
@@ -75,13 +75,14 @@ void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks, double xC
|
||||
double zd = zCave - zMid;
|
||||
double remaining = dist - step;
|
||||
double rr = (thickness + 2) + 16;
|
||||
if (xd * xd + zd * zd - (remaining * remaining) > rr * rr)
|
||||
{
|
||||
if (xd * xd + zd * zd - (remaining * remaining) > rr * rr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (xCave < xMid - 16 - rad * 2 || zCave < zMid - 16 - rad * 2 || xCave > xMid + 16 + rad * 2 || zCave > zMid + 16 + rad * 2) continue;
|
||||
if (xCave < xMid - 16 - rad * 2 || zCave < zMid - 16 - rad * 2 ||
|
||||
xCave > xMid + 16 + rad * 2 || zCave > zMid + 16 + rad * 2)
|
||||
continue;
|
||||
|
||||
int x0 = Mth::floor(xCave - rad) - xOffs * 16 - 1;
|
||||
int x1 = Mth::floor(xCave + rad) - xOffs * 16 + 1;
|
||||
@@ -102,20 +103,17 @@ void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks, double xC
|
||||
if (z1 > 16) z1 = 16;
|
||||
|
||||
bool detectedWater = false;
|
||||
for (int xx = x0; !detectedWater && xx < x1; xx++)
|
||||
{
|
||||
for (int zz = z0; !detectedWater && zz < z1; zz++)
|
||||
{
|
||||
for (int yy = y1 + 1; !detectedWater && yy >= y0 - 1; yy--)
|
||||
{
|
||||
for (int xx = x0; !detectedWater && xx < x1; xx++) {
|
||||
for (int zz = z0; !detectedWater && zz < z1; zz++) {
|
||||
for (int yy = y1 + 1; !detectedWater && yy >= y0 - 1; yy--) {
|
||||
int p = (xx * 16 + zz) * Level::genDepth + yy;
|
||||
if (yy < 0 || yy >= Level::genDepth) continue;
|
||||
if (blocks[p] == Tile::water_Id || blocks[p] == Tile::calmWater_Id)
|
||||
{
|
||||
if (yy < 0 || yy >= Level::genDepth) continue;
|
||||
if (blocks[p] == Tile::water_Id ||
|
||||
blocks[p] == Tile::calmWater_Id) {
|
||||
detectedWater = true;
|
||||
}
|
||||
if (yy != y0 - 1 && xx != x0 && xx != x1 - 1 && zz != z0 && zz != z1 - 1)
|
||||
{
|
||||
if (yy != y0 - 1 && xx != x0 && xx != x1 - 1 && zz != z0 &&
|
||||
zz != z1 - 1) {
|
||||
yy = y0;
|
||||
}
|
||||
}
|
||||
@@ -123,31 +121,25 @@ void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks, double xC
|
||||
}
|
||||
if (detectedWater) continue;
|
||||
|
||||
for (int xx = x0; xx < x1; xx++)
|
||||
{
|
||||
for (int xx = x0; xx < x1; xx++) {
|
||||
double xd = ((xx + xOffs * 16 + 0.5) - xCave) / rad;
|
||||
for (int zz = z0; zz < z1; zz++)
|
||||
{
|
||||
for (int zz = z0; zz < z1; zz++) {
|
||||
double zd = ((zz + zOffs * 16 + 0.5) - zCave) / rad;
|
||||
int p = (xx * 16 + zz) * Level::genDepth + y1;
|
||||
bool hasGrass = false;
|
||||
for (int yy = y1 - 1; yy >= y0; yy--)
|
||||
{
|
||||
for (int yy = y1 - 1; yy >= y0; yy--) {
|
||||
double yd = (yy + 0.5 - yCave) / yRad;
|
||||
if (yd > -0.7 && xd * xd + yd * yd + zd * zd < 1)
|
||||
{
|
||||
if (yd > -0.7 && xd * xd + yd * yd + zd * zd < 1) {
|
||||
int block = blocks[p];
|
||||
if (block == Tile::grass_Id) hasGrass = true;
|
||||
if (block == Tile::rock_Id || block == Tile::dirt_Id || block == Tile::grass_Id)
|
||||
{
|
||||
if (yy < 10)
|
||||
{
|
||||
blocks[p] = (uint8_t) Tile::lava_Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
blocks[p] = (uint8_t) 0;
|
||||
if (hasGrass && blocks[p - 1] == Tile::dirt_Id) blocks[p - 1] = (uint8_t) Tile::grass_Id;
|
||||
if (block == Tile::rock_Id || block == Tile::dirt_Id ||
|
||||
block == Tile::grass_Id) {
|
||||
if (yy < 10) {
|
||||
blocks[p] = (uint8_t)Tile::lava_Id;
|
||||
} else {
|
||||
blocks[p] = (uint8_t)0;
|
||||
if (hasGrass && blocks[p - 1] == Tile::dirt_Id)
|
||||
blocks[p - 1] = (uint8_t)Tile::grass_Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,35 +149,32 @@ void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks, double xC
|
||||
}
|
||||
if (singleStep) break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DungeonFeature::addFeature(Level *level, int x, int z, int xOffs, int zOffs, byteArray blocks)
|
||||
{
|
||||
void DungeonFeature::addFeature(Level* level, int x, int z, int xOffs,
|
||||
int zOffs, byteArray blocks) {
|
||||
int caves = random->nextInt(random->nextInt(random->nextInt(40) + 1) + 1);
|
||||
if (random->nextInt(15) != 0) caves = 0;
|
||||
|
||||
for (int cave = 0; cave < caves; cave++)
|
||||
{
|
||||
for (int cave = 0; cave < caves; cave++) {
|
||||
double xCave = x * 16 + random->nextInt(16);
|
||||
double yCave = random->nextInt(random->nextInt(Level::genDepth - 8) + 8);
|
||||
double yCave =
|
||||
random->nextInt(random->nextInt(Level::genDepth - 8) + 8);
|
||||
double zCave = z * 16 + random->nextInt(16);
|
||||
|
||||
int tunnels = 1;
|
||||
if (random->nextInt(4) == 0)
|
||||
{
|
||||
if (random->nextInt(4) == 0) {
|
||||
addRoom(xOffs, zOffs, blocks, xCave, yCave, zCave);
|
||||
tunnels += random->nextInt(4);
|
||||
}
|
||||
|
||||
for (int i = 0; i < tunnels; i++)
|
||||
{
|
||||
|
||||
for (int i = 0; i < tunnels; i++) {
|
||||
float yRot = random->nextFloat() * PI * 2;
|
||||
float xRot = ((random->nextFloat() - 0.5f) * 2) / 8;
|
||||
float thickness = random->nextFloat() * 2 + random->nextFloat();
|
||||
|
||||
addTunnel(xOffs, zOffs, blocks, xCave, yCave, zCave, thickness, yRot, xRot, 0, 0, 1.0);
|
||||
addTunnel(xOffs, zOffs, blocks, xCave, yCave, zCave, thickness,
|
||||
yRot, xRot, 0, 0, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user