Final repair of connection API. Added three types of flowerpots
parent
e14e1aa740
commit
07000ab636
|
@ -7,6 +7,9 @@ function connecting.are_nodes_identical(pos1, pos2)
|
|||
local add_props1 = minetest.registered_nodes[minetest.get_node(pos1).name].add_properties
|
||||
local add_props2 = minetest.registered_nodes[minetest.get_node(pos2).name].add_properties
|
||||
|
||||
minetest.debug("cmn1: " .. dump(add_props1 and add_props1.common_name or nil))
|
||||
minetest.debug("cmn2: " .. dump(add_props2 and add_props2.common_name or nil))
|
||||
|
||||
return add_props1 and add_props2 and add_props1.common_name == add_props2.common_name
|
||||
end
|
||||
|
||||
|
@ -18,7 +21,7 @@ function connecting.are_nodes_codirectional(pos1, pos2)
|
|||
end
|
||||
|
||||
-- Replaces surrounding the identical table nodes to other to look like "connected" with node at 'pos'
|
||||
function connecting.replace_node_to(pos, disconnect)
|
||||
function connecting.replace_node_to(pos, disconnect, cmn_name)
|
||||
local ord_shifts = {
|
||||
pos + vector.new(-1, 0, 0),
|
||||
pos + vector.new(0, 0, 1),
|
||||
|
@ -34,20 +37,27 @@ function connecting.replace_node_to(pos, disconnect)
|
|||
return
|
||||
end
|
||||
|
||||
if add_props.common_name ~= cmn_name then
|
||||
return
|
||||
end
|
||||
|
||||
local target_node = ""
|
||||
local rel_rot = 0
|
||||
|
||||
if connecting.are_nodes_identical(ord_shifts[1], pos) then
|
||||
minetest.debug("identical")
|
||||
target_node = "edge"
|
||||
rel_rot = 180
|
||||
end
|
||||
|
||||
if connecting.are_nodes_identical(ord_shifts[2], pos) then
|
||||
minetest.debug("identical")
|
||||
target_node = target_node == "edge" and "corner" or "edge"
|
||||
rel_rot = 90
|
||||
end
|
||||
|
||||
if connecting.are_nodes_identical(ord_shifts[3], pos) then
|
||||
minetest.debug("identical")
|
||||
if target_node == "corner" then
|
||||
target_node = "edge_middle"
|
||||
elseif target_node == "edge" then
|
||||
|
@ -59,6 +69,7 @@ function connecting.replace_node_to(pos, disconnect)
|
|||
end
|
||||
|
||||
if connecting.are_nodes_identical(ord_shifts[4], pos) then
|
||||
minetest.debug("identical")
|
||||
if target_node == "edge_middle" then
|
||||
target_node = "off_edge"
|
||||
rel_rot = 0
|
||||
|
@ -87,7 +98,7 @@ function connecting.replace_node_to(pos, disconnect)
|
|||
minetest.set_node(pos, {name="multidecor:" .. add_props.common_name .. target_node, param2=param2})
|
||||
end
|
||||
|
||||
function connecting.directional_replace_node_to(pos, dir, side, disconnect)
|
||||
function connecting.directional_replace_node_to(pos, dir, side, disconnect, cmn_name)
|
||||
local node = minetest.get_node(pos)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
local add_props = def.add_properties
|
||||
|
@ -98,6 +109,10 @@ function connecting.directional_replace_node_to(pos, dir, side, disconnect)
|
|||
return
|
||||
end
|
||||
|
||||
if add_props.common_name ~= cmn_name then
|
||||
return
|
||||
end
|
||||
|
||||
local left_dir
|
||||
local right_dir
|
||||
|
||||
|
@ -192,12 +207,13 @@ function connecting.update_adjacent_nodes_connection(pos, type, disconnect, old_
|
|||
pos + vector.new(0, 0, -1)
|
||||
}
|
||||
|
||||
local cmn_name = minetest.registered_nodes[disconnect and old_node.name or node.name].add_properties.common_name
|
||||
for _, s in ipairs(shifts) do
|
||||
connecting.replace_node_to(s, disconnect)
|
||||
connecting.replace_node_to(s, disconnect, cmn_name)
|
||||
end
|
||||
|
||||
if not disconnect then
|
||||
connecting.replace_node_to(pos)
|
||||
connecting.replace_node_to(pos, nil, cmn_name)
|
||||
end
|
||||
elseif type == "pair" then
|
||||
if not disconnect then
|
||||
|
@ -241,11 +257,12 @@ function connecting.update_adjacent_nodes_connection(pos, type, disconnect, old_
|
|||
local left = pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, -math.pi/2)
|
||||
local right = pos+vector.rotate_around_axis(dir, {x=0, y=1, z=0}, math.pi/2)
|
||||
|
||||
connecting.directional_replace_node_to(left, dir, "left", disconnect)
|
||||
connecting.directional_replace_node_to(right, dir, "right", disconnect)
|
||||
local cmn_name = minetest.registered_nodes[disconnect and old_node.name or node.name].add_properties.common_name
|
||||
connecting.directional_replace_node_to(left, dir, "left", disconnect, cmn_name)
|
||||
connecting.directional_replace_node_to(right, dir, "right", disconnect, cmn_name)
|
||||
|
||||
if not disconnect then
|
||||
connecting.directional_replace_node_to(pos, dir, nil)
|
||||
connecting.directional_replace_node_to(pos, dir, nil, nil, cmn_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -111,22 +111,236 @@ minetest.register_node(":multidecor:laminate",
|
|||
},
|
||||
groups = {choppy=1.5}
|
||||
})
|
||||
--[[register.register_furniture_unit("laminate", {
|
||||
type = "decoration",
|
||||
style = "modern",
|
||||
material = "wood",
|
||||
drawtype = "nodebox",
|
||||
|
||||
|
||||
local flowers = {
|
||||
"rose",
|
||||
"tulip",
|
||||
"dandelion_yellow",
|
||||
"chrysanthemum_green",
|
||||
"geranium",
|
||||
"viola",
|
||||
"dandelion_white",
|
||||
"tulip_black"
|
||||
}
|
||||
|
||||
local on_rightclick_flowerpot = function(pos, node, clicker, itemstack)
|
||||
local itemname = itemstack:get_name()
|
||||
|
||||
local is_flowers_mod_i, is_flowers_mod_i2 = itemname:find("flowers:")
|
||||
minetest.debug("is_flowers_mod_i: " .. dump(is_flowers_mod_i))
|
||||
minetest.debug("group: " .. minetest.get_item_group(itemname, "flower"))
|
||||
if not is_flowers_mod_i or minetest.get_item_group(itemname, "flower") == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local flower = itemname:sub(is_flowers_mod_i2+1)
|
||||
|
||||
minetest.set_node(pos, {name=node.name .. "_with_flower_" .. flower, param2=node.param2})
|
||||
|
||||
itemstack:take_item()
|
||||
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local on_rightclick_flowerpot_with_flower = function(pos, node, clicker, itemstack)
|
||||
local pot_groups = minetest.registered_nodes[node.name].groups
|
||||
local current_flower = flowers[pot_groups.flower_in_pot]
|
||||
|
||||
local itemname = itemstack:get_name()
|
||||
|
||||
local is_flowers_mod_i, is_flowers_mod_i2 = itemname:find("flowers:")
|
||||
if is_flowers_mod_i and minetest.get_item_group(itemname, "flower") == 1 then
|
||||
local flower = itemname:sub(is_flowers_mod_i2+1)
|
||||
minetest.set_node(pos, {name=node.name:gsub(current_flower, flower), param2=node.param2})
|
||||
|
||||
itemstack:take_item()
|
||||
else
|
||||
minetest.set_node(pos, {name=node.name:gsub("_with_flower_" .. current_flower, ""), param2=node.param2})
|
||||
end
|
||||
|
||||
minetest.debug("current_flower: " .. current_flower)
|
||||
clicker:get_inventory():add_item("main", "flowers:" .. current_flower)
|
||||
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local after_destruct_flowerpot = function(pos, oldnode, oldmeta, digger)
|
||||
local pot_groups = minetest.registered_nodes[oldnode.name].groups
|
||||
local flower = flowers[pot_groups.flower_in_pot]
|
||||
|
||||
digger:get_inventory():add_item("main", "flowers:" .. flower)
|
||||
end
|
||||
|
||||
local flowerpot_tmp_def = {
|
||||
visual_scale = 0.5,
|
||||
description = "Laminate",
|
||||
tiles = {"multidecor_laminate.png"},
|
||||
bounding_boxes = {{-0.5, -0.5, -0.5, 0.5 -0.45, 0.5}}
|
||||
drawtype = "mesh",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
}
|
||||
|
||||
local pots_defs = {
|
||||
["terracotta_flowerpot"] = {
|
||||
description = "Terracotta Flowerpot (right-click to place wielded flower)",
|
||||
mesh = "multidecor_terracotta_flowerpot",
|
||||
tiles = {
|
||||
"multidecor_terracotta_material2.png^[multiply:brown",
|
||||
"multidecor_terracotta_material.png^[multiply:brown",
|
||||
"default_dirt.png",
|
||||
},
|
||||
bounding_boxes = {{-0.4, -0.5, -0.4, 0.4, 0.25, 0.4}}
|
||||
},
|
||||
["green_small_flowerpot"] = {
|
||||
description = "Green Small Flowerpot (right-click to place wielded flower)",
|
||||
mesh = "multidecor_green_small_flowerpot",
|
||||
tiles = {
|
||||
"multidecor_terracotta_material.png^[multiply:palegreen",
|
||||
"default_dirt.png"
|
||||
},
|
||||
bounding_boxes = {{-0.3, -0.5, -0.3, 0.3, 0.05, 0.3}},
|
||||
}
|
||||
}
|
||||
|
||||
for name, def in pairs(pots_defs) do
|
||||
local cdef = table.copy(flowerpot_tmp_def)
|
||||
cdef.description = def.description
|
||||
cdef.mesh = def.mesh .. ".b3d"
|
||||
cdef.tiles = def.tiles
|
||||
cdef.collision_box = {
|
||||
type = "fixed",
|
||||
fixed = def.bounding_boxes
|
||||
}
|
||||
|
||||
cdef.groups = {cracky=1.5}
|
||||
cdef.sounds = default.node_sound_stone_defaults()
|
||||
cdef.selection_box = cdef.collision_box
|
||||
|
||||
cdef.on_rightclick = on_rightclick_flowerpot
|
||||
|
||||
minetest.register_node(":multidecor:" .. name, cdef)
|
||||
|
||||
for i=1, #flowers do
|
||||
local cdef2 = table.copy(cdef)
|
||||
cdef2.mesh = def.mesh .. "_with_flower.b3d"
|
||||
table.insert(cdef2.tiles, "flowers_" .. flowers[i] .. ".png")
|
||||
|
||||
cdef2.drop = "multidecor:" .. name
|
||||
cdef2.groups.not_in_creative_inventory = 1
|
||||
cdef2.groups.flower_in_pot = i
|
||||
cdef2.on_rightclick = on_rightclick_flowerpot_with_flower
|
||||
cdef2.after_dig_node = after_destruct_flowerpot
|
||||
|
||||
minetest.register_node(":multidecor:" .. name .. "_with_flower_" .. flowers[i], cdef2)
|
||||
end
|
||||
end
|
||||
|
||||
--[[minetest.register_node(":multidecor:terracotta_flowerpot", {
|
||||
visual_scale = 0.5,
|
||||
drawtype = "mesh",
|
||||
description = "Terracotta Flowerpot (right-click to place wielded flower)",
|
||||
paramtype = "light"
|
||||
mesh = "multidecor_terracotta_flowerpot.b3d",
|
||||
tiles = {
|
||||
"multidecor_terracotta_material2.png^[multiply:brown",
|
||||
"multidecor_terracotta_material.png^[multiply:brown",
|
||||
"default_dirt.png",
|
||||
},
|
||||
bounding_boxes = {{-0.4, -0.5, -0.4, 0.4, 0.25, 0.4}},
|
||||
callbacks = {
|
||||
on_rightclick = on_rightclick_flowerpot
|
||||
}
|
||||
},
|
||||
{
|
||||
recipe = {
|
||||
{"multidecor:plank", "multidecor:multidecor:plank", "multidecor:plank"},
|
||||
{"multidecor:saw", "", ""},
|
||||
{"", "", ""}
|
||||
{"multidecor:jungleboard", "multidecor:jungleboard", "multidecor:jungleboard"},
|
||||
{"doors:door_glass", "multidecor:digital_dial", "multidecor:jungleboard"},
|
||||
{"multidecor:gear", "multidecor:gear", "multidecor:spring"}
|
||||
}
|
||||
})]]
|
||||
}]]
|
||||
|
||||
minetest.debug("laminate: " .. dump(minetest.registered_nodes["multidecor:laminate"]))
|
||||
register.register_furniture_unit("white_plastic_flowerpot", {
|
||||
type = "decoration",
|
||||
style = "modern",
|
||||
material = "plastic",
|
||||
visual_scale = 0.5,
|
||||
description = "White Plastic Flowerpot",
|
||||
mesh = "multidecor_white_plastic_flowerpot.b3d",
|
||||
tiles = {
|
||||
"multidecor_white_plastic_pot.png",
|
||||
"default_dirt.png"
|
||||
},
|
||||
bounding_boxes = {{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}}
|
||||
}--[[,
|
||||
{
|
||||
recipe = {
|
||||
{"multidecor:jungleboard", "multidecor:jungleboard", "multidecor:jungleboard"},
|
||||
{"doors:door_glass", "multidecor:digital_dial", "multidecor:jungleboard"},
|
||||
{"multidecor:gear", "multidecor:gear", "multidecor:spring"}
|
||||
}
|
||||
}]])
|
||||
|
||||
--[[register.register_furniture_unit("green_small_flowerpot", {
|
||||
type = "decoration",
|
||||
style = "modern",
|
||||
material = "stone",
|
||||
visual_scale = 0.5,
|
||||
description = "Green Small Flowerpot (right-click to place wielded flower)",
|
||||
mesh = "multidecor_green_small_flowerpot.b3d",
|
||||
tiles = {
|
||||
"multidecor_terracotta_material.png^[multiply:palegreen",
|
||||
"default_dirt.png"
|
||||
},
|
||||
bounding_boxes = {{-0.3, -0.5, -0.3, 0.3, 0.05, 0.3}},
|
||||
callbacks = {
|
||||
on_rightclick = on_rightclick_flowerpot
|
||||
}
|
||||
}--[[,
|
||||
{
|
||||
recipe = {
|
||||
{"multidecor:jungleboard", "multidecor:jungleboard", "multidecor:jungleboard"},
|
||||
{"doors:door_glass", "multidecor:digital_dial", "multidecor:jungleboard"},
|
||||
{"multidecor:gear", "multidecor:gear", "multidecor:spring"}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
for i = 1, #flowers do
|
||||
register.register_furniture_unit("terracotta_flowerpot_with_flower_" .. flowers[i], {
|
||||
type = "decoration",
|
||||
style = "modern",
|
||||
material = "stone",
|
||||
visual_scale = 0.5,
|
||||
description = "Terracotta Flowerpot (right-click to place wielded flower)",
|
||||
mesh = "multidecor_terracotta_flowerpot_with_flower.b3d",
|
||||
tiles = {
|
||||
"multidecor_terracotta_material2.png^[multiply:brown",
|
||||
"multidecor_terracotta_material.png^[multiply:brown",
|
||||
"default_dirt.png",
|
||||
"flowers_" .. flowers[i] .. ".png"
|
||||
},
|
||||
bounding_boxes = {{-0.4, -0.5, -0.4, 0.4, 0.25, 0.4}},
|
||||
groups = {not_in_creative_inventory=1, flower_in_pot=i},
|
||||
callbacks = {
|
||||
on_rightclick = on_rightclick_flowerpot_with_flower
|
||||
}
|
||||
})
|
||||
|
||||
register.register_furniture_unit("green_small_flowerpot_with_flower_" .. flowers[i], {
|
||||
type = "decoration",
|
||||
style = "modern",
|
||||
material = "stone",
|
||||
visual_scale = 0.5,
|
||||
description = "Green Small Flowerpot (right-click to place wielded flower)",
|
||||
mesh = "multidecor_green_small_flowerpot_with_flower.b3d",
|
||||
tiles = {
|
||||
"multidecor_terracotta_material.png^[multiply:palegreen",
|
||||
"default_dirt.png",
|
||||
"flowers_" .. flowers[i] .. ".png"
|
||||
},
|
||||
bounding_boxes = {{-0.3, -0.5, -0.3, 0.3, 0.05, 0.3}},
|
||||
groups = {not_in_creative_inventory=1, flower_in_pot=i},
|
||||
callbacks = {
|
||||
on_rightclick = on_rightclick_flowerpot_with_flower
|
||||
}
|
||||
})
|
||||
end]]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
name = modern
|
||||
description = Modern-style furniture
|
||||
depends = beds, decor_api
|
||||
depends = beds, decor_api, flowers
|
||||
author = Andrey01
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -11,9 +11,9 @@ register.register_table("kitchen_modern_wooden_table", {
|
|||
on_construct = function(pos)
|
||||
connecting.update_adjacent_nodes_connection(pos, "horizontal")
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
after_dig_node = function(pos, oldnode)
|
||||
minetest.debug("1.2")
|
||||
connecting.update_adjacent_nodes_connection(pos, "horizontal", true)
|
||||
connecting.update_adjacent_nodes_connection(pos, "horizontal", true, oldnode)
|
||||
end
|
||||
}
|
||||
},
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Loading…
Reference in New Issue