[Mod] Endless Apples [endless_apples]

Post Reply
Shara
Moderator
Posts: 179
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

[Mod] Endless Apples [endless_apples]

by Shara » Post

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: 3722
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Endless Apples [endless_apples]

by TenPlus1 » Post

Yay! how do you like them apples :)

Chem871
Member
Posts: 999
Joined: Sat Aug 19, 2017 21:49
GitHub: Chemguy99
In-game: Chem Nyx
Location: My Basement's Attic

Re: [Mod] Endless Apples [endless_apples]

by Chem871 » Post

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

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

Re: [Mod] Endless Apples [endless_apples]

by Fixer » Post

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: 179
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Post

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
TechNolaByte
Member
Posts: 465
Joined: Wed May 10, 2017 21:00
GitHub: TechNolaByte

Re: [Mod] Endless Apples [endless_apples]

by TechNolaByte » Post

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?
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.

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

Re: [Mod] Endless Apples [endless_apples]

by Shara » Post

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: 577
Joined: Sun Apr 01, 2018 10:46

Re: [Mod] Endless Apples [endless_apples]

by Astrobe » Post

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...
My game? It's Minefall.

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

Re: [Mod] Endless Apples [endless_apples]

by Shara » Post

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: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [Mod] Endless Apples [endless_apples]

by bell07 » Post

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: 179
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Post

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: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Endless Apples [endless_apples]

by texmex » Post

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: 179
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: [Mod] Endless Apples [endless_apples]

by Shara » Post

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: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Endless Apples [endless_apples]

by texmex » Post

Right, sorry for overlooking. :)

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

Re: [Mod] Endless Apples [endless_apples]

by Shara » Post

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

PR is in, so now we wait and see.

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

Re: [Mod] Endless Apples [endless_apples]

by Shara » Post

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: 252
Joined: Sun Aug 02, 2015 05:43

Re: [Mod] Endless Apples [endless_apples]

by AccidentallyRhine » Post

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

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

Re: [Mod] Endless Apples [endless_apples]

by Shara » Post

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: 252
Joined: Sun Aug 02, 2015 05:43

Re: [Mod] Endless Apples [endless_apples]

by AccidentallyRhine » Post

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

Sokomine
Member
Posts: 4289
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: [Mod] Endless Apples [endless_apples]

by Sokomine » Post

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.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 26 guests