2019-08-17 09:47:16 +02:00
|
|
|
-- internationalization boilerplate
|
|
|
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
local S, NS = dofile(MP.."/intllib.lua")
|
|
|
|
|
|
|
|
local controller_nodebox = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.3125, -0.3125, -0.3125, 0.3125, 0.3125, 0.3125}, -- Core
|
|
|
|
{-0.1875, 0.3125, -0.1875, 0.1875, 0.5, 0.1875}, -- +y_connector
|
|
|
|
{-0.1875, -0.5, -0.1875, 0.1875, -0.3125, 0.1875}, -- -y_Connector
|
|
|
|
{0.3125, -0.1875, -0.1875, 0.5, 0.1875, 0.1875}, -- +x_connector
|
|
|
|
{-0.5, -0.1875, -0.1875, -0.3125, 0.1875, 0.1875}, -- -x_connector
|
|
|
|
{-0.1875, -0.1875, 0.3125, 0.1875, 0.1875, 0.5}, -- +z_connector
|
|
|
|
{-0.5, 0.125, -0.5, -0.125, 0.5, -0.3125}, -- back_connector_3
|
|
|
|
{0.125, 0.125, -0.5, 0.5, 0.5, -0.3125}, -- back_connector_1
|
|
|
|
{0.125, -0.5, -0.5, 0.5, -0.125, -0.3125}, -- back_connector_2
|
|
|
|
{-0.5, -0.5, -0.5, -0.125, -0.125, -0.3125}, -- back_connector_4
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
local get_controller_unconstructed_formspec = function(pos, player_name)
|
|
|
|
return "size[8,8]button[1,1;1,1;construct;Construct]"
|
|
|
|
end
|
|
|
|
|
2019-08-18 10:23:08 +02:00
|
|
|
local get_controller_constructed_formspec = function(pos, digtron_id_name, player_name)
|
2019-08-18 21:02:42 +02:00
|
|
|
digtron.retrieve_inventory(digtron_id_name)
|
2019-08-18 10:23:08 +02:00
|
|
|
|
2019-08-18 21:02:42 +02:00
|
|
|
return "size[9,9]button[1,0;1,1;deconstruct;Deconstruct]"
|
|
|
|
.. "list[detached:" .. digtron_id_name .. ";main;1,1;8,2]" -- TODO: paging system for inventory
|
|
|
|
.. "list[detached:" .. digtron_id_name .. ";fuel;1,3.5;8,2]" -- TODO: paging system for inventory
|
|
|
|
.."container[1,5]list[current_player;main;0,0;8,1;]list[current_player;main;0,1.25;8,3;8]container_end[]"
|
|
|
|
.."listring[current_player;main]"
|
|
|
|
.."listring[detached:" .. digtron_id_name .. ";main]"
|
2019-08-17 09:47:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("digtron:controller", {
|
|
|
|
description = S("Digtron Control Module"),
|
|
|
|
_doc_items_longdesc = nil,
|
|
|
|
_doc_items_usagehelp = nil,
|
|
|
|
groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 1},
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2= "facedir",
|
|
|
|
is_ground_content = false,
|
|
|
|
-- Aims in the +Z direction by default
|
|
|
|
tiles = {
|
|
|
|
"digtron_plate.png^[transformR90",
|
|
|
|
"digtron_plate.png^[transformR270",
|
|
|
|
"digtron_plate.png",
|
|
|
|
"digtron_plate.png^[transformR180",
|
|
|
|
"digtron_plate.png",
|
|
|
|
"digtron_plate.png^digtron_control.png",
|
|
|
|
},
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = controller_nodebox,
|
|
|
|
|
|
|
|
-- on_construct = function(pos)
|
|
|
|
-- end,
|
|
|
|
|
|
|
|
on_dig = function(pos, node, digger)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2019-08-18 10:23:08 +02:00
|
|
|
if meta:get_string("digtron_id") ~= "" then
|
2019-08-18 21:02:42 +02:00
|
|
|
return -- TODO: special handling here!
|
2019-08-17 09:47:16 +02:00
|
|
|
else
|
|
|
|
return minetest.node_dig(pos, node, digger)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2019-08-18 10:23:08 +02:00
|
|
|
local digtron_id = meta:get_string("digtron_id")
|
2019-08-17 09:47:16 +02:00
|
|
|
local player_name = clicker:get_player_name()
|
2019-08-18 10:23:08 +02:00
|
|
|
if digtron_id == "" then
|
2019-08-17 09:47:16 +02:00
|
|
|
minetest.show_formspec(player_name,
|
|
|
|
"digtron_controller_unconstructed:"..minetest.pos_to_string(pos)..":"..player_name,
|
|
|
|
get_controller_unconstructed_formspec(pos, player_name))
|
|
|
|
else
|
|
|
|
-- initialized
|
|
|
|
minetest.show_formspec(player_name,
|
|
|
|
"digtron_controller_constructed:"..minetest.pos_to_string(pos)..":"..player_name..":"..digtron_id,
|
2019-08-18 07:12:12 +02:00
|
|
|
get_controller_constructed_formspec(pos, digtron_id, player_name))
|
2019-08-17 09:47:16 +02:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_timer = function(pos, elapsed)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Dealing with an unconstructed Digtron controller
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
local formname_split = formname:split(":")
|
|
|
|
if #formname_split ~= 3 or formname_split[1] ~= "digtron_controller_unconstructed" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local pos = minetest.string_to_pos(formname_split[2])
|
|
|
|
if pos == nil then
|
|
|
|
minetest.log("error", "[Digtron] Unable to parse position from formspec name " .. formname)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name = formname_split[3]
|
|
|
|
if player:get_player_name() ~= name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields.construct then
|
|
|
|
local digtron_id = digtron.construct(pos, name)
|
|
|
|
if digtron_id then
|
2019-08-18 07:12:12 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2019-08-18 10:23:08 +02:00
|
|
|
meta:set_string("digtron_id", digtron_id)
|
2019-08-17 09:47:16 +02:00
|
|
|
minetest.show_formspec(name,
|
|
|
|
"digtron_controller_constructed:"..minetest.pos_to_string(pos)..":"..name..":"..digtron_id,
|
2019-08-18 07:12:12 +02:00
|
|
|
get_controller_constructed_formspec(pos, digtron_id, name))
|
2019-08-17 09:47:16 +02:00
|
|
|
end
|
|
|
|
end
|
2019-08-18 07:12:12 +02:00
|
|
|
|
2019-08-17 09:47:16 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- Controlling a fully armed and operational Digtron
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
local formname_split = formname:split(":")
|
|
|
|
if #formname_split ~= 4 or formname_split[1] ~= "digtron_controller_constructed" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local pos = minetest.string_to_pos(formname_split[2])
|
|
|
|
if pos == nil then
|
|
|
|
minetest.log("error", "[Digtron] Unable to parse position from formspec name " .. formname)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name = formname_split[3]
|
|
|
|
if player:get_player_name() ~= name then
|
|
|
|
return
|
|
|
|
end
|
2019-08-18 07:12:12 +02:00
|
|
|
local digtron_id = formname_split[4]
|
2019-08-17 09:47:16 +02:00
|
|
|
|
|
|
|
if fields.deconstruct then
|
|
|
|
minetest.chat_send_all("Deconstructing " .. digtron_id)
|
2019-08-18 07:12:12 +02:00
|
|
|
|
|
|
|
local meta = minetest.get_meta(pos)
|
2019-08-18 10:23:08 +02:00
|
|
|
local digtron_id = meta:get_string("digtron_id")
|
|
|
|
if digtron_id == "" then
|
2019-08-18 07:12:12 +02:00
|
|
|
minetest.log("error", "[Digtron] tried to deconstruct Digtron at pos "
|
|
|
|
.. minetest.pos_to_string(pos) .. " but it had no digtron_id in the node's metadata")
|
|
|
|
else
|
|
|
|
digtron.deconstruct(digtron_id, pos, name)
|
|
|
|
minetest.show_formspec(name,
|
|
|
|
"digtron_controller_unconstructed:"..minetest.pos_to_string(pos)..":"..name,
|
|
|
|
get_controller_unconstructed_formspec(pos, name))
|
|
|
|
end
|
2019-08-17 09:47:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end)
|