mirror of
https://github.com/joe7575/techpack.git
synced 2024-12-26 23:47:32 +01:00
v1.9 Controller commands get_counter() and clear_counter() added, Autocrafter got a command interface, some improvements to the robot, but still WIP(!)
This commit is contained in:
parent
965c272e57
commit
b3563d6d24
@ -1,4 +1,4 @@
|
||||
# TechPack V1.08
|
||||
# TechPack V1.09
|
||||
|
||||
TechPack, a Mining, Crafting, & Farming Modpack for Minetest.
|
||||
|
||||
@ -84,3 +84,4 @@ Gravelsieve optional: moreores, hopper, pipeworks
|
||||
- 2018-06-09 V1.06 * Recipes with API to grinder added
|
||||
- 2018-06-17 V1.07 * Tube placement completely reworked
|
||||
- 2018-06-22 V1.08 * Lua Controller and SaferLua added
|
||||
- 2018-07-22 V1.09 * Item counters for Pusher/Distributor and tubelib commands for Autocrafter added
|
||||
|
@ -36,6 +36,30 @@ sl_controller.register_function("get_status", {
|
||||
' example: sts = $get_status("1234")'
|
||||
})
|
||||
|
||||
sl_controller.register_function("get_counter", {
|
||||
cmnd = function(self, num)
|
||||
num = tostring(num or "")
|
||||
return tubelib.send_request(num, "counter", nil)
|
||||
end,
|
||||
help = " $get_counter(num)\n"..
|
||||
" Read number of pushed items from a\n"..
|
||||
" Pusher/Distributor node.\n"..
|
||||
" The Pusher returns a single value (number)\n"..
|
||||
" The Distributor returns a list with 4 values\n"..
|
||||
" like: {red=1, green=0, blue=8, yellow=0}\n"..
|
||||
' example: cnt = $get_counter("1234")\n'
|
||||
})
|
||||
|
||||
sl_controller.register_function("clear_counter", {
|
||||
cmnd = function(self, num)
|
||||
num = tostring(num or "")
|
||||
return tubelib.send_request(num, "clear_counter", nil)
|
||||
end,
|
||||
help = " $clear_counter(num)\n"..
|
||||
" Set counter(s) from Pusher/Distributor to zero.\n"..
|
||||
' example: $clear_counter("1234")'
|
||||
})
|
||||
|
||||
sl_controller.register_function("get_fuel_status", {
|
||||
cmnd = function(self, num)
|
||||
num = tostring(num or "")
|
||||
|
@ -25,7 +25,7 @@ sl_robot.register_action("get_ms_time", {
|
||||
|
||||
sl_robot.register_action("forward", {
|
||||
cmnd = function(self, steps)
|
||||
steps = math.min(tonumber(steps or 1), 9)
|
||||
steps = math.min(tonumber(steps or 1), 100)
|
||||
local idx = 1
|
||||
while idx <= steps do
|
||||
local meta = minetest.get_meta(self.meta.pos)
|
||||
@ -49,7 +49,7 @@ sl_robot.register_action("forward", {
|
||||
|
||||
sl_robot.register_action("backward", {
|
||||
cmnd = function(self, steps)
|
||||
steps = math.min(tonumber(steps or 1), 9)
|
||||
steps = math.min(tonumber(steps or 1), 100)
|
||||
local idx = 1
|
||||
while idx <= steps do
|
||||
local meta = minetest.get_meta(self.meta.pos)
|
||||
@ -216,3 +216,16 @@ sl_robot.register_action("stop", {
|
||||
help = "tbd"
|
||||
})
|
||||
|
||||
--sl_robot.register_action("run", {
|
||||
-- cmnd = function(self, sCmd, reverse)
|
||||
-- slot = math.min(tonumber(slot or 1), 8)
|
||||
-- local meta = minetest.get_meta(self.meta.pos)
|
||||
-- local robot_pos = minetest.string_to_pos(meta:get_string("robot_pos"))
|
||||
-- local robot_param2 = meta:get_int("robot_param2")
|
||||
|
||||
-- for cmnd in sCmd:gmatch("%w+") do
|
||||
-- if cmnd:byte()
|
||||
-- end
|
||||
-- end,
|
||||
-- help = " "
|
||||
--})
|
||||
|
@ -347,6 +347,7 @@ function sl_robot.robot_dig(base_pos, robot_pos, param2, owner, dir, slot)
|
||||
local src_inv = minetest.get_inventory({type="node", pos=base_pos})
|
||||
local src_list = src_inv:get_list("main")
|
||||
src_list[slot]:add_item(item)
|
||||
src_inv:set_list("main", src_list)
|
||||
end
|
||||
end
|
||||
|
||||
@ -373,6 +374,8 @@ minetest.register_node("sl_robot:robot", {
|
||||
},
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly=0, not_in_creative_inventory = 1},
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
@ -389,6 +392,8 @@ minetest.register_node("sl_robot:robot_leg", {
|
||||
},
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly=0, not_in_creative_inventory = 1},
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
@ -406,6 +411,8 @@ minetest.register_node("sl_robot:robot_foot", {
|
||||
},
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly=0, not_in_creative_inventory = 1},
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
|
@ -23,13 +23,14 @@ local Version = minetest.deserialize(storage:get_string("Version")) or 1
|
||||
local Number2Pos = minetest.deserialize(storage:get_string("Number2Pos")) or {}
|
||||
|
||||
local function update_mod_storage()
|
||||
minetest.log("action", "[Tubelib] Store data...")
|
||||
storage:set_string("NextNumber", minetest.serialize(NextNumber))
|
||||
storage:set_string("Version", minetest.serialize(Version))
|
||||
storage:set_string("Number2Pos", minetest.serialize(Number2Pos))
|
||||
storage:set_string("Key2Number", nil) -- not used any more
|
||||
-- store data each hour
|
||||
minetest.after(60*60, update_mod_storage)
|
||||
print("[Tubelib] Data stored")
|
||||
minetest.log("action", "[Tubelib] Data stored")
|
||||
end
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
|
@ -213,6 +213,8 @@ local function keep_running(pos, elapsed)
|
||||
local inv = meta:get_inventory()
|
||||
local list = inv:get_list("src")
|
||||
local kvSrc = invlist_content_as_kvlist(list)
|
||||
local counter = minetest.deserialize(meta:get_string("item_counter") or
|
||||
{red=0, green=0, blue=0, yellow=0})
|
||||
|
||||
-- calculate the filter settings only once
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
@ -241,6 +243,7 @@ local function keep_running(pos, elapsed)
|
||||
if not tubelib.push_items(pos, side, item, player_name) then -- <<=== tubelib
|
||||
tubelib.put_item(meta, "src", item)
|
||||
else
|
||||
counter[listname] = counter[listname] + 1
|
||||
busy = true
|
||||
end
|
||||
end
|
||||
@ -257,6 +260,7 @@ local function keep_running(pos, elapsed)
|
||||
if not tubelib.push_items(pos, side, item, player_name) then -- <<=== tubelib
|
||||
tubelib.put_item(meta, "src", item)
|
||||
else
|
||||
counter[listname] = counter[listname] + 1
|
||||
busy = true
|
||||
end
|
||||
end
|
||||
@ -276,6 +280,7 @@ local function keep_running(pos, elapsed)
|
||||
end
|
||||
end
|
||||
|
||||
meta:set_string("item_counter", minetest.serialize(counter))
|
||||
meta:set_int("running", running)
|
||||
return true
|
||||
end
|
||||
@ -357,6 +362,7 @@ minetest.register_node("tubelib:distributor", {
|
||||
inv:set_size('green', 6)
|
||||
inv:set_size('red', 6)
|
||||
inv:set_size('blue', 6)
|
||||
meta:set_string("item_counter", minetest.serialize({red=0, green=0, blue=0, yellow=0}))
|
||||
end,
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
@ -462,6 +468,13 @@ tubelib.register_node("tubelib:distributor", {"tubelib:distributor_active"}, {
|
||||
return tubelib.statestring(running)
|
||||
elseif topic == "filter" then
|
||||
return change_filter_settings(pos, payload.slot, payload.val)
|
||||
elseif topic == "counter" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
return minetest.deserialize(meta:get_string("item_counter") or
|
||||
{red=0, green=0, blue=0, yellow=0})
|
||||
elseif topic == "clear_counter" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("item_counter", minetest.serialize({red=0, green=0, blue=0, yellow=0}))
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
|
@ -88,6 +88,7 @@ local function keep_running(pos, elapsed)
|
||||
local node = minetest.get_node(pos)
|
||||
return goto_blocked(pos, node)
|
||||
end
|
||||
meta:set_int("item_counter", meta:get_int("item_counter") + 1)
|
||||
if running <= 0 then
|
||||
local node = minetest.get_node(pos)
|
||||
return switch_on(pos, node)
|
||||
@ -123,6 +124,7 @@ minetest.register_node("tubelib:pusher", {
|
||||
local number = tubelib.add_node(pos, "tubelib:pusher") -- <<=== tubelib
|
||||
meta:set_string("number", number)
|
||||
meta:set_string("infotext", "Pusher "..number..": stopped")
|
||||
meta:set_int("item_counter", 0)
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
@ -238,6 +240,12 @@ tubelib.register_node("tubelib:pusher", {"tubelib:pusher_active"}, {
|
||||
local meta = minetest.get_meta(pos)
|
||||
local running = meta:get_int("running") or tubelib.STATE_STOPPED
|
||||
return tubelib.statestring(running)
|
||||
elseif topic == "counter" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
return meta:get_int("item_counter")
|
||||
elseif topic == "clear_counter" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
return meta:set_int("item_counter", 0)
|
||||
else
|
||||
return "not supported"
|
||||
end
|
||||
|
@ -164,6 +164,8 @@ local function run_autocrafter(pos, elapsed)
|
||||
return true
|
||||
end
|
||||
|
||||
meta:set_int("item_counter", meta:get_int("item_counter") + output_item:get_count())
|
||||
|
||||
if running <= 0 then
|
||||
return start_crafter(pos)
|
||||
else
|
||||
@ -381,6 +383,7 @@ minetest.register_node("tubelib_addons1:autocrafter", {
|
||||
inv:set_size("output", 1)
|
||||
meta:set_string("number", number)
|
||||
meta:set_int("running", 0)
|
||||
meta:set_int("item_counter", 0)
|
||||
update_meta(meta, tubelib.STOPPED)
|
||||
end,
|
||||
|
||||
@ -464,4 +467,23 @@ tubelib.register_node("tubelib_addons1:autocrafter", {"tubelib_addons1:autocraft
|
||||
local meta = minetest.get_meta(pos)
|
||||
return tubelib.put_item(meta, "dst", item)
|
||||
end,
|
||||
on_recv_message = function(pos, topic, payload)
|
||||
if topic == "on" then
|
||||
return start_crafter(pos)
|
||||
elseif topic == "off" then
|
||||
return stop_crafter(pos)
|
||||
elseif topic == "state" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
local running = meta:get_int("running")
|
||||
return tubelib.statestring(running)
|
||||
elseif topic == "counter" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
return meta:get_int("item_counter")
|
||||
elseif topic == "clear_counter" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
return meta:set_int("item_counter", 0)
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
@ -88,6 +88,7 @@ local function keep_running(pos, elapsed)
|
||||
local node = minetest.get_node(pos)
|
||||
return goto_blocked(pos, node)
|
||||
end
|
||||
meta:set_int("item_counter", meta:get_int("item_counter") + 1)
|
||||
if running <= 0 then
|
||||
local node = minetest.get_node(pos)
|
||||
return switch_on(pos, node)
|
||||
@ -123,6 +124,7 @@ minetest.register_node("tubelib_addons1:pusher_fast", {
|
||||
local number = tubelib.add_node(pos, "tubelib_addons1:pusher_fast")
|
||||
meta:set_string("number", number)
|
||||
meta:set_string("infotext", "Pusher "..number..": stopped")
|
||||
meta:set_int("item_counter", 0)
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
@ -238,6 +240,12 @@ tubelib.register_node("tubelib_addons1:pusher_fast", {"tubelib_addons1:pusher_fa
|
||||
local meta = minetest.get_meta(pos)
|
||||
local running = meta:get_int("running") or tubelib.STATE_STOPPED
|
||||
return tubelib.statestring(running)
|
||||
elseif topic == "counter" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
return meta:get_int("item_counter")
|
||||
elseif topic == "clear_counter" then
|
||||
local meta = minetest.get_meta(pos)
|
||||
return meta:set_int("item_counter", 0)
|
||||
else
|
||||
return "not supported"
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user