Farming: update and cleanup

This commit is contained in:
MoNTE48 2020-04-28 21:33:22 +02:00
parent be02c70c00
commit 294bd09695
14 changed files with 191 additions and 243 deletions

View File

@ -6,4 +6,5 @@ Authors of source code
----------------------
Originally by PilzAdam (MIT)
webdesigner97 (MIT)
Various Minetest developers and contributors (MIT)
Various Minetest developers and contributors (MIT)
MultiCraft Development Team (MIT)

View File

@ -2,67 +2,55 @@
-- TODO Ignore group:flower
farming.registered_plants = {}
farming.hoe_on_use = function(itemstack, user, pointed_thing, uses)
local pt = pointed_thing
-- check if pointing at a node
if not pt then
return
end
if pt.type ~= "node" then
function farming.hoe_on_use(itemstack, user, pt, uses)
if not pt or pt.type ~= "node" or pt.above.y ~= pt.under.y + 1 then
-- Only nodes pointed on the top can be hoed
return
end
local under = minetest.get_node(pt.under)
local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
local above = minetest.get_node(p)
-- 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
if minetest.get_node(pt.above).name ~= "air" then
-- The hoe is obstructed from moving if there is no free space
return
end
-- check if the node above the pointed thing is air
if above.name ~= "air" then
local node_under = minetest.get_node(pt.under)
local node_under_def = minetest.registered_nodes[node_under.name]
if not node_under_def or
minetest.get_item_group(node_under.name, "soil") ~= 1 then
-- Not a soil node
return
end
-- check if pointing at soil
if minetest.get_item_group(under.name, "soil") ~= 1 then
-- Test if soil properties are defined
local soil = node_under_def.soil
if not soil or not soil.wet or not soil.dry then
return
end
-- check if (wet) soil defined
local regN = minetest.registered_nodes
if regN[under.name].soil == nil or regN[under.name].soil.wet == nil or regN[under.name].soil.dry == nil then
local playername = user and user:get_player_name() or ""
if minetest.is_protected(pt.under, playername) then
minetest.record_protection_violation(pt.under, playername)
return
end
if minetest.is_protected(pt.under, user:get_player_name()) then
minetest.record_protection_violation(pt.under, user:get_player_name())
return
end
if minetest.is_protected(pt.above, user:get_player_name()) then
minetest.record_protection_violation(pt.above, user:get_player_name())
return
end
-- turn the node into soil and play sound
minetest.set_node(pt.under, {name = regN[under.name].soil.dry})
-- Put the node which should appear after applying the hoe
node_under.name = node_under_def.soil.dry
minetest.swap_node(pt.under, node_under)
minetest.sound_play("default_dig_crumbly", {
pos = pt.under,
gain = 0.5,
gain = 0.5
})
if not (creative and creative.is_enabled_for
and creative.is_enabled_for(user:get_player_name())) then
-- wear tool
if creative and creative.is_enabled_for
and creative.is_enabled_for(user:get_player_name()) then
return
end
-- wear tool
itemstack:add_wear(65535 / (uses - 1))
if itemstack:is_empty() then
local wdef = itemstack:get_definition()
itemstack:add_wear(65535/(uses-1))
-- tool break sound
if itemstack:get_count() == 0 and wdef.sound and wdef.sound.breaks then
if wdef.sound and wdef.sound.breaks then
minetest.sound_play(wdef.sound.breaks, {pos = pt.above, gain = 0.5})
end
end
@ -70,7 +58,7 @@ farming.hoe_on_use = function(itemstack, user, pointed_thing, uses)
end
-- 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)
if name:sub(1,1) ~= ":" then
name = ":" .. name
@ -83,11 +71,13 @@ farming.register_hoe = function(name, def)
description = def.description,
inventory_image = def.inventory_image,
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,
def.max_uses) or itemstack
end,
groups = def.groups,
sound = {breaks = "default_tool_breaks"},
})
-- Register its recipe
if def.recipe then
minetest.register_craft({
@ -116,60 +106,43 @@ local function tick_again(pos)
end
-- Seed placement
farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
local pt = pointed_thing
-- check if pointing at a node
if not pt then
return itemstack
end
if pt.type ~= "node" then
return itemstack
end
local under = minetest.get_node(pt.under)
local above = minetest.get_node(pt.above)
local player_name = placer and placer:get_player_name() or ""
if minetest.is_protected(pt.under, player_name) then
minetest.record_protection_violation(pt.under, player_name)
return
end
if minetest.is_protected(pt.above, player_name) then
minetest.record_protection_violation(pt.above, player_name)
function farming.place_seed(itemstack, placer, pt, plantname)
if not pt or pt.type ~= "node" or pt.above.y ~= pt.under.y + 1 then
-- Seeds can only be placed on top of a node
return
end
-- return if any of the nodes is not registered
if not minetest.registered_nodes[under.name] then
return itemstack
end
if not minetest.registered_nodes[above.name] then
return itemstack
local playername = placer and placer:get_player_name() or ""
if minetest.is_protected(pt.above, playername) then
minetest.record_protection_violation(pt.above, playername)
return
end
-- check if pointing at the top of the node
if pt.above.y ~= pt.under.y+1 then
return itemstack
local node_above_def = minetest.registered_nodes[
minetest.get_node(pt.above).name]
if not node_above_def or not node_above_def.buildable_to then
-- We cannot put the seed here
return
end
-- check if you can replace the node above the pointed node
if not minetest.registered_nodes[above.name].buildable_to then
return itemstack
-- The seed must be placed onto a soil node
local node_under = minetest.get_node(pt.under)
if minetest.get_item_group(node_under.name, "soil") < 2 then
return
end
-- check if pointing at soil
if minetest.get_item_group(under.name, "soil") < 2 then
return itemstack
end
-- add the node and remove 1 item from the itemstack
-- Put the seed node
minetest.log("action", playername .. " places node " .. plantname ..
" at " .. minetest.pos_to_string(pt.above))
minetest.add_node(pt.above, {name = plantname, param2 = 1})
tick(pt.above)
if not (creative and creative.is_enabled_for
and creative.is_enabled_for(player_name)) then
itemstack:take_item()
if creative and creative.is_enabled_for
and creative.is_enabled_for(playername) then
return
end
itemstack:take_item()
return itemstack
end
@ -185,14 +158,15 @@ farming.grow_plant = function(pos)
-- grow seed
if minetest.get_item_group(node.name, "seed") and def.fertility then
local soil_node = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
local soil_node = minetest.get_node_or_nil(
{x = pos.x, y = pos.y - 1, z = pos.z})
if not soil_node then
tick_again(pos)
return
end
-- omitted is a check for light, we assume seeds can germinate in the dark.
for _, v in pairs(def.fertility) do
if minetest.get_item_group(soil_node.name, v) ~= 0 then
for _, groupname in pairs(def.fertility) do
if minetest.get_item_group(soil_node.name, groupname) ~= 0 then
local placenode = {name = def.next_plant}
if def.place_param2 then
placenode.param2 = def.place_param2
@ -238,9 +212,9 @@ end
-- Register plants
local singleplayer = minetest.is_singleplayer()
farming.register_plant = function(name, def)
local mname = name:split(":")[1]
local pname = name:split(":")[2]
local find_node_near = minetest.find_node_near
function farming.register_plant(name, def)
local mname, pname = unpack(name:split(":"))
-- Check def table
if not def.description then
@ -266,17 +240,18 @@ farming.register_plant = function(name, def)
-- Register seed
local lbm_nodes = {mname .. ":seed_" .. pname}
local g = {seed = 1, snappy = 3, attached_node = 1, flammable = 2}
for _, v in pairs(def.fertility) do
g[v] = 1
local seed_groups = {seed = 1, snappy = 3, attached_node = 1, flammable = 2}
for _, groupname in pairs(def.fertility) do
seed_groups[groupname] = 1
end
minetest.register_node(":" .. mname .. ":seed_" .. pname, {
description = def.description,
tiles = {def.inventory_image},
inventory_image = def.inventory_image,
wield_image = def.inventory_image,
drawtype = "signlike",
groups = g,
groups = seed_groups,
paramtype = "light",
paramtype2 = "wallmounted",
place_param2 = def.place_param2 or nil, -- this isn't actually used for placement
@ -304,7 +279,8 @@ farming.register_plant = function(name, def)
pointed_thing) or itemstack
end
return farming.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname)
return farming.place_seed(itemstack, placer, pointed_thing,
mname .. ":seed_" .. pname) or itemstack
end,
next_plant = mname .. ":" .. pname .. "_1",
on_timer = farming.grow_plant,
@ -334,8 +310,6 @@ farming.register_plant = function(name, def)
{items = {mname .. ":seed_" .. pname}, rarity = base_rarity * 2}
}
}
local nodegroups = {snappy = 3, flammable = 2, plant = 1, not_in_creative_inventory = 1, attached_node = 1}
nodegroups[pname] = i
local next_plant
@ -358,7 +332,8 @@ farming.register_plant = function(name, def)
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}
},
groups = nodegroups,
groups = {snappy = 3, flammable = 2, plant = 1,
not_in_creative_inventory = 1, attached_node = 1, [pname] = i},
sounds = default.node_sound_leaves_defaults(),
next_plant = next_plant,
on_timer = farming.grow_plant,
@ -366,6 +341,9 @@ farming.register_plant = function(name, def)
maxlight = def.maxlight,
floodable = singleplayer,
on_flood = function(pos, oldnode)
if not singleplayer and not find_node_near(pos, 3,
{"default:water_source", "default:river_water_source"})
then return true end
local items = minetest.get_node_drops(oldnode.name, nil)
for j = 1, #items do
minetest.add_item(pos, ItemStack(items[j]))
@ -383,9 +361,8 @@ farming.register_plant = function(name, def)
})
-- Return
local r = {
return {
seed = mname .. ":seed_" .. pname,
harvest = mname .. ":" .. pname
}
return r
end

View File

@ -60,7 +60,7 @@ minetest.register_craftitem("farming:string",{
minetest.register_craft({
output = "farming:string",
recipe = {{"default:paper", "default:paper"}},
recipe = {{"default:paper", "default:paper"}}
})
-- Straw
@ -76,9 +76,7 @@ minetest.register_craft({
minetest.register_craft({
output = "farming:wheat 3",
recipe = {
{"farming:straw"}
}
recipe = {{"farming:straw"}}
})

View File

@ -5,6 +5,7 @@ The MIT License (MIT)
Copyright (C) 2012-2016 PilzAdam
Copyright (C) 2014-2016 webdesigner97
Copyright (C) 2012-2016 Various Minetest developers and contributors
Copyright (C) 2018-2020 MultiCraft Development Team
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software

View File

@ -25,7 +25,8 @@ minetest.override_item("default:dirt_with_dry_grass", {
minetest.register_node("farming:soil", {
tiles = {"farming_soil.png", "default_dirt.png"},
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(),
soil = {
base = "default:dirt",
@ -37,7 +38,8 @@ minetest.register_node("farming:soil", {
minetest.register_node("farming:soil_wet", {
tiles = {"farming_soil_wet.png", "default_dirt.png"},
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(),
soil = {
base = "default:dirt",
@ -60,49 +62,59 @@ minetest.register_abm({
interval = 15,
chance = 4,
action = function(pos, node)
local n_def = minetest.registered_nodes[node.name] or nil
local wet = n_def.soil.wet or nil
local base = n_def.soil.base or nil
local dry = n_def.soil.dry or nil
if not n_def or not n_def.soil or not wet or not base or not dry then
return
end
pos.y = pos.y + 1
local nn = minetest.get_node_or_nil(pos)
if not nn or not nn.name then
if not nn then
return
end
local nn_def = minetest.registered_nodes[nn.name] or nil
local nn_def = minetest.registered_nodes[nn.name]
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})
local soil = minetest.registered_nodes[node.name].soil
local wet = soil.wet or nil
local base = soil.base or nil
local dry = soil.dry or nil
if not soil or not wet or not base or not dry then
return
end
-- check if there is water nearby
local wet_lvl = minetest.get_item_group(node.name, "wet")
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 wet_lvl == 0 then
minetest.set_node(pos, {name = wet})
end
else
-- only turn back if there are no unloaded blocks (and therefore
-- possible water sources) nearby
if not minetest.find_node_near(pos, 3, {"ignore"}) then
-- turn it back into base if it is already dry
if wet_lvl == 0 then
-- only turn it back if there is no plant/seed on top of it
if minetest.get_item_group(nn.name, "plant") == 0 and minetest.get_item_group(nn.name, "seed") == 0 then
minetest.set_node(pos, {name = base})
end
-- if its wet turn it back into dry soil
elseif wet_lvl == 1 then
minetest.set_node(pos, {name = dry})
end
if nn_def and nn_def.walkable and
minetest.get_item_group(nn.name, "plant") == 0 then
node.name = soil.base
minetest.set_node(pos, node)
return
end
local wet_lvl = minetest.get_item_group(node.name, "wet")
-- Make the node wet if water is near it
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 wet_lvl == 0 then
node.name = soil.wet
minetest.set_node(pos, node)
end
return
end
-- Only dry out if there are no unloaded blocks (and therefore
-- possible water sources) nearby
if minetest.find_node_near(pos, 3, {"ignore"}) then
return
end
-- Turn it back into base if it is already dry and no plant/seed
-- is on top of it
if wet_lvl == 0 then
if minetest.get_item_group(nn.name, "plant") == 0 and
minetest.get_item_group(nn.name, "seed") == 0 then
node.name = soil.base
minetest.set_node(pos, node)
end
-- If it is wet turn it back into dry soil
elseif wet_lvl == 1 then
node.name = soil.dry
minetest.set_node(pos, node)
end
end
})

View File

@ -7,7 +7,7 @@ Extends MultiCraft default farming mod with new plants and crops using only mine
Authors of source code
----------------------
Copyright (C) 2017-2018 SaKeL
Copyright (C) 2019 MultiCraft Development Team
Copyright (C) 2019-2020 MultiCraft Development Team
GNU Lesser General Public License v3.0 or later
@ -53,8 +53,3 @@ Allowed to be used in non-official builds ONLY for personal use.
- farming_addons_melon_6.png - modified by SaKeL
- farming_addons_melon_7.png - modified by SaKeL
- farming_addons_melon_8.png - modified by SaKeL
- farming_addons_wart_block.png
- farming_addons_wart_brick_block.png
- farming_addons_wart_brick.png
- farming_addons_wartrack.png
- farming_addons_wart_red_brick_block.png

View File

@ -1,33 +1,16 @@
-- main class
farming_addons = {}
-- how often node timers for plants will tick
function farming_addons.tick(pos)
minetest.get_node_timer(pos):start(math.random(512, 1024))
end
-- how often a growth failure tick is retried (e.g. too dark)
function farming_addons.tick_short(pos)
local function tick_short(pos)
minetest.get_node_timer(pos):start(math.random(256, 768))
end
-- just shorthand for minetest metadata handling
function farming_addons.meta_get_str(key, pos)
local meta = minetest.get_meta(pos)
return meta:get_string(key)
end
-- just shorthand for minetest metadata handling
function farming_addons.meta_set_str(key, value, pos)
local meta = minetest.get_meta(pos)
meta:set_string(key, value)
end
-- grow blocks next to the plant
function farming_addons.grow_block(pos)
local node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
local random_pos = false
local spawn_positions = {}
local right_pos = {x = pos.x + 1, y = pos.y, z = pos.z}
local front_pos = {x = pos.x, y = pos.y, z = pos.z + 1}
local left_pos = {x = pos.x - 1, y = pos.y, z = pos.z}
@ -36,7 +19,6 @@ function farming_addons.grow_block(pos)
local front = minetest.get_node(front_pos)
local left = minetest.get_node(left_pos)
local back = minetest.get_node(back_pos)
local def = minetest.registered_nodes[node.name]
local children = {}
@ -58,7 +40,7 @@ function farming_addons.grow_block(pos)
for _, child_pos in pairs(children) do
-- print(side, minetest.pos_to_string(child_pos))
local parent_pos_from_child = farming_addons.meta_get_str("parent", child_pos)
local parent_pos_from_child = minetest.get_meta(child_pos):get_string("parent")
-- disable timer for fully grown plant - fruit for this stem already exists
if minetest.pos_to_string(pos) == parent_pos_from_child then
@ -67,34 +49,36 @@ function farming_addons.grow_block(pos)
end
-- make sure that at least one side of the plant has space to put fruit
local spawn_pos = {}
if right.name == "air" then
spawn_positions[#spawn_positions+1] = right_pos
spawn_pos[#spawn_pos+1] = right_pos
end
if front.name == "air" then
spawn_positions[#spawn_positions+1] = front_pos
spawn_pos[#spawn_pos+1] = front_pos
end
if left.name == "air" then
spawn_positions[#spawn_positions+1] = left_pos
spawn_pos[#spawn_pos+1] = left_pos
end
if back.name == "air" then
spawn_positions[#spawn_positions+1] = back_pos
spawn_pos[#spawn_pos+1] = back_pos
end
-- plant is closed from all sides
if #spawn_positions < 1 then
farming_addons.tick_short(pos)
if #spawn_pos < 1 then
tick_short(pos)
return
else
-- pick random from the open sides
local pick_random
if #spawn_positions == 1 then
pick_random = #spawn_positions
if #spawn_pos == 1 then
pick_random = #spawn_pos
else
pick_random = math.random(1, #spawn_positions)
pick_random = math.random(1, #spawn_pos)
end
for k, v in pairs (spawn_positions) do
for k, v in pairs(spawn_pos) do
if k == pick_random then
random_pos = v
end
@ -104,14 +88,14 @@ function farming_addons.grow_block(pos)
-- check light
local light = minetest.get_node_light(pos)
if not light or light < 12 then
farming_addons.tick_short(pos)
tick_short(pos)
return
end
-- spawn block
if random_pos then
minetest.set_node(random_pos, {name = def.next_plant})
farming_addons.meta_set_str("parent", minetest.pos_to_string(pos), random_pos)
minetest.get_meta(random_pos):set_string("parent", minetest.pos_to_string(pos))
end
return
end

View File

@ -23,7 +23,7 @@ minetest.override_item("farming_addons:carrot", {
pointed_thing) or itemstack
end
return farming.place_seed(itemstack, placer, pointed_thing, "farming_addons:seed_carrot")
return farming.place_seed(itemstack, placer, pointed_thing, "farming_addons:seed_carrot") or itemstack
end
})

View File

@ -238,7 +238,7 @@ minetest.register_node("farming_addons:cocoa_3", {
is_ground_content = false,
drop = {
items = {
{items = {"farming_addons:cocoa_bean"}, rarity = 1},
{items = {"farming_addons:cocoa_bean"}},
{items = {"farming_addons:cocoa_bean"}, rarity = 2},
{items = {"farming_addons:cocoa_bean"}, rarity = 2}
}
@ -270,16 +270,6 @@ minetest.register_node("farming_addons:cocoa_3", {
minlight = 10
})
-- replacement LBM for pre-nodetimer plants
minetest.register_lbm({
name = "farming_addons:start_nodetimer_cocoa",
nodenames = {
"farming_addons:cocoa_1",
"farming_addons:cocoa_2"
},
action = tick_again
})
-- grow cocoa in jungletrees
local find_node_near = minetest.find_node_near
local get_node = minetest.get_node
@ -292,8 +282,8 @@ minetest.register_abm({
chance = 50,
catch_up = false,
action = function(pos)
if get_time() >= 0.25 and get_time() < 0.8 then
if find_node_near(pos, 3, "group:cocoa")
if get_time() > 0.25 and get_time() < 0.8 then
if find_node_near(pos, 4, "group:cocoa")
then return end
local apos = {x = pos.x, y = pos.y, z = pos.z}
@ -317,7 +307,7 @@ minetest.register_abm({
})
-- Cocoa
minetest.register_craft( {
minetest.register_craft({
output = "dye:brown 2",
recipe = {
{"farming_addons:cocoa_bean"}
@ -331,7 +321,7 @@ minetest.register_craftitem("farming_addons:cookie", {
on_use = minetest.item_eat(2)
})
minetest.register_craft( {
minetest.register_craft({
output = "farming_addons:cookie 8",
recipe = {
{"farming:wheat", "farming_addons:cocoa_bean", "farming:wheat"}
@ -345,7 +335,7 @@ minetest.register_craftitem("farming_addons:chocolate", {
groups = {food = 1}
})
minetest.register_craft( {
minetest.register_craft({
output = "farming_addons:chocolate",
recipe = {
{"", "", "farming_addons:cocoa_bean"},

View File

@ -22,7 +22,7 @@ minetest.override_item("farming_addons:corn", {
pointed_thing) or itemstack
end
return farming.place_seed(itemstack, placer, pointed_thing, "farming_addons:seed_corn")
return farming.place_seed(itemstack, placer, pointed_thing, "farming_addons:seed_corn") or itemstack
end
})
@ -74,12 +74,9 @@ minetest.register_craftitem("farming_addons:corn_baked", {
on_use = minetest.item_eat(8)
})
minetest.register_craft({
type = "cooking",
cooktime = 10,
output = "farming_addons:corn_baked",
recipe = "farming_addons:corn"
})

View File

@ -44,12 +44,3 @@ minetest.register_craft({
{"", "farming_addons:bowl", ""}
}
})
minetest.register_craft({
output = "farming_addons:bowl_hog_stew",
recipe = {
{"", "mobs:pork_raw", ""},
{"farming_addons:carrot", "farming_addons:potato_baked", "flowers:mushroom_red"},
{"", "farming_addons:bowl", ""}
}
})

View File

@ -14,15 +14,20 @@ minetest.override_item("farming_addons:melon", {
on_use = minetest.item_eat(2)
})
-- how often node timers for plants will tick
local function tick(pos)
minetest.get_node_timer(pos):start(math.random(512, 1024))
end
-- MELON FRUIT - HARVEST
minetest.register_node("farming_addons:melon_fruit", {
description = "Melon",
tiles = {"farming_addons_melon_fruit_top.png", "farming_addons_melon_fruit_top.png", "farming_addons_melon_fruit_side.png", "farming_addons_melon_fruit_side.png", "farming_addons_melon_fruit_side.png", "farming_addons_melon_fruit_side.png"},
tiles = {"farming_addons_melon_fruit_top.png", "farming_addons_melon_fruit_top.png", "farming_addons_melon_fruit_side.png"},
paramtype2 = "facedir",
sounds = default.node_sound_wood_defaults(),
is_ground_content = false,
groups = {snappy = 3, flammable = 4, fall_damage_add_percent = -30, food = 1, not_cuttable = 1},
drop = {
max_items = 7,
items = {
{items = {"farming_addons:melon"}},
{items = {"farming_addons:melon"}},
@ -33,7 +38,7 @@ minetest.register_node("farming_addons:melon_fruit", {
{items = {"farming_addons:melon"}, rarity = 3}
}
},
after_dig_node = function(_, _, oldmetadata, _)
after_dig_node = function(_, _, oldmetadata)
local parent = oldmetadata.fields.parent
local parent_pos_from_child = minetest.string_to_pos(parent)
local parent_node
@ -46,8 +51,8 @@ minetest.register_node("farming_addons:melon_fruit", {
-- tick parent if parent stem still exists
if parent_node ~= nil
and parent_node.name == "farming_addons:melon_8" then
farming_addons.tick(parent_pos_from_child)
and parent_node.name == "farming_addons:melon_8" then
tick(parent_pos_from_child)
end
end
})
@ -58,13 +63,6 @@ minetest.override_item("farming_addons:melon_8", {
on_timer = farming_addons.grow_block
})
-- replacement LBM for pre-nodetimer plants
minetest.register_lbm({
name = "farming_addons:start_nodetimer_melon",
nodenames = {"farming_addons:melon_8"},
action = farming_addons.tick_short
})
-- Melon
minetest.register_craftitem("farming_addons:melon_golden", {
description = "Golden Melon Slice",

View File

@ -23,19 +23,19 @@ minetest.override_item("farming_addons:potato", {
pointed_thing) or itemstack
end
return farming.place_seed(itemstack, placer, pointed_thing, "farming_addons:seed_potato")
end,
return farming.place_seed(itemstack, placer, pointed_thing, "farming_addons:seed_potato") or itemstack
end
})
-- add poisonous potato to drops
minetest.override_item("farming_addons:potato_4", {
drop = {
items = {
{items = {"farming_addons:potato"}, rarity = 1},
{items = {"farming_addons:potato"}},
{items = {"farming_addons:potato"}, rarity = 2},
{items = {"farming_addons:potato"}, rarity = 2},
{items = {"farming_addons:potato_poisonous"}, rarity = 5},
{items = {"farming_addons:seed_potato"}, rarity = 1},
{items = {"farming_addons:seed_potato"}},
{items = {"farming_addons:seed_potato"}, rarity = 2}
}
}

View File

@ -1,6 +1,6 @@
-- spawn snow golem
-- local function pumpkin_on_construct(pos)
--[[if not minetest.get_modpath("mobs_npc") then return end
--[[local function pumpkin_on_construct(pos)
if not minetest.get_modpath("mobs_npc") then return end
for i = 1, 2 do
if minetest.get_node({x = pos.x, y = pos.y - i, z=pos.z}).name ~= "default:snowblock" then
@ -14,7 +14,7 @@
end
minetest.add_entity({x = pos.x, y = pos.y - 1, z = pos.z}, "mobs_npc:snow_golem")
-- end]]
end]]
farming.register_plant("farming_addons:pumpkin", {
description = "Pumpkin Seed",
@ -22,9 +22,14 @@ farming.register_plant("farming_addons:pumpkin", {
steps = 8,
minlight = 12,
fertility = {"grassland", "desert"},
groups = {flammable = 4, food = 1},
groups = {flammable = 4, food = 1}
})
-- how often node timers for plants will tick
local function tick(pos)
minetest.get_node_timer(pos):start(math.random(512, 1024))
end
-- PUMPKIN FRUIT - HARVEST
minetest.register_node("farming_addons:pumpkin_fruit", {
description = "Pumpkin",
@ -46,27 +51,26 @@ minetest.register_node("farming_addons:pumpkin_fruit", {
-- tick parent if parent stem still exists
if parent_node ~= nil
and parent_node.name == "farming_addons:pumpkin_8" then
farming_addons.tick(parent_pos_from_child)
and parent_node.name == "farming_addons:pumpkin_8" then
tick(parent_pos_from_child)
end
end,
-- on_construct = pumpkin_on_construct
})
-- drop blocks instead of items
minetest.register_alias_force("farming_addons:pumpkin", "farming_addons:pumpkin_fruit")
minetest.register_alias_force("farming_addons:pumpkin", "farming_addons:seed_pumpkin")
-- take over the growth from minetest_game farming from here
-- take over the growth from farming from here
minetest.override_item("farming_addons:pumpkin_8", {
next_plant = "farming_addons:pumpkin_fruit",
on_timer = farming_addons.grow_block
})
-- replacement LBM for pre-nodetimer plants
minetest.register_lbm({
name = "farming_addons:start_nodetimer_pumpkin",
nodenames = {"farming_addons:pumpkin_8"},
action = farming_addons.tick_short
on_timer = farming_addons.grow_block,
drop = {
items = {
{items = {"farming_addons:seed_pumpkin"}},
{items = {"farming_addons:seed_pumpkin"}, rarity = 2},
{items = {"farming_addons:seed_pumpkin"}, rarity = 3}
}
}
})
-- pumpkin as fuel