2014-11-29 15:40:55 +01:00
|
|
|
local is_healthpack = function(node)
|
|
|
|
if node.name == 'bobblocks:health_off' or node.name == 'health_on' then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local update_healthpack = function (pos, node)
|
|
|
|
local nodename=""
|
|
|
|
local param2=""
|
|
|
|
--Switch HealthPack State
|
|
|
|
if node.name == 'bobblocks:health_off' then
|
|
|
|
nodename = 'bobblocks:health_on'
|
|
|
|
elseif node.name == 'bobblocks:health_on' then
|
|
|
|
nodename = 'bobblocks:health_off'
|
|
|
|
end
|
2015-02-02 18:37:29 +01:00
|
|
|
minetest.add_node(pos, {name = nodename})
|
2014-11-29 15:40:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local toggle_healthpack = function (pos, node)
|
|
|
|
if not is_healthgate(node) then return end
|
|
|
|
update_healthpack (pos, node, state)
|
|
|
|
end
|
2015-05-23 18:33:53 +02:00
|
|
|
|
2014-11-29 15:40:55 +01:00
|
|
|
local on_healthpack_punched = function (pos, node, puncher)
|
|
|
|
if node.name == 'bobblocks:health_off' or node.name == 'bobblocks:health_on' then
|
|
|
|
update_healthpack(pos, node)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Healing Node
|
|
|
|
|
|
|
|
minetest.register_node("bobblocks:health_off", {
|
|
|
|
description = "Health Pack 1 Off",
|
|
|
|
tile_images = {"bobblocks_health_off.png"},
|
|
|
|
inventory_image = "bobblocks_health_off.png",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
legacy_facedir_simple = true,
|
|
|
|
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
|
|
|
|
is_ground_content = true,
|
|
|
|
walkable = false,
|
|
|
|
climbable = false,
|
|
|
|
mesecons = {conductor={
|
|
|
|
state = mesecon.state.off,
|
|
|
|
onstate = "bobblocks:health_on"
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("bobblocks:health_on", {
|
|
|
|
description = "Health Pack 1 On",
|
|
|
|
tile_images = {"bobblocks_health_on.png"},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
legacy_facedir_simple = true,
|
2015-03-03 18:22:38 +01:00
|
|
|
light_source = default.LIGHT_MAX-1,
|
2014-11-29 15:40:55 +01:00
|
|
|
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
|
|
|
|
is_ground_content = true,
|
|
|
|
walkable = false,
|
|
|
|
climbable = false,
|
|
|
|
drop = "bobblocks:health_off",
|
|
|
|
mesecons = {conductor={
|
|
|
|
state = mesecon.state.on,
|
|
|
|
offstate = "bobblocks:health_off"
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_abm(
|
|
|
|
{nodenames = {"bobblocks:health_on"},
|
|
|
|
interval = 1.0,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2015-02-02 18:37:29 +01:00
|
|
|
local objs = minetest.get_objects_inside_radius(pos, 1)
|
2014-11-29 15:40:55 +01:00
|
|
|
for k, obj in pairs(objs) do
|
|
|
|
minetest.sound_play("bobblocks_health",
|
|
|
|
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
|
|
|
obj:set_hp(obj:get_hp()+5) -- give 2.5HP
|
2015-02-02 18:37:29 +01:00
|
|
|
minetest.remove_node(pos) -- remove the node after use
|
2014-11-29 15:40:55 +01:00
|
|
|
end
|
|
|
|
end,
|
2015-05-23 18:33:53 +02:00
|
|
|
|
2014-11-29 15:40:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
--- Health
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = 'NodeItem "bobblocks:health_off" 1',
|
|
|
|
recipe = {
|
|
|
|
{'node "default:dirt" 1', 'node "default:paper" 1', 'node "default:apple" 2'},
|
|
|
|
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_punchnode(on_healthpack_punched)
|
|
|
|
|