nodes_hay.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. -- contains hay_mat, hay and hay bale
  2. -- (gives the pitchfork some work)
  3. --
  4. local S = cottages.S
  5. -- If default:dirt_with_grass is digged while wielding a pitchfork, it will
  6. -- turn into dirt and get some hay placed above it.
  7. -- The hay will disappear (decay) after a couple of minutes.
  8. if( minetest.registered_items["default:dirt_with_grass"]
  9. and minetest.registered_tools["cottages:pitchfork"]) then
  10. minetest.override_item("default:dirt_with_grass", {
  11. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  12. if( not( pos ) or not( digger )) then
  13. return
  14. end
  15. local wielded = digger:get_wielded_item()
  16. if( not( wielded )
  17. or not( wielded:get_name() )
  18. or (wielded:get_name()~="cottages:pitchfork")) then
  19. return
  20. end
  21. local pos_above = {x=pos.x, y=pos.y+1, z=pos.z}
  22. local node_above = minetest.get_node_or_nil( pos_above)
  23. if( not(node_above) or not(node_above.name) or node_above.name ~= "air" ) then
  24. return nil
  25. end
  26. minetest.swap_node( pos, {name="default:dirt"})
  27. minetest.add_node( pos_above, {name="cottages:hay_mat", param2=math.random(2,25)})
  28. -- start a node timer so that the hay will decay after some time
  29. local timer = minetest.get_node_timer(pos_above)
  30. if not timer:is_started() then
  31. timer:start(math.random(60, 300))
  32. end
  33. -- TODO: prevent dirt from beeing multiplied this way (that is: give no dirt!)
  34. return
  35. end,
  36. })
  37. end
  38. -- more comparable to the straw mat than to a hay bale
  39. -- (can be created by digging dirt with grass with the pitchfork)
  40. minetest.register_node("cottages:hay_mat", {
  41. drawtype = "nodebox",
  42. paramtype2 = "leveled",
  43. description = S("Some hay"),
  44. tiles = {cottages.straw_texture.."^[multiply:#88BB88"},
  45. groups = {hay=3, snappy=2, oddly_breakable_by_hand=2, flammable=3},
  46. sounds = cottages.sounds.leaves,
  47. -- the bale is slightly smaller than a full node
  48. is_ground_content = false,
  49. node_box = {
  50. type = "leveled", --"fixed",
  51. fixed = {
  52. {-0.5,-0.5,-0.5, 0.5, 0.5, 0.5},
  53. }
  54. },
  55. -- make sure a placed hay block looks halfway reasonable
  56. after_place_node = function(pos, placer, itemstack, pointed_thing)
  57. minetest.swap_node( pos, {name="cottages:hay_mat", param2=math.random(2,25)})
  58. end,
  59. on_timer = function(pos, elapsed)
  60. local node = minetest.get_node(pos)
  61. if( node and node.name=="cottages:hay_mat") then
  62. minetest.remove_node(pos)
  63. minetest.check_for_falling(pos)
  64. end
  65. end,
  66. })
  67. -- hay block, similar to straw block
  68. minetest.register_node("cottages:hay", {
  69. description = S("Hay"),
  70. tiles = {cottages.straw_texture.."^[multiply:#88BB88"},
  71. groups = {hay=3, snappy=2, oddly_breakable_by_hand=2, flammable=3},
  72. sounds = cottages.sounds.leaves,
  73. is_ground_content = false,
  74. })
  75. -- hay bales for hungry animals
  76. minetest.register_node("cottages:hay_bale", {
  77. drawtype = "nodebox",
  78. description = S("Hay bale"),
  79. tiles = {"cottages_darkage_straw_bale.png^[multiply:#88BB88"},
  80. paramtype = "light",
  81. groups = {hay=3, snappy=2, oddly_breakable_by_hand=2, flammable=3},
  82. sounds = cottages.sounds.leaves,
  83. -- the bale is slightly smaller than a full node
  84. node_box = {
  85. type = "fixed",
  86. fixed = {
  87. {-0.45, -0.5,-0.45, 0.45, 0.45, 0.45},
  88. }
  89. },
  90. selection_box = {
  91. type = "fixed",
  92. fixed = {
  93. {-0.45, -0.5,-0.45, 0.45, 0.45, 0.45},
  94. }
  95. },
  96. is_ground_content = false,
  97. })
  98. --
  99. -- craft recipes
  100. --
  101. minetest.register_craft({
  102. output = "cottages:hay_mat 9",
  103. recipe = {
  104. {"cottages:hay"},
  105. },
  106. })
  107. minetest.register_craft({
  108. output = "cottages:hay",
  109. recipe = {
  110. {"cottages:hay_mat", "cottages:hay_mat", "cottages:hay_mat"},
  111. {"cottages:hay_mat", "cottages:hay_mat", "cottages:hay_mat"},
  112. {"cottages:hay_mat", "cottages:hay_mat", "cottages:hay_mat"},
  113. },
  114. })
  115. minetest.register_craft({
  116. output = "cottages:hay",
  117. recipe = {{"cottages:hay_bale"}},
  118. })
  119. minetest.register_craft({
  120. output = "cottages:hay_bale",
  121. recipe = {{"cottages:hay"}},
  122. })