@@ -3287,7 +3287,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
32873287 const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos,
32883288 const PointedThing &pointed, const NodeMetadata *meta)
32893289{
3290- std::string prediction = selected_def.node_placement_prediction ;
3290+ const auto &prediction = selected_def.node_placement_prediction ;
3291+
32913292 const NodeDefManager *nodedef = client->ndef ();
32923293 ClientMap &map = client->getEnv ().getClientMap ();
32933294 MapNode node;
@@ -3357,8 +3358,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
33573358
33583359 if (!found) {
33593360 errorstream << " Node placement prediction failed for "
3360- << selected_def.name << " (places "
3361- << prediction
3361+ << selected_def.name << " (places " << prediction
33623362 << " ) - Name not known" << std::endl;
33633363 // Handle this as if prediction was empty
33643364 // Report to server
@@ -3369,9 +3369,14 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
33693369 const ContentFeatures &predicted_f = nodedef->get (id);
33703370
33713371 // Predict param2 for facedir and wallmounted nodes
3372+ // Compare core.item_place_node() for what the server does
33723373 u8 param2 = 0 ;
33733374
3374- if (predicted_f.param_type_2 == CPT2_WALLMOUNTED ||
3375+ const u8 place_param2 = selected_def.place_param2 ;
3376+
3377+ if (place_param2) {
3378+ param2 = place_param2;
3379+ } else if (predicted_f.param_type_2 == CPT2_WALLMOUNTED ||
33753380 predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED) {
33763381 v3s16 dir = nodepos - neighbourpos;
33773382
@@ -3382,9 +3387,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
33823387 } else {
33833388 param2 = dir.Z < 0 ? 5 : 4 ;
33843389 }
3385- }
3386-
3387- if (predicted_f.param_type_2 == CPT2_FACEDIR ||
3390+ } else if (predicted_f.param_type_2 == CPT2_FACEDIR ||
33883391 predicted_f.param_type_2 == CPT2_COLORED_FACEDIR) {
33893392 v3s16 dir = nodepos - floatToInt (client->getEnv ().getLocalPlayer ()->getPosition (), BS);
33903393
@@ -3395,11 +3398,9 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
33953398 }
33963399 }
33973400
3398- assert (param2 <= 5 );
3399-
3400- // Check attachment if node is in group attached_node
3401- if (((ItemGroupList) predicted_f.groups )[" attached_node" ] != 0 ) {
3402- static v3s16 wallmounted_dirs[8 ] = {
3401+ // Check attachment if node is in group attached_node
3402+ if (itemgroup_get (predicted_f.groups , " attached_node" ) != 0 ) {
3403+ const static v3s16 wallmounted_dirs[8 ] = {
34033404 v3s16 (0 , 1 , 0 ),
34043405 v3s16 (0 , -1 , 0 ),
34053406 v3s16 (1 , 0 , 0 ),
@@ -3424,11 +3425,11 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
34243425 }
34253426
34263427 // Apply color
3427- if ((predicted_f.param_type_2 == CPT2_COLOR
3428+ if (!place_param2 && (predicted_f.param_type_2 == CPT2_COLOR
34283429 || predicted_f.param_type_2 == CPT2_COLORED_FACEDIR
34293430 || predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED)) {
3430- const std::string &indexstr = selected_item.metadata .getString (
3431- " palette_index" , 0 );
3431+ const auto &indexstr = selected_item.metadata .
3432+ getString ( " palette_index" , 0 );
34323433 if (!indexstr.empty ()) {
34333434 s32 index = mystoi (indexstr);
34343435 if (predicted_f.param_type_2 == CPT2_COLOR) {
@@ -3468,11 +3469,10 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
34683469 soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed ;
34693470 return false ;
34703471 }
3471- } catch (InvalidPositionException &e) {
3472+ } catch (const InvalidPositionException &e) {
34723473 errorstream << " Node placement prediction failed for "
34733474 << selected_def.name << " (places "
3474- << prediction
3475- << " ) - Position not loaded" << std::endl;
3475+ << prediction << " ) - Position not loaded" << std::endl;
34763476 soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed ;
34773477 return false ;
34783478 }
0 commit comments