initial draft / PoC
This commit is contained in:
commit
f562735eaa
17
.github/workflows/luacheck.yml
vendored
Normal file
17
.github/workflows/luacheck.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
name: luacheck
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: apt
|
||||
run: sudo apt-get install -y luarocks
|
||||
- name: luacheck install
|
||||
run: luarocks install --local luacheck
|
||||
- name: luacheck run
|
||||
run: $HOME/.luarocks/bin/luacheck ./
|
18
.luacheckrc
Normal file
18
.luacheckrc
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
globals = {
|
||||
"build_mirror",
|
||||
}
|
||||
|
||||
read_globals = {
|
||||
-- Stdlib
|
||||
string = {fields = {"split"}},
|
||||
table = {fields = {"copy", "getn"}},
|
||||
|
||||
-- Minetest
|
||||
"minetest",
|
||||
"vector", "ItemStack",
|
||||
"dump",
|
||||
|
||||
-- Deps
|
||||
"default"
|
||||
}
|
64
chatcommands.lua
Normal file
64
chatcommands.lua
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
|
||||
--[[
|
||||
/mirror y
|
||||
/mirror x
|
||||
/mirror z
|
||||
/mirror set
|
||||
/mirror off
|
||||
--]]
|
||||
|
||||
minetest.register_chatcommand("mirror", {
|
||||
params = "[set|x|y|z|off]",
|
||||
description = "",
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then
|
||||
return false, "Player not online!"
|
||||
end
|
||||
|
||||
if param == "off" then
|
||||
build_mirror.x[name] = nil
|
||||
build_mirror.y[name] = nil
|
||||
build_mirror.z[name] = nil
|
||||
build_mirror.update_hud(player)
|
||||
return true, "Mirror disabled"
|
||||
|
||||
-- TODO: set by punching a node
|
||||
elseif param == "set" then
|
||||
local ppos = player:get_pos()
|
||||
build_mirror.pos[name] = vector.round(ppos)
|
||||
build_mirror.update_hud(player)
|
||||
return true, "Set mirror-position to " .. minetest.pos_to_string(build_mirror.pos[name])
|
||||
|
||||
elseif param == "x" then
|
||||
build_mirror.x[name] = not build_mirror.x[name]
|
||||
build_mirror.update_hud(player)
|
||||
if build_mirror.x[name] then
|
||||
return true, "X-Axis mirror: enabled"
|
||||
else
|
||||
return true, "X-Axis mirror: disabled"
|
||||
end
|
||||
|
||||
elseif param == "y" then
|
||||
build_mirror.y[name] = not build_mirror.y[name]
|
||||
build_mirror.update_hud(player)
|
||||
if build_mirror.y[name] then
|
||||
return true, "Y-Axis mirror: enabled"
|
||||
else
|
||||
return true, "Y-Axis mirror: disabled"
|
||||
end
|
||||
|
||||
elseif param == "z" then
|
||||
build_mirror.z[name] = not build_mirror.z[name]
|
||||
build_mirror.update_hud(player)
|
||||
if build_mirror.z[name] then
|
||||
return true, "Z-Axis mirror: enabled"
|
||||
else
|
||||
return true, "Z-Axis mirror: disabled"
|
||||
end
|
||||
end
|
||||
|
||||
return false, "Invalid command!"
|
||||
end
|
||||
})
|
7
cleanup.lua
Normal file
7
cleanup.lua
Normal file
@ -0,0 +1,7 @@
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local playername = player:get_player_name()
|
||||
build_mirror.x[playername] = nil
|
||||
build_mirror.y[playername] = nil
|
||||
build_mirror.z[playername] = nil
|
||||
build_mirror.pos[playername] = nil
|
||||
end)
|
0
common.lua
Normal file
0
common.lua
Normal file
1
dev/minetest.conf
Normal file
1
dev/minetest.conf
Normal file
@ -0,0 +1 @@
|
||||
default_privs = interact, shout, zoom, fly, privs
|
9
dev/start.sh
Executable file
9
dev/start.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
docker run --rm -it \
|
||||
-u root:root \
|
||||
-v $(pwd)/minetest.conf:/etc/minetest/minetest.conf \
|
||||
-v $(pwd)/../:/root/.minetest/worlds/world/worldmods/build_mirror \
|
||||
-v build_mirror_world:/root/.minetest/worlds/world/ \
|
||||
--network host \
|
||||
registry.gitlab.com/minetest/minetest/server:5.2.0
|
64
dig.lua
Normal file
64
dig.lua
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
|
||||
local function dig_mirrored(pos, mirror_pos, mirrors)
|
||||
local mirrored_pos = { x = pos.x, y = pos.y, z = pos.z }
|
||||
|
||||
if mirrors.x then
|
||||
mirrored_pos.x = mirror_pos.x - (pos.x - mirror_pos.x)
|
||||
end
|
||||
if mirrors.y then
|
||||
mirrored_pos.y = mirror_pos.y - (pos.y - mirror_pos.y)
|
||||
end
|
||||
if mirrors.z then
|
||||
mirrored_pos.z = mirror_pos.z - (pos.z - mirror_pos.z)
|
||||
end
|
||||
|
||||
minetest.log("action", "[mirror] digging at " .. minetest.pos_to_string(mirrored_pos))
|
||||
minetest.set_node(mirrored_pos, { name = "air" })
|
||||
end
|
||||
|
||||
minetest.register_on_dignode(function(pos, _, digger)
|
||||
if not digger then
|
||||
return
|
||||
end
|
||||
|
||||
local playername = digger:get_player_name()
|
||||
local mirror_pos = build_mirror.pos[playername]
|
||||
|
||||
if not mirror_pos then
|
||||
return
|
||||
end
|
||||
|
||||
local ppos = digger:get_pos()
|
||||
if vector.distance(ppos, pos) > build_mirror.max_range then
|
||||
minetest.chat_send_player(playername, "[Build mirror] out of range!")
|
||||
end
|
||||
|
||||
if build_mirror.x[playername] then
|
||||
dig_mirrored(pos, mirror_pos, { x=true })
|
||||
end
|
||||
|
||||
if build_mirror.y[playername] then
|
||||
dig_mirrored(pos, mirror_pos, { y=true })
|
||||
end
|
||||
|
||||
if build_mirror.z[playername] then
|
||||
dig_mirrored(pos, mirror_pos, { z=true })
|
||||
end
|
||||
|
||||
if build_mirror.x[playername] and build_mirror.z[playername] then
|
||||
dig_mirrored(pos, mirror_pos, { x=true, z=true })
|
||||
end
|
||||
|
||||
if build_mirror.y[playername] and build_mirror.x[playername] then
|
||||
dig_mirrored(pos, mirror_pos, { y=true, x=true })
|
||||
end
|
||||
|
||||
if build_mirror.y[playername] and build_mirror.z[playername] then
|
||||
dig_mirrored(pos, mirror_pos, { y=true, z=true })
|
||||
end
|
||||
|
||||
if build_mirror.x[playername] and build_mirror.y[playername] and build_mirror.z[playername] then
|
||||
dig_mirrored(pos, mirror_pos, { x=true, y=true, z=true })
|
||||
end
|
||||
end)
|
34
hud.lua
Normal file
34
hud.lua
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
-- playername => id
|
||||
local waypoint = {}
|
||||
|
||||
function build_mirror.update_hud(player)
|
||||
local playername = player:get_player_name()
|
||||
local mirror_enabled = build_mirror.x[playername] or
|
||||
build_mirror.y[playername] or
|
||||
build_mirror.z[playername]
|
||||
|
||||
if waypoint[playername] then
|
||||
-- update
|
||||
if mirror_enabled then
|
||||
-- update position
|
||||
player:hud_change(waypoint[playername], "world_pos", build_mirror.pos[playername])
|
||||
else
|
||||
-- remove hud element
|
||||
player:hud_remove(waypoint[playername])
|
||||
waypoint[playername] = nil
|
||||
end
|
||||
else
|
||||
if build_mirror.pos[playername] then
|
||||
-- create new id
|
||||
local id = player:hud_add({
|
||||
hud_elem_type = "waypoint",
|
||||
name = "Build mirror",
|
||||
text = "m",
|
||||
number = 0xFF0000,
|
||||
world_pos = build_mirror.pos[playername]
|
||||
})
|
||||
waypoint[playername] = id
|
||||
end
|
||||
end
|
||||
end
|
23
init.lua
Normal file
23
init.lua
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
build_mirror = {
|
||||
|
||||
-- max radius around mirror
|
||||
max_range = 100,
|
||||
|
||||
-- playername => pos
|
||||
pos = {},
|
||||
|
||||
-- playername => true
|
||||
x = {},
|
||||
y = {},
|
||||
z = {}
|
||||
}
|
||||
|
||||
|
||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||
dofile(MP .. "/common.lua")
|
||||
dofile(MP .. "/chatcommands.lua")
|
||||
dofile(MP .. "/hud.lua")
|
||||
dofile(MP .. "/place.lua")
|
||||
dofile(MP .. "/dig.lua")
|
||||
dofile(MP .. "/cleanup.lua")
|
67
place.lua
Normal file
67
place.lua
Normal file
@ -0,0 +1,67 @@
|
||||
|
||||
local function place_mirrored(pos, node, mirror_pos, mirrors)
|
||||
local mirrored_pos = { x = pos.x, y = pos.y, z = pos.z }
|
||||
|
||||
if mirrors.x then
|
||||
mirrored_pos.x = mirror_pos.x - (pos.x - mirror_pos.x)
|
||||
end
|
||||
if mirrors.y then
|
||||
mirrored_pos.y = mirror_pos.y - (pos.y - mirror_pos.y)
|
||||
end
|
||||
if mirrors.z then
|
||||
mirrored_pos.z = mirror_pos.z - (pos.z - mirror_pos.z)
|
||||
end
|
||||
|
||||
minetest.log("action",
|
||||
"[mirror] placing " .. node.name ..
|
||||
" with param2 " .. node.param2 ..
|
||||
" at " .. minetest.pos_to_string(mirrored_pos)
|
||||
)
|
||||
minetest.set_node(mirrored_pos, node)
|
||||
end
|
||||
|
||||
minetest.register_on_placenode(function(pos, newnode, placer)
|
||||
if not placer then
|
||||
return
|
||||
end
|
||||
|
||||
local playername = placer:get_player_name()
|
||||
local mirror_pos = build_mirror.pos[playername]
|
||||
|
||||
if not mirror_pos then
|
||||
return
|
||||
end
|
||||
|
||||
local ppos = placer:get_pos()
|
||||
if vector.distance(ppos, pos) > build_mirror.max_range then
|
||||
minetest.chat_send_player(playername, "[Build mirror] out of range!")
|
||||
end
|
||||
|
||||
if build_mirror.x[playername] then
|
||||
place_mirrored(pos, newnode, mirror_pos, { x=true })
|
||||
end
|
||||
|
||||
if build_mirror.y[playername] then
|
||||
place_mirrored(pos, newnode, mirror_pos, { y=true })
|
||||
end
|
||||
|
||||
if build_mirror.z[playername] then
|
||||
place_mirrored(pos, newnode, mirror_pos, { z=true })
|
||||
end
|
||||
|
||||
if build_mirror.x[playername] and build_mirror.z[playername] then
|
||||
place_mirrored(pos, newnode, mirror_pos, { x=true, z=true })
|
||||
end
|
||||
|
||||
if build_mirror.y[playername] and build_mirror.x[playername] then
|
||||
place_mirrored(pos, newnode, mirror_pos, { y=true, x=true })
|
||||
end
|
||||
|
||||
if build_mirror.y[playername] and build_mirror.z[playername] then
|
||||
place_mirrored(pos, newnode, mirror_pos, { y=true, z=true })
|
||||
end
|
||||
|
||||
if build_mirror.x[playername] and build_mirror.y[playername] and build_mirror.z[playername] then
|
||||
place_mirrored(pos, newnode, mirror_pos, { x=true, y=true, z=true })
|
||||
end
|
||||
end)
|
Loading…
x
Reference in New Issue
Block a user