tweak & tidy code
This commit is contained in:
parent
e49346d65d
commit
22c81f4818
21
3d.lua
21
3d.lua
@ -1,8 +1,10 @@
|
|||||||
|
|
||||||
-- translation support
|
-- translation support
|
||||||
|
|
||||||
local S = minetest.get_translator("real_torch")
|
local S = minetest.get_translator("real_torch")
|
||||||
|
|
||||||
-- flood helper function
|
-- flood helper function
|
||||||
|
|
||||||
local function on_flood(pos, oldnode, newnode)
|
local function on_flood(pos, oldnode, newnode)
|
||||||
|
|
||||||
-- drop as unlit torch
|
-- drop as unlit torch
|
||||||
@ -26,8 +28,8 @@ local function on_flood(pos, oldnode, newnode)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- unlit floor torch
|
-- unlit floor torch
|
||||||
|
|
||||||
minetest.register_node("real_torch:torch", {
|
minetest.register_node("real_torch:torch", {
|
||||||
description = S("Unlit Torch"),
|
description = S("Unlit Torch"),
|
||||||
drawtype = "mesh",
|
drawtype = "mesh",
|
||||||
@ -52,8 +54,7 @@ minetest.register_node("real_torch:torch", {
|
|||||||
groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1},
|
groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1},
|
||||||
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(),
|
||||||
|
|
||||||
@ -99,8 +100,8 @@ minetest.register_node("real_torch:torch", {
|
|||||||
floodable = true, on_rotate = false, on_flood = on_flood
|
floodable = true, on_rotate = false, on_flood = on_flood
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
-- unlit wall torch
|
-- unlit wall 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",
|
||||||
@ -124,8 +125,7 @@ minetest.register_node("real_torch:torch_wall", {
|
|||||||
},
|
},
|
||||||
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(),
|
||||||
|
|
||||||
@ -139,8 +139,8 @@ minetest.register_node("real_torch:torch_wall", {
|
|||||||
floodable = true, on_rotate = false, on_flood = on_flood
|
floodable = true, on_rotate = false, on_flood = on_flood
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
-- unlit ceiling torch
|
-- unlit ceiling torch
|
||||||
|
|
||||||
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",
|
||||||
@ -164,8 +164,7 @@ minetest.register_node("real_torch:torch_ceiling", {
|
|||||||
},
|
},
|
||||||
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(),
|
||||||
|
|
||||||
@ -179,11 +178,11 @@ minetest.register_node("real_torch:torch_ceiling", {
|
|||||||
floodable = true, on_rotate = false, on_flood = on_flood
|
floodable = true, on_rotate = false, on_flood = on_flood
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
-- burnout helper function
|
-- burnout helper function
|
||||||
|
|
||||||
local function torch_override(name)
|
local function torch_override(name)
|
||||||
|
|
||||||
-- override default torch to burn out after 8-10 minutes
|
-- override default torch to burn out after 8-10 minutes and drop in water
|
||||||
minetest.override_item("default:" .. name, {
|
minetest.override_item("default:" .. name, {
|
||||||
|
|
||||||
on_timer = function(pos, elapsed)
|
on_timer = function(pos, elapsed)
|
||||||
|
75
init.lua
75
init.lua
@ -3,18 +3,19 @@
|
|||||||
|
|
||||||
real_torch = {}
|
real_torch = {}
|
||||||
|
|
||||||
-- check for timer settings or use defaults
|
-- translation and torch duration settings
|
||||||
|
|
||||||
|
local S = minetest.get_translator("real_torch")
|
||||||
|
|
||||||
real_torch.min_duration = tonumber(minetest.settings:get("torch_min_duration")) or 1200
|
real_torch.min_duration = tonumber(minetest.settings:get("torch_min_duration")) or 1200
|
||||||
real_torch.max_duration = tonumber(minetest.settings:get("torch_max_duration")) or 1800
|
real_torch.max_duration = tonumber(minetest.settings:get("torch_max_duration")) or 1800
|
||||||
|
|
||||||
-- translation support
|
-- add unlit torches & override current
|
||||||
local S = minetest.get_translator("real_torch")
|
|
||||||
|
|
||||||
-- add unlit torches
|
|
||||||
dofile(minetest.get_modpath("real_torch") .. "/3d.lua")
|
dofile(minetest.get_modpath("real_torch") .. "/3d.lua")
|
||||||
|
|
||||||
|
|
||||||
-- start timer on any already placed torches
|
-- start timer on any already placed torches
|
||||||
|
|
||||||
minetest.register_lbm({
|
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"},
|
||||||
@ -29,15 +30,15 @@ minetest.register_lbm({
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
-- creative check
|
-- creative check
|
||||||
|
|
||||||
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
||||||
local function is_creative(name)
|
local 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
|
||||||
|
|
||||||
|
|
||||||
-- coal powder
|
-- coal powder
|
||||||
|
|
||||||
minetest.register_craftitem("real_torch:coal_powder", {
|
minetest.register_craftitem("real_torch:coal_powder", {
|
||||||
description = S("Coal Powder"),
|
description = S("Coal Powder"),
|
||||||
inventory_image = "real_torch_coal_powder.png",
|
inventory_image = "real_torch_coal_powder.png",
|
||||||
@ -51,22 +52,16 @@ minetest.register_craftitem("real_torch:coal_powder", {
|
|||||||
|
|
||||||
local pos = pointed_thing.under
|
local pos = pointed_thing.under
|
||||||
local nod = minetest.get_node(pos)
|
local nod = minetest.get_node(pos)
|
||||||
local rep = false
|
|
||||||
|
|
||||||
if nod.name == "real_torch:torch" then
|
if nod.name == "real_torch:torch" then
|
||||||
nod.name = "default:torch"
|
nod.name = "default:torch"
|
||||||
rep = true
|
|
||||||
|
|
||||||
elseif nod.name == "real_torch:torch_wall" then
|
elseif nod.name == "real_torch:torch_wall" then
|
||||||
nod.name = "default:torch_wall"
|
nod.name = "default:torch_wall"
|
||||||
rep = true
|
|
||||||
|
|
||||||
elseif nod.name == "real_torch:torch_ceiling" then
|
elseif nod.name == "real_torch:torch_ceiling" then
|
||||||
nod.name = "default:torch_ceiling"
|
nod.name = "default:torch_ceiling"
|
||||||
rep = true
|
else nod.name = "" end
|
||||||
end
|
|
||||||
|
|
||||||
if rep then
|
if nod.name ~= "" then
|
||||||
|
|
||||||
minetest.set_node(pos, {name = nod.name, param2 = nod.param2})
|
minetest.set_node(pos, {name = nod.name, param2 = nod.param2})
|
||||||
|
|
||||||
@ -114,8 +109,8 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- explosion effect
|
||||||
|
|
||||||
-- particle effects
|
|
||||||
local function add_effects(pos, radius)
|
local function add_effects(pos, radius)
|
||||||
|
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
@ -166,34 +161,7 @@ minetest.override_item("tnt:gunpowder", {
|
|||||||
local pos = pointed_thing.under
|
local pos = pointed_thing.under
|
||||||
local nod = minetest.get_node(pos)
|
local nod = minetest.get_node(pos)
|
||||||
|
|
||||||
local rep = false
|
-- torch already lit, boom!
|
||||||
|
|
||||||
if nod.name == "real_torch:torch" then
|
|
||||||
nod.name = "default:torch"
|
|
||||||
rep = true
|
|
||||||
|
|
||||||
elseif nod.name == "real_torch:torch_wall" then
|
|
||||||
nod.name = "default:torch_wall"
|
|
||||||
rep = true
|
|
||||||
|
|
||||||
elseif nod.name == "real_torch:torch_ceiling" then
|
|
||||||
nod.name = "default:torch_ceiling"
|
|
||||||
rep = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if rep then
|
|
||||||
|
|
||||||
minetest.set_node(pos, {name = nod.name, param2 = nod.param2})
|
|
||||||
|
|
||||||
add_effects(pos, 1)
|
|
||||||
|
|
||||||
if not is_creative(user:get_player_name()) then
|
|
||||||
itemstack:take_item()
|
|
||||||
end
|
|
||||||
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
|
|
||||||
if nod.name == "default:torch"
|
if nod.name == "default:torch"
|
||||||
or nod.name == "default:torch_wall"
|
or nod.name == "default:torch_wall"
|
||||||
or nod.name == "default:torch_ceiling" then
|
or nod.name == "default:torch_ceiling" then
|
||||||
@ -213,6 +181,25 @@ minetest.override_item("tnt:gunpowder", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if nod.name == "real_torch:torch" then
|
||||||
|
nod.name = "default:torch"
|
||||||
|
elseif nod.name == "real_torch:torch_wall" then
|
||||||
|
nod.name = "default:torch_wall"
|
||||||
|
elseif nod.name == "real_torch:torch_ceiling" then
|
||||||
|
nod.name = "default:torch_ceiling"
|
||||||
|
else nod.name = "" end
|
||||||
|
|
||||||
|
if nod.name ~= "" then
|
||||||
|
|
||||||
|
minetest.set_node(pos, {name = nod.name, param2 = nod.param2})
|
||||||
|
|
||||||
|
add_effects(pos, 1)
|
||||||
|
|
||||||
|
if not is_creative(user:get_player_name()) then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user