diff --git a/mods/stairs/README.txt b/mods/stairs/README.txt index 78eb7216b1..d32cd71b94 100644 --- a/mods/stairs/README.txt +++ b/mods/stairs/README.txt @@ -1,26 +1,16 @@ -Minetest 0.4 mod: stairs +Minetest Game mod: stairs ========================= +See license.txt for license information. -License of source code: ------------------------ -Copyright (C) 2011-2012 Kahrl -Copyright (C) 2011-2012 celeron55, Perttu Ahola +Authors of source code +---------------------- +Originally by Kahrl (LGPL 2.1) and +celeron55, Perttu Ahola (LGPL 2.1) +Various Minetest developers and contributors (LGPL 2.1) -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -http://www.gnu.org/licenses/lgpl-2.1.html - -License of media (sounds) --------------------------------------- -Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) -http://creativecommons.org/licenses/by-sa/3.0/ - -Authors of media files ------------------------ -Everything not listed in here: -Copyright (C) 2010-2012 celeron55, Perttu Ahola +Authors of media (models) +------------------------- +Jean-Patrick G. (kilbith) (CC BY-SA 3.0): + stairs_stair.obj diff --git a/mods/stairs/init.lua b/mods/stairs/init.lua index ecba8a5c92..874e779f78 100644 --- a/mods/stairs/init.lua +++ b/mods/stairs/init.lua @@ -1,20 +1,40 @@ -- Minetest 0.4 mod: stairs -- See README.txt for licensing and other information. -local init = os.clock() + + +-- Global namespace for functions + stairs = {} + +-- Get setting for replace ABM + +local replace = minetest.setting_getbool("enable_stairs_replace_abm") + + +-- Register stairs. -- Node will be called stairs:stair_ + function stairs.register_stair(subname, recipeitem, groups, images, description, sounds) + groups.stair = 1 minetest.register_node(":stairs:stair_" .. subname, { description = description, - drawtype = "nodebox", + drawtype = "mesh", + mesh = "stairs_stair.obj", tiles = images, paramtype = "light", paramtype2 = "facedir", is_ground_content = false, groups = groups, sounds = sounds, - node_box = { + selection_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + {-0.5, 0, 0, 0.5, 0.5, 0.5}, + }, + }, + collision_box = { type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, @@ -25,98 +45,95 @@ function stairs.register_stair(subname, recipeitem, groups, images, description, if pointed_thing.type ~= "node" then return itemstack end - + local p0 = pointed_thing.under local p1 = pointed_thing.above - if p0.y-1 == p1.y then - local fakestack = ItemStack("stairs:stair_" .. subname.."upside_down") - local ret = minetest.item_place(fakestack, placer, pointed_thing) - if ret:is_empty() then - itemstack:take_item() - return itemstack + 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 - local futurpos = pointed_thing.under - local frontstair = {x=futurpos.x-1, y=futurpos.y+1, z=futurpos.z} - local leftstair = {x=futurpos.x, y=futurpos.y+1, z=futurpos.z+1} - print( minetest.get_node(frontstair).name) - if minetest.get_node(frontstair).name == "stairs:stair_"..subname.."" and minetest.get_node(leftstair).name == "stairs:stair_"..subname.."" then - local fakestack = ItemStack("stairs:stair_" .. subname.."_corner_1") - local ret = minetest.item_place(fakestack, placer, pointed_thing) - if ret:is_empty() then - itemstack:take_item() - return itemstack - end - end - - -- Otherwise place regularly - return minetest.item_place(itemstack, placer, pointed_thing) + + return minetest.item_place(itemstack, placer, pointed_thing, param2) end, }) - - minetest.register_node(":stairs:stair_" .. subname.."upside_down", { - drop = "stairs:stair_" .. subname, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - is_ground_content = false, - groups = groups, - sounds = sounds, - node_box = { - type = "fixed", - fixed = { - {-0.5, 0, -0.5, 0.5, 0.5, 0.5}, - {-0.5, -0.5, 0, 0.5, 0, 0.5}, + + -- for replace ABM + if replace then + minetest.register_node(":stairs:stair_" .. subname .. "upside_down", { + replace_name = "stairs:stair_" .. subname, + groups = {slabs_replace = 1}, + }) + end + + if recipeitem then + minetest.register_craft({ + output = 'stairs:stair_' .. subname .. ' 8', + recipe = { + {recipeitem, "", ""}, + {recipeitem, recipeitem, ""}, + {recipeitem, recipeitem, recipeitem}, }, - }, - }) + }) - minetest.register_node(":stairs:stair_" .. subname.."_corner_1", { - drop = "stairs:stair_" .. subname, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - is_ground_content = false, - groups = groups, - sounds = sounds, - node_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, - {-0.5, -0, -0, 0, 0.5, 0.5}, + -- Flipped recipe for the silly minecrafters + minetest.register_craft({ + output = 'stairs:stair_' .. subname .. ' 8', + recipe = { + {"", "", recipeitem}, + {"", recipeitem, recipeitem}, + {recipeitem, recipeitem, recipeitem}, }, - }, - }) + }) - minetest.register_craft({ - output = 'stairs:stair_' .. subname .. ' 4', - recipe = { - {recipeitem, "", ""}, - {recipeitem, recipeitem, ""}, - {recipeitem, recipeitem, recipeitem}, - }, - }) - - -- Flipped recipe for the silly minecrafters - minetest.register_craft({ - output = 'stairs:stair_' .. subname .. ' 4', - recipe = { - {"", "", recipeitem}, - {"", recipeitem, recipeitem}, - {recipeitem, recipeitem, recipeitem}, - }, - }) + -- Fuel + local baseburntime = minetest.get_craft_result({ + method = "fuel", + width = 1, + items = {recipeitem} + }).time + if baseburntime > 0 then + minetest.register_craft({ + type = "fuel", + recipe = 'stairs:stair_' .. subname, + burntime = math.floor(baseburntime * 0.75), + }) + end + end 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_ + function stairs.register_slab(subname, recipeitem, groups, images, description, sounds) + groups.slab = 1 minetest.register_node(":stairs:slab_" .. subname, { description = description, drawtype = "nodebox", tiles = images, paramtype = "light", + paramtype2 = "facedir", is_ground_content = false, groups = groups, sounds = sounds, @@ -125,116 +142,130 @@ function stairs.register_slab(subname, recipeitem, groups, images, description, fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, }, on_place = function(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" then - return itemstack - end + local under = minetest.get_node(pointed_thing.under) + local wield_item = itemstack:get_name() - -- If it's being placed on an another similar one, replace it with - -- a full block - local slabpos = nil - local slabnode = nil - local p0 = pointed_thing.under - local p1 = pointed_thing.above - local n0 = minetest.get_node(p0) - if n0.name == "stairs:slab_" .. subname and - p0.y+1 == p1.y then - slabpos = p0 - slabnode = n0 - end - if slabpos then - -- Remove the slab at slabpos - minetest.remove_node(slabpos) - -- Make a fake stack of a single item and try to place it - local fakestack = ItemStack(recipeitem) - pointed_thing.above = slabpos - fakestack = minetest.item_place(fakestack, placer, pointed_thing) - -- If the item was taken from the fake stack, decrement original - if not fakestack or fakestack:is_empty() then - itemstack:take_item(1) - -- Else put old node back - else - minetest.set_node(slabpos, slabnode) - end - return itemstack - end - - -- Upside down slabs - if p0.y-1 == p1.y then - -- Turn into full block if pointing at a existing slab - if n0.name == "stairs:slab_" .. subname.."upside_down" then - -- Remove the slab at the position of the slab - minetest.remove_node(p0) - -- Make a fake stack of a single item and try to place it - local fakestack = ItemStack(recipeitem) - pointed_thing.above = p0 - fakestack = minetest.item_place(fakestack, placer, pointed_thing) - -- If the item was taken from the fake stack, decrement original - if not fakestack or fakestack:is_empty() then - itemstack:take_item(1) - -- Else put old node back - else - minetest.set_node(p0, n0) + if under and wield_item == under.name then + -- place slab using under node orientation + local dir = minetest.dir_to_facedir(vector.subtract( + pointed_thing.above, pointed_thing.under), true) + + local p2 = under.param2 + + -- combine two slabs if possible + if slab_trans_dir[math.floor(p2 / 4)] == dir then + if not recipeitem then + return itemstack + end + local player_name = placer:get_player_name() + if minetest.is_protected(pointed_thing.under, player_name) and not + minetest.check_player_privs(placer, "protection_bypass") then + minetest.record_protection_violation(pointed_thing.under, + player_name) + return + end + minetest.set_node(pointed_thing.under, {name = recipeitem, param2 = p2}) + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() end return itemstack end - - -- Place upside down slab - local fakestack = ItemStack("stairs:slab_" .. subname.."upside_down") - local ret = minetest.item_place(fakestack, placer, pointed_thing) - if ret:is_empty() then - itemstack:take_item() - return itemstack + + -- Placing a slab on an upside down slab should make it right-side up. + if p2 >= 20 and dir == 8 then + p2 = p2 - 20 + -- same for the opposite case: slab below normal slab + elseif p2 <= 3 and dir == 4 then + p2 = p2 + 20 end - end - - -- If pointing at the side of a upside down slab - if n0.name == "stairs:slab_" .. subname.."upside_down" and - p0.y+1 ~= p1.y then - -- Place upside down slab - local fakestack = ItemStack("stairs:slab_" .. subname.."upside_down") - local ret = minetest.item_place(fakestack, placer, pointed_thing) - if ret:is_empty() then + + -- 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 itemstack:take_item() - return itemstack 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) end - - -- Otherwise place regularly - return minetest.item_place(itemstack, placer, pointed_thing) end, }) - - minetest.register_node(":stairs:slab_" .. subname.."upside_down", { - drop = "stairs:slab_"..subname, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - stack_max = 64, - paramtype2 = "facedir", - on_place = minetest.rotate_node, - is_ground_content = false, - groups = groups, - sounds = sounds, - node_box = { - type = "fixed", - fixed = {-0.5, 0, -0.5, 0.5, 0.5, 0.5}, - }, - }) - minetest.register_craft({ - output = 'stairs:slab_' .. subname .. ' 6', - recipe = { - {recipeitem, recipeitem, recipeitem}, - }, + -- for replace ABM + if replace then + minetest.register_node(":stairs:slab_" .. subname .. "upside_down", { + replace_name = "stairs:slab_".. subname, + groups = {slabs_replace = 1}, + }) + end + + if recipeitem then + minetest.register_craft({ + output = 'stairs:slab_' .. subname .. ' 6', + recipe = { + {recipeitem, recipeitem, recipeitem}, + }, + }) + + -- Fuel + local baseburntime = minetest.get_craft_result({ + method = "fuel", + width = 1, + items = {recipeitem} + }).time + if baseburntime > 0 then + minetest.register_craft({ + type = "fuel", + recipe = 'stairs:slab_' .. subname, + burntime = math.floor(baseburntime * 0.5), + }) + end + end +end + + +-- Optionally replace old "upside_down" nodes with new param2 versions. +-- Disabled by default. + +if replace then + minetest.register_abm({ + label = "Slab replace", + nodenames = {"group:slabs_replace"}, + interval = 16, + chance = 1, + action = function(pos, node) + node.name = minetest.registered_nodes[node.name].replace_name + node.param2 = node.param2 + 20 + if node.param2 == 21 then + node.param2 = 23 + elseif node.param2 == 23 then + node.param2 = 21 + end + minetest.set_node(pos, node) + end, }) end + +-- Stair/slab registration function. -- Nodes will be called stairs:{stair,slab}_ -function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds) + +function stairs.register_stair_and_slab(subname, recipeitem, + groups, images, desc_stair, desc_slab, sounds) stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds) stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds) end + stairs.register_stair("wood", "default:wood", {snappy=2,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood_stairs=1}, {"default_wood.png"}, @@ -404,6 +435,3 @@ minetest.register_craft({ recipe = "group:wood_slab", burntime = 15, }) - -local time_to_load= os.clock() - init -print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load)) diff --git a/mods/stairs/license.txt b/mods/stairs/license.txt new file mode 100644 index 0000000000..8f16bbd7b8 --- /dev/null +++ b/mods/stairs/license.txt @@ -0,0 +1,51 @@ +License of source code +---------------------- + +GNU Lesser General Public License, version 2.1 +Copyright (C) 2011-2016 Kahrl +Copyright (C) 2011-2016 celeron55, Perttu Ahola +Copyright (C) 2012-2016 Various Minetest developers and contributors + +This program is free software; you can redistribute it and/or modify it under the terms +of the GNU Lesser General Public License as published by the Free Software Foundation; +either version 2.1 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU Lesser General Public License for more details: +https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html + + +Licenses of media (models) +-------------------------- + +Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) +Copyright (C) 2015-2016 Jean-Patrick G. (kilbith) + +You are free to: +Share — copy and redistribute the material in any medium or format. +Adapt — remix, transform, and build upon the material for any purpose, even commercially. +The licensor cannot revoke these freedoms as long as you follow the license terms. + +Under the following terms: + +Attribution — You must give appropriate credit, provide a link to the license, and +indicate if changes were made. You may do so in any reasonable manner, but not in any way +that suggests the licensor endorses you or your use. + +ShareAlike — If you remix, transform, or build upon the material, you must distribute +your contributions under the same license as the original. + +No additional restrictions — You may not apply legal terms or technological measures that +legally restrict others from doing anything the license permits. + +Notices: + +You do not have to comply with the license for elements of the material in the public +domain or where your use is permitted by an applicable exception or limitation. +No warranties are given. The license may not give you all of the permissions necessary +for your intended use. For example, other rights such as publicity, privacy, or moral +rights may limit how you use the material. + +For more details: +http://creativecommons.org/licenses/by-sa/3.0/ diff --git a/mods/stairs/models/stairs_stair.obj b/mods/stairs/models/stairs_stair.obj new file mode 100644 index 0000000000..45882c6ee4 --- /dev/null +++ b/mods/stairs/models/stairs_stair.obj @@ -0,0 +1,113 @@ +# Blender v2.72 (sub 0) OBJ File: '' +# www.blender.org +mtllib stairs.mtl +o stairs_top +v -0.500000 0.000000 -0.500000 +v -0.500000 0.000000 0.000000 +v 0.500000 0.000000 0.000000 +v 0.500000 0.000000 -0.500000 +v -0.500000 0.500000 0.000000 +v 0.500000 0.500000 0.000000 +v -0.500000 0.500000 0.500000 +v 0.500000 0.500000 0.500000 +vt 0.000000 0.000000 +vt 1.000000 0.000000 +vt 1.000000 0.500000 +vt 0.000000 0.500000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vn 0.000000 1.000000 0.000000 +g stairs_top +usemtl None +s off +f 4/1/1 1/2/1 2/3/1 3/4/1 +f 7/5/1 8/6/1 6/4/1 5/3/1 +o stairs_bottom +v -0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +vt 1.000000 0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vn 0.000000 -1.000000 -0.000000 +g stairs_bottom +usemtl None +s off +f 11/7/2 9/8/2 10/9/2 12/10/2 +o stairs_right +v -0.500000 0.000000 -0.500000 +v -0.500000 -0.500000 -0.500000 +v -0.500000 0.000000 0.000000 +v -0.500000 -0.500000 0.500000 +v -0.500000 0.500000 0.000000 +v -0.500000 0.500000 0.500000 +vt 0.000000 0.500000 +vt 0.000000 0.000000 +vt 0.500000 0.500000 +vt 1.000000 1.000000 +vt 0.500000 1.000000 +vt 1.000000 0.000000 +vn -1.000000 0.000000 0.000000 +g stairs_right +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 +o stairs_left +v 0.500000 0.000000 0.000000 +v 0.500000 -0.500000 -0.500000 +v 0.500000 0.000000 -0.500000 +v 0.500000 -0.500000 0.500000 +v 0.500000 0.500000 0.000000 +v 0.500000 0.500000 0.500000 +vt 0.500000 0.500000 +vt 1.000000 0.000000 +vt 1.000000 0.500000 +vt 0.500000 1.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vn 1.000000 0.000000 0.000000 +g stairs_left +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 +o stairs_back +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +v -0.500000 0.500000 0.500000 +v 0.500000 0.500000 0.500000 +vt 1.000000 0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vn 0.000000 -0.000000 1.000000 +g stairs_back +usemtl None +s off +f 26/23/5 28/24/5 27/25/5 25/26/5 +o stairs_front +v -0.500000 0.000000 -0.500000 +v -0.500000 -0.500000 -0.500000 +v -0.500000 0.000000 0.000000 +v 0.500000 0.000000 0.000000 +v 0.500000 -0.500000 -0.500000 +v 0.500000 0.000000 -0.500000 +v -0.500000 0.500000 0.000000 +v 0.500000 0.500000 0.000000 +vt 1.000000 0.000000 +vt 1.000000 0.500000 +vt 0.000000 0.500000 +vt 0.000000 0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vn 0.000000 0.000000 -1.000000 +g stairs_front +usemtl None +s off +f 30/27/6 29/28/6 34/29/6 33/30/6 +f 31/28/6 35/31/6 36/32/6 32/29/6