abstract fake_fire node registration to reduce code size and make the code more maintainable

This commit is contained in:
Tim 2015-01-23 00:27:14 +01:00 committed by Vanessa Ezekowitz
parent b87ce2d2a7
commit e9bfc337d4
1 changed files with 54 additions and 160 deletions

View File

@ -1,197 +1,91 @@
local cp = nil local cp = nil
-- FLAME TYPES local function register_fake_fire(name, def)
assert(name, "local registration called without name")
assert(def, "local registration called without node definition")
-- SMOKEY FIRE (TRIGGERS SMOKE ABM) -- make sure shared definitions are set
minetest.register_node("fake_fire:fake_fire", { def.is_ground_content = true
description = "Smokey, Fake Fire", def.inventory_image = def.inventory_image or name.. ".png"
tiles = { def.drawtype = "plantlike"
{name="fake_fire_animated.png", animation={type="vertical_frames", def.waving = 1 -- Waving wasn't an option when this mod was written. ~ LazyJ, 2014_03_13
aspect_w=16, aspect_h=16, length=1.5}}, def.light_source = def.lightsource or 14
},
is_ground_content = true,
inventory_image = 'fake_fire.png',
wield_image = {
{name="fake_fire_animated.png", animation={type="vertical_frames",
aspect_w=16, aspect_h=16, length=1.5}},
},
drawtype = "plantlike",
-- Waving wasn't an option when this mod was written. ~ LazyJ, 2014_03_13
waving = 1,
light_source = 14,
-- Adding sunlight_propagtes and leaving comments as a future reference. -- Adding sunlight_propagtes and leaving comments as a future reference.
-- If true, sunlight will go infinitely through this (no shadow is cast). -- If true, sunlight will go infinitely through this (no shadow is cast).
-- Because fire produces light it should be "true" so fire *doesn't* have -- Because fire produces light it should be "true" so fire *doesn't* have
-- a shadow. -- a shadow.
sunlight_propagates = true, def.sunlight_propagates = true
-- damage_per_second = 2*0.5, -- It's *fake* fire. PvP on our server has -- damage_per_second = 2*0.5, -- It's *fake* fire. PvP on our server has
-- been disabled for a reason. I don't want griefers lighting players on -- been disabled for a reason. I don't want griefers lighting players on
-- fire or trapping them in blazes. ~ LazyJ, 2014_0_13 -- fire or trapping them in blazes. ~ LazyJ, 2014_0_13
--groups = {dig_immediate=3,attached_node=1},
groups = { def.groups = def.groups or {
oddly_breakable_by_hand=3, dig_immediate=2, attached_node=1, oddly_breakable_by_hand=3, dig_immediate=2,
not_in_creative_inventory=1 attached_node=1, not_in_creative_inventory=1
}, }
paramtype = "light", def.paramtype = "light"
walkable = false, def.walkable = false
buildable_to = true, def.drop = "" -- So fire won't return to the inventory. ~ LazyJ
drop = "", -- So fire won't return to the inventory. ~ LazyJ def.sounds = def.sounds or minetest.sound_play("fire_small", {pos=cp, loop=true})
sounds = minetest.sound_play("fire_small", {pos=cp, loop=true}), def.buildable_to = true
on_punch = function (pos,node,puncher)
local swap_on_punch = def.swap_on_punch
def.on_punch = def.on_punch or function (pos, node, puncher)
-- A max_hear_distance of 20 may freak some players out by the "hiss" -- A max_hear_distance of 20 may freak some players out by the "hiss"
-- so I reduced it to 5. -- so I reduced it to 5.
minetest.sound_play("fire_extinguish", {pos = pos, gain = 1.0, minetest.sound_play("fire_extinguish", {pos = pos, gain = 1.0, max_hear_distance = 5,})
max_hear_distance = 5,}) -- swap the node on_punch if def.swap_on_punch is set
-- This swaps the smoky version with the smokeless version. ~ LazyJ if swap_on_punch then
minetest.set_node(pos, {name = "fake_fire:smokeless_fire"}) minetest.set_node(pos, {name = swap_on_punch})
end
end end
})
-- no need to add these to the global registration table
def.swap_on_punch = nil
def.smoking = nil
minetest.register_node("fake_fire:" .. name, def)
end
-- FLAME TYPES
-- SMOKELESS FIRE (DOES NOT TRIGGER SMOKE ABM) register_fake_fire("fake_fire", {
minetest.register_node("fake_fire:smokeless_fire", { description = "Smokey, Fake Fire",
description = "Smokeless, Fake Fire",
tiles = { tiles = {
{name="fake_fire_animated.png", animation={type="vertical_frames", {name="fake_fire_animated.png", animation={type="vertical_frames",
aspect_w=16, aspect_h=16, length=1.5}}, aspect_w=16, aspect_h=16, length=1.5}},
}, },
is_ground_content = true, swap_on_punch = "fake_fire:smokeless_fire",
inventory_image = 'fake_fire.png', })
wield_image = {
register_fake_fire("smokeless_fire", {
description = "Smokeless, Fake Fire",
tiles = {
{name="fake_fire_animated.png", animation={type="vertical_frames", {name="fake_fire_animated.png", animation={type="vertical_frames",
aspect_w=16, aspect_h=16, length=1.5}}, aspect_w=16, aspect_h=16, length=1.5}},
}, },
drawtype = "plantlike", inventory_image = 'fake_fire.png',
-- Waving wasn't an option when this mod was written. ~ LazyJ, 2014_03_13 swap_on_punch = "fake_fire:fake_fire",
waving = 1,
light_source = 14,
-- Adding sunlight_propagtes and leaving comments as a future reference.
-- If true, sunlight will go infinitely through this (no shadow is cast).
-- Because fire produces light it should be "true" so fire *doesn't* have
-- a shadow.
sunlight_propagates = true,
-- damage_per_second = 2*0.5, -- It's *fake* fire. PvP on our server has
-- been disabled for a reason. I don't want griefers lighting players on
-- fire or trapping them in blazes. ~ LazyJ, 2014_0_13
--groups = {dig_immediate=3,attached_node=1},
groups = {
oddly_breakable_by_hand=3, dig_immediate=2, attached_node=1,
not_in_creative_inventory=1
},
paramtype = "light",
walkable = false,
buildable_to = true,
drop = "", -- So fire won't return to the inventory. ~ LazyJ
sounds = minetest.sound_play("fire_small", {pos=cp, loop=true}),
on_punch = function (pos,node,puncher)
-- A max_hear_distance of 20 may freak some players out by the "hiss"
-- so I reduced it to 5.
minetest.sound_play("fire_extinguish", {pos = pos, gain = 1.0,
max_hear_distance = 5,})
-- This swaps the smokeless version with the smoky version. ~ LazyJ
minetest.set_node(pos, {name = "fake_fire:fake_fire"})
end
}) })
register_fake_fire("ice_fire", {
description = "Smoky, Fake, Ice Fire",
-- SMOKEY ICE FIRE (TRIGGERS SMOKE ABM)
minetest.register_node("fake_fire:ice_fire", {
description = "Smoky, Fake, Ice Fire",
tiles = { tiles = {
{name="ice_fire_animated.png", animation={type="vertical_frames", {name="ice_fire_animated.png", animation={type="vertical_frames",
aspect_w=16, aspect_h=16, length=1.5}}, aspect_w=16, aspect_h=16, length=1.5}},
}, },
is_ground_content = true, swap_on_punch = "fake_fire:smokeless_ice_fire",
inventory_image = 'ice_fire.png',
wield_image = {
{name="ice_fire_animated.png", animation={type="vertical_frames",
aspect_w=16, aspect_h=16, length=1.5}},
},
drawtype = "plantlike",
-- Waving wasn't an option when this mod was written. ~ LazyJ, 2014_03_13
waving = 1,
light_source = 14,
-- Adding sunlight_propagtes and leaving comments as a future reference.
-- If true, sunlight will go infinitely through this (no shadow is cast).
-- Because fire produces light it should be "true" so fire *doesn't* have
-- a shadow.
sunlight_propagates = true,
-- damage_per_second = 2*0.5, -- It's *fake* fire. PvP on our server has
-- been disabled for a reason. I don't want griefers lighting players on
-- fire or trapping them in blazes. ~ LazyJ, 2014_0_13
--groups = {dig_immediate=3,attached_node=1},
groups = {
oddly_breakable_by_hand=3, dig_immediate=2, attached_node=1,
not_in_creative_inventory=1
},
paramtype = "light",
walkable = false,
buildable_to = true,
drop = "", -- So fire won't return to the inventory. ~ LazyJ
sounds = minetest.sound_play("fire_small", {pos=cp, loop=true}),
on_punch = function (pos,node,puncher)
-- A max_hear_distance of 20 may freak some players out by the "hiss"
-- so I reduced it to 5.
minetest.sound_play("fire_extinguish", {pos = pos, gain = 1.0,
max_hear_distance = 5,})
-- This swaps the smoky version with the smokeless version. ~ LazyJ
minetest.set_node(pos, {name = "fake_fire:smokeless_ice_fire"})
end
}) })
register_fake_fire("smokeless_ice_fire", {
description = "Smokeless, Fake, Ice Fire",
-- SMOKELESS ICE FIRE (DOES NOT TRIGGER SMOKE ABM)
minetest.register_node("fake_fire:smokeless_ice_fire", {
description = "Smokeless, Fake, Ice Fire",
tiles = { tiles = {
{name="ice_fire_animated.png", animation={type="vertical_frames", {name="ice_fire_animated.png", animation={type="vertical_frames",
aspect_w=16, aspect_h=16, length=1.5}}, aspect_w=16, aspect_h=16, length=1.5}},
}, },
is_ground_content = true,
inventory_image = 'ice_fire.png', inventory_image = 'ice_fire.png',
wield_image = { swap_on_punch = "fake_fire:ice_fire",
{name="ice_fire_animated.png", animation={type="vertical_frames",
aspect_w=16, aspect_h=16, length=1.5}},
},
drawtype = "plantlike",
-- Waving wasn't an option when this mod was written. ~ LazyJ, 2014_03_13
waving = 1,
light_source = 14,
-- Adding sunlight_propagtes and leaving comments as a future reference.
-- If true, sunlight will go infinitely through this (no shadow is cast).
-- Because fire produces light it should be "true" so fire *doesn't* have
-- a shadow.
sunlight_propagates = true,
-- damage_per_second = 2*0.5, -- It's *fake* fire. PvP on our server has
-- been disabled for a reason. I don't want griefers lighting players on
-- fire or trapping them in blazes. ~ LazyJ, 2014_0_13
--groups = {dig_immediate=3,attached_node=1},
groups = {
oddly_breakable_by_hand=3, dig_immediate=2, attached_node=1,
not_in_creative_inventory=1
},
paramtype = "light",
walkable = false,
buildable_to = true,
drop = "", -- So fire won't return to the inventory. ~ LazyJ
sounds = minetest.sound_play("fire_small", {pos=cp, loop=true}),
on_punch = function (pos,node,puncher)
-- A max_hear_distance of 20 may freak some players out by the "hiss"
-- so I reduced it to 5.
minetest.sound_play("fire_extinguish", {pos = pos, gain = 1.0,
max_hear_distance = 5,})
-- This swaps the smokeless version with the smoky version. ~ LazyJ
minetest.set_node(pos, {name = "fake_fire:ice_fire"})
end
}) })
-- FLINT and STEEL -- FLINT and STEEL
minetest.register_tool("fake_fire:flint_and_steel", { minetest.register_tool("fake_fire:flint_and_steel", {
description = "Flint and steel", description = "Flint and steel",
inventory_image = "flint_and_steel.png", inventory_image = "flint_and_steel.png",