Skip to content

Commit ef285b2

Browse files
numberZeroparamat
authored andcommittedJul 11, 2017
Add 'plantlike_rooted' drawtype
Useful for underwater plants. Node consists of a base cube plus a plantlike extension that can pass through liquid nodes above without creating air bubbles or interfering with liquid flow. Uses paramtype2 'leveled', param2 defines height of plantlike extension.
1 parent f871852 commit ef285b2

File tree

9 files changed

+193
-121
lines changed

9 files changed

+193
-121
lines changed
 

Diff for: ‎doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ Look for examples in `games/minimal` or `games/minetest_game`.
860860
* `raillike`
861861
* `nodebox` -- See below. (**Experimental!**)
862862
* `mesh` -- use models for nodes
863+
* `plantlike_rooted`
863864

864865
`*_optional` drawtypes need less rendering time if deactivated (always client side).
865866

Diff for: ‎src/content_mapblock.cpp

+76-53
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,49 @@ MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector
7373
blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
7474
}
7575

76-
void MapblockMeshGenerator::useTile(int index, bool disable_backface_culling)
76+
void MapblockMeshGenerator::useTile(int index, u8 set_flags, u8 reset_flags, bool special)
7777
{
78-
getNodeTileN(n, p, index, data, tile);
78+
if (special)
79+
getSpecialTile(index, &tile, p == data->m_crack_pos_relative);
80+
else
81+
getNodeTileN(n, p, index, data, tile);
7982
if (!data->m_smooth_lighting)
8083
color = encode_light(light, f->light_source);
8184
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
82-
tile.layers[layer].material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
83-
if (disable_backface_culling)
84-
tile.layers[layer].material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
85+
tile.layers[layer].material_flags |= set_flags;
86+
tile.layers[layer].material_flags &= ~reset_flags;
8587
}
8688
}
8789

88-
void MapblockMeshGenerator::useDefaultTile(bool set_color)
90+
void MapblockMeshGenerator::getTile(v3s16 direction, TileSpec *tile)
8991
{
90-
getNodeTile(n, p, v3s16(0, 0, 0), data, tile);
91-
if (set_color && !data->m_smooth_lighting)
92-
color = encode_light(light, f->light_source);
92+
getNodeTile(n, p, direction, data, *tile);
9393
}
9494

95-
void MapblockMeshGenerator::getTile(const v3s16& direction, TileSpec &tile)
95+
/*!
96+
* Returns the i-th special tile for a map node.
97+
*/
98+
void MapblockMeshGenerator::getSpecialTile(int index, TileSpec *tile, bool apply_crack)
9699
{
97-
getNodeTile(n, p, direction, data, tile);
100+
*tile = f->special_tiles[index];
101+
TileLayer *top_layer = NULL;
102+
for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
103+
TileLayer *layer = &tile->layers[layernum];
104+
if (layer->texture_id == 0)
105+
continue;
106+
top_layer = layer;
107+
if (!layer->has_color)
108+
n.getColor(*f, &layer->color);
109+
}
110+
if (apply_crack)
111+
top_layer->material_flags |= MATERIAL_FLAG_CRACK;
98112
}
99113

100-
void MapblockMeshGenerator::drawQuad(v3f *coords, const v3s16 &normal)
114+
void MapblockMeshGenerator::drawQuad(v3f *coords, const v3s16 &normal,
115+
float vertical_tiling)
101116
{
102-
static const v2f tcoords[4] = {v2f(0, 0), v2f(1, 0), v2f(1, 1), v2f(0, 1)};
117+
const v2f tcoords[4] = {v2f(0.0, 0.0), v2f(1.0, 0.0),
118+
v2f(1.0, vertical_tiling), v2f(0.0, vertical_tiling)};
103119
video::S3DVertex vertices[4];
104120
bool shade_face = !f->light_source && (normal != v3s16(0, 0, 0));
105121
v3f normal2(normal.X, normal.Y, normal.Z);
@@ -358,27 +374,10 @@ void MapblockMeshGenerator::drawAutoLightedCuboid(aabb3f box, const f32 *txc,
358374
}
359375
}
360376

