Skip to content

Commit cf78e37

Browse files
Desoursfan5
authored andcommittedSep 22, 2019
Move the code for meta formspec into bool Game::nodePlacement(const ItemDefinition &selected_def,
1 parent 70f9e1a commit cf78e37

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed
 

‎src/client/game.cpp

+39-37
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ class Game {
802802
void updateChat(f32 dtime, const v2u32 &screensize);
803803

804804
bool nodePlacement(const ItemDefinition &selected_def, const ItemStack &selected_item,
805-
const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed);
805+
const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed,
806+
const NodeMetadata *meta);
806807
static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
807808

808809
InputHandler *input = nullptr;
@@ -3199,50 +3200,26 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
31993200
runData.repeat_rightclick_timer = 0;
32003201
infostream << "Ground right-clicked" << std::endl;
32013202

3202-
if (meta && !meta->getString("formspec").empty() && !random_input
3203-
&& !isKeyDown(KeyType::SNEAK)) {
3204-
// Report right click to server
3205-
if (nodedef_manager->get(map.getNode(nodepos)).rightclickable) {
3206-
client->interact(INTERACT_PLACE, pointed);
3207-
}
3208-
3209-
infostream << "Launching custom inventory view" << std::endl;
3203+
camera->setDigging(1); // right click animation (always shown for feedback)
32103204

3211-
InventoryLocation inventoryloc;
3212-
inventoryloc.setNodeMeta(nodepos);
3205+
soundmaker->m_player_rightpunch_sound = SimpleSoundSpec();
32133206

3214-
NodeMetadataFormSource *fs_src = new NodeMetadataFormSource(
3215-
&client->getEnv().getClientMap(), nodepos);
3216-
TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
3217-
3218-
auto *&formspec = m_game_ui->updateFormspec("");
3219-
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
3220-
txt_dst, client->getFormspecPrepend());
3221-
3222-
formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
3223-
} else {
3224-
// Report right click to server
3207+
// If the wielded item has node placement prediction,
3208+
// make that happen
3209+
// And also set the sound and send the interact
3210+
// But first check for meta formspec and rightclickable
3211+
auto &def = selected_item.getDefinition(itemdef_manager);
3212+
bool placed = nodePlacement(def, selected_item, nodepos, neighbourpos,
3213+
pointed, meta);
32253214

3226-
camera->setDigging(1); // right click animation (always shown for feedback)
3227-
3228-
soundmaker->m_player_rightpunch_sound = SimpleSoundSpec();
3229-
3230-
// If the wielded item has node placement prediction,
3231-
// make that happen
3232-
// And also set the sound and send the interact
3233-
auto &def = selected_item.getDefinition(itemdef_manager);
3234-
bool placed = nodePlacement(def, selected_item, nodepos, neighbourpos,
3235-
pointed);
3236-
3237-
if (placed && client->modsLoaded())
3238-
client->getScript()->on_placenode(pointed, def);
3239-
}
3215+
if (placed && client->modsLoaded())
3216+
client->getScript()->on_placenode(pointed, def);
32403217
}
32413218
}
32423219

32433220
bool Game::nodePlacement(const ItemDefinition &selected_def,
32443221
const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos,
3245-
const PointedThing &pointed)
3222+
const PointedThing &pointed, const NodeMetadata *meta)
32463223
{
32473224
std::string prediction = selected_def.node_placement_prediction;
32483225
const NodeDefManager *nodedef = client->ndef();
@@ -3256,6 +3233,31 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
32563233
return false;
32573234
}
32583235

3236+
// formspec in meta
3237+
if (meta && !meta->getString("formspec").empty() && !random_input
3238+
&& !isKeyDown(KeyType::SNEAK)) {
3239+
// on_rightclick callbacks are called anyway
3240+
if (nodedef_manager->get(map.getNode(nodepos)).rightclickable)
3241+
client->interact(INTERACT_PLACE, pointed);
3242+
3243+
infostream << "Launching custom inventory view" << std::endl;
3244+
3245+
InventoryLocation inventoryloc;
3246+
inventoryloc.setNodeMeta(nodepos);
3247+
3248+
NodeMetadataFormSource *fs_src = new NodeMetadataFormSource(
3249+
&client->getEnv().getClientMap(), nodepos);
3250+
TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
3251+
3252+
auto *&formspec = m_game_ui->updateFormspec("");
3253+
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
3254+
txt_dst, client->getFormspecPrepend());
3255+
3256+
formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
3257+
return false;
3258+
}
3259+
3260+
// on_rightclick callback
32593261
if (prediction.empty() || (nodedef->get(node).rightclickable &&
32603262
!isKeyDown(KeyType::SNEAK))) {
32613263
// Report to server

0 commit comments

Comments
 (0)
Please sign in to comment.