forked from VoxeLibre/VoxeLibre
Force-connect stems to neighboring gourds
This commit is contained in:
parent
d4f9c5c122
commit
db123b3d16
|
@ -90,16 +90,42 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s
|
||||||
connected_stem_basename .. "_b",
|
connected_stem_basename .. "_b",
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Register gourd
|
|
||||||
if not gourd_def.after_dig_node then
|
|
||||||
gourd_def.after_dig_node = function(blockpos, oldnode, oldmetadata, user)
|
|
||||||
-- Disconnect any connected stems, turning them back to normal stems
|
|
||||||
local neighbors = {
|
local neighbors = {
|
||||||
{ x=-1, y=0, z=0 },
|
{ x=-1, y=0, z=0 },
|
||||||
{ x=1, y=0, z=0 },
|
{ x=1, y=0, z=0 },
|
||||||
{ x=0, y=0, z=-1 },
|
{ x=0, y=0, z=-1 },
|
||||||
{ x=0, y=0, z=1 },
|
{ x=0, y=0, z=1 },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Connect a stem to the first neighboring gourd block
|
||||||
|
local try_connect_stem = function(stempos)
|
||||||
|
local stem = minetest.get_node(stempos)
|
||||||
|
if stem.name ~= full_unconnected_stem then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
for n=1, #neighbors do
|
||||||
|
local offset = neighbors[n]
|
||||||
|
local blockpos = vector.add(stempos, offset)
|
||||||
|
local block = minetest.get_node(blockpos)
|
||||||
|
if block.name == gourd_itemstring then
|
||||||
|
if offset.x == 1 then
|
||||||
|
minetest.set_node(stempos, {name=connected_stem_names[1]})
|
||||||
|
elseif offset.x == -1 then
|
||||||
|
minetest.set_node(stempos, {name=connected_stem_names[2]})
|
||||||
|
elseif offset.z == 1 then
|
||||||
|
minetest.set_node(stempos, {name=connected_stem_names[3]})
|
||||||
|
elseif offset.z == -1 then
|
||||||
|
minetest.set_node(stempos, {name=connected_stem_names[4]})
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Register gourd
|
||||||
|
if not gourd_def.after_dig_node then
|
||||||
|
gourd_def.after_dig_node = function(blockpos, oldnode, oldmetadata, user)
|
||||||
|
-- Disconnect any connected stems, turning them back to normal stems
|
||||||
for n=1, #neighbors do
|
for n=1, #neighbors do
|
||||||
local offset = neighbors[n]
|
local offset = neighbors[n]
|
||||||
local expected_stem = connected_stem_names[n]
|
local expected_stem = connected_stem_names[n]
|
||||||
|
@ -107,10 +133,20 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s
|
||||||
local stem = minetest.get_node(stempos)
|
local stem = minetest.get_node(stempos)
|
||||||
if stem.name == expected_stem then
|
if stem.name == expected_stem then
|
||||||
minetest.add_node(stempos, {name=full_unconnected_stem})
|
minetest.add_node(stempos, {name=full_unconnected_stem})
|
||||||
|
try_connect_stem(stempos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if not gourd_def.on_construct then
|
||||||
|
gourd_def.on_construct = function(blockpos)
|
||||||
|
-- Connect all unconnected stems at full size
|
||||||
|
for n=1, #neighbors do
|
||||||
|
local stempos = vector.add(blockpos, neighbors[n])
|
||||||
|
connect_stem(stempos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
minetest.register_node(gourd_itemstring, gourd_def)
|
minetest.register_node(gourd_itemstring, gourd_def)
|
||||||
|
|
||||||
-- Register connected stems
|
-- Register connected stems
|
||||||
|
|
Loading…
Reference in New Issue