#5 - extra fruit not always but by change; #9 - debug prints removed

master
A. Demant 2018-10-23 16:26:21 +02:00
parent 9f1a46d836
commit b41709600b
2 changed files with 17 additions and 19 deletions

View File

@ -691,8 +691,6 @@ farming.step_on_punch = function(pos, node, puncher, pointed_thing)
placenode.param2 = def.place_param2
end
minetest.swap_node(pos, placenode)
print(dump(puncher))
print(dump(puncher:get_player_name()))
if puncher ~= nil and puncher:get_player_name() ~= "" then
puncher:get_inventory():add_item('main',def.drop_item)
@ -903,33 +901,26 @@ farming.wilt_on_timer = function(pos, elapsed)
local node = minetest.get_node(pos)
local name = node.name
local def = minetest.registered_nodes[name]
-- print(dump(def))
if def.groups.wiltable <= 2 then -- normal crop
minetest.swap_node(pos, {name="air"})
end
if def.groups.wiltable == 3 then -- nettle or weed
print("nettle")
-- determine all nearby nodes with soil
local pos0=vector.subtract(pos,2)
local pos1=vector.add(pos,2)
local neighb=minetest.find_nodes_in_area(pos0,pos1,"group:soil")
-- print(dump(neighb))
if neighb ~= nil then
local freen={}
-- get soil nodes with air above
for j=1,#neighb do
local jpos=neighb[j]
-- print(dump(minetest.get_node({x=jpos.x,y=jpos.y+1,z=jpos.z})))
if farming.has_value({"air","default:grass_1","default:grass_2","default:grass_3","default:grass_4","default:grass_5"},minetest.get_node({x=jpos.x,y=jpos.y+1,z=jpos.z}).name) then
table.insert(freen,1,jpos)
end
end
-- randomly pick one and spread
if #freen >= 1 then
print(#freen)
local jpos=freen[math.random(1,#freen)]
print(name.." spread "..dump(jpos))
-- print(dump(def))
minetest.add_node({x=jpos.x,y=jpos.y+1,z=jpos.z}, {name = def.seed_name, param2 = 1})
minetest.get_node_timer({x=jpos.x,y=jpos.y+1,z=jpos.z}):start(def.grow_time_min or 10)
end
@ -937,13 +928,10 @@ farming.wilt_on_timer = function(pos, elapsed)
-- after spreading the source has a one third change to be removed, to go one step back or stay
local wran=math.random(1,3)
if wran == 1 then
print("remove")
minetest.swap_node(pos, {name="air"})
end
if wran == 2 then
print("try to go one step back")
if def.pre_step ~= nil then
print("done")
minetest.swap_node(pos, {name=def.pre_step, param2=1})
minetest.get_node_timer(pos):start(math.random(def.grow_time_min or 10,def.grow_time_max or 20))
end
@ -1187,18 +1175,22 @@ farming.billhook_on_use = function(itemstack, user, pointed_thing, uses)
return
end
local tdef=itemstack:get_definition()
if not (creative and creative.is_enabled_for
and creative.is_enabled_for(user:get_player_name())) then
-- wear tool
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
minetest.sound_play(wdef.sound.breaks, {pos = pt.above, gain = 0.5})
if itemstack:get_count() == 0 and tdef.sound and tdef.sound.breaks then
minetest.sound_play(tdef.sound.breaks, {pos = pt.above, gain = 0.5})
end
end
user:get_inventory():add_item('main',pdef.drop_item)
user:get_inventory():add_item('main',pdef.drop_item)
if tdef.farming_change ~= nil then
if math.random(1,tdef.farming_change)==1 then
user:get_inventory():add_item('main',pdef.drop_item)
end
end
-- minetest.node_punch(pt.under, under, user, pointed_thing)
minetest.punch_node(pt.under)
return itemstack

View File

@ -23,7 +23,8 @@ farming.register_hoe(":farming:hoe_steel", {
farming.register_scythe(":farming:scythe_wood", {
description = "Wooden Scythe",
inventory_image = "farming_tool_scythe_wood.png",
-- max_uses = 30,
max_uses = 30,
farming_change = 20,
material = "group:wood",
groups = {flammable = 2},
tool_capabilities = {
@ -38,7 +39,8 @@ farming.register_scythe(":farming:scythe_wood", {
farming.register_scythe(":farming:scythe_stone", {
description = "Stone Scythe",
inventory_image = "farming_tool_scythe_stone.png",
-- max_uses = 60,
max_uses = 60,
farming_change = 10,
material = "group:stone",
groups = {flammable = 2},
tool_capabilities = {
@ -54,13 +56,15 @@ farming.register_scythe(":farming:scythe_steel", {
description = "Steel Scythe",
inventory_image = "farming_tool_scythe_steel.png",
max_uses = 500,
farming_change = 6,
material = "default:steel_ingot",
groups = {flammable = 2},
})
farming.register_billhook(":farming:billhook_wood", {
description = "Wooden Billhook",
inventory_image = "farming_tool_billhook_wood.png",
-- max_uses = 30,
max_uses = 30,
farming_change = 20,
material = "group:wood",
groups = {flammable = 2},
tool_capabilities = {
@ -76,6 +80,7 @@ farming.register_billhook(":farming:billhook_stone", {
description = "Stone Billhook",
inventory_image = "farming_tool_billhook_stone.png",
max_uses = 60,
farming_change = 10,
material = "group:stone",
groups = {flammable = 2},
})
@ -83,6 +88,7 @@ farming.register_billhook(":farming:billhook_steel", {
description = "Steel Billhook",
inventory_image = "farming_tool_billhook_steel.png",
max_uses = 500,
farming_change = 6,
material = "default:steel_ingot",
groups = {flammable = 2},
})