]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/game.cpp
Remove unnecessary checks before delete (#9500)
[dragonfireclient.git] / src / client / game.cpp
index 5bf41bcd6efd0bb99ed83bdacc1d92923849f29e..32291c7ef6b48430b15330f51c20a6c851b2362a 100644 (file)
@@ -55,7 +55,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "particles.h"
 #include "porting.h"
 #include "profiler.h"
-#include "quicktune_shortcutter.h"
 #include "raycast.h"
 #include "server.h"
 #include "settings.h"
@@ -65,6 +64,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/basic_macros.h"
 #include "util/directiontables.h"
 #include "util/pointedthing.h"
+#include "util/quicktune_shortcutter.h"
 #include "irrlicht_changes/static_text.h"
 #include "version.h"
 #include "script/scripting_client.h"
@@ -184,7 +184,7 @@ struct LocalFormspecHandler : public TextDest
                        return;
                }
 
-               if (m_client && m_client->moddingEnabled())
+               if (m_client && m_client->modsLoaded())
                        m_client->getScript()->on_formspec_input(m_formname, fields);
        }
 
@@ -413,6 +413,8 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
        CachedPixelShaderSetting<float, 3> m_eye_position_pixel;
        CachedVertexShaderSetting<float, 3> m_eye_position_vertex;
        CachedPixelShaderSetting<float, 3> m_minimap_yaw;
+       CachedPixelShaderSetting<float, 3> m_camera_offset_pixel;
+       CachedPixelShaderSetting<float, 3> m_camera_offset_vertex;
        CachedPixelShaderSetting<SamplerLayer_t> m_base_texture;
        CachedPixelShaderSetting<SamplerLayer_t> m_normal_texture;
        CachedPixelShaderSetting<SamplerLayer_t> m_texture_flags;
@@ -445,6 +447,8 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                m_eye_position_pixel("eyePosition"),
                m_eye_position_vertex("eyePosition"),
                m_minimap_yaw("yawVec"),
+               m_camera_offset_pixel("cameraOffset"),
+               m_camera_offset_vertex("cameraOffset"),
                m_base_texture("baseTexture"),
                m_normal_texture("normalTexture"),
                m_texture_flags("textureFlags"),
@@ -493,7 +497,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                        sunlight.b };
                m_day_light.set(dnc, services);
 
-               u32 animation_timer = porting::getTimeMs() % 100000;
+               u32 animation_timer = porting::getTimeMs() % 1000000;
                float animation_timer_f = (float)animation_timer / 100000.f;
                m_animation_timer_vertex.set(&animation_timer_f, services);
                m_animation_timer_pixel.set(&animation_timer_f, services);
@@ -523,6 +527,18 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                        m_minimap_yaw.set(minimap_yaw_array, services);
                }
 
+               float camera_offset_array[3];
+               v3f offset = intToFloat(m_client->getCamera()->getOffset(), BS);
+#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
+               camera_offset_array[0] = offset.X;
+               camera_offset_array[1] = offset.Y;
+               camera_offset_array[2] = offset.Z;
+#else
+               offset.getAs3Values(camera_offset_array);
+#endif
+               m_camera_offset_pixel.set(camera_offset_array, services);
+               m_camera_offset_vertex.set(camera_offset_array, services);
+
                SamplerLayer_t base_tex = 0,
                                normal_tex = 1,
                                flags_tex = 2;
@@ -795,14 +811,18 @@ class Game {
        void handleClientEvent_HudRemove(ClientEvent *event, CameraOrientation *cam);
        void handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *cam);
        void handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam);
+       void handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam);
+       void handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam);
+       void handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam);
        void handleClientEvent_OverrideDayNigthRatio(ClientEvent *event,
                CameraOrientation *cam);
        void handleClientEvent_CloudParams(ClientEvent *event, CameraOrientation *cam);
 
        void updateChat(f32 dtime, const v2u32 &screensize);
 
-       bool nodePlacementPrediction(const ItemDefinition &selected_def,
-               const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos);
+       bool nodePlacement(const ItemDefinition &selected_def, const ItemStack &selected_item,
+               const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed,
+               const NodeMetadata *meta);
        static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
 
        InputHandler *input = nullptr;
@@ -1083,7 +1103,7 @@ void Game::run()
                //    RenderingEngine::run() from this iteration
                //  + Sleep time until the wanted FPS are reached
                limitFps(&draw_times, &dtime);
