Refactor arrow→button hit

This commit is contained in:
Wuzzy 2018-05-08 18:22:08 +02:00
parent f392e23719
commit c43b8baff4
3 changed files with 24 additions and 7 deletions

View File

@ -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,
})

View File

@ -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

View File

@ -6,3 +6,4 @@ mcl_core?
mcl_mobitems?
mcl_playerphysics?
doc?
mesecons_button?