mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
Trigger on_place in many situations even if prediction failed
This commit is contained in:
parent
c413eeb026
commit
0b5c5499ec
@ -801,8 +801,8 @@ private:
|
||||
|
||||
void updateChat(f32 dtime, const v2u32 &screensize);
|
||||
|
||||
bool nodePlacementPrediction(const ItemDefinition &selected_def,
|
||||
const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos);
|
||||
bool nodePlacement(const ItemDefinition &selected_def, const ItemStack &selected_item,
|
||||
const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed);
|
||||
static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
|
||||
|
||||
InputHandler *input = nullptr;
|
||||
@ -3225,39 +3225,24 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
|
||||
|
||||
camera->setDigging(1); // right click animation (always shown for feedback)
|
||||
|
||||
soundmaker->m_player_rightpunch_sound = SimpleSoundSpec();
|
||||
|
||||
// If the wielded item has node placement prediction,
|
||||
// make that happen
|
||||
// And also set the sound and send the interact
|
||||
auto &def = selected_item.getDefinition(itemdef_manager);
|
||||
bool placed = nodePlacementPrediction(def, selected_item, nodepos,
|
||||
neighbourpos);
|
||||
bool placed = nodePlacement(def, selected_item, nodepos, neighbourpos,
|
||||
pointed);
|
||||
|
||||
if (placed) {
|
||||
// Report to server
|
||||
client->interact(INTERACT_PLACE, pointed);
|
||||
// Read the sound
|
||||
soundmaker->m_player_rightpunch_sound =
|
||||
def.sound_place;
|
||||
|
||||
if (client->modsLoaded())
|
||||
if (placed && client->modsLoaded())
|
||||
client->getScript()->on_placenode(pointed, def);
|
||||
} else {
|
||||
soundmaker->m_player_rightpunch_sound =
|
||||
SimpleSoundSpec();
|
||||
|
||||
if (def.node_placement_prediction.empty() ||
|
||||
nodedef_manager->get(map.getNode(nodepos)).rightclickable) {
|
||||
client->interact(INTERACT_PLACE, pointed); // Report to server
|
||||
} else {
|
||||
soundmaker->m_player_rightpunch_sound =
|
||||
def.sound_place_failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Game::nodePlacementPrediction(const ItemDefinition &selected_def,
|
||||
const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos)
|
||||
bool Game::nodePlacement(const ItemDefinition &selected_def,
|
||||
const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos,
|
||||
const PointedThing &pointed)
|
||||
{
|
||||
std::string prediction = selected_def.node_placement_prediction;
|
||||
const NodeDefManager *nodedef = client->ndef();
|
||||
@ -3266,28 +3251,37 @@ bool Game::nodePlacementPrediction(const ItemDefinition &selected_def,
|
||||
bool is_valid_position;
|
||||
|
||||
node = map.getNode(nodepos, &is_valid_position);
|
||||
if (!is_valid_position)
|
||||
if (!is_valid_position) {
|
||||
soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!prediction.empty() && !(nodedef->get(node).rightclickable &&
|
||||
if (prediction.empty() || (nodedef->get(node).rightclickable &&
|
||||
!isKeyDown(KeyType::SNEAK))) {
|
||||
// Report to server
|
||||
client->interact(INTERACT_PLACE, pointed);
|
||||
return false;
|
||||
}
|
||||
|
||||
verbosestream << "Node placement prediction for "
|
||||
<< selected_item.name << " is "
|
||||
<< selected_def.name << " is "
|
||||
<< prediction << std::endl;
|
||||
v3s16 p = neighbourpos;
|
||||
|
||||
// Place inside node itself if buildable_to
|
||||
MapNode n_under = map.getNode(nodepos, &is_valid_position);
|
||||
if (is_valid_position)
|
||||
{
|
||||
if (nodedef->get(n_under).buildable_to)
|
||||
if (is_valid_position) {
|
||||
if (nodedef->get(n_under).buildable_to) {
|
||||
p = nodepos;
|
||||
else {
|
||||
} else {
|
||||
node = map.getNode(p, &is_valid_position);
|
||||
if (is_valid_position &&!nodedef->get(node).buildable_to)
|
||||
if (is_valid_position && !nodedef->get(node).buildable_to) {
|
||||
// Report to server
|
||||
client->interact(INTERACT_PLACE, pointed);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find id of predicted node
|
||||
content_t id;
|
||||
@ -3295,9 +3289,12 @@ bool Game::nodePlacementPrediction(const ItemDefinition &selected_def,
|
||||
|
||||
if (!found) {
|
||||
errorstream << "Node placement prediction failed for "
|
||||
<< selected_item.name << " (places "
|
||||
<< selected_def.name << " (places "
|
||||
<< prediction
|
||||
<< ") - Name not known" << std::endl;
|
||||
// Handle this as if prediction was empty
|
||||
// Report to server
|
||||
client->interact(INTERACT_PLACE, pointed);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3350,9 +3347,12 @@ bool Game::nodePlacementPrediction(const ItemDefinition &selected_def,
|
||||
else
|
||||
pp = p + v3s16(0, -1, 0);
|
||||
|
||||
if (!nodedef->get(map.getNode(pp)).walkable)
|
||||
if (!nodedef->get(map.getNode(pp)).walkable) {
|
||||
// Report to server
|
||||
client->interact(INTERACT_PLACE, pointed);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply color
|
||||
if ((predicted_f.param_type_2 == CPT2_COLOR
|
||||
@ -3364,12 +3364,10 @@ bool Game::nodePlacementPrediction(const ItemDefinition &selected_def,
|
||||
s32 index = mystoi(indexstr);
|
||||
if (predicted_f.param_type_2 == CPT2_COLOR) {
|
||||
param2 = index;
|
||||
} else if (predicted_f.param_type_2
|
||||
== CPT2_COLORED_WALLMOUNTED) {
|
||||
} else if (predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED) {
|
||||
// param2 = pure palette index + other
|
||||
param2 = (index & 0xf8) | (param2 & 0x07);
|
||||
} else if (predicted_f.param_type_2
|
||||
== CPT2_COLORED_FACEDIR) {
|
||||
} else if (predicted_f.param_type_2 == CPT2_COLORED_FACEDIR) {
|
||||
// param2 = pure palette index + other
|
||||
param2 = (index & 0xe0) | (param2 & 0x1f);
|
||||
}
|
||||
@ -3390,20 +3388,25 @@ bool Game::nodePlacementPrediction(const ItemDefinition &selected_def,
|
||||
(nodedef->get(n).walkable &&
|
||||
neighbourpos != player->getStandingNodePos() + v3s16(0, 1, 0) &&
|
||||
neighbourpos != player->getStandingNodePos() + v3s16(0, 2, 0))) {
|
||||
|
||||
// This triggers the required mesh update too
|
||||
client->addNode(p, n);
|
||||
// Report to server
|
||||
client->interact(INTERACT_PLACE, pointed);
|
||||
// A node is predicted, also play a sound
|
||||
soundmaker->m_player_rightpunch_sound = selected_def.sound_place;
|
||||
return true;
|
||||
} else {
|
||||
soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed;
|
||||
return false;
|
||||
}
|
||||
} catch (InvalidPositionException &e) {
|
||||
errorstream << "Node placement prediction failed for "
|
||||
<< selected_item.name << " (places "
|
||||
<< selected_def.name << " (places "
|
||||
<< prediction
|
||||
<< ") - Position not loaded" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Game::handlePointingAtObject(const PointedThing &pointed,
|
||||
|
Loading…
Reference in New Issue
Block a user