stairs update

master
Toby plowy 2017-07-06 23:38:03 +02:00
parent 2d4ccce6b6
commit 7f11925041
2 changed files with 123 additions and 43 deletions

View File

@ -15,8 +15,32 @@ minetest.register_alias("stairs:slab_pinewood", "stairs:slab_pine_wood")
-- Get setting for replace ABM
local replace = minetest.setting_getbool("enable_stairs_replace_abm")
local replace = minetest.settings:get_bool("enable_stairs_replace_abm")
local function rotate_and_place(itemstack, placer, pointed_thing)
local p0 = pointed_thing.under
local p1 = pointed_thing.above
local param2 = 0
local placer_pos = placer:getpos()
if placer_pos then
param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos))
end
local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing)
local fpos = finepos.y % 1
if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5)
or (fpos < -0.5 and fpos > -0.999999999) then
param2 = param2 + 20
if param2 == 21 then
param2 = 23
elseif param2 == 23 then
param2 = 21
end
end
return minetest.item_place(itemstack, placer, pointed_thing, param2)
end
-- Register stairs.
-- Node will be called stairs:stair_<subname>
@ -52,30 +76,7 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
return itemstack
end
local p0 = pointed_thing.under
local p1 = pointed_thing.above
local param2 = 0
local placer_pos = placer:getpos()
if placer_pos then
local dir = {
x = p1.x - placer_pos.x,
y = p1.y - placer_pos.y,
z = p1.z - placer_pos.z
}
param2 = minetest.dir_to_facedir(dir)
end
if p0.y - 1 == p1.y then
param2 = param2 + 20
if param2 == 21 then
param2 = 23
elseif param2 == 23 then
param2 = 21
end
end
return minetest.item_place(itemstack, placer, pointed_thing, param2)
return rotate_and_place(itemstack, placer, pointed_thing)
end,
})
@ -126,8 +127,6 @@ end
-- Slab facedir to placement 6d matching table
local slab_trans_dir = {[0] = 8, 0, 2, 1, 3, 4}
-- Slab facedir when placing initial slab against other surface
local slab_trans_dir_place = {[0] = 0, 20, 12, 16, 4, 8}
-- Register slabs.
-- Node will be called stairs:slab_<subname>
@ -150,8 +149,10 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
on_place = function(itemstack, placer, pointed_thing)
local under = minetest.get_node(pointed_thing.under)
local wield_item = itemstack:get_name()
local creative_enabled = (creative and creative.is_enabled_for
and creative.is_enabled_for(placer:get_player_name()))
if under and wield_item == under.name then
if under and under.name:find("stairs:slab_") then
-- place slab using under node orientation
local dir = minetest.dir_to_facedir(vector.subtract(
pointed_thing.above, pointed_thing.under), true)
@ -159,7 +160,9 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
local p2 = under.param2
-- combine two slabs if possible
if slab_trans_dir[math.floor(p2 / 4)] == dir then
if slab_trans_dir[math.floor(p2 / 4)] == dir
and wield_item == under.name then
if not recipeitem then
return itemstack
end
@ -171,7 +174,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
return
end
minetest.set_node(pointed_thing.under, {name = recipeitem, param2 = p2})
if not minetest.setting_getbool("creative_mode") then
if not creative_enabled then
itemstack:take_item()
end
return itemstack
@ -187,21 +190,12 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
-- else attempt to place node with proper param2
minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2)
if not minetest.setting_getbool("creative_mode") then
if not creative_enabled then
itemstack:take_item()
end
return itemstack
else
-- place slab using look direction of player
local dir = minetest.dir_to_wallmounted(vector.subtract(
pointed_thing.above, pointed_thing.under), true)
local rot = slab_trans_dir_place[dir]
if rot == 0 or rot == 20 then
rot = rot + minetest.dir_to_facedir(placer:get_look_dir())
end
return minetest.item_place(itemstack, placer, pointed_thing, rot)
return rotate_and_place(itemstack, placer, pointed_thing)
end
end,
})
@ -444,6 +438,66 @@ stairs.register_stair_and_slab(
default.node_sound_stone_defaults()
)
stairs.register_stair_and_slab(
"desert_sandstone",
"default:desert_sandstone",
{crumbly = 1, cracky = 3},
{"default_desert_sandstone.png"},
"Desert Sandstone Stair",
"Desert Sandstone Slab",
default.node_sound_stone_defaults()
)
stairs.register_stair_and_slab(
"desert_sandstone_brick",
"default:desert_sandstone_brick",
{cracky = 2},
{"default_desert_sandstone_brick.png"},
"Desert Sandstone Brick Stair",
"Desert Sandstone Brick Slab",
default.node_sound_stone_defaults()
)
stairs.register_stair_and_slab(
"desert_sandstone_block",
"default:desert_sandstone_block",
{cracky = 2},
{"default_desert_sandstone_block.png"},
"Desert Sandstone Block Stair",
"Desert Sandstone Block Slab",
default.node_sound_stone_defaults()
)
stairs.register_stair_and_slab(
"silver_sandstone",
"default:silver_sandstone",
{crumbly = 1, cracky = 3},
{"default_silver_sandstone.png"},
"Silver Sandstone Stair",
"Silver Sandstone Slab",
default.node_sound_stone_defaults()
)
stairs.register_stair_and_slab(
"silver_sandstone_brick",
"default:silver_sandstone_brick",
{cracky = 2},
{"default_silver_sandstone_brick.png"},
"Silver Sandstone Brick Stair",
"Silver Sandstone Brick Slab",
default.node_sound_stone_defaults()
)
stairs.register_stair_and_slab(
"silver_sandstone_block",
"default:silver_sandstone_block",
{cracky = 2},
{"default_silver_sandstone_block.png"},
"Silver Sandstone Block Stair",
"Silver Sandstone Block Slab",
default.node_sound_stone_defaults()
)
stairs.register_stair_and_slab(
"obsidian",
"default:obsidian",
@ -533,3 +587,27 @@ stairs.register_stair_and_slab(
"Gold Block Slab",
default.node_sound_metal_defaults()
)
stairs.register_stair_and_slab(
"ice",
"default:ice",
{cracky = 3, puts_out_fire = 1, cools_lava = 1},
{"default_ice.png"},
"Ice Stair",
"Ice Slab",
default.node_sound_glass_defaults()
)
stairs.register_stair_and_slab(
"snowblock",
"default:snowblock",
{crumbly = 3, puts_out_fire = 1, cools_lava = 1, snowy = 1},
{"default_snow.png"},
"Snow Block Stair",
"Snow Block Slab",
default.node_sound_dirt_defaults({
footstep = {name = "default_snow_footstep", gain = 0.15},
dug = {name = "default_snow_footstep", gain = 0.2},
dig = {name = "default_snow_footstep", gain = 0.2}
})
)

View File

@ -55,7 +55,8 @@ usemtl None
s off
f 13/11/3 14/12/3 15/13/3
f 15/13/3 18/14/3 17/15/3
f 14/12/3 16/16/3 18/14/3
f 14/12/3 16/16/3 15/13/3
f 16/16/3 18/14/3 15/13/3
o stairs_left
v 0.500000 0.000000 0.000000
v 0.500000 -0.500000 -0.500000
@ -75,7 +76,8 @@ usemtl None
s off
f 19/17/4 20/18/4 21/19/4
f 19/17/4 23/20/4 24/21/4
f 20/18/4 24/21/4 22/22/4
f 20/18/4 19/17/4 22/22/4
f 19/17/4 24/21/4 22/22/4
o stairs_back
v -0.500000 -0.500000 0.500000
v 0.500000 -0.500000 0.500000