commit 1eabf5d91686d08bca7ecc18865e1a33f8d56c58 Author: Extex101 <33675971+Extex101@users.noreply.github.com> Date: Wed Aug 7 20:00:43 2019 -0700 Initial commit diff --git a/LICENSE.TXT b/LICENSE.TXT new file mode 100644 index 0000000..deea1f2 --- /dev/null +++ b/LICENSE.TXT @@ -0,0 +1,59 @@ +License of source code +---------------------- + +The MIT License (MIT) +Copyright (C) 2019 Extex + +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. + +For more details: +https://opensource.org/licenses/MIT + + +Licenses of media (texture) +-------------------------------------- + +Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) +Copyright (C) 2019 Extex + +You are free to: +Share — copy and redistribute the material in any medium or format. +Adapt — remix, transform, and build upon the material for any purpose, even commercially. +The licensor cannot revoke these freedoms as long as you follow the license terms. + +Under the following terms: + +Attribution — You must give appropriate credit, provide a link to the license, and +indicate if changes were made. You may do so in any reasonable manner, but not in any way +that suggests the licensor endorses you or your use. + +ShareAlike — If you remix, transform, or build upon the material, you must distribute +your contributions under the same license as the original. + +No additional restrictions — You may not apply legal terms or technological measures that +legally restrict others from doing anything the license permits. + +Notices: + +You do not have to comply with the license for elements of the material in the public +domain or where your use is permitted by an applicable exception or limitation. +No warranties are given. The license may not give you all of the permissions necessary +for your intended use. For example, other rights such as publicity, privacy, or moral +rights may limit how you use the material. + +For more details: +http://creativecommons.org/licenses/by-sa/3.0/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..b13c05e --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# Light Tool +This is a mod that adds a Torch/Flashlight to ![Minetest](https://www.minetest.net/) (![Github Repo](https://github.com/Minetest/minetest)) + +# Animated gif +Here's how it works + + +![GIF](https://github.com/Extex101/light_tool/blob/master/in%20use%20(animated).gif) + +The beam is obstructed by blocks and go through glass and other nodes (with sunlight_propagates = true) + +Minetest forumn topic ![here]() + + diff --git a/api.lua b/api.lua new file mode 100644 index 0000000..8ef28d1 --- /dev/null +++ b/api.lua @@ -0,0 +1,41 @@ +-- You can use light_tool.add_tool(, range) to define your own torches +-- and you can use light_tool.light_beam(pos, dir, range) to define your own light beam + +light_tool = {} +light_tool.tools = {} +light_tool.range = {} +light_tool.light_beam = function(pos, dir, range) + for i = 0, range do + local new_pos = { + x = pos.x + (dir.x * i), + y = pos.y + (dir.y * i), + z = pos.z + (dir.z * i), + } + local node = minetest.get_node(new_pos) + if minetest.get_node(new_pos).name == "air" or minetest.get_node(new_pos).name == "light_tool:light" then + minetest.set_node(new_pos, {name = "light_tool:light"}) + elseif minetest.registered_nodes[node.name].sunlight_propagates == false then + break + end + end +end + +light_tool.add_tool = function(toolname, range) + table.insert(light_tool.tools, toolname) + table.insert(light_tool.range, range) +end + +light_tool.check = function(table, value) + for i,v in ipairs(table) do + if v == value then + return true + end + end +end +light_tool.check_index = function(table, value) + for i,v in ipairs(table) do + if v == value then + return i + end + end +end diff --git a/author.txt b/author.txt new file mode 100644 index 0000000..31b2802 --- /dev/null +++ b/author.txt @@ -0,0 +1 @@ +Extex \ No newline at end of file diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..21c2521 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default? \ No newline at end of file diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..8c91a0f --- /dev/null +++ b/description.txt @@ -0,0 +1,3 @@ +When holding a Light Tool it adds an aimed beam of light that is obstructed by blocks and shine through glass +Great for night travel and mining situations +Light Tool also adds an api to make your own light tools and create beams of light for own mods \ No newline at end of file diff --git a/in use (animated).gif b/in use (animated).gif new file mode 100644 index 0000000..b368247 Binary files /dev/null and b/in use (animated).gif differ diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..7b3fb45 --- /dev/null +++ b/init.lua @@ -0,0 +1,60 @@ +local path = minetest.get_modpath("light_tool") + +dofile(path.."/api.lua") + +minetest.register_tool("light_tool:light_tool", { + description = "Light Tool", + inventory_image = "light_tool_light_tool.png", +}) +light_tool.add_tool("light_tool:light_tool", 20) + +minetest.register_node("light_tool:light", { + drawtype = "glasslike", + tiles = {"blank.png"}, + paramtype = "light", + walkable = false, + is_ground_content = true, + light_propagates = true, + sunlight_propagates = true, + light_source = 8, + pointable = false, + buildable_to = true, + on_construct = function(pos) + minetest.after(0.1, function() + minetest.set_node(pos, {name = "air"}) + end) + end, +}) + +minetest.register_lbm({ + name = "light_tool:remove_light", + nodenames = {"light_tool:light"}, + run_at_every_load = true, + action = function(pos, node) + minetest.set_node(pos, {name = "air"}) + end, +}) + +if minetest.get_modpath("default") then + minetest.register_craft({ + output = "light_tool:light_tool", + recipe = { + {"","default:mese_crystal_fragment","default:mese_crystal"}, + {"default:mese_crystal_fragment","default:steel_ingot","default:mese_crystal_fragment"}, + {"default:steel_ingot", "default:mese_crystal_fragment",""}, + }, + }) +end + +minetest.register_globalstep(function() + for _, user in ipairs(minetest.get_connected_players()) do + local stack = ItemStack(user:get_wielded_item()) + local wielded = stack:get_definition() + if light_tool.check(light_tool.tools, wielded.name) then + local index = light_tool.check_index(light_tool.tools, wielded.name) + local dir = user:get_look_dir() + local pos = user:get_pos() + light_tool.light_beam({x = pos.x, y = pos.y+1, z = pos.z}, dir, light_tool.range[index]) + end + end +end) \ No newline at end of file diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..c0fe8f4 Binary files /dev/null and b/screenshot.png differ diff --git a/textures/light_tool_light_tool.png b/textures/light_tool_light_tool.png new file mode 100644 index 0000000..398e336 Binary files /dev/null and b/textures/light_tool_light_tool.png differ