From e20268de06b114cf0c5730211a9f48ecb51ea197 Mon Sep 17 00:00:00 2001 From: Aleksey Chubukov Date: Sat, 18 Mar 2023 23:52:22 +0300 Subject: [PATCH] day 03-19: refactor tree registration * refactored tree registration * renamed textures so they can be used in loops --- mods/ebiome/biomes/grasslands.lua | 73 +--------- .../ebiome_oak_trunk_growing_corner.png | Bin 0 -> 929 bytes .../ebiome_oak_trunk_growing_normal.png | Bin 0 -> 841 bytes .../ebiome_oak_trunk_growing_slice.png | Bin 0 -> 745 bytes ... => ebiome_oak_trunk_growing_terminal.png} | Bin .../ebiome_oak_trunk_growing_tjunction.png | Bin 0 -> 918 bytes .../ebiome_oak_trunk_growing_xjunction.png | Bin 0 -> 952 bytes ...png => ebiome_oak_trunk_normal_corner.png} | Bin ...png => ebiome_oak_trunk_normal_normal.png} | Bin ....png => ebiome_oak_trunk_normal_slice.png} | Bin .../ebiome_oak_trunk_normal_terminal.png | Bin 0 -> 753 bytes .../ebiome_oak_trunk_normal_tjunction.png | Bin 0 -> 797 bytes .../ebiome_oak_trunk_normal_xjunction.png | Bin 0 -> 847 bytes mods/ebiometrees/init.lua | 1 + mods/ebiometrees/tree.lua | 128 ++++++++++++++++++ 15 files changed, 133 insertions(+), 69 deletions(-) create mode 100644 mods/ebiome/textures/ebiome_oak_trunk_growing_corner.png create mode 100644 mods/ebiome/textures/ebiome_oak_trunk_growing_normal.png create mode 100644 mods/ebiome/textures/ebiome_oak_trunk_growing_slice.png rename mods/ebiome/textures/{ebiome_oak_trunk_growing.png => ebiome_oak_trunk_growing_terminal.png} (100%) create mode 100644 mods/ebiome/textures/ebiome_oak_trunk_growing_tjunction.png create mode 100644 mods/ebiome/textures/ebiome_oak_trunk_growing_xjunction.png rename mods/ebiome/textures/{ebiome_oak_trunk_corner_normal.png => ebiome_oak_trunk_normal_corner.png} (100%) rename mods/ebiome/textures/{ebiome_oak_trunk_normal.png => ebiome_oak_trunk_normal_normal.png} (100%) rename mods/ebiome/textures/{ebiome_oak_trunk_slice_normal.png => ebiome_oak_trunk_normal_slice.png} (100%) create mode 100644 mods/ebiome/textures/ebiome_oak_trunk_normal_terminal.png create mode 100644 mods/ebiome/textures/ebiome_oak_trunk_normal_tjunction.png create mode 100644 mods/ebiome/textures/ebiome_oak_trunk_normal_xjunction.png create mode 100644 mods/ebiometrees/tree.lua diff --git a/mods/ebiome/biomes/grasslands.lua b/mods/ebiome/biomes/grasslands.lua index 6b9d83c..b3b9f59 100644 --- a/mods/ebiome/biomes/grasslands.lua +++ b/mods/ebiome/biomes/grasslands.lua @@ -1,4 +1,4 @@ -local S = minetest.get_translator("eterrain") +local S = minetest.get_translator("ebiome") minetest.register_biome({ name = "grasslands", node_top = "mapgen_topsoil", @@ -10,74 +10,9 @@ minetest.register_biome({ heat_point = 50, humidity_point = 50, }) -minetest.register_node("ebiome:oak_sapling", { - description = S("Oak tree sapling"), - drawtype = "plantlike", - tiles = { "ebiome_oak_sapling.png" }, - paramtype = "light", - on_timer = ebiometrees.get_sapling_grower("ebiome:oak_sprout"), - sunlight_propagates = true, - walkable = false, - groups = {snappy = 2, dig_immediate = 3, flammable = 2, - attached_node = 1, sapling = 1}, - on_construct = function(pos) - minetest.get_node_timer(pos):start(3) - end -}) -minetest.register_node("ebiome:oak_sprout", { - description = S("Oak tree sprout"), - drawtype = "plantlike", - visual_scale = 1.4, - tiles = { "ebiome_oak_sprout.png" }, - paramtype = "light", - sunlight_propagates = true, - walkable = false, - on_timer = ebiometrees.get_sprout_grower("ebiome:oak_trunk_normal", "ebiome:oak_trunk_growing"), - groups = {snappy = 3, dig_immediate = 3, flammable = 2, - attached_node = 1}, - on_construct = function(pos) - minetest.get_node_timer(pos):start(3) - end -}) -minetest.register_node("ebiome:oak_trunk_growing", { - description = S("Oak tree trunk"), - tiles = { "ebiome_oak_trunk_growing.png", - "ebiome_oak_trunk_slice_normal.png", - "ebiome_oak_trunk_growing.png" - }, - paramtype2 = "facedir", - is_ground_content = false, - groups = {tree = 1, choppy = 2, flammable = 2}, - on_place = minetest.rotate_node, - on_timer = function(pos) - return true - end, - on_construct = function(pos) - minetest.get_node_timer(pos):start(3) - end -}) -minetest.register_node("ebiome:oak_trunk_normal", { - description = S("Oak tree trunk"), - tiles = { "ebiome_oak_trunk_slice_normal.png", "ebiome_oak_trunk_slice_normal.png","ebiome_oak_trunk_normal.png"}, - paramtype2 = "facedir", - is_ground_content = false, - groups = {tree = 1, choppy = 2, flammable = 2}, - on_place = minetest.rotate_node -}) -minetest.register_node("ebiome:oak_trunk_normal_corner", { - description = S("Oak tree trunk corner branch"), - tiles = { - "ebiome_oak_trunk_normal.png", - "ebiome_oak_trunk_slice_normal.png", - "ebiome_oak_trunk_corner_normal.png^[transformFX", - "ebiome_oak_trunk_corner_normal.png", - "ebiome_oak_trunk_normal.png", - "ebiome_oak_trunk_slice_normal.png", - }, - paramtype2 = "facedir", - is_ground_content = false, - groups = {tree = 1, choppy = 2, flammable = 2}, - on_place = minetest.rotate_node +ebiometrees.register_tree("ebiome", "oak",{ + description = "Oak", + groups = {flammable = 2} }) minetest.register_node("ebiome:grass", { description = S("Grass"), diff --git a/mods/ebiome/textures/ebiome_oak_trunk_growing_corner.png b/mods/ebiome/textures/ebiome_oak_trunk_growing_corner.png new file mode 100644 index 0000000000000000000000000000000000000000..5977d695feae89784f9de0d9217816da672fa084 GIT binary patch literal 929 zcmV;S177@zP)zct%FMusTHicq_Js*K0=Zr#Z_=|C^(2N zz6SpTT?JPKK~Mw{H+Nr)NIbVKv`Bly&H3@&`yEccfH$1hGj`K7WU`JGnF|G$V=Dpw z8$P<|W(vQi+vd!|LYRi@`vH%t_amxT<9l^i+j_#*!P6o{j0Rx~mTUez;@tl@YK>nSTEJR}^Ge6Br=x|b1rK_ckPray>r81uO^)J2Oh8*$_9~~Z0v#Z=_M*)V-;MePN z@)q#TEzrK^8IJ?MS3G3ja(3Kxy8i=;NseWZ!cfnzct%FMusTHicq_Js*K0=Zr#Z_=|C^(2N zz6SpTT?JPKK~Mw{H+Nr)NIbVKv`Bly&H3@&`yEccfH$1hGj`K7WU`JGnF|G$V=Dpw z8$P<|W(vQi+vd!|LYRi@`vH%t_amxT<9l^i+j_#*!P6o{j0Rx~mTUez;@tl@YK>nSTEJR}^z@k8c0R}g`@382~lR_@*6&t12h>=^Lg zkqGJ*FqIaUqCmxoD?#WP!Pz*M%q@o6MvzEVRnLCh?jlAmjKqQNH@FL}FQ70jRDQA5 zp0`Ko|BCbStKDHwxRg3!|7%cdh+-Kt8S$rL>hyU}he8>UM~EWxYf(E8S}5G68y0xQ z57MQ+sqyvT%ymYo>>Hdhcd7+~RFz()B>F`hYCu7fSu1NA&w-o?Lh?cnCkWG^w5o-U zLRldZov{`2(vQVk15xmg8EK<>?UIlS`K;H4(zfmrP_CUQ%kbyG8R6~7;5CFlt}T}R TU^RIi00000NkvXXu0mjfB+G<| literal 0 HcmV?d00001 diff --git a/mods/ebiome/textures/ebiome_oak_trunk_growing_slice.png b/mods/ebiome/textures/ebiome_oak_trunk_growing_slice.png new file mode 100644 index 0000000000000000000000000000000000000000..dfde79eaf0bafa2cd26de0f65caec69ea88ca8a2 GIT binary patch literal 745 zcmVzct%FMusTHicq_Js*K0=Zr#Z_=|C^(2N zz6SpTT?JPKK~Mw{H+Nr)NIbVKv`Bly&H3@&`yEccfH$1hGj`K7WU`JGnF|G$V=Dpw z8$P<|W(vQi+vd!|LYRi@`vH%t_amxT<9l^i+j_#*!P6o{j0Rx~mTUez;@tl@YK>nSTEJR}^dPem`xYv zHj?1sbtXFluM`2PF-QVLVkL=L;0U&~CI!A%Bz@dR^@^adk%;m!0&}ZU5?Q`21_E0m zDSRQmS!|$6NkoZ*Die>e=UtjhUx#@b`3B0 b{OSJyh%JF2&My0d00000NkvXXu0mjfA}da? literal 0 HcmV?d00001 diff --git a/mods/ebiome/textures/ebiome_oak_trunk_growing.png b/mods/ebiome/textures/ebiome_oak_trunk_growing_terminal.png similarity index 100% rename from mods/ebiome/textures/ebiome_oak_trunk_growing.png rename to mods/ebiome/textures/ebiome_oak_trunk_growing_terminal.png diff --git a/mods/ebiome/textures/ebiome_oak_trunk_growing_tjunction.png b/mods/ebiome/textures/ebiome_oak_trunk_growing_tjunction.png new file mode 100644 index 0000000000000000000000000000000000000000..fa16c7502a4985949a48c1f09ebc190c30b5ff65 GIT binary patch literal 918 zcmV;H18Mw;P)zct%FMusTHicq_Js*K0=Zr#Z_=|C^(2N zz6SpTT?JPKK~Mw{H+Nr)NIbVKv`Bly&H3@&`yEccfH$1hGj`K7WU`JGnF|G$V=Dpw z8$P<|W(vQi+vd!|LYRi@`vH%t_amxT<9l^i+j_#*!P6o{j0Rx~mTUez;@tl@YK>nSTEJR}^k$29}ZLlf~ZP;CG&B_I?8KED8!6Kb^@ zW={>|EARw^`8$WI&?3Y{3@FzDEzl*X99pREoA3(;FWy=R5O_cXl#C%N)CYm#p)P@6 zOpgLjMPTX95@&@7N}IBpa8R~aYq$ssRbV^{)VB=}8J8YVWi_cAOXyS~aFjIBIHB|b z!RnNp-;gAMBl8D|uIm`o9D9cKhVcE=KoiG#Ff zklZh`pe&-tA!m>}$9>l9YFf;JyZ3g7M7}i9r17n{@~&I@bynz0ZI scT+}&`lIaUyStSHweY?t!TdXa14%uwnT;nS{r~^~07*qoM6N<$f>_F>MgRZ+ literal 0 HcmV?d00001 diff --git a/mods/ebiome/textures/ebiome_oak_trunk_growing_xjunction.png b/mods/ebiome/textures/ebiome_oak_trunk_growing_xjunction.png new file mode 100644 index 0000000000000000000000000000000000000000..4adf4cc610a2103aa1573ab3571e63a970aeb4e1 GIT binary patch literal 952 zcmV;p14sOcP)zct%FMusTHicq_Js*K0=Zr#Z_=|C^(2N zz6SpTT?JPKK~Mw{H+Nr)NIbVKv`Bly&H3@&`yEccfH$1hGj`K7WU`JGnF|G$V=Dpw z8$P<|W(vQi+vd!|LYRi@`vH%t_amxT<9l^i+j_#*!P6o{j0Rx~mTUez;@tl@YK>nSTEJR}^c;*BHZh*6i-M?6S*RuglS4 zH&{t$x~uBFd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{C)V23`Cls+YVa@E_k bvDWz)4~TMV%o1qL00000NkvXXu0mjf@bz+R literal 0 HcmV?d00001 diff --git a/mods/ebiome/textures/ebiome_oak_trunk_normal_xjunction.png b/mods/ebiome/textures/ebiome_oak_trunk_normal_xjunction.png new file mode 100644 index 0000000000000000000000000000000000000000..a727c99e2bc19f35593521a315b1d4f33a6cf812 GIT binary patch literal 847 zcmV-V1F-ywP)zct%FMusTHicq_Js*K0=Zr#Z_=|C^(2N zz6SpTT?JPKK~Mw{H+Nr)NIbVKv`Bly&H3@&`yEccfH$1hGj`K7WU`JGnF|G$V=Dpw z8$P<|W(vQi+vd!|LYRi@`vH%t_amxT<9l^i+j_#*!P6o{j0Rx~mTUez;@tl@YK>nSTEJR}^n`vz`O%_=s!6)A8gIdIOoyjyw&)YM z?E~+eUDDi9QUz31l>#c&fpe0Z^*I8Dg?|ocHgr`X#@9T6*Vio+WblX8OLq*JwpE4^2&--nk6k9uK_(1T64p-r&(Mj z%C)DOFv4a$Gp8j7Z`R{$7S>zqaS^gmzT^L(+Ihobb!fEUHHI|BGWo3_|IrRd1yAFn z0&?bT;!o+o1rs?-e`LZ_WZ5Bsa-ZUv`DNSUgb`M`>PB)~w4^NDqdZr7{zg<2Mp$vg Z{Q^PPqBNUg9;^TW002ovPDHLkV1k+zfW80# literal 0 HcmV?d00001 diff --git a/mods/ebiometrees/init.lua b/mods/ebiometrees/init.lua index 831ba60..c3df1cb 100644 --- a/mods/ebiometrees/init.lua +++ b/mods/ebiometrees/init.lua @@ -1 +1,2 @@ dofile(minetest.get_modpath("ebiometrees").."/sapling.lua") +dofile(minetest.get_modpath("ebiometrees").."/tree.lua") diff --git a/mods/ebiometrees/tree.lua b/mods/ebiometrees/tree.lua new file mode 100644 index 0000000..ce55c77 --- /dev/null +++ b/mods/ebiometrees/tree.lua @@ -0,0 +1,128 @@ +local function growth_timer(pos) + minetest.get_node_timer(pos):start(3) +end + + +local S = minetest.get_translator("ebiometrees") +function ebiometrees.register_tree(modname, basename, data) + -- register saplings + local sapling_name = modname..":"..basename.."_sapling" + local sprout_name = modname..":"..basename.."_sprout" + + local sapling_groups = table.copy(data.groups) + local sprout_groups = table.copy(data.groups) + sapling_groups.sapling = 1 + sapling_groups.snappy = 2 + sapling_groups.dig_immediate = 3 + sprout_groups.sapling = 1 + sprout_groups.snappy = 2 + minetest.register_node(sapling_name, { + description = S(data.description.." sapling"), + drawtype = "plantlike", + tiles = { modname.."_"..basename.."_sapling.png"}, + paramtype = "light", + on_timer = ebiometrees.get_sapling_grower(sprout_name), + sunlight_propagates = true, + walkable = false, + groups = sapling_groups, + on_construct = growth_timer + }) + minetest.register_node(sprout_name, { + description = S(data.description.." sprout"), + drawtype = "plantlike", + visual_scale = 1.4, + tiles = { modname.."_"..basename.."_sprout.png" }, + paramtype = "light", + sunlight_propagates = true, + walkable = false, + on_timer = ebiometrees.get_sprout_grower( + modname..":"..basename.."_trunk_growing_straight", + modname..":"..basename.."_trunk_growing_terminal"), + groups = sprout_groups, + on_construct = growth_timer + }) + -- registers tree and corresponding nodes + local trunk_groups = table.copy(data.groups) + trunk_groups.choppy = 2 -- TODO: customizations + local trunk_types = {"growing", "normal"} + local trunk_subtypes = {"terminal", "straight", "corner", + "tjunction", "t2junction", "xjunction", + "xtjunction", "x2junction"} + + for _, trunk_type in ipairs(trunk_types) + do + local texture_basename = modname.."_"..basename.."_trunk_"..trunk_type.."_" + local subtype_tiles = { + terminal = { + texture_basename.."terminal.png", + texture_basename.."slice.png", + texture_basename.."terminal.png" + }, + straight = { + texture_basename.."slice.png", + texture_basename.."slice.png", + texture_basename.."normal.png" + }, + corner = { + texture_basename.."normal.png", + texture_basename.."slice.png", + texture_basename.."corner.png^[transformFX", + texture_basename.."corner.png", + texture_basename.."normal.png", + texture_basename.."slice.png", + }, + tjunction = { + texture_basename.."slice.png", + texture_basename.."slice.png", + texture_basename.."tjunction.png^[transformFX", + texture_basename.."tjunction.png", + texture_basename.."normal.png", + texture_basename.."slice.png", + }, + t2junction = { + texture_basename.."slice.png", + texture_basename.."slice.png", + texture_basename.."tjunction.png^[transformFX", + texture_basename.."slice.png", + texture_basename.."tjunction.png", + texture_basename.."slice.png", + }, + xjunction = { + texture_basename.."slice.png", + texture_basename.."slice.png", + texture_basename.."xjunction.png^[transformFX", + texture_basename.."xjunction.png", + texture_basename.."slice.png", + texture_basename.."slice.png", + }, + xtjunction = { + texture_basename.."slice.png", + texture_basename.."slice.png", + texture_basename.."xjunction.png", + texture_basename.."slice.png", + texture_basename.."slice.png", + texture_basename.."slice.png", + }, + x2junction = { + texture_basename.."slice.png" + } + } + for _, trunk_subtype in ipairs(trunk_subtypes) + do + minetest.register_node( + modname..":"..basename.."_trunk_"..trunk_type.."_"..trunk_subtype, { + description = S(data.description.." "..trunk_type.." "..trunk_subtype), + groups = trunk_groups, + tiles = subtype_tiles[trunk_subtype], + paramtype2 = "facedir", + is_ground_content = false, + on_place = minetest.rotate_node, + on_timer = function(pos) + return true + end, + on_construct = growth_timer + }) + end + end +end +