init.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. -- bucket (Minetest 0.4 mod)
  2. -- A bucket, which can pick up water and lava
  3. minetest.register_alias("bucket", "bucket:bucket_empty")
  4. minetest.register_alias("bucket_water", "bucket:bucket_water")
  5. minetest.register_alias("bucket_lava", "bucket:bucket_lava")
  6. minetest.register_craft({
  7. output = 'bucket:bucket_empty 1',
  8. recipe = {
  9. {'default:steel_ingot', '', 'default:steel_ingot'},
  10. {'', 'default:steel_ingot', ''},
  11. }
  12. })
  13. bucket = {}
  14. bucket.liquids = {}
  15. -- Register a new liquid
  16. -- source = name of the source node
  17. -- flowing = name of the flowing node
  18. -- itemname = name of the new bucket item (or nil if liquid is not takeable)
  19. -- inventory_image = texture of the new bucket item (ignored if itemname == nil)
  20. -- This function can be called from any mod (that depends on bucket).
  21. function bucket.register_liquid(source, flowing, itemname, inventory_image)
  22. bucket.liquids[source] = {
  23. source = source,
  24. flowing = flowing,
  25. itemname = itemname,
  26. }
  27. bucket.liquids[flowing] = bucket.liquids[source]
  28. if itemname ~= nil then
  29. minetest.register_craftitem(itemname, {
  30. inventory_image = inventory_image,
  31. stack_max = 1,
  32. liquids_pointable = true,
  33. on_use = function(itemstack, user, pointed_thing)
  34. -- Must be pointing to node
  35. if pointed_thing.type ~= "node" then
  36. return
  37. end
  38. -- Check if pointing to a liquid
  39. n = minetest.get_node(pointed_thing.under)
  40. if bucket.liquids[n.name] == nil then
  41. -- Not a liquid
  42. minetest.add_node(pointed_thing.above, {name=source})
  43. elseif n.name ~= source then
  44. -- It's a liquid
  45. minetest.add_node(pointed_thing.under, {name=source})
  46. end
  47. return {name="bucket:bucket_empty"}
  48. end
  49. })
  50. end
  51. end
  52. minetest.register_craftitem("bucket:bucket_empty", {
  53. inventory_image = "bucket.png",
  54. stack_max = 1,
  55. liquids_pointable = true,
  56. on_use = function(itemstack, user, pointed_thing)
  57. -- Must be pointing to node
  58. if pointed_thing.type ~= "node" then
  59. return
  60. end
  61. -- Check if pointing to a liquid source
  62. n = minetest.get_node(pointed_thing.under)
  63. liquiddef = bucket.liquids[n.name]
  64. if liquiddef ~= nil and liquiddef.source == n.name and liquiddef.itemname ~= nil then
  65. minetest.add_node(pointed_thing.under, {name="air"})
  66. return {name=liquiddef.itemname}
  67. end
  68. end,
  69. })
  70. bucket.register_liquid(
  71. "default:water_source",
  72. "default:water_flowing",
  73. "bucket:bucket_water",
  74. "bucket_water.png"
  75. )
  76. bucket.register_liquid(
  77. "default:lava_source",
  78. "default:lava_flowing",
  79. "bucket:bucket_lava",
  80. "bucket_lava.png"
  81. )
  82. minetest.register_craft({
  83. type = "fuel",
  84. recipe = "bucket:bucket_lava",
  85. burntime = 60,
  86. })