Fix dependency on technic to ensure proper mod loading.

Always load remote, should work fine without technic.
Don't pass pake_max or queries into chest_formspec for remotes.
Wire up charging to the remote.
Fix query state.
This commit is contained in:
Mike Stump 2024-01-06 15:03:22 -08:00
parent a06c6539fa
commit a4b8870166
3 changed files with 39 additions and 51 deletions

@ -1,4 +1,4 @@
name = microexpansion name = microexpansion
description = A storage managing solution to get an overview over all your items. description = A storage managing solution to get an overview over all your items.
depends = default depends = default
optional_depends = pipeworks, drawers, technic_plus optional_depends = pipeworks, drawers, technic, technic_plus

@ -16,6 +16,7 @@ dofile(module_path.."/terminal.lua")
dofile(module_path.."/cterminal.lua") dofile(module_path.."/cterminal.lua")
dofile(module_path.."/cmonitor.lua") dofile(module_path.."/cmonitor.lua")
dofile(module_path.."/interface.lua") dofile(module_path.."/interface.lua")
dofile(module_path.."/remote.lua")
local drawers_enabled = minetest.get_modpath("drawers") and true or false local drawers_enabled = minetest.get_modpath("drawers") and true or false
if drawers_enabled then if drawers_enabled then
@ -24,7 +25,6 @@ if drawers_enabled then
end end
local technic_enabled = minetest.get_modpath("technic") and true or false local technic_enabled = minetest.get_modpath("technic") and true or false
if technic_enabled then if technic_enabled then
dofile(module_path.."/remote.lua")
dofile(module_path.."/technic-interop.lua") dofile(module_path.."/technic-interop.lua")
end end
local pipeworks_enabled = minetest.get_modpath("pipeworks") and true or false local pipeworks_enabled = minetest.get_modpath("pipeworks") and true or false

