From c43b8baff435bf58581aa2ce3b250033de6905bc Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 8 May 2018 18:22:08 +0200 Subject: [PATCH] =?UTF-8?q?Refactor=20arrow=E2=86=92button=20hit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mods/ITEMS/REDSTONE/mesecons_button/init.lua | 26 ++++++++++++++++---- mods/ITEMS/mcl_bows/arrow.lua | 4 +-- mods/ITEMS/mcl_bows/depends.txt | 1 + 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mesecons_button/init.lua b/mods/ITEMS/REDSTONE/mesecons_button/init.lua index 362d8c7c73..3e34670e0b 100644 --- a/mods/ITEMS/REDSTONE/mesecons_button/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_button/init.lua @@ -17,6 +17,20 @@ local boxes_on = { wall_top = { -4/16, 7/16, -2/16, 4/16, 8/16, 2/16 }, } +-- Push the button +mesecon.push_button = function(pos, node) + -- No-op if button is already pushed + if mesecon.is_receptor_on(node) then + return + end + local def = minetest.registered_nodes[node.name] + minetest.set_node(pos, {name="mesecons_button:button_"..def._mcl_button_basename.."_on", param2=node.param2}) + mesecon.receptor_on(pos, button_get_output_rules(node)) + minetest.sound_play("mesecons_button_push", {pos=pos}) + local timer = minetest.get_node_timer(pos) + timer:start(def._mcl_button_timer) +end + local on_button_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then -- no interaction possible with entities @@ -103,17 +117,16 @@ mesecon.register_button = function(basename, description, texture, recipeitem, s on_place = on_button_place, node_placement_prediction = "", on_rightclick = function (pos, node) - minetest.set_node(pos, {name="mesecons_button:button_"..basename.."_on", param2=node.param2}) - mesecon.receptor_on(pos, button_get_output_rules(node)) - minetest.sound_play("mesecons_button_push", {pos=pos}) - local timer = minetest.get_node_timer(pos) - timer:start(button_timer) + mesecon.push_button(pos, node) end, sounds = sounds, mesecons = {receptor = { state = mesecon.state.off, rules = button_get_output_rules, }}, + _mcl_button_basename = basename, + _mcl_button_timer = button_timer, + _mcl_blast_resistance = 2.5, _mcl_hardness = 0.5, }) @@ -139,6 +152,8 @@ mesecon.register_button = function(basename, description, texture, recipeitem, s state = mesecon.state.on, rules = button_get_output_rules }}, + _mcl_button_basename = basename, + _mcl_button_timer = button_timer, on_timer = function(pos, elapsed) local node = minetest.get_node(pos) if node.name=="mesecons_button:button_"..basename.."_on" then --has not been dug @@ -163,6 +178,7 @@ mesecon.register_button = function(basename, description, texture, recipeitem, s mesecon.receptor_off(pos, button_get_output_rules(node)) end end, + _mcl_blast_resistance = 2.5, _mcl_hardness = 0.5, }) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 019cdb4abc..8d05afface 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -177,8 +177,8 @@ ARROW_ENTITY.on_step = function(self, dtime) self.object:set_velocity({x=0, y=0, z=0}) self.object:set_acceleration({x=0, y=0, z=0}) -- Push the button - if minetest.get_item_group(node.name, "button") > 0 and minetest.get_item_group(node.name, "button_push_by_arrow") == 1 and def.on_rightclick then - def.on_rightclick(pos, node) + if minetest.get_modpath("mesecons_button") and minetest.get_item_group(node.name, "button") > 0 and minetest.get_item_group(node.name, "button_push_by_arrow") == 1 then + mesecon.push_button(pos, node) end elseif (def and def.liquidtype ~= "none") then -- Slow down arrow in liquids diff --git a/mods/ITEMS/mcl_bows/depends.txt b/mods/ITEMS/mcl_bows/depends.txt index 98f2eaa73d..eb7f075a1c 100644 --- a/mods/ITEMS/mcl_bows/depends.txt +++ b/mods/ITEMS/mcl_bows/depends.txt @@ -6,3 +6,4 @@ mcl_core? mcl_mobitems? mcl_playerphysics? doc? +mesecons_button?