[MOD 0.13.x] Tree Sapling Mod v0.1.4
[MOD 0.13.x] Tree Sapling Mod v0.1.4
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
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
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
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.
-
- Burner Inserter
- Posts: 18
- Joined: Thu Mar 17, 2016 12:03 pm
- Contact:
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
I'm intrigued, but I do not understand. Do these sapling things become vanilla trees eventually?
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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.
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.
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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)ALittleGreenStone wrote:I'm intrigued, but I do not understand. Do these sapling things become vanilla trees eventually?
1. Ok, I will add it to the main postseronis 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.
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.
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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:
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.
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
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
This is exactly what I was looking for! Thank you so much!
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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 helpseronis 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'.
I'm glad that you like itInjen wrote:This is exactly what I was looking for! Thank you so much!
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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.
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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:
since u are "just" providing a "trunk.png", its missing a trunk-1 and trunk-2 file
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
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
I will try to fix that as soon as possible , ty for telling me about this problemSpeadge 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:
since u are "just" providing a "trunk.png", its missing a trunk-1 and trunk-2 fileCode: Select all
Some code was here
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
-
- Filter Inserter
- Posts: 947
- Joined: Wed Nov 25, 2015 11:44 am
- Contact:
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
Is there a way to have construction bots automatically plant saplings in the place of destroyed trees like with landmines?
-
- Long Handed Inserter
- Posts: 55
- Joined: Thu May 12, 2016 12:57 pm
- Contact:
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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 ).
Hope you like 'em and want to incorporate them.
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 ).
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 189 times
-
- Burner Inserter
- Posts: 9
- Joined: Mon Mar 28, 2016 4:08 pm
- Contact:
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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.
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.
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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 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.
-
- Burner Inserter
- Posts: 9
- Joined: Mon Mar 28, 2016 4:08 pm
- Contact:
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
Okay then. Well, one way or another, this mod can NOT be used in multiplayer as-is, and removing the random interval fixes it.seronis wrote: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 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.
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
The large bounding boxes (larger than those of full grown trees!) were bothering me, so I made the following change to entity.lua:
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)
Code: Select all
collision_box = {{-0.3, -0.0}, {0.3, 0.6}},
selection_box = {{-0.5, -0.2}, {0.5, 1.0}},
(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)
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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.
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.
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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:
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 198 times
Re: [MOD 0.12.x] Tree Sapling Mod v0.1.2
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.
seronis: Thanks for the info on how the random numbers work , 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
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
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 pageShrooblord 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 ).
Hope you like 'em and want to incorporate them.
vaultdweller: Thanks for letting me know that there is a problem with the newest versionseronis wrote: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 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.
...
seronis: Thanks for the info on how the random numbers work , 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
Thanks for uploading a fix, at least for singleplayerntm 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
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
- JoaoBernardino
- Inserter
- Posts: 20
- Joined: Sat Jun 04, 2016 1:09 pm
- Contact:
Re: [MOD 0.13.x] Tree Sapling Mod v0.1.4
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!!
Good work!!
Nom Nom Nom