Add flipped stair recipe for silly minecrafters and make slabs convert to full cubes...
authorPerttu Ahola <celeron55@gmail.com>
Sun, 17 Jun 2012 16:47:17 +0000 (19:47 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 17 Jun 2012 16:47:17 +0000 (19:47 +0300)
mods/stairs/init.lua

index d07c96eb4d5a53a42ad46d246373251163e392de..1b00ef3663d227fe1acf5a5d1123dc187b4e426b 100644 (file)
@@ -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_<subname>
@@ -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({