Skip to content

Commit b0523ad

Browse files
committedOct 4, 2015
Add new ContentParamType2 "CPT2_DEGROTATE"
This might break some mods, but it is important for all uses of the param2 to be documented. This doesn't need a serialisation version or network protocol version change, as old clients will still work on new servers, and it is bearable to have new clients getting non rotated plants on old servers.
1 parent 5130dbc commit b0523ad

File tree

4 files changed

+58
-51
lines changed

4 files changed

+58
-51
lines changed
 

‎doc/lua_api.txt

+4
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ node definition:
538538
0 = y+ 1 = z+ 2 = z- 3 = x+ 4 = x- 5 = y-
539539
facedir's two less significant bits are rotation around the axis
540540
paramtype2 == "leveled"
541+
paramtype2 == "degrotate"
542+
^ The rotation of this node is stored in param2. Plants are rotated this way.
543+
Values range 0 - 179. The value stored in param2 is multiplied by two to
544+
get the actual rotation of the node.
541545
collision_box = {
542546
type = "fixed",
543547
fixed = {

‎src/content_mapblock.cpp

+51-51
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ void makeCuboid(MeshCollector *collector, const aabb3f &box,
5050

5151
v3f min = box.MinEdge;
5252
v3f max = box.MaxEdge;
53-
54-
55-
53+
54+
55+
5656
if(txc == NULL) {
5757
static const f32 txc_default[24] = {
5858
0,0,1,1,
@@ -350,7 +350,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
350350
*/
351351
if(top_is_same_liquid)
352352
continue;
353-
353+
354354
video::S3DVertex vertices[4] =
355355
{
356356
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
@@ -383,7 +383,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
383383
content_t c_source = nodedef->getId(f.liquid_alternative_source);
384384
if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
385385
top_is_same_liquid = true;
386-
386+
387387
u16 l = 0;
388388
// If this liquid emits light and doesn't contain light, draw
389389
// it at what it emits, for an increased effect
@@ -399,7 +399,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
399399
else
400400
l = getInteriorLight(n, 0, nodedef);
401401
video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
402-
402+
403403
u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
404404

405405
// Neighbor liquid levels (key = relative position)
@@ -451,15 +451,15 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
451451
n2.getContent() == c_flowing)
452452
flags |= neighborflag_top_is_same_liquid;
453453
}
454-
454+
455455
neighbor_levels[neighbor_dirs[i]] = level;
456456
neighbor_contents[neighbor_dirs[i]] = content;
457457
neighbor_flags[neighbor_dirs[i]] = flags;
458458
}
459459

460460
// Corner heights (average between four liquids)
461461
f32 corner_levels[4];
462-
462+
463463
v3s16 halfdirs[4] = {
464464
v3s16(0,0,0),
465465
v3s16(1,0,0),
@@ -539,14 +539,14 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
539539

540540
content_t neighbor_content = neighbor_contents[dir];
541541
const ContentFeatures &n_feat = nodedef->get(neighbor_content);
542-
542+
543543
// Don't draw face if neighbor is blocking the view
544544
if(n_feat.solidness == 2)
545545
continue;
546-
546+
547547
bool neighbor_is_same_liquid = (neighbor_content == c_source
548548
|| neighbor_content == c_flowing);
549-
549+
550550
// Don't draw any faces if neighbor same is liquid and top is
551551
// same liquid
552552
if(neighbor_is_same_liquid == true
@@ -558,15 +558,15 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
558558
const TileSpec *current_tile = &tile_liquid;
559559
if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
560560
current_tile = &tile_liquid_bfculled;
561-
561+
562562
video::S3DVertex vertices[4] =
563563
{
564564
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
565565
video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
566566
video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
567567
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
568568
};
569-
569+
570570
/*
571571
If our topside is liquid, set upper border of face
572572
at upper border of node
@@ -584,7 +584,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
584584
vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
585585
vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
586586
}
587-
587+
588588
/*
589589
If neighbor is liquid, lower border of face is corner
590590
liquid levels
@@ -603,7 +603,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
603603
vertices[0].Pos.Y = -0.5*BS;
604604
vertices[1].Pos.Y = -0.5*BS;
605605
}
606-
606+
607607
for(s32 j=0; j<4; j++)
608608
{
609609
if(dir == v3s16(0,0,1))
@@ -614,7 +614,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
614614
vertices[j].Pos.rotateXZBy(90);
615615
if(dir == v3s16(1,0,-0))
616616
vertices[j].Pos.rotateXZBy(-90);
617-
617+
618618
// Do this to not cause glitches when two liquids are
619619
// side-by-side
620620
/*if(neighbor_is_same_liquid == false){
@@ -629,11 +629,11 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
629629
// Add to mesh collector
630630
collector.append(*current_tile, vertices, 4, indices, 6);
631631
}
632-
632+
633633
/*
634634
Generate top side, if appropriate
635635
*/
636-
636+
637637
if(top_is_same_liquid == false)
638638
{
639639
video::S3DVertex vertices[4] =
@@ -643,7 +643,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
643643
video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
644644
video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
645645
};
646-
646+
647647
// To get backface culling right, the vertices need to go
648648
// clockwise around the front of the face. And we happened to
649649
// calculate corner levels in exact reverse order.
@@ -657,8 +657,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
657657
vertices[i].Pos.Y += corner_levels[j];
658658
vertices[i].Pos += intToFloat(p, BS);
659659
}
660-
661-
// Default downwards-flowing texture animation goes from
660+
661+
// Default downwards-flowing texture animation goes from
662662
// -Z towards +Z, thus the direction is +Z.
663663
// Rotate texture to make animation go in flow direction
664664
// Positive if liquid moves towards +Z
@@ -721,7 +721,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
721721
video::S3DVertex(BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 0,0),
722722
video::S3DVertex(-BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 1,0),
723723
};
724-
724+
725725
// Rotations in the g_6dirs format
726726
if(j == 0) // Z+
727727
for(u16 i=0; i<4; i++)
@@ -770,7 +770,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
770770
TileSpec tiles[6];
771771
for (i = 0; i < 6; i++)
772772
tiles[i] = getNodeTile(n, p, dirs[i], data);
773-
773+
774774
TileSpec glass_tiles[6];
775775
if (tiles[1].texture && tiles[2].texture && tiles[3].texture) {
776776
glass_tiles[0] = tiles[2];
@@ -781,21 +781,21 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
781781
glass_tiles[5] = tiles[1];
782782
} else {
783783
for (i = 0; i < 6; i++)
784-
glass_tiles[i] = tiles[1];
784+
glass_tiles[i] = tiles[1];
785785
}
786-
786+
787787
u8 param2 = n.getParam2();
788788
bool H_merge = ! bool(param2 & 128);
789789
bool V_merge = ! bool(param2 & 64);
790790
param2 = param2 & 63;
791-
791+
792792
u16 l = getInteriorLight(n, 1, nodedef);
793793
video::SColor c = MapBlock_LightColor(255, l, f.light_source);
794794
v3f pos = intToFloat(p, BS);
795795
static const float a = BS / 2;
796796
static const float g = a - 0.003;
797797
static const float b = .876 * ( BS / 2 );
798-
798+
799799
static const aabb3f frame_edges[12] = {
800800
aabb3f( b, b,-a, a, a, a), // y+
801801
aabb3f(-a, b,-a,-b, a, a), // y+
@@ -818,16 +818,16 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
818818
aabb3f(-g,-g, g, g, g, g), // z+
819819
aabb3f(-g,-g,-g, g, g,-g) // z-
820820
};
821-
821+
822822
// table of node visible faces, 0 = invisible
823823
int visible_faces[6] = {0,0,0,0,0,0};
824-
824+
825825
// table of neighbours, 1 = same type, checked with g_26dirs
826826
int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
827-
827+
828828
// g_26dirs to check when only horizontal merge is allowed
829829
int nb_H_dirs[8] = {0,2,3,5,10,11,12,13};
830-
830+
831831
content_t current = n.getContent();
832832
content_t n2c;
833833
MapNode n2;
@@ -845,14 +845,14 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
845845
n2 = data->m_vmanip.getNodeNoEx(n2p);
846846
n2c = n2.getContent();
847847
if (n2c == current || n2c == CONTENT_IGNORE)
848-
nb[4] = 1;
848+
nb[4] = 1;
849849
} else if (H_merge && !V_merge) {
850850
for(i = 0; i < 8; i++) {
851851
n2p = blockpos_nodes + p + g_26dirs[nb_H_dirs[i]];
852852
n2 = data->m_vmanip.getNodeNoEx(n2p);
853853
n2c = n2.getContent();
854854
if (n2c == current || n2c == CONTENT_IGNORE)
855-
nb[nb_H_dirs[i]] = 1;
855+
nb[nb_H_dirs[i]] = 1;
856856
}
857857
} else if (H_merge && V_merge) {
858858
for(i = 0; i < 18; i++) {
@@ -878,7 +878,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
878878
visible_faces[i] = 1;
879879
}
880880
}
881-
881+
882882
if (!H_merge) {
883883
visible_faces[2] = 1;
884884
visible_faces[3] = 1;
@@ -893,7 +893,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
893893
visible_faces[i] = 1;
894894
}
895895
}
896-
896+
897897
static const u8 nb_triplet[12*3] = {
898898
1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
899899
2,0,11, 2,3,13, 5,0,10, 5,3,12,
@@ -1010,7 +1010,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
10101010
case NDT_TORCHLIKE:
10111011
{
10121012
v3s16 dir = n.getWallMountedDir(nodedef);
1013-
1013+
10141014
u8 tileindex = 0;
10151015
if(dir == v3s16(0,-1,0)){
10161016
tileindex = 0; // floor
@@ -1070,7 +1070,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
10701070

10711071
u16 l = getInteriorLight(n, 0, nodedef);
10721072
video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1073-
1073+
10741074
float d = (float)BS/16;
10751075
float s = BS/2*f.visual_scale;
10761076
// Wall at X+ of node
@@ -1113,7 +1113,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
11131113

11141114
u16 l = getInteriorLight(n, 1, nodedef);
11151115
video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1116-
1116+
11171117
float s = BS / 2 * f.visual_scale;
11181118

11191119
for (int j = 0; j < 2; j++)
@@ -1125,16 +1125,16 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
11251125
video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
11261126
video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
11271127
};
1128+
float rotate_degree = 0;
1129+
if (f.param_type_2 == CPT2_DEGROTATE)
1130+
rotate_degree = n.param2 * 2;
11281131

1129-
if(j == 0)
1130-
{
1132+
if (j == 0) {
11311133
for(u16 i = 0; i < 4; i++)
1132-
vertices[i].Pos.rotateXZBy(46 + n.param2 * 2);
1133-
}
1134-
else if(j == 1)
1135-
{
1134+
vertices[i].Pos.rotateXZBy(46 + rotate_degree);
1135+
} else if (j == 1) {
11361136
for(u16 i = 0; i < 4; i++)
1137-
vertices[i].Pos.rotateXZBy(-44 + n.param2 * 2);
1137+
vertices[i].Pos.rotateXZBy(-44 + rotate_degree);
11381138
}
11391139

11401140
for (int i = 0; i < 4; i++)
@@ -1507,7 +1507,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
15071507
v3s16(0, 0, -1)
15081508
};
15091509
TileSpec tiles[6];
1510-
1510+
15111511
u16 l = getInteriorLight(n, 1, nodedef);
15121512
video::SColor c = MapBlock_LightColor(255, l, f.light_source);
15131513

@@ -1526,7 +1526,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
15261526
aabb3f box = *i;
15271527
box.MinEdge += pos;
15281528
box.MaxEdge += pos;
1529-
1529+
15301530
f32 temp;
15311531
if (box.MinEdge.X > box.MaxEdge.X)
15321532
{
@@ -1615,7 +1615,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
16151615
break;}
16161616
}
16171617
}
1618-
1618+
16191619
/*
16201620
Caused by incorrect alpha blending, selection mesh needs to be created as
16211621
last element to ensure it gets blended correct over nodes with alpha channel
@@ -1643,15 +1643,15 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
16431643
u16 l = 0;
16441644
u16 l1 = 0;
16451645
for (u8 i = 0; i < 7; i++) {
1646-
MapNode n1 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dirs[i]);
1646+
MapNode n1 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dirs[i]);
16471647
l1 = getInteriorLight(n1, -4, nodedef);
1648-
if (l1 > l)
1648+
if (l1 > l)
16491649
l = l1;
16501650
}
16511651
video::SColor c = MapBlock_LightColor(255, l, 0);
16521652
data->m_highlight_mesh_color = c;
16531653
std::vector<aabb3f> boxes = n.getSelectionBoxes(nodedef);
1654-
TileSpec h_tile;
1654+
TileSpec h_tile;
16551655
h_tile.material_flags |= MATERIAL_FLAG_HIGHLIGHTED;
16561656
h_tile.texture = tsrc->getTextureForMesh("halo.png",&h_tile.texture_id);
16571657
v3f pos = intToFloat(p, BS);

‎src/nodedef.h

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ enum ContentParamType2
6363
CPT2_WALLMOUNTED,
6464
// Block level like FLOWINGLIQUID
6565
CPT2_LEVELED,
66+
// 2D rotation for things like plants
67+
CPT2_DEGROTATE,
6668
};
6769

6870
enum LiquidType

‎src/script/cpp_api/s_node.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct EnumString ScriptApiNode::es_ContentParamType2[] =
5757
{CPT2_FACEDIR, "facedir"},
5858
{CPT2_WALLMOUNTED, "wallmounted"},
5959
{CPT2_LEVELED, "leveled"},
60+
{CPT2_DEGROTATE, "degrotate"},
6061
{0, NULL},
6162
};
6263

0 commit comments

Comments
 (0)
Please sign in to comment.