Created
March 24, 2017 17:03
-
-
Save bigfoot547/54a4efbb6c8fab59a7bc41f45be53b13 to your computer and use it in GitHub Desktop.
Diff between bigfoot547/csm-inspect and DS-minetest/oredetect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/inspect.lua b/oredetect.lua | |
--- a/inspect.lua | |
+++ b/oredetect.lua | |
@@ -1,61 +1,72 @@ | |
-local inspect = false | |
-minetest.register_chatcommand("inspect", { | |
- description = "Modify inspection settings", | |
- params = "help|get|on|off|hand|toggle", | |
+local oredetect = {} | |
+oredetect.on = false | |
+oredetect.radius = 10 | |
+oredetect.nodes = {} | |
+ | |
+minetest.register_chatcommand("oredetect", { | |
+ description = "Modify oredetect settings", | |
+ params = "help|get|on|off|toggle|add|remove|radius", | |
func = function(param) | |
param = param:lower() | |
if param == "help" then | |
minetest.display_chat_message("HELP: Show this help message.") | |
- minetest.display_chat_message("GET: Inspection settings.") | |
- minetest.display_chat_message("ON: Enable inspection.") | |
- minetest.display_chat_message("OFF: Disable inspection.") | |
- minetest.display_chat_message("HAND: Show held item.") | |
- minetest.display_chat_message("TOGGLE: Toggle inspection. (Default)") | |
+ minetest.display_chat_message("GET: Oredetection settings.") | |
+ minetest.display_chat_message("ON: Enable Oredetection.") | |
+ minetest.display_chat_message("OFF: Disable Oredetection.") | |
+ minetest.display_chat_message("TOGGLE: Toggle Oredetection. (Default)") | |
+ minetest.display_chat_message("ADD: Add a node to search for.") | |
+ minetest.display_chat_message("REMOVE: Remove a node from searchlist.") | |
+ minetest.display_chat_message("RADIUS: Set the searchradius.") | |
return true | |
elseif param == "get" then | |
- if inspect then | |
- return true, "Inspection is enabled." | |
+ if not oredetect.on then | |
+ return true, "Oredetection is disabled." | |
else | |
- return true, "Inspection is disabled." | |
+ return true, "Nodes to search for: "..dump(oredetect.nodes).. | |
+ " (radius: "..oredetect.radius..")" | |
end | |
elseif param == "on" then | |
- inspect = true | |
- return true, "Inspection enabled." | |
+ oredetect.on = true | |
+ return true, "Oredetection enabled." | |
elseif param == "off" then | |
- inspect = false | |
- return true, "Inspection disabled." | |
- elseif param == "hand" then | |
- local stack = minetest.get_wielded_item() | |
- if stack:get_name() == "" then | |
- minetest.display_chat_message("Your hand is empty.") | |
- return true | |
- end | |
- if stack:get_wear() > 0 then -- If a tool, then say wear instead of count. | |
- minetest.display_chat_message("You are holding a " .. stack:get_name() .. " which is " .. tostring(math.floor((stack:get_wear()/65535) * 100)) .. "% worn.") | |
- return true | |
- else | |
- minetest.display_chat_message("You are holding " .. tostring(stack:get_count()) .. " of " .. stack:get_name() .. ".") | |
- return true | |
- end | |
- return false, "Not Implimented." | |
+ oredetect.on = false | |
+ return true, "Oredetection disabled." | |
elseif param == "toggle" or param == "" then | |
- inspect = not inspect | |
- if inspect then | |
- return true, "Inspection enabled." | |
+ oredetect.on = not oredetect.on | |
+ if oredetect.on then | |
+ return true, "Oredetection enabled." | |
else | |
- return true, "Inspection disabled." | |
+ return true, "Oredetection disabled." | |
end | |
- return true | |
+ elseif param:sub(1,3) == "add" then | |
+ local n = param:sub(5) | |
+ oredetect.nodes[#oredetect.nodes+1] = n | |
+ return true, n.." added to searchlist." | |
+ elseif param:sub(1,6) == "remove" then | |
+ local n = param:sub(8) | |
+ for i = 1, #oredetect.nodes do | |
+ if oredetect.nodes[i] == n then | |
+ oredetect.nodes[i] = nil | |
+ end | |
+ end | |
+ return true, n.." removed from searchlist." | |
+ elseif param:sub(1,6) == "radius" then | |
+ oredetect.radius = tonumber(param:sub(8)) or oredetect.radius | |
+ return true, "Oredetection radius set to "..oredetect.radius.."." | |
else | |
return false, "Invalid Arguments." | |
end | |
end | |
}) | |
-minetest.register_on_punchnode(function(pos, node) | |
- if inspect then | |
- minetest.display_chat_message("Node name: " .. node.name) | |
- minetest.display_chat_message("Param1: " .. tostring(node.param1)) | |
- minetest.display_chat_message("Param2, Facedir: " .. tostring(node.param2) .. ", " .. tostring(node.param2 % 32)) | |
+minetest.register_on_punchnode(function(pos, punchnode) | |
+ if not oredetect.on then | |
+ return | |
+ end | |
+ local nodepos = core.find_node_near(pos, oredetect.radius, oredetect.nodes) | |
+ if not nodepos then | |
+ return | |
end | |
+ local node = core.get_node(nodepos) | |
+ minetest.display_chat_message(node.name.." was found at "..core.pos_to_string(nodepos)) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment