summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crops_settings.txt7
-rw-r--r--init.lua35
-rw-r--r--melon.lua39
-rw-r--r--potato.lua24
-rw-r--r--textures/crops_melon_plant_6.pngbin0 -> 414 bytes
-rw-r--r--tomato.lua40
6 files changed, 84 insertions, 61 deletions
diff --git a/crops_settings.txt b/crops_settings.txt
index e784407..7ab195e 100644
--- a/crops_settings.txt
+++ b/crops_settings.txt
@@ -23,13 +23,6 @@ crops.light = 10
crops.watercan = 25
crops.watercan_max = 89
crops.watercanuses = 20
-crops.waterstart = 50
-crops.wateruse = 1
-crops.night = 5
-crops.soak = 80
-crops.soak_damage = 90
-crops.wither = 20
-crops.wither_damage = 10
crops.max_damage = 50
--[[
diff --git a/init.lua b/init.lua
index a5ad48f..cd65e0c 100644
--- a/init.lua
+++ b/init.lua
@@ -48,7 +48,8 @@ end
crops.plant = function(pos, node)
minetest.set_node(pos, node)
local meta = minetest.get_meta(pos)
- meta:set_int("crops_water", crops.waterstart)
+ local plant = find_plant(node)
+ meta:set_int("crops_water", plant.properties.waterstart)
meta:set_int("crops_damage", 0)
end
@@ -56,9 +57,14 @@ crops.can_grow = function(pos)
if minetest.get_node_light(pos, nil) < crops.light then
return false
end
+ local node = minetest.get_node(pos)
+ local plant = find_plant(node)
+ if not plant then
+ return false
+ end
local meta = minetest.get_meta(pos)
local water = meta:get_int("crops_water")
- if water < crops.wither or water > crops.soak then
+ if water < plant.properties.wither or water > plant.properties.soak then
if math.random(0,1) == 0 then
return false
end
@@ -69,11 +75,6 @@ crops.can_grow = function(pos)
return false
end
end
- local node = minetest.get_node(pos)
- local plant = find_plant(node)
- if not plant then
- return false
- end
-- allow the plant to grow
return true
@@ -130,8 +131,7 @@ minetest.register_tool("crops:watering_can", {
range = 2.5,
stack_max = 1,
wear = 65535,
- tool_capabilities = {
- },
+ tool_capabilities = {},
on_use = function(itemstack, user, pointed_thing)
local pos = pointed_thing.under
if pos == nil then
@@ -216,7 +216,8 @@ dofile(modpath .. "/polebean.lua")
minetest.register_abm({
nodenames = {
"crops:tomato_plant_1", "crops:tomato_plant_2", "crops:tomato_plant_3", "crops:tomato_plant_4", "crops:tomato_plant_5",
- "crops:potato_plant_1", "crops:potato_plant_2", "crops:potato_plant_3", "crops:potato_plant_4"
+ "crops:potato_plant_1", "crops:potato_plant_2", "crops:potato_plant_3", "crops:potato_plant_4",
+ "crops:melon_plant_1", "crops:melon_plant_2", "crops:melon_plant_3", "crops:melon_plant_4", "crops:melon_plant_5"
},
interval = crops.interval,
chance = crops.chance,
@@ -243,23 +244,23 @@ minetest.register_abm({
end
-- compensate for light: at night give some water back to the plant
- if minetest.get_node_light(pos, nil) < crops.night then
+ if minetest.get_node_light(pos, nil) < plant.properties.night then
water = math.min(100, water + 1)
end
-- dry out the plant
- water = math.max(0, water - ( crops.wateruse * plant.wateruse ))
+ water = math.max(0, water - plant.properties.wateruse )
meta:set_int("crops_water", water)
- if water < crops.wither_damage then
+ if water < plant.properties.wither_damage then
crops.particles(pos, 0)
damage = damage + math.random(0,5)
- elseif water < crops.wither then
+ elseif water < plant.properties.wither then
crops.particles(pos, 0)
return
- elseif water > crops.soak_damage then
+ elseif water > plant.properties.soak_damage then
crops.particles(pos, 1)
damage = damage + math.random(0,5)
- elseif water > crops.soak then
+ elseif water > plant.properties.soak then
crops.particles(pos, 1)
return
end
@@ -267,7 +268,7 @@ minetest.register_abm({
-- is it dead?
if damage >= 100 then
- plant.wither(pos)
+ plant.properties.wither(pos)
end
end
})
diff --git a/melon.lua b/melon.lua
index 1473b7c..ec66332 100644
--- a/melon.lua
+++ b/melon.lua
@@ -35,7 +35,7 @@ minetest.register_node("crops:melon_seed", {
if minetest.get_item_group(under.name, "soil") <= 1 then
return
end
- minetest.set_node(pointed_thing.above, {name="crops:melon_plant_1"})
+ crops.plant(pointed_thing.above, {name="crops:melon_plant_1"})
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
@@ -43,7 +43,7 @@ minetest.register_node("crops:melon_seed", {
end
})
-for stage = 1, 5 do
+for stage = 1, 6 do
minetest.register_node("crops:melon_plant_" .. stage , {
description = "melon plant",
tiles = { "crops_melon_plant_" .. stage .. ".png" },
@@ -116,6 +116,7 @@ minetest.register_node("crops:melon", {
dug = { name = "default_dig_choppy" }
}),
on_dig = function(pos, node, digger)
+ -- FIXME correct for damage
local code = minetest.node_dig(pos, node, digger)
for face = 1, 4 do
local s = { x = pos.x + faces[face].x, y = pos.y, z = pos.z + faces[face].z }
@@ -123,7 +124,7 @@ minetest.register_node("crops:melon", {
if n.name == "crops:melon_plant_5_attached" then
-- make sure it was actually attached to this stem
if n.param2 == faces[face].o then
- minetest.set_node(s, { name = "crops:melon_plant_4" })
+ minetest.swap_node(s, { name = "crops:melon_plant_4" })
return code
end
end
@@ -141,14 +142,15 @@ minetest.register_abm({
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
- if minetest.get_node_light(pos, nil) < crops.light then
+ if not crops.can_grow(pos) then
return
end
+ local meta = minetest.get_meta(pos)
local n = string.gsub(node.name, "4", "5")
n = string.gsub(n, "3", "4")
n = string.gsub(n, "2", "3")
n = string.gsub(n, "1", "2")
- minetest.set_node(pos, { name = n })
+ minetest.swap_node(pos, { name = n })
end
})
@@ -161,7 +163,7 @@ minetest.register_abm({
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
- if minetest.get_node_light(pos, nil) < crops.light then
+ if not crops.can_grow(pos) then
return
end
for face = 1, 4 do
@@ -185,7 +187,7 @@ minetest.register_abm({
minetest.registered_nodes[n.name].groups.flora == 1 or
n.name == "air" then
minetest.set_node(t, {name = "crops:melon", param2 = faces[r].m})
- minetest.set_node(pos, {name = "crops:melon_plant_5_attached", param2 = faces[r].r})
+ minetest.swap_node(pos, {name = "crops:melon_plant_5_attached", param2 = faces[r].r})
end
end
})
@@ -205,6 +207,27 @@ minetest.register_abm({
return
end
end
- minetest.set_node(pos, {name = "crops:melon_plant_4" })
+ minetest.swap_node(pos, {name = "crops:melon_plant_4" })
end
})
+
+crops.melon_die = function(pos)
+ minetest.set_node(pos, { name = "crops:melon_plant_6" })
+end
+
+local properties = {
+ wither = crops.melon_die,
+ waterstart = 20,
+ wateruse = 1,
+ night = 5,
+ soak = 80,
+ soak_damage = 90,
+ wither = 20,
+ wither_damage = 10,
+}
+
+table.insert(crops.plants, { name = "crops:melon_plant_1", properties = properties })
+table.insert(crops.plants, { name = "crops:melon_plant_2", properties = properties })
+table.insert(crops.plants, { name = "crops:melon_plant_3", properties = properties })
+table.insert(crops.plants, { name = "crops:melon_plant_4", properties = properties })
+table.insert(crops.plants, { name = "crops:melon_plant_5", properties = properties })
diff --git a/potato.lua b/potato.lua
index 2b44cf7..093b9b5 100644
--- a/potato.lua
+++ b/potato.lua
@@ -123,7 +123,6 @@ minetest.register_abm({
return
end
local meta = minetest.get_meta(pos)
- local water = meta:get_int("crops_water")
local damage = meta:get_int("crops_damage")
if damage == 100 then
minetest.set_node(pos, { name = "crops:potato_plant_5" })
@@ -132,9 +131,7 @@ minetest.register_abm({
local n = string.gsub(node.name, "3", "4")
n = string.gsub(n, "2", "3")
n = string.gsub(n, "1", "2")
- minetest.set_node(pos, { name = n })
- meta:set_int("crops_water", water)
- meta:set_int("crops_damage", damage)
+ minetest.swap_node(pos, { name = n })
end
})
@@ -174,7 +171,18 @@ crops.potato_die = function(pos)
end
end
-table.insert(crops.plants, { name = "crops:potato_plant_1", wateruse = 1.0, wither = crops.potato_die })
-table.insert(crops.plants, { name = "crops:potato_plant_2", wateruse = 1.0, wither = crops.potato_die })
-table.insert(crops.plants, { name = "crops:potato_plant_3", wateruse = 1.0, wither = crops.potato_die })
-table.insert(crops.plants, { name = "crops:potato_plant_4", wateruse = 1.0, wither = crops.potato_die })
+local properties = {
+ wither = crops.potato_die,
+ waterstart = 30,
+ wateruse = 1,
+ night = 5,
+ soak = 80,
+ soak_damage = 90,
+ wither = 20,
+ wither_damage = 10,
+}
+
+table.insert(crops.plants, { name = "crops:potato_plant_1", properties = properties })
+table.insert(crops.plants, { name = "crops:potato_plant_2", properties = properties })
+table.insert(crops.plants, { name = "crops:potato_plant_3", properties = properties })
+table.insert(crops.plants, { name = "crops:potato_plant_4", properties = properties })
diff --git a/textures/crops_melon_plant_6.png b/textures/crops_melon_plant_6.png
new file mode 100644
index 0000000..f5fbe5e
--- /dev/null
+++ b/textures/crops_melon_plant_6.png
Binary files differ
diff --git a/tomato.lua b/tomato.lua
index f289059..72b3638 100644
--- a/tomato.lua
+++ b/tomato.lua
@@ -81,17 +81,13 @@ minetest.register_node("crops:tomato_plant_5" , {
local meta = minetest.get_meta(pos)
local ttl = meta:get_int("crops_tomato_ttl")
- local water = meta:get_int("crops_water")
- local damage = meta:get_int("crops_damage")
if ttl > 1 then
- minetest.set_node(pos, { name = "crops:tomato_plant_4"})
+ minetest.swap_node(pos, { name = "crops:tomato_plant_4"})
meta:set_int("crops_tomato_ttl", ttl - 1)
else
- minetest.set_node(pos, { name = "crops:tomato_plant_6"})
+ minetest.swap_node(pos, { name = "crops:tomato_plant_6"})
meta:set_int("crops_tomato_ttl", 0)
end
- meta:set_int("crops_water", water)
- meta:set_int("crops_damage", damage)
end
})
@@ -133,16 +129,11 @@ minetest.register_abm({
if not crops.can_grow(pos) then
return
end
- local meta = minetest.get_meta(pos)
- local water = meta:get_int("crops_water")
- local damage = meta:get_int("crops_damage")
local n = string.gsub(node.name, "4", "5")
n = string.gsub(n, "3", "4")
n = string.gsub(n, "2", "3")
n = string.gsub(n, "1", "2")
- minetest.set_node(pos, { name = n })
- meta:set_int("crops_water", water)
- meta:set_int("crops_damage", damage)
+ minetest.swap_node(pos, { name = n })
end
})
@@ -160,7 +151,6 @@ minetest.register_abm({
end
local meta = minetest.get_meta(pos)
local ttl = meta:get_int("crops_tomato_ttl")
- local water = meta:get_int("crops_water")
local damage = meta:get_int("crops_damage")
if ttl == 0 then
-- damage 0 - drops 4-6
@@ -169,10 +159,8 @@ minetest.register_abm({
ttl = math.random(4 - (4 * (damage / 100)), 6 - (5 * (damage / 100)))
end
if ttl > 1 then
- minetest.set_node(pos, { name = "crops:tomato_plant_5" })
+ minetest.swap_node(pos, { name = "crops:tomato_plant_5" })
meta:set_int("crops_tomato_ttl", ttl)
- meta:set_int("crops_water", water)
- meta:set_int("crops_damage", damage)
else
-- no luck, plant dead!
minetest.set_node(pos, { name = "crops:tomato_plant_6" })
@@ -184,9 +172,19 @@ crops.tomato_die = function(pos)
minetest.set_node(pos, { name = "crops:tomato_plant_6" })
end
-table.insert(crops.plants, { name = "crops:tomato_plant_1", wateruse = 1.0, wither = crops.tomato_die })
-table.insert(crops.plants, { name = "crops:tomato_plant_2", wateruse = 1.0, wither = crops.tomato_die })
-table.insert(crops.plants, { name = "crops:tomato_plant_3", wateruse = 1.0, wither = crops.tomato_die })
-table.insert(crops.plants, { name = "crops:tomato_plant_4", wateruse = 1.0, wither = crops.tomato_die })
-table.insert(crops.plants, { name = "crops:tomato_plant_5", wateruse = 1.0, wither = crops.tomato_die })
+local properties = {
+ wither = crops.tomato_die,
+ waterstart = 19,
+ wateruse = 1,
+ night = 5,
+ soak = 80,
+ soak_damage = 90,
+ wither = 20,
+ wither_damage = 10,
+}
+table.insert(crops.plants, { name = "crops:tomato_plant_1", properties = properties })
+table.insert(crops.plants, { name = "crops:tomato_plant_2", properties = properties })
+table.insert(crops.plants, { name = "crops:tomato_plant_3", properties = properties })
+table.insert(crops.plants, { name = "crops:tomato_plant_4", properties = properties })
+table.insert(crops.plants, { name = "crops:tomato_plant_5", properties = properties })