///////////////////////////////////////////////////////////////////////////////
+
void Decoration::resolveNodeNames()
{
getIdsFromNrBacklog(&c_place_on);
if (y < y_min_disp || y > y_max_disp || y < nmin.Y || y > nmax.Y)
continue;
- if (y + getHeight() > mg->vm->m_area.MaxEdge.Y) {
+ if (y + getHeight() > mg->vm->m_area.MaxEdge.Y)
continue;
-#if 0
- printf("Decoration at (%d %d %d) cut off\n", x, y, z);
- //add to queue
- MutexAutoLock cutofflock(cutoff_mutex);
- cutoffs.push_back(CutoffData(x, y, z, height));
-#endif
- }
if (mg->biomemap && !biomes.empty()) {
std::unordered_set<u8>::const_iterator iter =
}
-#if 0
-void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
-{
- PcgRandom pr(blockseed + 53);
- std::vector<CutoffData> handled_cutoffs;
-
- // Copy over the cutoffs we're interested in so we don't needlessly hold a lock
- {
- MutexAutoLock cutofflock(cutoff_mutex);
- for (std::list<CutoffData>::iterator i = cutoffs.begin();
- i != cutoffs.end(); ++i) {
- CutoffData cutoff = *i;
- v3s16 p = cutoff.p;
- s16 height = cutoff.height;
- if (p.X < nmin.X || p.X > nmax.X ||
- p.Z < nmin.Z || p.Z > nmax.Z)
- continue;
- if (p.Y + height < nmin.Y || p.Y > nmax.Y)
- continue;
-
- handled_cutoffs.push_back(cutoff);
- }
- }
-
- // Generate the cutoffs
- for (size_t i = 0; i != handled_cutoffs.size(); i++) {
- v3s16 p = handled_cutoffs[i].p;
- s16 height = handled_cutoffs[i].height;
-
- if (p.Y + height > nmax.Y) {
- //printf("Decoration at (%d %d %d) cut off again!\n", p.X, p.Y, p.Z);
- cuttoffs.push_back(v3s16(p.X, p.Y, p.Z));
- }
-
- generate(mg, &pr, nmax.Y, nmin.Y - p.Y, v3s16(p.X, nmin.Y, p.Z));
- }
-
- // Remove cutoffs that were handled from the cutoff list
- {
- MutexAutoLock cutofflock(cutoff_mutex);
- for (std::list<CutoffData>::iterator i = cutoffs.begin();
- i != cutoffs.end(); ++i) {
-
- for (size_t j = 0; j != handled_cutoffs.size(); j++) {
- CutoffData coff = *i;
- if (coff.p == handled_cutoffs[j].p)
- i = cutoffs.erase(i);
- }
- }
- }
-}
-#endif
-
-
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
+
size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
{
// Schematic could have been unloaded but not the decoration
if (flags & DECO_PLACE_CENTER_X)
p.X -= (schematic->size.X - 1) / 2;
- if (flags & DECO_PLACE_CENTER_Y)
- p.Y -= (schematic->size.Y - 1) / 2;
if (flags & DECO_PLACE_CENTER_Z)
p.Z -= (schematic->size.Z - 1) / 2;
+ if (flags & DECO_PLACE_CENTER_Y)
+ p.Y -= (schematic->size.Y - 1) / 2;
+ else
+ p.Y += place_offset_y;
+ // Check shifted schematic base is in voxelmanip
+ if (p.Y < vm->m_area.MinEdge.Y)
+ return 0;
+
Rotation rot = (rotation == ROTATE_RAND) ?
(Rotation)pr->range(ROTATE_0, ROTATE_270) : rotation;
int DecoSchematic::getHeight()
{
// Account for a schematic being sunk into the ground by flag.
- // When placed normally account for how a schematic is placed
- // sunk 1 node into the ground.
+ // When placed normally account for how a schematic is by default placed
+ // sunk 1 node into the ground or is vertically shifted by 'y_offset'.
return (flags & DECO_PLACE_CENTER_Y) ?
- (schematic->size.Y - 1) / 2 : schematic->size.Y - 1;
+ (schematic->size.Y - 1) / 2 : schematic->size.Y - 1 + place_offset_y;
}
extern FlagDesc flagdesc_deco[];
-#if 0
-struct CutoffData {
- VoxelArea a;
- Decoration *deco;
- //v3s16 p;
- //v3s16 size;
- //s16 height;
-
- CutoffData(s16 x, s16 y, s16 z, s16 h) {
- p = v3s16(x, y, z);
- height = h;
- }
-};
-#endif
-
class Decoration : public ObjDef, public NodeResolver {
public:
Decoration() = default;
bool canPlaceDecoration(MMVManip *vm, v3s16 p);
size_t placeDeco(Mapgen *mg, u32 blockseed,
v3s16 nmin, v3s16 nmax, s16 deco_zero_level);
- //size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p) = 0;
virtual int getHeight() = 0;
std::unordered_set<u8> biomes;
};
+
class DecoSimple : public Decoration {
public:
virtual void resolveNodeNames();
u8 deco_param2;
};
+
class DecoSchematic : public Decoration {
public:
DecoSchematic() = default;
virtual int getHeight();
Rotation rotation;
+ s16 place_offset_y = 0;
Schematic *schematic = nullptr;
};
};
*/
+
class DecorationManager : public ObjDefManager {
public:
DecorationManager(IGameDef *gamedef);