diff options
author | Ekdohibs <nathanael.courant@laposte.net> | 2017-03-22 03:25:16 +0100 |
---|---|---|
committer | Auke Kok <sofar+github@foo-projects.org> | 2017-04-06 21:27:29 -0700 |
commit | 08b680d58890ce896f5d57404adc84eb7b96fd79 (patch) | |
tree | aad96d77674cf963e4857d67c671e5169e348020 /src/game.cpp | |
parent | bce0d458d8cda70c10d78ea9ec476474f0a6f01a (diff) | |
download | minetest-08b680d58890ce896f5d57404adc84eb7b96fd79.tar.gz minetest-08b680d58890ce896f5d57404adc84eb7b96fd79.tar.bz2 minetest-08b680d58890ce896f5d57404adc84eb7b96fd79.zip |
Fix problems when overriding the hand:
- If the hand can dig a node the item wielded can't, allow to dig it anyway.
- Fix the API callbacks from setting the hand instead of the wielded item.
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/game.cpp b/src/game.cpp index 14dfa73b7..b2ce0c24f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3402,13 +3402,11 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) playeritem = mlist->getItem(client->getPlayerItem()); } - if (playeritem.getDefinition(itemdef_manager).name.empty()) { // override the hand - InventoryList *hlist = local_inventory->getList("hand"); - if (hlist) - playeritem = hlist->getItem(0); - } const ItemDefinition &playeritem_def = playeritem.getDefinition(itemdef_manager); + InventoryList *hlist = local_inventory->getList("hand"); + const ItemDefinition &hand_def = + hlist?hlist->getItem(0).getDefinition(itemdef_manager):itemdef_manager->get(""); v3f player_position = player->getPosition(); v3f camera_position = camera->getPosition(); @@ -3421,7 +3419,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) */ f32 d = playeritem_def.range; // max. distance - f32 d_hand = itemdef_manager->get("").range; + f32 d_hand = hand_def.range; if (d < 0 && d_hand >= 0) d = d_hand; @@ -3509,6 +3507,9 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) } else if (pointed.type == POINTEDTHING_NODE) { ToolCapabilities playeritem_toolcap = playeritem.getToolCapabilities(itemdef_manager); + if (playeritem.name.empty()) { + playeritem_toolcap = *hand_def.tool_capabilities; + } handlePointingAtNode(pointed, playeritem_def, playeritem_toolcap, dtime); } else if (pointed.type == POINTEDTHING_OBJECT) { handlePointingAtObject(pointed, playeritem, player_position, show_debug); @@ -3768,9 +3769,16 @@ void Game::handlePointingAtObject(const PointedThing &pointed, const ItemStack & // Report direct punch v3f objpos = runData.selected_object->getPosition(); v3f dir = (objpos - player_position).normalize(); + ItemStack item = playeritem; + if (playeritem.name.empty()) { + InventoryList *hlist = local_inventory->getList("hand"); + if (hlist) { + item = hlist->getItem(0); + } + } bool disable_send = runData.selected_object->directReportPunch( - dir, &playeritem, runData.time_from_last_punch); + dir, &item, runData.time_from_last_punch); runData.time_from_last_punch = 0; if (!disable_send) @@ -3807,7 +3815,9 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, // If can't dig, try hand if (!params.diggable) { - const ItemDefinition &hand = itemdef_manager->get(""); + InventoryList *hlist = local_inventory->getList("hand"); + const ItemDefinition &hand = + hlist?hlist->getItem(0).getDefinition(itemdef_manager):itemdef_manager->get(""); const ToolCapabilities *tp = hand.tool_capabilities; if (tp) |