diff --git a/src/client/game.cpp b/src/client/game.cpp index 9f71850f9..6807c7eca 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -239,7 +239,7 @@ public: Client *m_client; }; -class NodeDugEvent: public MtEvent +class NodeDugEvent : public MtEvent { public: v3s16 p; @@ -249,16 +249,14 @@ public: p(p), n(n) {} - MtEvent::Type getType() const - { - return MtEvent::NODE_DUG; - } + Type getType() const { return NODE_DUG; } }; class SoundMaker { ISoundManager *m_sound; const NodeDefManager *m_ndef; + public: bool makes_footstep_sound; float m_player_step_timer; @@ -3704,18 +3702,19 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, // See also: serverpackethandle.cpp, action == 2 LocalPlayer *player = client->getEnv().getLocalPlayer(); ClientMap &map = client->getEnv().getClientMap(); - MapNode n = client->getEnv().getClientMap().getNode(nodepos); + MapNode n = map.getNode(nodepos); + const auto &features = nodedef_manager->get(n); // NOTE: Similar piece of code exists on the server side for // cheat detection. // Get digging parameters - DigParams params = getDigParams(nodedef_manager->get(n).groups, + DigParams params = getDigParams(features.groups, &selected_item.getToolCapabilities(itemdef_manager), selected_item.wear); // If can't dig, try hand if (!params.diggable) { - params = getDigParams(nodedef_manager->get(n).groups, + params = getDigParams(features.groups, &hand_item.getToolCapabilities(itemdef_manager)); } @@ -3726,7 +3725,6 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, runData.dig_time_complete = params.time; if (m_cache_enable_particles) { - const ContentFeatures &features = client->getNodeDefManager()->get(n); client->getParticleManager()->addNodeParticle(client, player, nodepos, n, features); } @@ -3737,6 +3735,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, runData.dig_instantly = runData.dig_time_complete == 0; if (client->modsLoaded() && client->getScript()->on_punchnode(nodepos, n)) return; + client->interact(INTERACT_START_DIGGING, pointed); runData.digging = true; runData.btn_down_for_dig = true; @@ -3751,7 +3750,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, runData.dig_index = crack_animation_length; } - SimpleSoundSpec sound_dig = nodedef_manager->get(n).sound_dig; + const auto &sound_dig = features.sound_dig; if (sound_dig.exists() && params.diggable) { if (sound_dig.name == "__group") { @@ -3769,8 +3768,6 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, // Don't show cracks if not diggable if (runData.dig_time_complete >= 100000.0) { } else if (runData.dig_index < crack_animation_length) { - //TimeTaker timer("client.setTempMod"); - //infostream<<"dig_index="<setCrack(runData.dig_index, nodepos); } else { infostream << "Digging completed" << std::endl; @@ -3792,38 +3789,31 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, else if (runData.dig_instantly) runData.nodig_delay_timer = 0.15; - bool is_valid_position; - MapNode wasnode = map.getNode(nodepos, &is_valid_position); - if (is_valid_position) { - if (client->modsLoaded() && - client->getScript()->on_dignode(nodepos, wasnode)) { - return; - } - - const ContentFeatures &f = client->ndef()->get(wasnode); - if (f.node_dig_prediction == "air") { - client->removeNode(nodepos); - } else if (!f.node_dig_prediction.empty()) { - content_t id; - bool found = client->ndef()->getId(f.node_dig_prediction, id); - if (found) - client->addNode(nodepos, id, true); - } - // implicit else: no prediction + if (client->modsLoaded() && + client->getScript()->on_dignode(nodepos, n)) { + return; } + if (features.node_dig_prediction == "air") { + client->removeNode(nodepos); + } else if (!features.node_dig_prediction.empty()) { + content_t id; + bool found = nodedef_manager->getId(features.node_dig_prediction, id); + if (found) + client->addNode(nodepos, id, true); + } + // implicit else: no prediction + client->interact(INTERACT_DIGGING_COMPLETED, pointed); if (m_cache_enable_particles) { - const ContentFeatures &features = - client->getNodeDefManager()->get(wasnode); client->getParticleManager()->addDiggingParticles(client, - player, nodepos, wasnode, features); + player, nodepos, n, features); } // Send event to trigger sound - client->getEventManager()->put(new NodeDugEvent(nodepos, wasnode)); + client->getEventManager()->put(new NodeDugEvent(nodepos, n)); } if (runData.dig_time_complete < 100000.0) { diff --git a/src/inventory.cpp b/src/inventory.cpp index 6d2b7fba3..eaf7ba198 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -250,7 +250,7 @@ std::string ItemStack::getItemString(bool include_meta) const return os.str(); } -std::string ItemStack::getDescription(IItemDefManager *itemdef) const +std::string ItemStack::getDescription(const IItemDefManager *itemdef) const { std::string desc = metadata.getString("description"); if (desc.empty()) @@ -258,7 +258,7 @@ std::string ItemStack::getDescription(IItemDefManager *itemdef) const return desc.empty() ? name : desc; } -std::string ItemStack::getShortDescription(IItemDefManager *itemdef) const +std::string ItemStack::getShortDescription(const IItemDefManager *itemdef) const { std::string desc = metadata.getString("short_description"); if (desc.empty()) diff --git a/src/inventory.h b/src/inventory.h index 8b31de3a8..0f024792a 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -48,8 +48,8 @@ struct ItemStack // Returns the string used for inventory std::string getItemString(bool include_meta = true) const; // Returns the tooltip - std::string getDescription(IItemDefManager *itemdef) const; - std::string getShortDescription(IItemDefManager *itemdef) const; + std::string getDescription(const IItemDefManager *itemdef) const; + std::string getShortDescription(const IItemDefManager *itemdef) const; /* Quantity methods @@ -82,13 +82,13 @@ struct ItemStack } // Maximum size of a stack - u16 getStackMax(IItemDefManager *itemdef) const + u16 getStackMax(const IItemDefManager *itemdef) const { return itemdef->get(name).stack_max; } // Number of items that can be added to this stack - u16 freeSpace(IItemDefManager *itemdef) const + u16 freeSpace(const IItemDefManager *itemdef) const { u16 max = getStackMax(itemdef); if (count >= max) @@ -97,7 +97,7 @@ struct ItemStack } // Returns false if item is not known and cannot be used - bool isKnown(IItemDefManager *itemdef) const + bool isKnown(const IItemDefManager *itemdef) const { return itemdef->isKnown(name); } @@ -105,14 +105,14 @@ struct ItemStack // Returns a pointer to the item definition struct, // or a fallback one (name="unknown") if the item is unknown. const ItemDefinition& getDefinition( - IItemDefManager *itemdef) const + const IItemDefManager *itemdef) const { return itemdef->get(name); } // Get tool digging properties, or those of the hand if not a tool const ToolCapabilities& getToolCapabilities( - IItemDefManager *itemdef) const + const IItemDefManager *itemdef) const { const ToolCapabilities *item_cap = itemdef->get(name).tool_capabilities; @@ -127,7 +127,7 @@ struct ItemStack // Wear out (only tools) // Returns true if the item is (was) a tool - bool addWear(s32 amount, IItemDefManager *itemdef) + bool addWear(s32 amount, const IItemDefManager *itemdef) { if(getDefinition(itemdef).type == ITEM_TOOL) {