From dc8ffc7eda76b9d9cae06157ff79b2d67532912f Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Fri, 23 Apr 2021 16:57:12 -0700 Subject: [PATCH] Initial commit --- LICENSE.txt | 21 +++++++++++++++++ README.md | 11 +++++++++ formspec.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 13 +++++++++++ mod.conf | 4 ++++ node.lua | 19 ++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 formspec.lua create mode 100644 init.lua create mode 100644 mod.conf create mode 100644 node.lua diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..b1ffcac --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright © 2021 Jordan Irwin (AntumDeluge) + +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/README.md b/README.md new file mode 100644 index 0000000..e33a816 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +## Equipment Examiner + +### Description: + +Tool to examine item stats in Minetest. + +WARNING: this mod is in development & not ready for live use + +### Licensing: + +- [MIT](LICENSE.txt) diff --git a/formspec.lua b/formspec.lua new file mode 100644 index 0000000..337b865 --- /dev/null +++ b/formspec.lua @@ -0,0 +1,64 @@ + +local S = core.get_translator("equip_exam") + +equip_exam.formspec_name = "equipExam" + + +local function get_item_specs(item) + if not item then return nil end + + local specs = nil + local name = item.short_description + if not name then name = item.description end + local id = item.name + + if not name then + specs = S("ID: @1", id) + else + specs = S("name: @1", name) .. "," .. S("ID: @1", id) + end + + if item.tool_capabilities.damage_groups then + for k, v in pairs(item.tool_capabilities.damage_groups) do + if not specs or specs == "" then + specs = k .. ": " .. v + else + specs = specs .. "," .. S("Damge to @1 type:", k) .. " " .. v + end + end + end + + return specs +end + +local function get_formspec(item) + local specs + if item then + specs = get_item_specs(core.registered_tools[item]) + else + specs = "" -- empty + end + + if not specs then + specs = S("Specs unavailable") + end + + local formspec = "formspec_version[4]" + .. "size[12,9]" + --.. "box[1,1;1,1;#555555]" + --.. "list[context;input;1,1;1,1;]" + .. "list[context;input;1,1;1,1;0]" + .. "button_exit[0.25,3.1;2.5,0.8;close;Close]" + .. "label[3,0.7;" .. S("Specs:") .. "]" + .. "textlist[3,1;8,3;speclist;" .. specs .. ";1;false]" + .. "list[current_player;main;1.15,4.1;8,4;0]" + + return formspec +end + +function equip_exam:show_formspec(player) + local playername = player:get_player_name() + if not playername or not player:is_player() then return end + + core.show_formspec(playername, equip_exam.formspec_name, get_formspec()) +end diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..f52e68d --- /dev/null +++ b/init.lua @@ -0,0 +1,13 @@ + +equip_exam = {} +equip_exam.name = core.get_current_modname() +equip_exam.path = core.get_modpath(equip_exam.name) + +local files = { + "formspec", + "node", +} + +for _, f in pairs(files) do + dofile(equip_exam.path .. "/" .. f .. ".lua") +end diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..126f9da --- /dev/null +++ b/mod.conf @@ -0,0 +1,4 @@ +name = equip_exam +description = Equipment examiner. +version = 0.1 +license = MIT diff --git a/node.lua b/node.lua new file mode 100644 index 0000000..973978f --- /dev/null +++ b/node.lua @@ -0,0 +1,19 @@ + +local node_def = { + drawtype = "normal", + tiles = { + "equip_exam_examiner_front.png", + "equip_exam_examiner.png", + }, + is_gound_content = false, + stack_max = 1, + on_rightclick = function(pos, node, player, itemstack, pointed_thing) + equip_exam:show_formspec(player) + end, + on_construct = function(pos) + local inv = core.get_meta(pos):get_inventory() + inv:set_size('input', 1) + end, +} + +core.register_node("equip_exam:examiner", node_def)