Allow to combine slabs from below

This commit is contained in:
Wuzzy 2017-06-05 16:10:21 +02:00
parent 72a9eef09c
commit f3805ab395
1 changed files with 29 additions and 41 deletions

View File

@ -6,7 +6,7 @@
stairs = {} stairs = {}
local function place_slab(itemstack, placer, pointed_thing) local function place_slab_normal(itemstack, placer, pointed_thing)
local p0 = pointed_thing.under local p0 = pointed_thing.under
local p1 = pointed_thing.above local p1 = pointed_thing.above
@ -159,60 +159,47 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
local wield_item = itemstack:get_name() local wield_item = itemstack:get_name()
local creative_enabled = minetest.setting_getbool("creative_mode") local creative_enabled = minetest.setting_getbool("creative_mode")
if under and wield_item == under.name then -- place slab using under node orientation
-- place slab using under node orientation local dir = vector.subtract(pointed_thing.above, pointed_thing.under)
local dir = minetest.dir_to_facedir(vector.subtract(
pointed_thing.above, pointed_thing.under), true)
local p2 = under.param2 local p2 = under.param2
-- combine two slabs if possible -- combine two slabs if possible
if wield_item == under.name then -- Requirements: Same slab material, must be placed on top of lower slab, or on bottom of upper slab
if (wield_item == under.name or wield_item == minetest.registered_nodes[under.name]._mcl_other_slab_half) and
not ((dir.y >= 0 and minetest.get_item_group(under.name, "slab_top") == 1) or
(dir.y <= 0 and minetest.get_item_group(under.name, "slab_top") == 0)) then
if not recipeitem 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
local newnode
if full_node then
newnode = full_node
elseif double_description then
newnode = double_slab
else
newnode = recipeitem
end
minetest.set_node(pointed_thing.under, {name = newnode, param2 = p2})
if not creative_enabled then
itemstack:take_item()
end
return itemstack return itemstack
end end
local player_name = placer:get_player_name()
-- Placing a slab on an upside down slab should make it right-side up. if minetest.is_protected(pointed_thing.under, player_name) and not
if p2 >= 20 and dir == 8 then minetest.check_player_privs(placer, "protection_bypass") then
p2 = p2 - 20 minetest.record_protection_violation(pointed_thing.under,
-- same for the opposite case: slab below normal slab player_name)
elseif p2 <= 3 and dir == 4 then return
p2 = p2 + 20
end end
local newnode
-- else attempt to place node with proper param2 if full_node then
minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2) newnode = full_node
elseif double_description then
newnode = double_slab
else
newnode = recipeitem
end
minetest.set_node(pointed_thing.under, {name = newnode, param2 = p2})
if not creative_enabled then if not creative_enabled then
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack
-- No combination possible: Place slab normally
else else
return place_slab(itemstack, placer, pointed_thing) return place_slab_normal(itemstack, placer, pointed_thing)
end end
end, end,
_mcl_hardness = hardness, _mcl_hardness = hardness,
_mcl_other_slab_half = upper_slab,
} }
minetest.register_node(":"..lower_slab, slabdef) minetest.register_node(":"..lower_slab, slabdef)
@ -230,6 +217,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
topdef._doc_items_longdesc = nil topdef._doc_items_longdesc = nil
topdef._doc_items_usagehelp = nil topdef._doc_items_usagehelp = nil
topdef.drop = lower_slab topdef.drop = lower_slab
topdef._mcl_other_slab_half = lower_slab
topdef.node_box = { topdef.node_box = {
type = "fixed", type = "fixed",
fixed = {-0.5, 0, -0.5, 0.5, 0.5, 0.5}, fixed = {-0.5, 0, -0.5, 0.5, 0.5, 0.5},