summaryrefslogtreecommitdiff
path: root/mark.lua
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2025-01-11 23:10:13 -0600
committercheapie <no-email-for-you@example.com>2025-01-11 23:10:13 -0600
commitf9991863f5816920a1c8d8446e53895d95b4fc33 (patch)
tree8aa5df658642ed9730e65765b2e61bb003b1dcb7 /mark.lua
downloadtechage_forceload-main.tar
techage_forceload-main.tar.gz
techage_forceload-main.tar.bz2
techage_forceload-main.tar.xz
techage_forceload-main.zip
Add initial contentHEADmain
Diffstat (limited to 'mark.lua')
-rw-r--r--mark.lua100
1 files changed, 100 insertions, 0 deletions
diff --git a/mark.lua b/mark.lua
new file mode 100644
index 0000000..ebbe68e
--- /dev/null
+++ b/mark.lua
@@ -0,0 +1,100 @@
+--[[
+
+ Based primarily on code from:
+ TechAge
+ =======
+
+ Copyright (C) 2019 Joachim Stolberg
+
+ AGPL v3
+ See LICENSE.txt for more information
+
+ mark.lua:
+
+]]--
+
+local marker_region = {}
+
+function techage_forceload.unmark_region(name)
+ if marker_region[name] ~= nil then --marker already exists
+ --wip: make the area stay loaded somehow
+ for _, entity in ipairs(marker_region[name]) do
+ entity:remove()
+ end
+ marker_region[name] = nil
+ end
+end
+
+function techage_forceload.mark_region(name, pos1, pos2, owner, secs)
+
+ if not name or not pos1 or not pos2 then return end
+
+ techage_forceload.unmark_region(name)
+
+ local sizex, sizey, sizez = (1 + pos2.x - pos1.x) / 2, (1 + pos2.y - pos1.y) / 2, (1 + pos2.z - pos1.z) / 2
+ local markers = {}
+
+ --XY plane markers
+ for _, z in ipairs({pos1.z - 0.5, pos2.z + 0.5}) do
+ local markerpos = {x=pos1.x + sizex - 0.5, y=pos1.y + sizey - 0.5, z=z}
+ local marker = minetest.add_entity(markerpos, "techage_forceload:region_cube")
+ if marker ~= nil then
+ marker:set_properties({
+ visual_size={x=sizex * 2, y=sizey * 2},
+ --collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
+ collisionbox = {0,0,0, 0,0,0},
+ })
+ if owner then
+ marker:set_nametag_attributes({text = owner})
+ end
+ marker:get_luaentity().player_name = name
+ table.insert(markers, marker)
+ end
+ end
+
+ --YZ plane markers
+ for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do
+ local markerpos = {x=x, y=pos1.y + sizey - 0.5, z=pos1.z + sizez - 0.5}
+ local marker = minetest.add_entity(markerpos, "techage_forceload:region_cube")
+ if marker ~= nil then
+ marker:set_properties({
+ visual_size={x=sizez * 2, y=sizey * 2},
+ --collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
+ collisionbox = {0,0,0, 0,0,0},
+ })
+ marker:set_yaw(math.pi / 2)
+ marker:get_luaentity().player_name = name
+ table.insert(markers, marker)
+ end
+ end
+
+ marker_region[name] = markers
+ minetest.after(secs or 20, techage_forceload.unmark_region, name)
+end
+
+function techage_forceload.switch_region(name, pos1, pos2)
+ if marker_region[name] ~= nil then --marker already exists
+ techage_forceload.unmark_region(name)
+ else
+ techage_forceload.mark_region(name, pos1, pos2)
+ end
+end
+
+minetest.register_entity(":techage_forceload:region_cube", {
+ initial_properties = {
+ visual = "upright_sprite",
+ textures = {"techage_cube_mark.png"},
+ use_texture_alpha = true,
+ physical = false,
+ glow = 12,
+ },
+ on_step = function(self)
+ if marker_region[self.player_name] == nil then
+ self.object:remove()
+ return
+ end
+ end,
+ on_punch = function(self)
+ techage_forceload.unmark_region(self.player_name)
+ end,
+})