From 7082e1ab0d63a061c02a32a3340cd1435899bc99 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sun, 3 Jul 2022 16:07:38 +0200 Subject: [PATCH] Add time & name commands to the TA4 button --- basic_machines/grinder.lua | 5 ++++- basis/fly_lib.lua | 5 ++--- logic/button.lua | 31 +++++++++++++++++++++++++++++++ manuals/ta4_lua_controller_EN.md | 4 +++- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/basic_machines/grinder.lua b/basic_machines/grinder.lua index e41b2fa..97a8340 100644 --- a/basic_machines/grinder.lua +++ b/basic_machines/grinder.lua @@ -56,7 +56,10 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) return 0 end if listname == "src" then - CRD(pos).State:start_if_standby(pos) + local state = CRD(pos).State + if state then + state:start_if_standby(pos) + end end return stack:get_count() end diff --git a/basis/fly_lib.lua b/basis/fly_lib.lua index 742407b..be1a137 100644 --- a/basis/fly_lib.lua +++ b/basis/fly_lib.lua @@ -318,8 +318,7 @@ local function entity_to_node(pos, obj) local nvm = techage.get_nvm(self.base_pos) nvm.running = nil end - minetest.after(0.2, obj.remove, obj) - + minetest.after(0.1, obj.remove, obj) local node = minetest.get_node(pos) local ndef1 = minetest.registered_nodes[name] local ndef2 = minetest.registered_nodes[node.name] @@ -358,7 +357,7 @@ local function node_to_entity(start_pos) -- Block with other metadata node = minetest.get_node(start_pos) metadata = meta:to_table() - minetest.after(0.2, minetest.remove_node, start_pos) + minetest.after(0.1, minetest.remove_node, start_pos) else return end diff --git a/logic/button.lua b/logic/button.lua index 651fc37..c04d1f3 100644 --- a/logic/button.lua +++ b/logic/button.lua @@ -152,6 +152,9 @@ local function on_rightclick_on(pos, node, clicker) if fixed == "true" then if can_access(pos, clicker) then switch_on(pos) + local mem = techage.get_mem(pos) + mem.clicker = clicker and clicker:get_player_name() + mem.time = math.floor(minetest.get_us_time() / 100000) end end end @@ -334,3 +337,31 @@ minetest.register_craft({ {"", "", ""}, }, }) + +techage.register_node({ + "techage:ta4_button_off", "techage:ta4_button_on", + }, { + on_recv_message = function(pos, src, topic, payload) + if topic == "name" then + local mem = techage.get_mem(pos) + return mem.clicker or "" + elseif topic == "time" then + local mem = techage.get_mem(pos) + return mem.time or 0 + else + return "unsupported" + end + end, + on_beduino_request_data = function(pos, src, topic, payload) + if topic == 144 then -- Player Name + local mem = techage.get_mem(pos) + return 0, mem.clicker + elseif topic == 149 then --time + local mem = techage.get_mem(pos) + return 0, {mem.time or 0} + else + return 2, "" + end + end, + } +) diff --git a/manuals/ta4_lua_controller_EN.md b/manuals/ta4_lua_controller_EN.md index 07c1b61..a9c3315 100644 --- a/manuals/ta4_lua_controller_EN.md +++ b/manuals/ta4_lua_controller_EN.md @@ -374,7 +374,9 @@ Please note, that this is not a technical distinction, only a logical. | "count" | number of items | Read the total amount of TA4 chest items. An optional number as `add_data` is used to address only one inventory slot (1..8, from left to right). | | "itemstring" | item string of the given slot | Specific command for the TA4 8x2000 Chest to read the item type (technical name) of one chest slot, specified via `add_data` (1..8).
Example: s = $send_cmnd("223", "itemstring", 1) | | "output" | recipe output string,
e.g.: "default:glass" | Only for the Industrial Furnace. If no recipe is active, the command returns "unknown" | -| "input" | `` | Read a recipe from the TA4 Recipe Block. `` is the number of the recipe. The block return a list of recipe items. | +| "input" | \ | Read a recipe from the TA4 Recipe Block. `` is the number of the recipe. The block return a list of recipe items. | +| "name" | \ | Player name of the TA3/TA4 Player Detector or TA4 Button | +| "time" | number | Time in system ticks (norm. 100 ms) when the TA4 Button is clicked |