Make torches 3D

This commit is contained in:
BlockMen 2014-06-11 18:35:41 +02:00
parent 95932e1f1e
commit 02a343ad49
6 changed files with 91 additions and 230 deletions

View File

@ -219,6 +219,13 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2)
return itemstack, false
end
-- Don't place torches ceiling
if core.get_item_group(itemstack:get_name(), "torch") ~= 0 then
if core.dir_to_wallmounted({x = 0,y=under.y - above.y,z = 0}) == 0 then
return itemstack, false
end
end
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
olddef_under = olddef_under or core.nodedef_default
local olddef_above = ItemStack({name=oldnode_above.name}):get_definition()

View File

@ -1,47 +0,0 @@
# Blender v2.73 (sub 0) OBJ File: 'torch_floor_BlockMen.blend'
# www.blender.org
o Cube_Cube.001
v 0.061653 -0.496733 0.061674
v 0.061653 -0.496733 -0.062460
v -0.059258 -0.496733 0.061674
v -0.059258 -0.496733 -0.062460
v -0.059994 -0.497234 0.497315
v -0.059994 -0.497234 -0.498102
v -0.059994 0.507706 -0.498102
v -0.059994 0.507706 0.497315
v -0.494900 0.507706 0.061709
v -0.494900 -0.497234 0.061709
v 0.497295 0.507706 0.061709
v 0.497295 -0.497234 0.061709
v 0.062686 0.507706 -0.498102
v 0.062686 -0.497234 -0.498102
v 0.062686 0.507706 0.497315
v 0.062686 -0.497234 0.497315
v -0.494900 0.507706 -0.063149
v -0.494900 -0.497234 -0.063149
v 0.497295 0.507706 -0.063149
v 0.497295 -0.497234 -0.063149
v -0.058217 0.134520 0.060216
v -0.058217 0.135872 -0.061813
v 0.061944 0.135872 -0.061813
v 0.061944 0.134520 0.060216
vt 0.000000 1.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
vt 0.437500 0.500000
vt 0.562500 0.500000
vt 0.562500 0.625000
vt 0.437541 0.625000
vt 0.437541 0.000000
vt 0.562500 0.000000
vt 0.562500 0.125000
vt 0.437500 0.125000
usemtl None
s off
f 11/1 9/2 10/3 12/4
f 22/5 21/6 24/7 23/8
f 17/2 19/1 20/4 18/3
f 13/2 15/1 16/4 14/3
f 3/9 4/10 2/11 1/12
f 8/1 7/2 6/3 5/4

View File

@ -1,47 +0,0 @@
# Blender v2.73 (sub 0) OBJ File: 'torch_wall_BlockMen.blend'
# www.blender.org
o Cube_Cube.001
v 0.061653 -0.554493 -0.328908
v 0.061653 -0.442208 -0.381835
v -0.059258 -0.554493 -0.328908
v -0.059258 -0.442208 -0.381835
v -0.059994 -0.948766 -0.143618
v -0.059994 -0.048361 -0.568031
v -0.059994 0.380112 0.340988
v -0.059994 -0.520293 0.765401
v -0.494900 -0.126265 0.579672
v -0.494900 -0.554738 -0.329346
v 0.497295 -0.126265 0.579672
v 0.497295 -0.554738 -0.329346
v 0.062686 0.380112 0.340988
v 0.062686 -0.048361 -0.568031
v 0.062686 -0.520293 0.765401
v 0.062686 -0.948766 -0.143618
v -0.494900 -0.013324 0.526437
v -0.494900 -0.441797 -0.382582
v 0.497295 -0.013324 0.526437
v 0.497295 -0.441797 -0.382582
v -0.058217 -0.284029 0.241470
v -0.058217 -0.173071 0.190665
v 0.061944 -0.173071 0.190665
v 0.061944 -0.284029 0.241470
vt 0.000000 1.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
vt 0.437500 0.500000
vt 0.562500 0.500000
vt 0.562500 0.625000
vt 0.437541 0.625000
vt 0.437541 0.000000
vt 0.562500 0.000000
vt 0.562500 0.125000
vt 0.437500 0.125000
usemtl None
s off
f 11/1 9/2 10/3 12/4
f 22/5 21/6 24/7 23/8
f 17/2 19/1 20/4 18/3
f 13/2 15/1 16/4 14/3
f 3/9 4/10 2/11 1/12
f 8/1 7/2 6/3 5/4

View File

