mirror of
https://github.com/minetest/minetest.git
synced 2025-03-22 10:12:32 +01:00
Clean up Game::handleDigging() and some related parts
This commit is contained in:
src
@ -239,7 +239,7 @@ public:
|
|||||||
Client *m_client;
|
Client *m_client;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NodeDugEvent: public MtEvent
|
class NodeDugEvent : public MtEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
v3s16 p;
|
v3s16 p;
|
||||||
@ -249,16 +249,14 @@ public:
|
|||||||
p(p),
|
p(p),
|
||||||
n(n)
|
n(n)
|
||||||
{}
|
{}
|
||||||
MtEvent::Type getType() const
|
Type getType() const { return NODE_DUG; }
|
||||||
{
|
|
||||||
return MtEvent::NODE_DUG;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SoundMaker
|
class SoundMaker
|
||||||
{
|
{
|
||||||
ISoundManager *m_sound;
|
ISoundManager *m_sound;
|
||||||
const NodeDefManager *m_ndef;
|
const NodeDefManager *m_ndef;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool makes_footstep_sound;
|
bool makes_footstep_sound;
|
||||||
float m_player_step_timer;
|
float m_player_step_timer;
|
||||||
@ -3704,18 +3702,19 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
|
|||||||
// See also: serverpackethandle.cpp, action == 2
|
// See also: serverpackethandle.cpp, action == 2
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
ClientMap &map = client->getEnv().getClientMap();
|
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
|
// NOTE: Similar piece of code exists on the server side for
|
||||||
// cheat detection.
|
// cheat detection.
|
||||||
// Get digging parameters
|
// Get digging parameters
|
||||||
DigParams params = getDigParams(nodedef_manager->get(n).groups,
|
DigParams params = getDigParams(features.groups,
|
||||||
&selected_item.getToolCapabilities(itemdef_manager),
|
&selected_item.getToolCapabilities(itemdef_manager),
|
||||||
selected_item.wear);
|
selected_item.wear);
|
||||||
|
|
||||||
// If can't dig, try hand
|
// If can't dig, try hand
|
||||||
if (!params.diggable) {
|
if (!params.diggable) {
|
||||||
params = getDigParams(nodedef_manager->get(n).groups,
|
params = getDigParams(features.groups,
|
||||||
&hand_item.getToolCapabilities(itemdef_manager));
|
&hand_item.getToolCapabilities(itemdef_manager));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3726,7 +3725,6 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
|
|||||||
runData.dig_time_complete = params.time;
|
runData.dig_time_complete = params.time;
|
||||||
|
|
||||||
if (m_cache_enable_particles) {
|
if (m_cache_enable_particles) {
|
||||||
const ContentFeatures &features = client->getNodeDefManager()->get(n);
|
|
||||||
client->getParticleManager()->addNodeParticle(client,
|
client->getParticleManager()->addNodeParticle(client,
|
||||||
player, nodepos, n, features);
|
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;
|
runData.dig_instantly = runData.dig_time_complete == 0;
|
||||||
if (client->modsLoaded() && client->getScript()->on_punchnode(nodepos, n))
|
if (client->modsLoaded() && client->getScript()->on_punchnode(nodepos, n))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
client->interact(INTERACT_START_DIGGING, pointed);
|
client->interact(INTERACT_START_DIGGING, pointed);
|
||||||
runData.digging = true;
|
runData.digging = true;
|
||||||
runData.btn_down_for_dig = 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;
|
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.exists() && params.diggable) {
|
||||||
if (sound_dig.name == "__group") {
|
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
|
// Don't show cracks if not diggable
|
||||||
if (runData.dig_time_complete >= 100000.0) {
|
if (runData.dig_time_complete >= 100000.0) {
|
||||||
} else if (runData.dig_index < crack_animation_length) {
|
} else if (runData.dig_index < crack_animation_length) {
|
||||||
//TimeTaker timer("client.setTempMod");
|
|
||||||
//infostream<<"dig_index="<<dig_index<<std::endl;
|
|
||||||
client->setCrack(runData.dig_index, nodepos);
|
client->setCrack(runData.dig_index, nodepos);
|
||||||
} else {
|
} else {
|
||||||
infostream << "Digging completed" << std::endl;
|
infostream << "Digging completed" << std::endl;
|
||||||
@ -3792,38 +3789,31 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
|
|||||||
else if (runData.dig_instantly)
|
else if (runData.dig_instantly)
|
||||||
runData.nodig_delay_timer = 0.15;
|
runData.nodig_delay_timer = 0.15;
|
||||||
|
|
||||||
bool is_valid_position;
|
if (client->modsLoaded() &&
|
||||||
MapNode wasnode = map.getNode(nodepos, &is_valid_position);
|
client->getScript()->on_dignode(nodepos, n)) {
|
||||||
if (is_valid_position) {
|
return;
|
||||||
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 (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);
|
client->interact(INTERACT_DIGGING_COMPLETED, pointed);
|
||||||
|
|
||||||
if (m_cache_enable_particles) {
|
if (m_cache_enable_particles) {
|
||||||
const ContentFeatures &features =
|
|
||||||
client->getNodeDefManager()->get(wasnode);
|
|
||||||
client->getParticleManager()->addDiggingParticles(client,
|
client->getParticleManager()->addDiggingParticles(client,
|
||||||
player, nodepos, wasnode, features);
|
player, nodepos, n, features);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Send event to trigger sound
|
// 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) {
|
if (runData.dig_time_complete < 100000.0) {
|
||||||
|
@ -250,7 +250,7 @@ std::string ItemStack::getItemString(bool include_meta) const
|
|||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ItemStack::getDescription(IItemDefManager *itemdef) const
|
std::string ItemStack::getDescription(const IItemDefManager *itemdef) const
|
||||||
{
|
{
|
||||||
std::string desc = metadata.getString("description");
|
std::string desc = metadata.getString("description");
|
||||||
if (desc.empty())
|
if (desc.empty())
|
||||||
@ -258,7 +258,7 @@ std::string ItemStack::getDescription(IItemDefManager *itemdef) const
|
|||||||
return desc.empty() ? name : desc;
|
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");
|
std::string desc = metadata.getString("short_description");
|
||||||
if (desc.empty())
|
if (desc.empty())
|
||||||
|
@ -48,8 +48,8 @@ struct ItemStack
|
|||||||
// Returns the string used for inventory
|
// Returns the string used for inventory
|
||||||
std::string getItemString(bool include_meta = true) const;
|
std::string getItemString(bool include_meta = true) const;
|
||||||
// Returns the tooltip
|
// Returns the tooltip
|
||||||
std::string getDescription(IItemDefManager *itemdef) const;
|
std::string getDescription(const IItemDefManager *itemdef) const;
|
||||||
std::string getShortDescription(IItemDefManager *itemdef) const;
|
std::string getShortDescription(const IItemDefManager *itemdef) const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Quantity methods
|
Quantity methods
|
||||||
@ -82,13 +82,13 @@ struct ItemStack
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Maximum size of a stack
|
// Maximum size of a stack
|
||||||
u16 getStackMax(IItemDefManager *itemdef) const
|
u16 getStackMax(const IItemDefManager *itemdef) const
|
||||||
{
|
{
|
||||||
return itemdef->get(name).stack_max;
|
return itemdef->get(name).stack_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Number of items that can be added to this stack
|
// 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);
|
u16 max = getStackMax(itemdef);
|
||||||
if (count >= max)
|
if (count >= max)
|
||||||
@ -97,7 +97,7 @@ struct ItemStack
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns false if item is not known and cannot be used
|
// 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);
|
return itemdef->isKnown(name);
|
||||||
}
|
}
|
||||||
@ -105,14 +105,14 @@ struct ItemStack
|
|||||||
// Returns a pointer to the item definition struct,
|
// Returns a pointer to the item definition struct,
|
||||||
// or a fallback one (name="unknown") if the item is unknown.
|
// or a fallback one (name="unknown") if the item is unknown.
|
||||||
const ItemDefinition& getDefinition(
|
const ItemDefinition& getDefinition(
|
||||||
IItemDefManager *itemdef) const
|
const IItemDefManager *itemdef) const
|
||||||
{
|
{
|
||||||
return itemdef->get(name);
|
return itemdef->get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get tool digging properties, or those of the hand if not a tool
|
// Get tool digging properties, or those of the hand if not a tool
|
||||||
const ToolCapabilities& getToolCapabilities(
|
const ToolCapabilities& getToolCapabilities(
|
||||||
IItemDefManager *itemdef) const
|
const IItemDefManager *itemdef) const
|
||||||
{
|
{
|
||||||
const ToolCapabilities *item_cap =
|
const ToolCapabilities *item_cap =
|
||||||
itemdef->get(name).tool_capabilities;
|
itemdef->get(name).tool_capabilities;
|
||||||
@ -127,7 +127,7 @@ struct ItemStack
|
|||||||
|
|
||||||
// Wear out (only tools)
|
// Wear out (only tools)
|
||||||
// Returns true if the item is (was) a tool
|
// 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)
|
if(getDefinition(itemdef).type == ITEM_TOOL)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user