summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorDS-Minetest <vorunbekannt75@web.de>2019-09-19 19:50:15 +0200
committersfan5 <sfan5@live.de>2019-09-22 22:12:49 +0200
commitcf78e37da37d7565a6602034f1ba6c244936bc0c (patch)
treed8f60709e93b69467cd19435c11946650c49d175 /src/client
parent70f9e1aafa6cd7a2b2d204609cab6cc26539cdb9 (diff)
downloadminetest-cf78e37da37d7565a6602034f1ba6c244936bc0c.tar.gz
minetest-cf78e37da37d7565a6602034f1ba6c244936bc0c.tar.bz2
minetest-cf78e37da37d7565a6602034f1ba6c244936bc0c.zip
Move the code for meta formspec into bool Game::nodePlacement(const ItemDefinition &selected_def,
Diffstat (limited to 'src/client')
-rw-r--r--src/client/game.cpp76
1 files changed, 39 insertions, 37 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 042b61a78..722e6d0ad 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -802,7 +802,8 @@ private:
void updateChat(f32 dtime, const v2u32 &screensize);
bool nodePlacement(const ItemDefinition &selected_def, const ItemStack &selected_item,
- const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed);
+ const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed,
+ const NodeMetadata *meta);
static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
InputHandler *input = nullptr;
@@ -3199,50 +3200,26 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
runData.repeat_rightclick_timer = 0;
infostream << "Ground right-clicked" << std::endl;
- if (meta && !meta->getString("formspec").empty() && !random_input
- && !isKeyDown(KeyType::SNEAK)) {
- // Report right click to server
- if (nodedef_manager->get(map.getNode(nodepos)).rightclickable) {
- client->interact(INTERACT_PLACE, pointed);
- }
-
- infostream << "Launching custom inventory view" << std::endl;
+ camera->setDigging(1); // right click animation (always shown for feedback)
- InventoryLocation inventoryloc;
- inventoryloc.setNodeMeta(nodepos);
+ soundmaker->m_player_rightpunch_sound = SimpleSoundSpec();
- NodeMetadataFormSource *fs_src = new NodeMetadataFormSource(
- &client->getEnv().getClientMap(), nodepos);
- TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
-
- auto *&formspec = m_game_ui->updateFormspec("");
- GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
- txt_dst, client->getFormspecPrepend());
-
- formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
- } else {
- // Report right click to server
+ // If the wielded item has node placement prediction,
+ // make that happen
+ // And also set the sound and send the interact
+ // But first check for meta formspec and rightclickable
+ auto &def = selected_item.getDefinition(itemdef_manager);
+ bool placed = nodePlacement(def, selected_item, nodepos, neighbourpos,
+ pointed, meta);
- 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 = nodePlacement(def, selected_item, nodepos, neighbourpos,
- pointed);
-
- if (placed && client->modsLoaded())
- client->getScript()->on_placenode(pointed, def);
- }
+ if (placed && client->modsLoaded())
+ client->getScript()->on_placenode(pointed, def);
}
}
bool Game::nodePlacement(const ItemDefinition &selected_def,
const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos,
- const PointedThing &pointed)
+ const PointedThing &pointed, const NodeMetadata *meta)
{
std::string prediction = selected_def.node_placement_prediction;
const NodeDefManager *nodedef = client->ndef();
@@ -3256,6 +3233,31 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
return false;
}
+ // formspec in meta
+ if (meta && !meta->getString("formspec").empty() && !random_input
+ && !isKeyDown(KeyType::SNEAK)) {
+ // on_rightclick callbacks are called anyway
+ if (nodedef_manager->get(map.getNode(nodepos)).rightclickable)
+ client->interact(INTERACT_PLACE, pointed);
+
+ infostream << "Launching custom inventory view" << std::endl;
+
+ InventoryLocation inventoryloc;
+ inventoryloc.setNodeMeta(nodepos);
+
+ NodeMetadataFormSource *fs_src = new NodeMetadataFormSource(
+ &client->getEnv().getClientMap(), nodepos);
+ TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
+
+ auto *&formspec = m_game_ui->updateFormspec("");
+ GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
+ txt_dst, client->getFormspecPrepend());
+
+ formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
+ return false;
+ }
+
+ // on_rightclick callback
if (prediction.empty() || (nodedef->get(node).rightclickable &&
!isKeyDown(KeyType::SNEAK))) {
// Report to server