123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- --Helper function to see if there is open space to place a double wide node.
- --All wide nodes should extend to the right.
- --Returns true if item should be placeable.
- --[[
- ### Use this code on nodes that need to check space to side.
- Replace placed_node with the node that should be placed. Leave blank to use the default invisible item.
- after_place_node = function(pos, placer, itemstack)
- if not epic.space_to_side(pos, placed_node) then
- minetest.remove_node(pos)
- return itemstack
- end
- end,
- ### Use this code on nodes that need to remove the empty node.
- after_dig_node = function(pos, oldnode)
- epic.remove_side_node(pos, oldnode)
- end,
- ]]
- fdir_table = {
- { 1, 0 },
- { 0, -1 },
- { -1, 0 },
- { 0, 1 },
- { 1, 0 },
- { 0, -1 },
- { -1, 0 },
- { 0, 1 },
- }
- function epic.space_to_side(pos, placed_node)
- local node = minetest.get_node(pos)
- local fdir = node.param2 % 32
- local pos2 = {x = pos.x + fdir_table[fdir+1][1], y=pos.y, z = pos.z + fdir_table[fdir+1][2]}
- local node2 = minetest.get_node(pos2)
- local node2def = minetest.registered_nodes[node2.name] or nil
- if not node2def.buildable_to then
- return false
- else
- local placed_node = placed_node or 'epic:empty'
- minetest.set_node(pos2,{name = placed_node, param2=fdir})
- return true
- end
- end
- function epic.remove_side_node(pos, oldnode)
- local fdir = oldnode.param2 % 32
- local pos2 = {x = pos.x + fdir_table[fdir+1][1], y=pos.y, z = pos.z + fdir_table[fdir+1][2]}
- local node2 = minetest.get_node(pos2).name
- if minetest.get_item_group(node2, 'empty_node') > 0 then
- minetest.remove_node(pos2)
- end
- end
- function epic.space_to_front(pos)
- local node = minetest.get_node(pos)
- local fdir = node.param2 % 32
- local pos2 = {x = pos.x + fdir_table[fdir+4][1], y=pos.y, z = pos.z + fdir_table[fdir+4][2]}
- local node2 = minetest.get_node(pos2)
- local node2def = minetest.registered_nodes[node2.name] or nil
- if not node2def.buildable_to then
- return false
- else
- minetest.set_node(pos2,{name = 'epic:empty'})
- return true
- end
- end
- function epic.remove_front_node(pos, oldnode)
- local fdir = oldnode.param2 % 32
- local pos2 = {x = pos.x + fdir_table[fdir+4][1], y=pos.y, z = pos.z + fdir_table[fdir+4][2]}
- local node2 = minetest.get_node(pos2).name
- if minetest.get_item_group(node2, 'empty_node') > 0 then
- minetest.remove_node(pos2)
- end
- end
- function epic.space_for_picnic(pos, placed_node)
- local node = minetest.get_node(pos)
- local fdir = node.param2 % 32
- local pos2 = {x = pos.x + fdir_table[fdir+1][1], y=pos.y, z = pos.z + fdir_table[fdir+1][2]} --Side node
- local pos3 = {x = pos.x + fdir_table[fdir+4][1], y=pos.y, z = pos.z + fdir_table[fdir+4][2]} --Across node
- local node2 = minetest.get_node(pos2)
- local node3 = minetest.get_node(pos3)
- local node2def = minetest.registered_nodes[node2.name] or nil
- local node3def = minetest.registered_nodes[node3.name] or nil
- if not node2def.buildable_to or not node3def.buildable_to then
- return false
- else
- local placed_node = placed_node or 'epic:empty'
- minetest.set_node(pos2,{name = placed_node, param2=fdir})
- minetest.set_node(pos3,{name = placed_node, param2=fdir})
- return true
- end
- end
- function epic.remove_picnic_nodes(pos, oldnode)
- local fdir = oldnode.param2 % 32
- local pos2 = {x = pos.x + fdir_table[fdir+1][1], y=pos.y, z = pos.z + fdir_table[fdir+1][2]} --Side node
- local pos3 = {x = pos.x + fdir_table[fdir+4][1], y=pos.y, z = pos.z + fdir_table[fdir+4][2]} --Across node
- local node2 = minetest.get_node(pos2).name
- local node3 = minetest.get_node(pos3).name
- if minetest.get_item_group(node2, 'empty_node') > 0 and minetest.get_item_group(node3, 'empty_node') >0 then
- minetest.remove_node(pos2)
- minetest.remove_node(pos3)
- end
- end
|