[MOD 0.13.x] Tree Sapling Mod v0.1.4

Topics and discussion about specific mods
Post Reply
LukeM
Inserter
Inserter
Posts: 26
Joined: Sun Mar 20, 2016 8:32 pm
Contact:

[MOD 0.13.x] Tree Sapling Mod v0.1.4

Post by LukeM »

Tree Sapling Mod

Note: I am no longer updating this forum page, please go to the factorio mods page for updated details / versions or to let me know of any bugs, or ideas

Description:
This small mod adds saplings that grow into vanilla trees, recipes for saplings, and a technology to unlock them.

Details:
Factorio Version: 0.13.x
Factorio Versions tested: 0.13.20 (not tested in multiplayer)
Latest Mod Version: 0.1.4

Download:
https://mods.factorio.com/mods/LukeM/TreeSaplings

Credits:
Thanks to Shrooblord for the sapling and fertiliser item textures :D
Thanks to ntm for uploading a version for 0.13 while I wasn't here

Changelog:

Version: 0.1.4
Date: 16. 10. 2016
Changes:
- Updated to 0.13.x (apart from probably the multiplayer parts which I haven't been able to test yet)
- Replaced my bad graphics with the much better ones made by Shrooblord (Thanks!)

Version: 0.1.3
Date: 21. 05. 2016
Changes:
- Changed sapling growth code so that the time to grow is calculated when it is placed, rather than every second until it grows

Version: 0.1.2
Date: 22. 03. 2016
Bugfixes:
- Fixed breaking saplings as before they would not stop growing even after destroyed

Bugs:
None currently known, if you find any, please reply and give me as much information about them as possible
Last edited by LukeM on Wed Aug 16, 2017 5:38 pm, edited 7 times in total.

ALittleGreenStone
Burner Inserter
Burner Inserter
Posts: 18
Joined: Thu Mar 17, 2016 12:03 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by ALittleGreenStone »

I'm intrigued, but I do not understand. Do these sapling things become vanilla trees eventually?

seronis
Fast Inserter
Fast Inserter
Posts: 225
Joined: Fri Mar 04, 2016 8:04 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by seronis »

Please SPECIFICALLY list the version of factorio you test with. Its useless in the future if someone is using factorio 0.12.37 and they cant figure out that your mod was only tested with 0.12.22 and there was a change in the script API in the meantime.

That aside what is the performance hit on this? Are you running scripts on every individual sapling that check each tick or is it event based in some manner where updates only occur AS a growth actually needs to happen? Thats the difference between dozens of saplings being the max feasible and thousands of saplings being possible.

LukeM
Inserter
Inserter
Posts: 26
Joined: Sun Mar 20, 2016 8:32 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by LukeM »

ALittleGreenStone wrote:I'm intrigued, but I do not understand. Do these sapling things become vanilla trees eventually?
Yes, every second after 1 minute, the saplings have a chance to become trees, the chance increases until 61 minutes when the chance is 100%, but it is very VERY unlikely it will take this long, so it almost always takes less than 5 minutes. (The chance is (age in seconds - 60) / 3600 but this is likely to change)
seronis wrote:Please SPECIFICALLY list the version of factorio you test with. Its useless in the future if someone is using factorio 0.12.37 and they cant figure out that your mod was only tested with 0.12.22 and there was a change in the script API in the meantime.

That aside what is the performance hit on this? Are you running scripts on every individual sapling that check each tick or is it event based in some manner where updates only occur AS a growth actually needs to happen? Thats the difference between dozens of saplings being the max feasible and thousands of saplings being possible.
1. Ok, I will add it to the main post
2. The performance hit is relatively low I believe, when you place a sapling it adds it to a sapling table, and then every 60 ticks, (once a second) it loops through the list and for each sapling, generates a random number (most likely the most performance heavy part) and if it is less than ((age in seconds - 60)/3600) grows it into a random tree.

seronis
Fast Inserter
Fast Inserter
Posts: 225
Joined: Fri Mar 04, 2016 8:04 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by seronis »

Thats not the worst possible efficiency but its still far from optimal. You should consider using an event queue instead where each update you only process the saplings that are going to grow and dont run any computations at all on the ones that wont. To do this you would precompute the time it will take a given tree to grow using whatever random number generation you like. But this lets you do just ONE calculation on each sapling rather than a calculation per second until it grows. Once you know the time that the sapling will grow you put it in a table that is indexed by the timestamp, and the value at that index is itself a table that contains all the saplings that will grow on that particular 'tick'. This way each update of your mods main loop you do something equivalent to:

Code: Select all

function tick()
   local saplings = table[now]
   if saplings ~= nil
      //we have a table of 1 or more saplings,  process them!
      for _,sap in pairs(saplings) do
         grow(sap)
      end
      table[now] = nil //finished processing.  purge this group of saplings
   end
end
Its been a year(ish) since i've touched lua so that might be a little bad syntax. 'now' there is meant to be a timestamp representing the current tick.

Injen
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Mar 24, 2016 8:06 am
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by Injen »

This is exactly what I was looking for! Thank you so much!

LukeM
Inserter
Inserter
Posts: 26
Joined: Sun Mar 20, 2016 8:32 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by LukeM »

seronis wrote:Thats not the worst possible efficiency but its still far from optimal. You should consider using an event queue instead where each update you only process the saplings that are going to grow and dont run any computations at all on the ones that wont. To do this you would precompute the time it will take a given tree to grow using whatever random number generation you like. But this lets you do just ONE calculation on each sapling rather than a calculation per second until it grows. Once you know the time that the sapling will grow you put it in a table that is indexed by the timestamp, and the value at that index is itself a table that contains all the saplings that will grow on that particular 'tick'.
That seems like a much better idea :) I have no idea why I didn't think of doing it that way in the first place... Probably because I originally had each tree take an exact number of seconds to grow, but then later thought that that was kind of silly, having all saplings grow in the exact same order that they were planted, so added the random part. I will add something similar to what you suggested and will include it in the next version, ty for the help :)
Injen wrote:This is exactly what I was looking for! Thank you so much!
I'm glad that you like it :)

