create mcl_vegan_utils mod.
create utilities for: - loading files. - changing drops of existing nodes. - registering crops.
This commit is contained in:
parent
8fcd4c905e
commit
9c94d96fb9
6 changed files with 149 additions and 0 deletions
9
mcl_vegan_utils/debug.lua
Normal file
9
mcl_vegan_utils/debug.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
function mcl_vegan.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
|
3
mcl_vegan_utils/depends.txt
Normal file
3
mcl_vegan_utils/depends.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
mcl_core
|
||||
mcl_farming
|
||||
mcl_sounds
|
22
mcl_vegan_utils/drops.lua
Normal file
22
mcl_vegan_utils/drops.lua
Normal file
|
@ -0,0 +1,22 @@
|
|||
function mcl_vegan.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
|
||||
|
||||
function mcl_vegan.add_drop (target_name, item)
|
||||
local drops = mcl_vegan.get_drop(target_name)
|
||||
if not drops then return false end
|
||||
table.insert(drops.items, item)
|
||||
return true
|
||||
end
|
||||
|
||||
function mcl_vegan.add_drops (target_name, items)
|
||||
local drops = mcl_vegan.get_drop(target_name)
|
||||
if not drops then return false end
|
||||
for _, item in pairs(items) do
|
||||
table.insert(drops.items, item)
|
||||
end
|
||||
return true
|
||||
end
|
99
mcl_vegan_utils/farming.lua
Normal file
99
mcl_vegan_utils/farming.lua
Normal file
|
@ -0,0 +1,99 @@
|
|||
local registered_plants = {}
|
||||
mcl_vegan.registered_plants = registered_plants
|
||||
|
||||
local grasses = {
|
||||
"mcl_flowers:tallgrass",
|
||||
"mcl_flowers:fern",
|
||||
"mcl_flowers:double_grass",
|
||||
"mcl_flowers:double_fern",
|
||||
}
|
||||
|
||||
function mcl_vegan.register_basic_plant (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_plants[full_base_name] = def
|
||||
|
||||
local seed = own_mod_name .. ":" .. def.seed
|
||||
local descriptions = def.descriptions
|
||||
|
||||
-- copied from wheat
|
||||
if def.crop_heights == nil then
|
||||
def.crop_heights = {
|
||||
-5/16, -2/16, 0, 3/16,
|
||||
5/16, 6/16, 7/16, 8/16,
|
||||
}
|
||||
end
|
||||
local crop_heights = def.crop_heights
|
||||
|
||||
local final_drops = def.drops
|
||||
local interval = def.growth_interval
|
||||
local chance = def.growth_chance
|
||||
if def.can_forage == nil then def.can_forage = true end
|
||||
local can_forage = def.can_forage
|
||||
|
||||
|
||||
|
||||
local function register_plant_stage (stage, drops)
|
||||
local texture = own_mod_name .. "_" .. base_name .. "_stage_" .. (stage - 1) .. ".png"
|
||||
|
||||
minetest.register_node(full_base_name .. "_" .. stage, {
|
||||
description = descriptions.crop .. " (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, seed)
|
||||
end
|
||||
|
||||
register_plant_stage(8, final_drops)
|
||||
|
||||
mcl_farming:add_plant("plant_" .. base_name, full_base_name .. "_8", {
|
||||
full_base_name .. "_1",
|
||||
full_base_name .. "_2",
|
||||
full_base_name .. "_3",
|
||||
full_base_name .. "_4",
|
||||
full_base_name .. "_5",
|
||||
full_base_name .. "_6",
|
||||
full_base_name .. "_7",
|
||||
}, interval, chance)
|
||||
|
||||
if can_forage then
|
||||
for _, grass in pairs(grasses) do
|
||||
local drop = mcl_vegan.get_drop(grass)
|
||||
drop.max_items = drop.max_items + 1
|
||||
|
||||
mcl_vegan.add_drop(grass, {
|
||||
items = { seed },
|
||||
rarity = 8,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
13
mcl_vegan_utils/init.lua
Normal file
13
mcl_vegan_utils/init.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
local mcl_vegan = rawget(_G, "mcl_vegan") or {}
|
||||
rawset(_G, "mcl_vegan", mcl_vegan)
|
||||
|
||||
local function include (filename)
|
||||
local modname = minetest.get_current_modname()
|
||||
local path = minetest.get_modpath(modname)
|
||||
return dofile(path .. "/" .. filename .. ".lua")
|
||||
end
|
||||
rawset(_G, "include", include)
|
||||
|
||||
include("debug")
|
||||
include("farming")
|
||||
include("drops")
|
3
mcl_vegan_utils/mod.conf
Normal file
3
mcl_vegan_utils/mod.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
name = mcl_vegan_utils
|
||||
description = utilities for the mcl_vegan modpack.
|
||||
title = mcl vegan utilities
|
Loading…
Reference in a new issue