diff --git a/mods/ITEMS/mcl_farming/melon.lua b/mods/ITEMS/mcl_farming/melon.lua index 9087d7b8ce..61d6b98cdc 100644 --- a/mods/ITEMS/mcl_farming/melon.lua +++ b/mods/ITEMS/mcl_farming/melon.lua @@ -35,7 +35,7 @@ local melon_base_def = { } -- Drop proabilities for melon stem -local stemdrop = { +local stem_drop = { max_items = 1, -- FIXME: The probabilities are slightly off from the original. -- Update this drop list when the Minetest drop probability system @@ -64,7 +64,7 @@ for s=1,7 do walkable = false, drawtype = "plantlike", sunlight_propagates = true, - drop = stemdrop, + drop = stem_drop, tiles = {"mcl_farming_melontige_"..s..".png"}, selection_box = { type = "fixed", @@ -79,31 +79,17 @@ for s=1,7 do end -- Full melon stem, able to spawn melons -minetest.register_node("mcl_farming:melontige_unconnect", { +local stem_def = { description = "Mature Melon Stem", _doc_items_create_entry = false, - paramtype = "light", - walkable = false, - sunlight_propagates = true, - drop = stemdrop, - drawtype = "plantlike", tiles = {"mcl_farming_melontige_8.png"}, - selection_box = { - type = "fixed", - fixed = { - {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15} - }, - }, - groups = {dig_immediate=3, not_in_creative_inventory=1, attached_node=1, dig_by_water=1}, - sounds = mcl_sounds.node_sound_leaves_defaults(), - _mcl_blast_resistance = 0, -}) +} -- Register stem growth mcl_farming:add_plant("mcl_farming:melontige_unconnect", {"mcl_farming:melontige_1", "mcl_farming:melontige_2", "mcl_farming:melontige_3", "mcl_farming:melontige_4", "mcl_farming:melontige_5", "mcl_farming:melontige_6", "mcl_farming:melontige_7"}, 50, 20) -- Register actual melon, connected stems and stem-to-melon growth -mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", stemdrop, "mcl_farming:melon", melon_base_def, 25, 15) +mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", "mcl_farming:melontige_unconnect", stem_def, stemdrop, "mcl_farming:melon", melon_base_def, 25, 15) -- Items and crafting minetest.register_craftitem("mcl_farming:melon_item", { diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index 64b77ab9a6..2d253b2466 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -11,7 +11,7 @@ minetest.register_craftitem("mcl_farming:pumpkin_seeds", { end }) -local stemdrop = { +local stem_drop = { max_items = 1, -- FIXME: The probabilities are slightly off from the original. -- Update this drop list when the Minetest drop probability system @@ -41,7 +41,7 @@ for s=1,7 do walkable = false, drawtype = "plantlike", sunlight_propagates = true, - drop = stemdrop, + drop = stem_drop, tiles = {"mcl_farming_pumpkintige_"..s..".png"}, selection_box = { type = "fixed", @@ -56,25 +56,11 @@ for s=1,7 do end -- Full stem (not connected) -minetest.register_node("mcl_farming:pumpkintige_unconnect", { +local stem_def = { description = "Mature Pumpkin Stem", _doc_items_create_entry = false, - paramtype = "light", - walkable = false, - sunlight_propagates = true, - drop = stemdrop, - drawtype = "plantlike", tiles = {"mcl_farming_pumpkintige_8.png"}, - selection_box = { - type = "fixed", - fixed = { - {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15} - }, - }, - groups = {dig_immediate=3, not_in_creative_inventory=1, attached_node=1, dig_by_water=1}, - sounds = mcl_sounds.node_sound_leaves_defaults(), - _mcl_blast_resistance = 0, -}) +} -- Template for pumpkin local pumpkin_base_def = { @@ -93,7 +79,7 @@ local pumpkin_base_def = { mcl_farming:add_plant("mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 80, 20) -- Register actual pumpkin, connected stems and stem-to-pumpkin growth -mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", stemdrop, "mcl_farming:pumpkin_face", pumpkin_base_def, 30, 15) +mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", "mcl_farming:pumpkintige_unconnect", stem_def, stem_drop, "mcl_farming:pumpkin_face", pumpkin_base_def, 30, 15) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index c6334226da..3f4f01a29f 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -74,14 +74,16 @@ end - full_unconnected_stem: itemstring of the full-grown but unconnceted stem node. This node must already be done - connected_stem_basename: prefix of the itemstrings used for the 4 connected stem nodes to create -- stemdrop: Drop probability table for all stem +- stem_itemstring: Desired itemstring of the fully-grown unconnected stem node +- stem_def: Partial node definition of the fully-grown unconnected stem node. Many fields are already defined. You need to add `tiles` and `description` at minimum. Don't define on_construct without good reason +- stem_drop: Drop probability table for all stem - gourd_itemstring: Desired itemstring of the full gourd node - gourd_def: (almost) full definition of the gourd node. This function will add after_dig_node to the definition for unconnecting any connected stems - grow_interval: Will attempt to grow a gourd periodically at this interval in seconds - grow_chance: Chance of 1/grow_chance to grow a gourd next to the full unconnected stem after grow_interval has passed. Must be a natural number ]] -function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, stemdrop, gourd_itemstring, gourd_def, grow_interval, grow_chance) +function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, stem_itemstring, stem_def, stem_drop, gourd_itemstring, gourd_def, grow_interval, grow_chance) local connected_stem_names = { connected_stem_basename .. "_r", @@ -97,7 +99,8 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s { x=0, y=0, z=1 }, } - -- Connect a stem to the first neighboring gourd block + -- Connect the stem at stempos to the first neighboring gourd block. + -- No-op if not a stem or no gourd block found local try_connect_stem = function(stempos) local stem = minetest.get_node(stempos) if stem.name ~= full_unconnected_stem then @@ -143,12 +146,53 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s -- Connect all unconnected stems at full size for n=1, #neighbors do local stempos = vector.add(blockpos, neighbors[n]) - connect_stem(stempos) + try_connect_stem(stempos) end end end minetest.register_node(gourd_itemstring, gourd_def) + -- Register unconnected stem + + -- Default values for the stem definition + if not stem_def.selection_box then + stem_def.selection_box = { + type = "fixed", + fixed = { + {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15} + }, + } + end + if not stem_def.paramtype then + stem_def.paramtype = "light" + end + if not stem_def.drawtype then + stem_def.drawtype = "plantlike" + end + if stem_def.walkable == nil then + stem_def.walkable = false + end + if stem_def.sunlight_propagates == nil then + stem_def.sunlight_propagates = true + end + if stem_def.drop == nil then + stem_def.drop = stem_drop + end + if stem_def.groups == nil then + stem_def.groups = {dig_immediate=3, not_in_creative_inventory=1, attached_node=1, dig_by_water=1} + end + if stem_def.sounds == nil then + stem_def.sounds = mcl_sounds.node_sound_leaves_defaults() + end + + if not stem_def.on_construct then + stem_def.on_construct = function(stempos) + -- Connect stem to gourd (if possible) + try_connect_stem(stempos) + end + end + minetest.register_node(stem_itemstring, stem_def) + -- Register connected stems local connected_stem_tiles = { @@ -200,7 +244,7 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s paramtype = "light", sunlight_propagates = true, walkable = false, - drop = stemdrop, + drop = stem_drop, drawtype = "nodebox", paramtype = "light", node_box = {