From 33f7331eb9111624c034829c96d6dbdb27d93e60 Mon Sep 17 00:00:00 2001 From: Sheriff_U3 <210896603+Sheriff-Unit-3@users.noreply.github.com> Date: Sun, 28 Jun 2026 19:12:30 -0500 Subject: [PATCH] core -> minetest and fix some formating/style (#16) Co-authored-by: Sheriff_U3 --- .luacheckrc | 3 ++- crafts.lua | 10 ++++------ depends.txt | 2 -- drowning.lua | 14 ++++++-------- hud.lua | 49 +++++++++++++++++++++---------------------------- init.lua | 8 ++------ readme.md | 17 ++++++++++------- suit.lua | 30 ++++++++++++++++++++++++------ 8 files changed, 69 insertions(+), 64 deletions(-) delete mode 100644 depends.txt diff --git a/.luacheckrc b/.luacheckrc index 170b26e..8813a8a 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -4,8 +4,9 @@ globals = { } read_globals = { - -- Minetest + -- Luanti "minetest", + "core", -- Deps "armor", diff --git a/crafts.lua b/crafts.lua index 63fecd4..7146c45 100644 --- a/crafts.lua +++ b/crafts.lua @@ -1,6 +1,4 @@ - - -minetest.register_craft({ +core.register_craft({ output = "spacesuit:helmet", recipe = { {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, @@ -9,7 +7,7 @@ minetest.register_craft({ }, }) -minetest.register_craft({ +core.register_craft({ output = "spacesuit:chestplate", recipe = { {"default:steel_ingot", "default:mese", "default:steel_ingot"}, @@ -18,7 +16,7 @@ minetest.register_craft({ }, }) -minetest.register_craft({ +core.register_craft({ output = "spacesuit:pants", recipe = { {"default:steel_ingot", "wool:white", "default:steel_ingot"}, @@ -27,7 +25,7 @@ minetest.register_craft({ }, }) -minetest.register_craft({ +core.register_craft({ output = "spacesuit:boots", recipe = { {"default:steel_ingot", "wool:white", "default:steel_ingot"}, diff --git a/depends.txt b/depends.txt deleted file mode 100644 index 585cc7a..0000000 --- a/depends.txt +++ /dev/null @@ -1,2 +0,0 @@ -default -3d_armor diff --git a/drowning.lua b/drowning.lua index 96e677b..46cb7aa 100644 --- a/drowning.lua +++ b/drowning.lua @@ -10,9 +10,7 @@ local function check_player(player, timer) local has_chestplate = armor_inv:contains_item("armor", "spacesuit:chestplate") local has_pants = armor_inv:contains_item("armor", "spacesuit:pants") local has_boots = armor_inv:contains_item("armor", "spacesuit:boots") - local has_full_suit = has_helmet and has_chestplate and has_pants and has_boots - local armor_list = armor_inv:get_list("armor") -- does the player wear a suit? @@ -24,7 +22,7 @@ local function check_player(player, timer) if not stack:is_empty() then local name = stack:get_name() if name:sub(1, 10) == "spacesuit:" then - local use = minetest.get_item_group(name, "armor_use") * timer or 0 + local use = (core.get_item_group(name, "armor_use") * timer) or 0 armor:damage(player, i, stack, use) end end @@ -34,17 +32,17 @@ local function check_player(player, timer) elseif not has_full_suit then -- check if player is in vacuum without spacesuit - local is_admin = minetest.check_player_privs(player:get_player_name(), "privs") + local is_admin = core.check_player_privs(player:get_player_name(), "privs") if not is_admin then local ppos = player:get_pos() - local node = minetest.get_node(ppos) + local node = core.get_node(ppos) if node.name == "vacuum:vacuum" then -- player does not wear a suit, let him/her suffer! local breath = player:get_breath() if breath > 0 then player:set_breath(math.max(0, player:get_breath() - 4)) end - if breath < 4 then + if breath < 4 then player:set_hp( player:get_hp() - 2, "drown" ) end end @@ -53,10 +51,10 @@ local function check_player(player, timer) end local timer = 0 -minetest.register_globalstep(function(dtime) +core.register_globalstep(function(dtime) timer = timer + dtime; if timer >= 2 then - for _,player in ipairs(minetest.get_connected_players()) do + for _,player in ipairs(core.get_connected_players()) do check_player(player, timer) end timer = 0 diff --git a/hud.lua b/hud.lua index c568617..1940af6 100644 --- a/hud.lua +++ b/hud.lua @@ -1,27 +1,24 @@ - -local HUD_POSITION = { x = 0.09, y = 0.4 } -local OFFSET_LABEL = { x = 0, y = -16 } -local OFFSET_LEVEL = { x = 0, y = 16} -local OFFSET_WARNING = { x = 0, y = -34 } -local OFFSET_BAR = { x = 0, y = 0 } -local HUD_ALIGNMENT = { x = 1, y = 0 } - +local HUD_POSITION = {x = 0.09, y = 0.4} +local OFFSET_LABEL = {x = 0, y = -16} +local OFFSET_LEVEL = {x = 0, y = 16} +local OFFSET_WARNING = {x = 0, y = -34} +local OFFSET_BAR = {x = 0, y = 0} +local HUD_ALIGNMENT = {x = 1, y = 0} local hud = {} -- playername -> data - local setup_hud = function(player) local playername = player:get_player_name() local hud_data = {} hud[playername] = hud_data hud_data.overlay = player:hud_add({ - hud_elem_type = "image", - position = { x = 0.5, y = 0.5 }, - scale = { - x = -100, - y = -100 - }, - text = "spacesuit_overlay.png" + hud_elem_type = "image", + position = {x = 0.5, y = 0.5}, + scale = { + x = -100, + y = -100 + }, + text = "spacesuit_overlay.png" }) hud_data.o2_bg = player:hud_add({ @@ -30,7 +27,7 @@ local setup_hud = function(player) offset = OFFSET_BAR, text = "spacesuit_o2_levels_bg.png", alignment = HUD_ALIGNMENT, - scale = { x = -7, y = 1 } + scale = {x = -7, y = 1} }) hud_data.o2_fg = player:hud_add({ @@ -39,7 +36,7 @@ local setup_hud = function(player) offset = OFFSET_BAR, text = "spacesuit_o2_levels_fg_green.png", alignment = HUD_ALIGNMENT, - scale = { x = 0, y = 1 } + scale = {x = 0, y = 1} }) hud_data.o2_label = player:hud_add({ @@ -48,7 +45,7 @@ local setup_hud = function(player) offset = OFFSET_LABEL, text = "O2-Level:", alignment = HUD_ALIGNMENT, - scale = { x = 100, y = 100 }, + scale = {x = 100, y = 100}, number = 0x00FF00 }) @@ -58,7 +55,7 @@ local setup_hud = function(player) offset = OFFSET_LEVEL, text = "", alignment = HUD_ALIGNMENT, - scale = { x = 100, y = 100 }, + scale = {x = 100, y = 100}, number = 0x00FF00 }) @@ -68,10 +65,9 @@ local setup_hud = function(player) offset = OFFSET_WARNING, text = "", alignment = HUD_ALIGNMENT, - scale = { x = 100, y = 100 }, + scale = {x = 100, y = 100}, number = 0xFF0000 }) - end local remove_hud = function(player) @@ -123,7 +119,7 @@ local update_hud = function(player, has_full_suit, armor_list) local factor_full = 1 - (max_wear / 65535) player:hud_change(hud_data.o2_level, "text", math.floor(factor_full * 100) .. "%") - player:hud_change(hud_data.o2_fg, "scale", { x = math.floor(factor_full * -7), y = 1 }) + player:hud_change(hud_data.o2_fg, "scale", {x = math.floor(factor_full * -7), y = 1}) local color @@ -141,15 +137,13 @@ local update_hud = function(player, has_full_suit, armor_list) -- red color = get_color(255,0,0) player:hud_change(hud_data.o2_fg, "text", "spacesuit_o2_levels_fg_red.png") - end player:hud_change(hud_data.o2_label, "number", color) player:hud_change(hud_data.o2_level, "number", color) - end -minetest.register_on_leaveplayer(function(player) +core.register_on_leaveplayer(function(player) -- remove stale hud data local playername = player:get_player_name() hud[playername] = nil @@ -170,9 +164,8 @@ spacesuit.set_player_wearing = function(player, has_full_suit, has_helmet, armor elseif not hud_data and has_helmet then -- player started wearing setup_hud(player) - minetest.after(0.1, function() + core.after(0.1, function() update_hud(player, has_full_suit, armor_list) end) - end end diff --git a/init.lua b/init.lua index aaa6ad2..5cfd1cc 100644 --- a/init.lua +++ b/init.lua @@ -1,14 +1,10 @@ - spacesuit = { - armor_use = tonumber(minetest.settings:get("spacesuit.armor_use")) or 70, + armor_use = tonumber(core.settings:get("spacesuit.armor_use")) or 70, } - -local MP = minetest.get_modpath("spacesuit") +local MP = core.get_modpath("spacesuit") dofile(MP.."/suit.lua") dofile(MP.."/crafts.lua") dofile(MP.."/hud.lua") dofile(MP.."/drowning.lua") - -print("[OK] Spacesuit") diff --git a/readme.md b/readme.md index 5550aa8..c308081 100644 --- a/readme.md +++ b/readme.md @@ -1,16 +1,19 @@ - # Spacesuit [![luacheck](https://github.com/mt-mods/spacesuit/workflows/luacheck/badge.svg)](https://github.com/mt-mods/spacesuit/actions) +[forum topic](https://forum.luanti.org/viewtopic.php?p=185473) -Spacesuit mod for minetest +Spacesuit mod for Luanti/Minetest + +## Dependencies -# Dependencies * 3d_armor -# Features +## Features + * Breathe in vacuum or water -# Attributions -* Spacesuit textures: Anonymous_moose (https://forum.minetest.net/viewtopic.php?p=185473#p185473) -* textures/spacesuit_overlay.png (https://github.com/bas080/minetest_vignette) +## Attributions + +* Spacesuit textures: [Anonymous_moose](https://forum.luanti.org/memberlist.php?mode=viewprofile&u=7281) +* textures/spacesuit_overlay.png [bas080](https://github.com/bas080/minetest_vignette) diff --git a/suit.lua b/suit.lua index 9375321..673f3ca 100644 --- a/suit.lua +++ b/suit.lua @@ -1,9 +1,12 @@ - - armor:register_armor("spacesuit:helmet", { description = "Spacesuit Helmet", inventory_image = "spacesuit_inv_helmet.png", - groups = {armor_head=5, armor_heal=1, armor_use=spacesuit.armor_use, not_repaired_by_anvil=1}, + groups = { + armor_head = 5, + armor_heal = 1, + armor_use = spacesuit.armor_use, + not_repaired_by_anvil = 1 + }, wear = 0, wear_represents = "spacesuit_wear", }) @@ -11,7 +14,12 @@ armor:register_armor("spacesuit:helmet", { armor:register_armor("spacesuit:chestplate", { description = "Spacesuit Chestplate", inventory_image = "spacesuit_inv_chestplate.png", - groups = {armor_torso=8, armor_heal=1, armor_use=spacesuit.armor_use, not_repaired_by_anvil=1}, + groups = { + armor_torso = 8, + armor_heal = 1, + armor_use = spacesuit.armor_use, + not_repaired_by_anvil = 1 + }, wear = 0, wear_represents = "spacesuit_wear", }) @@ -19,7 +27,12 @@ armor:register_armor("spacesuit:chestplate", { armor:register_armor("spacesuit:pants", { description = "Spacesuit Pants", inventory_image = "spacesuit_inv_pants.png", - groups = {armor_legs=7, armor_heal=1, armor_use=spacesuit.armor_use, not_repaired_by_anvil=1}, + groups = { + armor_legs = 7, + armor_heal = 1, + armor_use = spacesuit.armor_use, + not_repaired_by_anvil = 1 + }, wear = 0, wear_represents = "spacesuit_wear", }) @@ -27,7 +40,12 @@ armor:register_armor("spacesuit:pants", { armor:register_armor("spacesuit:boots", { description = "Spacesuit Boots", inventory_image = "spacesuit_inv_boots.png", - groups = {armor_feet=4, armor_heal=1, armor_use=spacesuit.armor_use, not_repaired_by_anvil=1}, + groups = { + armor_feet = 4, + armor_heal = 1, + armor_use = spacesuit.armor_use, + not_repaired_by_anvil = 1 + }, wear = 0, wear_represents = "spacesuit_wear", })