1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.levelgen.structure.h"
#include "StructureStart.h"
#include "StructurePiece.h"
#include "BoundingBox.h"
StructureStart::StructureStart()
{
chunkX = chunkZ = 0;
boundingBox = NULL; // 4J added initialiser
}
StructureStart::StructureStart(int x, int z)
{
this->chunkX = x;
this->chunkZ = z;
boundingBox = NULL;
}
StructureStart::~StructureStart()
{
for(AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ )
{
delete (*it);
}
delete boundingBox;
}
BoundingBox *StructureStart::getBoundingBox()
{
return boundingBox;
}
list<StructurePiece *> *StructureStart::getPieces()
{
return &pieces;
}
void StructureStart::postProcess(Level *level, Random *random, BoundingBox *chunkBB)
{
AUTO_VAR(it, pieces.begin());
while( it != pieces.end() )
{
if( (*it)->getBoundingBox()->intersects(chunkBB) && !(*it)->postProcess(level, random, chunkBB))
{
// this piece can't be placed, so remove it to avoid future
// attempts
it = pieces.erase(it);
}
else
{
it++;
}
}
}
void StructureStart::calculateBoundingBox()
{
boundingBox = BoundingBox::getUnknownBox();
for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ )
{
StructurePiece *piece = *it;
boundingBox->expand(piece->getBoundingBox());
}
}
CompoundTag *StructureStart::createTag(int chunkX, int chunkZ)
{
CompoundTag *tag = new CompoundTag();
tag->putString(L"id", StructureFeatureIO::getEncodeId(this));
tag->putInt(L"ChunkX", chunkX);
tag->putInt(L"ChunkZ", chunkZ);
tag->put(L"BB", boundingBox->createTag(L"BB"));
ListTag<CompoundTag> *childrenTags = new ListTag<CompoundTag>(L"Children");
for(AUTO_VAR(it, pieces.begin()); it != pieces.end(); ++it)
{
StructurePiece *piece = *it;
childrenTags->add(piece->createTag());
}
tag->put(L"Children", childrenTags);
addAdditonalSaveData(tag);
return tag;
}
void StructureStart::addAdditonalSaveData(CompoundTag *tag)
{
}
void StructureStart::load(Level *level, CompoundTag *tag)
{
chunkX = tag->getInt(L"ChunkX");
chunkZ = tag->getInt(L"ChunkZ");
if (tag->contains(L"BB"))
{
boundingBox = new BoundingBox(tag->getIntArray(L"BB"));
}
ListTag<CompoundTag> *children = (ListTag<CompoundTag> *) tag->getList(L"Children");
for (int i = 0; i < children->size(); i++)
{
pieces.push_back(StructureFeatureIO::loadStaticPiece(children->get(i), level));
}
readAdditonalSaveData(tag);
}
void StructureStart::readAdditonalSaveData(CompoundTag *tag)
{
}
void StructureStart::moveBelowSeaLevel(Level *level, Random *random, int offset)
{
const int MAX_Y = level->seaLevel - offset;
// set lowest possible position (at bedrock)
int y1Pos = boundingBox->getYSpan() + 1;
// move up randomly within the available span
if (y1Pos < MAX_Y)
{
y1Pos += random->nextInt(MAX_Y - y1Pos);
}
// move all bounding boxes
int dy = y1Pos - boundingBox->y1;
boundingBox->move(0, dy, 0);
for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ )
{
StructurePiece *piece = *it;
piece->getBoundingBox()->move(0, dy, 0);
}
}
void StructureStart::moveInsideHeights(Level *level, Random *random, int lowestAllowed, int highestAllowed)
{
int heightSpan = highestAllowed - lowestAllowed + 1 - boundingBox->getYSpan();
int y0Pos = 1;
if (heightSpan > 1)
{
y0Pos = lowestAllowed + random->nextInt(heightSpan);
}
else
{
y0Pos = lowestAllowed;
}
// move all bounding boxes
int dy = y0Pos - boundingBox->y0;
boundingBox->move(0, dy, 0);
for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ )
{
StructurePiece *piece = *it;
piece->getBoundingBox()->move(0, dy, 0);
}
}
bool StructureStart::isValid()
{
return true;
}
int StructureStart::getChunkX()
{
return chunkX;
}
int StructureStart::getChunkZ()
{
return chunkZ;
}
|