Skip to content

Commit

Permalink
Add wallmounted support for plantlike and plantlike_rooted nodes (#11379
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Wuzzy2 committed Jul 15, 2021
1 parent 68143ed commit f4d8cc0
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 7 deletions.
3 changes: 2 additions & 1 deletion builtin/game/falling.lua
Expand Up @@ -157,7 +157,8 @@ core.register_entity(":__builtin:falling_node", {
if euler then
self.object:set_rotation(euler)
end
elseif (def.paramtype2 == "wallmounted" or def.paramtype2 == "colorwallmounted" or def.drawtype == "signlike") then
elseif (def.drawtype ~= "plantlike" and def.drawtype ~= "plantlike_rooted" and
(def.paramtype2 == "wallmounted" or def.paramtype2 == "colorwallmounted" or def.drawtype == "signlike")) then
local rot = node.param2 % 8
if (def.drawtype == "signlike" and def.paramtype2 ~= "wallmounted" and def.paramtype2 ~= "colorwallmounted") then
-- Change rotation to "floor" by default for non-wallmounted paramtype2
Expand Down
10 changes: 8 additions & 2 deletions doc/lua_api.txt
Expand Up @@ -1022,7 +1022,8 @@ The function of `param2` is determined by `paramtype2` in node definition.
to access/manipulate the content of this field
* Bit 3: If set, liquid is flowing downwards (no graphical effect)
* `paramtype2 = "wallmounted"`
* Supported drawtypes: "torchlike", "signlike", "normal", "nodebox", "mesh"
* Supported drawtypes: "torchlike", "signlike", "plantlike",
"plantlike_rooted", "normal", "nodebox", "mesh"
* The rotation of the node is stored in `param2`
* You can make this value by using `minetest.dir_to_wallmounted()`
* Values range 0 - 5
Expand Down Expand Up @@ -1198,7 +1199,12 @@ Look for examples in `games/devtest` or `games/minetest_game`.
* `plantlike_rooted`
* Enables underwater `plantlike` without air bubbles around the nodes.
* Consists of a base cube at the co-ordinates of the node plus a
`plantlike` extension above with a height of `param2 / 16` nodes.
`plantlike` extension above
* If `paramtype2="leveled", the `plantlike` extension has a height
of `param2 / 16` nodes, otherwise it's the height of 1 node
* If `paramtype2="wallmounted"`, the `plantlike` extension
will be at one of the corresponding 6 sides of the base cube.
Also, the base cube rotates like a `normal` cube would
* The `plantlike` extension visually passes through any nodes above the
base cube without affecting them.
* The base cube texture tiles are defined as normal, the `plantlike`
Expand Down
30 changes: 30 additions & 0 deletions games/devtest/mods/testnodes/drawtypes.lua
Expand Up @@ -208,6 +208,19 @@ minetest.register_node("testnodes:plantlike_waving", {
groups = { dig_immediate = 3 },
})

minetest.register_node("testnodes:plantlike_wallmounted", {
description = S("Wallmounted Plantlike Drawtype Test Node"),
drawtype = "plantlike",
paramtype = "light",
paramtype2 = "wallmounted",
tiles = { "testnodes_plantlike_wallmounted.png" },
leveled = 1,


walkable = false,
sunlight_propagates = true,
groups = { dig_immediate = 3 },
})


-- param2 will rotate
Expand Down Expand Up @@ -320,6 +333,20 @@ minetest.register_node("testnodes:plantlike_rooted", {
groups = { dig_immediate = 3 },
})

minetest.register_node("testnodes:plantlike_rooted_wallmounted", {
description = S("Wallmounted Rooted Plantlike Drawtype Test Node"),
drawtype = "plantlike_rooted",
paramtype = "light",
paramtype2 = "wallmounted",
tiles = {
"testnodes_plantlike_rooted_base.png",
"testnodes_plantlike_rooted_base.png",
"testnodes_plantlike_rooted_base_side_wallmounted.png" },
special_tiles = { "testnodes_plantlike_rooted_wallmounted.png" },

groups = { dig_immediate = 3 },
})

minetest.register_node("testnodes:plantlike_rooted_waving", {
description = S("Waving Rooted Plantlike Drawtype Test Node"),
drawtype = "plantlike_rooted",
Expand Down Expand Up @@ -588,6 +615,9 @@ scale("allfaces_optional_waving",
scale("plantlike",
S("Double-sized Plantlike Drawtype Test Node"),
S("Half-sized Plantlike Drawtype Test Node"))
scale("plantlike_wallmounted",
S("Double-sized Wallmounted Plantlike Drawtype Test Node"),
S("Half-sized Wallmounted Plantlike Drawtype Test Node"))
scale("torchlike_wallmounted",
S("Double-sized Wallmounted Torchlike Drawtype Test Node"),
S("Half-sized Wallmounted Torchlike Drawtype Test Node"))
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 46 additions & 2 deletions src/client/content_mapblock.cpp
Expand Up @@ -958,10 +958,38 @@ void MapblockMeshGenerator::drawPlantlikeQuad(float rotation, float quad_offset,
vertex.rotateXZBy(rotation + rotate_degree);
vertex += offset;
}

u8 wall = n.getWallMounted(nodedef);
if (wall != DWM_YN) {
for (v3f &vertex : vertices) {
switch (wall) {
case DWM_YP:
vertex.rotateYZBy(180);
vertex.rotateXZBy(180);
break;
case DWM_XP:
vertex.rotateXYBy(90);
break;
case DWM_XN:
vertex.rotateXYBy(-90);
vertex.rotateYZBy(180);
break;
case DWM_ZP:
vertex.rotateYZBy(-90);
vertex.rotateXYBy(90);
break;
case DWM_ZN:
vertex.rotateYZBy(90);
vertex.rotateXYBy(90);
break;
}
}
}

drawQuad(vertices, v3s16(0, 0, 0), plant_height);
}

void MapblockMeshGenerator::drawPlantlike()
void MapblockMeshGenerator::drawPlantlike(bool is_rooted)
{
draw_style = PLANT_STYLE_CROSS;
scale = BS / 2 * f->visual_scale;
Expand Down Expand Up @@ -998,6 +1026,22 @@ void MapblockMeshGenerator::drawPlantlike()
break;
}

if (is_rooted) {
u8 wall = n.getWallMounted(nodedef);
switch (wall) {
case DWM_YP:
offset.Y += BS*2;
break;
case DWM_XN:
case DWM_XP:
case DWM_ZN:
case DWM_ZP:
offset.X += -BS;
offset.Y += BS;
break;
}
}

switch (draw_style) {
case PLANT_STYLE_CROSS:
drawPlantlikeQuad(46);
Expand Down Expand Up @@ -1048,7 +1092,7 @@ void MapblockMeshGenerator::drawPlantlikeRootedNode()
MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
light = LightPair(getInteriorLight(ntop, 1, nodedef));
}
drawPlantlike();
drawPlantlike(true);
p.Y--;
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/content_mapblock.h
Expand Up @@ -146,7 +146,7 @@ class MapblockMeshGenerator

void drawPlantlikeQuad(float rotation, float quad_offset = 0,
bool offset_top_only = false);
void drawPlantlike();
void drawPlantlike(bool is_rooted = false);

// firelike-specific
void drawFirelikeQuad(float rotation, float opening_angle,
Expand Down
4 changes: 3 additions & 1 deletion src/mapnode.cpp
Expand Up @@ -161,7 +161,9 @@ u8 MapNode::getWallMounted(const NodeDefManager *nodemgr) const
if (f.param_type_2 == CPT2_WALLMOUNTED ||
f.param_type_2 == CPT2_COLORED_WALLMOUNTED) {
return getParam2() & 0x07;
} else if (f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_TORCHLIKE) {
} else if (f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_TORCHLIKE ||
f.drawtype == NDT_PLANTLIKE ||
f.drawtype == NDT_PLANTLIKE_ROOTED) {
return 1;
}
return 0;
Expand Down

0 comments on commit f4d8cc0

Please sign in to comment.