From 845dfaa6a2230fe18409579f30efd91b8d8820e6 Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Sun, 16 Jul 2023 23:39:29 +0200 Subject: [PATCH] refactor: make mcl_soy use mcl_vegan_utils. --- mcl_soy/depends.txt | 1 + mcl_soy/init.lua | 7 ----- mcl_soy/item.lua | 40 ------------------------ mcl_soy/node.lua | 74 ++++++++------------------------------------- 4 files changed, 13 insertions(+), 109 deletions(-) diff --git a/mcl_soy/depends.txt b/mcl_soy/depends.txt index 2274fb1..8e2a7c9 100644 --- a/mcl_soy/depends.txt +++ b/mcl_soy/depends.txt @@ -1,3 +1,4 @@ +mcl_vegan_utils mcl_core mcl_farming mcl_sounds diff --git a/mcl_soy/init.lua b/mcl_soy/init.lua index 3235c65..fa82dbc 100644 --- a/mcl_soy/init.lua +++ b/mcl_soy/init.lua @@ -1,10 +1,3 @@ --- TODO: extract this into general utility mod. -local function include (filename) - local modname = minetest.get_current_modname() - local path = minetest.get_modpath(modname) - return dofile(path .. "/" .. filename .. ".lua") -end - include("item") include("node") include("craft") diff --git a/mcl_soy/item.lua b/mcl_soy/item.lua index b593792..d481cbd 100644 --- a/mcl_soy/item.lua +++ b/mcl_soy/item.lua @@ -39,43 +39,3 @@ minetest.register_craftitem(modname .. ":tofu_cooked", { on_place = minetest.item_eat(6), on_secondary_use = minetest.item_eat(6), }) - --- TODO: extract this into general utility mod. -local function get_drop (target_name) - local def = minetest.registered_items[target_name] - if not def then return false end - def.drop = def.drop or {} - return def.drop -end - -local function stringify_table (tab) - local result = "{ " - for key, value in pairs(tab) do - if type(key) == "table" then key = stringify_table(key) end - if type(value) == "table" then value = stringify_table(value) end - result = result .. key .. " = " .. value .. ", " - end - return result .. "}" -end - --- TODO: extract this into general utility mod. -local function add_drop (target_name, item) - local drops = get_drop(target_name) - if not drops then return false end - table.insert(drops.items, item) - return true -end - -local grasses = { - "mcl_flowers:tallgrass", - "mcl_flowers:fern", - "mcl_flowers:double_grass", - "mcl_flowers:double_fern", -} - -for _, grass in pairs(grasses) do - add_drop(grass, { - items = { modname .. ":soy" }, - rarity = 8, - }) -end diff --git a/mcl_soy/node.lua b/mcl_soy/node.lua index 2c50da6..a18e9ab 100644 --- a/mcl_soy/node.lua +++ b/mcl_soy/node.lua @@ -1,55 +1,6 @@ local modname = minetest.get_current_modname() --- copied from wheat for now -local crop_heights = { - -5/16, - -2/16, - 0, - 3/16, - 5/16, - 6/16, - 7/16, - 8/16, -} - -local function register_plant_stage (stage, drops) - local texture = modname .. "_soy_stage_" .. (stage - 1) .. ".png" - - minetest.register_node(modname .. ":soy_" .. stage, { - description = "Soy Plant (stage " .. stage .. ")", - paramtype = "light", - sunlight_propagates = true, - walkable = false, - drawtype = "plantlike", - drop = drops, - tiles = { texture }, - inventory_image = texture, - wield_image = texture, - selection_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, crop_heights[stage], 0.5} - }, - }, - groups = { - dig_immediate = 3, - not_in_creative_inventory = 1, - plant = 1, - attached_node = 1, - dig_by_water = 1, - destroy_by_lava_flow = 1, - dig_by_piston = 1, - }, - sounds = mcl_sounds.node_sound_leaves_defaults(), - _mcl_blast_resistance = 0, - }) -end - -for i=1,7 do - register_plant_stage(i, modname .. ":soy") -end - -register_plant_stage(8, { +local final_drops = { max_items = 4, items = { { items = { modname .. ":soy" } }, @@ -58,16 +9,15 @@ register_plant_stage(8, { { items = { modname .. ":soy" } }, { items = { modname .. ":soy 5" }, rarity = 6 }, }, +} + +mcl_vegan.register_basic_plant(modname, "soy", { + seed = "soy", + descriptions = { + crop = "Soy Plant", + }, + drops = final_drops, + growth_interval = 15, + growth_chance = 20, + can_forage = true, }) - - - -mcl_farming:add_plant("plant_soy", modname .. ":soy_8", { - modname .. ":soy_1", - modname .. ":soy_2", - modname .. ":soy_3", - modname .. ":soy_4", - modname .. ":soy_5", - modname .. ":soy_6", - modname .. ":soy_7", -}, 20, 15)