Skip to content

Commit

Permalink
Simple deco: Allow setting param2 value on placement
Browse files Browse the repository at this point in the history
Schematics can already be placed with a param2 value, but not
simple 1-node plant decorations of the simple type.

This adds a `param2` field to the simple deco type that is
checked to be between 0 and 255, and put to the placed node
at mapgen.

This can be used to put a degrotate value in, or e.g. a fill
value for leveltype nodes, or a place_param2 value at mapgen
placement, or vary the shape of meshoptions plantlike drawtype.
  • Loading branch information
sofar authored and paramat committed Dec 7, 2016
1 parent 075833e commit 2e69711
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion doc/lua_api.txt
Expand Up @@ -4040,8 +4040,10 @@ The Biome API is still in an experimental phase and subject to change.
-- ^ Number of nodes high the decoration is made.
-- ^ If height_max is not 0, this is the lower bound of the randomly selected height.
height_max = 0,
-- ^ Number of nodes the decoration can be at maximum.
-- ^ Number of nodes the decoration can be at maximum.
-- ^ If absent, the parameter 'height' is used as a constant.
param2 = 0,
-- ^ Param2 value of placed decoration node.

----- Schematic-type parameters
schematic = "foobar.mts",
Expand Down
2 changes: 1 addition & 1 deletion src/mg_decoration.cpp
Expand Up @@ -315,7 +315,7 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
!force_placement)
break;

vm->m_data[vi] = MapNode(c_place);
vm->m_data[vi] = MapNode(c_place, 0, deco_param2);
}

return 1;
Expand Down
1 change: 1 addition & 0 deletions src/mg_decoration.h
Expand Up @@ -100,6 +100,7 @@ class DecoSimple : public Decoration {
std::vector<content_t> c_decos;
s16 deco_height;
s16 deco_height_max;
u8 deco_param2;
};

class DecoSchematic : public Decoration {
Expand Down
7 changes: 7 additions & 0 deletions src/script/lua_api/l_mapgen.cpp
Expand Up @@ -975,6 +975,7 @@ bool read_deco_simple(lua_State *L, DecoSimple *deco)

deco->deco_height = getintfield_default(L, index, "height", 1);
deco->deco_height_max = getintfield_default(L, index, "height_max", 0);
deco->deco_param2 = getintfield_default(L, index, "param2", 0);

if (deco->deco_height <= 0) {
errorstream << "register_decoration: simple decoration height"
Expand All @@ -990,6 +991,12 @@ bool read_deco_simple(lua_State *L, DecoSimple *deco)
return false;
}

if ((deco->deco_param2 < 0) || (deco->deco_param2 > 255)) {
errorstream << "register_decoration: param2 out of bounds (0-255)"
<< std::endl;
return false;
}

return true;
}

Expand Down

0 comments on commit 2e69711

Please sign in to comment.