From: Perttu Ahola Date: Sun, 17 Jun 2012 16:47:17 +0000 (+0300) Subject: Add flipped stair recipe for silly minecrafters and make slabs convert to full cubes... X-Git-Tag: 0.4.0~3 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=274f280e1043bcd244dc93b100a2440cfaca2993;p=oweals%2Fminetest_game.git Add flipped stair recipe for silly minecrafters and make slabs convert to full cubes when placed on each other --- diff --git a/mods/stairs/init.lua b/mods/stairs/init.lua index d07c96eb..1b00ef36 100644 --- a/mods/stairs/init.lua +++ b/mods/stairs/init.lua @@ -30,6 +30,16 @@ function stairs.register_stair(subname, recipeitem, groups, images, description) {recipeitem, recipeitem, recipeitem}, }, }) + + -- Flipped recipe for the silly minecrafters + minetest.register_craft({ + output = 'stairs:stair_' .. subname .. ' 4', + recipe = { + {"", "", recipeitem}, + {"", recipeitem, recipeitem}, + {recipeitem, recipeitem, recipeitem}, + }, + }) end -- Node will be called stairs:slab_ @@ -49,6 +59,46 @@ function stairs.register_slab(subname, recipeitem, groups, images, description) type = "fixed", 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 + + -- 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.env:get_node(p0) + local n1 = minetest.env:get_node(p1) + if n0.name == "stairs:slab_" .. subname then + slabpos = p0 + slabnode = n0 + elseif n1.name == "stairs:slab_" .. subname then + slabpos = p1 + slabnode = n1 + end + if slabpos then + -- Remove the slab at slabpos + minetest.env: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.env:set_node(slabpos, slabnode) + end + return itemstack + end + + -- Otherwise place regularly + return minetest.item_place(itemstack, placer, pointed_thing) + end, }) minetest.register_craft({