From 3bed0981d058b512bfb8aeeeeed235c9ee9385af Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sat, 15 Aug 2020 15:45:28 +0200 Subject: [PATCH] UI Update; Added AutoTool --- builtin/client/cheats.lua | 6 +- clientmods/chat/init.lua | 36 ++++++++ clientmods/chat/rainbow.lua | 61 +++++++++++++ clientmods/colorchat/LICENSE | 21 ----- clientmods/colorchat/init.lua | 90 ------------------- clientmods/colorchat/mod.conf | 3 - clientmods/enderchest/mod.conf | 3 - .../init.lua => inventory/enderchest.lua} | 13 +-- clientmods/inventory/init.lua | 56 ++++++++++++ clientmods/inventory/invhack.lua | 13 +++ clientmods/mapbot/api.lua | 41 --------- clientmods/mapbot/init.lua | 10 --- clientmods/mapbot/mod.conf | 3 - clientmods/mapbot/simple_bots.lua | 30 ------- clientmods/maputil/buildbot.lua | 57 ------------ clientmods/maputil/commands.lua | 42 --------- clientmods/maputil/init.lua | 5 -- clientmods/maputil/mod.conf | 3 - clientmods/misc/init.lua | 2 - clientmods/misc/mod.conf | 3 - clientmods/mods.conf | 9 +- clientmods/world/init.lua | 85 ++++++++++++++++++ clientmods/worldhacks/init.lua | 44 --------- src/client/game.cpp | 2 +- src/script/lua_api/l_localplayer.cpp | 13 +++ src/script/lua_api/l_localplayer.h | 3 + 26 files changed, 273 insertions(+), 381 deletions(-) create mode 100644 clientmods/chat/init.lua create mode 100644 clientmods/chat/rainbow.lua delete mode 100644 clientmods/colorchat/LICENSE delete mode 100644 clientmods/colorchat/init.lua delete mode 100644 clientmods/colorchat/mod.conf delete mode 100644 clientmods/enderchest/mod.conf rename clientmods/{enderchest/init.lua => inventory/enderchest.lua} (73%) create mode 100644 clientmods/inventory/init.lua create mode 100644 clientmods/inventory/invhack.lua delete mode 100644 clientmods/mapbot/api.lua delete mode 100644 clientmods/mapbot/init.lua delete mode 100644 clientmods/mapbot/mod.conf delete mode 100644 clientmods/mapbot/simple_bots.lua delete mode 100644 clientmods/maputil/buildbot.lua delete mode 100644 clientmods/maputil/commands.lua delete mode 100644 clientmods/maputil/init.lua delete mode 100644 clientmods/maputil/mod.conf delete mode 100644 clientmods/misc/init.lua delete mode 100644 clientmods/misc/mod.conf create mode 100644 clientmods/world/init.lua delete mode 100644 clientmods/worldhacks/init.lua diff --git a/builtin/client/cheats.lua b/builtin/client/cheats.lua index 3a1f6b24a..839021ad2 100644 --- a/builtin/client/cheats.lua +++ b/builtin/client/cheats.lua @@ -20,6 +20,7 @@ core.cheats = { ["NoHurtCam"] = "no_hurt_cam", ["BrightNight"] = "no_night", ["Coords"] = "coords", + ["Clouds"] = "enable_clouds", }, ["World"] = { ["FastDig"] = "fastdig", @@ -31,11 +32,6 @@ core.cheats = { ["UnlimitedRange"] = "increase_tool_range_plus", ["PointLiquids"] = "point_liquids", }, - ["Misc"] = { - ["Enderchest"] = function() - minetest.open_special_inventory() - end, - } } function core.register_cheat(cheatname, category, func) diff --git a/clientmods/chat/init.lua b/clientmods/chat/init.lua new file mode 100644 index 000000000..5b3ca7971 --- /dev/null +++ b/clientmods/chat/init.lua @@ -0,0 +1,36 @@ +chat = {} + +chat.rainbow = dofile(minetest.get_modpath("chat") .. "/rainbow.lua") + +function chat.send(message) + local starts_with = message:sub(1,1) == "/" + + if starts_with == "/" or starts_with == "." then return end + + local reverse = minetest.settings:get_bool("chat_reverse") + + if reverse then + local msg = "" + for i = 1, #message do + msg = message:sub(i, i) .. msg + end + message = msg + end + + local color = minetest.settings:get("chat_color") + + if color then + local msg + if color == "rainbow" then + msg = chat.rainbow(message) + else + msg = minetest.colorize(color, message) + end + message = msg + end + + minetest.send_chat_message(message) + return true +end + +minetest.register_on_sending_chat_message(chat.send) diff --git a/clientmods/chat/rainbow.lua b/clientmods/chat/rainbow.lua new file mode 100644 index 000000000..1519619a7 --- /dev/null +++ b/clientmods/chat/rainbow.lua @@ -0,0 +1,61 @@ +local function rgb_to_hex(rgb) + local hexadecimal = '#' + + for key, value in pairs(rgb) do + local hex = '' + + while(value > 0)do + local index = math.fmod(value, 16) + 1 + value = math.floor(value / 16) + hex = string.sub('0123456789ABCDEF', index, index) .. hex + end + + if(string.len(hex) == 0)then + hex = '00' + + elseif(string.len(hex) == 1)then + hex = '0' .. hex + end + + hexadecimal = hexadecimal .. hex + end + + return hexadecimal +end + +local function color_from_hue(hue) + local h = hue / 60 + local c = 255 + local x = (1 - math.abs(h%2 - 1)) * 255 + + local i = math.floor(h); + if (i == 0) then + return rgb_to_hex({c, x, 0}) + elseif (i == 1) then + return rgb_to_hex({x, c, 0}) + elseif (i == 2) then + return rgb_to_hex({0, c, x}) + elseif (i == 3) then + return rgb_to_hex({0, x, c}); + elseif (i == 4) then + return rgb_to_hex({x, 0, c}); + else + return rgb_to_hex({c, 0, x}); + end +end + +return function(input) + local step = 360 / input:len() + local hue = 0 + local output = "" + for i = 1, input:len() do + local char = input:sub(i,i) + if char:match("%s") then + output = output .. char + else + output = output .. minetest.get_color_escape_sequence(color_from_hue(hue)) .. char + end + hue = hue + step + end + return output +end diff --git a/clientmods/colorchat/LICENSE b/clientmods/colorchat/LICENSE deleted file mode 100644 index 93f5629ca..000000000 --- a/clientmods/colorchat/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018 red-001 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/clientmods/colorchat/init.lua b/clientmods/colorchat/init.lua deleted file mode 100644 index 66330063f..000000000 --- a/clientmods/colorchat/init.lua +++ /dev/null @@ -1,90 +0,0 @@ -local modstorage = minetest.get_mod_storage() - -local register_on_message = minetest.register_on_sending_chat_message -if minetest.register_on_sending_chat_messages then - register_on_message = minetest.register_on_sending_chat_messages -end - -local function rgb_to_hex(rgb) - local hexadecimal = '#' - - for key, value in pairs(rgb) do - local hex = '' - - while(value > 0)do - local index = math.fmod(value, 16) + 1 - value = math.floor(value / 16) - hex = string.sub('0123456789ABCDEF', index, index) .. hex - end - - if(string.len(hex) == 0)then - hex = '00' - - elseif(string.len(hex) == 1)then - hex = '0' .. hex - end - - hexadecimal = hexadecimal .. hex - end - - return hexadecimal -end - -local function color_from_hue(hue) - local h = hue / 60 - local c = 255 - local x = (1 - math.abs(h%2 - 1)) * 255 - - local i = math.floor(h); - if (i == 0) then - return rgb_to_hex({c, x, 0}) - elseif (i == 1) then - return rgb_to_hex({x, c, 0}) - elseif (i == 2) then - return rgb_to_hex({0, c, x}) - elseif (i == 3) then - return rgb_to_hex({0, x, c}); - elseif (i == 4) then - return rgb_to_hex({x, 0, c}); - else - return rgb_to_hex({c, 0, x}); - end -end - -register_on_message(function(message) - if message:sub(1,1) == "/" or modstorage:get_string("color") == "" or modstorage:get_string("color") == "white" then - return false - end - - minetest.send_chat_message(minetest.get_color_escape_sequence(modstorage:get_string("color")) .. message) - return true -end) - -minetest.register_chatcommand("set_color", { - description = minetest.gettext("Change chat color"), - func = function(colour) - modstorage:set_string("color", colour) - return true, "Chat color changed." - end, -}) - -minetest.register_chatcommand("rainbow", { - description = minetest.gettext("rainbow text"), - func = function(param) - local step = 360 / param:len() - local hue = 0 - -- iterate the whole 360 degrees - local output = "" - for i = 1, param:len() do - local char = param:sub(i,i) - if char:match("%s") then - output = output .. char - else - output = output .. minetest.get_color_escape_sequence(color_from_hue(hue)) .. char - end - hue = hue + step - end - minetest.send_chat_message(output) - return true -end, -}) diff --git a/clientmods/colorchat/mod.conf b/clientmods/colorchat/mod.conf deleted file mode 100644 index f152fc1ce..000000000 --- a/clientmods/colorchat/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = colorchat -author = red-001, Fleckenstein -description = A minetest CSM mod for changing the color of text sent to the server. diff --git a/clientmods/enderchest/mod.conf b/clientmods/enderchest/mod.conf deleted file mode 100644 index f3c30ea3e..000000000 --- a/clientmods/enderchest/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = enderchest -author = Fleckenstein -description = You can use this mod in MineClone2 to view you Enderinventory without an Ender Chest. diff --git a/clientmods/enderchest/init.lua b/clientmods/inventory/enderchest.lua similarity index 73% rename from clientmods/enderchest/init.lua rename to clientmods/inventory/enderchest.lua index 92544eb61..45ac216f3 100644 --- a/clientmods/enderchest/init.lua +++ b/clientmods/inventory/enderchest.lua @@ -24,15 +24,4 @@ function minetest.open_special_inventory() minetest.show_formspec("enderchest:enderchest", formspec) end -minetest.register_chatcommand("invhack", { - func = function(player) - minetest.show_formspec( - "invhack:invhack", - "" - .. "size[8,7.5]" - .. "list[" .. player .. ";main;0,3.5;8,4;]" - .. "list[" .. player .. ";craft;3,0;3,3;]" - .. "list[" .. player .. ";craftpreview;7,1;1,1;]" - ) - end -}) +minetest.register_cheat("Enderchest", "Inventory", minetest.open_special_inventory) diff --git a/clientmods/inventory/init.lua b/clientmods/inventory/init.lua new file mode 100644 index 000000000..5050fbe8b --- /dev/null +++ b/clientmods/inventory/init.lua @@ -0,0 +1,56 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +dofile(modpath .. "/invhack.lua") +dofile(modpath .. "/enderchest.lua") + +local elapsed_time = 0 +local tick_time = 0.05 + +minetest.register_globalstep(function(dtime) + elapsed_time = elapsed_time + dtime + if elapsed_time < tick_time then return end + local player = minetest.localplayer + if not player then return end + local item = player:get_wielded_item() + if item:get_count() == 0 and minetest.settings:get_bool("next_item") then + local index = player:get_wield_index() + player:set_wield_index(index + 1) + end + elapsed_time = 0 +end) + +local function check_tool(groups, old_best_time) + local toolcaps = minetest.localplayer:get_wielded_item():get_tool_capabilities() + if not toolcaps then return end + local best_time = old_best_time + for group, groupdef in pairs(toolcaps.groupcaps) do + local level = groups[group] + if level then + local this_time = groupdef.times[level] + if this_time < best_time then + best_time = this_time + end + end + end + return best_time < old_best_time, best_time +end + +minetest.register_on_punchnode(function(pos, node) + if not minetest.settings:get_bool("autotool") then return end + local player = minetest.localplayer + local groups = minetest.get_node_def(node.name).groups + local new_index = player:get_wield_index() + local better, best = check_tool(groups, math.huge) + for i = 0, 35 do + player:set_wield_index(i) + better, best = check_tool(groups, best) + if better then + new_index = i + end + end + player:set_wield_index(new_index) +end) + +minetest.register_cheat("NextItem", "Inventory", "next_item") +minetest.register_cheat("AutoTool", "Inventory", "autotool") diff --git a/clientmods/inventory/invhack.lua b/clientmods/inventory/invhack.lua new file mode 100644 index 000000000..c19167e4e --- /dev/null +++ b/clientmods/inventory/invhack.lua @@ -0,0 +1,13 @@ +minetest.register_chatcommand("invhack", { + func = function(player) + minetest.show_formspec( + "invhack:invhack", + "" + .. "size[8,7.5]" + .. "list[" .. player .. ";main;0,3.5;8,4;]" + .. "list[" .. player .. ";craft;3,0;3,3;]" + .. "list[" .. player .. ";craftpreview;7,1;1,1;]" + ) + end +}) + diff --git a/clientmods/mapbot/api.lua b/clientmods/mapbot/api.lua deleted file mode 100644 index 8d7398b56..000000000 --- a/clientmods/mapbot/api.lua +++ /dev/null @@ -1,41 +0,0 @@ -mapbot.bots = {} - -mapbot.paramtypes = { - ["pos"] = { - ",,", - function (param) - local _, pos = minetest.parse_relative_pos(param) - return pos - end - }, - ["nodes"] = { - " [] ...", - function (param) - return param:split(" ") - end - }, -} - -function mapbot.register_bot(name, description, paramtype, func) - local pt = mapbot.paramtypes[paramtype] - if not pt then return end - minetest.register_chatcommand(name, { - param = pt[1], - description = description .. " Empty parameter to stop.", - func = function(param) - mapbot.storage:set_string(name, param) - return true, "Changed " .. name .. " config." - end - }) - table.insert(mapbot.bots, {name, pt, func}) -end - -function mapbot.loop() - for _, bot in pairs(mapbot.bots) do - local param = mapbot.storage:get_string(bot[1]) - param = (param == "") and nil or bot[2][2](param) - if param and bot[3](param) end - end -end - -minetest.register_on_connect(mapbot.loop) diff --git a/clientmods/mapbot/init.lua b/clientmods/mapbot/init.lua deleted file mode 100644 index 4b2a73fe4..000000000 --- a/clientmods/mapbot/init.lua +++ /dev/null @@ -1,10 +0,0 @@ -mapbot = {} - -local modname = minetest.get_modname() -local modpath = minetest.get_modpath(modname) -mapbot.storage = minetest.get_mod_storage() - -dofile(modpath .. "/api.lua") -dofile(modpath .. "/simple_bots.lua") - - diff --git a/clientmods/mapbot/mod.conf b/clientmods/mapbot/mod.conf deleted file mode 100644 index 89eea839e..000000000 --- a/clientmods/mapbot/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = mapbot -author = Fleckenstein -description = An API to create simple bots, optimized for map interaction diff --git a/clientmods/mapbot/simple_bots.lua b/clientmods/mapbot/simple_bots.lua deleted file mode 100644 index 30b44f81b..000000000 --- a/clientmods/mapbot/simple_bots.lua +++ /dev/null @@ -1,30 +0,0 @@ -mapbot.register_bot("place_into", "Automatically place wielditem into specified nodes.", "nodes", function(nodes) - local pos = minetest.find_node_near(minetest.localplayer:get_pos(), 5, nodes, true) - if pos then - minetest.place_node(pos) - end -end) - -mapbot.register_bot("dig_nodes", "Automatically dig specified nodes.", "nodes", function(nodes) - local pos = minetest.find_node_near(minetest.localplayer:get_pos(), 5, nodes, true) - if pos then - minetest.dig_node(pos) - end -end) - -mapbot.register_bot("place_into_pos", "Automatically place wielditem at specified pos.", "pos", minetest.place_node) - -mapbot.register_bot("dig_pos", "Automatically dig node at specified pos.", "pos", minetest.dig_node) - -mapbot.register_bot("dig_place_nodes", "Automatically dig specified nodes and immediately place wielditem there.", "nodes", function (nodes) - local pos = minetest.find_node_near(minetest.localplayer:get_pos(), 5, nodes, true) - if pos then - minetest.dig_node(pos) - minetest.place_node(pos) - end -end) - -mapbot.register_bot("dig_place_pos", "Automatically dig node at specified pos and immediately place wielditem there.", "pos", function (pos) - minetest.dig_node(pos) - minetest.place_node(pos) -end) diff --git a/clientmods/maputil/buildbot.lua b/clientmods/maputil/buildbot.lua deleted file mode 100644 index 81e6e75e0..000000000 --- a/clientmods/maputil/buildbot.lua +++ /dev/null @@ -1,57 +0,0 @@ -local build = {} - -local function build_y(callback) - build.pos.y = build.pos.y - build.step.y - local function step() - build.pos.y = build.pos.y + build.step.y - minetest.after(0.25, (build.pos.y == build.goal.y) and callback or step) - minetest.place_node(build.pos) - local player_pos = minetest.find_node_near(build.pos, 2, "air") - if player_pos then - minetest.localplayer:set_pos(player_pos) - end - end - minetest.after(0.25, step) -end - -local function build_z(callback) - build.pos.z = build.pos.z - build.step.z - local function step() - build.start.y, build.goal.y = build.goal.y, build.start.y - build.step.y = (build.goal.y > build.pos.y) and 1 or -1 - build.pos.z = build.pos.z + build.step.z - build_y((build.pos.z == build.goal.z) and callback or step) - end - minetest.after(0.25, step) -end - -local function build_x(callback) - build.pos.x = build.pos.x - build.step.x - local function step() - build.start.z, build.goal.z = build.goal.z, build.start.z - build.step.z = (build.goal.z > build.pos.z) and 1 or -1 - build.pos.x = build.pos.x + build.step.x - build_z((build.pos.x == build.goal.x) and callback or step) - end - minetest.after(0.25, step) -end - -minetest.register_chatcommand("build", { - func = function(param) - local sucess - build.start = vector.round(minetest.localplayer:get_pos()) - build.pos = vector.new(build.start) - success, build.goal = minetest.parse_relative_pos(param) - if success then - build.step = {} - build.step.x = (build.goal.x > build.start.x) and 1 or -1 - build.start.z, build.goal.z = build.goal.z, build.start.z - build.start.y, build.goal.y = build.goal.y, build.start.y - build_x(function() minetest.display_chat_message("Done.") end) - end - return false, build.goal - end -}) - - - diff --git a/clientmods/maputil/commands.lua b/clientmods/maputil/commands.lua deleted file mode 100644 index 4f88cd145..000000000 --- a/clientmods/maputil/commands.lua +++ /dev/null @@ -1,42 +0,0 @@ -minetest.register_chatcommand("findnodes", { - description = "Scan for one or multible nodes in a radius around you", - param = " [,...]", - 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, -}) - -minetest.register_chatcommand("place", { - params = ",,", - description = "Place wielded item", - func = function(param) - local success, pos = minetest.parse_relative_pos(param) - if success then - minetest.place_node(pos) - return true, "Node placed at " .. minetest.pos_to_string(pos) - end - return false, pos - end, -}) - -minetest.register_chatcommand("dig", { - params = ",,", - description = "Dig node", - func = function(param) - local success, pos = minetest.parse_relative_pos(param) - if success then - minetest.dig_node(pos) - return true, "Node at " .. minetest.pos_to_string(pos) .. " dug" - end - return false, pos - end, -}) - - diff --git a/clientmods/maputil/init.lua b/clientmods/maputil/init.lua deleted file mode 100644 index 58af2fcb9..000000000 --- a/clientmods/maputil/init.lua +++ /dev/null @@ -1,5 +0,0 @@ -local modname = minetest.get_current_modname() -local modpath = minetest.get_modpath(modname) - -dofile(modpath .. "/commands.lua") -dofile(modpath .. "/buildbot.lua") diff --git a/clientmods/maputil/mod.conf b/clientmods/maputil/mod.conf deleted file mode 100644 index b2ad5305d..000000000 --- a/clientmods/maputil/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = maputil -author = Fleckenstein -description = Includes commands and a advanced bot for map interaction diff --git a/clientmods/misc/init.lua b/clientmods/misc/init.lua deleted file mode 100644 index 7d43f4325..000000000 --- a/clientmods/misc/init.lua +++ /dev/null @@ -1,2 +0,0 @@ -minetest.override_item("air", {liquids_pointable = true}) - diff --git a/clientmods/misc/mod.conf b/clientmods/misc/mod.conf deleted file mode 100644 index da48a676b..000000000 --- a/clientmods/misc/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = misc -author = Fleckenstein -description = Misc cheats diff --git a/clientmods/mods.conf b/clientmods/mods.conf index 94878b939..de7e3c74c 100644 --- a/clientmods/mods.conf +++ b/clientmods/mods.conf @@ -1,9 +1,6 @@ load_mod_warp = true +load_mod_world = true load_mod_respawn = true -load_mod_colorchat = true +load_mod_inventory = true load_mod_commands = true -load_mod_maputil = true -load_mod_enderchest = true -load_mod_misc = true -load_mod_mapbot = false -load_mod_worldhacks = true +load_mod_chat = true diff --git a/clientmods/world/init.lua b/clientmods/world/init.lua new file mode 100644 index 000000000..303900f8a --- /dev/null +++ b/clientmods/world/init.lua @@ -0,0 +1,85 @@ +minetest.register_chatcommand("findnodes", { + description = "Scan for one or multible nodes in a radius around you", + param = " [,...]", + func = function(param) + local radius = tonumber(param:split(" ")[1]) + local nodes = param:split(" ")[2]:split(",") + local pos = minetest.localplayer:get_pos() + local fpos = minetest.find_node_near(pos, radius, nodes, true) + if fpos then + return true, "Found " .. table.concat(nodes, " or ") .. " at " .. minetest.pos_to_string(fpos) + end + return false, "None of " .. table.concat(nodes, " or ") .. " found in a radius of " .. tostring(radius) + end, +}) + +minetest.register_chatcommand("place", { + params = ",,", + description = "Place wielded item", + func = function(param) + local success, pos = minetest.parse_relative_pos(param) + if success then + minetest.place_node(pos) + return true, "Node placed at " .. minetest.pos_to_string(pos) + end + return false, pos + end, +}) + +minetest.register_chatcommand("dig", { + params = ",,", + description = "Dig node", + func = function(param) + local success, pos = minetest.parse_relative_pos(param) + if success then + minetest.dig_node(pos) + return true, "Node at " .. minetest.pos_to_string(pos) .. " dug" + end + return false, pos + end, +}) + +minetest.register_globalstep(function() + local player = minetest.localplayer + if not player then return end + local pos = minetest.localplayer:get_pos() + local wielditem = minetest.localplayer:get_wielded_item() + if minetest.settings:get_bool("scaffold") then + minetest.place_node(vector.add(pos, {x = 0, y = -0.6, z = 0})) + end + if minetest.settings:get_bool("highway_z") and wielditem then + local z = pos.z + local positions = { + {x = 0, y = 0, z = z}, + {x = 1, y = 0, z = z}, + {x = 2, y = 1, z = z}, + {x = -2, y = 1, z = z}, + {x = -2, y = 0, z = z}, + {x = -1, y = 0, z = z}, + {x = 2, y = 0, z = z} + } + for _, p in pairs(positions) do + local node = minetest.get_node_or_nil(p) + if node and not minetest.get_node_def(node.name).walkable then + minetest.place_node(p) + end + end + end + if minetest.settings:get_bool("fucker") then + local p = minetest.find_node_near(pos, 5, "group:bed", true) + if p then + minetest.dig_node(p) + end + end + if minetest.settings:get_bool("destroy_liquids") then + local p = minetest.find_node_near(pos, 5, "mcl_core:water_source", true) + if p then + minetest.place_node(p) + end + end +end) + +minetest.register_cheat("Scaffold", "World", "scaffold") +minetest.register_cheat("HighwayZ", "World", "highway_z") +minetest.register_cheat("Fucker", "World", "fucker") +minetest.register_cheat("BlockWater", "World", "destroy_liquids") diff --git a/clientmods/worldhacks/init.lua b/clientmods/worldhacks/init.lua deleted file mode 100644 index 5b642e1a5..000000000 --- a/clientmods/worldhacks/init.lua +++ /dev/null @@ -1,44 +0,0 @@ -minetest.register_globalstep(function() - local player = minetest.localplayer - if not player then return end - local pos = minetest.localplayer:get_pos() - local wielditem = minetest.localplayer:get_wielded_item() - if minetest.settings:get_bool("scaffold") then - minetest.place_node(vector.add(pos, {x = 0, y = -0.6, z = 0})) - end - if minetest.settings:get_bool("highway_z") and wielditem then - local z = pos.z - local positions = { - {x = 0, y = 0, z = z}, - {x = 1, y = 0, z = z}, - {x = 2, y = 1, z = z}, - {x = -2, y = 1, z = z}, - {x = -2, y = 0, z = z}, - {x = -1, y = 0, z = z}, - {x = 2, y = 0, z = z} - } - for _, p in pairs(positions) do - local node = minetest.get_node_or_nil(p) - if node and not minetest.get_node_def(node.name).walkable then - minetest.place_node(p) - end - end - end - if minetest.settings:get_bool("fucker") then - local p = minetest.find_node_near(pos, 5, "group:bed", true) - if p then - minetest.dig_node(p) - end - end - if minetest.settings:get_bool("destroy_liquids") then - local p = minetest.find_node_near(pos, 5, "mcl_core:water_source", true) - if p then - minetest.place_node(p) - end - end -end) - -minetest.register_cheat("Scaffold", "World", "scaffold") -minetest.register_cheat("HighwayZ", "World", "highway_z") -minetest.register_cheat("Fucker", "World", "fucker") -minetest.register_cheat("DestroyWater", "World", "destroy_liquids") diff --git a/src/client/game.cpp b/src/client/game.cpp index b08dac878..b9e7e4d9b 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2290,7 +2290,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++; + d += 2; if (g_settings->getBool("increase_tool_range_plus")) d = 1000; diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp index bde120c1d..2644893f9 100644 --- a/src/script/lua_api/l_localplayer.cpp +++ b/src/script/lua_api/l_localplayer.cpp @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_content.h" #include "client/client.h" #include "client/content_cao.h" +#include "client/game.h" LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m) { @@ -86,6 +87,17 @@ int LuaLocalPlayer::l_get_wield_index(lua_State *L) return 1; } +// set_wield_index(self) +int LuaLocalPlayer::l_set_wield_index(lua_State *L) +{ + LocalPlayer *player = getobject(L, 1); + u32 index = luaL_checkinteger(L, 2); + + player->setWieldIndex(index); + g_game->processItemSelection(&g_game->runData.new_playeritem); + return 0; +} + // get_wielded_item(self) int LuaLocalPlayer::l_get_wielded_item(lua_State *L) { @@ -468,6 +480,7 @@ const luaL_Reg LuaLocalPlayer::methods[] = { luamethod(LuaLocalPlayer, get_hp), luamethod(LuaLocalPlayer, get_name), luamethod(LuaLocalPlayer, get_wield_index), + luamethod(LuaLocalPlayer, set_wield_index), luamethod(LuaLocalPlayer, get_wielded_item), luamethod(LuaLocalPlayer, is_attached), luamethod(LuaLocalPlayer, is_touching_ground), diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h index 2c9881d58..a5d1081c7 100644 --- a/src/script/lua_api/l_localplayer.h +++ b/src/script/lua_api/l_localplayer.h @@ -43,6 +43,9 @@ class LuaLocalPlayer : public ModApiBase // get_wield_index(self) static int l_get_wield_index(lua_State *L); + + // set_wield_index(self) + static int l_set_wield_index(lua_State *L); // get_wielded_item(self) static int l_get_wielded_item(lua_State *L); -- 2.44.0