seronis
Fast Inserter
Fast Inserter
Posts: 225
Joined: Fri Mar 04, 2016 8:04 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by seronis »

Right now my main laptop is out of commision and i'm stuck using an Inspirion without a dedicated gpu and only 2gb ram. So im kinda focused on finding mod alternatives that are highly efficient =-) Good luck with those updates.

Speadge
Fast Inserter
Fast Inserter
Posts: 130
Joined: Tue Mar 29, 2016 10:01 am
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by Speadge »

there is a problem with waitex which has some code in it to look for a -1 and -2 filename for tree entities in the base-override.lua:

Code: Select all

--trees are a special case because there is so many files for them. Therefore they are checked here but only if they are of the type tree
if AllowChange("tree") then
	if AllowChange("tree", data.raw["tree"]["tree-01"].variations[1].leaves) then
		for k,trees in pairs(data.raw["tree"]) do
			if trees.variations then
				for k1, treeVariations in pairs(trees.variations) do
					OverrideSprite(treeVariations.leaves)
					local filename = treeVariations.trunk.filename
					filename = string.gsub(filename, ".png", "") -- not good to have it here... oh well
					filename = string.gsub(filename, "__base__", "__WaiTex__")
				
					AddStripes(treeVariations.trunk, nil, nil, 
					{
						{filename.."-1.png", 3, 1},
						{filename.."-2.png", 2, 1}
					})
				end
			end
		end
	end
end

since u are "just" providing a "trunk.png", its missing a trunk-1 and trunk-2 file

LukeM
Inserter
Inserter
Posts: 26
Joined: Sun Mar 20, 2016 8:32 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by LukeM »

Speadge wrote:there is a problem with waitex which has some code in it to look for a -1 and -2 filename for tree entities in the base-override.lua:

Code: Select all

Some code was here
since u are "just" providing a "trunk.png", its missing a trunk-1 and trunk-2 file
I will try to fix that as soon as possible :), ty for telling me about this problem

