[Mod] Endless Apples [endless_apples]

Shara
Moderator
 
Posts: 158
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

[Mod] Endless Apples [endless_apples]

by Shara » Sat May 05, 2018 12:30

A simple mod that causes default apples to regrow on trees.

Image

Features:
  • Uses node timers, instead of laggy ABMs, so should be very light to run.
  • Apples only regrow when they were placed by mapgen, not when they were placed by players.
  • If tree leaves are removed, the apples no longer regrow.

Download: https://github.com/Ezhh/endless_apples/ ... master.zip

Source: https://github.com/Ezhh/endless_apples

License: This mod is released under MIT.

Dependencies:
default
 

User avatar
TenPlus1
Member
 
Posts: 2419
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1
 

Chem871
Member
 
Posts: 866
Joined: Sat Aug 19, 2017 21:49
Location: SCP-2935
GitHub: Chemguy99
In-game: Nyx Serris

Re: [Mod] Endless Apples [endless_apples]

by Chem871 » Sat May 05, 2018 19:28

Very much, but only if they are crispy.
What is SCP-055 again? I forgot.
 

User avatar
Fixer
Member
 
Posts: 866
Joined: Sun Jul 31, 2011 11:23
Location: Ukraine
IRC: Fixer
In-game: Fixer

Re: [Mod] Endless Apples [endless_apples]

by Fixer » Sat May 05, 2018 19:39

Actually I was wondering for ages why the heck they not regrow in default minetest_game. Performance reasons yet again? Why not include this in default?
 

Shara
Moderator
 
Posts: 158
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Sat May 05, 2018 19:45

Hi Fixer, I think it's simply because no one (to the best of my knowledge) did this with node timers yet. It's very likely I will try and get this added to MTG if no one finds any bugs I can't fix.
 

User avatar
RSLRedstonier
Member
 
Posts: 443
Joined: Wed May 10, 2017 21:00
Location: some were in middle earth
GitHub: RSL-Redstonier
In-game: RSLRedstonier

Re: [Mod] Endless Apples [endless_apples]

by RSLRedstonier » Sat May 05, 2018 19:53

so if I go in the wild and find an apple tree, and break one of the apples the leaf block that the apple was hanging from will overtime regrow the apple but no other leaf block will?
"A programmer is just a tool which converts caffeine into code"

try out my skytest mod always being updated!
https://forum.minetest.net/viewtopic.php?f=9&t=17568
 

Shara
Moderator
 
Posts: 158
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Sat May 05, 2018 19:58

Apples will only regrow where they were originally placed on mapgen, and when that place is next to a leaf node. If you destroy all leaves next to an apple, then the apple won't grow back anymore once removed.
 

Astrobe
Member
 
Posts: 151
Joined: Sun Apr 01, 2018 10:46

Re: [Mod] Endless Apples [endless_apples]

by Astrobe » Sun May 06, 2018 10:40

Shara wrote:Hi Fixer, I think it's simply because no one (to the best of my knowledge) did this with node timers yet. It's very likely I will try and get this added to MTG if no one finds any bugs I can't fix.


I think it needs a slight improvement with regard to configuration. The regrow timer will certainly need to be adapted to the duration of the day and other parameters. As an extreme example, I have hacked MTG's default so that trees grow in one or two IRL days.
Also, for having played with something similar for some time, I think one might want to make the regrowth unreliable, so that trees with four apples don't become "food fountains"; you still have to manage your trees and cut down trees that don't give apples anymore (for games that have a resource management focus).

I think those choices depend heavily on the population size: single player, small server or 24/7 crowded server.

So I suggest something like this:

Code: Select all
local get_apple_timer=function(pos)
   -- this function defines how long it takes to grow an apple
   -- if it returns 0, the apple won't regrow.
   -- the position is passed to the function so that additional environment
   -- checks can be performed
   return math.random(4800, 9600)
end

and then in after_dig_node():
Code: Select all
      local t=get_apple_timer(pos)
      if t>0 then minetest.get_node_timer(pos):start(t) end


