Commit e77b6990 authored by BlockMen's avatar BlockMen

Huge cleanup and fixes; push to 2.1

parent 38052254
Minetest mod "Torches"
=======================
version: 2.0
======================
version: 2.1
License of source code and textures: WTFPL
-----------------------------------------
------------------------------------------
(c) Copyright BlockMen (2013-2015)
......@@ -45,3 +45,8 @@ Changelog:
- Update particle usage
- New textures; flame texture fix by Yepoleb
- Fix for doors, chests, etc (rightclick support)
2.1
- Fix wallmounted torch mesh
- Clean up code, use wallmounted paramtype2
- Fix torches being placeable on ceilings (reported by kilbith)
......@@ -8,13 +8,8 @@ end
local VIEW_DISTANCE = 13 -- from what distance (in nodes) flames are send to player/client
local dirs = {
{-1,0,-1}, {-1,0,0}, {0,0,-1},
{1,0,1}, {1,0,0}, {0,0,1}, {0,1,0}
}
-- constants
local rotat = {"I", "FX"}
local particle_def = {
pos = {x = 0, y = 0, z = 0},
velocity = { x= 0, y = 0, z = 0},
......@@ -26,11 +21,8 @@ local particle_def = {
texture = "torches_fire_1.png",
}
--fire_particles
-- fire particles (flames)
local function add_fire(pos, duration, offset)
--if duration <= 1 then
-- duration = 1
--end
if offset then
pos.x = pos.x + offset.x
pos.z = pos.z + offset.z
......@@ -47,45 +39,7 @@ local function add_fire(pos, duration, offset)
minetest.add_particle(particle_def)
end
--help functions
function check_attached_node_fdir(p, n)
local def = minetest.registered_nodes[n.name] or nil
local d = {x = 0, y = 0, z = 0}
if def and def.paramtype2 == "facedir" then
if n.param2 == 0 then
d.z = 1
elseif n.param2 == 1 then
d.x = 1
elseif n.param2 == 2 then
d.z = -1
elseif n.param2 == 3 then
d.x = -1
end
end
local p2 = {x = p.x + d.x, y = p.y + d.y, z = p.z + d.z}
local nn = minetest.get_node(p2).name
local def2 = minetest.registered_nodes[nn]
if def2 and not def2.walkable then
return false
end
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
-- helper functions
local function player_near(pos)
for _,object in ipairs(minetest.get_objects_inside_radius(pos, VIEW_DISTANCE)) do
if object:is_player() then
......@@ -96,16 +50,16 @@ local function player_near(pos)
return false
end
local function get_offset(fdir)
local function get_offset(wdir)
local z = 0
local x = 0
if fdir == 0 then
if wdir == 4 then
z = 0.15
elseif fdir == 1 then
elseif wdir == 2 then
x = 0.15
elseif fdir == 2 then
elseif wdir == 5 then
z = -0.15
elseif fdir == 3 then
elseif wdir == 3 then
x = -0.15
end
return {x = x, y = -0.06, z = z}
......@@ -148,20 +102,20 @@ minetest.register_abm({
action = function(pos)
local n = minetest.get_node(pos)
local def = minetest.registered_nodes[n.name]
if def then
if n and 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"})
minetest.set_node(pos, {name = "torches:floor", param2 = wdir})
else
minetest.set_node(pos, {name = "torches:wand", param2 = is_wall(wdir)})
minetest.set_node(pos, {name = "torches:wall", param2 = wdir})
end
end
end
})
--node_boxes
-- Item definitions
minetest.register_craftitem(":default:torch", {
description = "Torch",
inventory_image = "torches_torch.png^[transformR90",
......@@ -176,39 +130,27 @@ minetest.register_craftitem(":default:torch", {
local above = pointed_thing.above
local under = pointed_thing.under
local wdir = minetest.dir_to_wallmounted({x = under.x - above.x, y = under.y - above.y, z = under.z - above.z})
local u_n = minetest.get_node(under)
local a_n = minetest.get_node(above)
if string.find(u_n.name, "torch") or string.find(a_n.name, "torch") then
local fakestack = itemstack
local retval = false
if wdir < 1 then
return itemstack
end
local udef = minetest.registered_nodes[u_n.name]
-- check for on_rightclick (like doors)
if not placer:get_player_control().sneak then
if u_n and udef and udef.on_rightclick then
return udef.on_rightclick(under, u_n, placer, itemstack, pointed_thing) or itemstack
end
end
if u_n and udef and not udef.walkable then above = under end
u_n = minetest.get_node(above)
udef = minetest.registered_nodes[u_n.name]
if u_n and udef and udef.walkable then return itemstack end
local fdir = nil
if wdir == 1 then
minetest.add_node(above, {name = "torches:floor"})
elseif wdir == 1 then
retval = fakestack:set_name("torches:floor")
else
fdir = is_wall(wdir)
minetest.add_node(above, {name = "torches:wand", param2 = fdir})
fdir = get_offset(fdir)
retval = fakestack:set_name("torches:wall")
end
if not wdir == 0 or not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
if not retval then
return itemstack
end
--expect node switch one sever step (default 0.1) delayed
minetest.after(0.1, add_fire, above, dur, fdir)
itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
itemstack:set_name("default:torch")
-- add flame if placing was sucessfull
if retval then
-- expect node switch one sever step (default 0.1) delayed
minetest.after(0.1, add_fire, above, dur, get_offset(wdir))
end
return itemstack
end
})
......@@ -226,23 +168,15 @@ 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,torch=1},
groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
legacy_wallmounted = true,
selection_box = {
type = "fixed",
fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
},
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if not digger:is_player() then minetest.add_item(pos, {name="default:torch"}) end
end,
update = function(pos, node, pos2)
if pos2.y < pos.y then
minetest.dig_node(pos)
end
end,
})
minetest.register_node("torches:wand", {
minetest.register_node("torches:wall", {
inventory_image = "default_torch.png",
wield_image = "torches_torch.png",
wield_scale = {x = 1, y = 1, z = 1 + 1/16},
......@@ -250,38 +184,18 @@ minetest.register_node("torches:wand", {
mesh = "torch_wall.obj",
tiles = {"torches_torch.png"},
paramtype = "light",
paramtype2 = "facedir",
paramtype2 = "wallmounted",
sunlight_propagates = true,
walkable = false,
light_source = 13,
groups = {choppy=2,dig_immediate=3,flammable=1,not_in_creative_inventory=1,torch=1},
legacy_wallmounted = true,
groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
drop = "default:torch",
selection_box = {
type = "fixed",
fixed = {-1/16, -6/16, 7/16, 1/16, 2/16, 2/16},
type = "wallmounted",
wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
},
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if not digger:is_player() then minetest.add_item(pos, {name="default:torch"}) end
end,
update = function(pos, node)
if not check_attached_node_fdir(pos, node) then
minetest.dig_node(pos)
end
end,
})
minetest.register_on_dignode(function(pos, oldnode, digger)
if minetest.find_node_near(pos, 1, {"group:torch"}) == nil then return end
for i = 1, #dirs do
local v = dirs[i]
local p = {x = pos.x + v[1], y = pos.y + v[2], z = pos.z + v[3]}
local n = minetest.get_node_or_nil(p)
if n and n.name then
local def = minetest.registered_nodes[n.name]
if def and def.update then
def.update(p, n, pos)
end
end
end
end)
minetest.register_alias("torches:wand", "torches:wall")
# Blender v2.69 (sub 0) OBJ File: 'torch112.blend'
# Blender v2.73 (sub 0) OBJ File: ''
# www.blender.org
mtllib torch112.mtl
v 0.064697 -0.491509 -0.063732
v -0.060303 0.133491 -0.063732
v -0.060303 0.133491 0.061268
v -0.060303 -0.491509 -0.063732
v 0.064697 -0.491509 0.061268
v -0.060303 -0.491509 0.061268
mtllib torch_floor.mtl
o torch_floor
v -0.060303 -0.491509 0.061268
v -0.060303 -0.491509 -0.063732
v 0.064697 -0.491509 -0.063732
v 0.064697 -0.491509 0.061268
v 0.064697 0.133491 0.061268
v -0.060303 0.133491 0.061268
v -0.060303 0.133491 -0.063732
v 0.064697 0.133491 -0.063732
v 0.064697 0.133491 0.061268
v -0.060303 0.133491 -0.063732
v -0.060303 0.133491 0.061268
v -0.060303 -0.491509 0.061268
v -0.060303 -0.491509 -0.063732
v -0.060303 0.133491 -0.063732
v 0.064697 -0.491509 -0.063732
v 0.064697 0.133491 -0.063732
v 0.064697 -0.491509 0.061268
v 0.064697 0.133491 0.061268
vt 0.622957 0.249888
vt 0.622957 0.125460
vt 0.747385 0.125460
vt 0.747385 0.249888
vt 0.623570 0.437907
vt 0.623570 0.562335
vt 0.001430 0.562335
vt 0.001430 0.437907
vt 0.623570 0.437907
vt 0.623570 0.562335
vt 0.622412 0.125460
vt 0.622412 0.249888
vt 0.000273 0.249889
vt 0.000272 0.125460
vt 0.623570 0.437799
vt 0.623570 0.562228
vt 0.001430 0.562228
vt 0.001430 0.437799
vt 0.623570 0.437933
vt 0.623570 0.437799
vt 0.623570 0.562228
vt 0.623570 0.562361
vt 0.001430 0.562362
vt 0.001430 0.437933
vt 0.623548 0.562415
vt 0.001409 0.562201
vt 0.001452 0.437772
vt 0.623591 0.437987
vt 0.622412 0.874755
vt 0.000272 0.874755
vt 0.000272 0.750327
vt 0.622412 0.750326
vt 0.623570 0.562308
vt 0.001430 0.562308
vt 0.001430 0.437880
vt 0.623570 0.437880
vt 0.623570 0.562281
vt 0.001430 0.562281
vt 0.001430 0.437853
vt 0.623570 0.437853
vt 0.747385 0.499835
vt 0.622957 0.499835
vt 0.622957 0.375407
......@@ -65,25 +55,17 @@ vt 0.747385 0.374861
vt 0.622957 0.374861
vt 0.622957 0.250433
vt 0.747385 0.250433
vn 0.000000 -1.000000 0.000001
vn 0.000000 0.000000 1.000000
vn 1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn 0.000000 -0.000000 -1.000000
vn 0.000000 1.000000 -0.000001
vn 0.000000 -1.000000 0.000000
vn 0.000000 1.000000 -0.000000
usemtl None
usemtl None.001
s off
f 6/1/1 4/2/1 1/3/1 5/4/1
f 16/5/2 3/6/2 6/7/2 5/8/2
f 15/9/3 16/10/3 5/11/3 1/12/3
f 3/13/4 2/14/4 4/15/4 6/16/4
f 2/17/5 15/18/5 1/19/5 4/20/5
f 11/21/3 7/22/3 8/23/3 12/24/3
f 12/25/2 8/26/2 9/27/2 13/28/2
f 13/29/4 9/30/4 10/31/4 14/32/4
f 14/33/5 10/34/5 7/35/5 11/36/5
f 7/37/6 10/38/6 9/39/6 8/40/6
f 14/41/7 11/42/7 12/43/7 13/44/7
f 16/45/8 15/46/8 2/47/8 3/48/8
f 1/1 2/2 3/3 4/4
f 1/5 4/6 5/7 6/8
f 7/9 5/10 4/11 3/12
f 2/13 1/14 6/15 8/16
f 8/7 7/17 3/18 2/6
f 9/19 10/13 11/20 12/21
f 12/22 11/23 13/24 14/25
f 14/8 13/5 15/6 16/7
f 16/8 15/5 10/6 9/7
f 10/26 15/27 13/28 11/29
f 16/30 9/31 12/32 14/33
f 5/34 7/35 8/36 6/37
# Blender v2.69 (sub 0) OBJ File: 'torch112.blend'
# Blender v2.73 (sub 0) OBJ File: ''
# www.blender.org
mtllib torch113.mtl
v 0.063913 -0.421603 0.470748
v -0.061087 0.086663 0.107031
v -0.061087 0.159407 0.208684
v -0.061087 -0.421603 0.470748
v 0.063913 -0.348860 0.572402
v -0.061087 -0.348860 0.572402
v -0.061087 -0.348860 0.572402
v -0.061087 -0.421603 0.470748
v 0.063913 -0.421603 0.470748
v 0.063913 -0.348860 0.572402
v -0.061087 0.159407 0.208684
v -0.061087 0.086663 0.107031
v 0.063913 0.086663 0.107031
v 0.063913 0.159407 0.208684
v 0.063913 0.086663 0.107031
v 0.063913 0.159407 0.208684
mtllib torch_wall.mtl
o torch_wall
v 0.061088 -0.475096 -0.371119
v 0.061088 -0.571653 -0.291735
v -0.063912 -0.571653 -0.291735
v -0.063912 -0.475096 -0.371119
v -0.063913 -0.078178 0.111667
v 0.061087 -0.078178 0.111667
v -0.063913 -0.174736 0.191050
v 0.061087 -0.174736 0.191050
v 0.061087 -0.078178 0.111667
v 0.061088 -0.475096 -0.371119
v 0.061088 -0.571653 -0.291735
v 0.061087 -0.174736 0.191050
v -0.063912 -0.571653 -0.291735
v -0.063913 -0.174736 0.191050
v -0.063912 -0.475096 -0.371119
v -0.063913 -0.078178 0.111667
vt 0.622957 0.249888
vt 0.622957 0.125460
vt 0.747385 0.125460
vt 0.747385 0.249888
vt 0.623570 0.437907
vt 0.623570 0.562335
vt 0.001430 0.562335
vt 0.001430 0.437907
vt 0.623570 0.437907
vt 0.623570 0.562335
vt 0.622412 0.125460
vt 0.622412 0.249888
vt 0.000273 0.249889
vt 0.000272 0.125460
vt 0.623570 0.437799
vt 0.623570 0.562228
vt 0.001430 0.562228
vt 0.001430 0.437799
vt 0.623570 0.437933
vt 0.623570 0.437799
vt 0.623570 0.562228
vt 0.623570 0.562361
vt 0.001430 0.562362
vt 0.001430 0.437933
vt 0.623548 0.562415
vt 0.001409 0.562201
vt 0.001452 0.437772
vt 0.623591 0.437987
vt 0.622412 0.874755
vt 0.000272 0.874755
vt 0.000272 0.750327
vt 0.622412 0.750326
vt 0.623570 0.562308
vt 0.001430 0.562308
vt 0.001430 0.437880
vt 0.623570 0.437880
vt 0.623570 0.562281
vt 0.001430 0.562281
vt 0.001430 0.437853
vt 0.623570 0.437853
vt 0.747385 0.499835
vt 0.622957 0.499835
vt 0.622957 0.375407
......@@ -65,23 +55,17 @@ vt 0.747385 0.374861
vt 0.622957 0.374861
vt 0.622957 0.250433
vt 0.747385 0.250433
vn 0.000000 -0.813226 0.581948
vn 0.000000 0.581948 0.813226
vn 1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn 0.000000 -0.581948 -0.813226
vn 0.000000 0.813226 -0.581948
usemtl None
s off
f 6/1/1 4/2/1 1/3/1 5/4/1
f 16/5/2 3/6/2 6/7/2 5/8/2
f 15/9/3 16/10/3 5/11/3 1/12/3
f 3/13/4 2/14/4 4/15/4 6/16/4
f 2/17/5 15/18/5 1/19/5 4/20/5
f 11/21/3 7/22/3 8/23/3 12/24/3
f 12/25/2 8/26/2 9/27/2 13/28/2
f 13/29/4 9/30/4 10/31/4 14/32/4
f 14/33/5 10/34/5 7/35/5 11/36/5
f 7/37/6 10/38/6 9/39/6 8/40/6
f 14/41/1 11/42/1 12/43/1 13/44/1
f 16/45/6 15/46/6 2/47/6 3/48/6
f 1/1 2/2 3/3 4/4
f 1/5 4/6 5/7 6/8
f 7/9 5/10 4/11 3/12
f 2/13 1/14 6/15 8/16
f 8/7 7/17 3/18 2/6
f 9/19 10/13 11/20 12/21
f 12/22 11/23 13/24 14/25
f 14/8 13/5 15/6 16/7
f 16/8 15/5 10/6 9/7
f 10/26 15/27 13/28 11/29
f 16/30 9/31 12/32 14/33
f 5/34 7/35 8/36 6/37
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment