Skip to content

Commit 9a41a3d

Browse files
committedOct 10, 2017
Simple decorations: Make 'place_offset_y' usable with simple decorations
Necessary for placing the base cube of 'plantlike_rooted' drawtype in the seabed instead of on it. Useful for placing decorations sunk into, or buried in, the ground.
1 parent 2cf9014 commit 9a41a3d

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed
 

Diff for: ‎doc/lua_api.txt

+17-12
Original file line numberDiff line numberDiff line change
@@ -4814,38 +4814,43 @@ Definition tables
48144814
y_min = -31000
48154815
y_max = 31000
48164816
-- ^ Lower and upper limits for decoration.
4817-
-- ^ This parameter refers to the `y` position of the decoration base, so
4818-
-- the actual maximum height would be `height_max + size.Y`.
4817+
-- ^ These parameters refer to the Y co-ordinate of the 'place_on' node.
48194818
spawn_by = "default:water",
48204819
-- ^ Node (or list of nodes) that the decoration only spawns next to.
48214820
-- ^ Checks two horizontal planes of neighbouring nodes (including diagonal neighbours),
4822-
-- ^ one plane at Y = surface and one plane at Y = surface = + 1.
4821+
-- ^ one plane level with the 'place_on' node and a plane one node above that.
48234822
num_spawn_by = 1,
48244823
-- ^ Number of spawn_by nodes that must be surrounding the decoration position to occur.
48254824
-- ^ If absent or -1, decorations occur next to any nodes.
48264825
flags = "liquid_surface, force_placement",
48274826
-- ^ Flags for all decoration types.
4828-
-- ^ "liquid_surface": Instead of placement on the highest solid surface
4829-
-- ^ in a mapchunk column, placement is on the highest liquid surface.
4830-
-- ^ Placement is disabled if solid nodes are found above the liquid surface.
4827+
-- ^ "liquid_surface": Instead of placement on the highest solid surface in
4828+
-- ^ a mapchunk column, placement is on the highest liquid surface. Placement
4829+
-- ^ is disabled if solid nodes are found above the liquid surface.
48314830
-- ^ "force_placement": Nodes other than "air" and "ignore" are replaced by the decoration.
48324831

48334832
----- Simple-type parameters
48344833
decoration = "default:grass",
48354834
-- ^ The node name used as the decoration.
48364835
-- ^ If instead a list of strings, a randomly selected node from the list is placed as the decoration.
48374836
height = 1,
4838-
-- ^ Number of nodes high the decoration is made.
4839-
-- ^ If height_max is not 0, this is the lower bound of the randomly selected height.
4837+
-- ^ Decoration height in nodes.
4838+
-- ^ If height_max is not 0, this is the lower limit of a randomly selected height.
48404839
height_max = 0,
4841-
-- ^ Number of nodes the decoration can be at maximum.
4840+
-- ^ Upper limit of the randomly selected height.
48424841
-- ^ If absent, the parameter 'height' is used as a constant.
48434842
param2 = 0,
4844-
-- ^ Param2 value of placed decoration node.
4845-
-- ^ If param2_max is not 0, this is the lower bound of the randomly selected param2.
4843+
-- ^ Param2 value of decoration nodes.
4844+
-- ^ If param2_max is not 0, this is the lower limit of a randomly selected param2.
48464845
param2_max = 0,
4847-
-- ^ Upper bound of the randomly selected param2.
4846+
-- ^ Upper limit of the randomly selected param2.
48484847
-- ^ If absent, the parameter 'param2' is used as a constant.
4848+
place_offset_y = 0,
4849+
-- ^ Y offset of the decoration base node relative to the standard
4850+
-- ^ base node position for simple decorations.
4851+
-- ^ Can be positive or negative. Default is 0.
4852+
-- ^ Ignored by 'y_min', 'y_max' and 'spawn_by' checks, which always refer
4853+
-- ^ to the 'place_on' node.
48494854

48504855
----- Schematic-type parameters
48514856
schematic = "foobar.mts",

Diff for: ‎src/mg_decoration.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
219219
if (c_decos.empty())
220220
return 0;
221221

222+
// Check for a negative place_offset_y causing placement below the voxelmanip
223+
if (p.Y + 1 + place_offset_y < vm->m_area.MinEdge.Y)
224+
return 0;
225+
222226
if (!canPlaceDecoration(vm, p))
223227
return 0;
224228

@@ -234,9 +238,10 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
234238

235239
const v3s16 &em = vm->m_area.getExtent();
236240
u32 vi = vm->m_area.index(p);
241+
vm->m_area.add_y(em, vi, place_offset_y);
242+
237243
for (int i = 0; i < height; i++) {
238244
vm->m_area.add_y(em, vi, 1);
239-
240245
content_t c = vm->m_data[vi].getContent();
241246
if (c != CONTENT_AIR && c != CONTENT_IGNORE &&
242247
!force_placement)
@@ -251,7 +256,8 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
251256

252257
int DecoSimple::getHeight()
253258
{
254-
return (deco_height_max > 0) ? deco_height_max : deco_height;
259+
return ((deco_height_max > 0) ? deco_height_max : deco_height)
260+
+ place_offset_y;
255261
}
256262

257263

Diff for: ‎src/mg_decoration.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Decoration : public ObjDef, public NodeResolver {
6969
NoiseParams np;
7070
std::vector<content_t> c_spawnby;
7171
s16 nspawnby;
72+
s16 place_offset_y = 0;
7273

7374
std::unordered_set<u8> biomes;
7475
};
@@ -96,7 +97,6 @@ class DecoSchematic : public Decoration {
9697
virtual int getHeight();
9798

9899
Rotation rotation;
99-
s16 place_offset_y = 0;
100100
Schematic *schematic = nullptr;
101101
};
102102

Diff for: ‎src/script/lua_api/l_mapgen.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -906,12 +906,13 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
906906
return 0;
907907
}
908908

909-
deco->name = getstringfield_default(L, index, "name", "");
910-
deco->fill_ratio = getfloatfield_default(L, index, "fill_ratio", 0.02);
911-
deco->y_min = getintfield_default(L, index, "y_min", -31000);
912-
deco->y_max = getintfield_default(L, index, "y_max", 31000);
913-
deco->nspawnby = getintfield_default(L, index, "num_spawn_by", -1);
914-
deco->sidelen = getintfield_default(L, index, "sidelen", 8);
909+
deco->name = getstringfield_default(L, index, "name", "");
910+
deco->fill_ratio = getfloatfield_default(L, index, "fill_ratio", 0.02);
911+
deco->y_min = getintfield_default(L, index, "y_min", -31000);
912+
deco->y_max = getintfield_default(L, index, "y_max", 31000);
913+
deco->nspawnby = getintfield_default(L, index, "num_spawn_by", -1);
914+
deco->place_offset_y = getintfield_default(L, index, "place_offset_y", 0);
915+
deco->sidelen = getintfield_default(L, index, "sidelen", 8);
915916
if (deco->sidelen <= 0) {
916917
errorstream << "register_decoration: sidelen must be "
917918
"greater than 0" << std::endl;
@@ -1024,8 +1025,6 @@ bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic
10241025
deco->rotation = (Rotation)getenumfield(L, index, "rotation",
10251026
ModApiMapgen::es_Rotation, ROTATE_0);
10261027

1027-
deco->place_offset_y = getintfield_default(L, index, "place_offset_y", 0);
1028-
10291028
StringMap replace_names;
10301029
lua_getfield(L, index, "replacements");
10311030
if (lua_istable(L, -1))

0 commit comments

Comments
 (0)
Please sign in to comment.