A question: why do you re-register the apple node rather than using override_item()?

PS: yep, still no Github account...
 

Shara
Moderator
 
Posts: 158
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Sun May 06, 2018 12:01

Hi Astrobe (get yourself on Github! :P)!

The regrow timer already has an issue here: https://github.com/Ezhh/endless_apples/issues/5. I just haven't got around to deciding on what to use yet. A separate function would be excessive, so that won't happen, but the times do need to be a lot longer.

I am overriding the apple node; I'm just doing it differently. It's mostly just a personal preference, and it probably would be better to change it, but since this is likely to be considered for MTG it's easier to work with the full node definition and see everything at once.
 

bell07
Member
 
Posts: 534
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [Mod] Endless Apples [endless_apples]

by bell07 » Mon May 07, 2018 06:14

Great Mod!

one hint for code: please use minetest.override_item("default:apple", redefinition) instead of minetest.register_node(":default:apple"full_definition"). This way you do not need the full copy of apple definition.

+1 this mod should be in minetest_game
 

Shara
Moderator
 
Posts: 158
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Mon May 07, 2018 10:34

Thanks bell07. I've adjusted the timers now so that it takes at least a couple of days for the apples to regrow and I'll probably make a PR to MTG within the next day or two. The override method won't be important for that, because it will just edit the original node definition there.
 

User avatar
texmex
Member
 
Posts: 1062
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

Re: [Mod] Endless Apples [endless_apples]

by texmex » Mon May 07, 2018 12:16

Shara wrote:The override method won't be important for that, because it will just edit the original node definition there.

Not using override might break other mods that also overrides other parts of the apple definition though, because as of now they would need a dependency on your mod to work properly. For example, I have a nod that redefines the drawtype from plantlike to nodebox.
 

Shara
Moderator
 
Posts: 158
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Mon May 07, 2018 13:25

texmex, my point is that if it gets added to MTG, it's in the default definition anyway, so there won't be an issue. I've already said the other approach is better, but I don't want to change this until I know for sure whether it will get into MTG. After that I don't mind changing it either way.
 

User avatar
texmex
Member
 
Posts: 1062
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex
 

Shara
Moderator
 
Posts: 158
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Mon May 07, 2018 22:59

No problem - I'm glad you took the time to look. :)

PR is in, so now we wait and see.
 

Shara
Moderator
 
Posts: 158
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Wed May 23, 2018 22:48

All done - I'm now considering this mod complete.

Regrowing apples will be included in MTG for 0.5, but if anyone wants them working sooner, this mod will do it and can just be disabled once you switch to 0.5.
 

User avatar
AccidentallyRhine
Member
 
Posts: 228
Joined: Sun Aug 02, 2015 05:43

Re: [Mod] Endless Apples [endless_apples]

by AccidentallyRhine » Thu May 24, 2018 16:43

What about newly grown trees? Will apples only regrow on trees created by mapgen?
 

Shara
Moderator
 
Posts: 158
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Thu May 24, 2018 19:39

It should work on already existing trees and newly grown ones as well, as long as the apples were from mapgen or grown and not placed by hand.
 

User avatar
AccidentallyRhine
Member
 
Posts: 228
Joined: Sun Aug 02, 2015 05:43

Re: [Mod] Endless Apples [endless_apples]

by AccidentallyRhine » Thu May 24, 2018 21:30

Nice work! I may pre-add this to my server until it is mainlined in 0.5.0.
 

Sokomine
Member
 
Posts: 3616
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine

Re: [Mod] Endless Apples [endless_apples]

by Sokomine » Sun Jun 24, 2018 19:08

Shara wrote:Regrowing apples will be included in MTG for 0.5, but if anyone wants them working sooner, this mod will do it and can just be disabled once you switch to 0.5.

That's good news. It was always a pity to have to tear down the entire tree to get more apples. Still, they're mostly useful for craft receipes or feeding horses.
A list of my mods can be found here.
 


Return to Mod Releases



Who is online

Users browsing this forum: No registered users and 7 guests