@ -1,107 +1,26 @@
minetest.register_craftitem("default:torch", {
minetest.register_node("default:torch", {
description = "Torch",
inventory_image = "default_torch.png",
wield_image = "default_torch.png",
wield_scale = {x = 1, y = 1, z = 1 + 1/16},
liquids_pointable = false,
groups = {fuel = 3},
on_place = function(itemstack, placer, pointed_thing)
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})
if wdir < 1 then
return itemstack
end
local fakestack = itemstack
local retval = false
if wdir <= 1 then
retval = fakestack:set_name("default:torch_floor")
else
retval = fakestack:set_name("default:torch_wall")
end
if not retval then
return itemstack
end
itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
itemstack:set_name("default:torch")
return itemstack
end
})
minetest.register_node("default:torch_floor", {
description = "Torch",
inventory_image = "default_torch.png",
wield_image = "default_torch.png",
wield_scale = {x = 1, y = 1, z = 1 + 1/16},
drawtype = "mesh",
mesh = "torch_floor.obj",
drawtype = "torchlike",
tiles = {
{
name = "default_torch_on_floor_animated.png",
animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
}
{name = "default_torch_on_floor_animated.png",
animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.0},
},
},
inventory_image = "default_torch.png",
wield_image = "default_torch.png",
paramtype = "light",
paramtype2 = "wallmounted",
sunlight_propagates = true,
is_ground_content = false,
walkable = false,
light_source = 13,
groups = {choppy = 2, dig_immediate = 3, flammable = 1, not_in_creative_inventory = 1, attached_node = 1, torch = 1},
drop = "default:torch",
selection_box = {
type = "wallmounted",
wall_top = {-1/16, -2/16, -1/16, 1/16, 0.5, 1/16},
wall_bottom = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
wall_top = {-0.1, 0.5 - 0.6, -0.1, 0.1, 0.5, 0.1},
wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5 + 0.6, 0.1},
wall_side = {-0.5, -0.3, -0.1, -0.5 + 0.3, 0.3, 0.1},
},
})
minetest.register_node("default:torch_wall", {
inventory_image = "default_torch.png",
wield_image = "default_torch.png",
wield_scale = {x = 1, y = 1, z = 1 + 1/16},
drawtype = "mesh",
mesh = "torch_wall.obj",
tiles = {
{
name = "default_torch_on_floor_animated.png",
animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
}
},
paramtype = "light",
paramtype2 = "wallmounted",
sunlight_propagates = true,
walkable = false,
light_source = 13,
groups = {choppy = 2, dig_immediate = 3, flammable = 1, not_in_creative_inventory = 1, attached_node = 1, torch = 1},
drop = "default:torch",
selection_box = {
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},
},
})
-- 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 n and def then
local wdir = n.param2
local node_name = "default:torch_wall"
if wdir < 1 then
minetest.remove_node(pos)
minetest.add_item(pos, {name = "default:torch"})
return
elseif wdir <= 1 then
node_name = "default:torch_floor"
end
minetest.set_node(pos, {name = node_name, param2 = wdir})
end
end
groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1, torch = 1},
legacy_wallmounted = true,
sounds = default.node_sound_defaults(),
})

View File

@ -76,6 +76,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// results. (negative coordinates, values between nodes, ...)
// Use floatToInt(p, BS) and intToFloat(p, BS).
#define BS (10.0)
#define HBS (BS/2)
// Dimension of a MapBlock
#define MAP_BLOCKSIZE 16

View File

