From f639917a981982e336f4069ce25d84fd888e3128 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Sat, 25 Jan 2020 10:02:51 +0000 Subject: [PATCH] Code tweaked and tidied thanks to MoNTE48 --- init.lua | 93 ++++++++++++++++--------------- locale/ru.txt | 7 +++ mods.lua | 16 +++--- screenshot.png | Bin 15254 -> 15242 bytes textures/bonemeal_fertiliser.png | Bin 186 -> 182 bytes textures/bonemeal_item.png | Bin 186 -> 182 bytes textures/bonemeal_mulch.png | Bin 186 -> 182 bytes 7 files changed, 62 insertions(+), 54 deletions(-) create mode 100644 locale/ru.txt diff --git a/init.lua b/init.lua index 27f64c9..c2a1c00 100644 --- a/init.lua +++ b/init.lua @@ -1,9 +1,13 @@ bonemeal = {} +local path = minetest.get_modpath("bonemeal") +local table_insert = table.insert +local min, max, random = math.min, math.max, math.random + + -- Load support for intllib. -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP .. "/intllib.lua") +local S, NS = dofile(path .. "/intllib.lua") -- creative check @@ -16,7 +20,7 @@ end -- default crops local crops = { {"farming:cotton_", 8, "farming:seed_cotton"}, - {"farming:wheat_", 8, "farming:seed_wheat"}, + {"farming:wheat_", 8, "farming:seed_wheat"} } @@ -45,7 +49,7 @@ local saplings = { {"default:acacia_bush_sapling", default.grow_acacia_bush, "soil"}, {"default:large_cactus_seedling", default.grow_large_cactus, "sand"}, {"default:blueberry_bush_sapling", default.grow_blueberry_bush, "soil"}, - {"default:pine_bush_sapling", default.grow_pine_bush, "soil"}, + {"default:pine_bush_sapling", default.grow_pine_bush, "soil"} } -- helper tables ( "" denotes a blank item ) @@ -59,15 +63,14 @@ local dry_grass = { "default:dry_grass_5", "", "" } -local flowers = { - "flowers:dandelion_white", "flowers:dandelion_yellow", "flowers:geranium", - "flowers:rose", "flowers:tulip", "flowers:viola", "" -} +-- add all in-game flowers except waterlily +local flowers = {} --- 5.0 flower check -if minetest.registered_nodes["flowers:tulip_black"] then - flowers[#flowers + 1] = "flowers:tulip_black" - flowers[#flowers + 1] = "flowers:chrysanthemum_green" +for node, def in pairs(minetest.registered_nodes) do + + if def.groups.flower and not node:find("waterlily") then + flowers[#flowers + 1] = node + end end -- add additional bakedclay flowers if enabled @@ -107,7 +110,7 @@ local function particle_effect(pos) maxexptime = 1, minsize = 1, maxsize = 3, - texture = "bonemeal_particle.png", + texture = "bonemeal_particle.png" }) end @@ -191,7 +194,7 @@ local function check_crops(pos, nodename, strength) -- grow registered crops for n = 1, #crops do - if string.find(nodename, crops[n][1]) + if nodename:find(crops[n][1]) or nodename == crops[n][3] then -- separate mod and node name @@ -200,7 +203,7 @@ local function check_crops(pos, nodename, strength) -- get stage number or set to 0 for seed stage = tonumber( crop:split("_")[2] ) or 0 - stage = math.min(stage + strength, crops[n][2]) + stage = min(stage + strength, crops[n][2]) -- check for place_param setting nod = crops[n][1] .. stage @@ -222,7 +225,7 @@ local function check_soil(pos, nodename, strength) -- set radius according to strength local side = strength - 1 - local tall = math.max(strength - 2, 0) + local tall = max(strength - 2, 0) local floor local groups = minetest.registered_items[nodename] and minetest.registered_items[nodename].groups or {} @@ -264,17 +267,17 @@ local function check_soil(pos, nodename, strength) pos2.y = pos2.y + 1 - if math.random(1, 5) == 5 then + if random(5) == 5 then if decor and #decor > 0 then -- place random decoration (rare) local dnum = #decor or 1 - nod = decor[math.random(1, dnum)] or "" + nod = decor[random(dnum)] or "" end else if grass and #grass > 0 then -- place random grass (common) local dgra = #grass or 1 - nod = #grass > 0 and grass[math.random(1, dgra)] or "" + nod = #grass > 0 and grass[random(dgra)] or "" end end @@ -299,7 +302,7 @@ end function bonemeal:add_sapling(list) for n = 1, #list do - table.insert(saplings, list[n]) + table_insert(saplings, list[n]) end end @@ -310,7 +313,7 @@ end function bonemeal:add_crop(list) for n = 1, #list do - table.insert(crops, list[n]) + table_insert(crops, list[n]) end end @@ -330,11 +333,11 @@ function bonemeal:add_deco(list) if list[l][1] == deco[n][1] then -- adding grass types - for _,extra in ipairs(list[l][2]) do + for _,extra in pairs(list[l][2]) do if extra ~= "" then - for __,entry in ipairs(deco[n][2]) do + for _,entry in pairs(deco[n][2]) do if extra == entry then extra = false @@ -344,7 +347,7 @@ function bonemeal:add_deco(list) end if extra then - table.insert(deco[n][2], extra) + table_insert(deco[n][2], extra) end end @@ -353,7 +356,7 @@ function bonemeal:add_deco(list) if extra ~= "" then - for __,entry in ipairs(deco[n][3]) do + for __,entry in pairs(deco[n][3]) do if extra == entry then extra = false @@ -363,7 +366,7 @@ function bonemeal:add_deco(list) end if extra then - table.insert(deco[n][3], extra) + table_insert(deco[n][3], extra) end end @@ -373,7 +376,7 @@ function bonemeal:add_deco(list) end if list[l] then - table.insert(deco, list[l]) + table_insert(deco, list[l]) end end end @@ -397,7 +400,7 @@ function bonemeal:set_deco(list) end if list[l] then - table.insert(deco, list[l]) + table_insert(deco, list[l]) end end end @@ -416,8 +419,8 @@ function bonemeal:on_use(pos, strength, node) -- make sure strength is between 1 and 4 strength = strength or 1 - strength = math.max(strength, 1) - strength = math.min(strength, 4) + strength = max(strength, 1) + strength = min(strength, 4) -- papyrus and cactus if node.name == "default:papyrus" then @@ -448,7 +451,7 @@ function bonemeal:on_use(pos, strength, node) -- check for tree growth if pointing at sapling -- if minetest.get_item_group(node.name, "sapling") > 0 - if math.random(1, (5 - strength)) == 1 then + if random(5 - strength) == 1 then check_sapling(pos, node.name) return end @@ -487,7 +490,7 @@ minetest.register_craftitem("bonemeal:mulch", { bonemeal:on_use(pointed_thing.under, 1) return itemstack - end, + end }) @@ -517,7 +520,7 @@ minetest.register_craftitem("bonemeal:bonemeal", { bonemeal:on_use(pointed_thing.under, 2) return itemstack - end, + end }) @@ -547,21 +550,21 @@ minetest.register_craftitem("bonemeal:fertiliser", { bonemeal:on_use(pointed_thing.under, 3) return itemstack - end, + end }) -- bone minetest.register_craftitem("bonemeal:bone", { description = S("Bone"), - inventory_image = "bonemeal_bone.png", + inventory_image = "bonemeal_bone.png" }) -- gelatin powder minetest.register_craftitem("bonemeal:gelatin_powder", { description = S("Gelatin Powder"), inventory_image = "bonemeal_gelatin_powder.png", - groups = {food_gelatin = 1, flammable = 2}, + groups = {food_gelatin = 1, flammable = 2} }) @@ -577,28 +580,28 @@ minetest.register_craft({ }, replacements = { {"bucket:bucket_water", "bucket:bucket_empty 5"}, - }, + } }) -- bonemeal (from bone) minetest.register_craft({ type = "shapeless", output = "bonemeal:bonemeal 2", - recipe = {"bonemeal:bone"}, + recipe = {"bonemeal:bone"} }) -- bonemeal (from player bones) minetest.register_craft({ type = "shapeless", output = "bonemeal:bonemeal 4", - recipe = {"bones:bones"}, + recipe = {"bones:bones"} }) -- bonemeal (from coral skeleton) minetest.register_craft({ type = "shapeless", output = "bonemeal:bonemeal 2", - recipe = {"default:coral_skeleton"}, + recipe = {"default:coral_skeleton"} }) -- mulch @@ -609,14 +612,14 @@ minetest.register_craft({ "group:tree", "group:leaves", "group:leaves", "group:leaves", "group:leaves", "group:leaves", "group:leaves", "group:leaves", "group:leaves" - }, + } }) -- fertiliser minetest.register_craft({ type = "shapeless", output = "bonemeal:fertiliser 2", - recipe = {"bonemeal:bonemeal", "bonemeal:mulch"}, + recipe = {"bonemeal:bonemeal", "bonemeal:mulch"} }) @@ -627,10 +630,10 @@ minetest.override_item("default:dirt", { items = { { items = {"bonemeal:bone"}, - rarity = 30, + rarity = 30 }, { - items = {"default:dirt"}, + items = {"default:dirt"} } } }, @@ -638,8 +641,6 @@ minetest.override_item("default:dirt", { -- add support for other mods -local path = minetest.get_modpath("bonemeal") - dofile(path .. "/mods.lua") dofile(path .. "/lucky_block.lua") diff --git a/locale/ru.txt b/locale/ru.txt new file mode 100644 index 0000000..4faa2e0 --- /dev/null +++ b/locale/ru.txt @@ -0,0 +1,7 @@ +# init.lua + +Mulch = Мульча +Bone Meal = Костная Мука +Fertiliser = Удобрение +Bone = Кость +[MOD] bonemeal loaded = [MOD] костная мука загружена diff --git a/mods.lua b/mods.lua index 0a51131..1c8f577 100644 --- a/mods.lua +++ b/mods.lua @@ -5,7 +5,7 @@ if minetest.get_modpath("animalmaterials") then minetest.register_craft({ type = "shapeless", output = "bonemeal:bonemeal 2", - recipe = {"animalmaterials:bone"}, + recipe = {"animalmaterials:bone"} }) end @@ -38,7 +38,7 @@ if farming and farming.mod and farming.mod == "redo" then {"farming:beetroot_", 5}, {"farming:rye_", 8}, {"farming:oat_", 8}, - {"farming:rice_", 8}, + {"farming:rice_", 8} }) end @@ -47,7 +47,7 @@ if minetest.get_modpath("ethereal") then bonemeal:add_crop({ {"ethereal:strawberry_", 8}, - {"ethereal:onion_", 5}, + {"ethereal:onion_", 5} }) bonemeal:add_sapling({ @@ -63,7 +63,7 @@ if minetest.get_modpath("ethereal") then {"ethereal:orange_tree_sapling", ethereal.grow_orange_tree, "soil"}, {"ethereal:bamboo_sprout", ethereal.grow_bamboo_tree, "soil"}, {"ethereal:birch_sapling", ethereal.grow_birch_tree, "soil"}, - {"ethereal:sakura_sapling", ethereal.grow_sakura_tree, "soil"}, + {"ethereal:sakura_sapling", ethereal.grow_sakura_tree, "soil"} }) local grass = {"default:grass_3", "default:grass_4", "default:grass_5", ""} @@ -79,7 +79,7 @@ if minetest.get_modpath("ethereal") then {"ethereal:mushroom_dirt", {}, {"flowers:mushroom_red", "flowers:mushroom_brown", "", "", ""}}, {"ethereal:jungle_dirt", grass, {"default:junglegrass", "", "", ""}}, {"ethereal:grove_dirt", grass, {"ethereal:fern", "", "", ""}}, - {"ethereal:bamboo_dirt", grass, {}}, + {"ethereal:bamboo_dirt", grass, {}} }) end @@ -115,13 +115,13 @@ if minetest.get_modpath("moretrees") then {"moretrees:poplar_sapling", moretrees.spawn_poplar_object, "soil"}, {"moretrees:willow_sapling", moretrees.spawn_willow_object, "soil"}, {"moretrees:rubber_tree_sapling", moretrees.spawn_rubber_tree_object, "soil"}, - {"moretrees:fir_sapling", fir_grow, "soil"}, + {"moretrees:fir_sapling", fir_grow, "soil"} }) elseif minetest.get_modpath("technic_worldgen") then bonemeal:add_sapling({ - {"moretrees:rubber_tree_sapling", technic.rubber_tree_model, "soil"}, + {"moretrees:rubber_tree_sapling", technic.rubber_tree_model, "soil"} }) end @@ -138,6 +138,6 @@ if minetest.get_modpath("caverealms") then end bonemeal:add_sapling({ - {"caverealms:mushroom_sapling", add_shroom, "soil"}, + {"caverealms:mushroom_sapling", add_shroom, "soil"} }) end diff --git a/screenshot.png b/screenshot.png index c4b9fa718333f8a3d2d64c35b96daf21553cc365..a14caeaed8e81374cac338b9eea3a16c49568298 100644 GIT binary patch delta 35 pcmbPM-c>%~J(E@I#*Zutn;8{br3CIyGxuWv0#8>zmvv4FO#u8}41)jw delta 47 zcmeAwpH@EMJ(B{%#*Zut-1iOs)iN+hwR*ZZZvLXsCM6Iy;jl0R5O})!xvXS0C=DP$eqUpN^}cN T@>*E300000NkvXXu0mjf-3lzU delta 117 zcmV-*0E+*%0lEQ@Om108L_t&t*G0KAngKT7ofO+mi=dvlK3EeoWLak z_=>ZE;#`aplYOE2sSk#0ph{P%v?kYKEnqT@*Q&|B*%{YrLtk(J#IS0C=DP$eqUpN^}cN T@>*E300000NkvXXu0mjf-3lzU delta 117 zcmV-*0E+*%0lEQ@Om108L_t&t*G0KAngKT7ofO+mi=dvlK3EeoWLak z_=>ZE;#`aplYOE2sSk#0ph{P%v?kYKEnqT@*Q&|B*%{YrLtk(J#IS0C=DP$eqUpN^}cN T@>*E300000NkvXXu0mjf-3lzU delta 117 zcmV-*0E+*%0lEQ@Om108L_t&t*G0KAngKT7ofO+mi=dvlK3EeoWLak z_=>ZE;#`aplYOE2sSk#0ph{P%v?kYKEnqT@*Q&|B*%{YrLtk(J#I