Skip to content
This repository has been archived by the owner on Dec 14, 2019. It is now read-only.

Commit

Permalink
Fix dropping, convert old torches
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMen committed Jan 22, 2014
1 parent 5e4294a commit 646089e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 30 deletions.
10 changes: 7 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,11 +19,15 @@ 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:
----------
- 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
75 changes: 48 additions & 27 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -44,6 +60,7 @@ local function player_near(pos)
return false
end

-- abms for flames
minetest.register_abm({
nodenames = {"torches:wand"},
interval = 1,
Expand All @@ -52,45 +69,40 @@ 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
})

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", {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)

0 comments on commit 646089e

Please sign in to comment.