@ -1012,58 +1012,86 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
break;
case NDT_TORCHLIKE:
{
v3s16 dir = n.getWallMountedDir(nodedef);
v3s16 dir(0,0,0);
dir = n.getWallMountedDir(nodedef);
u8 tileindex = 0;
if(dir == v3s16(0,-1,0)){
tileindex = 0; // floor
} else if(dir == v3s16(0,1,0)){
tileindex = 1; // ceiling
// For backwards compatibility
} else if(dir == v3s16(0,0,0)){
tileindex = 0; // floor
} else {
tileindex = 2; // side
}
TileSpec tile = getNodeTileN(n, p, tileindex, data);
TileSpec tile = getNodeTileN(n, p, 0, data);
tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
u16 l = getInteriorLight(n, 1, nodedef);
video::SColor c = MapBlock_LightColor(255, l, f.light_source);
float s = BS/2*f.visual_scale;
// Wall at X+ of node
video::S3DVertex vertices[4] =
{
video::S3DVertex(-s,-s,0, 0,0,0, c, 0,1),
video::S3DVertex( s,-s,0, 0,0,0, c, 1,1),
video::S3DVertex( s, s,0, 0,0,0, c, 1,0),
video::S3DVertex(-s, s,0, 0,0,0, c, 0,0),
float d = (float)BS/64;
f32 HBB = HBS/8;
video::S3DVertex vertices[6][4] = {
{ // right
video::S3DVertex(HBB,HBS-1,-HBS, 1,0,0, c, 0,0),
video::S3DVertex(HBB,HBS-1,HBS, 1,0,0, c, 1,0),
video::S3DVertex(HBB,-HBS,HBS, 1,0,0, c, 1,1),
video::S3DVertex(HBB,-HBS,-HBS, 1,0,0, c, 0,1)
},
{ // left
video::S3DVertex(-HBB,HBS,HBS, -1,0,0, c, 0,0),
video::S3DVertex(-HBB,HBS,-HBS, -1,0,0, c, 1,0),
video::S3DVertex(-HBB,-HBS,-HBS, -1,0,0, c, 1,1),
video::S3DVertex(-HBB,-HBS,HBS, -1,0,0, c, 0,1)
},
{ // back
video::S3DVertex(HBS,HBS-1,HBB, 0,0,0, c, 0,0),
video::S3DVertex(-HBS,HBS-1,HBB, 0,0,0, c, 1,0),
video::S3DVertex(-HBS,-HBS,HBB, 0,0,0, c, 1,1),
video::S3DVertex(HBS,-HBS,HBB, 0,0,0, c, 0,1)
},
{ // front
video::S3DVertex(-HBS,HBS,-HBB, 0,0,0, c, 0,0),
video::S3DVertex(HBS,HBS,-HBB, 0,0,0, c, 1,0),
video::S3DVertex(HBS,-HBS,-HBB, 0,0,0, c, 1,1),
video::S3DVertex(-HBS,-HBS,-HBB, 0,0,0, c, 0,1)
},
{ // up
video::S3DVertex(HBB,HBS-d-2.375,HBB, 0,0,0, c, HBB-0.18,0.18),
video::S3DVertex(-HBB,HBS-d-2.375,HBB, 0,0,0, c, HBB-0.06,0.18),
video::S3DVertex(-HBB,HBS-d-2.375,-HBB, 0,0,0, c, HBB-0.06,0.305),
video::S3DVertex(HBB,HBS-d-2.375,-HBB, 0,0,0, c, HBB-0.18,0.305)
},
{ // down
video::S3DVertex(-HBB,-HBS+d,-HBB, 0,0,0, c, HBB-0.18,0.875),
video::S3DVertex(HBB,-HBS+d,-HBB, 0,0,0, c, HBB-0.06,0.875),
video::S3DVertex(HBB,-HBS+d,HBB, 0,0,0, c, HBB-0.06,1),
video::S3DVertex(-HBB,-HBS+d,HBB, 0,0,0, c, HBB-0.18,1)
}
};
for(s32 i=0; i<4; i++)
{
if(dir == v3s16(1,0,0))
vertices[i].Pos.rotateXZBy(0);
if(dir == v3s16(-1,0,0))
vertices[i].Pos.rotateXZBy(180);
if(dir == v3s16(0,0,1))
vertices[i].Pos.rotateXZBy(90);
if(dir == v3s16(0,0,-1))
vertices[i].Pos.rotateXZBy(-90);
if(dir == v3s16(0,-1,0))
vertices[i].Pos.rotateXZBy(45);
if(dir == v3s16(0,1,0))
vertices[i].Pos.rotateXZBy(-45);
for(u16 j=0; j<6; j++) {
for(u16 i=0; i<4; i++) {
f32 y_offset = 0;
if (dir == v3s16(0,1,0)){
vertices[j][i].Pos.rotateXYBy(180); // ceiling
} else if(dir != v3s16(0,0,0) && dir != v3s16(0,-1,0)) {
vertices[j][i].Pos.rotateXYBy(20); // wall
y_offset = 1;
}
if(dir == v3s16(1,0,0))
vertices[j][i].Pos.rotateXZBy(0);
if(dir == v3s16(-1,0,0))
vertices[j][i].Pos.rotateXZBy(180);
if(dir == v3s16(0,0,1))
vertices[j][i].Pos.rotateXZBy(90);
if(dir == v3s16(0,0,-1))
vertices[j][i].Pos.rotateXZBy(-90);
if(dir == v3s16(0,-1,0))
vertices[j][i].Pos.rotateXZBy(0); // old 45
if(dir == v3s16(0,1,0))
vertices[j][i].Pos.rotateXZBy(0); // old -45
vertices[j][i].Pos += intToFloat(p, BS);
vertices[j][i].Pos += v3f(3.3*dir.X,y_offset,3.3*dir.Z);
}
vertices[i].Pos += intToFloat(p, BS);
u16 indices[] = {0,1,2,2,3,0};
// Add to mesh collector
collector.append(tile, vertices[j], 4, indices, 6);
}
u16 indices[] = {0,1,2,2,3,0};
// Add to mesh collector
collector.append(tile, vertices, 4, indices, 6);
break;}
case NDT_SIGNLIKE:
{