add registration of farming items to utility mod.

This commit is contained in:
trans_soup 2023-07-17 00:03:20 +02:00
parent 845dfaa6a2
commit d78db87afa
3 changed files with 67 additions and 4 deletions

View file

@ -0,0 +1,62 @@
local registered_plant_items = {}
mcl_vegan.registered_plant_items = registered_plant_items
function mcl_vegan.register_plant_items (own_mod_name, base_name, def)
def.own_mod_name = own_mod_name
def.base_name = base_name
local full_base_name = own_mod_name .. ":" .. base_name
registered_plant_items[full_base_name] = def
local seed = def.seed
local full_seed = own_mod_name .. ":" .. seed
local descriptions = def.descriptions
-- 0 means inedible
if def.food_strength == nil then def.food_strength = 0 end
local food_strength = def.food_strength
local on_secondary_use = nil
if food_strength > 0 then
on_secondary_use = minetest.item_eat(food_strength)
end
local plant_seed = function (item_stack, placer, pointed_thing)
return mcl_farming:place_seed(item_stack, placer, pointed_thing, full_base_name .. "_1")
end
local on_place = nil
if seed == base_name then
on_place = plant_seed
elseif food_strength > 0 then
on_place = on_secondary_use
end
minetest.register_craftitem(full_base_name, {
description = descriptions.base,
groups = {
craftitem = 1,
food = 1,
eatable = food_strength,
},
_mcl_saturation = food_strength,
inventory_image = own_mod_name .. "_" .. base_name .. ".png",
on_place = on_place,
on_secondary_use = on_secondary_use
})
if seed ~= base_name then
minetest.register_craftitem(full_seed, {
description = descriptions.seed,
groups = {
craftitem = 1,
},
inventory_image = modname .. "_" .. seed .. ".png",
on_place = plant_seed,
})
end
end

View file

@ -1,5 +1,5 @@
local registered_plants = {}
mcl_vegan.registered_plants = registered_plants
local registered_plant_nodes = {}
mcl_vegan.registered_plant_nodes = registered_plant_nodes
local grasses = {
"mcl_flowers:tallgrass",
@ -14,7 +14,7 @@ function mcl_vegan.register_basic_plant (own_mod_name, base_name, def)
local full_base_name = own_mod_name .. ":" .. base_name
registered_plants[full_base_name] = def
registered_plant_nodes[full_base_name] = def
local seed = own_mod_name .. ":" .. def.seed
local descriptions = def.descriptions

View file

@ -9,5 +9,6 @@ end
rawset(_G, "include", include)
include("debug")
include("farming")
include("farming_node")
include("farming_item")
include("drops")