summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorAuke Kok <auke-jan.h.kok@intel.com>2015-05-05 23:47:42 -0700
committerAuke Kok <auke-jan.h.kok@intel.com>2015-05-05 23:47:42 -0700
commitfa07d3307ab454b16f84ddc1d5abf60298a5cdeb (patch)
treea6be8973a8f04fd3451ce52f9c92290680d6ed49 /init.lua
parenta4a53ba854114ff2cafb0fd7f76d8d81f485a306 (diff)
Humidity for corn.
Adding some code to handle double sized plants easily. The watering can now redirects water to the bottom, and the hydrometer reads the bottom half water value instead of the top. No ABM's for hydration happen on the top half, so no risk of double damage there.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index e7982ed..d1c52ac 100644
--- a/init.lua
+++ b/init.lua
@@ -146,6 +146,11 @@ minetest.register_tool("crops:watering_can", {
itemstack:set_wear(1)
return itemstack
end
+ -- using it on a top-half part of a plant?
+ local meta = minetest.get_meta(pos)
+ if meta:get_int("crops_top_half") == 1 then
+ pos = {x = pos.x, y = pos.y - 1, z = pos.z}
+ end
-- using it on a plant?
local meta = minetest.get_meta(pos)
local water = meta:get_int("crops_water")
@@ -159,6 +164,7 @@ minetest.register_tool("crops:watering_can", {
end
water = math.min(water + crops.watercan, crops.watercan_max)
meta:set_int("crops_water", water)
+
itemstack:set_wear(math.min(65534, wear + (65535 / crops.watercanuses)))
return itemstack
end,
@@ -177,6 +183,12 @@ minetest.register_tool("crops:hydrometer", {
if pos == nil then
return itemstack
end
+ -- doublesize plant?
+ local meta = minetest.get_meta(pos)
+ if meta:get_int("crops_top_half") == 1 then
+ pos = {x = pos.x, y = pos.y - 1, z = pos.z}
+ end
+
local meta = minetest.get_meta(pos)
-- using it on a plant?
local water = meta:get_int("crops_water")
@@ -254,6 +266,14 @@ minetest.register_abm({
-- dry out the plant
water = math.max(0, water - plant.properties.wateruse )
meta:set_int("crops_water", water)
+
+ -- for convenience, copy water attribute to top half
+ if not plant.properties.doublesize == nil and plant.properties.doublesize then
+ local above = { x = pos.x, y = pos.y + 1, z = pos.z}
+ local meta = minetest.get_meta(above)
+ meta:set_int("crops_water", water)
+ end
+
if water < plant.properties.wither_damage then
crops.particles(pos, 0)
damage = damage + math.random(0,5)