mirror of
https://github.com/minetest/minetest.git
synced 2025-01-11 15:57:29 +01:00
Clean up Game::handleDigging() and some related parts
This commit is contained in:
parent
13a8948edd
commit
bbdb1929c6
@ -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="<<dig_index<<std::endl;
|
||||
client->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)) {
|
||||
client->getScript()->on_dignode(nodepos, n)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ContentFeatures &f = client->ndef()->get(wasnode);
|
||||
if (f.node_dig_prediction == "air") {
|
||||
if (features.node_dig_prediction == "air") {
|
||||
client->removeNode(nodepos);
|
||||
} else if (!f.node_dig_prediction.empty()) {
|
||||
} else if (!features.node_dig_prediction.empty()) {
|
||||
content_t id;
|
||||
bool found = client->ndef()->getId(f.node_dig_prediction, 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) {
|
||||
|
@ -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())
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user