diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..d327731 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +A node that keeps the map block it is in loaded when players are not near by. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..d20a5dd --- /dev/null +++ b/init.lua @@ -0,0 +1,74 @@ + +-- display entity shown when loader node is punched +minetest.register_entity("simple_anchor:display", { + physical = false, + collisionbox = {0, 0, 0, 0, 0, 0}, + visual = "wielditem", + -- wielditem seems to be scaled to 1.5 times original node size + visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5}, + textures = {"simple_anchor:display_node"}, + timer = 0, + on_step = function(self, dtime) + self.timer = self.timer + dtime + -- remove after 8 seconds + if self.timer > 8 then + self.object:remove() + end + end, +}) + + +-- Display-zone node, Do NOT place the display as a node, +-- it is made to be used as an entity (see above) +local x = 8 +minetest.register_node("simple_anchor:display_node", { + tiles = {"loader_display.png"}, + use_texture_alpha = true, + walkable = false, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + -- sides + {-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)}, + {-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)}, + {(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)}, + {-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)}, + -- top + {-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)}, + -- bottom + {-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)}, + }, + }, + groups = {dig_immediate = 3, not_in_creative_inventory = 1}, + drop = "", +}) + + +minetest.register_node("simple_anchor:loader_block", { + description = "forceload anchor", + tiles = {"loader_block.png"}, + groups = {dig_immediate=2}, + light_source = 4, + on_construct = function (pos) + if minetest.forceload_block(pos) then + minetest.debug("forceload block ".. minetest.pos_to_string(pos)) + local meta = minetest.get_meta(pos) + local vm = minetest.get_voxel_manip(pos, pos) + local pmin, pmax = vm:get_emerged_area() + local epos = vector.divide(vector.add(pmin,pmax),2) + meta:set_string("epos",minetest.pos_to_string(epos)) + else + minetest.debug("failed forceload block ".. minetest.pos_to_string(pos)) + end + end, + on_destruct = function (pos) + minetest.forceload_free_block(pos) + minetest.debug("unforceloaded block ".. minetest.pos_to_string(pos)) + end, + on_punch = function (pos, node, puncher, pointed_thing) + local meta = minetest.get_meta(pos) + local epos = minetest.string_to_pos(meta:get_string("epos")) + minetest.add_entity(epos, "simple_anchor:display") + end, +}); diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..92ba5b8 --- /dev/null +++ b/license.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 zing269 + +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/mod.conf b/mod.conf new file mode 100644 index 0000000..2598ab1 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = simple_anchor \ No newline at end of file diff --git a/simple_anchor_1.png b/simple_anchor_1.png new file mode 100644 index 0000000..38865ab Binary files /dev/null and b/simple_anchor_1.png differ diff --git a/simple_anchor_2.png b/simple_anchor_2.png new file mode 100644 index 0000000..597e836 Binary files /dev/null and b/simple_anchor_2.png differ