From 6ec11d0efcdb38d6b5a2f1f8522f8c8faddfe624 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Mon, 28 Oct 2013 21:11:37 -0400 Subject: [PATCH] Make bushes drop either fruits, whole bushes, or sticks depending on the tool used (or the hand) Uses a re-colored version of the mod's original unadorned strawberry bush image for the "fruitless" bush. --- bushes_classic/nodes.lua | 205 +++++++++++++++--- .../textures/bushes_fruitless_bush.png | Bin 0 -> 1878 bytes 2 files changed, 169 insertions(+), 36 deletions(-) create mode 100644 bushes_classic/textures/bushes_fruitless_bush.png diff --git a/bushes_classic/nodes.lua b/bushes_classic/nodes.lua index f55bf9d..0c1bf54 100644 --- a/bushes_classic/nodes.lua +++ b/bushes_classic/nodes.lua @@ -1,44 +1,146 @@ -for i, bush_name in ipairs(bushes_classic.bushes) do - local desc = bushes_classic.bushes_descriptions[i] - if bush_name ~= "mixed_berry" then - minetest.register_node(":bushes:" .. bush_name .. "_bush", { - description = desc.." Bush", - drawtype = "plantlike", - visual_scale = 1.3, - tiles = { "bushes_" .. bush_name .. "_bush.png" }, - inventory_image = "bushes_" .. bush_name .. "_bush.png", - paramtype = "light", - sunlight_propagates = true, - walkable = false, - groups = { snappy = 3, bush = 1, flammable = 2}, - sounds = default.node_sound_leaves_defaults(), - drop = { - max_items = 2, - items = { - {items = {"bushes:" .. bush_name .. "_bush"}, rarity = 1 }, -- always get at least one on dig - {items = {"bushes:" .. bush_name .. "_bush"}, rarity = 5 }, -- 1/5 chance of getting a second one. - } - }, - }) - minetest.register_craft({ - output = "bushes:"..bush_name.." 4", - recipe = { - { "bushes:"..bush_name.."_bush", }, - } - }) +plantlife_bushes = {} - minetest.register_craft({ - output = "bushes:" .. bush_name .. "_bush", - recipe = { - { "bushes:" .. bush_name, "bushes:" .. bush_name, "bushes:" .. bush_name }, - { "bushes:" .. bush_name, "bushes:" .. bush_name, "bushes:" .. bush_name }, - } - }) +-- TODO: add support for nodebreakers? those dig like mese picks +plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger) + if( not( digger ) or not( pos ) or not (oldnode )) then + return nil; end + -- find out which bush type we are dealing with + local bush_name = ""; + local can_harvest = false; + + if( oldnode.name == 'bushes:fruitless_bush' ) then + -- this bush has not grown fruits yet (but will eventually) + bush_name = oldmetadata[ 'fields' ][ 'bush_type' ]; + -- no fruits to be found, so can_harvest stays false + else + local name_parts = oldnode.name:split( ":" ); + if( #name_parts >= 2 and name_parts[2]~=nil ) then + + name_parts = name_parts[2]:split( "_" ); + + if( #name_parts >= 2 and name_parts[1]~=nil ) then + bush_name = name_parts[1]; + -- this bush really carries fruits + can_harvest = true; + end + end + end + + -- find out which tool the digger was wielding (if any) + local toolstack = digger:get_wielded_item(); + local capabilities = toolstack:get_tool_capabilities(); + + -- what the player will get + local harvested = ""; + local amount = ""; + + -- failure to find out what the tool can do: destroy the bush and return nothing + if( not( capabilities["groupcaps"] )) then + return nil; + + -- digging with the hand or something like that + elseif( capabilities["groupcaps"]["snappy"] ) then + + -- plant a new bush without fruits + minetest.env:add_node(pos,{type='node',name='bushes:fruitless_bush'}) + local meta = minetest.env:get_meta( pos ); + meta:set_string( 'bush_type', bush_name ); + + -- construct the stack of fruits the player will get + -- only bushes that have grown fruits can actually give fruits + if( can_harvest == true ) then + amount = "4"; + harvested = "bushes:"..bush_name.." "..amount; + end + + -- something like a shovel + elseif( capabilities["groupcaps"]["crumbly"] ) then + + -- with a chance of 1/3, return 2 bushes + if( math.random(1,3)==1 ) then + amount = "2"; + else + amount = "1"; + end + -- return the bush itself + harvested = "bushes:" .. bush_name .. "_bush "..amount; + + -- something like an axe + elseif( capabilities["groupcaps"]["choppy"] ) then + + -- the amount of sticks may vary + amount = math.random( 4, 20 ); + -- return some sticks + harvested = "default:stick "..amount; + + -- nothing known - destroy the plant + else + return nil; + end + + -- give the harvested result to the player + if( harvested ~= "" ) then + --minetest.chat_send_player("singleplayer","you would now get "..tostring( harvested ) ); + digger:get_inventory():add_item( "main", harvested ); + end +end + + + +plantlife_bushes.after_place_node = function(pos, placer, itemstack) + + if( not( itemstack ) or not( pos )) then + return nil; + end + + local name_parts = itemstack:get_name():split( ":" ); + if( #name_parts <2 or name_parts[2]==nil ) then + return nil; + end + + name_parts = name_parts[2]:split( "_" ); + + if( #name_parts <2 or name_parts[1]==nil ) then + return nil; + end + + minetest.env:set_node( pos, {type='node',name='bushes:fruitless_bush'}); + local meta = minetest.env:get_meta( pos ); + meta:set_string( 'bush_type', name_parts[1] ); + + return nil; +end + + + +-- regrow berries +minetest.register_abm({ + nodenames = { "bushes:fruitless_bush" }, + interval = 20, + chance = 2, + action = function(pos, node, active_object_count, active_object_count_wider) + + local meta = minetest.env:get_meta( pos ); + local bush_name = meta:get_string( 'bush_type' ); + if( bush_name ~= nil and bush_name ~= '' ) then + minetest.env:set_node( pos, {type='node',name='bushes:'..bush_name..'_bush'}); + end + end +}) + + + + + +for i, bush_name in ipairs(bushes_classic.bushes) do + + local desc = bushes_classic.bushes_descriptions[i] + minetest.register_node(":bushes:basket_"..bush_name, { description = "Basket with "..desc.." Pies", tiles = { @@ -50,9 +152,39 @@ for i, bush_name in ipairs(bushes_classic.bushes) do groups = { dig_immediate = 3 }, }) - table.insert(bushes_classic.spawn_list, "bushes:"..bush_name.."_bush") + if bush_name == "mixed_berry" then + bush_name = "fruitless"; + desc = "currently fruitless"; + end + + minetest.register_node(":bushes:" .. bush_name .. "_bush", { + description = desc.." Bush", + drawtype = "plantlike", + visual_scale = 1.3, + tiles = { "bushes_" .. bush_name .. "_bush.png" }, + inventory_image = "bushes_" .. bush_name .. "_bush.png", + paramtype = "light", + sunlight_propagates = true, + walkable = false, + + groups = { snappy = 3, bush = 1, flammable = 2}, + 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, + }) + + -- do not spawn fruitless bushes + if bush_name ~= "fruitless" then + table.insert(bushes_classic.spawn_list, "bushes:"..bush_name.."_bush") + end end + minetest.register_node(":bushes:basket_empty", { description = "Basket", tiles = { @@ -63,3 +195,4 @@ minetest.register_node(":bushes:basket_empty", { groups = { dig_immediate = 3 }, }) + diff --git a/bushes_classic/textures/bushes_fruitless_bush.png b/bushes_classic/textures/bushes_fruitless_bush.png new file mode 100644 index 0000000000000000000000000000000000000000..ae850eb91f5edbdac6ede837aeabb2fb7027f963 GIT binary patch literal 1878 zcmV-c2dVgpP)^Sxah${spb#NhVi5t}c;O?!J8ygmJ^>OBk$?vz zKtiBIA#oDo;4O}m!Pqm?vvha$UR~?qVMHJy@di9`o~lZ>&i|*g+Z8FOe_uL!MhfM05|;}=-N9@91ivx=>^TAVwt<$me7 zX9|A!<0E1!!Lz}#HOE&R*5@q_Pg3G2As@9-38b5C)`kP>;!%36L6*VHVaOXz&R$UR zND(-9UWGon zC7i@ue^1my0sP=c%VH_T`*#w?tv$khsLz5b42HuTi4|^5v(>23-0cCd;5Nv}7$gJI z1avJx!Xa4#g%UPC_-w7uOo6F2D@z5_#AN2gA#U$vY;2_rCxXAADNlMtWUP);4BsYJ z8GX7$W}Vn-u(s~A|IsE=g+Uk2eRT=@Xe#gjZeKl61lBLkNiB@g%N7?eIQ;xqBTldT zAd0R1lxoG`>R(gVS1i8!Qp`_&YT#EiRZp1Y27`?q%tBLMZBoQJqpc364_Dsc-T+U( zfTX1vmWDaKnr3mqq*gY$a(T?*RgYX0H}9rAeZnTsgr-F7((smcy zRR}^f7N#SZnK$U}=X~_3RD7Zh-+2vX4nq{h23^S>rNlbP~^FA`k2X|u0<%o z?F?WyWYpRx8VV{KqDCR63*%uy90`6&Q?4p93YtxWC(k4ItN}||44EL?BTxla?y#~{ z=Elu2>nA-fzqyN^!gje%zYBIFBaOjy1W+i$Lgy*t{=qlf1LbPsC?_>@lH@)ck{Mgz!RII4@q7yf3!+<7LvFi z8Rj@1Xs?WAsm}*^=H+=wL~(T1U=j<}n#I??xyZ<iYE60 zzV%dzXvQF}%ursPUNOb|L2c%u=8m(#jY zuyoSE6cEE8&ojc^0=KNWdAU&cJPV#XZ_4goMlf#xFd60~)h07^$wiU*Gpr6{J}6l< zCKLABQ#yME%V!%*H@md%!19_R4uvc`C^WYQuCMvarO)YtPutN`mdrGS>*WS>*Y?N~ z2$mItEx~l5*M`+I2K`CS{INOG%^u1rbLCQ(k_%o1=8hOl;)2eW&|K17f4fi*d?7h< z+K^fxgu0H`?@$ReTek|zGmuW9-v-}@B!N=JAd?)g2JPDiHKWagYL8P0yQoK=3p@`g zm7vpwk_)~ESq@r3brJUO96XyQxOJF@&<;_ahcp-A?gr{VnhT-`)o!DtK#eA-y$;Mi zZeSG#^IjRpR#+(9vW4Yq+Tnp<6rt`X{z#+QKkPB)<(Vf_-g?iW