]> git.lizzy.rs Git - minetest.git/blobdiff - src/client/game.cpp
Dual wielding
[minetest.git] / src / client / game.cpp
index edd0039e9240c259f7254b911164bf94dc6842fa..e31db44a831768ee47532ca630c060ff274cfe55 100644 (file)
@@ -841,7 +841,8 @@ class Game {
                        bool look_for_object, const v3s16 &camera_offset);
        void handlePointingAtNothing(const ItemStack &playerItem);
        void handlePointingAtNode(const PointedThing &pointed,
-                       const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
+                       const ItemStack &selected_item, const ItemStack &hand_item,
+                       const ItemStack &place_item, f32 dtime);
        void handlePointingAtObject(const PointedThing &pointed, const ItemStack &playeritem,
                        const v3f &player_position, bool show_debug);
        void handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
@@ -1833,19 +1834,19 @@ inline bool Game::handleCallbacks()
 
        if (g_gamecallback->changepassword_requested) {
                (new GUIPasswordChange(guienv, guiroot, -1,
-                                      &g_menumgr, client, texture_src))->drop();
+                                          &g_menumgr, client, texture_src))->drop();
                g_gamecallback->changepassword_requested = false;
        }
 
        if (g_gamecallback->changevolume_requested) {
                (new GUIVolumeChange(guienv, guiroot, -1,
-                                    &g_menumgr, texture_src))->drop();
+                                        &g_menumgr, texture_src))->drop();
                g_gamecallback->changevolume_requested = false;
        }
 
        if (g_gamecallback->keyconfig_requested) {
                (new GUIKeyChangeMenu(guienv, guiroot, -1,
-                                     &g_menumgr, texture_src))->drop();
+                                         &g_menumgr, texture_src))->drop();
                g_gamecallback->keyconfig_requested = false;
        }
 
@@ -2149,7 +2150,7 @@ void Game::processItemSelection(u16 *new_playeritem)
        *new_playeritem = player->getWieldIndex();
        s32 wheel = input->getMouseWheel();
        u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE - 1,
-                   player->hud_hotbar_itemcount - 1);
+                       player->hud_hotbar_itemcount - 1);
 
        s32 dir = wheel;
 
@@ -3175,9 +3176,9 @@ void Game::updateSound(f32 dtime)
        // Update sound listener
        v3s16 camera_offset = camera->getOffset();
        sound->updateListener(camera->getCameraNode()->getPosition() + intToFloat(camera_offset, BS),
-                             v3f(0, 0, 0), // velocity
-                             camera->getDirection(),
-                             camera->getCameraNode()->getUpVector());
+                                 v3f(0, 0, 0), // velocity
+                                 camera->getDirection(),
+                                 camera->getCameraNode()->getUpVector());
 
        bool mute_sound = g_settings->getBool("mute_sound");
        if (mute_sound) {
@@ -3219,7 +3220,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
                Calculate what block is the crosshair pointing to
        */
 
-       ItemStack selected_item, hand_item;
+       ItemStack selected_item, hand_item, offhand_item, place_item;
        const ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item);
 
        const ItemDefinition &selected_def = selected_item.getDefinition(itemdef_manager);
@@ -3260,6 +3261,8 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
                        !runData.btn_down_for_dig,
                        camera_offset);
 
+       player->getOffhandWieldedItem(&offhand_item, &place_item, itemdef_manager, pointed);
+
        if (pointed != runData.pointed_old)
                infostream << "Pointing at " << pointed.dump() << std::endl;
 
@@ -3325,7 +3328,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
                                !client->getScript()->on_item_use(selected_item, pointed)))
                        client->interact(INTERACT_USE, pointed);
        } else if (pointed.type == POINTEDTHING_NODE) {
-               handlePointingAtNode(pointed, selected_item, hand_item, dtime);
+               handlePointingAtNode(pointed, selected_item, hand_item, place_item, dtime);
        } else if (pointed.type == POINTEDTHING_OBJECT) {
                v3f player_position  = player->getPosition();
                bool basic_debug_allowed = client->checkPrivilege("debug") || (player->hud_flags & HUD_FLAG_BASIC_DEBUG);
@@ -3338,13 +3341,13 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
                if (wasKeyPressed(KeyType::DIG) && client->modsLoaded())
                        client->getScript()->on_item_use(selected_item, pointed);
        } else if (wasKeyPressed(KeyType::PLACE)) {
-               handlePointingAtNothing(selected_item);
+               handlePointingAtNothing(place_item);
        }
 
        runData.pointed_old = pointed;
 
        if (runData.punching || wasKeyPressed(KeyType::DIG))
-               camera->setDigging(0); // dig animation
+               camera->setDigging(0, MAINHAND); // dig animation
 
        input->clearWasKeyPressed();
        input->clearWasKeyReleased();
@@ -3468,7 +3471,8 @@ void Game::handlePointingAtNothing(const ItemStack &playerItem)
 
 
 void Game::handlePointingAtNode(const PointedThing &pointed,
-       const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime)
+       const ItemStack &selected_item, const ItemStack &hand_item,
+       const ItemStack &place_item, f32 dtime)
 {
        v3s16 nodepos = pointed.node_undersurface;
        v3s16 neighborpos = pointed.node_abovesurface;
@@ -3506,7 +3510,10 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
                infostream << "Place button pressed while looking at ground" << std::endl;
 
                // Placing animation (always shown for feedback)
-               camera->setDigging(1);
+               if (place_item == selected_item)
+                       camera->setDigging(1, MAINHAND);
+               else
+                       camera->setDigging(1, OFFHAND);
 
                soundmaker->m_player_rightpunch_sound = SimpleSoundSpec();
 
@@ -3514,8 +3521,8 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
                // 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, neighborpos,
+               auto &def = place_item.getDefinition(itemdef_manager);
+               bool placed = nodePlacement(def, place_item, nodepos, neighborpos,
                        pointed, meta);
 
                if (placed && client->modsLoaded())
@@ -3907,7 +3914,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
                client->setCrack(-1, nodepos);
        }
 
-       camera->setDigging(0);  // Dig animation
+       camera->setDigging(0, MAINHAND);  // Dig animation
 }
 
 void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
@@ -3951,7 +3958,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
                direct_brightness = client->getEnv().getClientMap()
                                .getBackgroundBrightness(MYMIN(runData.fog_range * 1.2, 60 * BS),
                                        daynight_ratio, (int)(old_brightness * 255.5), &sunlight_seen)
-                                   / 255.0;
+                                       / 255.0;
        }
 
        float time_of_day_smooth = runData.time_of_day_smooth;
@@ -4073,9 +4080,11 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
 
        if (client->updateWieldedItem()) {
                // Update wielded tool
-               ItemStack selected_item, hand_item;
+               ItemStack selected_item, hand_item, offhand_item;
                ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item);
-               camera->wield(tool_item);
+               camera->wield(tool_item, MAINHAND);
+               player->getOffhandWieldedItem(&offhand_item, nullptr, itemdef_manager, PointedThing());
+               camera->wield(offhand_item, OFFHAND);
        }
 
        /*