init.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. -----------------------------------------------------------------------------------------------
  2. local title = "Grasses" -- former "Dry plants"
  3. local version = "0.1.5"
  4. local mname = "dryplants"
  5. -----------------------------------------------------------------------------------------------
  6. -- by Mossmanikin
  7. -- textures & ideas partly by Neuromancer
  8. -- Contains code from: default, farming
  9. -- Looked at code from: darkage, sickle, stairs
  10. -- Dependencies: default, farming, biome_lib
  11. -- Supports:
  12. -----------------------------------------------------------------------------------------------
  13. abstract_dryplants = {}
  14. -- support for i18n
  15. local S = minetest.get_translator("dryplants")
  16. dofile(minetest.get_modpath("dryplants").."/crafting.lua")
  17. dofile(minetest.get_modpath("dryplants").."/settings.txt")
  18. dofile(minetest.get_modpath("dryplants").."/reed.lua")
  19. if REEDMACE_GENERATES == true then
  20. dofile(minetest.get_modpath("dryplants").."/reedmace.lua")
  21. end
  22. if SMALL_JUNCUS_GENERATES == true then
  23. dofile(minetest.get_modpath("dryplants").."/juncus.lua")
  24. end
  25. if EXTRA_TALL_GRASS_GENERATES == true then
  26. dofile(minetest.get_modpath("dryplants").."/moregrass.lua")
  27. end
  28. --dofile(minetest.get_modpath("dryplants").."/meadowvariation.lua")
  29. -----------------------------------------------------------------------------------------------
  30. -- Sickle
  31. -----------------------------------------------------------------------------------------------
  32. local function sickle_can_break(pos, deff, player)
  33. local def = ItemStack({name=deff.name}):get_definition()
  34. if not def.diggable or (def.can_dig and not def.can_dig(pos,player)) then
  35. minetest.log("info", player:get_player_name() .. " tried to sickle "
  36. .. def.name .. " which is not diggable "
  37. .. minetest.pos_to_string(pos))
  38. return
  39. end
  40. if minetest.is_protected(pos, player:get_player_name()) then
  41. minetest.log("action", player:get_player_name()
  42. .. " tried to sickle " .. def.name
  43. .. " at protected position "
  44. .. minetest.pos_to_string(pos))
  45. minetest.record_protection_violation(pos, player:get_player_name())
  46. return
  47. end
  48. return true
  49. end
  50. -- turns nodes with group flora=1 & flower=0 into cut grass
  51. local function sickle_on_use(itemstack, user, pointed_thing, uses)
  52. local pt = pointed_thing
  53. -- check if pointing at a node
  54. if not pt then
  55. return
  56. end
  57. if pt.type ~= "node" then
  58. return
  59. end
  60. local under = minetest.get_node(pt.under)
  61. local above_pos = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
  62. local above = minetest.get_node(above_pos)
  63. -- return if any of the nodes is not registered
  64. if not minetest.registered_nodes[under.name] then
  65. return
  66. end
  67. if not minetest.registered_nodes[above.name] then
  68. return
  69. end
  70. if not sickle_can_break(pt.under, under, user) then
  71. return
  72. end
  73. -- check if something that can be cut using fine tools
  74. if minetest.get_item_group(under.name, "snappy") > 0 then
  75. -- check if flora but no flower
  76. if minetest.get_item_group(under.name, "flora") == 1 and minetest.get_item_group(under.name, "flower") == 0 then
  77. -- turn the node into cut grass, wear out item and play sound
  78. minetest.swap_node(pt.under, {name="dryplants:grass"})
  79. else -- otherwise dig the node
  80. if not minetest.node_dig(pt.under, under, user) then
  81. return
  82. end
  83. end
  84. minetest.sound_play("default_dig_crumbly", {
  85. pos = pt.under,
  86. gain = 0.5,
  87. })
  88. itemstack:add_wear(65535/(uses-1))
  89. return itemstack
  90. elseif string.find(under.name, "default:dirt_with_grass") then
  91. if minetest.is_protected(above_pos, user:get_player_name()) or above.name ~= "air" then
  92. return
  93. end
  94. minetest.swap_node(pt.under, {name="dryplants:grass_short"})
  95. minetest.swap_node(above_pos, {name="dryplants:grass"})
  96. minetest.sound_play("default_dig_crumbly", {
  97. pos = pt.under,
  98. gain = 0.5,
  99. })
  100. itemstack:add_wear(65535/(uses-1))
  101. return itemstack
  102. end
  103. end
  104. -- the tool
  105. minetest.register_tool("dryplants:sickle", {
  106. description = S("Sickle"),
  107. inventory_image = "dryplants_sickle.png",
  108. on_use = function(itemstack, user, pointed_thing)
  109. return sickle_on_use(itemstack, user, pointed_thing, 220)
  110. end,
  111. })
  112. -----------------------------------------------------------------------------------------------
  113. -- Cut Grass
  114. -----------------------------------------------------------------------------------------------
  115. minetest.register_node("dryplants:grass", {
  116. description = S("Cut Grass"),
  117. inventory_image = "dryplants_grass.png",
  118. wield_image = "dryplants_grass.png",
  119. paramtype = "light",
  120. sunlight_propagates = true,
  121. tiles = {"dryplants_grass.png"},
  122. drawtype = "nodebox",
  123. node_box = {
  124. type = "fixed",
  125. fixed = {-0.5 , -0.5 , -0.5 , 0.5 , -0.4375, 0.5 },
  126. },
  127. groups = {snappy=3, flammable=2},
  128. sounds = default.node_sound_leaves_defaults(),
  129. })
  130. -----------------------------------------------------------------------------------------------
  131. -- Cut Grass becomes Hay over time
  132. -----------------------------------------------------------------------------------------------
  133. minetest.register_abm({
  134. nodenames = {"dryplants:grass"},
  135. interval = HAY_DRYING_TIME, --1200, -- 20 minutes: a minetest-day/night-cycle
  136. chance = 1,
  137. action = function(pos)
  138. minetest.swap_node(pos, {name="dryplants:hay"})
  139. end,
  140. })
  141. -----------------------------------------------------------------------------------------------
  142. -- Hay
  143. -----------------------------------------------------------------------------------------------
  144. minetest.register_node("dryplants:hay", {
  145. description = S("Hay"),
  146. inventory_image = "dryplants_hay.png",
  147. wield_image = "dryplants_hay.png",
  148. paramtype = "light",
  149. sunlight_propagates = true,
  150. tiles = {"dryplants_hay.png"},
  151. drawtype = "nodebox",
  152. node_box = {
  153. type = "fixed",
  154. fixed = {-0.5 , -0.5 , -0.5 , 0.5 , -0.4375, 0.5 },
  155. },
  156. groups = {snappy=3, flammable=2},
  157. sounds = default.node_sound_leaves_defaults(),
  158. })
  159. -----------------------------------------------------------------------------------------------
  160. -- Short Grass
  161. -----------------------------------------------------------------------------------------------
  162. minetest.register_node("dryplants:grass_short", {
  163. description = S("Short Grass"),
  164. tiles = {"default_grass.png^dryplants_grass_short.png", "default_dirt.png", "default_dirt.png^default_grass_side.png^dryplants_grass_short_side.png"},
  165. is_ground_content = true,
  166. groups = {crumbly=3,soil=1,not_in_creative_inventory=1},
  167. --drop = 'default:dirt',
  168. sounds = default.node_sound_dirt_defaults({
  169. footstep = {name="default_grass_footstep", gain=0.4},
  170. }),
  171. })
  172. -----------------------------------------------------------------------------------------------
  173. -- Short Grass becomes Dirt with Grass over time
  174. -----------------------------------------------------------------------------------------------
  175. minetest.register_abm({
  176. nodenames = {"dryplants:grass_short"},
  177. interval = GRASS_REGROWING_TIME, --1200, -- 20 minutes: a minetest-day/night-cycle
  178. chance = 100/GRASS_REGROWING_CHANCE,
  179. action = function(pos)
  180. -- Only become dirt with grass if no cut grass or hay lies on top
  181. local above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
  182. if above.name ~= "dryplants:grass" and above.name ~= "dryplants:hay" then
  183. minetest.swap_node(pos, {name="default:dirt_with_grass"})
  184. end
  185. end,
  186. })
  187. -----------------------------------------------------------------------------------------------
  188. print("[Mod] "..title.." ["..version.."] ["..mname.."] Loaded...")
  189. -----------------------------------------------------------------------------------------------