-               
+
                // Prepare render data for next iteration
 
                updateStats(&stats, draw_times, dtime);
@@ -1870,7 +1890,7 @@ void Game::processKeyInput()
        } else if (wasKeyDown(KeyType::CMD)) {
                openConsole(0.2, L"/");
        } else if (wasKeyDown(KeyType::CMD_LOCAL)) {
-               if (client->moddingEnabled())
+               if (client->modsLoaded())
                        openConsole(0.2, L".");
                else
                        m_game_ui->showStatusText(wgettext("Client side scripting is disabled"));
@@ -2026,7 +2046,7 @@ void Game::openInventory()
        InventoryLocation inventoryloc;
        inventoryloc.setCurrentPlayer();
 
-       if (!client->moddingEnabled()
+       if (!client->modsLoaded()
                        || !client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) {
                TextDest *txt_dst = new TextDestPlayerInventory(client);
                auto *&formspec = m_game_ui->updateFormspec("");
@@ -2332,7 +2352,7 @@ void Game::toggleFullViewRange()
 void Game::checkZoomEnabled()
 {
        LocalPlayer *player = client->getEnv().getLocalPlayer();
-       if (player->getZoomFOV() < 0.001f)
+       if (player->getZoomFOV() < 0.001f || player->getFov().fov > 0.0f)
                m_game_ui->showTranslatedStatusText("Zoom currently disabled by game or mod");
 }
 
@@ -2464,7 +2484,8 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
        }
 
        // autoforward if set: simulate "up" key
-       if (player->getPlayerSettings().continuous_forward && !player->isDead()) {
+       if (player->getPlayerSettings().continuous_forward &&
+                       client->activeObjectsReceived() && !player->isDead()) {
                control.up = true;
                keypress_bits |= 1U << 0;
        }
@@ -2505,6 +2526,9 @@ const ClientEventHandler Game::clientEventHandler[CLIENTEVENT_MAX] = {
        {&Game::handleClientEvent_HudRemove},
        {&Game::handleClientEvent_HudChange},
        {&Game::handleClientEvent_SetSky},
+       {&Game::handleClientEvent_SetSun},
+       {&Game::handleClientEvent_SetMoon},
+       {&Game::handleClientEvent_SetStars},
        {&Game::handleClientEvent_OverrideDayNigthRatio},
        {&Game::handleClientEvent_CloudParams},
 };
@@ -2516,9 +2540,8 @@ void Game::handleClientEvent_None(ClientEvent *event, CameraOrientation *cam)
 
 void Game::handleClientEvent_PlayerDamage(ClientEvent *event, CameraOrientation *cam)
 {
-       if (client->moddingEnabled()) {
+       if (client->modsLoaded())
                client->getScript()->on_damage_taken(event->player_damage.amount);
-       }
 
        // Damage flash and hurt tilt are not used at death
        if (client->getHP() > 0) {
@@ -2546,7 +2569,7 @@ void Game::handleClientEvent_Deathscreen(ClientEvent *event, CameraOrientation *
 {
        // If client scripting is enabled, deathscreen is handled by CSM code in
        // builtin/client/init.lua
-       if (client->moddingEnabled())
+       if (client->modsLoaded())
                client->getScript()->on_death();
        else
                showDeathFormspec();
@@ -2633,6 +2656,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
        e->offset = *event->hudadd.offset;
        e->world_pos = *event->hudadd.world_pos;
        e->size = *event->hudadd.size;
+       e->z_index = event->hudadd.z_index;
        hud_server_to_client[server_id] = player->addHud(e);
 
        delete event->hudadd.pos;
@@ -2711,6 +2735,10 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca
                case HUD_STAT_SIZE:
                        e->size = *event->hudchange.v2s32data;
                        break;
+
+               case HUD_STAT_Z_INDEX:
+                       e->z_index = event->hudchange.data;
+                       break;
        }
 
        delete event->hudchange.v3fdata;
@@ -2722,41 +2750,85 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca
 void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
 {
        sky->setVisible(false);
-       // Whether clouds are visible in front of a custom skybox
-       sky->setCloudsEnabled(event->set_sky.clouds);
+       // Whether clouds are visible in front of a custom skybox.
+       sky->setCloudsEnabled(event->set_sky->clouds);
 
        if (skybox) {
                skybox->remove();
                skybox = NULL;
        }
-
+       // Clear the old textures out in case we switch rendering type.
+       sky->clearSkyboxTextures();
        // Handle according to type
-       if (*event->set_sky.type == "regular") {
+       if (event->set_sky->type == "regular") {
+               // Shows the mesh skybox
                sky->setVisible(true);
-               sky->setCloudsEnabled(true);
-       } else if (*event->set_sky.type == "skybox" &&
-               event->set_sky.params->size() == 6) {
-               sky->setFallbackBgColor(*event->set_sky.bgcolor);
-               skybox = RenderingEngine::get_scene_manager()->addSkyBoxSceneNode(
-                       texture_src->getTextureForMesh((*event->set_sky.params)[0]),
-                       texture_src->getTextureForMesh((*event->set_sky.params)[1]),
-                       texture_src->getTextureForMesh((*event->set_sky.params)[2]),
-                       texture_src->getTextureForMesh((*event->set_sky.params)[3]),
-                       texture_src->getTextureForMesh((*event->set_sky.params)[4]),
-                       texture_src->getTextureForMesh((*event->set_sky.params)[5]));
-       }
-               // Handle everything else as plain color
-       else {
-               if (*event->set_sky.type != "plain")
+               // Update mesh based skybox colours if applicable.
+               sky->setSkyColors(*event->set_sky);
+               sky->setHorizonTint(
+                       event->set_sky->sun_tint,
+                       event->set_sky->moon_tint,
+                       event->set_sky->tint_type
+               );
+       } else if (event->set_sky->type == "skybox" &&
+                       event->set_sky->textures.size() == 6) {
+               // Disable the dyanmic mesh skybox:
+               sky->setVisible(false);
+               // Set fog colors:
+               sky->setFallbackBgColor(event->set_sky->bgcolor);
+               // Set sunrise and sunset fog tinting:
+               sky->setHorizonTint(
+                       event->set_sky->sun_tint,
+                       event->set_sky->moon_tint,
+                       event->set_sky->tint_type
+               );
+               // Add textures to skybox.
+               for (int i = 0; i < 6; i++)
+                       sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src);
+       } else {
+               // Handle everything else as plain color.
+               if (event->set_sky->type != "plain")
                        infostream << "Unknown sky type: "
-                               << (*event->set_sky.type) << std::endl;
-
-               sky->setFallbackBgColor(*event->set_sky.bgcolor);
+                               << (event->set_sky->type) << std::endl;
+               sky->setVisible(false);
+               sky->setFallbackBgColor(event->set_sky->bgcolor);
+               // Disable directional sun/moon tinting on plain or invalid skyboxes.
+               sky->setHorizonTint(
+                       event->set_sky->bgcolor,
+                       event->set_sky->bgcolor,
+                       "custom"
+               );
        }
+       delete event->set_sky;
+}
+
+void Game::handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam)
+{
+       sky->setSunVisible(event->sun_params->visible);
+       sky->setSunTexture(event->sun_params->texture,
+               event->sun_params->tonemap, texture_src);
+       sky->setSunScale(event->sun_params->scale);
+       sky->setSunriseVisible(event->sun_params->sunrise_visible);
+       sky->setSunriseTexture(event->sun_params->sunrise, texture_src);
+       delete event->sun_params;
+}
 
-       delete event->set_sky.bgcolor;
-       delete event->set_sky.type;
-       delete event->set_sky.params;
+void Game::handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam)
+{
+       sky->setMoonVisible(event->moon_params->visible);
+       sky->setMoonTexture(event->moon_params->texture,
+               event->moon_params->tonemap, texture_src);
+       sky->setMoonScale(event->moon_params->scale);
+       delete event->moon_params;
+}
+
+void Game::handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam)
+{
+       sky->setStarsVisible(event->star_params->visible);
+       sky->setStarCount(event->star_params->count, false);
+       sky->setStarColor(event->star_params->starcolor);
+       sky->setStarScale(event->star_params->scale);
+       delete event->star_params;
 }
 
 void Game::handleClientEvent_OverrideDayNigthRatio(ClientEvent *event,
@@ -3033,9 +3105,8 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
        else
                runData.repeat_rightclick_timer = 0;
 
-
        if (selected_def.usable && input->getLeftState()) {
-               if (input->getLeftClicked() && (!client->moddingEnabled()
+               if (input->getLeftClicked() && (!client->modsLoaded()
                                || !client->getScript()->on_item_use(selected_item, pointed)))
                        client->interact(INTERACT_USE, pointed);
        } else if (pointed.type == POINTEDTHING_NODE) {
@@ -3045,6 +3116,9 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
        } else if (input->getLeftState()) {
                // When button is held down in air, show continuous animation
                runData.left_punch = true;
+               // Run callback even though item is not usable
+               if (input->getLeftClicked() && client->modsLoaded())
+                       client->getScript()->on_item_use(selected_item, pointed);
        } else if (input->getRightClicked()) {
                handlePointingAtNothing(selected_item);
        }
@@ -3201,65 +3275,26 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
                runData.repeat_rightclick_timer = 0;
                infostream << "Ground right-clicked" << std::endl;
 
-               if (meta && !meta->getString("formspec").empty() && !random_input
-                               && !isKeyDown(KeyType::SNEAK)) {
-                       // Report right click to server
-                       if (nodedef_manager->get(map.getNode(nodepos)).rightclickable) {
-                               client->interact(INTERACT_PLACE, pointed);
-                       }
-
-                       infostream << "Launching custom inventory view" << std::endl;
-
-                       InventoryLocation inventoryloc;
-                       inventoryloc.setNodeMeta(nodepos);
-
-                       NodeMetadataFormSource *fs_src = new NodeMetadataFormSource(
-                               &client->getEnv().getClientMap(), nodepos);
-                       TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
-
-                       auto *&formspec = m_game_ui->updateFormspec("");
-                       GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
-                               txt_dst, client->getFormspecPrepend());
-
-                       formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
-               } else {
-                       // Report right click to server
-
-                       camera->setDigging(1);  // right click animation (always shown for feedback)
-
-                       // If the wielded item has node placement prediction,
-                       // make that happen
-                       auto &def = selected_item.getDefinition(itemdef_manager);
-                       bool placed = nodePlacementPrediction(def, selected_item, nodepos,
-                               neighbourpos);
+               camera->setDigging(1);  // right click animation (always shown for feedback)
 
-                       if (placed) {
-                               // Report to server
-                               client->interact(INTERACT_PLACE, pointed);
-                               // Read the sound
-                               soundmaker->m_player_rightpunch_sound =
-                                               def.sound_place;
+               soundmaker->m_player_rightpunch_sound = SimpleSoundSpec();
 
-                               if (client->moddingEnabled())
-                                       client->getScript()->on_placenode(pointed, def);
-                       } else {
-                               soundmaker->m_player_rightpunch_sound =
-                                               SimpleSoundSpec();
+               // If the wielded item has node placement prediction,
+               // make that happen
+               // And also set the sound and send the interact
+               // But first check for meta formspec and rightclickable
+               auto &def = selected_item.getDefinition(itemdef_manager);
+               bool placed = nodePlacement(def, selected_item, nodepos, neighbourpos,
+                       pointed, meta);
 
-                               if (def.node_placement_prediction.empty() ||
-                                               nodedef_manager->get(map.getNode(nodepos)).rightclickable) {
-                                       client->interact(INTERACT_PLACE, pointed); // Report to server
-                               } else {
-                                       soundmaker->m_player_rightpunch_sound =
-                                               def.sound_place_failed;
-                               }
-                       }
-               }
+               if (placed && client->modsLoaded())
+                       client->getScript()->on_placenode(pointed, def);
        }
 }
 
-bool Game::nodePlacementPrediction(const ItemDefinition &selected_def,
-       const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos)
+bool Game::nodePlacement(const ItemDefinition &selected_def,
+       const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos,
+       const PointedThing &pointed, const NodeMetadata *meta)
 {
        std::string prediction = selected_def.node_placement_prediction;
        const NodeDefManager *nodedef = client->ndef();
@@ -3268,144 +3303,187 @@ bool Game::nodePlacementPrediction(const ItemDefinition &selected_def,
        bool is_valid_position;
 
        node = map.getNode(nodepos, &is_valid_position);
-       if (!is_valid_position)
+       if (!is_valid_position) {
+               soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed;
                return false;
+       }
+
+       // formspec in meta
+       if (meta && !meta->getString("formspec").empty() && !random_input
+                       && !isKeyDown(KeyType::SNEAK)) {
+               // on_rightclick callbacks are called anyway
+               if (nodedef_manager->get(map.getNode(nodepos)).rightclickable)
+                       client->interact(INTERACT_PLACE, pointed);
 
-       if (!prediction.empty() && !(nodedef->get(node).rightclickable &&
+               infostream << "Launching custom inventory view" << std::endl;
+
+               InventoryLocation inventoryloc;
+               inventoryloc.setNodeMeta(nodepos);
+
+               NodeMetadataFormSource *fs_src = new NodeMetadataFormSource(
+                       &client->getEnv().getClientMap(), nodepos);
+               TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
+
+               auto *&formspec = m_game_ui->updateFormspec("");
+               GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
+                       txt_dst, client->getFormspecPrepend());
+
+               formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
+               return false;
+       }
+
+       // on_rightclick callback
+       if (prediction.empty() || (nodedef->get(node).rightclickable &&
                        !isKeyDown(KeyType::SNEAK))) {
-               verbosestream << "Node placement prediction for "
-                       << selected_item.name << " is "
-                       << prediction << std::endl;
-               v3s16 p = neighbourpos;
-
-               // Place inside node itself if buildable_to
-               MapNode n_under = map.getNode(nodepos, &is_valid_position);
-               if (is_valid_position)
-               {
-                       if (nodedef->get(n_under).buildable_to)
-                               p = nodepos;
-                       else {
-                               node = map.getNode(p, &is_valid_position);
-                               if (is_valid_position &&!nodedef->get(node).buildable_to)
-                                       return false;
+               // Report to server
+               client->interact(INTERACT_PLACE, pointed);
+               return false;
+       }
+
+       verbosestream << "Node placement prediction for "
+               << selected_def.name << " is "
+               << prediction << std::endl;
+       v3s16 p = neighbourpos;
+
+       // Place inside node itself if buildable_to
+       MapNode n_under = map.getNode(nodepos, &is_valid_position);
+       if (is_valid_position) {
+               if (nodedef->get(n_under).buildable_to) {
+                       p = nodepos;
+               } else {
+                       node = map.getNode(p, &is_valid_position);
+                       if (is_valid_position && !nodedef->get(node).buildable_to) {
+                               // Report to server
+                               client->interact(INTERACT_PLACE, pointed);
+                               return false;
                        }
                }
+       }
 
-               // Find id of predicted node
-               content_t id;
-               bool found = nodedef->getId(prediction, id);
+       // Find id of predicted node
+       content_t id;
+       bool found = nodedef->getId(prediction, id);
 
-               if (!found) {
-                       errorstream << "Node placement prediction failed for "
-                               << selected_item.name << " (places "
-                               << prediction
-                               << ") - Name not known" << std::endl;
-                       return false;
-               }
+       if (!found) {
+               errorstream << "Node placement prediction failed for "
+                       << selected_def.name << " (places "
+                       << prediction
+                       << ") - Name not known" << std::endl;
+               // Handle this as if prediction was empty
+               // Report to server
+               client->interact(INTERACT_PLACE, pointed);
+               return false;
+       }
 
-               const ContentFeatures &predicted_f = nodedef->get(id);
+       const ContentFeatures &predicted_f = nodedef->get(id);
 
-               // Predict param2 for facedir and wallmounted nodes
-               u8 param2 = 0;
+       // Predict param2 for facedir and wallmounted nodes
+       u8 param2 = 0;
 
-               if (predicted_f.param_type_2 == CPT2_WALLMOUNTED ||
+       if (predicted_f.param_type_2 == CPT2_WALLMOUNTED ||
                        predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED) {
-                       v3s16 dir = nodepos - neighbourpos;
+               v3s16 dir = nodepos - neighbourpos;
 
-                       if (abs(dir.Y) > MYMAX(abs(dir.X), abs(dir.Z))) {
-                               param2 = dir.Y < 0 ? 1 : 0;
-                       } else if (abs(dir.X) > abs(dir.Z)) {
-                               param2 = dir.X < 0 ? 3 : 2;
-                       } else {
-                               param2 = dir.Z < 0 ? 5 : 4;
-                       }
+               if (abs(dir.Y) > MYMAX(abs(dir.X), abs(dir.Z))) {
+                       param2 = dir.Y < 0 ? 1 : 0;
+               } else if (abs(dir.X) > abs(dir.Z)) {
+                       param2 = dir.X < 0 ? 3 : 2;
+               } else {
+                       param2 = dir.Z < 0 ? 5 : 4;
                }
+       }
 
-               if (predicted_f.param_type_2 == CPT2_FACEDIR ||
+       if (predicted_f.param_type_2 == CPT2_FACEDIR ||
                        predicted_f.param_type_2 == CPT2_COLORED_FACEDIR) {
-                       v3s16 dir = nodepos - floatToInt(client->getEnv().getLocalPlayer()->getPosition(), BS);
+               v3s16 dir = nodepos - floatToInt(client->getEnv().getLocalPlayer()->getPosition(), BS);
 
-                       if (abs(dir.X) > abs(dir.Z)) {
-                               param2 = dir.X < 0 ? 3 : 1;
-                       } else {
-                               param2 = dir.Z < 0 ? 2 : 0;
-                       }
+               if (abs(dir.X) > abs(dir.Z)) {
+                       param2 = dir.X < 0 ? 3 : 1;
+               } else {
+                       param2 = dir.Z < 0 ? 2 : 0;
                }
+       }
+
+       assert(param2 <= 5);
+
+       //Check attachment if node is in group attached_node
+       if (((ItemGroupList) predicted_f.groups)["attached_node"] != 0) {
+               static v3s16 wallmounted_dirs[8] = {
+                       v3s16(0, 1, 0),
+                       v3s16(0, -1, 0),
+                       v3s16(1, 0, 0),
+                       v3s16(-1, 0, 0),
+                       v3s16(0, 0, 1),
+                       v3s16(0, 0, -1),
+               };
+               v3s16 pp;
 
-               assert(param2 <= 5);
-
-               //Check attachment if node is in group attached_node
-               if (((ItemGroupList) predicted_f.groups)["attached_node"] != 0) {
-                       static v3s16 wallmounted_dirs[8] = {
-                               v3s16(0, 1, 0),
-                               v3s16(0, -1, 0),
-                               v3s16(1, 0, 0),
-                               v3s16(-1, 0, 0),
-                               v3s16(0, 0, 1),
-                               v3s16(0, 0, -1),
-                       };
-                       v3s16 pp;
-
-                       if (predicted_f.param_type_2 == CPT2_WALLMOUNTED ||
+               if (predicted_f.param_type_2 == CPT2_WALLMOUNTED ||
                                predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED)
-                               pp = p + wallmounted_dirs[param2];
-                       else
-                               pp = p + v3s16(0, -1, 0);
+                       pp = p + wallmounted_dirs[param2];
+               else
+                       pp = p + v3s16(0, -1, 0);
 
-                       if (!nodedef->get(map.getNode(pp)).walkable)
-                               return false;
+               if (!nodedef->get(map.getNode(pp)).walkable) {
+                       // Report to server
+                       client->interact(INTERACT_PLACE, pointed);
+                       return false;
                }
+       }
 
-               // Apply color
-               if ((predicted_f.param_type_2 == CPT2_COLOR
+       // Apply color
+       if ((predicted_f.param_type_2 == CPT2_COLOR
                        || predicted_f.param_type_2 == CPT2_COLORED_FACEDIR
                        || predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED)) {
-                       const std::string &indexstr = selected_item.metadata.getString(
-                               "palette_index", 0);
-                       if (!indexstr.empty()) {
-                               s32 index = mystoi(indexstr);
-                               if (predicted_f.param_type_2 == CPT2_COLOR) {
-                                       param2 = index;
-                               } else if (predicted_f.param_type_2
-                                       == CPT2_COLORED_WALLMOUNTED) {
-                                       // param2 = pure palette index + other
-                                       param2 = (index & 0xf8) | (param2 & 0x07);
-                               } else if (predicted_f.param_type_2
-                                       == CPT2_COLORED_FACEDIR) {
-                                       // param2 = pure palette index + other
-                                       param2 = (index & 0xe0) | (param2 & 0x1f);
-                               }
+               const std::string &indexstr = selected_item.metadata.getString(
+                       "palette_index", 0);
+               if (!indexstr.empty()) {
+                       s32 index = mystoi(indexstr);
+                       if (predicted_f.param_type_2 == CPT2_COLOR) {
+                               param2 = index;
+                       } else if (predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED) {
+                               // param2 = pure palette index + other
+                               param2 = (index & 0xf8) | (param2 & 0x07);
+                       } else if (predicted_f.param_type_2 == CPT2_COLORED_FACEDIR) {
+                               // param2 = pure palette index + other
+                               param2 = (index & 0xe0) | (param2 & 0x1f);
                        }
                }
+       }
 
-               // Add node to client map
-               MapNode n(id, 0, param2);
+       // Add node to client map
+       MapNode n(id, 0, param2);
 
-               try {
-                       LocalPlayer *player = client->getEnv().getLocalPlayer();
+       try {
+               LocalPlayer *player = client->getEnv().getLocalPlayer();
 
-                       // Dont place node when player would be inside new node
-                       // NOTE: This is to be eventually implemented by a mod as client-side Lua
-                       if (!nodedef->get(n).walkable ||
+               // Dont place node when player would be inside new node
+               // NOTE: This is to be eventually implemented by a mod as client-side Lua
+               if (!nodedef->get(n).walkable ||
                                g_settings->getBool("enable_build_where_you_stand") ||
                                (client->checkPrivilege("noclip") && g_settings->getBool("noclip")) ||
                                (nodedef->get(n).walkable &&
                                        neighbourpos != player->getStandingNodePos() + v3s16(0, 1, 0) &&
                                        neighbourpos != player->getStandingNodePos() + v3s16(0, 2, 0))) {
-
-                               // This triggers the required mesh update too
-                               client->addNode(p, n);
-                               return true;
-                       }
-               } catch (InvalidPositionException &e) {
-                       errorstream << "Node placement prediction failed for "
-                               << selected_item.name << " (places "
-                               << prediction
-                               << ") - Position not loaded" << std::endl;
+                       // This triggers the required mesh update too
+                       client->addNode(p, n);
+                       // Report to server
+                       client->interact(INTERACT_PLACE, pointed);
+                       // A node is predicted, also play a sound
+                       soundmaker->m_player_rightpunch_sound = selected_def.sound_place;
+                       return true;
+               } else {
+                       soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed;
+                       return false;
                }
+       } catch (InvalidPositionException &e) {
+               errorstream << "Node placement prediction failed for "
+                       << selected_def.name << " (places "
+                       << prediction
+                       << ") - Position not loaded" << std::endl;
+               soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed;
+               return false;
        }
-
-       return false;
 }
 
 void Game::handlePointingAtObject(const PointedThing &pointed,
@@ -3496,7 +3574,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
        if (!runData.digging) {
                infostream << "Started digging" << std::endl;
                runData.dig_instantly = runData.dig_time_complete == 0;
-               if (client->moddingEnabled() && client->getScript()->on_punchnode(nodepos, n))
+               if (client->modsLoaded() && client->getScript()->on_punchnode(nodepos, n))
                        return;
                client->interact(INTERACT_START_DIGGING, pointed);
                runData.digging = true;
@@ -3556,7 +3634,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
                bool is_valid_position;
                MapNode wasnode = map.getNode(nodepos, &is_valid_position);
                if (is_valid_position) {
-                       if (client->moddingEnabled() &&
+                       if (client->modsLoaded() &&
                                        client->getScript()->on_dignode(nodepos, wasnode)) {
                                return;
                        }
@@ -3678,7 +3756,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
                                video::SColor clouds_dark = clouds->getColor()
                                                .getInterpolated(video::SColor(255, 0, 0, 0), 0.9);
                                sky->overrideColors(clouds_dark, clouds->getColor());
-                               sky->setBodiesVisible(false);
+                               sky->setInClouds(true);
                                runData.fog_range = std::fmin(runData.fog_range * 0.5f, 32.0f * BS);
                                // do not draw clouds after all
                                clouds->setVisible(false);
@@ -3983,7 +4061,7 @@ void Game::extendedResourceCleanup()
 void Game::showDeathFormspec()
 {
        static std::string formspec_str =
-               std::string(FORMSPEC_VERSION_STRING) +
+               std::string("formspec_version[1]") +
                SIZE_TAG
                "bgcolor[#320000b4;true]"
                "label[4.85,1.35;" + gettext("You died") + "]"
@@ -4057,7 +4135,7 @@ void Game::showPauseMenu()
        float ypos = simple_singleplayer_mode ? 0.7f : 0.1f;
        std::ostringstream os;
 
-       os << FORMSPEC_VERSION_STRING  << SIZE_TAG
+       os << "formspec_version[1]" << SIZE_TAG
                << "button_exit[4," << (ypos++) << ";3,0.5;btn_continue;"
                << strgettext("Continue") << "]";