Compare commits

...

1 commit

Author SHA1 Message Date
trans_soup
15ac639ed0 create mapper prototype.
create a node that scans the area around it and creates a smaller
replica of it out of entities.
2023-10-23 14:23:39 +02:00
6 changed files with 125 additions and 0 deletions

52
mods/bg_map/entity.lua Normal file
View file

@ -0,0 +1,52 @@
local modname = minetest.get_current_modname()
local function yoink_texture (tiles)
local result = {}
for _, tile in pairs(tiles) do
table.insert(result, tile)
end
while #result < 6 do
table.insert(result, result[#result])
end
return result
end
local function cube_texture (texture)
return { texture, texture, texture, texture, texture, texture, }
end
minetest.register_entity(modname .. ":projection", {
initial_properties = {
pointable = false,
visual = "cube",
textures = cube_texture(modname .. "_mapper.png"),
visual_size = {
x = 1/4,
y = 1/4,
z = 1/4,
},
},
on_activate = function (self, static_data, deltatime)
local data = minetest.parse_json(static_data)
if not data then return end
self._projected_node = data.projected_node
local node_def = minetest.registered_items[self._projected_node]
self._texture = yoink_texture(node_def.tiles)
self.object:set_properties({
textures = self._texture,
})
end,
get_staticdata = function (self)
return minetest.write_json({
texture = self._texture,
projected_node = self._projected_node,
})
end,
on_step = function (self, deltatime, moveresult)
if math.random() > 0.99 ^ deltatime then
self.object:remove()
end
end,
})

3
mods/bg_map/init.lua Normal file
View file

@ -0,0 +1,3 @@
load_file("node")
load_file("entity")
load_file("map")

55
mods/bg_map/map.lua Normal file
View file

@ -0,0 +1,55 @@
local modname = minetest.get_current_modname()
local function spawn_projection (pos, nodename)
return minetest.add_entity(pos, modname .. ":projection", minetest.write_json({
projected_node = nodename,
}))
end
local function step_to_delta (step, size)
return vector.new(
step % size,
math.floor(step / (size ^ 2)) % size,
math.floor(step / size) % size
)
end
local function project_at (pos, step, config)
config = config or {}
config.scan_distance = config.scan_distance or 8
config.projection_scale = config.projection_scale or 1/4
local sd = config.scan_distance
local pos_delta = step_to_delta(step, sd*2 + 1) - vector.new(sd, sd, sd)
local target = pos + pos_delta
local projected_pos = pos + pos_delta * config.projection_scale
if minetest.get_node(projected_pos).name ~= "air" then return end
local nodename = minetest.get_node(target).name
if nodename == "air" then return end
spawn_projection(projected_pos, nodename)
end
blockgame.register_abm({
label = "project maps",
nodenames = {modname .. ":mapper"},
interval = 1,
chance = 1,
action = function (pos, node)
local meta = minetest.get_meta(pos)
local step = meta:get_int("step")
local count = math.random(16, 32)
for i=1, count do
project_at(pos, step)
step = step + 1
end
step = step % ((8*2 + 1) ^ 3) -- TODO: don't have this hardcoded.
meta:set_int("step", step)
end,
})

3
mods/bg_map/mod.conf Normal file
View file

@ -0,0 +1,3 @@
name = bg_map
description = in-world mapping of the game world for blockgame.
depends = bg_api

12
mods/bg_map/node.lua Normal file
View file

@ -0,0 +1,12 @@
local modname = minetest.get_current_modname()
blockgame.register_node(modname .. ":mapper", {
description = "Mapper",
groups = {
cracky = 3,
},
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_int("step", 0)
end,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B