mirror of
https://github.com/joe7575/techpack.git
synced 2024-12-25 23:17:36 +01:00
command "num_items" added to Warehouse Boxes
This commit is contained in:
parent
1206e5a461
commit
952b0f1284
@ -82,6 +82,18 @@ sl_controller.register_function("get_fuel_status", {
|
||||
' example: sts = $get_fuel_status("1234")'
|
||||
})
|
||||
|
||||
sl_controller.register_function("get_num_items", {
|
||||
cmnd = function(self, num, idx)
|
||||
num = tostring(num or "")
|
||||
idx = tonumber(idx)
|
||||
return tubelib.send_request(num, "num_items", idx)
|
||||
end,
|
||||
help = " $get_num_items(num)\n"..
|
||||
" Read number of stored items in one\n"..
|
||||
" storage (1..8) from a Warehouse Box.\n"..
|
||||
' example: cnt = $get_num_items("1234", 4)\n'
|
||||
})
|
||||
|
||||
sl_controller.register_function("time_as_str", {
|
||||
cmnd = function(self)
|
||||
local t = minetest.get_timeofday()
|
||||
|
@ -152,6 +152,8 @@ tubelib.register_node(NODE_NAME,
|
||||
local resp = Box.State:on_receive_message(pos, topic, payload)
|
||||
if resp then
|
||||
return resp
|
||||
elseif topic == "num_items" then
|
||||
return wh.get_num_items(M(pos), payload)
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
|
@ -152,6 +152,8 @@ tubelib.register_node(NODE_NAME,
|
||||
local resp = Box.State:on_receive_message(pos, topic, payload)
|
||||
if resp then
|
||||
return resp
|
||||
elseif topic == "num_items" then
|
||||
return wh.get_num_items(M(pos), payload)
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
|
@ -152,6 +152,8 @@ tubelib.register_node(NODE_NAME,
|
||||
local resp = Box.State:on_receive_message(pos, topic, payload)
|
||||
if resp then
|
||||
return resp
|
||||
elseif topic == "num_items" then
|
||||
return wh.get_num_items(M(pos), payload)
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
|
@ -63,12 +63,14 @@ local function move_to_main(pos, index)
|
||||
local main_stack = inv:get_stack("main", index)
|
||||
local inp_stack = inv:get_stack("input", index)
|
||||
|
||||
local stack = ItemStack(inp_stack:get_name())
|
||||
stack:set_count(inp_stack:get_count() + main_stack:get_count())
|
||||
inp_stack:clear()
|
||||
|
||||
inv:set_stack("main", index, stack)
|
||||
inv:set_stack("input", index, inp_stack)
|
||||
if inp_stack:get_name() ~= "" then
|
||||
local stack = ItemStack(inp_stack:get_name())
|
||||
stack:set_count(inp_stack:get_count() + main_stack:get_count())
|
||||
inp_stack:clear()
|
||||
|
||||
inv:set_stack("main", index, stack)
|
||||
inv:set_stack("input", index, inp_stack)
|
||||
end
|
||||
end
|
||||
|
||||
function techpack_warehouse.tiles(background_img)
|
||||
@ -309,3 +311,11 @@ function techpack_warehouse.after_dig_node(self, pos, oldnode, oldmetadata, digg
|
||||
self.State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end
|
||||
end
|
||||
|
||||
function techpack_warehouse.get_num_items(meta, index)
|
||||
index = index and tonumber(index)
|
||||
if index < 1 then index = 1 end
|
||||
if index > 8 then index = 8 end
|
||||
local inv = meta:get_inventory()
|
||||
return inv:get_stack("main", index):get_count()
|
||||
end
|
Loading…
Reference in New Issue
Block a user