init.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. minetest.register_craftitem("floodfill:bucket", {
  2. description = "Floodfill Magic Bucket",
  3. inventory_image = "bucket.png^[colorize:gold:80",
  4. stack_max = 1,
  5. liquids_pointable = true,
  6. on_use = function(itemstack, player, pointed_thing)
  7. if pointed_thing.type ~= "node" then
  8. return
  9. end
  10. local opos = pointed_thing.under
  11. local node = minetest.get_node(opos)
  12. if node.name ~= "default:water_source" and node.name ~= "default:water_flowing" then
  13. return
  14. end
  15. local radius = 10
  16. local visited = {}
  17. local stack = { opos }
  18. while #stack > 0 do
  19. -- pop this node
  20. local cpos = table.remove(stack)
  21. local chash = minetest.hash_node_position(cpos)
  22. if visited[chash] == nil then
  23. visited[chash] = 1
  24. local cnode = minetest.get_node(cpos)
  25. local def = node and minetest.registered_nodes[cnode.name]
  26. if node.name == "air" or def.buildable_to then
  27. minetest.add_node(cpos, {name = "default:water_source"})
  28. if math.abs(opos.x - cpos.x) < radius and math.abs(opos.z - cpos.z) < radius then
  29. table.insert(stack, {x=cpos.x + 1, y=cpos.y, z=cpos.z})
  30. table.insert(stack, {x=cpos.x - 1, y=cpos.y, z=cpos.z})
  31. table.insert(stack, {x=cpos.x, y=cpos.y, z=cpos.z + 1})
  32. table.insert(stack, {x=cpos.x, y=cpos.y, z=cpos.z - 1})
  33. end
  34. end
  35. end
  36. end
  37. end,
  38. })
  39. minetest.register_craft({
  40. output = 'floodfill:bucket',
  41. type = "shapeless",
  42. recipe = {'default:bucket_empty', 'default:gold_ingot'},
  43. })