diff --git a/README.txt b/README.txt index 327ebda..8802edd 100644 --- a/README.txt +++ b/README.txt @@ -1,10 +1,10 @@ Minetest mod "Torches" ======================= -version: 1.2 +version: 1.3 License of source code and textures: WTFPL ----------------------------------------- -(c) Copyright BlockMen (2013) +(c) Copyright BlockMen (2013-2014) This program is free software. It comes without any warranty, to @@ -19,7 +19,7 @@ Using the mod: This mod adds 3D torches to Minetest. They also have real flames and look much more realistic. -Notice: Already placed old torches wont be changed. +Notice: Already placed old torches will be converted to new, ceiling placed will be removed Changelog: @@ -27,3 +27,7 @@ Changelog: - Torches on wall dont fall when node under it is dug - Torches fall directly when not placed on floor or wall - fixed different placing bugs + +1.3: +- Torches only show flames when player is near (13 blocks) +- Old torches are converted to new, ceiling torches are dropped diff --git a/init.lua b/init.lua index 125af28..580fa38 100644 --- a/init.lua +++ b/init.lua @@ -11,6 +11,7 @@ local function add_fire(pos) 1.5, true, "torches_fire"..tostring(math.random(1,2)) ..".png") end +--help functions function check_attached_node_fdir(p, n) local def = minetest.registered_nodes[n.name] local d = {x=0, y=0, z=0} @@ -34,6 +35,21 @@ function check_attached_node_fdir(p, n) return true end +local function is_wall(wallparam) + if wallparam == 0 then return false end + local para2 = 0 + if wallparam == 2 then + para2 = 1 + elseif wallparam == 3 then + para2 = 3 + elseif wallparam == 4 then + para2 = 0 + elseif wallparam == 5 then + para2 = 2 + end + return para2 +end + local function player_near(pos) for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, VIEW_DISTANCE)) do if object:is_player() then @@ -44,6 +60,7 @@ local function player_near(pos) return false end +-- abms for flames minetest.register_abm({ nodenames = {"torches:wand"}, interval = 1, @@ -52,9 +69,6 @@ minetest.register_abm({ if player_near(pos) then add_fire(pos) end - if not check_attached_node_fdir(pos, minetest.env:get_node(pos)) then - minetest.dig_node(pos) - end end }) @@ -62,35 +76,33 @@ minetest.register_abm({ nodenames = {"torches:floor"}, interval = 1, chance = 1, - action = function(pos) + action = function(pos) if player_near(pos) then add_fire(pos) end - pos.y = pos.y-1 - local nn = minetest.env:get_node(pos).name - local def2 = minetest.registered_nodes[nn] - if def2 and not def2.walkable then - pos.y = pos.y+1 - minetest.dig_node(pos) - end end }) ---help function -local function is_wall(wallparam) - if wallparam == 0 then return false end - local para2 = 0 - if wallparam == 2 then - para2 = 1 - elseif wallparam == 3 then - para2 = 3 - elseif wallparam == 4 then - para2 = 0 - elseif wallparam == 5 then - para2 = 2 +-- convert old torches and remove ceiling placed +minetest.register_abm({ + nodenames = {"default:torch"}, + interval = 1, + chance = 1, + action = function(pos) + local n = minetest.get_node(pos) + local def = minetest.registered_nodes[n.name] + if def then + local wdir = n.param2 + if wdir == 0 then + minetest.remove_node(pos) + elseif wdir == 1 then + minetest.set_node(pos, {name = "torches:floor"}) + else + minetest.set_node(pos, {name = "torches:wand", param2 = is_wall(wdir)}) + end + end end - return para2 -end +}) --node_boxes minetest.register_craftitem(":default:torch", { @@ -138,7 +150,7 @@ minetest.register_node("torches:floor", { drop = "default:torch", walkable = false, light_source = 13, - groups = {choppy=2,dig_immediate=3,flammable=1,not_in_creative_inventory=1}, + groups = {choppy=2,dig_immediate=3,flammable=1,not_in_creative_inventory=1,torch=1}, legacy_wallmounted = true, node_box = { type = "fixed", @@ -178,7 +190,7 @@ minetest.register_node("torches:wand", { sunlight_propagates = true, walkable = false, light_source = 13, - groups = {choppy=2,dig_immediate=3,flammable=1,not_in_creative_inventory=1}, + groups = {choppy=2,dig_immediate=3,flammable=1,not_in_creative_inventory=1,torch=1}, legacy_wallmounted = true, drop = "default:torch", node_box = { @@ -195,3 +207,12 @@ minetest.register_node("torches:wand", { }) + +minetest.register_on_dignode(function(pos, oldnode, digger) + local p = minetest.find_node_near(pos, 1, {"group:torch"}) + if p and p ~= nil then + if not check_attached_node_fdir(p, minetest.get_node(p)) then + minetest.dig_node(p) + end + end +end)