Edit: The problem here is that WaiTex, when it finds a tree file location, replaces '__base__' with '__WaiTex__' as the rest of the file directories are the same. This does not work with trees from mods, as it cannot change '__base__' with '__WaiTex__' as it is not in the filename (as it begins with __TreeSaplings__ instead) so tries to look for the HD textures inside the other mod's directory, which causes it to crash, as it does not exist. I will try to see if there is anything that I can do to fix this, but it is mostly caused by WaiTex, not TreeSaplings so it may be difficult. I will also try to contact the maker of WaiTex to see if they can fix the problem, as it should be relatively easy for them to do.

Edit 2: Just noticed that they have already responded to the message you put on their forum page, saying that they have already fixed this :)

vanatteveldt
Filter Inserter
Filter Inserter
Posts: 945
Joined: Wed Nov 25, 2015 11:44 am
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by vanatteveldt »

Is there a way to have construction bots automatically plant saplings in the place of destroyed trees like with landmines?

Shrooblord
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Thu May 12, 2016 12:57 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by Shrooblord »

Hi!

I made new images for the tree sapling and for the ammonium nitrate. :)

The sapling is a combination of in-game tree and leaves, except I cut some branches off, shortened the trunk and made the branches shorter and gave the leaves a young-and-freshly-new green tint (as young plants in real life would have). The ammonium nitrate sprite is my go at making a heap of sort of see-throughish crystals using your original sprite's colour.

Tested them in-game. They look nice and blend in well (that was the intention in any case :P ).

Hope you like 'em and want to incorporate them.
Attachments
Tree_n_Fertiliser.zip
My sprites for the sapling and fertiliser
(3.69 KiB) Downloaded 147 times

vaultdweller
Burner Inserter
Burner Inserter
Posts: 9
Joined: Mon Mar 28, 2016 4:08 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by vaultdweller »

This mod does not seem to work in multiplayer and causes a neverending desync loop. It uses a random number generator call when checking if a sapling should turn into a tree; each player generates a different random number, causing the desync. We had to edit that function to make the saplings become trees after a pre-determined interval to get it to work for us.

Factorio is generally a deterministic game, not a probablistic one. If you want probabilities in the mod, then for multiplayer you'll need some way to seed the RNG with a constant that is shared between all players so that all players will have the same RNG output.

seronis
Fast Inserter
Fast Inserter
Posts: 225
Joined: Fri Mar 04, 2016 8:04 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by seronis »

vaultdweller wrote:This mod does not seem to work in multiplayer and causes a neverending desync loop. It uses a random number generator call when checking if a sapling should turn into a tree; each player generates a different random number, causing the desync. We had to edit that function to make the saplings become trees after a pre-determined interval to get it to work for us.

Factorio is generally a deterministic game, not a probablistic one. If you want probabilities in the mod, then for multiplayer you'll need some way to seed the RNG with a constant that is shared between all players so that all players will have the same RNG output.
False. The games rng is a seeded PRNG meaning that at any time every player will always generate the exact same sequence of numbers. It can be a logic issue causing the desync. But the rng itself is mp safe and is used in lots of mods.

vaultdweller
Burner Inserter
Burner Inserter
Posts: 9
Joined: Mon Mar 28, 2016 4:08 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by vaultdweller »

seronis wrote:
vaultdweller wrote:This mod does not seem to work in multiplayer and causes a neverending desync loop. It uses a random number generator call when checking if a sapling should turn into a tree; each player generates a different random number, causing the desync. We had to edit that function to make the saplings become trees after a pre-determined interval to get it to work for us.

Factorio is generally a deterministic game, not a probablistic one. If you want probabilities in the mod, then for multiplayer you'll need some way to seed the RNG with a constant that is shared between all players so that all players will have the same RNG output.
False. The games rng is a seeded PRNG meaning that at any time every player will always generate the exact same sequence of numbers. It can be a logic issue causing the desync. But the rng itself is mp safe and is used in lots of mods.
Okay then. Well, one way or another, this mod can NOT be used in multiplayer as-is, and removing the random interval fixes it.

