From e610149c0cc3516b61115541f2f4f78344a0bb2c Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 6 Jul 2020 15:50:55 +0200 Subject: [PATCH] Initial Commit --- builtin/client/cheats.lua | 160 ------------------ builtin/client/init.lua | 2 +- builtin/client/pos.lua | 19 +++ clientmods/preview/example.lua | 2 - clientmods/preview/examples/first.lua | 1 - clientmods/preview/init.lua | 229 -------------------------- src/client/client.h | 6 +- src/client/content_cao.cpp | 3 + src/client/game.cpp | 50 +++++- src/client/game.h | 3 + src/client/inputhandler.cpp | 3 + src/client/keys.h | 5 +- src/client/mapblock_mesh.cpp | 20 ++- src/client/mesh_generator_thread.h | 2 +- src/gui/guiInventoryList.cpp | 45 +++-- src/gui/guiInventoryList.h | 8 +- src/network/clientpackethandler.cpp | 9 + src/nodedef.cpp | 6 - src/script/lua_api/l_localplayer.cpp | 2 + 19 files changed, 147 insertions(+), 428 deletions(-) delete mode 100644 builtin/client/cheats.lua create mode 100644 builtin/client/pos.lua delete mode 100644 clientmods/preview/example.lua delete mode 100644 clientmods/preview/examples/first.lua delete mode 100644 clientmods/preview/init.lua diff --git a/builtin/client/cheats.lua b/builtin/client/cheats.lua deleted file mode 100644 index 9d7fd932c..000000000 --- a/builtin/client/cheats.lua +++ /dev/null @@ -1,160 +0,0 @@ -core.register_chatcommand("set", { - params = "([-n] ) | ", - description = "Set or read client configuration setting", - privs = {server=true}, - func = function(param) - local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)") - if arg and arg == "-n" and setname and setvalue then - core.settings:set(setname, setvalue) - return true, setname .. " = " .. setvalue - end - - setname, setvalue = string.match(param, "([^ ]+) (.+)") - if setname and setvalue then - if not core.settings:get(setname) then - return false, "Failed. Use '.set -n ' to create a new setting." - end - core.settings:set(setname, setvalue) - return true, setname .. " = " .. setvalue - end - - setname = string.match(param, "([^ ]+)") - if setname then - setvalue = core.settings:get(setname) - if not setvalue then - setvalue = "" - end - return true, setname .. " = " .. setvalue - end - - return false, "Invalid parameters (see .help set)." - end, -}) - -function core.parse_pos(param) - local p = {} - p.x, p.y, p.z = string.match(param, "^([~|%d.-]+)[, ] *([~|%d.-]+)[, ] *([~|%d.-]+)$") - for k, v in pairs(p) do - if p[k] == "~" then - p[k] = core.localplayer:get_pos()[k] - else - p[k] = tonumber(v) - end - end - if p.x and p.y and p.z then - local lm = 31000 - if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then - return false, "Position out of Map bounds." - end - return true, p - end - return false, "Invalid position (" .. param .. ")" -end - -core.register_chatcommand("teleport", { - params = ",,", - description = "Teleport to position", - func = function(param) - local success, pos = core.parse_pos(param) - if success then - core.localplayer:set_pos(pos) - return true, "Teleporting to " .. core.pos_to_string(pos) - end - return false, pos - end, -}) - -core.register_chatcommand("place", { - params = ",,", - description = "Place wielded item", - func = function(param) - local success, pos = core.parse_pos(param) - if success then - core.place_node(pos) - return true, "Node placed at " .. core.pos_to_string(pos) - end - return false, pos - end, -}) - -core.register_chatcommand("dig", { - params = ",,", - description = "Dig node", - func = function(param) - local success, pos = core.parse_pos(param) - if success then - core.dig_node(pos) - return true, "Node at " .. core.pos_to_string(pos) .. " dug" - end - return false, pos - end, -}) - -core.register_chatcommand("kill", { - description = "Kill yourself", - func = function(param) - core.send_damage(core.localplayer:get_hp()) - end, -}) - -core.register_chatcommand("scan", { - description = "Scan for one or multible nodes in a radius around you", - param = " node1[,node2...]", - func = function(param) - local radius = tonumber(param:split(" ")[1]) - local nodes = param:split(" ")[2]:split(",") - local pos = core.localplayer:get_pos() - local fpos = core.find_node_near(pos, radius, nodes, true) - if fpos then - return true, "Found " .. table.concat(nodes, " or ") .. " at " .. core.pos_to_string(fpos) - end - return false, "None of " .. table.concat(nodes, " or ") .. " found in a radius of " .. tostring(radius) - end, -}) - -core.register_chatcommand("digaround", { - description = "Scan for one or multible nodes in a radius around you", - param = " node1[,node2...]", - func = function(param) - local radius = tonumber(param:split(" ")[1]) - local nodes = param:split(" ")[2]:split(",") - local function loop() - local fpos = core.find_node_near(core.localplayer:get_pos(), radius, nodes, true) - if fpos then core.dig_node(fpos) end - core.after(0, loop) - end - loop() - end, -}) - -local keep_digging = false - -core.register_chatcommand("keepdigging", { - params = ",,", - description = "Dig node again and again", - func = function(param) - local success, pos = core.parse_pos(param) - if success then - keep_digging = true - local function loop() - core.dig_node(pos) - if keep_digging then - core.after(0.1, loop) - end - end - loop() - end - end, -}) - -core.register_chatcommand("stopdigging", { - description = "Stop diggin", - func = function() - keep_digging = false - end, -}) - -core.register_on_punchnode(function(pos) - --core.dig_node(pos) -end) - diff --git a/builtin/client/init.lua b/builtin/client/init.lua index 6c024f02e..f3c1a4c82 100644 --- a/builtin/client/init.lua +++ b/builtin/client/init.lua @@ -9,5 +9,5 @@ dofile(commonpath .. "chatcommands.lua") dofile(commonpath .. "vector.lua") dofile(clientpath .. "death_formspec.lua") dofile(clientpath .. "chatcommands.lua") -dofile(clientpath .. "cheats.lua") +dofile(clientpath .. "pos.lua") diff --git a/builtin/client/pos.lua b/builtin/client/pos.lua new file mode 100644 index 000000000..618c142e7 --- /dev/null +++ b/builtin/client/pos.lua @@ -0,0 +1,19 @@ +function core.parse_pos(param) + local p = {} + p.x, p.y, p.z = string.match(param, "^([~|%d.-]+)[, ] *([~|%d.-]+)[, ] *([~|%d.-]+)$") + for k, v in pairs(p) do + if p[k] == "~" then + p[k] = core.localplayer:get_pos()[k] + else + p[k] = tonumber(v) + end + end + if p.x and p.y and p.z then + local lm = 31000 + if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then + return false, "Position out of Map bounds." + end + return true, p + end + return false, "Invalid position (" .. param .. ")" +end diff --git a/clientmods/preview/example.lua b/clientmods/preview/example.lua deleted file mode 100644 index 2f42eef64..000000000 --- a/clientmods/preview/example.lua +++ /dev/null @@ -1,2 +0,0 @@ -print("Loaded example file!, loading more examples") -dofile(core.get_modpath(core.get_current_modname()) .. "/examples/first.lua") diff --git a/clientmods/preview/examples/first.lua b/clientmods/preview/examples/first.lua deleted file mode 100644 index c24f461e6..000000000 --- a/clientmods/preview/examples/first.lua +++ /dev/null @@ -1 +0,0 @@ -print("loaded first.lua example file") diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua deleted file mode 100644 index 5777adcaf..000000000 --- a/clientmods/preview/init.lua +++ /dev/null @@ -1,229 +0,0 @@ -local modname = assert(core.get_current_modname()) -local modstorage = core.get_mod_storage() -local mod_channel - -dofile(core.get_modpath(modname) .. "example.lua") - -core.register_on_shutdown(function() - print("[PREVIEW] shutdown client") -end) -local id = nil - -do - local server_info = core.get_server_info() - print("Server version: " .. server_info.protocol_version) - print("Server ip: " .. server_info.ip) - print("Server address: " .. server_info.address) - print("Server port: " .. server_info.port) - - print("CSM restrictions: " .. dump(core.get_csm_restrictions())) - - local l1, l2 = core.get_language() - print("Configured language: " .. l1 .. " / " .. l2) -end - -mod_channel = core.mod_channel_join("experimental_preview") - -core.after(4, function() - if mod_channel:is_writeable() then - mod_channel:send_all("preview talk to experimental") - end -end) - -core.after(1, function() - id = core.localplayer:hud_add({ - hud_elem_type = "text", - name = "example", - number = 0xff0000, - position = {x=0, y=1}, - offset = {x=8, y=-8}, - text = "You are using the preview mod", - scale = {x=200, y=60}, - alignment = {x=1, y=-1}, - }) -end) - -core.register_on_modchannel_message(function(channel, sender, message) - print("[PREVIEW][modchannels] Received message `" .. message .. "` on channel `" - .. channel .. "` from sender `" .. sender .. "`") - core.after(1, function() - mod_channel:send_all("CSM preview received " .. message) - end) -end) - -core.register_on_modchannel_signal(function(channel, signal) - print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `" - .. channel) -end) - -core.register_on_inventory_open(function(inventory) - print("INVENTORY OPEN") - print(dump(inventory)) - return false -end) - -core.register_on_placenode(function(pointed_thing, node) - print("The local player place a node!") - print("pointed_thing :" .. dump(pointed_thing)) - print("node placed :" .. dump(node)) - return false -end) - -core.register_on_item_use(function(itemstack, pointed_thing) - print("The local player used an item!") - print("pointed_thing :" .. dump(pointed_thing)) - print("item = " .. itemstack:get_name()) - - if not itemstack:is_empty() then - return false - end - - local pos = vector.add(core.localplayer:get_pos(), core.camera:get_offset()) - local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 100)) - - local rc = core.raycast(pos, pos2) - local i = rc:next() - print("[PREVIEW] raycast next: " .. dump(i)) - if i then - print("[PREVIEW] line of sight: " .. (core.line_of_sight(pos, i.above) and "yes" or "no")) - - local n1 = core.find_nodes_in_area(pos, i.under, {"default:stone"}) - local n2 = core.find_nodes_in_area_under_air(pos, i.under, {"default:stone"}) - print(("[PREVIEW] found %s nodes, %s nodes under air"):format( - n1 and #n1 or "?", n2 and #n2 or "?")) - end - - return false -end) - --- This is an example function to ensure it's working properly, should be removed before merge -core.register_on_receiving_chat_message(function(message) - print("[PREVIEW] Received message " .. message) - return false -end) - --- This is an example function to ensure it's working properly, should be removed before merge -core.register_on_sending_chat_message(function(message) - print("[PREVIEW] Sending message " .. message) - return false -end) - --- This is an example function to ensure it's working properly, should be removed before merge -core.register_on_hp_modification(function(hp) - print("[PREVIEW] HP modified " .. hp) -end) - --- This is an example function to ensure it's working properly, should be removed before merge -core.register_on_damage_taken(function(hp) - print("[PREVIEW] Damage taken " .. hp) -end) - --- This is an example function to ensure it's working properly, should be removed before merge -core.register_chatcommand("dump", { - func = function(param) - return true, dump(_G) - end, -}) - -core.register_chatcommand("colorize_test", { - func = function(param) - return true, core.colorize("red", param) - end, -}) - -core.register_chatcommand("test_node", { - func = function(param) - core.display_chat_message(dump(core.get_node({x=0, y=0, z=0}))) - core.display_chat_message(dump(core.get_node_or_nil({x=0, y=0, z=0}))) - end, -}) - -local function preview_minimap() - local minimap = core.ui.minimap - if not minimap then - print("[PREVIEW] Minimap is disabled. Skipping.") - return - end - minimap:set_mode(4) - minimap:show() - minimap:set_pos({x=5, y=50, z=5}) - minimap:set_shape(math.random(0, 1)) - - print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) .. - " position => " .. dump(minimap:get_pos()) .. - " angle => " .. dump(minimap:get_angle())) -end - -core.after(2, function() - print("[PREVIEW] loaded " .. modname .. " mod") - modstorage:set_string("current_mod", modname) - print(modstorage:get_string("current_mod")) - preview_minimap() -end) - -core.after(5, function() - if core.ui.minimap then - core.ui.minimap:show() - end - - print("[PREVIEW] Time of day " .. core.get_timeofday()) - - print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) .. - " max level " .. core.get_node_max_level({x=0, y=20, z=0})) - - print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10, - {"group:tree", "default:dirt", "default:stone"}))) -end) - -core.register_on_dignode(function(pos, node) - print("The local player dug a node!") - print("pos:" .. dump(pos)) - print("node:" .. dump(node)) - return false -end) - -core.register_on_punchnode(function(pos, node) - print("The local player punched a node!") - local itemstack = core.get_wielded_item() - --[[ - -- getters - print(dump(itemstack:is_empty())) - print(dump(itemstack:get_name())) - print(dump(itemstack:get_count())) - print(dump(itemstack:get_wear())) - print(dump(itemstack:get_meta())) - print(dump(itemstack:get_metadata() - print(dump(itemstack:is_known())) - --print(dump(itemstack:get_definition())) - print(dump(itemstack:get_tool_capabilities())) - print(dump(itemstack:to_string())) - print(dump(itemstack:to_table())) - -- setters - print(dump(itemstack:set_name("default:dirt"))) - print(dump(itemstack:set_count("95"))) - print(dump(itemstack:set_wear(934))) - print(dump(itemstack:get_meta())) - print(dump(itemstack:get_metadata())) - --]] - print(dump(itemstack:to_table())) - print("pos:" .. dump(pos)) - print("node:" .. dump(node)) - return false -end) - -core.register_chatcommand("privs", { - func = function(param) - return true, core.privs_to_string(minetest.get_privilege_list()) - end, -}) - -core.register_chatcommand("text", { - func = function(param) - return core.localplayer:hud_change(id, "text", param) - end, -}) - - -core.register_on_mods_loaded(function() - core.log("Yeah preview mod is loaded with other CSM mods.") -end) diff --git a/src/client/client.h b/src/client/client.h index 1e6ba4140..3c0c133e0 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -445,6 +445,10 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef { return m_env.getLocalPlayer()->formspec_prepend; } + + void sendPlayerPos(); + MeshUpdateThread m_mesh_update_thread; + private: void loadMods(); bool checkBuiltinIntegrity(); @@ -459,7 +463,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef void ReceiveAll(); - void sendPlayerPos(); void deleteAuthData(); // helper method shared with clientpackethandler @@ -492,7 +495,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef MtEventManager *m_event; - MeshUpdateThread m_mesh_update_thread; ClientEnvironment m_env; ParticleManager m_particle_manager; std::unique_ptr m_con; diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 5d719293a..fa2ed43c9 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -793,6 +793,9 @@ void GenericCAO::addToScene(ITextureSource *tsrc) void GenericCAO::updateLight(u8 light_at_pos) { + if (g_settings->getBool("fullbright")) + light_at_pos = 255; + // Don't update light of attached one if (getParent() != NULL) { return; diff --git a/src/client/game.cpp b/src/client/game.cpp index 9f8eb8c94..7c2249296 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1069,6 +1069,12 @@ void Game::processKeyInput() toggleFast(); } else if (wasKeyDown(KeyType::NOCLIP)) { toggleNoClip(); + } else if (wasKeyDown(KeyType::XRAY)) { + toggleXray(); + } else if (wasKeyDown(KeyType::FULLBRIGHT)) { + toggleFullbright(); + } else if (wasKeyDown(KeyType::KILLAURA)) { + toggleKillaura(); } else if (wasKeyDown(KeyType::MUTE)) { bool new_mute_sound = !g_settings->getBool("mute_sound"); g_settings->setBool("mute_sound", new_mute_sound); @@ -1327,6 +1333,44 @@ void Game::toggleNoClip() } } +void Game::toggleXray() +{ + bool xray = ! g_settings->getBool("xray"); + g_settings->set("xray", bool_to_cstr(xray)); + + if (xray) { + m_game_ui->showTranslatedStatusText("Xray enabled"); + } else { + m_game_ui->showTranslatedStatusText("Xray disabled"); + } + client->m_mesh_update_thread.doUpdate(); +} + +void Game::toggleFullbright() +{ + bool fullbright = ! g_settings->getBool("fullbright"); + g_settings->set("fullbright", bool_to_cstr(fullbright)); + + if (fullbright) { + m_game_ui->showTranslatedStatusText("Fullbright enabled"); + } else { + m_game_ui->showTranslatedStatusText("Fullbright disabled"); + } + client->m_mesh_update_thread.doUpdate(); +} + +void Game::toggleKillaura() +{ + bool killaura = ! g_settings->getBool("killaura"); + g_settings->set("killaura", bool_to_cstr(killaura)); + + if (killaura) { + m_game_ui->showTranslatedStatusText("Killaura enabled"); + } else { + m_game_ui->showTranslatedStatusText("Killaura disabled"); + } +} + void Game::toggleCinematic() { bool cinematic = !g_settings->getBool("cinematic"); @@ -2181,7 +2225,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) f32 d = getToolRange(selected_def, hand_item.getDefinition(itemdef_manager)); if(g_settings->getBool("increase_tool_range")) - d = 1000; + d = 5; core::line3d shootline; @@ -2697,7 +2741,7 @@ void Game::handlePointingAtObject(const PointedThing &pointed, m_game_ui->setInfoText(infotext); - if (input->getLeftState() || g_settings->getBool("killaura")) { + if (input->getLeftState() || (g_settings->getBool("killaura") && ! g_settings->getBool("killaura_fast"))) { bool do_punch = false; bool do_punch_damage = false; @@ -2707,7 +2751,7 @@ void Game::handlePointingAtObject(const PointedThing &pointed, runData.object_hit_delay_timer = object_hit_delay; } - if (input->getLeftClicked() || g_settings->getBool("killaura")) + if (input->getLeftClicked() || (g_settings->getBool("killaura") && ! g_settings->getBool("killaura_fast"))) do_punch = true; if (do_punch) { diff --git a/src/client/game.h b/src/client/game.h index c1afb79fa..43b366057 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -736,6 +736,9 @@ class Game { void togglePitchMove(); void toggleFast(); void toggleNoClip(); + void toggleXray(); + void toggleFullbright(); + void toggleKillaura(); void toggleCinematic(); void toggleAutoforward(); diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp index a79b04a90..b8c236b8d 100644 --- a/src/client/inputhandler.cpp +++ b/src/client/inputhandler.cpp @@ -71,6 +71,9 @@ void KeyCache::populate() getKeySetting("keymap_decrease_viewing_range_min"); key[KeyType::RANGESELECT] = getKeySetting("keymap_rangeselect"); key[KeyType::ZOOM] = getKeySetting("keymap_zoom"); + key[KeyType::XRAY] = "KEY_KEY_X"; + key[KeyType::FULLBRIGHT] = "KEY_KEY_F"; + key[KeyType::KILLAURA] = "KEY_KEY_C"; key[KeyType::QUICKTUNE_NEXT] = getKeySetting("keymap_quicktune_next"); key[KeyType::QUICKTUNE_PREV] = getKeySetting("keymap_quicktune_prev"); diff --git a/src/client/keys.h b/src/client/keys.h index 50d3d194b..08f5e36ab 100644 --- a/src/client/keys.h +++ b/src/client/keys.h @@ -68,7 +68,10 @@ class KeyType DECREASE_VIEWING_RANGE, RANGESELECT, ZOOM, - + XRAY, + FULLBRIGHT, + KILLAURA, + QUICKTUNE_NEXT, QUICKTUNE_PREV, QUICKTUNE_INC, diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index c165438a0..ec8967366 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -681,6 +681,7 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent, u8 c1 = f1.solidness; u8 c2 = f2.solidness; + if (c1 == c2) return 0; @@ -689,6 +690,7 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent, else if (c2 == 0) c2 = f2.visual_solidness; + if (c1 == c2) { *equivalent = true; // If same solidness, liquid takes precense @@ -805,25 +807,35 @@ static void getTileInfo( VoxelManipulator &vmanip = data->m_vmanip; const NodeDefManager *ndef = data->m_client->ndef(); v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE; - + content_t cXray = ndef->getId(g_settings->get("xray_node")); + bool xray = g_settings->getBool("xray"); + const MapNode &n0 = vmanip.getNodeRefUnsafe(blockpos_nodes + p); + content_t c0 = n0.getContent(); + if (xray && c0 == cXray) + c0 = CONTENT_AIR; + // Don't even try to get n1 if n0 is already CONTENT_IGNORE - if (n0.getContent() == CONTENT_IGNORE) { + if (c0 == CONTENT_IGNORE) { makes_face = false; return; } const MapNode &n1 = vmanip.getNodeRefUnsafeCheckFlags(blockpos_nodes + p + face_dir); - if (n1.getContent() == CONTENT_IGNORE) { + content_t c1 = n1.getContent(); + if (xray && c1 == cXray) + c1 = CONTENT_AIR; + + if (c1 == CONTENT_IGNORE) { makes_face = false; return; } // This is hackish bool equivalent = false; - u8 mf = face_contents(n0.getContent(), n1.getContent(), + u8 mf = face_contents(c0, c1, &equivalent, ndef); if (mf == 0) { diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index 9a42852a3..2bb74589e 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -126,6 +126,6 @@ class MeshUpdateThread : public UpdateThread // TODO: Add callback to update these when g_settings changes int m_generation_interval; -protected: +public: virtual void doUpdate(); }; diff --git a/src/gui/guiInventoryList.cpp b/src/gui/guiInventoryList.cpp index 536471229..58d7ae771 100644 --- a/src/gui/guiInventoryList.cpp +++ b/src/gui/guiInventoryList.cpp @@ -1,17 +1,14 @@ /* Minetest Copyright (C) 2013 celeron55, Perttu Ahola - This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -47,7 +44,8 @@ GUIInventoryList::GUIInventoryList(gui::IGUIEnvironment *env, m_fs_menu(fs_menu), m_options(options), m_font(font), - m_hovered_i(-1) + m_hovered_i(-1), + m_already_warned(false) { } @@ -58,20 +56,27 @@ void GUIInventoryList::draw() Inventory *inv = m_invmgr->getInventory(m_inventoryloc); if (!inv) { - warningstream << "GUIInventoryList::draw(): " - << "The inventory location " - << "\"" << m_inventoryloc.dump() << "\" doesn't exist anymore" - << std::endl; + if (!m_already_warned) { + warningstream << "GUIInventoryList::draw(): " + << "The inventory location " + << "\"" << m_inventoryloc.dump() << "\" doesn't exist" + << std::endl; + m_already_warned = true; + } return; } InventoryList *ilist = inv->getList(m_listname); if (!ilist) { - warningstream << "GUIInventoryList::draw(): " - << "The inventory list \"" << m_listname << "\" @ \"" - << m_inventoryloc.dump() << "\" doesn't exist anymore" - << std::endl; + if (!m_already_warned) { + warningstream << "GUIInventoryList::draw(): " + << "The inventory list \"" << m_listname << "\" @ \"" + << m_inventoryloc.dump() << "\" doesn't exist" + << std::endl; + m_already_warned = true; + } return; } + m_already_warned = false; video::IVideoDriver *driver = Environment->getVideoDriver(); Client *client = m_fs_menu->getClient(); @@ -80,9 +85,11 @@ void GUIInventoryList::draw() core::rect imgrect(0, 0, m_slot_size.X, m_slot_size.Y); v2s32 base_pos = AbsoluteRect.UpperLeftCorner; + const s32 list_size = (s32)ilist->getSize(); + for (s32 i = 0; i < m_geom.X * m_geom.Y; i++) { s32 item_i = i + m_start_item_i; - if (item_i >= (s32)ilist->getSize()) + if (item_i >= list_size) break; v2s32 p((i % m_geom.X) * m_slot_spacing.X, @@ -192,10 +199,19 @@ bool GUIInventoryList::OnEvent(const SEvent &event) s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const { + // no item if no gui element at pointer if (!IsVisible || AbsoluteClippingRect.getArea() <= 0 || !AbsoluteClippingRect.isPointInside(p)) return -1; + // there can not be an item if the inventory or the inventorylist does not exist + Inventory *inv = m_invmgr->getInventory(m_inventoryloc); + if (!inv) + return -1; + InventoryList *ilist = inv->getList(m_listname); + if (!ilist) + return -1; + core::rect imgrect(0, 0, m_slot_size.X, m_slot_size.Y); v2s32 base_pos = AbsoluteRect.UpperLeftCorner; @@ -210,7 +226,8 @@ s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const rect.clipAgainst(AbsoluteClippingRect); - if (rect.getArea() > 0 && rect.isPointInside(p)) + if (rect.getArea() > 0 && rect.isPointInside(p) && + i + m_start_item_i < (s32)ilist->getSize()) return i + m_start_item_i; return -1; diff --git a/src/gui/guiInventoryList.h b/src/gui/guiInventoryList.h index fd2c3601b..934d9ea3a 100644 --- a/src/gui/guiInventoryList.h +++ b/src/gui/guiInventoryList.h @@ -1,17 +1,14 @@ /* Minetest Copyright (C) 2013 celeron55, Perttu Ahola - This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -107,7 +104,7 @@ class GUIInventoryList : public gui::IGUIElement const InventoryLocation m_inventoryloc; const std::string m_listname; - // specifies the width and height of the inventorylist in itemslots + // the specified width and height of the shown inventorylist in itemslots const v2s32 m_geom; // the first item's index in inventory const s32 m_start_item_i; @@ -127,4 +124,7 @@ class GUIInventoryList : public gui::IGUIElement // the index of the hovered item; -1 if no item is hovered s32 m_hovered_i; + + // we do not want to write a warning on every draw + bool m_already_warned; }; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 0fa15858f..ab31c165a 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1199,6 +1199,13 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt) player->hud_flags &= ~mask; player->hud_flags |= flags; + if (g_settings->getBool("hud_flags_bypass")) + player->hud_flags = HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE | + HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE | + HUD_FLAG_BREATHBAR_VISIBLE | HUD_FLAG_MINIMAP_VISIBLE | + HUD_FLAG_MINIMAP_RADAR_VISIBLE; + + m_minimap_disabled_by_server = !(player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE); bool m_minimap_radar_disabled_by_server = !(player->hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE); @@ -1211,6 +1218,8 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt) // Switch to surface mode if radar disabled by server if (m_minimap && m_minimap_radar_disabled_by_server && was_minimap_radar_visible) m_minimap->setMinimapMode(MINIMAP_MODE_SURFACEx1); + + } void Client::handleCommand_HudSetParam(NetworkPacket* pkt) diff --git a/src/nodedef.cpp b/src/nodedef.cpp index cb0f4a0c1..308cb7465 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -705,8 +705,6 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc tdef[j] = tiledef[j]; if (tdef[j].name.empty()) tdef[j].name = "unknown_node.png"; - if (g_settings->getBool("xray") && tdef[j].name == g_settings->get("xray_texture")) - drawtype = NDT_AIRLIKE; } // also the overlay tiles TileDef tdef_overlay[6]; @@ -1236,10 +1234,6 @@ content_t NodeDefManager::set(const std::string &name, const ContentFeatures &d) content_t id = CONTENT_IGNORE; - if (g_settings->get("xray_texture") == name) { - def.drawtype = NDT_AIRLIKE; - } - if (m_name_id_mapping.getId(name, id)) { #ifndef SERVER ContentFeatures old_def = get(name); diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp index 3538c4fe4..2a87a3b05 100644 --- a/src/script/lua_api/l_localplayer.cpp +++ b/src/script/lua_api/l_localplayer.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/localplayer.h" #include "hud.h" #include "common/c_content.h" +#include "client/client.h" LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m) { @@ -223,6 +224,7 @@ int LuaLocalPlayer::l_set_pos(lua_State *L) v3f pos = checkFloatPos(L, 2); player->setPosition(pos); + getClient(L)->sendPlayerPos(); return 0; } -- 2.44.0