flower forste part 1 + decompiled roofed forest

This commit is contained in:
Lord Cambion
2026-03-23 03:44:02 +01:00
parent 58d57f2b54
commit f0b06116c2
22 changed files with 901 additions and 630 deletions
+77 -66
View File
@@ -5,81 +5,108 @@
#include "TreeTile2.h"
#include "LeafTile2.h"
#include <cmath>
#include <algorithm>
DarkOakFeature::DarkOakFeature(bool doUpdate) : Feature(doUpdate) {
this->baseHeight = 6;
}
bool DarkOakFeature::place(Level *worldIn, Random *rand, int x, int y, int z) {
int i = rand->nextInt(3) + rand->nextInt(2) + 6;
int j = x;
int k = y;
int l = z;
bool DarkOakFeature::place(Level *level, Random *rand, int x, int y, int z) {
int treeHeight = rand->nextInt(3) + rand->nextInt(2) + 6;
int startX = x;
int startY = y;
int startZ = z;
if (k >= 1 && k + i + 1 < Level::maxBuildHeight) {
int below = worldIn->getTile(j, k - 1, l);
bool isSoil = (below == Tile::grass_Id || below == Tile::dirt_Id);
if (startY >= 1 && startY + treeHeight + 1 < Level::maxBuildHeight) {
int belowTile = level->getTile(startX, startY - 1, startZ);
bool isSoil = (belowTile == Tile::grass_Id || belowTile == Tile::dirt_Id);
if (!(isSoil && k < Level::maxBuildHeight - i - 1)) {
if (!(isSoil && startY < Level::maxBuildHeight - treeHeight - 1)) {
return false;
} else if (!this->checkSpace(worldIn, j, k, l, i)) {
} else if (!this->checkSpace(level, startX, startY, startZ, treeHeight)) {
return false;
} else {
int dirX = 0;
int dirZ = 0;
int facing = rand->nextInt(4);
if (facing == 0) dirX = 1;
else if (facing == 1) dirX = -1;
else if (facing == 2) dirZ = 1;
else if (facing == 3) dirZ = -1;
int i1 = i - rand->nextInt(4);
int j1 = 2 - rand->nextInt(3);
int k1 = j;
int l1 = l;
int i2 = k + i - 1;
if(app.getLevelGenerationOptions() != nullptr)
{
LevelGenerationOptions *levelGenOptions = app.getLevelGenerationOptions();
int radius = 4;
bool intersects = levelGenOptions->checkIntersects(x - radius, y - 1, z - radius, x + radius + 1, y + treeHeight, z + radius + 1);
if(intersects)
{
return false;
}
}
for (int j2 = 0; j2 < i; ++j2) {
if (j2 >= i1 && j1 > 0) {
k1 += dirX;
l1 += dirZ;
--j1;
placeBlock(level, startX, startY - 1, startZ, Tile::dirt_Id);
placeBlock(level, startX + 1, startY - 1, startZ, Tile::dirt_Id);
placeBlock(level, startX, startY - 1, startZ + 1, Tile::dirt_Id);
placeBlock(level, startX + 1, startY - 1, startZ + 1, Tile::dirt_Id);
int face = rand->nextInt(4); // Direzione: 0=N, 1=E, 2=S, 3=W
int dx = 0;
int dz = 0;
if (face == 0) dz = -1;
else if (face == 1) dx = 1;
else if (face == 2) dz = 1;
else if (face == 3) dx = -1;
int bendHeight = treeHeight - rand->nextInt(4);
int bendLength = 2 - rand->nextInt(3);
int trunkX = startX;
int trunkZ = startZ;
int topY = startY + treeHeight - 1;
for (int j2 = 0; j2 < treeHeight; ++j2) {
if (j2 >= bendHeight && bendLength > 0) {
trunkX += dx;
trunkZ += dz;
--bendLength;
}
int k2 = k + j2;
this->placeLog(worldIn, k1, k2, l1);
this->placeLog(worldIn, k1 + 1, k2, l1);
this->placeLog(worldIn, k1, k2, l1 + 1);
this->placeLog(worldIn, k1 + 1, k2, l1 + 1);
int currentY = startY + j2;
this->placeLog(level, trunkX, currentY, trunkZ);
this->placeLog(level, trunkX + 1, currentY, trunkZ);
this->placeLog(level, trunkX, currentY, trunkZ + 1);
this->placeLog(level, trunkX + 1, currentY, trunkZ + 1);
}
for (int i3 = -2; i3 <= 0; ++i3) {
for (int l3 = -2; l3 <= 0; ++l3) {
int k4 = -1;
this->placeLeaf(worldIn, k1 + i3, i2 + k4, l1 + l3);
this->placeLeaf(worldIn, 1 + k1 - i3, i2 + k4, l1 + l3);
this->placeLeaf(worldIn, k1 + i3, i2 + k4, 1 + l1 - l3);
this->placeLeaf(worldIn, 1 + k1 - i3, i2 + k4, 1 + l1 - l3);
this->placeLeaf(level, trunkX + i3, topY + k4, trunkZ + l3);
this->placeLeaf(level, 1 + trunkX - i3, topY + k4, trunkZ + l3);
this->placeLeaf(level, trunkX + i3, topY + k4, 1 + trunkZ - l3);
this->placeLeaf(level, 1 + trunkX - i3, topY + k4, 1 + trunkZ - l3);
if ((i3 > -2 || l3 > -1) && (i3 != -1 || l3 != -2)) {
k4 = 1;
this->placeLeaf(worldIn, k1 + i3, i2 + k4, l1 + l3);
this->placeLeaf(worldIn, 1 + k1 - i3, i2 + k4, l1 + l3);
this->placeLeaf(worldIn, k1 + i3, i2 + k4, 1 + l1 - l3);
this->placeLeaf(worldIn, 1 + k1 - i3, i2 + k4, 1 + l1 - l3);
this->placeLeaf(level, trunkX + i3, topY + k4, trunkZ + l3);
this->placeLeaf(level, 1 + trunkX - i3, topY + k4, trunkZ + l3);
this->placeLeaf(level, trunkX + i3, topY + k4, 1 + trunkZ - l3);
this->placeLeaf(level, 1 + trunkX - i3, topY + k4, 1 + trunkZ - l3);
}
}
}
if (rand->nextInt(2) == 0) {
this->placeLeaf(level, trunkX, topY + 2, trunkZ);
this->placeLeaf(level, trunkX + 1, topY + 2, trunkZ);
this->placeLeaf(level, trunkX + 1, topY + 2, trunkZ + 1);
this->placeLeaf(level, trunkX, topY + 2, trunkZ + 1);
}
for (int j3 = -3; j3 <= 4; ++j3) {
for (int i4 = -3; i4 <= 4; ++i4) {
if ((j3 != -3 || i4 != -3) && (j3 != -3 || i4 != 4) && (j3 != 4 || i4 != -3) && (j3 != 4 || i4 != 4) && (std::abs(j3) < 3 || std::abs(i4) < 3)) {
this->placeLeaf(worldIn, k1 + j3, i2, l1 + i4);
this->placeLeaf(level, trunkX + j3, topY, trunkZ + i4);
}
}
}
@@ -92,21 +119,20 @@ bool DarkOakFeature::place(Level *worldIn, Random *rand, int x, int y, int z) {
for (int i5 = 0; i5 < l4; ++i5) {
this->placeLog(worldIn, j + k3, i2 - i5 - 1, l + j4);
this->placeLog(level, startX + k3, topY - i5 - 1, startZ + j4);
}
for (int j5 = -1; j5 <= 1; ++j5) {
for (int l2 = -1; l2 <= 1; ++l2) {
this->placeLeaf(worldIn, k1 + k3 + j5, i2, l1 + j4 + l2);
this->placeLeaf(level, trunkX + k3 + j5, topY, trunkZ + j4 + l2);
}
}
for (int k5 = -2; k5 <= 2; ++k5) {
for (int l5 = -2; l5 <= 2; ++l5) {
if (std::abs(k5) != 2 || std::abs(l5) != 2) {
this->placeLeaf(worldIn, k1 + k3 + k5, i2 - 1, l1 + j4 + l5);
this->placeLeaf(level, trunkX + k3 + k5, topY - 1, trunkZ + j4 + l5);
}
}
}
@@ -120,27 +146,18 @@ bool DarkOakFeature::place(Level *worldIn, Random *rand, int x, int y, int z) {
return false;
}
bool DarkOakFeature::checkSpace(Level *worldIn, int x, int y, int z, int height) {
for (int l = 0; l <= height + 1; ++l) {
int i1 = 1;
if (l == 0) {
i1 = 0;
}
if (l >= height - 1) {
i1 = 2;
}
if (l == 0) i1 = 0;
if (l >= height - 1) i1 = 2;
for (int j1 = -i1; j1 <= i1; ++j1) {
for (int k1 = -i1; k1 <= i1; ++k1) {
if (l == 0 && j1 == 0 && k1 == 0) continue;
int tile = worldIn->getTile(x + j1, y + l, z + k1);
if (tile != 0 &&
tile != Tile::leaves_Id && tile != Tile::leaves2_Id &&
tile != Tile::tallgrass_Id && tile != Tile::sapling_Id &&
@@ -149,10 +166,7 @@ bool DarkOakFeature::checkSpace(Level *worldIn, int x, int y, int z, int height)
return false;
}
if (tile == Tile::water_Id) {
return false;
}
if (tile == Tile::water_Id) return false;
}
}
}
@@ -161,16 +175,13 @@ bool DarkOakFeature::checkSpace(Level *worldIn, int x, int y, int z, int height)
void DarkOakFeature::placeLog(Level *worldIn, int x, int y, int z) {
int tile = worldIn->getTile(x, y, z);
if (tile == 0 || tile == Tile::leaves_Id || tile == Tile::leaves2_Id || tile == Tile::tallgrass_Id) {
placeBlock(worldIn, x, y, z, Tile::tree2Trunk_Id, TreeTile2::DARK_TRUNK);
}
}
void DarkOakFeature::placeLeaf(Level *worldIn, int x, int y, int z) {
int tile = worldIn->getTile(x, y, z);
if (tile == 0) {
placeBlock(worldIn, x, y, z, Tile::leaves2_Id, 1);