TOGoS
Former Staff
Former Staff
Posts: 93
Joined: Fri Jun 24, 2016 2:29 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by TOGoS »

The large bounding boxes (larger than those of full grown trees!) were bothering me, so I made the following change to entity.lua:

Code: Select all

    collision_box = {{-0.3, -0.0}, {0.3, 0.6}},
    selection_box = {{-0.5, -0.2}, {0.5, 1.0}},
This makes them much smaller and centered on the place where they come out of the ground
(there may be a way to offset the image so that the collision_box can be centered on 0,0, but I am new at this and didn't figure it out)

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by TheSAguy »

Had anyone else experienced MP Desync?
I don't play any MP, but was hoping to use a little of this code in my mod, but dont want to if it might cause desyncs.
Looking at the code, I don't see why there would be though.

Thanks.

ntm
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Jul 06, 2016 12:48 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by ntm »

I updated this mod to work with 0.13.x, feel free to upload it to mods.factorio.com, or I can do it too if you'd no longer like to mantain this mod.

Changes:
  • Now works for 0.13.x
  • moved sapling recipe from nature tab to terrains (alongside concrete)
  • new icon for saplings
Attachments
TreeSaplings_0.1.3.zip
(29.06 KiB) Downloaded 159 times

LukeM
Inserter
Inserter
Posts: 26
Joined: Sun Mar 20, 2016 8:32 pm
Contact:

Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2

Post by LukeM »

Sorry for not replying to any comments for the past few months, the last time I checked (just before 0.13) this topic had drifted down to about page 4 or 5, so I didnt think there would be anyone using this mod anymore. I have tried to update it to 0.13, and have uploaded it to the factorio mods page, but am not yet able to test the multiplayer thing, as my friend who I usually play factorio with is not online.
Shrooblord wrote:Hi!

I made new images for the tree sapling and for the ammonium nitrate. :)

The sapling is a combination of in-game tree and leaves, except I cut some branches off, shortened the trunk and made the branches shorter and gave the leaves a young-and-freshly-new green tint (as young plants in real life would have). The ammonium nitrate sprite is my go at making a heap of sort of see-throughish crystals using your original sprite's colour.

Tested them in-game. They look nice and blend in well (that was the intention in any case :P ).

Hope you like 'em and want to incorporate them.
Thanks! Your graphics are much better than my ones, and they do, as you said, fit into the game very well. I have added them to the latest version and credited you in the factorio mods page :D
seronis wrote:
vaultdweller wrote:This mod does not seem to work in multiplayer and causes a neverending desync loop. It uses a random number generator call when checking if a sapling should turn into a tree; each player generates a different random number, causing the desync. We had to edit that function to make the saplings become trees after a pre-determined interval to get it to work for us.
...
False. The games rng is a seeded PRNG meaning that at any time every player will always generate the exact same sequence of numbers. It can be a logic issue causing the desync. But the rng itself is mp safe and is used in lots of mods.
vaultdweller: Thanks for letting me know that there is a problem with the newest version
seronis: Thanks for the info on how the random numbers work :D, I think the version that I was using, that I didn't upload as it was such a small change, shouldn't have that issue, but as I said at the top of this post, I can't test it yet
ntm wrote:I updated this mod to work with 0.13.x, feel free to upload it to mods.factorio.com, or I can do it too if you'd no longer like to mantain this mod.

Changes:
  • Now works for 0.13.x
  • moved sapling recipe from nature tab to terrains (alongside concrete)
  • new icon for saplings
Thanks for uploading a fix, at least for singleplayer :D
I will continue to try to maintain this mod as long as I still play factorio, and notice that something needs maintaining, but thanks for the offer

User avatar
JoaoBernardino
Inserter
Inserter
Posts: 20
Joined: Sat Jun 04, 2016 1:09 pm
Contact:

Re: [MOD 0.13.x] Tree Sapling Mod v0.1.4

Post by JoaoBernardino »

Don't abandon this!! I need trees on my base, for aesthetic and pollution reasons!! This is the only mod that actually plant real trees!

Good work!! :D
Nom Nom Nom

Post Reply

Return to “Mods”