nodePlacement: add sort of working force_sneak

doesn't work with mcl2 and stuff
i suspect client->interact being annoying
This commit is contained in:
cron 2020-11-03 20:03:50 +00:00
parent f08a0cfce7
commit 16577548e6
3 changed files with 7 additions and 6 deletions

View File

@ -2589,13 +2589,14 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
bool Game::nodePlacement(const ItemDefinition &selected_def,
const ItemStack &selected_item, const v3s16 &nodepos, const v3s16 &neighbourpos,
const PointedThing &pointed, const NodeMetadata *meta)
const PointedThing &pointed, const NodeMetadata *meta, bool force_sneak)
{
std::string prediction = selected_def.node_placement_prediction;
const NodeDefManager *nodedef = client->ndef();
ClientMap &map = client->getEnv().getClientMap();
MapNode node;
bool is_valid_position;
bool sneaking = force_sneak or isKeyDown(KeyType::SNEAK);
node = map.getNode(nodepos, &is_valid_position);
if (!is_valid_position) {
@ -2605,7 +2606,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
// formspec in meta
if (meta && !meta->getString("formspec").empty() && !input->isRandom()
&& !isKeyDown(KeyType::SNEAK)) {
&& !sneaking) {
// on_rightclick callbacks are called anyway
if (nodedef_manager->get(map.getNode(nodepos)).rightclickable)
client->interact(INTERACT_PLACE, pointed);
@ -2628,8 +2629,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
}
// on_rightclick callback
if (prediction.empty() || (nodedef->get(node).rightclickable &&
!isKeyDown(KeyType::SNEAK))) {
if (prediction.empty() || (nodedef->get(node).rightclickable
&& !sneaking)) {
// Report to server
client->interact(INTERACT_PLACE, pointed);
return false;

View File

@ -838,7 +838,7 @@ public:
bool nodePlacement(const ItemDefinition &selected_def, const ItemStack &selected_item,
const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed,
const NodeMetadata *meta);
const NodeMetadata *meta, bool force_sneak = false);
static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
InputHandler *input = nullptr;

View File

@ -439,7 +439,7 @@ int ModApiClient::l_place_node(lua_State *L)
pointed.node_abovesurface = pos;
pointed.node_undersurface = pos;
NodeMetadata *meta = map.getNodeMetadata(pos);
g_game->nodePlacement(selected_def, selected_item, pos, pos, pointed, meta);
g_game->nodePlacement(selected_def, selected_item, pos, pos, pointed, meta, true); // always force sneak
return 0;
}