api.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. farming_super.registered_plants = {}
  2. function deepclone(t)
  3. if type(t) ~= "table" then
  4. return t
  5. end
  6. local meta = getmetatable(t)
  7. local target = {}
  8. for k, v in pairs(t) do
  9. if type(v) == "table" then
  10. target[k] = deepclone(v)
  11. else
  12. target[k] = v
  13. end
  14. end
  15. setmetatable(target, meta)
  16. return target
  17. end
  18. -- hoes are defined in farming, no need to override here
  19. local base_speed = 200
  20. -- how often node timers for plants will tick, +/- some random value
  21. local function tick(pos, mul)
  22. local timer = minetest.get_node_timer(pos)
  23. timer:stop()
  24. timer:start(math.random(base_speed * mul, base_speed * mul))
  25. end
  26. -- how often a growth failure tick is retried (e.g. too dark)
  27. local function tick_again(pos, mul)
  28. local timer = minetest.get_node_timer(pos)
  29. timer:stop()
  30. timer:start(math.random(base_speed * mul, base_speed * mul))
  31. end
  32. farming_super.tick_node = tick
  33. -- Seed placement
  34. farming_super.place_seed = function(itemstack, placer, pointed_thing, plantname)
  35. local pt = pointed_thing
  36. -- check if pointing at a node
  37. if not pt then
  38. return itemstack
  39. end
  40. if pt.type ~= "node" then
  41. return itemstack
  42. end
  43. local under = minetest.get_node(pt.under)
  44. local above = minetest.get_node(pt.above)
  45. local player_name = placer and placer:get_player_name() or ""
  46. if minetest.is_protected(pt.under, player_name) then
  47. minetest.record_protection_violation(pt.under, player_name)
  48. return
  49. end
  50. if minetest.is_protected(pt.above, player_name) then
  51. minetest.record_protection_violation(pt.above, player_name)
  52. return
  53. end
  54. -- return if any of the nodes is not registered
  55. if not minetest.registered_nodes[under.name] then
  56. return itemstack
  57. end
  58. if not minetest.registered_nodes[above.name] then
  59. return itemstack
  60. end
  61. -- check if pointing at the top of the node
  62. if pt.above.y ~= pt.under.y+1 then
  63. return itemstack
  64. end
  65. -- check if you can replace the node above the pointed node
  66. if not minetest.registered_nodes[above.name].buildable_to then
  67. return itemstack
  68. end
  69. -- check if pointing at soil
  70. if minetest.get_item_group(under.name, "soil") < 2 then
  71. return itemstack
  72. end
  73. -- add the node and remove 1 item from the itemstack
  74. minetest.add_node(pt.above, {name = plantname, param2 = 1})
  75. tick(pt.above, minetest.registered_nodes[plantname].step_len)
  76. if not (creative and creative.is_enabled_for
  77. and creative.is_enabled_for(player_name)) then
  78. itemstack:take_item()
  79. end
  80. return itemstack
  81. end
  82. local function cut_whole_plant(pos, oldnode, oldmetadata, digger)
  83. local p = {x=pos.x, y=pos.y, z=pos.z}
  84. local old_def = minetest.registered_items[oldnode.name]
  85. local bn = old_def.base_plant
  86. local dinv = digger:get_inventory();
  87. -- go down
  88. while true do
  89. p.y = p.y - 1
  90. local n = minetest.get_node_or_nil(p)
  91. if not n then
  92. break
  93. end
  94. local n_def = minetest.registered_items[n.name]
  95. if not n_def or not n_def.base_plant or n_def.base_plant ~= bn then
  96. break
  97. end
  98. -- dig node
  99. local drops = minetest.get_node_drops(n.name)
  100. for _, stack in ipairs(drops) do
  101. dinv:add_item("main", stack)
  102. end
  103. minetest.set_node(p, {name="air"})
  104. end
  105. -- go up
  106. p = {x=pos.x, y=pos.y, z=pos.z}
  107. while true do
  108. p.y = p.y + 1
  109. local n = minetest.get_node_or_nil(p)
  110. if not n then
  111. break
  112. end
  113. local n_def = minetest.registered_items[n.name]
  114. if not n_def or not n_def.base_plant or n_def.base_plant ~= bn then
  115. break
  116. end
  117. -- dig node
  118. local drops = minetest.get_node_drops(n.name)
  119. for _, stack in ipairs(drops) do
  120. dinv:add_item("main", stack)
  121. end
  122. minetest.set_node(p, {name="air"})
  123. end
  124. end
  125. local function install_plant(def, pos, step)
  126. if not step then
  127. return
  128. end
  129. local bp = def.base_plant
  130. local tc = def.tier_count
  131. local pos2 = {x=pos.x, y=pos.y, z=pos.z}
  132. local nname = def.base_plant .. "_"..step.."_1"
  133. local first_def = minetest.registered_items[nname]
  134. for i = 1,first_def.tier_count do
  135. local name = def.base_plant .. "_"..step.."_"..i
  136. print("node name "..name)
  137. local new_def = minetest.registered_items[name]
  138. local placenode = {name = name}
  139. if new_def.place_param2 then
  140. placenode.param2 = new_def.place_param2
  141. end
  142. minetest.swap_node(pos2, placenode)
  143. pos2.y = pos2.y + 1
  144. end
  145. end
  146. local function get_seed_variant(def, nitro)
  147. if not def.seed_variants then
  148. return def.base_plant
  149. end
  150. for _,v in pairs(def.seed_variants) do
  151. if v.minNitrogen <= nitro and v.maxNitrogen >= nitro then
  152. return v.name
  153. end
  154. end
  155. return def.base_plant
  156. end
  157. farming_super.grow_plant = function(pos, elapsed)
  158. local node = minetest.get_node(pos)
  159. local name = node.name
  160. local def = minetest.registered_nodes[name]
  161. local bp = def.base_plant
  162. local fdef = farming_super.registered_plants[bp]
  163. -- print("base_plant ".. bp)
  164. -- print("next_growth_step ".. (def.next_growth_step or "end"))
  165. local next_step = def.next_growth_step or (fdef.last_step + 1)
  166. -- print(dump(def))
  167. -- print(dump(fdef))
  168. -- print(dump(next_step))
  169. local step_len = fdef.step_len[next_step] or 1
  170. -- check if on wet soil
  171. local below = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
  172. if minetest.get_item_group(below.name, "soil") < 3 then
  173. tick_again(pos, def.step_len)
  174. print("not wet")
  175. return
  176. end
  177. -- check light
  178. local light = minetest.get_node_light(pos)
  179. if not light or light < def.minlight or light > def.maxlight then
  180. tick_again(pos, step_len)
  181. print("too dim ".. light.. ":"..def.minlight..":"..def.maxlight)
  182. return
  183. end
  184. -- print(dump(step_len))
  185. -- print("elapsed "..elapsed)
  186. -- calculate how many steps should have elapsed
  187. while elapsed > step_len * base_speed do
  188. elapsed = elapsed - step_len * base_speed
  189. next_step = next_step + 1
  190. step_len = fdef.step_len[next_step]
  191. if not step_len then
  192. step_len = 1
  193. break
  194. end
  195. if next_step >= fdef.last_step then
  196. break
  197. end
  198. end
  199. -- grow seed
  200. if minetest.get_item_group(node.name, "seed") and def.fertility then
  201. local soil_node = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
  202. if not soil_node then
  203. -- print("no soil")
  204. tick_again(pos, step_len)
  205. return
  206. end
  207. -- omitted is a check for light, we assume seeds can germinate in the dark.
  208. for _, v in pairs(def.fertility) do
  209. -- print("fertility: " ..v)
  210. if minetest.get_item_group(soil_node.name, v) ~= 0 then
  211. local soil_meta = minetest.get_meta({x=pos.x, y=pos.y-1, z=pos.z})
  212. local nlevel = soil_meta:get_int("nitrogen")
  213. if nlevel == 0 then
  214. nlevel = 9
  215. soil_meta:set_int("nitrogen", nlevel)
  216. end
  217. -- print("nlevel: " ..nlevel)
  218. local var_name = get_seed_variant(def, nlevel) .. "_1_1"
  219. local var_def = minetest.registered_items[var_name]
  220. if var_name == "death" or var_def == nil then
  221. minetest.set_node(pos, {name="air"})
  222. return
  223. end
  224. install_plant(var_def, pos, math.min(next_step, fdef.last_step))
  225. if var_def.groups.use_nitrogen then
  226. soil_meta:set_int("nitrogen", math.max(1, nlevel - var_def.groups.use_nitrogen))
  227. -- print("new nlevel: " ..nlevel - (var_def.groups.use_nitrogen or 0))
  228. end
  229. --[[local placenode = {name = def.base_plant .. "_1_1"}
  230. if def.place_param2 then
  231. placenode.param2 = def.place_param2
  232. end
  233. ]] -- minetest.swap_node(pos, placenode)
  234. -- if minetest.registered_nodes[def.base_plant .. "_1_1"].next_plant then
  235. tick(pos, step_len)
  236. return
  237. -- return
  238. -- end
  239. end
  240. end
  241. return
  242. end
  243. -- grow
  244. install_plant(def, pos, math.min(next_step, fdef.last_step))
  245. -- new timer needed?
  246. if next_step < fdef.last_step then
  247. tick(pos, step_len)
  248. else -- end of growth, give nutrients
  249. local soil_meta = minetest.get_meta({x = pos.x, y = pos.y - 1, z = pos.z})
  250. if def.groups.fix_nitrogen then
  251. local nlevel = soil_meta:get_int("nitrogen")
  252. soil_meta:set_int("nitrogen", math.min(16, nlevel + def.groups.fix_nitrogen))
  253. end
  254. end
  255. return
  256. end
  257. -- Register plants
  258. farming_super.register_plant = function(name, def)
  259. local mname = name:split(":")[1]
  260. local pname = name:split(":")[2]
  261. local def_drops = def.drops or {}
  262. -- Check def table
  263. if not def.description then
  264. def.description = "Seed"
  265. end
  266. if not def.inventory_image then
  267. def.inventory_image = "unknown_item.png"
  268. end
  269. if not def.steps then
  270. return nil
  271. end
  272. if type(def.steps) == "number" then
  273. def.steps = {def.steps}
  274. end
  275. if not def.minlight then
  276. def.minlight = 1
  277. end
  278. if not def.maxlight then
  279. def.maxlight = 14
  280. end
  281. if not def.fertility then
  282. def.fertility = {}
  283. end
  284. if def.place_param2 == "plus" then
  285. def.place_param2 = 1
  286. elseif def.place_param2 == "hex" then
  287. def.place_param2 = 2
  288. elseif def.place_param2 == "hatch" or def.place_param2 == "#" then
  289. def.place_param2 = 3 -- the shape of #
  290. elseif def.place_param2 == "V" or def.place_param2 == "v" then
  291. def.place_param2 = 4 -- used by dry_shrub
  292. elseif def.place_param2 == "X" or def.place_param2 == "x" then
  293. def.place_param2 = 0 -- regular plants
  294. end
  295. local base_plant = mname .. ":" .. pname
  296. def.step_len = def.step_len or {}
  297. def.step_len[1] = def.step_len[1] or 1
  298. -- Register seed -- attached node needs not be on 2nd tier nodes
  299. local g = {seed = 1, snappy = 3, attached_node = 1, flammable = 2}
  300. local g2 = {seed = 1, snappy = 3, flammable = 2}
  301. for k, v in pairs(def.fertility) do
  302. g[v] = 1
  303. g2[v] = 1
  304. end
  305. for k, v in pairs(def.groups) do
  306. g[k] = v
  307. g2[k] = v
  308. end
  309. if not def.no_seed then
  310. minetest.register_node(":" .. mname .. ":seed_" .. pname, {
  311. description = def.description,
  312. tiles = {def.inventory_image},
  313. inventory_image = def.inventory_image,
  314. wield_image = def.inventory_image,
  315. drawtype = "signlike",
  316. groups = g,
  317. paramtype = "light",
  318. paramtype2 = "wallmounted",
  319. walkable = false,
  320. place_param2 = def.place_param2 or nil, -- this isn't actually used for placement
  321. --walkable = false,
  322. sunlight_propagates = true,
  323. selection_box = {
  324. type = "fixed",
  325. fixed = {-0.5, -0.5, -0.5, 0.5, -0.375, 0.5},
  326. },
  327. fertility = def.fertility,
  328. sounds = default.node_sound_dirt_defaults({
  329. dig = {name = "", gain = 0},
  330. dug = {name = "default_grass_footstep", gain = 0.2},
  331. place = {name = "default_place_node", gain = 0.25},
  332. }),
  333. base_plant = base_plant,
  334. next_growth_step = 1,
  335. tier_count = 1,
  336. step_len = def.step_len[1],
  337. groups = g,
  338. on_place = function(itemstack, placer, pointed_thing)
  339. local under = pointed_thing.under
  340. local node = minetest.get_node(under)
  341. local udef = minetest.registered_nodes[node.name]
  342. if udef and udef.on_rightclick and
  343. not (placer and placer:is_player() and
  344. placer:get_player_control().sneak) then
  345. return udef.on_rightclick(under, node, placer, itemstack,
  346. pointed_thing) or itemstack
  347. end
  348. return farming_super.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname)
  349. end,
  350. --next_plant = mname .. ":" .. pname .. "_1",
  351. on_timer = farming_super.grow_plant,
  352. minlight = def.minlight,
  353. maxlight = def.maxlight,
  354. seed_variants = def.seed_variants,
  355. })
  356. end
  357. if not def.no_harvest then
  358. -- Register harvest
  359. local h_def = {
  360. description = pname:gsub("^%l", string.upper),
  361. inventory_image = mname .. "_" .. pname .. ".png",
  362. groups = {flammable = 2},
  363. }
  364. if def.eat_value ~= nil then
  365. h_def.on_use = minetest.item_eat(def.eat_value)
  366. end
  367. minetest.register_craftitem(":" .. mname .. ":" .. pname, h_def)
  368. end
  369. local next_node = {
  370. [mname .. ":seed_" .. pname] = mname .. ":" .. pname .. "_1_1"
  371. }
  372. local stack_height = {
  373. [mname .. ":seed_" .. pname] = 1
  374. }
  375. local last = nil
  376. local name
  377. local totalSteps = 0
  378. for _,numSteps in ipairs(def.steps) do
  379. totalSteps = totalSteps + numSteps
  380. end
  381. def.last_step = totalSteps
  382. -- print("total steps " .. totalSteps)
  383. local tex_base = mname.."_"..pname
  384. if def.textures and def.textures.base then
  385. tex_base = def.textures.base
  386. end
  387. local step = 1
  388. for tierCount,numSteps in ipairs(def.steps) do
  389. for tierStep = 1,numSteps do
  390. local ns = step + 1
  391. if step == totalSteps then
  392. ns = nil
  393. end
  394. for tier = 1,tierCount do
  395. name = mname .. ":" .. pname .. "_"..step.."_"..tier
  396. local dropname = "p"..tierCount.."s"..tierStep.."t"..tier
  397. local drops = def_drops[dropname] or def.default_drop
  398. local tex = (def.textures and def.textures[dropname]) or (tex_base.."_"..tierCount.."_"..tierStep.."_"..tier..".png")
  399. local gg = g2
  400. if tier == 1 then
  401. gg = g
  402. end
  403. local height = -0.4
  404. if tierCount > 1 and tier < tierCount then
  405. height = 0.5
  406. end
  407. def.step_len[step+1] = def.step_len[step+1] or 1
  408. local sbox = {
  409. type = "fixed",
  410. fixed = {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5},
  411. }
  412. if tierCount > 1 then
  413. sbox = {
  414. type = "fixed",
  415. fixed = {-5 / 16, -0.5, -5 / 16, 5 / 16, height, 5 / 16},
  416. }
  417. end
  418. --print(name.."-> ".. tier .. " / "..tierCount .. " " ..height)
  419. minetest.register_node(name, {
  420. drawtype = "plantlike",
  421. waving = 0,
  422. tiles = {tex},
  423. use_texture_alpha = "clip",
  424. paramtype = "light",
  425. paramtype2 = def.paramtype2 or nil,
  426. place_param2 = def.place_param2 or nil,
  427. walkable = false,
  428. buildable_to = true,
  429. sunlight_propagates = true,
  430. drop = drops,
  431. selection_box = sbox,
  432. groups = gg,
  433. sounds = default.node_sound_leaves_defaults(),
  434. next_growth_step = ns,
  435. tier_count = tierCount,
  436. base_plant = base_plant,
  437. step_len = def.step_len[step+1],
  438. on_timer = farming_super.grow_plant,
  439. minlight = def.minlight,
  440. maxlight = def.maxlight,
  441. -- todo: ondestruct
  442. after_dig_node = cut_whole_plant,
  443. })
  444. --[[
  445. if minetest.global_exists("seasons") then
  446. seasons.reg_custom("fall", name, dead_vine_name)
  447. seasons.reg_custom("winter", vine_name, "air")
  448. end
  449. ]]
  450. if last then
  451. next_node[last] = name
  452. stack_height[last] = step
  453. end
  454. last = name
  455. end
  456. step = step + 1
  457. end
  458. end
  459. def.next_node = next_node
  460. def.stack_height = stack_height
  461. -- print("def name "..pname)
  462. farming_super.registered_plants[base_plant] = def
  463. --[[
  464. for i = 1, 5 do
  465. minetest.override_item("default:grass_"..i, {drop = {
  466. max_items = 1,
  467. items = {
  468. {items = {'farming:seed_wheat'},rarity = 5},
  469. {items = {'default:grass_1'}},
  470. }
  471. }})
  472. end
  473. ]]
  474. if not def.no_seed then
  475. local old_grass_drops = deepclone(minetest.registered_items["default:junglegrass"].drop)
  476. -- print('+++++++++++++++++++++++++++++++++++++++++++')
  477. table.insert(old_grass_drops.items, 1, {items={mname .. ":seed_" .. pname}, rarity=2})
  478. table.sort(old_grass_drops.items, function(a, b) return (b.rarity or 0) < (a.rarity or 0) end)
  479. minetest.override_item("default:junglegrass", {drop = old_grass_drops})
  480. -- print(dump(minetest.registered_items["default:junglegrass"]))
  481. end
  482. -- minetest.override_item("default:junglegrass", {drop = old_grass_drops})
  483. --
  484. -- minetest.override_item("default:junglegrass", {drop = {
  485. -- max_items = 1,
  486. -- items = {
  487. -- {items = {mname .. ":seed_" .. pname}},
  488. -- -- {items = {'default:junglegrass'}},
  489. -- }
  490. -- }})
  491. --
  492. --[[
  493. -- Register growing steps
  494. for i = 1, def.steps do
  495. local base_rarity = 1
  496. if def.steps ~= 1 then
  497. base_rarity = 8 - (i - 1) * 7 / (def.steps - 1)
  498. end
  499. local drop = {
  500. items = {
  501. {items = {mname .. ":" .. pname}, rarity = base_rarity},
  502. {items = {mname .. ":" .. pname}, rarity = base_rarity * 2},
  503. {items = {mname .. ":seed_" .. pname}, rarity = base_rarity},
  504. {items = {mname .. ":seed_" .. pname}, rarity = base_rarity * 2},
  505. }
  506. }
  507. local nodegroups = {snappy = 3, flammable = 2, plant = 1, not_in_creative_inventory = 1, attached_node = 1}
  508. nodegroups[pname] = i
  509. local next_plant = nil
  510. if i lt def.steps then
  511. next_plant = mname .. ":" .. pname .. "_" .. (i + 1)
  512. lbm_nodes[#lbm_nodes + 1] = mname .. ":" .. pname .. "_" .. i
  513. end
  514. minetest.register_node(":" .. mname .. ":" .. pname .. "_" .. i, {
  515. drawtype = "plantlike",
  516. waving = 1,
  517. tiles = {mname .. "_" .. pname .. "_" .. i .. ".png"},
  518. paramtype = "light",
  519. paramtype2 = def.paramtype2 or nil,
  520. place_param2 = def.place_param2 or nil,
  521. walkable = false,
  522. buildable_to = true,
  523. drop = drop,
  524. selection_box = {
  525. type = "fixed",
  526. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
  527. },
  528. groups = nodegroups,
  529. sounds = default.node_sound_leaves_defaults(),
  530. next_plant = next_plant,
  531. on_timer = farming_super.grow_plant,
  532. minlight = def.minlight,
  533. maxlight = def.maxlight,
  534. })
  535. end
  536. ]]
  537. -- replacement LBM for pre-nodetimer plants
  538. minetest.register_lbm({
  539. name = ":" .. mname .. ":start_nodetimer_" .. pname,
  540. nodenames = lbm_nodes,
  541. action = function(pos, node)
  542. tick_again(pos)
  543. end,
  544. })
  545. -- Return
  546. local r = {
  547. seed = mname .. ":seed_" .. pname,
  548. harvest = mname .. ":" .. pname
  549. }
  550. return r
  551. end
  552. -- plants with hardware above ground, like tomatoes
  553. farming_super.register_rooted_plant = function(name, def)
  554. local mname = name:split(":")[1]
  555. local pname = name:split(":")[2]
  556. local def_drops = def.drops or {}
  557. -- Check def table
  558. if not def.description then
  559. def.description = "Seed"
  560. end
  561. if not def.inventory_image then
  562. def.inventory_image = "unknown_item.png"
  563. end
  564. if not def.steps then
  565. return nil
  566. end
  567. if type(def.steps) == "number" then
  568. def.steps = {def.steps}
  569. end
  570. if not def.minlight then
  571. def.minlight = 1
  572. end
  573. if not def.maxlight then
  574. def.maxlight = 14
  575. end
  576. if not def.fertility then
  577. def.fertility = {}
  578. end
  579. if def.place_param2 == "plus" then
  580. def.place_param2 = 1
  581. elseif def.place_param2 == "hex" then
  582. def.place_param2 = 2
  583. elseif def.place_param2 == "hatch" or def.place_param2 == "#" then
  584. def.place_param2 = 3 -- the shape of #
  585. elseif def.place_param2 == "V" or def.place_param2 == "v" then
  586. def.place_param2 = 4 -- used by dry_shrub
  587. elseif def.place_param2 == "X" or def.place_param2 == "x" then
  588. def.place_param2 = 0 -- regular plants
  589. end
  590. local base_plant = mname .. ":" .. pname
  591. def.step_len = def.step_len or {}
  592. def.step_len[1] = def.step_len[1] or 1
  593. -- Register seed -- attached node needs not be on 2nd tier nodes
  594. local g = {seed = 1, snappy = 3, attached_node = 1, flammable = 2}
  595. local g2 = {seed = 1, snappy = 3, flammable = 2}
  596. for k, v in pairs(def.fertility) do
  597. g[v] = 1
  598. g2[v] = 1
  599. end
  600. for k, v in pairs(def.groups) do
  601. g[k] = v
  602. g2[k] = v
  603. end
  604. if not def.no_harvest then
  605. -- Register harvest
  606. local h_def = {
  607. description = pname:gsub("^%l", string.upper),
  608. inventory_image = mname .. "_" .. pname .. ".png",
  609. groups = {flammable = 2},
  610. }
  611. if def.eat_value ~= nil then
  612. h_def.on_use = minetest.item_eat(def.eat_value)
  613. end
  614. minetest.register_craftitem(":" .. mname .. ":" .. pname, h_def)
  615. end
  616. local next_node = {
  617. [mname .. ":seed_" .. pname] = mname .. ":" .. pname .. "_1_1"
  618. }
  619. local stack_height = {
  620. [mname .. ":seed_" .. pname] = 1
  621. }
  622. local last = nil
  623. local totalSteps = 0
  624. for _,numSteps in ipairs(def.steps) do
  625. totalSteps = totalSteps + numSteps
  626. end
  627. def.last_step = totalSteps
  628. -- print("total steps " .. totalSteps)
  629. local tex_base = mname.."_"..pname
  630. if def.textures and def.textures.base then
  631. tex_base = def.textures.base
  632. end
  633. local name = mname .. ":" .. pname .. "_"..step.."_"..tier
  634. local dropname = "p"..tierCount.."s"..tierStep.."t"..tier
  635. local drops = def_drops[dropname] or def.default_drop
  636. local tex = (def.textures and def.textures[dropname]) or (tex_base.."_"..tierCount.."_"..tierStep.."_"..tier..".png")
  637. local gg = g2
  638. if tier == 1 then
  639. gg = g
  640. end
  641. local height = -0.4
  642. if tierCount > 1 and tier < tierCount then
  643. height = 0.5
  644. end
  645. def.step_len[step+1] = def.step_len[step+1] or 1
  646. local sbox = {
  647. type = "fixed",
  648. fixed = {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5},
  649. }
  650. if tierCount > 1 then
  651. sbox = {
  652. type = "fixed",
  653. fixed = {-5 / 16, -0.5, -5 / 16, 5 / 16, height, 5 / 16},
  654. }
  655. end
  656. minetest.register_node(name, {
  657. description = "Hops Plant",
  658. drawtype = "plantlike_rooted",
  659. -- waving = 1,
  660. tiles = {"default_dirt.png^farming_soil_wet.png", "default_dirt.png^farming_soil_wet_side.png"},
  661. drop = "default:dirt",
  662. special_tiles = {{name = "farming_super_hops_vine.png", tileable_vertical = true}},
  663. inventory_image = "farming_super_hops_vine.png",
  664. paramtype = "light",
  665. paramtype2 = "leveled",
  666. place_param2 = 1,
  667. groups = {snappy = 3},
  668. visual_scale = 1.5,
  669. selection_box = {
  670. type = "fixed",
  671. fixed = {
  672. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  673. {-2/16, 0.5, -2/16, 2/16, 3.5, 2/16},
  674. },
  675. },
  676. node_dig_prediction = "default:sand",
  677. node_placement_prediction = "",
  678. sounds = default.node_sound_sand_defaults({
  679. dig = {name = "default_dig_snappy", gain = 0.2},
  680. dug = {name = "default_grass_footstep", gain = 0.25},
  681. }),
  682. after_destruct = function(pos, oldnode)
  683. local n = minetest.get_node(pos)
  684. -- if n.name == "farming_super:hops_vine_fruit" then
  685. -- minetest.set_node(pos, {name = "farming_super:hops_vine", param2 = oldnode.param2})
  686. if n.name ~= "farming_super:hops_vine_fruit" then
  687. minetest.set_node(pos, {name = "farming:soil_wet"})
  688. end
  689. end,
  690. })
  691. def.next_node = next_node
  692. -- print("def name "..pname)
  693. farming_super.registered_plants[base_plant] = def
  694. if not def.no_seed then
  695. local old_grass_drops = deepclone(minetest.registered_items["default:junglegrass"].drop)
  696. -- print('+++++++++++++++++++++++++++++++++++++++++++')
  697. table.insert(old_grass_drops.items, 1, {items={mname .. ":seed_" .. pname}, rarity=2})
  698. table.sort(old_grass_drops.items, function(a, b) return (b.rarity or 0) < (a.rarity or 0) end)
  699. minetest.override_item("default:junglegrass", {drop = old_grass_drops})
  700. -- print(dump(minetest.registered_items["default:junglegrass"]))
  701. end
  702. -- Return
  703. local r = {
  704. seed = mname .. ":seed_" .. pname,
  705. harvest = mname .. ":" .. pname
  706. }
  707. return r
  708. end