Merge 32533f4fd7
into 00a0d9a5d4
10
game_api.txt
|
@ -154,21 +154,17 @@ farming.register_plant(name, Plant definition)
|
||||||
---------------
|
---------------
|
||||||
{
|
{
|
||||||
description = "", -- Description for tooltip
|
description = "", -- Description for tooltip
|
||||||
inventory_image = "unknown_item.png", -- Image to be used as wield- and inventory image
|
inventory_image = , -- Image to be used as wield- and inventory image
|
||||||
max_uses = 30, -- Uses until destroyed
|
max_uses = 30, -- Uses until destroyed
|
||||||
material = "", -- Material for recipes
|
material = "", -- Material for recipes
|
||||||
recipe = { -- Craft recipe, if material isn't used
|
recipe = , -- Craft recipe, if material isn't used
|
||||||
{"air", "air", "air"},
|
|
||||||
{"", "group:stick"},
|
|
||||||
{"", "group:stick"},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#Plant definition
|
#Plant definition
|
||||||
-----------------
|
-----------------
|
||||||
{
|
{
|
||||||
description = "", -- Description of seed item
|
description = "", -- Description of seed item
|
||||||
inventory_image = "unknown_item.png", -- Image to be used as seed's wield- and inventory image
|
inventory_image = , -- 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
|
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)
|
^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber)
|
||||||
minlight = 13, -- Minimum light to grow
|
minlight = 13, -- Minimum light to grow
|
||||||
|
|
|
@ -1,43 +1,30 @@
|
||||||
-- Wear out hoes, place soil
|
-- Wear out hoes, place soil
|
||||||
-- TODO Ignore group:flower
|
-- TODO Ignore group:flower
|
||||||
farming.hoe_on_use = function(itemstack, user, pointed_thing, uses)
|
|
||||||
local pt = pointed_thing
|
local creative = minetest.setting_getbool("creative_mode")
|
||||||
-- check if pointing at a node
|
function farming.hoe_on_use(itemstack, user, pt, max_uses)
|
||||||
if not pt then
|
-- check if pointing at a node's top
|
||||||
|
if not pt or pt.type ~= "node" or pt.above.y ~= pt.under.y+1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if pt.type ~= "node" then
|
|
||||||
|
local above = minetest.get_node(pt.above)
|
||||||
|
if above.name ~= "air" or not minetest.registered_nodes[above.name] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local under = minetest.get_node(pt.under)
|
local under = minetest.get_node(pt.under)
|
||||||
local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
|
if not minetest.registered_nodes[under.name] or
|
||||||
local above = minetest.get_node(p)
|
minetest.get_item_group(under.name, "soil") ~= 1 then
|
||||||
|
|
||||||
-- return if any of the nodes is not registered
|
|
||||||
if not minetest.registered_nodes[under.name] then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not minetest.registered_nodes[above.name] then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if the node above the pointed thing is air
|
|
||||||
if above.name ~= "air" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if pointing at soil
|
|
||||||
if minetest.get_item_group(under.name, "soil") ~= 1 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if (wet) soil defined
|
-- check if (wet) soil defined
|
||||||
local regN = minetest.registered_nodes
|
local soil = minetest.registered_nodes[under.name].soil
|
||||||
if regN[under.name].soil == nil or regN[under.name].soil.wet == nil or regN[under.name].soil.dry == nil then
|
if not soil or not soil.wet or not soil.dry then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.is_protected(pt.under, user:get_player_name()) then
|
if minetest.is_protected(pt.under, user:get_player_name()) then
|
||||||
minetest.record_protection_violation(pt.under, user:get_player_name())
|
minetest.record_protection_violation(pt.under, user:get_player_name())
|
||||||
return
|
return
|
||||||
|
@ -47,163 +34,132 @@ farming.hoe_on_use = function(itemstack, user, pointed_thing, uses)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- turn the node into soil, wear out item and play sound
|
-- turn the node into soil, wear out item and play sound
|
||||||
minetest.set_node(pt.under, {name = regN[under.name].soil.dry})
|
minetest.set_node(pt.under, {name = soil.dry})
|
||||||
minetest.sound_play("default_dig_crumbly", {
|
minetest.sound_play("default_dig_crumbly", {
|
||||||
pos = pt.under,
|
pos = pt.under,
|
||||||
gain = 0.5,
|
gain = 0.5,
|
||||||
})
|
})
|
||||||
|
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if creative then
|
||||||
itemstack:add_wear(65535/(uses-1))
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
itemstack:add_wear(65535/(max_uses-1))
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register new hoes
|
-- Register new hoes
|
||||||
farming.register_hoe = function(name, def)
|
function farming.register_hoe(name, def)
|
||||||
-- Check for : prefix (register new hoes in your mod's namespace)
|
-- Check for : prefix (register new hoes in your mod's namespace)
|
||||||
if name:sub(1,1) ~= ":" then
|
if name:sub(1,1) ~= ":" then
|
||||||
name = ":" .. name
|
name = ":" .. name
|
||||||
end
|
end
|
||||||
-- Check def table
|
-- Check def table
|
||||||
if def.description == nil then
|
assert(def.description, "[farming] missing field description (hoe "..name..")")
|
||||||
def.description = "Hoe"
|
assert(def.inventory_image, "[farming] missing field inventory_image (hoe "..name..")")
|
||||||
end
|
|
||||||
if def.inventory_image == nil then
|
local uses = tonumber(def.max_uses)
|
||||||
def.inventory_image = "unknown_item.png"
|
assert(uses and uses > 1, "[farming] max uses are invalid (hoe "..name..")")
|
||||||
end
|
|
||||||
if def.recipe == nil then
|
|
||||||
def.recipe = {
|
|
||||||
{"air","air",""},
|
|
||||||
{"","group:stick",""},
|
|
||||||
{"","group:stick",""}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
if def.max_uses == nil then
|
|
||||||
def.max_uses = 30
|
|
||||||
end
|
|
||||||
-- Register the tool
|
-- Register the tool
|
||||||
minetest.register_tool(name, {
|
minetest.register_tool(name, {
|
||||||
description = def.description,
|
description = def.description,
|
||||||
inventory_image = def.inventory_image,
|
inventory_image = def.inventory_image,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
return farming.hoe_on_use(itemstack, user, pointed_thing, def.max_uses)
|
return farming.hoe_on_use(itemstack, user, pointed_thing, uses)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Register its recipe
|
-- Register its recipe
|
||||||
if def.material == nil then
|
if not def.material then
|
||||||
minetest.register_craft({
|
if def.recipe then
|
||||||
output = name:sub(2),
|
minetest.register_craft({
|
||||||
recipe = def.recipe
|
output = name:sub(2),
|
||||||
})
|
recipe = def.recipe
|
||||||
else
|
})
|
||||||
minetest.register_craft({
|
end
|
||||||
output = name:sub(2),
|
return
|
||||||
recipe = {
|
|
||||||
{def.material, def.material, ""},
|
|
||||||
{"", "group:stick", ""},
|
|
||||||
{"", "group:stick", ""}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
-- Reverse Recipe
|
|
||||||
minetest.register_craft({
|
|
||||||
output = name:sub(2),
|
|
||||||
recipe = {
|
|
||||||
{"", def.material, def.material},
|
|
||||||
{"", "group:stick", ""},
|
|
||||||
{"", "group:stick", ""}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = name:sub(2),
|
||||||
|
recipe = {
|
||||||
|
{def.material, def.material, ""},
|
||||||
|
{"", "group:stick", ""},
|
||||||
|
{"", "group:stick", ""}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Reverse Recipe
|
||||||
|
minetest.register_craft({
|
||||||
|
output = name:sub(2),
|
||||||
|
recipe = {
|
||||||
|
{"", def.material, def.material},
|
||||||
|
{"", "group:stick", ""},
|
||||||
|
{"", "group:stick", ""}
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Seed placement
|
-- Seed placement
|
||||||
farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
|
function farming.place_seed(itemstack, placer, pt, plantname)
|
||||||
local pt = pointed_thing
|
-- check if pointing at a node's top
|
||||||
-- check if pointing at a node
|
if not pt or pt.type ~= "node" or pt.above.y ~= pt.under.y+1 then
|
||||||
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)
|
|
||||||
|
|
||||||
if minetest.is_protected(pt.under, placer:get_player_name()) then
|
|
||||||
minetest.record_protection_violation(pt.under, placer:get_player_name())
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if minetest.is_protected(pt.above, placer:get_player_name()) then
|
|
||||||
minetest.record_protection_violation(pt.above, placer:get_player_name())
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local playername = placer:get_player_name()
|
||||||
-- return if any of the nodes is not registered
|
if minetest.is_protected(pt.under, playername) then
|
||||||
if not minetest.registered_nodes[under.name] then
|
minetest.record_protection_violation(pt.under, playername)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not minetest.registered_nodes[above.name] then
|
if minetest.is_protected(pt.above, playername) then
|
||||||
|
minetest.record_protection_violation(pt.above, playername)
|
||||||
return
|
return
|
||||||
end
|
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
|
-- check if you can replace the node above the pointed node
|
||||||
if not minetest.registered_nodes[above.name].buildable_to then
|
local above = minetest.get_node(pt.above)
|
||||||
|
if not (minetest.registered_nodes[above.name] and
|
||||||
|
minetest.registered_nodes[above.name].buildable_to) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if pointing at soil
|
-- check if pointing at soil
|
||||||
if minetest.get_item_group(under.name, "soil") < 2 then
|
local under = minetest.get_node(pt.under)
|
||||||
|
if not minetest.registered_nodes[under.name] or
|
||||||
|
minetest.get_item_group(under.name, "soil") < 2 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- add the node and remove 1 item from the itemstack
|
-- add the node and remove 1 item from the itemstack
|
||||||
minetest.add_node(pt.above, {name = plantname, param2 = 1})
|
minetest.add_node(pt.above, {name = plantname, param2 = 1})
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
|
||||||
itemstack:take_item()
|
if creative then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
itemstack:take_item()
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register plants
|
-- Register plants
|
||||||
farming.register_plant = function(name, def)
|
function farming.register_plant(name, def)
|
||||||
local mname = name:split(":")[1]
|
|
||||||
local pname = name:split(":")[2]
|
|
||||||
|
|
||||||
-- Check def table
|
-- Check def table
|
||||||
if not def.description then
|
assert(def.steps, "[farming] missing field steps (plant "..name..")")
|
||||||
def.description = "Seed"
|
assert(def.inventory_image, "[farming] missing field inventory_image (plant "..name..")")
|
||||||
end
|
assert(def.description, "[farming] missing field description (plant "..name..")")
|
||||||
if not def.inventory_image then
|
def.fertility = def.fertility or {}
|
||||||
def.inventory_image = "unknown_item.png"
|
|
||||||
end
|
|
||||||
if not def.steps then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
if not def.minlight then
|
|
||||||
def.minlight = 1
|
|
||||||
end
|
|
||||||
if not def.maxlight then
|
|
||||||
def.maxlight = 14
|
|
||||||
end
|
|
||||||
if not def.fertility then
|
|
||||||
def.fertility = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Register seed
|
-- Register seed
|
||||||
local g = {seed = 1, snappy = 3, attached_node = 1}
|
local g = {seed = 1, snappy = 3, attached_node = 1}
|
||||||
for k, v in pairs(def.fertility) do
|
for k, v in pairs(def.fertility) do
|
||||||
g[v] = 1
|
g[v] = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local mname, pname = unpack(name:split(":"))
|
||||||
|
|
||||||
minetest.register_node(":" .. mname .. ":seed_" .. pname, {
|
minetest.register_node(":" .. mname .. ":seed_" .. pname, {
|
||||||
description = def.description,
|
description = def.description,
|
||||||
tiles = {def.inventory_image},
|
tiles = {def.inventory_image},
|
||||||
|
@ -221,7 +177,8 @@ farming.register_plant = function(name, def)
|
||||||
},
|
},
|
||||||
fertility = def.fertility,
|
fertility = def.fertility,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
return farming.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname)
|
return farming.place_seed(itemstack, placer, pointed_thing,
|
||||||
|
mname .. ":seed_" .. pname)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -232,17 +189,16 @@ farming.register_plant = function(name, def)
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Register growing steps
|
-- Register growing steps
|
||||||
for i=1,def.steps do
|
for i = 1, def.steps do
|
||||||
local drop = {
|
local nodegroups = {
|
||||||
items = {
|
snappy = 3,
|
||||||
{items = {mname .. ":" .. pname}, rarity = 9 - i},
|
flammable = 2,
|
||||||
{items = {mname .. ":" .. pname}, rarity= 18 - i * 2},
|
plant = 1,
|
||||||
{items = {mname .. ":seed_" .. pname}, rarity = 9 - i},
|
not_in_creative_inventory = 1,
|
||||||
{items = {mname .. ":seed_" .. pname}, rarity = 18 - i * 2},
|
attached_node = 1
|
||||||
}
|
|
||||||
}
|
}
|
||||||
local nodegroups = {snappy = 3, flammable = 2, plant = 1, not_in_creative_inventory = 1, attached_node = 1}
|
|
||||||
nodegroups[pname] = i
|
nodegroups[pname] = i
|
||||||
|
|
||||||
minetest.register_node(mname .. ":" .. pname .. "_" .. i, {
|
minetest.register_node(mname .. ":" .. pname .. "_" .. i, {
|
||||||
drawtype = "plantlike",
|
drawtype = "plantlike",
|
||||||
waving = 1,
|
waving = 1,
|
||||||
|
@ -250,7 +206,14 @@ farming.register_plant = function(name, def)
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
walkable = false,
|
walkable = false,
|
||||||
buildable_to = true,
|
buildable_to = true,
|
||||||
drop = drop,
|
drop = {
|
||||||
|
items = {
|
||||||
|
{items = {mname .. ":" .. pname}, rarity = 9 - i},
|
||||||
|
{items = {mname .. ":" .. pname}, rarity= 18 - i * 2},
|
||||||
|
{items = {mname .. ":seed_" .. pname}, rarity = 9 - i},
|
||||||
|
{items = {mname .. ":seed_" .. pname}, rarity = 18 - i * 2},
|
||||||
|
}
|
||||||
|
},
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
|
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
|
||||||
|
@ -260,6 +223,9 @@ farming.register_plant = function(name, def)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def.minlight = def.minlight or 1
|
||||||
|
def.maxlight = def.maxlight or 14
|
||||||
|
|
||||||
-- Growing ABM
|
-- Growing ABM
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"group:" .. pname, "group:seed"},
|
nodenames = {"group:" .. pname, "group:seed"},
|
||||||
|
@ -267,40 +233,36 @@ farming.register_plant = function(name, def)
|
||||||
interval = 9,
|
interval = 9,
|
||||||
chance = 20,
|
chance = 20,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
local plant_height = minetest.get_item_group(node.name, pname)
|
|
||||||
|
|
||||||
-- return if already full grown
|
-- return if already full grown
|
||||||
if plant_height == def.steps then
|
if minetest.get_item_group(node.name, pname) == def.steps then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local node_def = minetest.registered_items[node.name] or nil
|
pos.y = pos.y-1
|
||||||
|
local soil_node = minetest.get_node_or_nil(pos)
|
||||||
|
if not soil_node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
pos.y = pos.y+1
|
||||||
|
|
||||||
|
local fertility = minetest.registered_items[node.name].fertility
|
||||||
|
|
||||||
-- grow seed
|
-- grow seed
|
||||||
if minetest.get_item_group(node.name, "seed") and node_def.fertility then
|
if fertility and minetest.get_item_group(node.name, "seed") then
|
||||||
local can_grow = false
|
for _, v in pairs(fertility) do
|
||||||
local soil_node = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
|
|
||||||
if not soil_node then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for _, v in pairs(node_def.fertility) do
|
|
||||||
if minetest.get_item_group(soil_node.name, v) ~= 0 then
|
if minetest.get_item_group(soil_node.name, v) ~= 0 then
|
||||||
can_grow = true
|
node.name = node.name:gsub("seed_", "") .. "_1"
|
||||||
|
minetest.set_node(pos, node)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if can_grow then
|
|
||||||
minetest.set_node(pos, {name = node.name:gsub("seed_", "") .. "_1"})
|
|
||||||
end
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if on wet soil
|
-- check if on wet soil
|
||||||
pos.y = pos.y - 1
|
if minetest.get_item_group(soil_node.name, "soil") < 3 then
|
||||||
local n = minetest.get_node(pos)
|
|
||||||
if minetest.get_item_group(n.name, "soil") < 3 then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
pos.y = pos.y + 1
|
|
||||||
|
|
||||||
-- check light
|
-- check light
|
||||||
local ll = minetest.get_node_light(pos)
|
local ll = minetest.get_node_light(pos)
|
||||||
|
@ -310,14 +272,14 @@ farming.register_plant = function(name, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- grow
|
-- grow
|
||||||
minetest.set_node(pos, {name = mname .. ":" .. pname .. "_" .. plant_height + 1})
|
node.name = mname .. ":" .. pname .. "_" .. plant_height + 1
|
||||||
|
minetest.set_node(pos, node)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Return
|
-- Return
|
||||||
local r = {
|
return {
|
||||||
seed = mname .. ":seed_" .. pname,
|
seed = mname .. ":seed_" .. pname,
|
||||||
harvest = mname .. ":" .. pname
|
harvest = mname .. ":" .. pname
|
||||||
}
|
}
|
||||||
return r
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,13 @@ minetest.register_node("farming:soil", {
|
||||||
description = "Soil",
|
description = "Soil",
|
||||||
tiles = {"default_dirt.png^farming_soil.png", "default_dirt.png"},
|
tiles = {"default_dirt.png^farming_soil.png", "default_dirt.png"},
|
||||||
drop = "default:dirt",
|
drop = "default:dirt",
|
||||||
groups = {crumbly=3, not_in_creative_inventory=1, soil=2, grassland = 1, field = 1},
|
groups = {
|
||||||
|
crumbly = 3,
|
||||||
|
not_in_creative_inventory = 1,
|
||||||
|
soil = 2,
|
||||||
|
grassland = 1,
|
||||||
|
field = 1
|
||||||
|
},
|
||||||
sounds = default.node_sound_dirt_defaults(),
|
sounds = default.node_sound_dirt_defaults(),
|
||||||
soil = {
|
soil = {
|
||||||
base = "default:dirt",
|
base = "default:dirt",
|
||||||
|
@ -31,9 +37,19 @@ minetest.register_node("farming:soil", {
|
||||||
|
|
||||||
minetest.register_node("farming:soil_wet", {
|
minetest.register_node("farming:soil_wet", {
|
||||||
description = "Wet Soil",
|
description = "Wet Soil",
|
||||||
tiles = {"default_dirt.png^farming_soil_wet.png", "default_dirt.png^farming_soil_wet_side.png"},
|
tiles = {
|
||||||
|
"default_dirt.png^farming_soil_wet.png",
|
||||||
|
"default_dirt.png^farming_soil_wet_side.png"
|
||||||
|
},
|
||||||
drop = "default:dirt",
|
drop = "default:dirt",
|
||||||
groups = {crumbly=3, not_in_creative_inventory=1, soil=3, wet = 1, grassland = 1, field = 1},
|
groups = {
|
||||||
|
crumbly = 3,
|
||||||
|
not_in_creative_inventory = 1,
|
||||||
|
soil = 3,
|
||||||
|
wet = 1,
|
||||||
|
grassland = 1,
|
||||||
|
field = 1
|
||||||
|
},
|
||||||
sounds = default.node_sound_dirt_defaults(),
|
sounds = default.node_sound_dirt_defaults(),
|
||||||
soil = {
|
soil = {
|
||||||
base = "default:dirt",
|
base = "default:dirt",
|
||||||
|
@ -54,7 +70,15 @@ minetest.register_node("farming:desert_sand_soil", {
|
||||||
description = "Desert Sand Soil",
|
description = "Desert Sand Soil",
|
||||||
drop = "default:desert_sand",
|
drop = "default:desert_sand",
|
||||||
tiles = {"farming_desert_sand_soil.png", "default_desert_sand.png"},
|
tiles = {"farming_desert_sand_soil.png", "default_desert_sand.png"},
|
||||||
groups = {crumbly=3, not_in_creative_inventory = 1, falling_node=1, sand=1, soil = 2, desert = 1, field = 1},
|
groups = {
|
||||||
|
crumbly = 3,
|
||||||
|
not_in_creative_inventory = 1,
|
||||||
|
falling_node = 1,
|
||||||
|
sand = 1,
|
||||||
|
soil = 2,
|
||||||
|
desert = 1,
|
||||||
|
field = 1
|
||||||
|
},
|
||||||
sounds = default.node_sound_sand_defaults(),
|
sounds = default.node_sound_sand_defaults(),
|
||||||
soil = {
|
soil = {
|
||||||
base = "default:desert_sand",
|
base = "default:desert_sand",
|
||||||
|
@ -66,8 +90,20 @@ minetest.register_node("farming:desert_sand_soil", {
|
||||||
minetest.register_node("farming:desert_sand_soil_wet", {
|
minetest.register_node("farming:desert_sand_soil_wet", {
|
||||||
description = "Wet Desert Sand Soil",
|
description = "Wet Desert Sand Soil",
|
||||||
drop = "default:desert_sand",
|
drop = "default:desert_sand",
|
||||||
tiles = {"farming_desert_sand_soil_wet.png", "farming_desert_sand_soil_wet_side.png"},
|
tiles = {
|
||||||
groups = {crumbly=3, falling_node=1, sand=1, not_in_creative_inventory=1, soil=3, wet = 1, desert = 1, field = 1},
|
"farming_desert_sand_soil_wet.png",
|
||||||
|
"farming_desert_sand_soil_wet_side.png"
|
||||||
|
},
|
||||||
|
groups = {
|
||||||
|
crumbly = 3,
|
||||||
|
falling_node = 1,
|
||||||
|
sand = 1,
|
||||||
|
not_in_creative_inventory = 1,
|
||||||
|
soil = 3,
|
||||||
|
wet = 1,
|
||||||
|
desert = 1,
|
||||||
|
field = 1
|
||||||
|
},
|
||||||
sounds = default.node_sound_sand_defaults(),
|
sounds = default.node_sound_sand_defaults(),
|
||||||
soil = {
|
soil = {
|
||||||
base = "default:desert_sand",
|
base = "default:desert_sand",
|
||||||
|
@ -89,64 +125,75 @@ minetest.register_abm({
|
||||||
interval = 15,
|
interval = 15,
|
||||||
chance = 4,
|
chance = 4,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
local n_def = minetest.registered_nodes[node.name] or nil
|
pos.y = pos.y + 1
|
||||||
local wet = n_def.soil.wet or nil
|
local nn = minetest.get_node_or_nil(pos)
|
||||||
local base = n_def.soil.base or nil
|
if not nn then
|
||||||
local dry = n_def.soil.dry or nil
|
return
|
||||||
if not n_def or not n_def.soil or not wet or not base or not dry then
|
end
|
||||||
|
local nn_def = minetest.registered_nodes[nn.name]
|
||||||
|
pos.y = pos.y - 1
|
||||||
|
|
||||||
|
local soil = minetest.registered_nodes[node.name].soil
|
||||||
|
assert(soil, "[farming] field "..node.name.." doesn't have soil")
|
||||||
|
local wet = soil.wet
|
||||||
|
local base = soil.base
|
||||||
|
local dry = soil.dry
|
||||||
|
assert(wet and base and dry, "[farming] field "..node.name..
|
||||||
|
"'s soil must have wet, base and dry")
|
||||||
|
|
||||||
|
if nn_def and nn_def.walkable and
|
||||||
|
minetest.get_item_group(nn.name, "plant") == 0 then
|
||||||
|
node.name = base
|
||||||
|
minetest.set_node(pos, node)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
pos.y = pos.y + 1
|
-- only turn back if there are no unloaded blocks (and therefore
|
||||||
local nn = minetest.get_node_or_nil(pos)
|
-- possible water sources) nearby
|
||||||
if not nn or not nn.name then
|
if minetest.find_node_near(pos, 3, {"ignore"}) then
|
||||||
return
|
|
||||||
end
|
|
||||||
local nn_def = minetest.registered_nodes[nn.name] or nil
|
|
||||||
pos.y = pos.y - 1
|
|
||||||
|
|
||||||
if nn_def and nn_def.walkable and minetest.get_item_group(nn.name, "plant") == 0 then
|
|
||||||
minetest.set_node(pos, {name = base})
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if there is water nearby
|
-- check if there is water nearby
|
||||||
local wet_lvl = minetest.get_item_group(node.name, "wet")
|
local wet_lvl = minetest.get_item_group(node.name, "wet")
|
||||||
if minetest.find_node_near(pos, 3, {"group:water"}) then
|
if minetest.find_node_near(pos, 3, {"group:water"}) then
|
||||||
-- if it is dry soil and not base node, turn it into wet soil
|
-- if it is dry soil and not base node, turn it into wet soil
|
||||||
if wet_lvl == 0 then
|
if wet_lvl == 0 then
|
||||||
minetest.set_node(pos, {name = wet})
|
node.name = wet
|
||||||
|
minetest.set_node(pos, node)
|
||||||
end
|
end
|
||||||
else
|
return
|
||||||
-- only turn back if there are no unloaded blocks (and therefore
|
end
|
||||||
-- possible water sources) nearby
|
|
||||||
if not minetest.find_node_near(pos, 3, {"ignore"}) then
|
-- turn it back into base if it is already dry
|
||||||
-- turn it back into base if it is already dry
|
if wet_lvl == 0 then
|
||||||
if wet_lvl == 0 then
|
-- only turn it back if there is no plant/seed on top of it
|
||||||
-- only turn it back if there is no plant/seed on top of it
|
if minetest.get_item_group(nn.name, "plant") == 0 and
|
||||||
if minetest.get_item_group(nn.name, "plant") == 0 and minetest.get_item_group(nn.name, "seed") == 0 then
|
minetest.get_item_group(nn.name, "seed") == 0 then
|
||||||
minetest.set_node(pos, {name = base})
|
node.name = base
|
||||||
end
|
minetest.set_node(pos, node)
|
||||||
|
|
||||||
-- if its wet turn it back into dry soil
|
|
||||||
elseif wet_lvl == 1 then
|
|
||||||
minetest.set_node(pos, {name = dry})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- if its wet turn it back into dry soil
|
||||||
|
elseif wet_lvl == 1 then
|
||||||
|
node.name = dry
|
||||||
|
minetest.set_node(pos, node)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
for i = 1, 5 do
|
local defchange = {drop = {
|
||||||
minetest.override_item("default:grass_"..i, {drop = {
|
max_items = 1,
|
||||||
max_items = 1,
|
items = {
|
||||||
items = {
|
{items = {'farming:seed_wheat'},rarity = 5},
|
||||||
{items = {'farming:seed_wheat'},rarity = 5},
|
{items = {'default:grass_1'}},
|
||||||
{items = {'default:grass_1'}},
|
}
|
||||||
}
|
}}
|
||||||
}})
|
for i = 1, 5 do
|
||||||
|
minetest.override_item("default:grass_"..i, defchange)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.override_item("default:junglegrass", {drop = {
|
minetest.override_item("default:junglegrass", {drop = {
|
||||||
max_items = 1,
|
max_items = 1,
|
||||||
items = {
|
items = {
|
||||||
|
|
Before Width: | Height: | Size: 393 B After Width: | Height: | Size: 388 B |
Before Width: | Height: | Size: 159 B After Width: | Height: | Size: 158 B |
Before Width: | Height: | Size: 170 B After Width: | Height: | Size: 163 B |
Before Width: | Height: | Size: 196 B After Width: | Height: | Size: 192 B |
Before Width: | Height: | Size: 467 B After Width: | Height: | Size: 467 B |
Before Width: | Height: | Size: 351 B After Width: | Height: | Size: 351 B |
Before Width: | Height: | Size: 706 B After Width: | Height: | Size: 703 B |
Before Width: | Height: | Size: 677 B After Width: | Height: | Size: 676 B |
Before Width: | Height: | Size: 212 B After Width: | Height: | Size: 212 B |
Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 240 B |
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 168 B |
Before Width: | Height: | Size: 191 B After Width: | Height: | Size: 185 B |
Before Width: | Height: | Size: 218 B After Width: | Height: | Size: 208 B |
Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 223 B |
Before Width: | Height: | Size: 253 B After Width: | Height: | Size: 240 B |
Before Width: | Height: | Size: 310 B After Width: | Height: | Size: 310 B |