TU19: merge Minecraft.World/WorldGen

This commit is contained in:
Tropical
2026-03-21 17:45:10 -05:00
parent eb23fc1a83
commit 0f280b5ed3
108 changed files with 3505 additions and 957 deletions

View File

@@ -7,6 +7,12 @@
#include "../../Headers/net.minecraft.world.level.h"
#include "../../Level/LevelData.h"
StructureFeature::StructureFeature() {
#ifdef ENABLE_STRUCTURE_SAVING
savedData = nullptr;
#endif
}
StructureFeature::~StructureFeature() {
for (AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end();
it++) {
@@ -20,6 +26,8 @@ void StructureFeature::addFeature(Level* level, int x, int z, int xOffs,
// the chunk being generated, but not all chunks are the sources of
// structures
restoreSavedData(level);
if (cachedStructures.find(ChunkPos::hashCode(x, z)) !=
cachedStructures.end()) {
return;
@@ -35,11 +43,14 @@ void StructureFeature::addFeature(Level* level, int x, int z, int xOffs,
level->getLevelData()->getGenerator() == LevelType::lvl_flat)) {
StructureStart* start = createStructureStart(x, z);
cachedStructures[ChunkPos::hashCode(x, z)] = start;
saveFeature(x, z, start);
}
}
bool StructureFeature::postProcess(Level* level, Random* random, int chunkX,
int chunkZ) {
restoreSavedData(level);
// 4J Stu - The x and z used to be offset by (+8) here, but that means we
// can miss out half structures on the edge of the world Normal feature
// generation offsets generation by half a chunk to ensure that it can
@@ -62,6 +73,11 @@ bool StructureFeature::postProcess(Level* level, Random* random, int chunkX,
structureStart->postProcess(level, random, bb);
delete bb;
intersection = true;
// because some feature pieces are modified in the postProcess
// step, we need to save them again
saveFeature(structureStart->getChunkX(),
structureStart->getChunkZ(), structureStart);
}
}
}
@@ -70,6 +86,8 @@ bool StructureFeature::postProcess(Level* level, Random* random, int chunkX,
}
bool StructureFeature::isIntersection(int cellX, int cellZ) {
restoreSavedData(level);
for (AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end();
it++) {
StructureStart* structureStart = it->second;
@@ -90,10 +108,13 @@ bool StructureFeature::isIntersection(int cellX, int cellZ) {
return false;
}
///////////////////////////////////////////
// 4J-PB - Below functions added from 1.2.3
///////////////////////////////////////////
bool StructureFeature::isInsideFeature(int cellX, int cellY, int cellZ) {
restoreSavedData(level);
return getStructureAt(cellX, cellY, cellZ) != NULL;
}
StructureStart* StructureFeature::getStructureAt(int cellX, int cellY,
int cellZ) {
// for (StructureStart structureStart : cachedStructures.values())
for (AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end();
++it) {
@@ -104,10 +125,10 @@ bool StructureFeature::isInsideFeature(int cellX, int cellY, int cellZ) {
cellX, cellZ)) {
/*
Iterator<StructurePiece> it =
structureStart.getPieces().iterator(); while (it.hasNext()) {
StructurePiece next = it.next();
if (next.getBoundingBox().isInside(cellX, cellY, cellZ)) {
return true;
structureStart.getPieces().iterator(); while (it.hasNext())
{ StructurePiece next = it.next(); if
(next.getBoundingBox().isInside(cellX, cellY, cellZ)) { return
true;
}
*/
std::list<StructurePiece*>* pieces =
@@ -118,12 +139,27 @@ bool StructureFeature::isInsideFeature(int cellX, int cellY, int cellZ) {
StructurePiece* piece = *it2;
if (piece->getBoundingBox()->isInside(cellX, cellY,
cellZ)) {
return true;
return pStructureStart;
}
}
}
}
}
return NULL;
}
bool StructureFeature::isInsideBoundingFeature(int cellX, int cellY,
int cellZ) {
restoreSavedData(level);
for (AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end();
++it) {
StructureStart* structureStart = it->second;
if (structureStart->isValid()) {
return (structureStart->getBoundingBox()->intersects(cellX, cellZ,
cellX, cellZ));
}
}
return false;
}
@@ -133,6 +169,8 @@ TilePos* StructureFeature::getNearestGeneratedFeature(Level* level, int cellX,
// even if the player hasn't generated new chunks yet
this->level = level;
restoreSavedData(level);
random->setSeed(level->getSeed());
int64_t xScale = random->nextLong();
int64_t zScale = random->nextLong();
@@ -159,7 +197,7 @@ TilePos* StructureFeature::getNearestGeneratedFeature(Level* level, int cellX,
int dx = locatorPosition->x - cellX;
int dy = locatorPosition->y - cellY;
int dz = locatorPosition->z - cellZ;
double dist = dx + dx * dy * dy + dz * dz;
double dist = dx * dx + dy * dy + dz * dz;
if (dist < minDistance) {
minDistance = dist;
@@ -180,7 +218,7 @@ TilePos* StructureFeature::getNearestGeneratedFeature(Level* level, int cellX,
int dx = (*it).x - cellX;
int dy = (*it).y - cellY;
int dz = (*it).z - cellZ;
double dist = dx + dx * dy * dy + dz * dz;
double dist = dx * dx + dy * dy + dz * dz;
if (dist < minDistance) {
minDistance = dist;
@@ -199,3 +237,50 @@ TilePos* StructureFeature::getNearestGeneratedFeature(Level* level, int cellX,
std::vector<TilePos>* StructureFeature::getGuesstimatedFeaturePositions() {
return NULL;
}
void StructureFeature::restoreSavedData(Level* level) {
#ifdef ENABLE_STRUCTURE_SAVING
if (savedData == NULL) {
savedData = std::dynamic_pointer_cast<StructureFeatureSavedData>(
level->getSavedData(typeid(StructureFeatureSavedData),
getFeatureName()));
if (savedData == NULL) {
savedData = std::shared_ptr<StructureFeatureSavedData>(
new StructureFeatureSavedData(getFeatureName()));
level->setSavedData(getFeatureName(), savedData);
} else {
CompoundTag* fullTag = savedData->getFullTag();
std::vector<Tag*>* allTags = fullTag->getAllTags();
for (AUTO_VAR(it, allTags->begin()); it != allTags->end(); ++it) {
Tag* featureTag = *it;
if (featureTag->getId() == Tag::TAG_Compound) {
CompoundTag* ct = (CompoundTag*)featureTag;
if (ct->contains(L"ChunkX") && ct->contains(L"ChunkZ")) {
int cx = ct->getInt(L"ChunkX");
int cz = ct->getInt(L"ChunkZ");
StructureStart* start =
StructureFeatureIO::loadStaticStart(ct, level);
// System.out.println("Loaded " +
// start.getClass().getSimpleName() + " from file");
cachedStructures[ChunkPos::hashCode(cx, cz)] = start;
}
}
}
delete allTags;
}
}
#endif
}
void StructureFeature::saveFeature(int chunkX, int chunkZ,
StructureStart* feature) {
#ifdef ENABLE_STRUCTURE_SAVING
savedData->putFeatureTag(feature->createTag(chunkX, chunkZ), chunkX,
chunkZ);
savedData->setDirty();
#endif
}