diff --git a/barley.lua b/crops/barley.lua similarity index 100% rename from barley.lua rename to crops/barley.lua diff --git a/beanpole.lua b/crops/beans.lua similarity index 100% rename from beanpole.lua rename to crops/beans.lua diff --git a/beetroot.lua b/crops/beetroot.lua similarity index 100% rename from beetroot.lua rename to crops/beetroot.lua diff --git a/blueberry.lua b/crops/blueberry.lua similarity index 100% rename from blueberry.lua rename to crops/blueberry.lua diff --git a/carrot.lua b/crops/carrot.lua similarity index 100% rename from carrot.lua rename to crops/carrot.lua diff --git a/chili.lua b/crops/chili.lua similarity index 100% rename from chili.lua rename to crops/chili.lua diff --git a/cocoa.lua b/crops/cocoa.lua similarity index 100% rename from cocoa.lua rename to crops/cocoa.lua diff --git a/coffee.lua b/crops/coffee.lua similarity index 100% rename from coffee.lua rename to crops/coffee.lua diff --git a/corn.lua b/crops/corn.lua similarity index 100% rename from corn.lua rename to crops/corn.lua diff --git a/cotton.lua b/crops/cotton.lua similarity index 100% rename from cotton.lua rename to crops/cotton.lua diff --git a/cucumber.lua b/crops/cucumber.lua similarity index 100% rename from cucumber.lua rename to crops/cucumber.lua diff --git a/garlic.lua b/crops/garlic.lua similarity index 100% rename from garlic.lua rename to crops/garlic.lua diff --git a/grapes.lua b/crops/grapes.lua similarity index 100% rename from grapes.lua rename to crops/grapes.lua diff --git a/hemp.lua b/crops/hemp.lua similarity index 100% rename from hemp.lua rename to crops/hemp.lua diff --git a/melon.lua b/crops/melon.lua similarity index 100% rename from melon.lua rename to crops/melon.lua diff --git a/onion.lua b/crops/onion.lua similarity index 100% rename from onion.lua rename to crops/onion.lua diff --git a/pea.lua b/crops/peas.lua similarity index 100% rename from pea.lua rename to crops/peas.lua diff --git a/pepper.lua b/crops/pepper.lua similarity index 100% rename from pepper.lua rename to crops/pepper.lua diff --git a/pineapple.lua b/crops/pineapple.lua similarity index 100% rename from pineapple.lua rename to crops/pineapple.lua diff --git a/potato.lua b/crops/potato.lua similarity index 100% rename from potato.lua rename to crops/potato.lua diff --git a/pumpkin.lua b/crops/pumpkin.lua similarity index 100% rename from pumpkin.lua rename to crops/pumpkin.lua diff --git a/raspberry.lua b/crops/raspberry.lua similarity index 100% rename from raspberry.lua rename to crops/raspberry.lua diff --git a/rhubarb.lua b/crops/rhubarb.lua similarity index 100% rename from rhubarb.lua rename to crops/rhubarb.lua diff --git a/tomato.lua b/crops/tomato.lua similarity index 100% rename from tomato.lua rename to crops/tomato.lua diff --git a/wheat.lua b/crops/wheat.lua similarity index 100% rename from wheat.lua rename to crops/wheat.lua diff --git a/donut.lua b/donut.lua deleted file mode 100644 index 9b29d27..0000000 --- a/donut.lua +++ /dev/null @@ -1,76 +0,0 @@ - -local S = farming.intllib - --- Donut (thanks to Bockwurst for making the donut images) -minetest.register_craftitem("farming:donut", { - description = S("Donut"), - inventory_image = "farming_donut.png", - on_use = minetest.item_eat(4), -}) - -minetest.register_craft({ - output = "farming:donut 3", - recipe = { - {"", "group:food_wheat", ""}, - {"group:food_wheat", "group:food_sugar", "group:food_wheat"}, - {"", "group:food_wheat", ""}, - } -}) - --- Chocolate Donut -minetest.register_craftitem("farming:donut_chocolate", { - description = S("Chocolate Donut"), - inventory_image = "farming_donut_chocolate.png", - on_use = minetest.item_eat(6), -}) - -minetest.register_craft({ - output = "farming:donut_chocolate", - recipe = { - {'group:food_cocoa'}, - {'farming:donut'}, - } -}) - --- Apple Donut -minetest.register_craftitem("farming:donut_apple", { - description = S("Apple Donut"), - inventory_image = "farming_donut_apple.png", - on_use = minetest.item_eat(6), -}) - -minetest.register_craft({ - output = "farming:donut_apple", - recipe = { - {'default:apple'}, - {'farming:donut'}, - } -}) - --- Porridge Oats -minetest.register_craftitem("farming:porridge", { - description = S("Porridge"), - inventory_image = "farming_porridge.png", - on_use = minetest.item_eat(6, "farming:bowl"), -}) - -minetest.after(0, function() - - local fluid = "bucket:bucket_water" - local fluid_return = "bucket:bucket_water" - - if minetest.get_modpath("mobs") and mobs and mobs.mod == "redo" then - fluid = "group:food_milk" - fluid_return = "mobs:bucket_milk" - end - - minetest.register_craft({ - type = "shapeless", - output = "farming:porridge", - recipe = { - "group:food_barley", "group:food_barley", "group:food_wheat", - "group:food_wheat", "group:food_bowl", fluid - }, - replacements = {{fluid_return, "bucket:bucket_empty"}} - }) -end) diff --git a/farming.conf_example b/farming.conf_example index 2505054..f652e9c 100644 --- a/farming.conf_example +++ b/farming.conf_example @@ -13,7 +13,6 @@ farming.cucumber = true farming.corn = true farming.coffee = true farming.melon = true -farming.sugar = true farming.pumpkin = true farming.cocoa = true farming.raspberry = true @@ -30,7 +29,6 @@ farming.pepper = true farming.pineapple = true farming.peas = true farming.beetroot = true -farming.donuts = true -- rarety of crops on map, default is 0.001 (higher number = more crops) farming.rarety = 0.002 diff --git a/food.lua b/food.lua index 777e317..f099e53 100644 --- a/food.lua +++ b/food.lua @@ -112,3 +112,77 @@ minetest.register_craft({ output = "farming:garlic_bread", recipe = {"group:food_toast", "group:food_garlic_clove", "group:food_garlic_clove"}, }) + +--= Donuts (thanks to Bockwurst for making the donut images) + +minetest.register_craftitem("farming:donut", { + description = S("Donut"), + inventory_image = "farming_donut.png", + on_use = minetest.item_eat(4), +}) + +minetest.register_craft({ + output = "farming:donut 3", + recipe = { + {"", "group:food_wheat", ""}, + {"group:food_wheat", "group:food_sugar", "group:food_wheat"}, + {"", "group:food_wheat", ""}, + } +}) + +minetest.register_craftitem("farming:donut_chocolate", { + description = S("Chocolate Donut"), + inventory_image = "farming_donut_chocolate.png", + on_use = minetest.item_eat(6), +}) + +minetest.register_craft({ + output = "farming:donut_chocolate", + recipe = { + {'group:food_cocoa'}, + {'farming:donut'}, + } +}) + +minetest.register_craftitem("farming:donut_apple", { + description = S("Apple Donut"), + inventory_image = "farming_donut_apple.png", + on_use = minetest.item_eat(6), +}) + +minetest.register_craft({ + output = "farming:donut_apple", + recipe = { + {'default:apple'}, + {'farming:donut'}, + } +}) + +--= Porridge Oats + +minetest.register_craftitem("farming:porridge", { + description = S("Porridge"), + inventory_image = "farming_porridge.png", + on_use = minetest.item_eat(6, "farming:bowl"), +}) + +minetest.after(0, function() + + local fluid = "bucket:bucket_water" + local fluid_return = "bucket:bucket_water" + + if minetest.get_modpath("mobs") and mobs and mobs.mod == "redo" then + fluid = "group:food_milk" + fluid_return = "mobs:bucket_milk" + end + + minetest.register_craft({ + type = "shapeless", + output = "farming:porridge", + recipe = { + "group:food_barley", "group:food_barley", "group:food_wheat", + "group:food_wheat", "group:food_bowl", fluid + }, + replacements = {{fluid_return, "bucket:bucket_empty"}} + }) +end) diff --git a/hoebomb.lua b/hoebomb.lua deleted file mode 100644 index be8f828..0000000 --- a/hoebomb.lua +++ /dev/null @@ -1,142 +0,0 @@ - --- load support for intllib. -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - - --- hoe bomb function -local function hoe_area(pos, player) - - -- check for protection - if minetest.is_protected(pos, player:get_player_name()) then - minetest.record_protection_violation(pos, player:get_player_name()) - return - end - - local r = 5 -- radius - - -- remove flora (grass, flowers etc.) - local res = minetest.find_nodes_in_area( - {x = pos.x - r, y = pos.y - 1, z = pos.z - r}, - {x = pos.x + r, y = pos.y + 2, z = pos.z + r}, - {"group:flora"}) - - for n = 1, #res do - minetest.swap_node(res[n], {name = "air"}) - end - - -- replace dirt with tilled soil - res = nil - res = minetest.find_nodes_in_area_under_air( - {x = pos.x - r, y = pos.y - 1, z = pos.z - r}, - {x = pos.x + r, y = pos.y + 2, z = pos.z + r}, - {"group:soil"}) - - for n = 1, #res do - minetest.swap_node(res[n], {name = "farming:soil"}) - end -end - - --- throwable hoe bomb -minetest.register_entity("farming:hoebomb_entity", { - physical = true, - visual = "sprite", - visual_size = {x = 1.0, y = 1.0}, - textures = {"farming_hoe_bomb.png"}, - collisionbox = {0,0,0,0,0,0}, - lastpos = {}, - player = "", - - on_step = function(self, dtime) - - if not self.player then - - self.object:remove() - - return - end - - local pos = self.object:get_pos() - - if self.lastpos.x ~= nil then - - local vel = self.object:getvelocity() - - -- only when potion hits something physical - if vel.x == 0 - or vel.y == 0 - or vel.z == 0 then - - if self.player ~= "" then - - -- round up coords to fix glitching through doors - self.lastpos = vector.round(self.lastpos) - - hoe_area(self.lastpos, self.player) - end - - self.object:remove() - - return - - end - end - - self.lastpos = pos - end -}) - - --- actual throwing function -local function throw_potion(itemstack, player) - - local playerpos = player:get_pos() - - local obj = minetest.add_entity({ - x = playerpos.x, - y = playerpos.y + 1.5, - z = playerpos.z - }, "farming:hoebomb_entity") - - local dir = player:get_look_dir() - local velocity = 20 - - obj:setvelocity({ - x = dir.x * velocity, - y = dir.y * velocity, - z = dir.z * velocity - }) - - obj:setacceleration({ - x = dir.x * -3, - y = -9.5, - z = dir.z * -3 - }) - - obj:setyaw(player:get_look_yaw() + math.pi) - obj:get_luaentity().player = player -end - - --- hoe bomb item -minetest.register_craftitem("farming:hoe_bomb", { - description = S("Hoe Bomb (use or throw on grassy areas to hoe land"), - inventory_image = "farming_hoe_bomb.png", - groups = {flammable = 2, not_in_creative_inventory = 1}, - on_use = function(itemstack, user, pointed_thing) - - if pointed_thing.type == "node" then - hoe_area(pointed_thing.above, user) - else - throw_potion(itemstack, user) - - if not farming.is_creative(user:get_player_name()) then - - itemstack:take_item() - - return itemstack - end - end - end, -}) diff --git a/hoes.lua b/hoes.lua index eaacb29..633e6f0 100644 --- a/hoes.lua +++ b/hoes.lua @@ -192,3 +192,141 @@ minetest.override_item("farming:hoe_diamond", { original_description = "Diamond Hoe", description = toolranks.create_description("Diamond Hoe")}) end + + +-- hoe bomb function +local function hoe_area(pos, player) + + -- check for protection + if minetest.is_protected(pos, player:get_player_name()) then + minetest.record_protection_violation(pos, player:get_player_name()) + return + end + + local r = 5 -- radius + + -- remove flora (grass, flowers etc.) + local res = minetest.find_nodes_in_area( + {x = pos.x - r, y = pos.y - 1, z = pos.z - r}, + {x = pos.x + r, y = pos.y + 2, z = pos.z + r}, + {"group:flora"}) + + for n = 1, #res do + minetest.swap_node(res[n], {name = "air"}) + end + + -- replace dirt with tilled soil + res = nil + res = minetest.find_nodes_in_area_under_air( + {x = pos.x - r, y = pos.y - 1, z = pos.z - r}, + {x = pos.x + r, y = pos.y + 2, z = pos.z + r}, + {"group:soil"}) + + for n = 1, #res do + minetest.swap_node(res[n], {name = "farming:soil"}) + end +end + + +-- throwable hoe bomb +minetest.register_entity("farming:hoebomb_entity", { + physical = true, + visual = "sprite", + visual_size = {x = 1.0, y = 1.0}, + textures = {"farming_hoe_bomb.png"}, + collisionbox = {0,0,0,0,0,0}, + lastpos = {}, + player = "", + + on_step = function(self, dtime) + + if not self.player then + + self.object:remove() + + return + end + + local pos = self.object:get_pos() + + if self.lastpos.x ~= nil then + + local vel = self.object:getvelocity() + + -- only when potion hits something physical + if vel.x == 0 + or vel.y == 0 + or vel.z == 0 then + + if self.player ~= "" then + + -- round up coords to fix glitching through doors + self.lastpos = vector.round(self.lastpos) + + hoe_area(self.lastpos, self.player) + end + + self.object:remove() + + return + + end + end + + self.lastpos = pos + end +}) + + +-- actual throwing function +local function throw_potion(itemstack, player) + + local playerpos = player:get_pos() + + local obj = minetest.add_entity({ + x = playerpos.x, + y = playerpos.y + 1.5, + z = playerpos.z + }, "farming:hoebomb_entity") + + local dir = player:get_look_dir() + local velocity = 20 + + obj:setvelocity({ + x = dir.x * velocity, + y = dir.y * velocity, + z = dir.z * velocity + }) + + obj:setacceleration({ + x = dir.x * -3, + y = -9.5, + z = dir.z * -3 + }) + + obj:setyaw(player:get_look_yaw() + math.pi) + obj:get_luaentity().player = player +end + + +-- hoe bomb item +minetest.register_craftitem("farming:hoe_bomb", { + description = S("Hoe Bomb (use or throw on grassy areas to hoe land"), + inventory_image = "farming_hoe_bomb.png", + groups = {flammable = 2, not_in_creative_inventory = 1}, + on_use = function(itemstack, user, pointed_thing) + + if pointed_thing.type == "node" then + hoe_area(pointed_thing.above, user) + else + throw_potion(itemstack, user) + + if not farming.is_creative(user:get_player_name()) then + + itemstack:take_item() + + return itemstack + end + end + end, +}) diff --git a/init.lua b/init.lua index 3364b0f..8baf53e 100644 --- a/init.lua +++ b/init.lua @@ -7,7 +7,7 @@ farming = {} farming.mod = "redo" -farming.version = "20180519" +farming.version = "20180609" farming.path = minetest.get_modpath("farming") farming.select = { type = "fixed", @@ -586,7 +586,6 @@ farming.cucumber = true farming.corn = true farming.coffee = true farming.melon = true -farming.sugar = true farming.pumpkin = true farming.cocoa = true farming.raspberry = true @@ -603,7 +602,6 @@ farming.pepper = true farming.pineapple = true farming.peas = true farming.beetroot = true -farming.donuts = true farming.rarety = 0.002 -- 0.006 @@ -632,37 +630,44 @@ dofile(farming.path.."/grass.lua") dofile(farming.path.."/utensils.lua") -- default crops -dofile(farming.path.."/wheat.lua") -dofile(farming.path.."/cotton.lua") +dofile(farming.path.."/crops/wheat.lua") +dofile(farming.path.."/crops/cotton.lua") --- additional crops and food (if enabled) -if farming.carrot then dofile(farming.path.."/carrot.lua") end -if farming.potato then dofile(farming.path.."/potato.lua") end -if farming.tomato then dofile(farming.path.."/tomato.lua") end -if farming.cucumber then dofile(farming.path.."/cucumber.lua") end -if farming.corn then dofile(farming.path.."/corn.lua") end -if farming.coffee then dofile(farming.path.."/coffee.lua") end -if farming.melon then dofile(farming.path.."/melon.lua") end -if farming.sugar then dofile(farming.path.."/food.lua") end -if farming.pumpkin then dofile(farming.path.."/pumpkin.lua") end -if farming.cocoa then dofile(farming.path.."/cocoa.lua") end -if farming.raspberry then dofile(farming.path.."/raspberry.lua") end -if farming.blueberry then dofile(farming.path.."/blueberry.lua") end -if farming.rhubarb then dofile(farming.path.."/rhubarb.lua") end -if farming.beans then dofile(farming.path.."/beanpole.lua") end -if farming.grapes then dofile(farming.path.."/grapes.lua") end -if farming.barley then dofile(farming.path.."/barley.lua") end -if farming.hemp then dofile(farming.path.."/hemp.lua") end -if farming.garlic then dofile(farming.path.."/garlic.lua") end -if farming.onion then dofile(farming.path.."/onion.lua") end -if farming.pepper then dofile(farming.path.."/pepper.lua") end -if farming.pineapple then dofile(farming.path.."/pineapple.lua") end -if farming.peas then dofile(farming.path.."/pea.lua") end -if farming.beetroot then dofile(farming.path.."/beetroot.lua") end -if farming.chili then dofile(farming.path.."/chili.lua") end -if farming.donuts then dofile(farming.path.."/donut.lua") end +-- helper function +local function ddoo(file, check) + + if check then + dofile(farming.path .. "/crops/" .. file) + end +end + +-- add additional crops and food (if enabled) +ddoo("carrot.lua", farming.carrot) +ddoo("potato.lua", farming.potato) +ddoo("tomato.lua", farming.tomato) +ddoo("cucumber.lua", farming.cucumber) +ddoo("corn.lua", farming.corn) +ddoo("coffee.lua", farming.coffee) +ddoo("melon.lua", farming.melon) +ddoo("pumpkin.lua", farming.pumpkin) +ddoo("cocoa.lua", farming.cocoa) +ddoo("raspberry.lua", farming.raspberry) +ddoo("blueberry.lua", farming.blueberry) +ddoo("rhubarb.lua", farming.rhubarb) +ddoo("beans.lua", farming.beans) +ddoo("grapes.lua", farming.grapes) +ddoo("barley.lua", farming.barley) +ddoo("hemp.lua", farming.hemp) +ddoo("garlic.lua", farming.garlic) +ddoo("onion.lua", farming.onion) +ddoo("pepper.lua", farming.pepper) +ddoo("pineapple.lua", farming.pineapple) +ddoo("peas.lua", farming.peas) +ddoo("beetroot.lua", farming.beetroot) +ddoo("chili.lua", farming.chili) + +dofile(farming.path.."/food.lua") dofile(farming.path.."/mapgen.lua") dofile(farming.path.."/compatibility.lua") -- Farming Plus compatibility -dofile(farming.path.."/hoebomb.lua") dofile(farming.path.."/lucky_block.lua")