tweak code, use new "clip" for alpha textures, use on_flood feature

This commit is contained in:
tenplus1 2021-04-02 10:58:12 +01:00
parent 2277ce17dd
commit 95f9afe1bd
4 changed files with 150 additions and 93 deletions

13
2d.lua
View File

@ -7,7 +7,7 @@ minetest.register_node("real_torch:torch", {
tiles = { tiles = {
{name = "real_torch_on_floor.png"}, {name = "real_torch_on_floor.png"},
{name = "real_torch_ceiling.png"}, {name = "real_torch_ceiling.png"},
{name = "real_torch_wall.png"}, {name = "real_torch_wall.png"}
}, },
inventory_image = "real_torch_on_floor.png", inventory_image = "real_torch_on_floor.png",
wield_image = "real_torch_on_floor.png", wield_image = "real_torch_on_floor.png",
@ -21,11 +21,11 @@ minetest.register_node("real_torch:torch", {
type = "wallmounted", type = "wallmounted",
wall_top = {-0.1, 0.5 - 0.6, -0.1, 0.1, 0.5, 0.1}, wall_top = {-0.1, 0.5 - 0.6, -0.1, 0.1, 0.5, 0.1},
wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5 + 0.6, 0.1}, wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5 + 0.6, 0.1},
wall_side = {-0.5, -0.3, -0.1, -0.5 + 0.3, 0.3, 0.1}, wall_side = {-0.5, -0.3, -0.1, -0.5 + 0.3, 0.3, 0.1}
}, },
groups = {choppy = 2, dig_immediate = 3, attached_node = 1}, groups = {choppy = 2, dig_immediate = 3, attached_node = 1},
legacy_wallmounted = true, legacy_wallmounted = true,
sounds = default.node_sound_defaults(), sounds = default.node_sound_defaults()
}) })
@ -33,10 +33,13 @@ minetest.register_node("real_torch:torch", {
minetest.override_item("default:torch", { minetest.override_item("default:torch", {
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
local p2 = minetest.get_node(pos).param2 local p2 = minetest.get_node(pos).param2
minetest.set_node(pos, {name = "real_torch:torch", param2 = p2}) minetest.set_node(pos, {name = "real_torch:torch", param2 = p2})
minetest.sound_play({name="real_torch_burnout", gain = 0.1},
{pos = pos, max_hear_distance = 10}) minetest.sound_play("real_torch_burnout",
{pos = pos, gain = 0.1, max_hear_distance = 10})
end, end,
on_construct = function(pos) on_construct = function(pos)

134
3d.lua
View File

@ -1,4 +1,31 @@
local function on_flood(pos, oldnode, newnode)
minetest.add_item(pos, ItemStack("real_torch:torch 1"))
-- Play flame-extinguish sound if liquid is not an 'igniter'
local nodedef = minetest.registered_items[newnode.name]
-- return if torch is unlit already
if oldnode.name == "real_torch:torch"
or oldnode.name == "real_torch:torch_wall"
or oldnode.name == "real_torch:torch_ceiling" then
return false
end
-- play sound if torch is lit
if not (nodedef and nodedef.groups and nodedef.groups.igniter
and nodedef.groups.igniter > 0) then
minetest.sound_play("default_cool_lava",
{pos = pos, max_hear_distance = 16, gain = 0.1}, true)
end
-- Remove the torch node
return false
end
-- unlit floor torch -- unlit floor torch
minetest.register_node("real_torch:torch", { minetest.register_node("real_torch:torch", {
description = "Torch", description = "Torch",
@ -6,10 +33,18 @@ minetest.register_node("real_torch:torch", {
mesh = "torch_floor.obj", mesh = "torch_floor.obj",
inventory_image = "real_torch_on_floor.png", inventory_image = "real_torch_on_floor.png",
wield_image = "real_torch_on_floor.png", wield_image = "real_torch_on_floor.png",
tiles = {{ tiles = {
{
name = "real_torch_on_floor.png", name = "real_torch_on_floor.png",
animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3} animation = {
}}, type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 3.3
}
}
},
use_texture_alpha = "clip",
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
light_source = 3, light_source = 3,
@ -20,13 +55,16 @@ minetest.register_node("real_torch:torch", {
drop = "real_torch:torch", drop = "real_torch:torch",
selection_box = { selection_box = {
type = "wallmounted", type = "wallmounted",
wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8}, wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8}
}, },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under local under = pointed_thing.under
local node = minetest.get_node(under) local node = minetest.get_node(under)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
if def and def.on_rightclick and if def and def.on_rightclick and
((not placer) or (placer and not placer:get_player_control().sneak)) then ((not placer) or (placer and not placer:get_player_control().sneak)) then
return def.on_rightclick(under, node, placer, itemstack, return def.on_rightclick(under, node, placer, itemstack,
@ -36,6 +74,7 @@ minetest.register_node("real_torch:torch", {
local above = pointed_thing.above local above = pointed_thing.above
local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above)) local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
local fakestack = itemstack local fakestack = itemstack
if wdir == 0 then if wdir == 0 then
fakestack:set_name("real_torch:torch_ceiling") fakestack:set_name("real_torch:torch_ceiling")
elseif wdir == 1 then elseif wdir == 1 then
@ -49,10 +88,16 @@ minetest.register_node("real_torch:torch", {
return itemstack return itemstack
end, end,
on_ignite = function(pos, igniter) on_ignite = function(pos, igniter)
local nod = minetest.get_node(pos) local nod = minetest.get_node(pos)
minetest.set_node(pos, {name = "default:torch", param2 = nod.param2}) minetest.set_node(pos, {name = "default:torch", param2 = nod.param2})
end, end,
floodable = true,
on_flood = on_flood
}) })
@ -60,26 +105,43 @@ minetest.register_node("real_torch:torch", {
minetest.register_node("real_torch:torch_wall", { minetest.register_node("real_torch:torch_wall", {
drawtype = "mesh", drawtype = "mesh",
mesh = "torch_wall.obj", mesh = "torch_wall.obj",
tiles = {{ tiles = {
{
name = "real_torch_on_floor.png", name = "real_torch_on_floor.png",
animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3} animation = {
}}, type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 3.3
}
}
},
use_texture_alpha = "clip",
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
light_source = 3, light_source = 3,
sunlight_propagates = true, sunlight_propagates = true,
walkable = false, walkable = false,
groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1}, groups = {
choppy = 2, dig_immediate = 3, flammable = 1, not_in_creative_inventory = 1,
attached_node = 1
},
drop = "real_torch:torch", drop = "real_torch:torch",
selection_box = { selection_box = {
type = "wallmounted", type = "wallmounted",
wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8}, wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8}
}, },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_ignite = function(pos, igniter) on_ignite = function(pos, igniter)
local nod = minetest.get_node(pos) local nod = minetest.get_node(pos)
minetest.set_node(pos, {name = "default:torch_wall", param2 = nod.param2}) minetest.set_node(pos, {name = "default:torch_wall", param2 = nod.param2})
end, end,
floodable = true,
on_flood = on_flood
}) })
@ -87,26 +149,43 @@ minetest.register_node("real_torch:torch_wall", {
minetest.register_node("real_torch:torch_ceiling", { minetest.register_node("real_torch:torch_ceiling", {
drawtype = "mesh", drawtype = "mesh",
mesh = "torch_ceiling.obj", mesh = "torch_ceiling.obj",
tiles = {{ tiles = {
{
name = "real_torch_on_floor.png", name = "real_torch_on_floor.png",
animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3} animation = {
}}, type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 3.3
}
}
},
use_texture_alpha = "clip",
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
light_source = 3, light_source = 3,
sunlight_propagates = true, sunlight_propagates = true,
walkable = false, walkable = false,
groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1}, groups = {
choppy = 2, dig_immediate = 3, flammable = 1, not_in_creative_inventory = 1,
attached_node = 1
},
drop = "real_torch:torch", drop = "real_torch:torch",
selection_box = { selection_box = {
type = "wallmounted", type = "wallmounted",
wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8}, wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8}
}, },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_ignite = function(pos, igniter) on_ignite = function(pos, igniter)
local nod = minetest.get_node(pos) local nod = minetest.get_node(pos)
minetest.set_node(pos, {name = "default:torch_ceiling", param2 = nod.param2}) minetest.set_node(pos, {name = "default:torch_ceiling", param2 = nod.param2})
end, end,
floodable = true,
on_flood = on_flood
}) })
@ -114,46 +193,61 @@ minetest.register_node("real_torch:torch_ceiling", {
minetest.override_item("default:torch", { minetest.override_item("default:torch", {
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
local p2 = minetest.get_node(pos).param2 local p2 = minetest.get_node(pos).param2
minetest.set_node(pos, {name = "real_torch:torch", param2 = p2}) minetest.set_node(pos, {name = "real_torch:torch", param2 = p2})
minetest.sound_play({name="real_torch_burnout", gain = 0.1},
{pos = pos, max_hear_distance = 10}) minetest.sound_play("real_torch_burnout",
{pos = pos, gain = 0.1, max_hear_distance = 10}, true)
end, end,
on_construct = function(pos) on_construct = function(pos)
minetest.get_node_timer(pos):start( minetest.get_node_timer(pos):start(
math.random(real_torch.min_duration, real_torch.max_duration)) math.random(real_torch.min_duration, real_torch.max_duration))
end, end,
on_flood = on_flood
}) })
minetest.override_item("default:torch_wall", { minetest.override_item("default:torch_wall", {
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
local p2 = minetest.get_node(pos).param2 local p2 = minetest.get_node(pos).param2
minetest.set_node(pos, {name = "real_torch:torch_wall", param2 = p2}) minetest.set_node(pos, {name = "real_torch:torch_wall", param2 = p2})
minetest.sound_play({name="real_torch_burnout", gain = 0.1},
{pos = pos, max_hear_distance = 10}) minetest.sound_play("real_torch_burnout",
{pos = pos, gain = 0.1, max_hear_distance = 10}, true)
end, end,
on_construct = function(pos) on_construct = function(pos)
minetest.get_node_timer(pos):start( minetest.get_node_timer(pos):start(
math.random(real_torch.min_duration, real_torch.max_duration)) math.random(real_torch.min_duration, real_torch.max_duration))
end, end,
on_flood = on_flood
}) })
minetest.override_item("default:torch_ceiling", { minetest.override_item("default:torch_ceiling", {
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
local p2 = minetest.get_node(pos).param2 local p2 = minetest.get_node(pos).param2
minetest.set_node(pos, {name = "real_torch:torch_ceiling", param2 = p2}) minetest.set_node(pos, {name = "real_torch:torch_ceiling", param2 = p2})
minetest.sound_play({name="real_torch_burnout", gain = 0.1},
{pos = pos, max_hear_distance = 10}) minetest.sound_play("real_torch_burnout",
{pos = pos, gain = 0.1, max_hear_distance = 10}, true)
end, end,
on_construct = function(pos) on_construct = function(pos)
minetest.get_node_timer(pos):start( minetest.get_node_timer(pos):start(
math.random(real_torch.min_duration, real_torch.max_duration)) math.random(real_torch.min_duration, real_torch.max_duration))
end, end,
on_flood = on_flood
}) })

View File

@ -22,7 +22,9 @@ minetest.register_lbm({
name = "real_torch:convert_torch_to_node_timer", name = "real_torch:convert_torch_to_node_timer",
nodenames = {"default:torch", "default:torch_wall", "default:torch_ceiling"}, nodenames = {"default:torch", "default:torch_wall", "default:torch_ceiling"},
action = function(pos) action = function(pos)
if not minetest.get_node_timer(pos):is_started() then if not minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):start( minetest.get_node_timer(pos):start(
math.random(real_torch.min_duration, real_torch.max_duration)) math.random(real_torch.min_duration, real_torch.max_duration))
end end
@ -32,6 +34,7 @@ minetest.register_lbm({
-- creative check -- creative check
local creative_mode_cache = minetest.settings:get_bool("creative_mode") local creative_mode_cache = minetest.settings:get_bool("creative_mode")
function is_creative(name) function is_creative(name)
return creative_mode_cache or minetest.check_player_privs(name, {creative = true}) return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
end end
@ -75,93 +78,48 @@ minetest.register_craftitem("real_torch:coal_powder", {
end end
return itemstack return itemstack
end, end
}) })
-- use coal powder as furnace fuel -- use coal powder as furnace fuel
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "real_torch:coal_powder", recipe = "real_torch:coal_powder",
burntime = 8, burntime = 8
}) })
-- 2x coal lumps = 12x coal powder -- 2x coal lumps = 12x coal powder
minetest.register_craft({ minetest.register_craft({
type = "shapeless", type = "shapeless",
output = "real_torch:coal_powder 12", output = "real_torch:coal_powder 12",
recipe = {"default:coal_lump", "default:coal_lump"}, recipe = {"default:coal_lump", "default:coal_lump"}
}) })
-- coal powder can make black dye -- coal powder can make black dye
minetest.register_craft({ minetest.register_craft({
type = "shapeless", type = "shapeless",
output = "dye:black", output = "dye:black",
recipe = {"real_torch:coal_powder"}, recipe = {"real_torch:coal_powder"}
}) })
-- add coal powder to burnt out torch to relight -- add coal powder to burnt out torch to relight
minetest.register_craft({ minetest.register_craft({
type = "shapeless", type = "shapeless",
output = "default:torch", output = "default:torch",
recipe = {"real_torch:torch", "real_torch:coal_powder"}, recipe = {"real_torch:torch", "real_torch:coal_powder"}
}) })
-- 4x burnt out torches = 1x stick -- 4x burnt out torches = 1x stick
minetest.register_craft({ minetest.register_craft({
type = "shapeless", type = "shapeless",
output = "default:stick", output = "default:stick",
recipe = {"real_torch:torch", "real_torch:torch", "real_torch:torch", "real_torch:torch"}, recipe = {
"real_torch:torch", "real_torch:torch",
"real_torch:torch", "real_torch:torch"
}
}) })
-- Make sure Ethereal mod isn't running as this Abm already exists there
if not minetest.get_modpath("ethereal") then
-- if torch touches water then drop as unlit torch
minetest.register_abm({
label = "Real Torch water check",
nodenames = {
"default:torch", "default:torch_wall", "default:torch:ceiling",
"real_torch:torch", "real_torch:torch_wall", "real_torch:torch_ceiling"
},
neighbors = {"group:water"},
interval = 5,
chance = 1,
catch_up = false,
action = function(pos, node)
local num = #minetest.find_nodes_in_area(
{x = pos.x - 1, y = pos.y, z = pos.z},
{x = pos.x + 1, y = pos.y, z = pos.z},
{"group:water"})
if num == 0 then
num = num + #minetest.find_nodes_in_area(
{x = pos.x, y = pos.y, z = pos.z - 1},
{x = pos.x, y = pos.y, z = pos.z + 1},
{"group:water"})
end
if num == 0 then
num = num + #minetest.find_nodes_in_area(
{x = pos.x, y = pos.y + 1, z = pos.z},
{x = pos.x, y = pos.y + 1, z = pos.z},
{"group:water"})
end
if num > 0 then
minetest.set_node(pos, {name = "air"})
minetest.sound_play({name="real_torch_extinguish", gain = 0.2},
{pos = pos, max_hear_distance = 10})
minetest.add_item(pos, {name = "real_torch:torch"})
end
end,
})
end
-- particle effects -- particle effects
local function add_effects(pos, radius) local function add_effects(pos, radius)
@ -170,12 +128,12 @@ local function add_effects(pos, radius)
pos = pos, pos = pos,
velocity = vector.new(), velocity = vector.new(),
acceleration = vector.new(), acceleration = vector.new(),
expirationtime = 0.4, expirationtime = 0.5,
size = radius * 10, size = radius * 10,
collisiondetection = false, collisiondetection = false,
vertical = false, vertical = false,
texture = "tnt_boom.png", texture = "tnt_boom.png",
glow = 15, glow = 15
}) })
minetest.add_particlespawner({ minetest.add_particlespawner({
@ -191,7 +149,7 @@ local function add_effects(pos, radius)
maxexptime = 2.5, maxexptime = 2.5,
minsize = radius * 3, minsize = radius * 3,
maxsize = radius * 5, maxsize = radius * 5,
texture = "tnt_smoke.png", texture = "tnt_smoke.png"
}) })
minetest.sound_play("tnt_explode", {pos = pos, gain = 0.1, max_hear_distance = 5}) minetest.sound_play("tnt_explode", {pos = pos, gain = 0.1, max_hear_distance = 5})
@ -255,6 +213,6 @@ minetest.override_item("tnt:gunpowder", {
end end
return itemstack return itemstack
end, end
}) })
end end

View File

@ -24,3 +24,5 @@ Changelog:
- 0.6 - Burnout and extinguish sounds added by tacotexmex :) - 0.6 - Burnout and extinguish sounds added by tacotexmex :)
- 0.7 - Torches can be re-lit using flint & steel and gunpowder, settings added - 0.7 - Torches can be re-lit using flint & steel and gunpowder, settings added
- 0.8 - Updated to newer functions, requires Minetest 0.4.16 to run - 0.8 - Updated to newer functions, requires Minetest 0.4.16 to run
- 0.9 - Use on_flood from newer 5.x functions to drop torches
- 1.0 - Tweak code and use use_texture_alpha = "clip" to stop warnings