@ -1,6 +1,6 @@
local me = microexpansion local me = microexpansion
technic = rawget(_G, "technic") or {} --technic = rawget(_G, "technic") or {}
--local S = technic.getter --local S = technic.getter
@ -8,9 +8,6 @@ local S = function(t)
return t return t
end end
-- technic.register_power_tool("microexpansion:remote", 300000)
local function get_metadata(toolstack) local function get_metadata(toolstack)
local m = minetest.deserialize(toolstack:get_metadata()) local m = minetest.deserialize(toolstack:get_metadata())
if not m then m = {} end if not m then m = {} end
@ -23,14 +20,13 @@ local function get_metadata(toolstack)
return m return m
end end
local function chest_formspec(s, pos, start_id, listname, page_max, q) local function chest_formspec(s, pos, start_id, listname)
local list local list
local page_number = "" local page_number = ""
local buttons = "" local buttons = ""
local query = q or ""
local net,cpos = me.get_connected_network(pos) local net,cpos = me.get_connected_network(pos)
if cpos then if net then
local inv = net:get_inventory() local inv = net:get_inventory()
if listname and (inv:get_size(listname) > 0 or net:get_item_capacity() > 0) then if listname and (inv:get_size(listname) > 0 or net:get_item_capacity() > 0) then
local ctrlinvname = net:get_inventory_name() local ctrlinvname = net:get_inventory_name()
@ -70,7 +66,7 @@ local function chest_formspec(s, pos, start_id, listname, page_max, q)
button[7.25,4.35;0.8,0.9;next;>] button[7.25,4.35;0.8,0.9;next;>]
tooltip[prev;Previous] tooltip[prev;Previous]
tooltip[next;Next] tooltip[next;Next]
field[0.29,4.6;2.2,1;filter;;]]..query..[[] field[0.29,4.6;2.2,1;filter;;]]..s.query..[[]
button[2.1,4.5;0.8,0.5;search;?] button[2.1,4.5;0.8,0.5;search;?]
button[2.75,4.5;0.8,0.5;clear;X] button[2.75,4.5;0.8,0.5;clear;X]
tooltip[search;Search] tooltip[search;Search]
@ -86,9 +82,9 @@ local function chest_formspec(s, pos, start_id, listname, page_max, q)
else else
list = "label[3,2;" .. minetest.colorize("red", "No connected network!") .. "]" list = "label[3,2;" .. minetest.colorize("red", "No connected network!") .. "]"
end end
if page_max then if s.page_max then
page_number = "label[6.15,4.5;" .. math.floor((start_id / 32)) + 1 .. page_number = "label[6.15,4.5;" .. math.floor((start_id / 32)) + 1 ..
"/" .. page_max .."]" "/" .. s.page_max .."]"
end end
return [[ return [[
@ -111,53 +107,46 @@ minetest.register_tool("microexpansion:remote", {
description = S("Microexpansion Remote"), description = S("Microexpansion Remote"),
inventory_image = "technic_prospector.png", inventory_image = "technic_prospector.png",
wear_represents = "technic_RE_charge", wear_represents = "technic_RE_charge",
-- on_refill = technic.refill_RE_charge, on_refill = technic.refill_RE_charge,
on_use = function(toolstack, user, pointed_thing) on_use = function(toolstack, user, pointed_thing)
if not user or not user:is_player() or user.is_fake_player then return end if not user or not user:is_player() or user.is_fake_player then return end
local toolmeta = get_metadata(toolstack) local toolmeta = get_metadata(toolstack)
local net = nil
if pointed_thing.type == "node" then if pointed_thing.type == "node" then
local pos = pointed_thing.under local pos = pointed_thing.under
pos.z = pos.z - 1 pos.z = pos.z - 1
local net,cpos = me.get_connected_network(pos) local net,cpos = me.get_connected_network(pos)
-- TODO: ensure that pos is a crafting terminal
if net then if net then
me.log("REMOTE: is now bound", "error") minetest.chat_send_player(user:get_player_name(), "Connected to ME network, use left-click to use.")
toolmeta.terminal = pos toolmeta.terminal = pos
toolmeta.controller = cpos
local pinv = user:get_inventory() local pinv = user:get_inventory()
pinv:set_size("recipe", 3*3) pinv:set_size("recipe", 3*3)
pinv:set_size("output", 1) pinv:set_size("output", 1)
toolstack:set_metadata(minetest.serialize(toolmeta)) toolstack:set_metadata(minetest.serialize(toolmeta))
user:set_wielded_item(toolstack) user:set_wielded_item(toolstack)
else else
me.log("REMOTE: is not bound", "error") minetest.chat_send_player(user:get_player_name(), "Left-click on ME block to connect to ME network.")
return
end end
end end
if not net then
net = me.get_connected_network(toolmeta.controller)
end
local pos = toolmeta.terminal
end, end,
on_secondary_use = function(toolstack, user, pointed_thing) on_secondary_use = function(toolstack, user, pointed_thing)
if not user or not user:is_player() or user.is_fake_player then return end if not user or not user:is_player() or user.is_fake_player then return end
local toolmeta = get_metadata(toolstack) local toolmeta = get_metadata(toolstack)
local net = nil
if not net then
net = me.get_connected_network(toolmeta.terminal)
end
local pos = toolmeta.terminal local pos = toolmeta.terminal
local cpos = toolmeta.controller local net = me.get_connected_network(pos)
-- if not net then return end -- if not net then return end
local charge_to_take = 1 local charge_to_take = 100
-- if toolmeta.charge < charge_to_take then return end if toolmeta.charge < charge_to_take then
minetest.chat_send_player(user:get_player_name(), "No power left, recharge in technic battery.")
return
end
if false and not technic.creative_mode then if technic and not technic.creative_mode then
toolmeta.charge = toolmeta.charge - charge_to_take toolmeta.charge = toolmeta.charge - charge_to_take
toolstack:set_metadata(minetest.serialize(toolmeta)) toolstack:set_metadata(minetest.serialize(toolmeta))
-- technic.set_RE_wear(toolstack, toolmeta.charge, technic.power_tools[toolstack:get_name()]) technic.set_RE_wear(toolstack, toolmeta.charge, technic.power_tools[toolstack:get_name()])
end end
local page = toolmeta.page local page = toolmeta.page
@ -165,15 +154,11 @@ minetest.register_tool("microexpansion:remote", {
local query = toolmeta.query local query = toolmeta.query
local crafts = toolmeta.crafts local crafts = toolmeta.crafts
local page_max
local inv local inv
local meta
local own_inv = user:get_inventory() local own_inv = user:get_inventory()
local ctrl_inv local ctrl_inv
if cpos then if net then
ctrl_inv = net:get_inventory() ctrl_inv = net:get_inventory()
meta = minetest.get_meta(pos)
me.log("REMOTE: invname "..inv_name.." page "..page.." query "..query.." crafts "..crafts, "error")
end end
if inv_name == "main" then if inv_name == "main" then
inv = ctrl_inv inv = ctrl_inv
@ -181,11 +166,12 @@ minetest.register_tool("microexpansion:remote", {
inv = own_inv inv = own_inv
end end
if net then if net then
page_max = math.floor(inv:get_size(inv_name) / 32) + 1 toolmeta.page_max = math.floor(inv:get_size(inv_name) / 32) + 1
toolstack:set_metadata(minetest.serialize(toolmeta))
end end
minetest.show_formspec(user:get_player_name(), "microexpansion:remote_control", minetest.show_formspec(user:get_player_name(), "microexpansion:remote_control",
chest_formspec(toolmeta, pos, page, inv_name, page_max, query)) chest_formspec(toolmeta, pos, page, inv_name))
return toolstack return toolstack
end, end,
@ -202,20 +188,17 @@ minetest.register_on_player_receive_fields(function(user, formname, fields)
toolmeta.charge = toolmeta.charge - 1 toolmeta.charge = toolmeta.charge - 1
local pos = toolmeta.terminal local pos = toolmeta.terminal
local cpos = toolmeta.controller
local net local net
if toolmeta.terminal then if pos then
net = me.get_connected_network(toolmeta.terminal) net = me.get_connected_network(pos)
end end
local page_max local page_max
local inv local inv
local meta
local own_inv = user:get_inventory() local own_inv = user:get_inventory()
local ctrl_inv local ctrl_inv
if cpos then if net then
ctrl_inv = net:get_inventory() ctrl_inv = net:get_inventory()
meta = minetest.get_meta(pos)
end end
if inv_name == "main" then if inv_name == "main" then
inv = ctrl_inv inv = ctrl_inv
@ -231,27 +214,28 @@ minetest.register_on_player_receive_fields(function(user, formname, fields)
if page + 32 <= inv:get_size(inv_name) then if page + 32 <= inv:get_size(inv_name) then
page = page + 32 page = page + 32
toolmeta.page = page toolmeta.page = page
--meta:set_string("formspec", chest_formspec(toolmeta, pos, page, inv_name, page_max, fields.filter)) --meta:set_string("formspec", chest_formspec(toolmeta, pos, page, inv_name))
end end
elseif field == "prev" then elseif field == "prev" then
if page - 32 >= 1 then if page - 32 >= 1 then
page = page - 32 page = page - 32
toolmeta.page = page toolmeta.page = page
--meta:set_string("formspec", chest_formspec(toolmeta, pos, page, inv_name, page_max, fields.filter)) --meta:set_string("formspec", chest_formspec(toolmeta, pos, page, inv_name))
end end
elseif field == "crafts" then elseif field == "crafts" then
toolmeta.crafts = value toolmeta.crafts = value
elseif field == "filter" then elseif field == "filter" then
toolmeta.filter = value toolmeta.query = value
elseif field == "search" then elseif field == "search" then
elseif field == "clear" then elseif field == "clear" then
own_inv:set_size("me_search", 0) own_inv:set_size("me_search", 0)
own_inv:set_size("me_crafts", 0) own_inv:set_size("me_crafts", 0)
toolmeta.page = 1 toolmeta.page = 1
toolmeta.inv_name = "main" toolmeta.inv_name = "main"
toolmeta.query = ""
toolmeta.crafts = "false" toolmeta.crafts = "false"
toolmeta.page_max = math.floor(ctrl_inv:get_size(inv_name) / 32) + 1 toolmeta.page_max = math.floor(inv:get_size(inv_name) / 32) + 1
--meta:set_string("formspec", chest_formspec(toolmeta, pos, 1, inv_name, page_max)) --meta:set_string("formspec", chest_formspec(toolmeta, pos, 1, inv_name))
elseif field == "tochest" then elseif field == "tochest" then
elseif field == "autocraft" then elseif field == "autocraft" then
if tonumber(value) ~= nil then if tonumber(value) ~= nil then
@ -259,7 +243,7 @@ minetest.register_on_player_receive_fields(function(user, formname, fields)
end end
elseif field == "key_enter_field" and value == "autocraft" then elseif field == "key_enter_field" and value == "autocraft" then
local count = tonumber(toolmeta.autocraft) local count = tonumber(toolmeta.autocraft)
if not own_inv:get_stack("output", 1):is_empty() and count < math.pos(2,16) then if not own_inv:get_stack("output", 1):is_empty() and count < math.pow(2,16) then
me.autocraft(me.autocrafterCache, pos, net, own_inv, ctrl_inv, count) me.autocraft(me.autocrafterCache, pos, net, own_inv, ctrl_inv, count)
end end
end end
@ -273,7 +257,11 @@ minetest.register_craft({
output = "microexpansion:remote", output = "microexpansion:remote",
recipe = { recipe = {
{"basic_materials:brass_ingot", "", "pipeworks:teleport_tube_1"}, {"basic_materials:brass_ingot", "", "pipeworks:teleport_tube_1"},
{"", "technic:control_logic_unit", "basic_materials:brass_ingot"}, {"", (technic and "technic:control_logic_unit") or "", "basic_materials:brass_ingot"},
{"", "", ""}, {"", "", ""},
} }
}) })
if technic then
technic.register_power_tool("microexpansion:remote", 450000)
end