Skip to content

Commit 865f380

Browse files
committedMay 24, 2013
Predict param2 of facedir nodes and attachment of attached_node nodes
1 parent 3abbe7e commit 865f380

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed
 

‎src/game.cpp

+28-3
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ void nodePlacementPrediction(Client &client,
847847
<<") - Name not known"<<std::endl;
848848
return;
849849
}
850-
// Predict param2
850+
// Predict param2 for facedir and wallmounted nodes
851851
u8 param2 = 0;
852852
if(nodedef->get(id).param_type_2 == CPT2_WALLMOUNTED){
853853
v3s16 dir = nodepos - neighbourpos;
@@ -859,8 +859,33 @@ void nodePlacementPrediction(Client &client,
859859
param2 = dir.Z < 0 ? 5 : 4;
860860
}
861861
}
862-
// TODO: Facedir prediction
863-
// TODO: If predicted node is in attached_node group, check attachment
862+
if(nodedef->get(id).param_type_2 == CPT2_FACEDIR){
863+
v3s16 dir = nodepos - floatToInt(client.getEnv().getLocalPlayer()->getPosition(), BS);
864+
if(abs(dir.X) > abs(dir.Z)){
865+
param2 = dir.X < 0 ? 3 : 1;
866+
} else {
867+
param2 = dir.Z < 0 ? 2 : 0;
868+
}
869+
}
870+
assert(param2 >= 0 && param2 <= 5);
871+
//Check attachment if node is in group attached_node
872+
if(((ItemGroupList) nodedef->get(id).groups)["attached_node"] != 0){
873+
static v3s16 wallmounted_dirs[8] = {
874+
v3s16(0,1,0),
875+
v3s16(0,-1,0),
876+
v3s16(1,0,0),
877+
v3s16(-1,0,0),
878+
v3s16(0,0,1),
879+
v3s16(0,0,-1),
880+
};
881+
v3s16 pp;
882+
if(nodedef->get(id).param_type_2 == CPT2_WALLMOUNTED)
883+
pp = p + wallmounted_dirs[param2];
884+
else
885+
pp = p + v3s16(0,-1,0);
886+
if(!nodedef->get(map.getNode(pp)).walkable)
887+
return;
888+
}
864889
// Add node to client map
865890
MapNode n(id, 0, param2);
866891
try{

0 commit comments

Comments
 (0)
Please sign in to comment.