local modname = minetest.get_current_modname()

local function on_place(itemstack, placer, pointed_thing)
	if not placer then
		return
	end
	local ctrl = placer:get_player_control()
	local param2
	if ctrl.aux1 then
		--place just like pointed slab
		minetest.chat_send_all("a")
		local pointed = minetest.get_node(pointed_thing.under)
		if minetest.get_item_group(pointed.name, "slab") > 0 then
			param2 = pointed.param2
		end
	end
	return minetest.item_place_node(itemstack, placer, pointed_thing, param2)
end

local slabs = {}
_G[modname] = slabs

--registeres a slab node for an aleready registered node
function slabs.slabify(S, name, def, description)
	name = name .. "_slab"
	def = table.copy(def)
	def.description = description
	def.drawtype = "nodebox"
	def.paramtype = "light"
	def.paramtype2 = "wallmounted"
	def.node_box = {
		type = "wallmounted",
		wall_bottom = {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
		wall_top = {-0.5, 0, -0.5, 0.5, 0.5, 0.5},
		wall_side = {-0.5, -0.5, -0.5, 0, 0.5, 0.5},
	}
	def.groups["slab"] = 1
	def.on_place = on_place
	minetest.register_node(name, def)
end

function slabs.register_slabs(node_list)
	for name, description in pairs(node_list)
	do
		local def = minetest.registered_nodes[name]
		slabs.slabify(S, name, def, description)
	end
end
