Added minetest.close_formspec
This commit is contained in:
parent
f825cf0e35
commit
5bead7daaf
@ -79,22 +79,27 @@ local function check_tool(stack, node_groups, old_best_time)
|
||||
return best_time < old_best_time, best_time
|
||||
end
|
||||
|
||||
core.register_on_punchnode(function(pos, node)
|
||||
if not minetest.settings:get_bool("autotool") then return end
|
||||
function core.select_best_tool(nodename)
|
||||
local player = minetest.localplayer
|
||||
local inventory = minetest.get_inventory("current_player")
|
||||
local node_groups = minetest.get_node_def(node.name).groups
|
||||
local node_groups = minetest.get_node_def(nodename).groups
|
||||
local new_index = player:get_wield_index()
|
||||
local is_better, best_time = false, math.huge
|
||||
is_better, best_time = check_tool(player:get_wielded_item(), node_groups, best_time)
|
||||
is_better, best_time = check_tool(inventory.hand[1], node_groups, best_time)
|
||||
for index, stack in pairs(inventory.main) do
|
||||
for index, stack in ipairs(inventory.main) do
|
||||
is_better, best_time = check_tool(stack, node_groups, best_time)
|
||||
if is_better then
|
||||
new_index = index
|
||||
end
|
||||
end
|
||||
player:set_wield_index(new_index)
|
||||
end
|
||||
|
||||
core.register_on_punchnode(function(pos, node)
|
||||
if not minetest.settings:get_bool("autotool") then
|
||||
core.select_best_tool(node.name)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Enderchest
|
||||
|
@ -49,4 +49,8 @@ function core.get_pointed_thing()
|
||||
local def = core.get_item_def(item:get_name())
|
||||
local ray = core.raycast(pos, pos2, true, core.settings:get_bool("point_liquids") or def and def.liquids_pointable)
|
||||
return ray and ray:next()
|
||||
end
|
||||
end
|
||||
|
||||
function core.close_formspec(formname)
|
||||
return core.show_formspec(formname, "")
|
||||
end
|
||||
|
@ -1107,6 +1107,14 @@ Passed to `HTTPApiTable.fetch` callback. Returned by
|
||||
* Reference to the camera object. See [`Camera`](#camera) class reference for methods.
|
||||
* `minetest.show_formspec(formname, formspec)` : returns true on success
|
||||
* Shows a formspec to the player
|
||||
* `minetest.close_formspec(formname)`
|
||||
* `formname`: has to exactly match the one given in `show_formspec`, or the
|
||||
formspec will not close.
|
||||
* calling `show_formspec(formname, "")` is equal to this
|
||||
expression.
|
||||
* to close a formspec regardless of the formname, call
|
||||
`minetest.close_formspec("")`.
|
||||
**USE THIS ONLY WHEN ABSOLUTELY NECESSARY!**
|
||||
* `minetest.display_chat_message(message)` returns true on success
|
||||
* Shows a chat message to the current player.
|
||||
|
||||
|
@ -1889,13 +1889,21 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation
|
||||
}
|
||||
|
||||
void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrientation *cam)
|
||||
{
|
||||
FormspecFormSource *fs_src = new FormspecFormSource(*event->show_formspec.formspec);
|
||||
LocalFormspecHandler *txt_dst =
|
||||
new LocalFormspecHandler(*event->show_formspec.formname, client);
|
||||
GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, &input->joystick,
|
||||
{
|
||||
if (event->show_formspec.formspec->empty()) {
|
||||
auto formspec = m_game_ui->getFormspecGUI();
|
||||
if (formspec && (event->show_formspec.formname->empty()
|
||||
|| *(event->show_formspec.formname) == m_game_ui->getFormspecName())) {
|
||||
formspec->quitMenu();
|
||||
}
|
||||
} else {
|
||||
FormspecFormSource *fs_src = new FormspecFormSource(*event->show_formspec.formspec);
|
||||
LocalFormspecHandler *txt_dst =
|
||||
new LocalFormspecHandler(*event->show_formspec.formname, client);
|
||||
GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, &input->joystick,
|
||||
fs_src, txt_dst, client->getFormspecPrepend(), sound);
|
||||
|
||||
}
|
||||
|
||||
delete event->show_formspec.formspec;
|
||||
delete event->show_formspec.formname;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user