aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation/active_common.lua
diff options
context:
space:
mode:
author1F616EMO <root@1f616emo.xyz>2026-04-04 11:47:31 +0800
committerorwell <orwell@bleipb.de>2026-07-08 22:12:22 +0200
commitd251015ce1f19f5a276f0f298a4b6b7f632557f4 (patch)
treeac3267d48c59aa069b0bfdf0f4b771200463e9c1 /advtrains_luaautomation/active_common.lua
parent38cc24e968d3671cba63918d69be59afc26b1052 (diff)
Introduce default LuaATC environment on place
Adds the command /env_default to set per-player default environment to be used on placing new LuaATC components. This makes component placement more predictable, and should any error be triggered, it won't go to the wrong player.
Diffstat (limited to 'advtrains_luaautomation/active_common.lua')
-rw-r--r--advtrains_luaautomation/active_common.lua38
1 files changed, 32 insertions, 6 deletions
diff --git a/advtrains_luaautomation/active_common.lua b/advtrains_luaautomation/active_common.lua
index 63ccfcd..311ec04 100644
--- a/advtrains_luaautomation/active_common.lua
+++ b/advtrains_luaautomation/active_common.lua
@@ -12,16 +12,42 @@ function ac.save()
return {nodes = ac.nodes}
end
+function ac.get_player_default_environment(player)
+ local meta = player:get_meta()
+ local env = meta:get_string("atlatc_default_env")
+
+ if not atlatc.envs[env] then
+ -- Set the first key for the user as default environment
+ for envname, _ in pairs(atlatc.envs) do
+ meta:set_string("atlatc_default_env", envname)
+ return envname
+ end
+
+ -- We don't have any environments
+ return nil
+ end
+
+ return env
+end
+function ac.set_player_default_environment(player, env)
+ if atlatc.envs[env] then
+ local meta = player:get_meta()
+ meta:set_string("atlatc_default_env", env)
+ return true
+ end
+ return false
+end
+
function ac.after_place_node(pos, player)
+ local env = ac.get_player_default_environment(player)
+ if env then
+ local ph = minetest.pos_to_string(pos)
+ ac.nodes[ph] = { env = env }
+ end
+
local meta=minetest.get_meta(pos)
meta:set_string("formspec", ac.getform(pos, meta))
meta:set_string("infotext", S("Unconfigured LuaATC component"))
- local ph=minetest.pos_to_string(pos)
- --just get first available key!
- for en,_ in pairs(atlatc.envs) do
- ac.nodes[ph]={env=en}
- return
- end
end
function ac.getform(pos, meta_p)
local meta = meta_p or minetest.get_meta(pos)