From bf6c660aecaf145b2cba466f0a7dad7c3ca9771f Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Sun, 3 May 2015 11:30:30 -0700 Subject: Add damage to potato nodes. Note this is highly unbalanced still. Potatoes grow way too fast and so there's little damage with the default settings. --- potato.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'potato.lua') diff --git a/potato.lua b/potato.lua index 7dbeb0c..2b44cf7 100644 --- a/potato.lua +++ b/potato.lua @@ -89,8 +89,12 @@ minetest.register_node("crops:soil_with_potatoes", { sounds = default.node_sound_dirt_defaults(), on_dig = function(pos, node, digger) local drops = {} - -- fixme account for damage - for i = 1, math.random(3, 5) do + -- damage 0 = drops 3-5 + -- damage 50 = drops 1-3 + -- damage 100 = drops 0-1 + local meta = minetest.get_meta(pos) + local damage = meta:get_int("crops_damage") + for i = 1, math.random(3 - (3 * damage / 100), 5 - (4 * (damage / 100))) do table.insert(drops, "crops:potato") end core.handle_node_drops(pos, drops, digger) @@ -121,6 +125,10 @@ minetest.register_abm({ 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" }) + return + end local n = string.gsub(node.name, "3", "4") n = string.gsub(n, "2", "3") n = string.gsub(n, "1", "2") @@ -151,6 +159,8 @@ minetest.register_abm({ local damage = meta:get_int("crops_damage") local below = { x = pos.x, y = pos.y - 1, z = pos.z} minetest.set_node(below, { name = "crops:soil_with_potatoes" }) + local meta = minetest.get_meta(below) + meta:set_int("crops_damage", damage) end }) -- cgit v1.2.3