Use mesh drawtype and fix particle usage

master
BlockMen 2014-11-09 19:58:11 +01:00
parent ca8d3dce8b
commit b6ea056ba6
6 changed files with 244 additions and 40 deletions

View File

@ -1,6 +1,6 @@
Minetest mod "Torches"
=======================
version: 1.3.2
version: 2.0
License of source code and textures: WTFPL
-----------------------------------------
@ -38,3 +38,8 @@ Changelog:
1.3.2:
- fix crashes by unknown nodes
2.0:
- Use new mesh drawtype to improve wallmounted torches
- Update particle usage
- New textures

101
init.lua
View File

@ -8,22 +8,39 @@ end
local VIEW_DISTANCE = 13 -- if player is near that distance flames are shown
local null = {x=0, y=0, z=0}
local dirs = {{-1,0,-1},{-1,0,0},{0,0,-1},
{1,0,1},{1,0,0},{0,0,1},{0,1,0}}
local particle_def = {
pos = {x=0, y=0, z=0},
velocity = {x=0, y=0, z=0},
acceleration = {x=0, y=0, z=0},
expirationtime = 1,
size = 1.5,
collisiondetection = true,
vertical = false,
texture = "torches_fire_1.png",
}
--fire_particles
local function add_fire(pos, duration)
local function add_fire(pos, duration, offset)
if duration < 1 then
duration = 1.1
end
if offset then
pos.x = pos.x + offset.x
pos.z = pos.z + offset.z
end
pos.y = pos.y+0.19
minetest.add_particle(pos, null, null, duration,
3.0, true, "torches_fire"..tostring(math.random(1,2)) ..".png")
particle_def.pos = pos
particle_def.expirationtime = duration
particle_def.texture = "torches_fire"..tostring(math.random(1,2)) ..".png"
minetest.add_particle(particle_def)
pos.y = pos.y +0.01
minetest.add_particle(pos, null, null, duration-0.3,
3.0, true, "torches_fire"..tostring(math.random(1,2)) ..".png")
particle_def.pos = pos
particle_def.texture = "torches_fire"..tostring(math.random(1,2)) ..".png"
minetest.add_particle(particle_def)
end
--help functions
@ -75,6 +92,22 @@ local function player_near(pos)
return false
end
local function get_offset(fdir)
local z = 0
local x = 0
if fdir == 0 then
z = 0.15
elseif fdir == 1 then
x = 0.15
elseif fdir == 2 then
z = -0.15
elseif fdir == 3 then
x = -0.15
end
return {x=x, y=-0.06, z=z}
end
-- abms for flames
minetest.register_abm({
nodenames = {"torches:wand"},
@ -82,7 +115,12 @@ minetest.register_abm({
chance = 1,
action = function(pos)
if player_near(pos) then
add_fire(pos, dur)
local n = minetest.get_node_or_nil(pos)
dir = {x=0,y=0,z=0}
if n and n.param2 then
dir = get_offset(n.param2)
end
add_fire(pos, dur, dir)
end
end
})
@ -122,8 +160,8 @@ minetest.register_abm({
--node_boxes
minetest.register_craftitem(":default:torch", {
description = "Torch",
inventory_image = "torches_torch.png",
wield_image = "torches_torch.png",
inventory_image = "torches_torch.png^[transformR90",
wield_image = "torches_torch.png^[transformR90",
wield_scale = {x=1,y=1,z=1+1/16},
liquids_pointable = false,
on_place = function(itemstack, placer, pointed_thing)
@ -139,15 +177,20 @@ minetest.register_craftitem(":default:torch", {
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.env:add_node(above, {name = "torches:floor"})
minetest.add_node(above, {name = "torches:floor"})
else
minetest.env:add_node(above, {name = "torches:wand", param2 = is_wall(wdir)})
fdir = is_wall(wdir)
minetest.add_node(above, {name = "torches:wand", param2 = fdir})
fdir = get_offset(fdir)
end
if not wdir == 0 or not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
add_fire(above, dur)
--expect node switch one sever step delayed
minetest.after(0.1, add_fire, above, dur, fdir)
return itemstack
end
@ -159,9 +202,9 @@ minetest.register_node("torches:floor", {
inventory_image = "default_torch.png",
wield_image = "torches_torch.png",
wield_scale = {x=1,y=1,z=1+2/16},
drawtype = "nodebox",
tiles = {"torches_torch.png^[transformfy", "default_wood.png", "torches_torch.png",
"torches_torch.png^[transformfx", "torches_torch.png", "torches_torch.png"},
drawtype = "mesh",
mesh = "torch_floor.obj",
tiles = {"torches_torch.png"},
paramtype = "light",
paramtype2 = "none",
sunlight_propagates = true,
@ -170,10 +213,6 @@ minetest.register_node("torches:floor", {
light_source = 13,
groups = {choppy=2,dig_immediate=3,flammable=1,not_in_creative_inventory=1,torch=1},
legacy_wallmounted = true,
node_box = {
type = "fixed",
fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
},
selection_box = {
type = "fixed",
fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
@ -188,26 +227,14 @@ minetest.register_node("torches:floor", {
end,
})
local wall_ndbx = {
{-1/16,-6/16, 6/16, 1/16, -5/16, 0.5},
{-1/16,-5/16, 5/16, 1/16, -4/16, 7/16},
{-1/16,-4/16, 4/16, 1/16, -3/16, 6/16},
{-1/16,-3/16, 3/16, 1/16, -2/16, 5/16},
{-1/16,-2/16, 2/16, 1/16, -1/16, 4/16},
{-1/16,-1/16, 1/16, 1/16, 0, 3/16},
{-1/16,0, 1/16, 1/16, 1/16, 2/16},
{-1/16, 0, -1/16, 1/16, 2/16, 1/16},
}
minetest.register_node("torches:wand", {
--description = "Fakel",
inventory_image = "default_torch.png",
wield_image = "torches_torch.png",
wield_scale = {x=1,y=1,z=1+1/16},
drawtype = "nodebox",
tiles = {"torches_torch.png^[transformfy", "default_wood.png", "torches_side.png",
"torches_side.png^[transformfx", "default_wood.png", "torches_torch.png"},
drawtype = "mesh",
mesh = "torch_wall.obj",
tiles = {"torches_torch.png"},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
@ -216,10 +243,6 @@ minetest.register_node("torches:wand", {
groups = {choppy=2,dig_immediate=3,flammable=1,not_in_creative_inventory=1,torch=1},
legacy_wallmounted = true,
drop = "default:torch",
node_box = {
type = "fixed",
fixed = wall_ndbx
},
selection_box = {
type = "fixed",
fixed = {-1/16, -6/16, 7/16, 1/16, 2/16, 2/16},

89
models/torch_floor.obj Normal file
View File

@ -0,0 +1,89 @@
# Blender v2.69 (sub 0) OBJ File: 'torch112.blend'
# 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
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.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.064697 0.133491 -0.063732
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.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.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
vt 0.747385 0.375407
vt 0.624714 0.562308
vt 0.500286 0.562308
vt 0.500286 0.437880
vt 0.624714 0.437880
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
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

87
models/torch_wall.obj Normal file
View File

@ -0,0 +1,87 @@
# Blender v2.69 (sub 0) OBJ File: 'torch112.blend'
# 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
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.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.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
vt 0.747385 0.375407
vt 0.624714 0.562308
vt 0.500286 0.562308
vt 0.500286 0.437880
vt 0.624714 0.437880
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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 B

After

Width:  |  Height:  |  Size: 195 B