2017-08-03 15:02:56 +02:00
|
|
|
-- support for i18n
|
2020-02-15 15:32:06 +01:00
|
|
|
local S = minetest.get_translator("bushes_classic")
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
plantlife_bushes = {}
|
|
|
|
|
|
|
|
-- TODO: add support for nodebreakers? those dig like mese picks
|
2020-07-23 22:10:33 +02:00
|
|
|
local random = math.random
|
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
if not (digger and pos and oldnode) then
|
|
|
|
return
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- find out which bush type we are dealing with
|
2015-01-25 10:00:42 +01:00
|
|
|
local bush_name = ""
|
|
|
|
local can_harvest = false
|
2017-08-03 15:02:56 +02:00
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
if oldnode.name == "bushes:fruitless_bush" then
|
2013-10-29 02:11:37 +01:00
|
|
|
-- this bush has not grown fruits yet (but will eventually)
|
2015-01-25 10:00:42 +01:00
|
|
|
bush_name = oldmetadata.fields.bush_type
|
2013-10-29 02:11:37 +01:00
|
|
|
-- no fruits to be found, so can_harvest stays false
|
|
|
|
else
|
2015-01-25 10:00:42 +01:00
|
|
|
local name_parts = oldnode.name:split(":")
|
|
|
|
if #name_parts >= 2 and name_parts[2] ~= nil then
|
2013-10-29 02:11:37 +01:00
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
name_parts = name_parts[2]:split("_")
|
2013-10-29 02:11:37 +01:00
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
if #name_parts >= 2 and name_parts[1] ~= nil then
|
|
|
|
bush_name = name_parts[1]
|
2013-10-29 02:11:37 +01:00
|
|
|
-- this bush really carries fruits
|
2015-01-25 10:00:42 +01:00
|
|
|
can_harvest = true
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- find out which tool the digger was wielding (if any)
|
2015-01-25 10:00:42 +01:00
|
|
|
local toolstack = digger:get_wielded_item()
|
|
|
|
local capabilities = toolstack:get_tool_capabilities()
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
-- what the player will get
|
2015-01-25 10:00:42 +01:00
|
|
|
local harvested
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
-- failure to find out what the tool can do: destroy the bush and return nothing
|
2015-01-25 10:00:42 +01:00
|
|
|
local groupcaps = capabilities.groupcaps
|
|
|
|
if not groupcaps then
|
|
|
|
return
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
-- digging with the hand or something like that
|
2015-01-25 10:00:42 +01:00
|
|
|
elseif groupcaps.snappy then
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
-- plant a new bush without fruits
|
2018-10-25 16:27:54 +02:00
|
|
|
minetest.swap_node(pos, {type = "node", name = "bushes:fruitless_bush"})
|
2015-01-25 10:00:42 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string('bush_type', bush_name)
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
-- construct the stack of fruits the player will get
|
|
|
|
-- only bushes that have grown fruits can actually give fruits
|
2015-01-25 10:00:42 +01:00
|
|
|
if can_harvest then
|
|
|
|
local amount = "4"
|
|
|
|
harvested = "bushes:" .. bush_name .. " " .. amount
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- something like a shovel
|
2015-01-25 10:00:42 +01:00
|
|
|
elseif groupcaps.crumbly then
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
-- with a chance of 1/3, return 2 bushes
|
2015-01-25 10:00:42 +01:00
|
|
|
local amount
|
2020-07-23 22:10:33 +02:00
|
|
|
if random(1,3) == 1 then
|
2015-01-25 10:00:42 +01:00
|
|
|
amount = "2"
|
2013-10-29 02:11:37 +01:00
|
|
|
else
|
2015-01-25 10:00:42 +01:00
|
|
|
amount = "1"
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
-- return the bush itself
|
2015-01-25 10:00:42 +01:00
|
|
|
harvested = "bushes:" .. bush_name .. "_bush "..amount
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
-- something like an axe
|
2015-01-25 10:00:42 +01:00
|
|
|
elseif groupcaps.choppy then
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
-- the amount of sticks may vary
|
2020-07-23 22:10:33 +02:00
|
|
|
local amount = random(4, 20)
|
2013-10-29 02:11:37 +01:00
|
|
|
-- return some sticks
|
2015-01-25 10:00:42 +01:00
|
|
|
harvested = "default:stick " .. amount
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
-- nothing known - destroy the plant
|
|
|
|
else
|
2015-01-25 10:00:42 +01:00
|
|
|
return
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- give the harvested result to the player
|
2015-01-25 10:00:42 +01:00
|
|
|
if harvested then
|
2013-10-29 02:11:37 +01:00
|
|
|
--minetest.chat_send_player("singleplayer","you would now get "..tostring( harvested ) );
|
2015-01-25 10:18:56 +01:00
|
|
|
local itemstack = ItemStack(harvested)
|
2015-01-25 10:00:42 +01:00
|
|
|
local inventory = digger:get_inventory()
|
2015-01-25 10:18:56 +01:00
|
|
|
if inventory:room_for_item("main", itemstack) then
|
|
|
|
inventory:add_item("main", itemstack)
|
|
|
|
else
|
|
|
|
minetest.item_drop(itemstack, digger, pos)
|
|
|
|
end
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
plantlife_bushes.after_place_node = function(pos, placer, itemstack)
|
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
if not (itemstack and pos) then
|
|
|
|
return
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
local name_parts = itemstack:get_name():split(":")
|
|
|
|
if #name_parts < 2 or name_parts[2] == nil then
|
|
|
|
return
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
name_parts = name_parts[2]:split("_")
|
2013-10-29 02:11:37 +01:00
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
if #name_parts < 2 or name_parts[1] == nil then
|
|
|
|
return
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
|
2018-10-25 16:27:54 +02:00
|
|
|
minetest.swap_node(pos, {name = "bushes:fruitless_bush"})
|
2015-01-25 10:00:42 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("bush_type", name_parts[1])
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
|
2015-08-09 16:11:30 +02:00
|
|
|
-- regrow berries (uses a base abm instead of biome_lib because of the use of metadata).
|
2013-10-29 02:20:10 +01:00
|
|
|
|
2013-10-29 02:11:37 +01:00
|
|
|
minetest.register_abm({
|
2015-01-25 10:00:42 +01:00
|
|
|
nodenames = {"bushes:fruitless_bush"},
|
|
|
|
neighbors = {"group:soil", "group:potting_soil"},
|
2013-10-29 02:20:10 +01:00
|
|
|
interval = 500,
|
2013-11-03 23:46:15 +01:00
|
|
|
chance = 5,
|
2013-10-29 02:11:37 +01:00
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local bush_name = meta:get_string("bush_type")
|
2015-01-21 04:34:21 +01:00
|
|
|
|
2015-01-25 10:00:42 +01:00
|
|
|
if bush_name and bush_name ~= "" then
|
|
|
|
local dirtpos = {x = pos.x, y = pos.y-1, z = pos.z}
|
2013-11-03 23:46:15 +01:00
|
|
|
local dirt = minetest.get_node(dirtpos)
|
2015-01-21 04:34:21 +01:00
|
|
|
local is_soil = minetest.get_item_group(dirt.name, "soil") or minetest.get_item_group(dirt.name, "potting_soil")
|
|
|
|
|
2020-07-23 22:10:33 +02:00
|
|
|
if is_soil and (dirt.name == "farming:soil_wet" or random(1,3) == 1) then
|
2018-10-25 16:27:54 +02:00
|
|
|
minetest.swap_node( pos, {name = "bushes:" .. bush_name .. "_bush"})
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
2013-11-03 23:46:15 +01:00
|
|
|
end
|
|
|
|
end
|
2013-10-29 02:11:37 +01:00
|
|
|
})
|
|
|
|
|
2013-10-29 02:20:10 +01:00
|
|
|
-- Define the basket and bush nodes
|
2013-10-29 02:11:37 +01:00
|
|
|
|
Multiple changes
There are now five bushes in this mod: strawberry, blackberry,
blueberry, raspberry, and gooseberry.
Instead of giving you the fruit, digging a bush now directly gives you
that bush, with a 1/5 chance of getting two.
Craft one bush by itself to turn it into four of the corresponding
fruit. Craft six of that fruit to get the bush back (this is how it was
before, I opted to keep it that way).
Craft:
- - -
S J S
f f f
That is, two sugar, one jungle grass, and three fruit as before, to get
one raw pie of that fruit. Cook it as usual. Heals 2 hearts.
Craft one whole pie by itself to get four slices, each of which heals
1/2 heart.
Craft:
S J S
f f f
f f f
That is, two sugar, one jungle grass, and mix-and-match six fruits to
get two mixed fruit pies. Cook as usual, craft one to get four slices.
Baskets of pies can be crafted the same as before (craft a basket from
four sticks in a "T" shape, then craft one of those plus three pies of
the desired type).
In addition: some moderate rewriting and re-arranging of the code to
facilitating adding the new objects.
Made the bushes lower-resolution (they were 64px, which made them not
fit in so well into the usual 16px landscape - reduced them to 32px.
Ditto for the basket textures. Pies are all 16px.
New textures for the pies.
2013-10-24 03:51:28 +02:00
|
|
|
for i, bush_name in ipairs(bushes_classic.bushes) do
|
2013-10-29 02:11:37 +01:00
|
|
|
|
|
|
|
minetest.register_node(":bushes:basket_"..bush_name, {
|
2017-08-03 15:02:56 +02:00
|
|
|
description = bushes_classic.bushes_descriptions[i][5],
|
2015-01-26 10:10:20 +01:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "bushes_basket_full.obj",
|
2013-10-29 02:11:37 +01:00
|
|
|
tiles = {
|
2015-01-26 10:10:20 +01:00
|
|
|
"bushes_basket_pie_"..bush_name..".png",
|
|
|
|
"bushes_basket.png"
|
2013-10-29 02:11:37 +01:00
|
|
|
},
|
2015-01-26 10:10:20 +01:00
|
|
|
paramtype = "light",
|
2015-03-17 18:34:23 +01:00
|
|
|
paramtype2 = "facedir",
|
2013-11-02 22:12:14 +01:00
|
|
|
on_use = minetest.item_eat(18),
|
2013-10-29 02:11:37 +01:00
|
|
|
groups = { dig_immediate = 3 },
|
|
|
|
})
|
|
|
|
|
2013-11-11 18:42:01 +01:00
|
|
|
local texture_top, texture_bottom
|
|
|
|
|
2014-07-04 23:55:05 +02:00
|
|
|
local groups = {snappy = 3, bush = 1, flammable = 2, attached_node=1}
|
2013-10-29 02:11:37 +01:00
|
|
|
if bush_name == "mixed_berry" then
|
|
|
|
bush_name = "fruitless";
|
2013-11-11 18:42:01 +01:00
|
|
|
texture_top = "bushes_fruitless_bush_top.png"
|
|
|
|
texture_bottom = "bushes_fruitless_bush_bottom.png"
|
2014-07-04 23:55:05 +02:00
|
|
|
groups.not_in_creative_inventory = 1
|
2013-11-11 18:42:01 +01:00
|
|
|
else
|
|
|
|
texture_top = "bushes_bush_top.png"
|
|
|
|
texture_bottom = "bushes_bush_bottom.png"
|
2013-10-29 02:11:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node(":bushes:" .. bush_name .. "_bush", {
|
2017-08-03 15:02:56 +02:00
|
|
|
description = bushes_classic.bushes_descriptions[i][6],
|
2015-01-25 21:06:31 +01:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "bushes_bush.obj",
|
|
|
|
tiles = {"bushes_bush_"..bush_name..".png"},
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
|
|
|
groups = groups,
|
|
|
|
sounds = default.node_sound_leaves_defaults(),
|
|
|
|
drop = "",
|
|
|
|
after_dig_node = function( pos, oldnode, oldmetadata, digger )
|
|
|
|
return plantlife_bushes.after_dig_node(pos, oldnode, oldmetadata, digger);
|
|
|
|
end,
|
|
|
|
after_place_node = function( pos, placer, itemstack )
|
|
|
|
return plantlife_bushes.after_place_node(pos, placer, itemstack);
|
|
|
|
end,
|
Multiple changes
There are now five bushes in this mod: strawberry, blackberry,
blueberry, raspberry, and gooseberry.
Instead of giving you the fruit, digging a bush now directly gives you
that bush, with a 1/5 chance of getting two.
Craft one bush by itself to turn it into four of the corresponding
fruit. Craft six of that fruit to get the bush back (this is how it was
before, I opted to keep it that way).
Craft:
- - -
S J S
f f f
That is, two sugar, one jungle grass, and three fruit as before, to get
one raw pie of that fruit. Cook it as usual. Heals 2 hearts.
Craft one whole pie by itself to get four slices, each of which heals
1/2 heart.
Craft:
S J S
f f f
f f f
That is, two sugar, one jungle grass, and mix-and-match six fruits to
get two mixed fruit pies. Cook as usual, craft one to get four slices.
Baskets of pies can be crafted the same as before (craft a basket from
four sticks in a "T" shape, then craft one of those plus three pies of
the desired type).
In addition: some moderate rewriting and re-arranging of the code to
facilitating adding the new objects.
Made the bushes lower-resolution (they were 64px, which made them not
fit in so well into the usual 16px landscape - reduced them to 32px.
Ditto for the basket textures. Pies are all 16px.
New textures for the pies.
2013-10-24 03:51:28 +02:00
|
|
|
})
|
|
|
|
|
2013-10-29 02:11:37 +01:00
|
|
|
-- do not spawn fruitless bushes
|
|
|
|
if bush_name ~= "fruitless" then
|
|
|
|
table.insert(bushes_classic.spawn_list, "bushes:"..bush_name.."_bush")
|
|
|
|
end
|
Multiple changes
There are now five bushes in this mod: strawberry, blackberry,
blueberry, raspberry, and gooseberry.
Instead of giving you the fruit, digging a bush now directly gives you
that bush, with a 1/5 chance of getting two.
Craft one bush by itself to turn it into four of the corresponding
fruit. Craft six of that fruit to get the bush back (this is how it was
before, I opted to keep it that way).
Craft:
- - -
S J S
f f f
That is, two sugar, one jungle grass, and three fruit as before, to get
one raw pie of that fruit. Cook it as usual. Heals 2 hearts.
Craft one whole pie by itself to get four slices, each of which heals
1/2 heart.
Craft:
S J S
f f f
f f f
That is, two sugar, one jungle grass, and mix-and-match six fruits to
get two mixed fruit pies. Cook as usual, craft one to get four slices.
Baskets of pies can be crafted the same as before (craft a basket from
four sticks in a "T" shape, then craft one of those plus three pies of
the desired type).
In addition: some moderate rewriting and re-arranging of the code to
facilitating adding the new objects.
Made the bushes lower-resolution (they were 64px, which made them not
fit in so well into the usual 16px landscape - reduced them to 32px.
Ditto for the basket textures. Pies are all 16px.
New textures for the pies.
2013-10-24 03:51:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node(":bushes:basket_empty", {
|
2014-03-12 19:06:27 +01:00
|
|
|
description = S("Basket"),
|
2015-01-26 10:10:20 +01:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "bushes_basket_empty.obj",
|
|
|
|
tiles = { "bushes_basket.png" },
|
|
|
|
paramtype = "light",
|
2015-03-17 18:34:23 +01:00
|
|
|
paramtype2 = "facedir",
|
Multiple changes
There are now five bushes in this mod: strawberry, blackberry,
blueberry, raspberry, and gooseberry.
Instead of giving you the fruit, digging a bush now directly gives you
that bush, with a 1/5 chance of getting two.
Craft one bush by itself to turn it into four of the corresponding
fruit. Craft six of that fruit to get the bush back (this is how it was
before, I opted to keep it that way).
Craft:
- - -
S J S
f f f
That is, two sugar, one jungle grass, and three fruit as before, to get
one raw pie of that fruit. Cook it as usual. Heals 2 hearts.
Craft one whole pie by itself to get four slices, each of which heals
1/2 heart.
Craft:
S J S
f f f
f f f
That is, two sugar, one jungle grass, and mix-and-match six fruits to
get two mixed fruit pies. Cook as usual, craft one to get four slices.
Baskets of pies can be crafted the same as before (craft a basket from
four sticks in a "T" shape, then craft one of those plus three pies of
the desired type).
In addition: some moderate rewriting and re-arranging of the code to
facilitating adding the new objects.
Made the bushes lower-resolution (they were 64px, which made them not
fit in so well into the usual 16px landscape - reduced them to 32px.
Ditto for the basket textures. Pies are all 16px.
New textures for the pies.
2013-10-24 03:51:28 +02:00
|
|
|
groups = { dig_immediate = 3 },
|
|
|
|
})
|