diff options
Diffstat (limited to 'src/client/game.cpp')
-rw-r--r-- | src/client/game.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp index caa83ce13..bc27920fc 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -746,7 +746,8 @@ protected: 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, @@ -3055,7 +3056,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, use_item; const ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item); const ItemDefinition &selected_def = selected_item.getDefinition(itemdef_manager); @@ -3098,6 +3099,8 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud) !runData.btn_down_for_dig, camera_offset); + player->getOffhandWieldedItem(&offhand_item, &use_item, itemdef_manager, pointed); + if (pointed != runData.pointed_old) infostream << "Pointing at " << pointed.dump() << std::endl; @@ -3161,7 +3164,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, use_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); @@ -3174,13 +3177,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(use_item); } runData.pointed_old = pointed; if (runData.punching || wasKeyPressed(KeyType::DIG)) - camera->setDigging(0); // dig animation + camera->setDigging(0, 0); // dig animation input->clearWasKeyPressed(); input->clearWasKeyReleased(); @@ -3300,7 +3303,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 neighbourpos = pointed.node_abovesurface; @@ -3338,7 +3342,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, 0); + else + camera->setDigging(1, 1); soundmaker->m_player_rightpunch_sound = SimpleSoundSpec(); @@ -3346,8 +3353,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, neighbourpos, + auto &def = place_item.getDefinition(itemdef_manager); + bool placed = nodePlacement(def, place_item, nodepos, neighbourpos, pointed, meta); if (placed && client->modsLoaded()) @@ -3737,7 +3744,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, client->setCrack(-1, nodepos); } - camera->setDigging(0); // Dig animation + camera->setDigging(0, 0); // Dig animation } void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, @@ -3897,9 +3904,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, 0); + player->getOffhandWieldedItem(&offhand_item, nullptr, itemdef_manager, PointedThing()); + camera->wield(offhand_item, 1); } /* |