mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-05-24 11:44:39 +00:00
TU24
This commit is contained in:
@@ -9,7 +9,9 @@
|
||||
|
||||
StructureFeature::StructureFeature()
|
||||
{
|
||||
#ifdef ENABLE_STRUCTURE_SAVING
|
||||
savedData = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
StructureFeature::~StructureFeature()
|
||||
@@ -69,11 +71,8 @@ bool StructureFeature::postProcess(Level *level, Random *random, int chunkX, int
|
||||
delete bb;
|
||||
intersection = true;
|
||||
|
||||
if (structureStart->isDirty())
|
||||
{
|
||||
// because some feature pieces are modified in the postProcess step, we need to save them again
|
||||
saveFeature(structureStart->getChunkX(), structureStart->getChunkZ(), structureStart);
|
||||
}
|
||||
// because some feature pieces are modified in the postProcess step, we need to save them again
|
||||
saveFeature(structureStart->getChunkX(), structureStart->getChunkZ(), structureStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,12 +203,47 @@ TilePos *StructureFeature::getNearestGeneratedFeature(Level *level, int cellX, i
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selected != nullptr)
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<TilePos> *guesstimatedFeaturePositions = getGuesstimatedFeaturePositions();
|
||||
if (guesstimatedFeaturePositions != nullptr)
|
||||
{
|
||||
TilePos *pSelectedPos = new TilePos(0,0,0);
|
||||
|
||||
for(const auto& it : *guesstimatedFeaturePositions)
|
||||
{
|
||||
int dx = it.x - cellX;
|
||||
int dy = it.y - cellY;
|
||||
int dz = it.z - cellZ;
|
||||
double dist = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
if (dist < minDistance)
|
||||
{
|
||||
minDistance = dist;
|
||||
pSelectedPos->x = it.x;
|
||||
pSelectedPos->y = it.y;
|
||||
pSelectedPos->z = it.z;
|
||||
}
|
||||
}
|
||||
delete guesstimatedFeaturePositions;
|
||||
return pSelectedPos;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
vector<TilePos> *StructureFeature::getGuesstimatedFeaturePositions()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void StructureFeature::restoreSavedData(Level *level)
|
||||
{
|
||||
#ifdef ENABLE_STRUCTURE_SAVING
|
||||
if (savedData == nullptr)
|
||||
{
|
||||
savedData = dynamic_pointer_cast<StructureFeatureSavedData>( level->getSavedData(typeid(StructureFeatureSavedData), getFeatureName()) );
|
||||
@@ -221,39 +255,36 @@ void StructureFeature::restoreSavedData(Level *level)
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("==== Restoring saved data for %ls\n", getFeatureName());
|
||||
|
||||
CompoundTag *fullTag = savedData->getFullTag();
|
||||
|
||||
vector<Tag *> *allTags = fullTag->getAllTags();
|
||||
for (auto it = allTags->begin(); it != allTags->end(); ++it)
|
||||
{
|
||||
Tag *currentTag = *it;
|
||||
for ( Tag *featureTag : *allTags )
|
||||
{
|
||||
if ( featureTag && featureTag->getId() == Tag::TAG_Compound)
|
||||
{
|
||||
CompoundTag *ct = (CompoundTag *) featureTag;
|
||||
|
||||
if (currentTag->getId() == Tag::TAG_Byte_Array)
|
||||
{
|
||||
StructureStart *start = StructureFeatureIO::loadStaticStart((ByteArrayTag *)currentTag, level);
|
||||
if (ct->contains(L"ChunkX") && ct->contains(L"ChunkZ"))
|
||||
{
|
||||
int cx = ct->getInt(L"ChunkX");
|
||||
int cz = ct->getInt(L"ChunkZ");
|
||||
|
||||
if (start)
|
||||
{
|
||||
int cx = start->getChunkX();
|
||||
int cz = start->getChunkZ();
|
||||
|
||||
app.DebugPrintf("========= Restoring structure starting in chunk %d, %d\n", cx, cz);
|
||||
|
||||
cachedStructures[ChunkPos::hashCode(cx, cz)] = start;
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
app.DebugPrintf("########### Saving %ls feature [%d, %d]\n", getFeatureName(), chunkX, chunkZ);
|
||||
#ifdef ENABLE_STRUCTURE_SAVING
|
||||
savedData->putFeatureTag(feature->createTag(chunkX, chunkZ), chunkX, chunkZ);
|
||||
savedData->setDirty();
|
||||
feature->clearDirty();
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user