BobBlocks/health.lua
Vanessa Ezekowitz 20221b2618 minetest.env:* --> minetest.* (#2)
* minetest.env:* --> minetest.*

* tile_images --> tiles

* Add standard mod files.

* Rewrote the mod to use the new param2 color method
New dependency on Unified Dyes.

This change comes with a few neutral-to-positive side effects:

1) Minor recipe changes were necessary since there are only two blocks and
   two poles now.
2) All recipes, node names, etc. were updated to current minetest API.
3) Where recipes called for leaves or sticks, I used groups.
4) the "wavy" (formerly "grey") block and fence/pole can now be
   colored as well.
5) Inside the conversion LBM, some of the original colors were re-mapped
   to the closest Unified Dyes equivalents, to try to keep the on-screen
   appearance mostly the same after conversion.
6) Aside from "BTM" and "Health", all block and pole nodes can take on the
   entire Unified Dyes palette instead of just the 9 originally offered.

Mod works the same as others that depend on Unified Dyes - craft and place
a block or pole, then right-click on it with dye to colorize it.

* unified dyes uses on_use now, instead of on_rightclick

* don't run the LBM at every load
2017-02-19 08:12:17 -05:00

96 lines
2.5 KiB
Lua

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
minetest.add_node(pos, {name = nodename})
end
local toggle_healthpack = function (pos, node)
if not is_healthgate(node) then return end
update_healthpack (pos, node, state)
end
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",
tiles = {"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",
tiles = {"bobblocks_health_on.png"},
paramtype2 = "facedir",
legacy_facedir_simple = true,
light_source = LIGHT_MAX-0,
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)
local objs = minetest.get_objects_inside_radius(pos, 1)
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()+10) -- give 10HP
minetest.remove_node(pos) -- remove the node after use
end
end,
})
--- 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)