code tidy and tweak

This commit is contained in:
tenplus1 2024-05-30 10:24:43 +01:00
parent c3969b1c64
commit f2ea1dfaa5
2 changed files with 25 additions and 17 deletions

35
3d.lua
View File

@ -1,24 +1,21 @@
local function on_flood(pos, oldnode, newnode) local function on_flood(pos, oldnode, newnode)
-- drop as unlit torch
minetest.add_item(pos, ItemStack("real_torch:torch 1")) 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 -- return if torch is unlit already
if oldnode.name == "real_torch:torch" if oldnode.name:find("real_torch:") then
or oldnode.name == "real_torch:torch_wall"
or oldnode.name == "real_torch:torch_ceiling" then
return false return false
end end
-- play sound if torch is lit local def = minetest.registered_items[newnode.name]
if not (nodedef and nodedef.groups and nodedef.groups.igniter
and nodedef.groups.igniter > 0) then -- play extinquish sound if lit torch put out by water
if def and def.groups and def.groups.water and def.groups.water > 0 then
minetest.sound_play("default_cool_lava", minetest.sound_play("default_cool_lava",
{pos = pos, max_hear_distance = 16, gain = 0.1}, true) {pos = pos, max_hear_distance = 10, gain = 0.1}, true)
end end
-- Remove the torch node -- Remove the torch node
@ -65,8 +62,10 @@ minetest.register_node("real_torch:torch", {
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
((not placer) or (placer and not placer:get_player_control().sneak)) then and not (placer and placer:is_player()
and placer:get_player_control().sneak) then
return def.on_rightclick(under, node, placer, itemstack, return def.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack pointed_thing) or itemstack
end end
@ -97,7 +96,8 @@ minetest.register_node("real_torch:torch", {
end, end,
floodable = true, floodable = true,
on_flood = on_flood on_flood = on_flood,
on_rotate = false
}) })
@ -141,7 +141,8 @@ minetest.register_node("real_torch:torch_wall", {
end, end,
floodable = true, floodable = true,
on_flood = on_flood on_flood = on_flood,
on_rotate = false
}) })
@ -185,7 +186,8 @@ minetest.register_node("real_torch:torch_ceiling", {
end, end,
floodable = true, floodable = true,
on_flood = on_flood on_flood = on_flood,
on_rotate = false
}) })
@ -203,6 +205,7 @@ minetest.override_item("default:torch", {
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,
@ -224,6 +227,7 @@ minetest.override_item("default:torch_wall", {
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,
@ -245,6 +249,7 @@ minetest.override_item("default:torch_ceiling", {
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,

View File

@ -145,7 +145,7 @@ local function add_effects(pos, radius)
}) })
minetest.sound_play("tnt_explode", minetest.sound_play("tnt_explode",
{pos = pos, gain = 0.1, max_hear_distance = 5}, true) {pos = pos, gain = 0.1, max_hear_distance = 10}, true)
end end
@ -198,7 +198,10 @@ minetest.override_item("tnt:gunpowder", {
-- small delay to fix dupe bug -- small delay to fix dupe bug
minetest.after(0.1, function(user) minetest.after(0.1, function(user)
user:set_hp(user:get_hp() - 2)
if user and user:get_pos() then
user:set_hp(user:get_hp() - 2)
end
end, user) end, user)
add_effects(pos, 1) add_effects(pos, 1)