From a637107a4e81be88938d68df4deae50e68cf2cd8 Mon Sep 17 00:00:00 2001 From: raymoo Date: Tue, 18 Apr 2017 16:30:27 -0700 Subject: Allow overriding tool capabilities through itemstack metadata This makes it possible to modify the tool capabilities of individual itemstacks by calling a method on itemstack metadata references. --- src/game.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index cd4650baf..fd3914356 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3701,8 +3701,13 @@ 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() && hand_def.tool_capabilities != NULL) { - playeritem_toolcap = *hand_def.tool_capabilities; + if (playeritem.name.empty()) { + const ToolCapabilities *handToolcap = hlist + ? &hlist->getItem(0).getToolCapabilities(itemdef_manager) + : itemdef_manager->get("").tool_capabilities; + + if (handToolcap != nullptr) + playeritem_toolcap = *handToolcap; } handlePointingAtNode(pointed, playeritem_def, playeritem, playeritem_toolcap, dtime); @@ -4004,9 +4009,9 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, // If can't dig, try hand if (!params.diggable) { 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; + const ToolCapabilities *tp = hlist + ? &hlist->getItem(0).getToolCapabilities(itemdef_manager) + : itemdef_manager->get("").tool_capabilities; if (tp) params = getDigParams(nodedef_manager->get(n).groups, tp); -- cgit v1.2.3