1
0
Fork 0

Auto-connect stem after stem construction

This commit is contained in:
Wuzzy 2017-03-14 04:17:35 +01:00
parent db123b3d16
commit 36e6c78eeb
3 changed files with 59 additions and 43 deletions

View File

@ -35,7 +35,7 @@ local melon_base_def = {
} }
-- Drop proabilities for melon stem -- Drop proabilities for melon stem
local stemdrop = { local stem_drop = {
max_items = 1, max_items = 1,
-- FIXME: The probabilities are slightly off from the original. -- FIXME: The probabilities are slightly off from the original.
-- Update this drop list when the Minetest drop probability system -- Update this drop list when the Minetest drop probability system
@ -64,7 +64,7 @@ for s=1,7 do
walkable = false, walkable = false,
drawtype = "plantlike", drawtype = "plantlike",
sunlight_propagates = true, sunlight_propagates = true,
drop = stemdrop, drop = stem_drop,
tiles = {"mcl_farming_melontige_"..s..".png"}, tiles = {"mcl_farming_melontige_"..s..".png"},
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -79,31 +79,17 @@ for s=1,7 do
end end
-- Full melon stem, able to spawn melons -- Full melon stem, able to spawn melons
minetest.register_node("mcl_farming:melontige_unconnect", { local stem_def = {
description = "Mature Melon Stem", description = "Mature Melon Stem",
_doc_items_create_entry = false, _doc_items_create_entry = false,
paramtype = "light",
walkable = false,
sunlight_propagates = true,
drop = stemdrop,
drawtype = "plantlike",
tiles = {"mcl_farming_melontige_8.png"}, 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 -- 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) 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 -- 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 -- Items and crafting
minetest.register_craftitem("mcl_farming:melon_item", { minetest.register_craftitem("mcl_farming:melon_item", {

View File

@ -11,7 +11,7 @@ minetest.register_craftitem("mcl_farming:pumpkin_seeds", {
end end
}) })
local stemdrop = { local stem_drop = {
max_items = 1, max_items = 1,
-- FIXME: The probabilities are slightly off from the original. -- FIXME: The probabilities are slightly off from the original.
-- Update this drop list when the Minetest drop probability system -- Update this drop list when the Minetest drop probability system
@ -41,7 +41,7 @@ for s=1,7 do
walkable = false, walkable = false,
drawtype = "plantlike", drawtype = "plantlike",
sunlight_propagates = true, sunlight_propagates = true,
drop = stemdrop, drop = stem_drop,
tiles = {"mcl_farming_pumpkintige_"..s..".png"}, tiles = {"mcl_farming_pumpkintige_"..s..".png"},
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -56,25 +56,11 @@ for s=1,7 do
end end
-- Full stem (not connected) -- Full stem (not connected)
minetest.register_node("mcl_farming:pumpkintige_unconnect", { local stem_def = {
description = "Mature Pumpkin Stem", description = "Mature Pumpkin Stem",
_doc_items_create_entry = false, _doc_items_create_entry = false,
paramtype = "light",
walkable = false,
sunlight_propagates = true,
drop = stemdrop,
drawtype = "plantlike",
tiles = {"mcl_farming_pumpkintige_8.png"}, 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 -- Template for pumpkin
local pumpkin_base_def = { 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) 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 -- 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)

View File

@ -74,14 +74,16 @@ end
- full_unconnected_stem: itemstring of the full-grown but unconnceted stem node. This node must already be done - 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 - 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_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 - 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_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 - 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 = { local connected_stem_names = {
connected_stem_basename .. "_r", 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 }, { 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 try_connect_stem = function(stempos)
local stem = minetest.get_node(stempos) local stem = minetest.get_node(stempos)
if stem.name ~= full_unconnected_stem then 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 -- Connect all unconnected stems at full size
for n=1, #neighbors do for n=1, #neighbors do
local stempos = vector.add(blockpos, neighbors[n]) local stempos = vector.add(blockpos, neighbors[n])
connect_stem(stempos) try_connect_stem(stempos)
end end
end end
end end
minetest.register_node(gourd_itemstring, gourd_def) 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 -- Register connected stems
local connected_stem_tiles = { local connected_stem_tiles = {
@ -200,7 +244,7 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
walkable = false, walkable = false,
drop = stemdrop, drop = stem_drop,
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
node_box = { node_box = {