From fb1eca6c11c18dad4d9fb4cd811977cbb18470e4 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Wed, 22 Dec 2021 18:16:01 +0100 Subject: [PATCH] Add .luacheckrc and do some code fixes --- README.md | 1 + nether/.luacheckrc | 15 +++++++++++++++ nether/furnace.lua | 4 ++-- nether/guide.lua | 36 ++++++++++++++++++++++++----------- nether/init.lua | 4 ++-- nether/items.lua | 36 +++++++++++++++++++++++------------ nether/pearl.lua | 14 +++----------- nether/portal.lua | 18 ++++++++---------- nether/weird_mapgen_noise.lua | 4 +++- 9 files changed, 83 insertions(+), 49 deletions(-) create mode 100644 nether/.luacheckrc diff --git a/README.md b/README.md index 1e68409..7697561 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,4 @@ https://forum.minetest.net/viewtopic.php?f=9&t=10265 TODO: * Find a way to get the perlin noise inside [-1; 1] or use another noise * Add some node which containing items to the simple pyramid "buildings" +* Change the sky background, fog, etc. in the nether diff --git a/nether/.luacheckrc b/nether/.luacheckrc new file mode 100644 index 0000000..4d04b6a --- /dev/null +++ b/nether/.luacheckrc @@ -0,0 +1,15 @@ +read_globals = { + -- Defined by Minetest + "minetest", "vector", "PseudoRandom", "VoxelArea", "ItemStack", "dump", + "string", + + -- Mods + "default", "stairs", "creative" +} +globals = {"nether"} +ignore = { + "212", + -- Unused argument + "411", "421", "422", "423", "431", "432", + -- Shadowing +} diff --git a/nether/furnace.lua b/nether/furnace.lua index 7de5d25..577d737 100644 --- a/nether/furnace.lua +++ b/nether/furnace.lua @@ -257,7 +257,7 @@ minetest.register_abm({ meta:set_float("timedif", timediff-times) - for i = 1,times do + for _ = 1,times do for _,name in pairs({ "fuel_totaltime", "fuel_time", @@ -292,7 +292,7 @@ minetest.register_abm({ inv:add_item("dst", cooked.item) -- take stuff from "src" list inv:set_stack("src", 1, aftercooked.items[1]) - else + --~ else --print("Could not insert '"..cooked.item:to_string().."'") end meta:set_string("src_time", 0) diff --git a/nether/guide.lua b/nether/guide.lua index 0f99e29..11fdc11 100644 --- a/nether/guide.lua +++ b/nether/guide.lua @@ -68,10 +68,13 @@ local guide_infos = { {"text", "One contains 4 kinds of blocks :"}, {"image", {1, 1, cube("nether_blood.png"), 1}}, {"image", {1, 1, - cube("nether_blood_top.png", "nether_blood.png^nether_blood_side.png", "nether_blood.png^nether_blood_side.png"), + cube("nether_blood_top.png", + "nether_blood.png^nether_blood_side.png", + "nether_blood.png^nether_blood_side.png"), 2}}, {"image", {1, 1, "nether_fruit.png", 3}}, - {"image", {1, 1, cube("nether_blood_stem_top.png", "nether_blood_stem.png", "nether_blood_stem.png")}}, + {"image", {1, 1, cube("nether_blood_stem_top.png", + "nether_blood_stem.png", "nether_blood_stem.png")}}, {"y", 0.1}, {"text", "Blood stem, blood, blood head and nether fruit"}, {"y", 0.1}, @@ -123,10 +126,14 @@ local guide_infos = { "After that it's recommended to use cooked blood nodes."}, {"y", 0.1}, {"text", "Some nether items can be cooked:"}, - {"image", {1, 1, cube("nether_blood_stem_top_cooked.png", "nether_blood_stem_cooked.png", "nether_blood_stem_cooked.png"), 0.35}}, + {"image", {1, 1, cube("nether_blood_stem_top_cooked.png", + "nether_blood_stem_cooked.png", "nether_blood_stem_cooked.png"), + 0.35}}, {"image", {1, 1, cube("nether_blood_cooked.png"), 1.6}}, {"image", {1, 1, - cube("nether_blood_top_cooked.png", "nether_blood_cooked.png^nether_blood_side_cooked.png", "nether_blood_cooked.png^nether_blood_side_cooked.png"), + cube("nether_blood_top_cooked.png", + "nether_blood_cooked.png^nether_blood_side_cooked.png", + "nether_blood_cooked.png^nether_blood_side_cooked.png"), 2.9}}, {"image", {1, 1, cube("nether_wood_cooked.png"), 4.3}}, {"y", 1.2}, @@ -142,14 +149,18 @@ local guide_infos = { {"text", "Here you can find out information about the nether extractor."}, {"y", 0.2}, {"text", "Here you can see its craft recipe:"}, - {"image", {0.5, 0.5, cube("nether_blood_top_cooked.png", "nether_blood_cooked.png^nether_blood_side_cooked.png", "nether_blood_cooked.png^nether_blood_side_cooked.png"), 0.5}}, + {"image", {0.5, 0.5, cube("nether_blood_top_cooked.png", + "nether_blood_cooked.png^nether_blood_side_cooked.png", + "nether_blood_cooked.png^nether_blood_side_cooked.png"), 0.5}}, {"image", {0.5, 0.5, cube("nether_netherrack_brick.png"), 1}}, {"image", {0.5, 0.5, cube("nether_netherrack_brick.png")}}, {"image", {0.5, 0.5, cube("nether_blood_extractor.png"), 2.5}}, {"image", {0.5, 0.5, "nether_shroom_stem.png", 0.5}}, {"image", {0.5, 0.5, cube("nether_blood_cooked.png"), 1}}, {"image", {0.5, 0.5, cube("nether_blood_cooked.png")}}, - {"image", {0.5, 0.5, cube("nether_blood_stem_top_cooked.png", "nether_blood_stem_cooked.png", "nether_blood_stem_cooked.png"), 0.5}}, + {"image", {0.5, 0.5, cube("nether_blood_stem_top_cooked.png", + "nether_blood_stem_cooked.png", "nether_blood_stem_cooked.png"), + 0.5}}, {"image", {0.5, 0.5, cube("nether_netherrack_brick.png"), 1}}, {"image", {0.5, 0.5, cube("nether_netherrack_brick.png")}}, {"y", 0.2}, @@ -347,11 +358,12 @@ for n,i in ipairs(guide_forms) do end -- creates contents formspec -local y = 0 for y,i in ipairs(guide_forms) do - local desc, form = unpack(i) - local s = #desc*1.3/font_size+1.5 - guide_forms.contents = guide_forms.contents.."button["..guide_size.cx*12/s-0.5 ..","..guide_size.cy+y/1.3 ..";"..s..",1;name;"..desc.."]" + local desc = i[1] + local s = #desc * 1.3 / font_size + 1.5 + guide_forms.contents = guide_forms.contents .. + "button[" .. guide_size.cx * 12 / s - 0.5 .. "," .. + guide_size.cy + y / 1.3 .. ";" .. s .. ",1;name;" .. desc .. "]" end -- shows the contents of the formspec @@ -387,7 +399,9 @@ minetest.register_chatcommand("nether_help", { return false end if player:getpos().y > nether.start then - minetest.chat_send_player(name, "Usually you don't neet this guide here. You can view it in the nether.") + minetest.chat_send_player(name, + "Usually you don't neet this guide here. " .. + "You can view it in the nether.") return false end minetest.chat_send_player(name, "Showing guide...") diff --git a/nether/init.lua b/nether/init.lua index 5061c84..aec6091 100644 --- a/nether/init.lua +++ b/nether/init.lua @@ -62,7 +62,7 @@ nether.start = f_h_max+100 local NETHER_HEIGHT = 30 -- Maximum amount of randomness in the map generation -NETHER_RANDOM = 2 +local NETHER_RANDOM = 2 -- Frequency of Glowstone on the "roof" of the Nether (higher is less frequent) local GLOWSTONE_FREQ_ROOF = 500 @@ -117,7 +117,7 @@ end local path = minetest.get_modpath"nether" -dofile(path.."/weird_mapgen_noise.lua") +local nether_weird_noise = dofile(path.."/weird_mapgen_noise.lua") dofile(path.."/items.lua") --dofile(path.."/furnace.lua") dofile(path.."/pearl.lua") diff --git a/nether/items.lua b/nether/items.lua index cc67ae9..1b58678 100644 --- a/nether/items.lua +++ b/nether/items.lua @@ -41,11 +41,13 @@ local function digging_allowed(player, v) if not player then return false end - if creative_installed and creative.is_enabled_for(player:get_player_name()) then + if creative_installed + and creative.is_enabled_for(player:get_player_name()) then return true end local tool = player:get_wielded_item():get_name() - tool = minetest.registered_tools[tool] or tool == "" and minetest.registered_items[tool] + tool = minetest.registered_tools[tool] or tool == "" + and minetest.registered_items[tool] if not tool or not tool.tool_capabilities then return false @@ -210,7 +212,8 @@ add_more_nodes("blood_empty") minetest.register_node("nether:blood_top", { description = "Nether Blood Head", - tiles = {"nether_blood_top.png", "nether_blood.png", "nether_blood.png^nether_blood_side.png"}, + tiles = {"nether_blood_top.png", "nether_blood.png", + "nether_blood.png^nether_blood_side.png"}, groups = {snappy=2, choppy=2, oddly_breakable_by_hand=1}, sounds = default.node_sound_wood_defaults(), }) @@ -218,7 +221,8 @@ add_more_nodes("blood_top") minetest.register_node("nether:blood_top_cooked", { description = "Cooked Nether Blood Head", - tiles = {"nether_blood_top_cooked.png", "nether_blood_cooked.png", "nether_blood_cooked.png^nether_blood_side_cooked.png"}, + tiles = {"nether_blood_top_cooked.png", "nether_blood_cooked.png", + "nether_blood_cooked.png^nether_blood_side_cooked.png"}, groups = {nether=3}, sounds = nether_sound, furnace_burntime = 10, @@ -230,7 +234,8 @@ add_more_nodes("blood_top_cooked") minetest.register_node("nether:blood_top_empty", { description = "Nether Blood Head Extracted", - tiles = {"nether_blood_top_empty.png", "nether_blood_empty.png", "nether_blood_empty.png^nether_blood_side_empty.png"}, + tiles = {"nether_blood_top_empty.png", "nether_blood_empty.png", + "nether_blood_empty.png^nether_blood_side_empty.png"}, groups = {snappy=2, choppy=2, oddly_breakable_by_hand=1}, sounds = default.node_sound_wood_defaults(), }) @@ -239,7 +244,8 @@ add_more_nodes("blood_top_empty") minetest.register_node("nether:blood_stem", { description = "Nether Blood Stem", - tiles = {"nether_blood_stem_top.png", "nether_blood_stem_top.png", "nether_blood_stem.png"}, + tiles = {"nether_blood_stem_top.png", "nether_blood_stem_top.png", + "nether_blood_stem.png"}, groups = {snappy=2, choppy=2, oddly_breakable_by_hand=1}, sounds = default.node_sound_wood_defaults(), }) @@ -247,7 +253,8 @@ add_more_nodes("blood_stem") minetest.register_node("nether:blood_stem_cooked", { description = "Cooked Nether Blood Stem", - tiles = {"nether_blood_stem_top_cooked.png", "nether_blood_stem_top_cooked.png", "nether_blood_stem_cooked.png"}, + tiles = {"nether_blood_stem_top_cooked.png", + "nether_blood_stem_top_cooked.png", "nether_blood_stem_cooked.png"}, groups = {nether=3}, sounds = nether_sound, furnace_burntime = 30, @@ -259,7 +266,8 @@ add_more_nodes("blood_stem_cooked") minetest.register_node("nether:blood_stem_empty", { description = "Nether Blood Stem Extracted", - tiles = {"nether_blood_stem_top_empty.png", "nether_blood_stem_top_empty.png", "nether_blood_stem_empty.png"}, + tiles = {"nether_blood_stem_top_empty.png", + "nether_blood_stem_top_empty.png", "nether_blood_stem_empty.png"}, groups = {tree=1, choppy=2, oddly_breakable_by_hand=1}, sounds = default.node_sound_wood_defaults(), }) @@ -351,7 +359,9 @@ minetest.override_item("riesenpilz:nether_shroom", { minetest.register_node("nether:apple", { description = "Nether Fruit", drawtype = "nodebox", - tiles = {"nether_fruit_top.png", "nether_fruit_bottom.png", "nether_fruit.png", "nether_fruit.png^[transformFX", "nether_fruit.png^[transformFX", "nether_fruit.png"}, + tiles = {"nether_fruit_top.png", "nether_fruit_bottom.png", + "nether_fruit.png", "nether_fruit.png^[transformFX", + "nether_fruit.png^[transformFX", "nether_fruit.png"}, node_box = { type = "fixed", fixed = { @@ -379,7 +389,7 @@ minetest.register_node("nether:apple", { return end itemstack:take_item() - if nether_port(user, vector.round(user:getpos())) then + if nether.teleport_player(user) then return itemstack end local amount = math.random(4, 6) @@ -506,8 +516,10 @@ minetest.register_node("nether:tree", { minetest.register_node("nether:tree_corner", { description = "Nether Trunk Corner", - tiles = {"nether_tree.png^[transformR180", "nether_tree_top.png", "nether_tree_corner.png^[transformFY", - "nether_tree_corner.png^[transformR180", "nether_tree.png", "nether_tree_top.png"}, + tiles = {"nether_tree.png^[transformR180", "nether_tree_top.png", + "nether_tree_corner.png^[transformFY", + "nether_tree_corner.png^[transformR180", "nether_tree.png", + "nether_tree_top.png"}, paramtype2 = "facedir", is_ground_content = false, groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,not_in_creative_inventory=1}, diff --git a/nether/pearl.lua b/nether/pearl.lua index ec79576..55af1e0 100644 --- a/nether/pearl.lua +++ b/nether/pearl.lua @@ -1,13 +1,4 @@ -local function table_contains(t, v) - for _,i in pairs(t) do - if v == i then - return true - end - end - return false -end -local creative = minetest.settings:get_bool("creative_mode") local function throw_pearl(item, player) local playerpos = player:getpos() playerpos.y = playerpos.y+1.625 @@ -15,8 +6,9 @@ local function throw_pearl(item, player) local dir = player:get_look_dir() obj:setvelocity(vector.multiply(dir, 30)) obj:setacceleration({x=dir.x*-3, y=-dir.y^8*80-10, z=dir.z*-3}) - obj:get_luaentity().player = player:get_player_name() - if not creative then + local pname = player:get_player_name() + obj:get_luaentity().player = pname + if not minetest.is_creative_enabled(pname) then item:take_item() return item end diff --git a/nether/portal.lua b/nether/portal.lua index 79e059f..bb24764 100644 --- a/nether/portal.lua +++ b/nether/portal.lua @@ -484,7 +484,7 @@ local function make_portal(pos) for d=0,3 do for y=p1.y,p2.y do - local p = {} + local p if param2 == 0 then p = {x=p1.x+d, y=y, z=p1.z} else @@ -580,8 +580,7 @@ end) -- a not filled square -vector.square = vector.square or -function(r) +local function vector_square(r) local tab, n = {}, 1 for i = -r+1, r do for j = -1, 1, 2 do @@ -601,13 +600,13 @@ local function is_netherportal(pos) return end end - for _,sn in pairs(vector.square(1)) do + for _,sn in pairs(vector_square(1)) do if minetest.get_node({x=x+sn[1], y=y-1, z=z+sn[2]}).name ~= "nether:netherrack" or minetest.get_node({x=x+sn[1], y=y+3, z=z+sn[2]}).name ~= "nether:blood_cooked" then return end end - for _,sn in pairs(vector.square(2)) do + for _,sn in pairs(vector_square(2)) do if minetest.get_node({x=x+sn[1], y=y-1, z=z+sn[2]}).name ~= "nether:netherrack_black" or minetest.get_node({x=x+sn[1], y=y+3, z=z+sn[2]}).name ~= "nether:wood_empty" then return @@ -651,13 +650,12 @@ local function set_portal(t, z,x, y) end -- used when a player eats that fruit in a portal -function nether_port(player, pos) - if not player - or not pos - or not pos.x then - minetest.log("error", "[nether] nether_port: something failed.") +function nether.teleport_player(player) + if not player then + minetest.log("error", "[nether] Missing player.") return end + local pos = vector.round(player:getpos()) if not is_netherportal(pos) then return end diff --git a/nether/weird_mapgen_noise.lua b/nether/weird_mapgen_noise.lua index 4fa9bed..8fe436d 100644 --- a/nether/weird_mapgen_noise.lua +++ b/nether/weird_mapgen_noise.lua @@ -5,7 +5,7 @@ end local r_chs = {} -function nether_weird_noise(minp, fct, s, seed, range, scale) +local function nether_weird_noise(minp, fct, s, seed, range, scale) if not r_chs[s] then r_chs[s] = math.floor(s/3+0.5) end @@ -86,3 +86,5 @@ minetest.register_node("ac:wmg", { end end, })]] + +return nether_weird_noise