361-
/*!
362-
* Returns the i-th special tile for a map node.
363-
*/
364-
static TileSpec getSpecialTile(const ContentFeatures &f,
365-
const MapNode &n, u8 i)
366-
{
367-
TileSpec copy = f.special_tiles[i];
368-
for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
369-
TileLayer *layer = &copy.layers[layernum];
370-
if (layer->texture_id == 0)
371-
continue;
372-
if (!layer->has_color)
373-
n.getColor(f, &(layer->color));
374-
}
375-
return copy;
376-
}
377-
378377
void MapblockMeshGenerator::prepareLiquidNodeDrawing()
379378
{
380-
tile_liquid_top = getSpecialTile(*f, n, 0);
381-
tile_liquid = getSpecialTile(*f, n, 1);
379+
getSpecialTile(0, &tile_liquid_top);
380+
getSpecialTile(1, &tile_liquid);
382381

383382
MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(p.X, p.Y + 1, p.Z));
384383
c_flowing = nodedef->getId(f->liquid_alternative_flowing);
@@ -603,7 +602,7 @@ void MapblockMeshGenerator::drawLiquidNode()
603602

604603
void MapblockMeshGenerator::drawGlasslikeNode()
605604
{
606-
useDefaultTile();
605+
useTile(0, 0, 0);
607606

608607
for (int face = 0; face < 6; face++) {
609608
// Check this neighbor
@@ -638,7 +637,7 @@ void MapblockMeshGenerator::drawGlasslikeFramedNode()
638637
{
639638
TileSpec tiles[6];
640639
for (int face = 0; face < 6; face++)
641-
getTile(g_6dirs[face], tiles[face]);
640+
getTile(g_6dirs[face], &tiles[face]);
642641

643642
TileSpec glass_tiles[6];
644643
if (tiles[1].layers[0].texture &&
@@ -751,7 +750,7 @@ void MapblockMeshGenerator::drawGlasslikeFramedNode()
751750
// Internal liquid level has param2 range 0 .. 63,
752751
// convert it to -0.5 .. 0.5
753752
float vlev = (param2 / 63.0) * 2.0 - 1.0;
754-
tile = getSpecialTile(*f, n, 0);
753+
getSpecialTile(0, &tile);
755754
drawAutoLightedCuboid(aabb3f(-(nb[5] ? g : b),
756755
-(nb[4] ? g : b),
757756
-(nb[3] ? g : b),
@@ -764,7 +763,7 @@ void MapblockMeshGenerator::drawGlasslikeFramedNode()
764763
void MapblockMeshGenerator::drawAllfacesNode()
765764
{
766765
static const aabb3f box(-BS / 2, -BS / 2, -BS / 2, BS / 2, BS / 2, BS / 2);
767-
useDefaultTile(false);
766+
useTile(0, 0, 0);
768767
drawAutoLightedCuboid(box);
769768
}
770769

@@ -777,7 +776,7 @@ void MapblockMeshGenerator::drawTorchlikeNode()
777776
case DWM_YN: tileindex = 0; break; // floor
778777
default: tileindex = 2; // side (or invalid—should we care?)
779778
}
780-
useTile(tileindex, true);
779+
useTile(tileindex, MATERIAL_FLAG_CRACK_OVERLAY, MATERIAL_FLAG_BACKFACE_CULLING);
781780

782781
float size = BS / 2 * f->visual_scale;
783782
v3f vertices[4] = {
@@ -802,7 +801,7 @@ void MapblockMeshGenerator::drawTorchlikeNode()
802801
void MapblockMeshGenerator::drawSignlikeNode()
803802
{
804803
u8 wall = n.getWallMounted(nodedef);
805-
useTile(0, true);
804+
useTile(0, MATERIAL_FLAG_CRACK_OVERLAY, MATERIAL_FLAG_BACKFACE_CULLING);
806805
static const float offset = BS / 16;
807806
float size = BS / 2 * f->visual_scale;
808807
// Wall at X+ of node
@@ -829,8 +828,8 @@ void MapblockMeshGenerator::drawPlantlikeQuad(float rotation, float quad_offset,
829828
bool offset_top_only)
830829
{
831830
v3f vertices[4] = {
832-
v3f(-scale, -BS / 2 + scale * 2, 0),
833-
v3f( scale, -BS / 2 + scale * 2, 0),
831+
v3f(-scale, -BS / 2 + 2.0 * scale * plant_height, 0),
832+
v3f( scale, -BS / 2 + 2.0 * scale * plant_height, 0),
834833
v3f( scale, -BS / 2, 0),
835834
v3f(-scale, -BS / 2, 0),
836835
};
@@ -845,18 +844,18 @@ void MapblockMeshGenerator::drawPlantlikeQuad(float rotation, float quad_offset,
845844
vertices[i].rotateXZBy(rotation + rotate_degree);
846845
vertices[i] += offset;
847846
}
848-
drawQuad(vertices);
847+
drawQuad(vertices, v3s16(0, 0, 0), plant_height);
849848
}
850849

851-
void MapblockMeshGenerator::drawPlantlikeNode()
850+
void MapblockMeshGenerator::drawPlantlike()
852851
{
853-
useTile(0, false);
854852
draw_style = PLANT_STYLE_CROSS;
855853
scale = BS / 2 * f->visual_scale;
856854
offset = v3f(0, 0, 0);
857855
rotate_degree = 0;
858856
random_offset_Y = false;
859857
face_num = 0;
858+
plant_height = 1.0;
860859

861860
switch (f->param_type_2) {
862861
case CPT2_MESHOPTIONS:
@@ -876,6 +875,10 @@ void MapblockMeshGenerator::drawPlantlikeNode()
876875
rotate_degree = n.param2 * 2;
877876
break;
878877

878+
case CPT2_LEVELED:
879+
plant_height = n.param2 / 16.0;
880+
break;
881+
879882
default:
880883
break;
881884
}
@@ -913,6 +916,27 @@ void MapblockMeshGenerator::drawPlantlikeNode()
913916
}
914917
}
915918

919+
void MapblockMeshGenerator::drawPlantlikeNode()
920+
{
921+
useTile();
922+
drawPlantlike();
923+
}
924+
925+
void MapblockMeshGenerator::drawPlantlikeRootedNode()
926+
{
927+
useTile(0, MATERIAL_FLAG_CRACK_OVERLAY, 0, true);
928+
origin += v3f(0.0, BS, 0.0);
929+
p.Y++;
930+
if (data->m_smooth_lighting) {
931+
getSmoothLightFrame();
932+
} else {
933+
MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
934+
light = getInteriorLight(ntop, 1, nodedef);
935+
}
936+
drawPlantlike();
937+
p.Y--;
938+
}
939+
916940
void MapblockMeshGenerator::drawFirelikeQuad(float rotation, float opening_angle,
917941
float offset_h, float offset_v)
918942
{
@@ -933,7 +957,7 @@ void MapblockMeshGenerator::drawFirelikeQuad(float rotation, float opening_angle
933957

934958
void MapblockMeshGenerator::drawFirelikeNode()
935959
{
936-
useTile(0, false);
960+
useTile();
937961
scale = BS / 2 * f->visual_scale;
938962

939963
// Check for adjacent nodes
@@ -980,7 +1004,7 @@ void MapblockMeshGenerator::drawFirelikeNode()
9801004

9811005
void MapblockMeshGenerator::drawFencelikeNode()
9821006
{
983-
useDefaultTile(false);
1007+
useTile(0, 0, 0);
9841008
TileSpec tile_nocrack = tile;
9851009
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
9861010
tile_nocrack.layers[layer].material_flags &= ~MATERIAL_FLAG_CRACK;
@@ -1130,7 +1154,7 @@ void MapblockMeshGenerator::drawRaillikeNode()
11301154
angle = rail_kinds[code].angle;
11311155
}
11321156

1133-
useTile(tile_index, true);
1157+
useTile(tile_index, MATERIAL_FLAG_CRACK_OVERLAY, MATERIAL_FLAG_BACKFACE_CULLING);
11341158

11351159
static const float offset = BS / 64;
11361160
static const float size = BS / 2;
@@ -1171,7 +1195,7 @@ void MapblockMeshGenerator::drawNodeboxNode()
11711195
TileSpec tiles[6];
11721196
for (int face = 0; face < 6; face++) {
11731197
// Handles facedir rotation for textures
1174-
getTile(tile_dirs[face], tiles[face]);
1198+
getTile(tile_dirs[face], &tiles[face]);
11751199
}
11761200

11771201
// locate possible neighboring nodes to connect to
@@ -1228,7 +1252,7 @@ void MapblockMeshGenerator::drawMeshNode()
12281252

12291253
int mesh_buffer_count = mesh->getMeshBufferCount();
12301254
for (int j = 0; j < mesh_buffer_count; j++) {
1231-
useTile(j, false);
1255+
useTile(j);
12321256
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
12331257
video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices();
12341258
int vertex_count = buf->getVertexCount();
@@ -1269,13 +1293,17 @@ void MapblockMeshGenerator::drawNode()
12691293
else
12701294
light = getInteriorLight(n, 1, nodedef);
12711295
switch (f->drawtype) {
1296+
case NDT_NORMAL: break; // Drawn by MapBlockMesh
1297+
case NDT_AIRLIKE: break; // Not drawn at all
1298+
case NDT_LIQUID: break; // Drawn by MapBlockMesh
12721299
case NDT_FLOWINGLIQUID: drawLiquidNode(); break;
12731300
case NDT_GLASSLIKE: drawGlasslikeNode(); break;
12741301
case NDT_GLASSLIKE_FRAMED: drawGlasslikeFramedNode(); break;
12751302
case NDT_ALLFACES: drawAllfacesNode(); break;
12761303
case NDT_TORCHLIKE: drawTorchlikeNode(); break;
12771304
case NDT_SIGNLIKE: drawSignlikeNode(); break;
12781305
case NDT_PLANTLIKE: drawPlantlikeNode(); break;
1306+
case NDT_PLANTLIKE_ROOTED: drawPlantlikeRootedNode(); break;
12791307
case NDT_FIRELIKE: drawFirelikeNode(); break;
12801308
case NDT_FENCELIKE: drawFencelikeNode(); break;
12811309
case NDT_RAILLIKE: drawRaillikeNode(); break;
@@ -1296,11 +1324,6 @@ void MapblockMeshGenerator::generate()
12961324
for (p.X = 0; p.X < MAP_BLOCKSIZE; p.X++) {
12971325
n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
12981326
f = &nodedef->get(n);
1299-
// Solid nodes are drawn by MapBlockMesh
1300-
if (f->solidness != 0)
1301-
continue;
1302-
if (f->drawtype == NDT_AIRLIKE)
1303-
continue;
13041327
origin = intToFloat(p, BS);
13051328
drawNode();
13061329
}

Diff for: ‎src/content_mapblock.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ class MapblockMeshGenerator
6262
video::SColor blendLightColor(const v3f &vertex_pos);
6363
video::SColor blendLightColor(const v3f &vertex_pos, const v3f &vertex_normal);
6464

65-
void useTile(int index, bool disable_backface_culling);
66-
void useDefaultTile(bool set_color = true);
67-
void getTile(const v3s16 &direction, TileSpec &tile);
65+
void useTile(int index = 0, u8 set_flags = MATERIAL_FLAG_CRACK_OVERLAY,
66+
u8 reset_flags = 0, bool special = false);
67+
void getTile(v3s16 direction, TileSpec *tile);
68+
void getSpecialTile(int index, TileSpec *tile, bool apply_crack = false);
6869

6970
// face drawing
70-
void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0));
71+
void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0),
72+
float vertical_tiling = 1.0);
7173

7274
// cuboid drawing!
7375
void drawCuboid(const aabb3f &box, TileSpec *tiles, int tilecount,
@@ -111,9 +113,11 @@ class MapblockMeshGenerator
111113
int rotate_degree;
112114
bool random_offset_Y;
113115
int face_num;
116+
float plant_height;
114117

115118
void drawPlantlikeQuad(float rotation, float quad_offset = 0,
116119
bool offset_top_only = false);
120+
void drawPlantlike();
117121

118122
// firelike-specific
119123
void drawFirelikeQuad(float rotation, float opening_angle,
@@ -127,6 +131,7 @@ class MapblockMeshGenerator
127131
void drawTorchlikeNode();
128132
void drawSignlikeNode();
129133
void drawPlantlikeNode();
134+
void drawPlantlikeRootedNode();
130135
void drawFirelikeNode();
131136
void drawFencelikeNode();
132137
void drawRaillikeNode();

Diff for: ‎src/nodedef.cpp

+20-14
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,9 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
772772
case NDT_RAILLIKE:
773773
solidness = 0;
774774
break;
775+
case NDT_PLANTLIKE_ROOTED:
776+
solidness = 2;
777+
break;
775778
}
776779

777780
if (is_liquid) {
@@ -783,38 +786,41 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
783786
TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT;
784787
}
785788

786-
u32 tile_shader[6];
787-
for (u16 j = 0; j < 6; j++) {
788-
tile_shader[j] = shdsrc->getShader("nodes_shader",
789-
material_type, drawtype);
790-
}
789+
u32 tile_shader = shdsrc->getShader("nodes_shader", material_type, drawtype);
790+
791791
u8 overlay_material = material_type;
792792
if (overlay_material == TILE_MATERIAL_OPAQUE)
793793
overlay_material = TILE_MATERIAL_BASIC;
794794
else if (overlay_material == TILE_MATERIAL_LIQUID_OPAQUE)
795795
overlay_material = TILE_MATERIAL_LIQUID_TRANSPARENT;
796-
u32 overlay_shader[6];
797-
for (u16 j = 0; j < 6; j++) {
798-
overlay_shader[j] = shdsrc->getShader("nodes_shader",
799-
overlay_material, drawtype);
800-
}
796+
797+
u32 overlay_shader = shdsrc->getShader("nodes_shader", overlay_material, drawtype);
801798

802799
// Tiles (fill in f->tiles[])
803800
for (u16 j = 0; j < 6; j++) {
804-
fillTileAttribs(tsrc, &tiles[j].layers[0], &tdef[j], tile_shader[j],
801+
fillTileAttribs(tsrc, &tiles[j].layers[0], &tdef[j], tile_shader,
805802
tsettings.use_normal_texture,
806803
tdef[j].backface_culling, material_type);
807804
if (tdef_overlay[j].name != "")
808805
fillTileAttribs(tsrc, &tiles[j].layers[1], &tdef_overlay[j],
809-
overlay_shader[j], tsettings.use_normal_texture,
806+
overlay_shader, tsettings.use_normal_texture,
810807
tdef[j].backface_culling, overlay_material);
811808
}
812809

810+
u8 special_material = material_type;
811+
if (drawtype == NDT_PLANTLIKE_ROOTED) {
812+
if (waving == 1)
813+
special_material = TILE_MATERIAL_WAVING_PLANTS;
814+
else if (waving == 2)
815+
special_material = TILE_MATERIAL_WAVING_LEAVES;
816+
}
817+
u32 special_shader = shdsrc->getShader("nodes_shader", special_material, drawtype);
818+
813819
// Special tiles (fill in f->special_tiles[])
814820
for (u16 j = 0; j < CF_SPECIAL_COUNT; j++) {
815821
fillTileAttribs(tsrc, &special_tiles[j].layers[0], &tdef_spec[j],
816-
tile_shader[j], tsettings.use_normal_texture,
817-
tdef_spec[j].backface_culling, material_type);
822+
special_shader, tsettings.use_normal_texture,
823+
tdef_spec[j].backface_culling, special_material);
818824
}
819825

820826
if (param_type_2 == CPT2_COLOR ||

Diff for: ‎src/nodedef.h

+2
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ enum NodeDrawType
187187
NDT_GLASSLIKE_FRAMED_OPTIONAL,
188188
// Uses static meshes
189189
NDT_MESH,
190+
// Combined plantlike-on-solid
191+
NDT_PLANTLIKE_ROOTED,
190192
};
191193

192194
// Mesh options for NDT_PLANTLIKE with CPT2_MESHOPTIONS

Diff for: ‎src/script/common/c_content.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
362362
bool default_culling = true;
363363
switch (drawtype) {
364364
case NDT_PLANTLIKE:
365+
case NDT_PLANTLIKE_ROOTED:
365366
case NDT_FIRELIKE:
366367
default_tiling = false;
367368
// "break" is omitted here intentionaly, as PLANTLIKE

Diff for: ‎src/script/cpp_api/s_node.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct EnumString ScriptApiNode::es_DrawType[] =
4747
{NDT_FIRELIKE, "firelike"},
4848
{NDT_GLASSLIKE_FRAMED_OPTIONAL, "glasslike_framed_optional"},
4949
{NDT_MESH, "mesh"},
50+
{NDT_PLANTLIKE_ROOTED, "plantlike_rooted"},
5051
{0, NULL},
5152
};
5253

Diff for: ‎src/shader.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,8 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
618618
"NDT_NODEBOX",
619619
"NDT_GLASSLIKE_FRAMED",
620620
"NDT_FIRELIKE",
621-
"NDT_GLASSLIKE_FRAMED_OPTIONAL"
621+
"NDT_GLASSLIKE_FRAMED_OPTIONAL",
622+
"NDT_PLANTLIKE_ROOTED",
622623
};
623624

624625
for (int i = 0; i < 14; i++){

Diff for: ‎src/wieldmesh.cpp

+81-49
Original file line numberDiff line numberDiff line change
@@ -327,28 +327,45 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client)
327327
m_meshnode->setScale(
328328
def.wield_scale * WIELD_SCALE_FACTOR
329329
/ (BS * f.visual_scale));
330-
} else if (f.drawtype == NDT_AIRLIKE) {
331-
changeToMesh(nullptr);
332-
} else if (f.drawtype == NDT_PLANTLIKE) {
333-
setExtruded(tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
334-
def.wield_scale, tsrc,
335-
f.tiles[0].layers[0].animation_frame_count);
336-
} else if (f.drawtype == NDT_NORMAL || f.drawtype == NDT_ALLFACES) {
337-
setCube(f, def.wield_scale);
338330
} else {
339-
MeshMakeData mesh_make_data(client, false);
340-
MapNode mesh_make_node(id, 255, 0);
341-
mesh_make_data.fillSingleNode(&mesh_make_node);
342-
MapBlockMesh mapblock_mesh(&mesh_make_data, v3s16(0, 0, 0));
343-
scene::SMesh *mesh = cloneMesh(mapblock_mesh.getMesh());
344-
translateMesh(mesh, v3f(-BS, -BS, -BS));
345-
postProcessNodeMesh(mesh, f, m_enable_shaders, true,
346-
&m_material_type, &m_colors);
347-
changeToMesh(mesh);
348-
mesh->drop();
349-
m_meshnode->setScale(
350-
def.wield_scale * WIELD_SCALE_FACTOR
351-
/ (BS * f.visual_scale));
331+
switch (f.drawtype) {
332+
case NDT_AIRLIKE: {
333+
changeToMesh(nullptr);
334+
break;
335+
}
336+
case NDT_PLANTLIKE: {
337+
setExtruded(tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
338+
def.wield_scale, tsrc,
339+
f.tiles[0].layers[0].animation_frame_count);
340+
break;
341+
}
342+
case NDT_PLANTLIKE_ROOTED: {
343+
setExtruded(tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id),
344+
def.wield_scale, tsrc,
345+
f.special_tiles[0].layers[0].animation_frame_count);
346+
break;
347+
}
348+
case NDT_NORMAL:
349+
case NDT_ALLFACES: {
350+
setCube(f, def.wield_scale);
351+
break;
352+
}
353+
default: {
354+
MeshMakeData mesh_make_data(client, false);
355+
MapNode mesh_make_node(id, 255, 0);
356+
mesh_make_data.fillSingleNode(&mesh_make_node);
357+
MapBlockMesh mapblock_mesh(&mesh_make_data, v3s16(0, 0, 0));
358+
scene::SMesh *mesh = cloneMesh(mapblock_mesh.getMesh());
359+
translateMesh(mesh, v3f(-BS, -BS, -BS));
360+
postProcessNodeMesh(mesh, f, m_enable_shaders, true,
361+
&m_material_type, &m_colors);
362+
changeToMesh(mesh);
363+
mesh->drop();
364+
m_meshnode->setScale(
365+
def.wield_scale * WIELD_SCALE_FACTOR
366+
/ (BS * f.visual_scale));
367+
}
368+
}
352369
}
353370
u32 material_count = m_meshnode->getMaterialCount();
354371
for (u32 i = 0; i < material_count; ++i) {
@@ -446,35 +463,50 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
446463
if (f.mesh_ptr[0]) {
447464
mesh = cloneMesh(f.mesh_ptr[0]);
448465
scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
449-
} else if (f.drawtype == NDT_PLANTLIKE) {
450-
mesh = getExtrudedMesh(tsrc,
451-
tsrc->getTextureName(f.tiles[0].layers[0].texture_id));
452-
} else if (f.drawtype == NDT_NORMAL || f.drawtype == NDT_ALLFACES
453-
|| f.drawtype == NDT_LIQUID || f.drawtype == NDT_FLOWINGLIQUID) {
454-
scene::IMesh *cube = g_extrusion_mesh_cache->createCube();
455-
mesh = cloneMesh(cube);
456-
cube->drop();
457-
scaleMesh(mesh, v3f(1.2, 1.2, 1.2));
458466
} else {
459-
MeshMakeData mesh_make_data(client, false);
460-
MapNode mesh_make_node(id, 255, 0);
461-
mesh_make_data.fillSingleNode(&mesh_make_node);
462-
MapBlockMesh mapblock_mesh(&mesh_make_data, v3s16(0, 0, 0));
463-
mesh = cloneMesh(mapblock_mesh.getMesh());
464-
translateMesh(mesh, v3f(-BS, -BS, -BS));
465-
scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
466-
467-
u32 mc = mesh->getMeshBufferCount();
468-
for (u32 i = 0; i < mc; ++i) {
469-
video::SMaterial &material1 =
470-
mesh->getMeshBuffer(i)->getMaterial();
471-
video::SMaterial &material2 =
472-
mapblock_mesh.getMesh()->getMeshBuffer(i)->getMaterial();
473-
material1.setTexture(0, material2.getTexture(0));
474-
material1.setTexture(1, material2.getTexture(1));
475-
material1.setTexture(2, material2.getTexture(2));
476-
material1.setTexture(3, material2.getTexture(3));
477-
material1.MaterialType = material2.MaterialType;
467+
switch (f.drawtype) {
468+
case NDT_PLANTLIKE: {
469+
mesh = getExtrudedMesh(tsrc,
470+
tsrc->getTextureName(f.tiles[0].layers[0].texture_id));
471+
break;
472+
}
473+
case NDT_PLANTLIKE_ROOTED: {
474+
mesh = getExtrudedMesh(tsrc,
475+
tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id));
476+
break;
477+
}
478+
case NDT_NORMAL:
479+
case NDT_ALLFACES:
480+
case NDT_LIQUID:
481+
case NDT_FLOWINGLIQUID: {
482+
scene::IMesh *cube = g_extrusion_mesh_cache->createCube();
483+
mesh = cloneMesh(cube);
484+
cube->drop();
485+
scaleMesh(mesh, v3f(1.2, 1.2, 1.2));
486+
break;
487+
}
488+
default: {
489+
MeshMakeData mesh_make_data(client, false);
490+
MapNode mesh_make_node(id, 255, 0);
491+
mesh_make_data.fillSingleNode(&mesh_make_node);
492+
MapBlockMesh mapblock_mesh(&mesh_make_data, v3s16(0, 0, 0));
493+
mesh = cloneMesh(mapblock_mesh.getMesh());
494+
translateMesh(mesh, v3f(-BS, -BS, -BS));
495+
scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
496+
497+
u32 mc = mesh->getMeshBufferCount();
498+
for (u32 i = 0; i < mc; ++i) {
499+
video::SMaterial &material1 =
500+
mesh->getMeshBuffer(i)->getMaterial();
501+
video::SMaterial &material2 =
502+
mapblock_mesh.getMesh()->getMeshBuffer(i)->getMaterial();
503+
material1.setTexture(0, material2.getTexture(0));
504+
material1.setTexture(1, material2.getTexture(1));
505+
material1.setTexture(2, material2.getTexture(2));
506+
material1.setTexture(3, material2.getTexture(3));
507+
material1.MaterialType = material2.MaterialType;
508+
}
509+
}
478510
}
479511
}
480512

0 commit comments

Comments
 (0)
Please sign in to comment.