From 274f280e1043bcd244dc93b100a2440cfaca2993 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 17 Jun 2012 19:47:17 +0300 Subject: [PATCH] Add flipped stair recipe for silly minecrafters and make slabs convert to full cubes when placed on each other --- mods/stairs/init.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) 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({ -- 2.25.1