1
0
mirror of https://codeberg.org/tenplus1/farming.git synced 2025-06-29 23:01:00 +02:00

separate food /non-food items from crop files, tidy code

This commit is contained in:
tenplus1
2024-08-11 15:38:55 +01:00
parent cdac09a8f4
commit a9a1b720a3
57 changed files with 3691 additions and 3271 deletions

View File

@ -1,28 +1,22 @@
local S = farming.translate
local tr = minetest.get_modpath("toolranks")
-- translation and mod check
local S = minetest.get_translator("farming")
local mod_tr = minetest.get_modpath("toolranks")
-- Hoe registration function
farming.register_hoe = function(name, def)
-- Check for : prefix (register new hoes in your mod's namespace)
if name:sub(1,1) ~= ":" then
name = ":" .. name
end
if name:sub(1,1) ~= ":" then name = ":" .. name end
-- Check def table
if def.description == nil then
def.description = S("Hoe")
end
if def.description == nil then def.description = S("Hoe") end
if def.inventory_image == nil then
def.inventory_image = "unknown_item.png"
end
if def.inventory_image == nil then def.inventory_image = "unknown_item.png" end
if def.max_uses == nil then
def.max_uses = 30
end
if def.max_uses == nil then def.max_uses = 30 end
-- add hoe group
def.groups = def.groups or {}
@ -32,20 +26,23 @@ farming.register_hoe = function(name, def)
minetest.register_tool(name, {
description = def.description,
inventory_image = def.inventory_image,
groups = def.groups,
sound = {breaks = "default_tool_breaks"},
on_use = function(itemstack, user, pointed_thing)
return farming.hoe_on_use(itemstack, user, pointed_thing, def.max_uses)
end,
groups = def.groups,
sound = {breaks = "default_tool_breaks"}
end
})
-- Register its recipe
if def.recipe then
minetest.register_craft({
output = name:sub(2),
recipe = def.recipe
})
elseif def.material then
minetest.register_craft({
output = name:sub(2),
recipe = {
@ -64,8 +61,7 @@ function farming.hoe_on_use(itemstack, user, pointed_thing, uses)
local pt = pointed_thing
-- am I going to hoe the top of a dirt node?
if not pt or pt.type ~= "node"
or pt.above.y ~= pt.under.y + 1 then
if not pt or pt.type ~= "node" or pt.above.y ~= pt.under.y + 1 then
return
end
@ -82,22 +78,17 @@ function farming.hoe_on_use(itemstack, user, pointed_thing, uses)
-- return if any of the nodes is not registered
if not minetest.registered_nodes[under.name]
or not minetest.registered_nodes[above.name] then
return
end
or not minetest.registered_nodes[above.name] then return end
-- check if the node above the pointed thing is air
if above.name ~= "air" then
return
end
if above.name ~= "air" then return end
-- check if pointing at dirt
if minetest.get_item_group(under.name, "soil") ~= 1 then
return
end
if minetest.get_item_group(under.name, "soil") ~= 1 then return end
-- check if (wet) soil defined
local ndef = minetest.registered_nodes[under.name]
if ndef.soil == nil or ndef.soil.wet == nil or ndef.soil.dry == nil then
return
end
@ -116,14 +107,15 @@ function farming.hoe_on_use(itemstack, user, pointed_thing, uses)
local wear = 65535 / (uses - 1)
if farming.is_creative(user:get_player_name()) then
if tr then
if mod_tr then
wear = 1
else
wear = 0
end
end
if tr then
if mod_tr then
itemstack = toolranks.new_afteruse(itemstack, user, under, {wear = wear})
else
itemstack:add_wear(wear)
@ -188,7 +180,8 @@ farming.register_hoe(":farming:hoe_diamond", {
})
-- Toolranks support
if tr then
if mod_tr then
minetest.override_item("farming:hoe_wood", {
original_description = S("Wood Hoe"),
@ -215,8 +208,8 @@ if tr then
description = toolranks.create_description(S("Diamond Hoe"))})
end
-- hoe bomb function
local function hoe_area(pos, player)
-- check for protection
@ -229,9 +222,8 @@ local function hoe_area(pos, player)
-- 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"})
{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"})
@ -249,8 +241,8 @@ local function hoe_area(pos, player)
end
end
-- throwable hoe bomb entity
-- throwable hoe bomb
minetest.register_entity("farming:hoebomb_entity", {
initial_properties = {
@ -280,9 +272,7 @@ minetest.register_entity("farming:hoebomb_entity", {
local vel = self.object:get_velocity()
-- only when potion hits something physical
if vel.x == 0
or vel.y == 0
or vel.z == 0 then
if vel.x == 0 or vel.y == 0 or vel.z == 0 then
if self.player ~= "" then
@ -303,8 +293,8 @@ minetest.register_entity("farming:hoebomb_entity", {
end
})
-- actual throwing function
local function throw_potion(itemstack, player)
local playerpos = player:get_pos()
@ -327,12 +317,13 @@ local function throw_potion(itemstack, player)
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
@ -381,22 +372,16 @@ minetest.register_tool("farming:scythe_mithril", {
on_use = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
if pointed_thing.type ~= "node" then return end
local pos = pointed_thing.under
local name = placer:get_player_name()
if minetest.is_protected(pos, name) then
return
end
if minetest.is_protected(pos, name) then return end
local node = minetest.get_node_or_nil(pos)
if not node then
return
end
if not node then return end
local def = minetest.registered_nodes[node.name]
@ -414,9 +399,7 @@ minetest.register_tool("farming:scythe_mithril", {
local mname = node.name:split(":")[1]
local pname = node_not_num(node.name:split(":")[2])
if not pname then
return
end
if not pname then return end
-- add dropped items
for _, dropped_item in pairs(drops) do
@ -470,9 +453,11 @@ minetest.register_tool("farming:scythe_mithril", {
return itemstack
end
end,
end
})
-- if moreores found add mithril scythe recipe
if minetest.get_modpath("moreores") then
minetest.register_craft({