Move hades_farming seeds to new mod hades_seeds

master
Wuzzy 2021-07-20 08:44:11 +02:00
parent 739891fc2d
commit 7c6210e7a5
10 changed files with 153 additions and 88 deletions

View File

@ -19,7 +19,9 @@ Hoe Definition
Plant definition
{
description = "", -- Description of seed item
description_seed = "", -- Description of seed item
description_plant = "", -- Description of plant item (needs a @1 placeholder for translation)
meshoptions = 0, -- If set, this is the meshoptions param2 value the plant spawns with
inventory_image = "unknown_item.png", -- Image to be used as seed's wield- and inventory image
steps = 8, -- How many steps the plant has to grow, until it can be harvested
^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber)

View File

@ -112,61 +112,6 @@ hades_farming.register_hoe = function(name, def)
end
end
-- Seed placement
hades_farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
local pt = pointed_thing
-- check if pointing at a node
if not pt then
return
end
if pt.type ~= "node" then
return
end
local under = minetest.get_node(pt.under)
local above = minetest.get_node(pt.above)
local udef = minetest.registered_nodes[under.name]
if udef and udef.on_rightclick and
((not placer) or (placer and not placer:get_player_control().sneak)) then
return udef.on_rightclick(pt.under, under, placer, itemstack,
pt) or itemstack
end
-- return if any of the nodes is not registered
if not minetest.registered_nodes[under.name] then
return
end
if not minetest.registered_nodes[above.name] then
return
end
-- check if pointing at the top of the node
if pt.above.y ~= pt.under.y+1 then
return
end
-- check if you can replace the node above the pointed node
if not minetest.registered_nodes[above.name].buildable_to then
return
end
-- check if pointing at soil
if minetest.get_item_group(under.name, "soil") < 2 then
return
end
minetest.sound_play({name="hades_farming_seed_place", gain=1.0}, {pos=pt.above}, true)
-- add the node and remove 1 item from the itemstack
local pdef = minetest.registered_nodes[plantname]
minetest.add_node(pt.above, {name = plantname, param2 = pdef.place_param2})
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
return itemstack
end
-- Register plants
hades_farming.register_plant = function(name, def)
local mname = name:split(":")[1]
@ -196,42 +141,23 @@ hades_farming.register_plant = function(name, def)
end
-- Register seed
local g = {seed = 1, snappy = 3, attached_node = 1}
local g = {}
for k, v in pairs(def.fertility) do
g[v] = 1
end
minetest.register_node(":" .. mname .. ":seed_" .. pname, {
local surface_check = function(node)
return minetest.get_item_group(node.name, "soil") >= 2
end
hades_seeds.register_seed(":" .. mname .. ":seed_" .. pname, {
description = def.description_seed,
_tt_help = def._tt_help,
tiles = {def.inventory_image, def.inventory_image, "blank.png"},
use_texture_alpha = "clip",
inventory_image = def.inventory_image,
wield_image = def.inventory_image,
drawtype = "nodebox",
groups = g,
paramtype = "light",
place_param2 = def.place_param2,
walkable = false,
floodable = true,
sunlight_propagates = true,
node_placement_prediction = "",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -31/64, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
},
sounds = {
dig = { name = "hades_farming_seed_dig", gain = 0.1 },
dug = { name = "hades_farming_seed_dug", gain = 0.5 },
-- place sound is done in hades_farming.place_seed
},
surface_check = surface_check,
extra_groups = g,
fertility = def.fertility,
on_place = function(itemstack, placer, pointed_thing)
return hades_farming.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname)
end
})
-- Register harvest
@ -287,12 +213,18 @@ hades_farming.register_plant = function(name, def)
-- Growing ABM
minetest.register_abm({
label = "Grow seeds",
label = "Grow farming seeds and plants: "..pname,
nodenames = {"group:" .. pname, "group:seed"},
neighbors = {"group:soil"},
interval = 93,
chance = 12,
action = function(pos, node)
local split = node.name:split(":")
local mname = split[1]
local pname = split[2]
pname = pname:gsub("seed_", "")
pname = pname:gsub("_%d+", "")
local plant_height = minetest.get_item_group(node.name, pname)
-- return if already full grown
@ -303,7 +235,7 @@ hades_farming.register_plant = function(name, def)
local node_def = minetest.registered_items[node.name] or nil
-- grow seed
if minetest.get_item_group(node.name, "seed") and node_def.fertility then
if minetest.get_item_group(node.name, "seed") ~= 0 and node_def.fertility then
local can_grow = false
local soil_node = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
if not soil_node then
@ -315,7 +247,7 @@ hades_farming.register_plant = function(name, def)
end
end
if can_grow then
minetest.set_node(pos, {name = node.name:gsub("seed_", "") .. "_1", param2 = node.param2})
minetest.set_node(pos, {name = mname .. ":" .. pname .. "_1", param2 = node.param2})
end
return
end

View File

@ -1,2 +1,2 @@
name = hades_farming
depends = hades_sounds, hades_core, hades_grass, wool
depends = hades_sounds, hades_core, hades_seeds, hades_grass, wool

129
mods/hades_seeds/init.lua Normal file
View File

@ -0,0 +1,129 @@
local S = minetest.get_translator("hades_seeds")
local DEFAULT_MINLIGHT = 8
local DEFAULT_MAXLIGHT = minetest.LIGHT_MAX
hades_seeds = {}
-- Seed placement
-- * itemstack, placer, pointed_thing: Same as node's on_place function
-- * nodename: Name of seed node to place
-- * surface_check: Function that takes the node on which the seed is placed as argument,
-- must return true if seed is allowed to be placed here
hades_seeds.place_seed = function(itemstack, placer, pointed_thing, nodename, surface_check)
local pt = pointed_thing
-- check if pointing at a node
if not pt then
return
end
if pt.type ~= "node" then
return
end
local under = minetest.get_node(pt.under)
local above = minetest.get_node(pt.above)
local udef = minetest.registered_nodes[under.name]
if udef and udef.on_rightclick and
((not placer) or (placer and not placer:get_player_control().sneak)) then
return udef.on_rightclick(pt.under, under, placer, itemstack,
pt) or itemstack
end
-- return if any of the nodes is not registered
if not minetest.registered_nodes[under.name] then
return
end
if not minetest.registered_nodes[above.name] then
return
end
-- check if pointing at the top of the node
if pt.above.y ~= pt.under.y+1 then
return
end
-- check if you can replace the node above the pointed node
if not minetest.registered_nodes[above.name].buildable_to then
return
end
-- check if placed on correct surface
if not surface_check(under) then
return
end
minetest.sound_play({name="hades_seeds_seed_place", gain=1.0}, {pos=pt.above}, true)
-- add the node and remove 1 item from the itemstack
local pdef = minetest.registered_nodes[nodename]
minetest.add_node(pt.above, {name = nodename, param2 = pdef.place_param2})
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
return itemstack
end
-- Register seed node.
-- name: itemstring
-- def: Definition table:
-- * description: Same as for normal node def
-- * inventory_image: Same as for normal node def
-- * place_param2: Same as for normal node def
-- * surface_check: Same as for hades_seeds.place_seed
-- * _tt_help: Tooltip extension (for 'tt' mod)
-- * fertilty: internal argument required for hades_farming plants only
hades_seeds.register_seed = function(name, def)
local placename = name
if string.sub(name, 1, 1) == ":" then
placename = string.sub(name, 2)
end
-- Check def table
if not def.inventory_image then
def.inventory_image = "unknown_item.png"
end
if def.meshoptions then
def.place_param2 = def.meshoptions
end
-- Register seed
local g = {seed = 1, snappy = 3, attached_node = 1}
for k, v in pairs(def.extra_groups) do
g[k] = v
end
minetest.register_node(name, {
description = def.description,
_tt_help = def._tt_help,
tiles = {def.inventory_image, def.inventory_image, "blank.png"},
use_texture_alpha = "clip",
inventory_image = def.inventory_image,
wield_image = def.inventory_image,
drawtype = "nodebox",
groups = g,
fertility = def.fertility,
paramtype = "light",
place_param2 = def.place_param2,
walkable = false,
floodable = true,
sunlight_propagates = true,
node_placement_prediction = "",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -31/64, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
},
sounds = {
dig = { name = "hades_seeds_seed_dig", gain = 0.1 },
dug = { name = "hades_seeds_seed_dug", gain = 0.5 },
-- place sound is done in hades_seeds.place_seed
},
on_place = function(itemstack, placer, pointed_thing)
return hades_seeds.place_seed(itemstack, placer, pointed_thing, placename, def.surface_check)
end
})
end

View File

@ -0,0 +1,2 @@
name = hades_seeds
description = API to register placable seed nodes