diff options
author | bashterm <2001flyingpigs14@gmail.com> | 2016-03-06 21:34:58 -0500 |
---|---|---|
committer | Auke Kok <sofar@foo-projects.org> | 2016-03-13 22:12:40 -0700 |
commit | 77d00903ad964319b74e13503fcb1e3877c9768e (patch) | |
tree | 6c34785950c37bf8cc753415a282c430fa6ade07 /tools.lua | |
parent | 25ebe3ecfaade9923bfb03e2e0041ad3e7d740fa (diff) |
Allow Disabling of Hydration mechanics
Disables the hydration mechanics when the user sets the game difficulty
to easy in the crops_settings.txt file. This makes the mod much easier
to play on easy mode. This was acheived by only executing the parts
of the code that pertain to hydration when the hydration variable in
settings is set to true. Otherwise the code that does hydration is
never executed.
Diffstat (limited to 'tools.lua')
-rw-r--r-- | tools.lua | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/tools.lua b/tools.lua new file mode 100644 index 0000000..5605254 --- /dev/null +++ b/tools.lua @@ -0,0 +1,119 @@ +--[[ + +Copyright (C) 2015 - Auke Kok <sofar@foo-projects.org> + +"crops" is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 +of the license, or (at your option) any later version. + +--]] +minetest.register_tool("crops:watering_can", { + description = "Watering Can", + inventory_image = "crops_watering_can.png", + liquids_pointable = true, + range = 2.5, + stack_max = 1, + wear = 65535, + tool_capabilities = {}, + on_use = function(itemstack, user, pointed_thing) + local pos = pointed_thing.under + local ppos = pos + if not pos then + return itemstack + end + -- filling it up? + local wear = itemstack:get_wear() + if minetest.get_item_group(minetest.get_node(pos).name, "water") >= 3 then + if wear ~= 1 then + minetest.sound_play("crops_watercan_entering", {pos=pos, gain=0.8}) + minetest.after(math.random()/2, function(pos) + if math.random(2) == 1 then + minetest.sound_play("crops_watercan_splash_quiet", {pos=pos, gain=0.1}) + end + if math.random(3) == 1 then + minetest.after(math.random()/2, function(pos) + minetest.sound_play("crops_watercan_splash_small", {pos=pos, gain=0.7}) + end, pos) + end + if math.random(3) == 1 then + minetest.after(math.random()/2, function(pos) + minetest.sound_play("crops_watercan_splash_big", {pos=pos, gain=0.7}) + end, pos) + end + end, pos) + itemstack:set_wear(1) + end + 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 + meta = minetest.get_meta({x=pos.x, y=pos.y-1, z=pos.z}) + end + -- using it on a plant? + local water = meta:get_int("crops_water") + if water < 1 then + return itemstack + end + -- empty? + if wear == 65534 then + return itemstack + end + crops.particles(ppos, 2) + minetest.sound_play("crops_watercan_watering", {pos=pos, gain=0.8}) + water = math.min(water + crops.settings.watercan, crops.settings.watercan_max) + meta:set_int("crops_water", water) + + itemstack:set_wear(math.min(65534, wear + (65535 / crops.settings.watercan_uses))) + return itemstack + end, +}) + +minetest.register_tool("crops:hydrometer", { + description = "Hydrometer", + inventory_image = "crops_hydrometer.png", + liquids_pointable = false, + range = 2.5, + stack_max = 1, + tool_capabilities = { + }, + on_use = function(itemstack, user, pointed_thing) + local pos = pointed_thing.under + if not pos then + return itemstack + end + -- doublesize plant? + local meta = minetest.get_meta(pos) + if meta:get_int("crops_top_half") == 1 then + meta = minetest.get_meta({x=pos.x, y=pos.y-1, z=pos.z}) + end + + -- using it on a plant? + local water = meta:get_int("crops_water") + if water == nil then + itemstack:set_wear(65534) + return itemstack + end + itemstack:set_wear(65535 - ((65534 / 100) * water)) + return itemstack + end, +}) + +minetest.register_craft({ + output = "crops:watering_can", + recipe = { + { "default:steel_ingot", "", "" }, + { "default:steel_ingot", "", "default:steel_ingot" }, + { "", "default:steel_ingot", "" }, + }, +}) + +minetest.register_craft({ + output = "crops:hydrometer", + recipe = { + { "default:mese_crystal_fragment", "", "" }, + { "", "default:steel_ingot", "" }, + { "", "", "default:steel_ingot" }, + }, +}) |