Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaves don't seem to decay? #3

Open
AmyMoriyama opened this issue Aug 27, 2022 · 35 comments
Open

Leaves don't seem to decay? #3

AmyMoriyama opened this issue Aug 27, 2022 · 35 comments

Comments

@AmyMoriyama
Copy link

So I've been noticing that leaves from naturalbiomes trees don't seem to "decay".

@Skandarella
Copy link
Owner

Yes it is a known problem. Leaf decay only works for some bushes. The problem is also mentioned in the forums, but no solution at this moment, because nobody knows how to change leaf param type from 2 to 0.
https://forum.minetest.net/viewtopic.php?f=9&t=28390

@sfence
Copy link

sfence commented Oct 27, 2022

Yes it is a known problem. Leaf decay only works for some bushes. The problem is also mentioned in the forums, but no
solution at this moment, because nobody knows how to change leaf param type from 2 to 0. https://forum.minetest.net/viewtopic.php?f=9&t=28390

It looks like you are not calling function default.register_leafdecay, to add leaves to decay system provided by default minetest game.
Default decay system expected param2 of node to be different from 1 to work.
So you will probably have to update your schematic .mts files, to not set param2 of spawned leaves to 1.

@Skandarella
Copy link
Owner

The problem is when I look into a .mts file from another mod, they have a clear code that can be edited.
My schematics made with handle_schematics mod look like this, if I open them:
呍䵓ЀȀȀЀ罿Ȁ̀楡r渜瑡牵污楢浯獥愺灬楰敮弱牴湵硫掜恠摠�璬ᨽ਄⎲0雄ገ

@sfence
Copy link

sfence commented Oct 30, 2022

I have been able to covert it by using mod schemedit and mod sfence_help.

I copied aldertree.mts to the world directory scheme, use schemedit command /mts2lua aldertree to get aldertree.lua in same disrtecotry. I have replaced param2=1 by param2=0 and I convert lua back to mts by sfence_help command /lua2mts aldertree.

I imported a new schematic file by schemedit mod node, dig the trunk, and leaves decays.

@Skandarella
Copy link
Owner

Thank you for help, I will fix this in the next update.

@Skandarella
Copy link
Owner

Skandarella commented Nov 8, 2022

I converted the .mts to lua and replaced the param2 =1 by param2 = 0 but after converting back to .mts and replacing the old .mts with the new ones, I got this error when starting a game with the mod:

ModError: Failed to load and run script from F:\minetest-5.6.1-win64\bin..\mods\naturalbiomes\init.lua:
decompressZlib: inflate failed
stack traceback:
[C]: in function 'orig_reg_fn'
F:\minetest-5.6.1-win64\bin..\builtin\game\register.lua:506: in function 'register_decoration'
...est-5.6.1-win64\bin..\mods\naturalbiomes/alderswamp.lua:214: in main chunk
[C]: in function 'dofile'
F:\minetest-5.6.1-win64\bin..\mods\naturalbiomes\init.lua:35: in main chunk
Für mehr Details siehe debug.txt.

When I replace the new(fixed) .mts with the old, all works fine, but the fixed/converted .mts create errors.
Is there a way to directly get the correct leaf param type when creating the shematics in schemedit or handleschematics?

@sfence
Copy link

sfence commented Nov 8, 2022

I tried to update and push the alder tree and alp pine trees https://github.com/sfence/naturalbiomes/tree/try_some_mts_update and it works fine (leaves are placed with param2=0, and the world is loading). After register_leafdecay is added, it decays well.

I am running it under Linux, minetest 5.6.0. So you can try my versions.

Are updated *.mts files from my branch working on your computer?

@sfence
Copy link

sfence commented Nov 8, 2022

You can use lua version of the schematic as well:
schematic = dofile(minetest.get_modpath("naturalbiomes").."/schematics/n aturalbiomes_alpine_pine2_0_90.lua"),

Can help with debugging.

@Skandarella
Copy link
Owner

I have tried it with fresh converted (/mts2lua) files, but I still get an ERROR when logging into a new world with the mod activated:
ERROR(MAIN): deserializeFromMts: invalid schematic file

@sfence
Copy link

sfence commented Nov 8, 2022

I have tried it with fresh converted (/mts2lua) files, but I still get an ERROR when logging into a new world with the mod activated: ERROR(MAIN): deserializeFromMts: invalid schematic file

You probably only change .mts to .lua, but dofile should be added too.

This is code which works for me:
schematic = dofile(minetest.get_modpath("naturalbiomes").."/schematics/n aturalbiomes_alpine_pine2_0_90.lua")

The schematic should be a schematic mts file or lua table with a schematic definition. Function dofile load table in lua file and return it.

@Skandarella
Copy link
Owner

Hmm still get the error. here is the changed code in the alderswamp.lua:
schematic = dofile(minetest.get_modpath("naturalbiomes").."/schematics/naturalbiomes_aldertree_0_270.lua", "0", nil, true)
end

@sfence
Copy link

sfence commented Nov 9, 2022

to much arguments...

in grow function you can replace:
minetest.place_schematic({x = pos.x, y = pos.y, z = pos.z}, modpath.."/schematics/naturalbiomes_aldertree_0_270.mts", "0", nil, true)
by
minetest.place_schematic({x = pos.x, y = pos.y, z = pos.z}, dofile(modpath.."/schematics/naturalbiomes_aldertree_0_270.lua"), "0", nil, true)

in decoration registration replace:
schematic = minetest.get_modpath("naturalbiomes").."/schematics/n aturalbiomes_alpine_pine2_0_90.mts"
by:
schematic = dofile(minetest.get_modpath("naturalbiomes").."/schematics/n aturalbiomes_alpine_pine2_0_90.lua")

Maybe, if you have discord, it will be a better way to discuss this there (use a private message on minetest forum to send me a discord contact in that case: https://forum.minetest.net/memberlist.php?mode=viewprofile&u=25513 )

@Skandarella
Copy link
Owner

Skandarella commented Nov 9, 2022

I replaced the code like you said and the ERROR does not appear again. But the schematics dont spawn anymore in a new world now. The trees are gone: https://ibb.co/fYR8dGr

@sfence
Copy link

sfence commented Nov 9, 2022

In the code, I post here for schematic =, I have used .lua for the alpine tree with excessing space, not for the alder tree.

Did you replace lua file with a valid existing one for the alder tree, you are experimenting with?

This happens to me too, when the name of a lua file was bad.

@Skandarella
Copy link
Owner

minetest.place_schematic({x = pos.x, y = pos.y, z = pos.z}, dofile(modpath.."/schematics/naturalbiomes_aldertree_0_270.lua"), "0", nil, true)

    schematic = dofile(minetest.get_modpath("naturalbiomes").."/schematics/naturalbiomes_aldertree_0_270.lua)

ModError: Failed to load and run script from F:\minetest-5.6.1-win64\bin..\mods\naturalbiomes\init.lua:
...est-5.6.1-win64\bin..\mods\naturalbiomes/alderswamp.lua:224: unfinished string near '"/schematics/naturalbiomes_aldertree_0_270.lua)'
stack traceback:
[C]: in function 'dofile'
F:\minetest-5.6.1-win64\bin..\mods\naturalbiomes\init.lua:35: in main chunk
Für mehr Details siehe debug.txt.

@sfence
Copy link

sfence commented Nov 9, 2022

missing ending " on
schematic = dofile(minetest.get_modpath("naturalbiomes").."/schematics/naturalbiomes_aldertree_0_270.lua)

do

schematic = dofile(minetest.get_modpath("naturalbiomes").."/schematics/naturalbiomes_aldertree_0_270.lua")

@Skandarella
Copy link
Owner

minetest.register_decoration({
name = "naturalbiomes:alder_tree",
deco_type = "schematic",
place_on = {"naturalbiomes:alderswamp_litter"},
place_offset_y = 0,
sidelen = 16,
fill_ratio = 0.02115,
biomes = {"naturalbiomes:alderswamp"},
y_max = 5,
y_min = 1,
schematic = dofile(minetest.get_modpath("naturalbiomes").."/schematics/naturalbiomes_aldertree_0_270.lua")
flags = "place_center_x, place_center_z",
rotation = "random",
})

ModError: Failed to load and run script from F:\minetest-5.6.1-win64\bin..\mods\naturalbiomes\init.lua:
...est-5.6.1-win64\bin..\mods\naturalbiomes/alderswamp.lua:225: '}' expected (to close '{' at line 214) near 'flags'
stack traceback:
[C]: in function 'dofile'
F:\minetest-5.6.1-win64\bin..\mods\naturalbiomes\init.lua:35: in main chunk
Für mehr Details siehe debug.txt.

@sfence
Copy link

sfence commented Nov 9, 2022

missing comma on the end of the line in the table definition.

@Skandarella
Copy link
Owner

No ERROR message now, but empty biome without trees again.

@sfence
Copy link

sfence commented Nov 9, 2022

Looks like some problem in updated lua file. Can you send me that file?

@Skandarella
Copy link
Owner

Skandarella commented Nov 9, 2022

Its not even an updated file, it happens also with a fresh converted file.

Here is the link for a fresh converted one, dont click on the advertisement(Fileupload): https://www.file-upload.net/download-15037065/naturalbiomes_aldertree_0_270.lua.html

@sfence
Copy link

sfence commented Nov 10, 2022

I am sorry. I did some error when testing the loading schema from lua file for the alppine2 tree, so I beleave it works.

Good is that I see the same problem as you.

Try to add function:

function load_schem(file)
  local f = assert(io.open(file, "rb"))
  local schema = f:read("*all")
  f:close()
  schema = loadstring(schema.." return schematic");
  return schema()
end

and use it instead of dofile for load schematic from lua.

if you fall to situation, the you will want to release this mod with this function, it is a good idea to define it in mod namespace...

naturalbiomes = {}
function naturalbiomes.load_schem(file)
  local f = assert(io.open(file, "rb"))
  local schema = f:read("*all")
  f:close()
  schema = loadstring(schema.." return schematic");
  return schema()
end

and I files use it with in biome files:

local load_schem = naturalbiomes.load_schem -- local shorter copy of function

load_schem(path_to_schem_lua_file)

@sfence
Copy link

sfence commented Nov 10, 2022

There is also a problem, that saplings grow hard/forced and are not centered. (overwrite nearby flora and sometimes ground nodes like dirt etc.)

See https://github.com/runsy/cool_trees/blob/master/cherrytree/init.lua#L64
for example.

if you correctly move the corner of the place area, the trunk should grow on the place where the sapling is.

@Skandarella
Copy link
Owner

Can you write an example with a tree for adding function? I am not skilled in programming at all, so I dont know how to add all things like "(file) "(file, "rb"" etc.

Where do i have to place this? In a sepratae .lua, or in the biome files?

@Skandarella
Copy link
Owner

I used the code for placement from the cherrytree for the sapling. The result is, that the saplings dont sprout anymore. It is right that the trees dont grow centered, this is possible to fix, but the replacement of nodes and decoration in the range of the grown tree, is a problem of the schematic it seems. It acts like a forced placement. I will try to recreate the schematic of the alder tree later with schemedit instead of handle_schematics maybe, this works.

@sfence
Copy link

sfence commented Nov 10, 2022

This is FORCE placement of the schematic:
minetest.place_schematic({x = pos.x, y = pos.y, z = pos.z}, modpath.."/schematics/naturalbiomes_aldertree_0_270.mts", "0", nil, true)

This is SOFT placement of the schematic:
minetest.place_schematic({x = pos.x, y = pos.y, z = pos.z}, modpath.."/schematics/naturalbiomes_aldertree_0_270.mts", "0", nil, false)

The only difference is in the last parameter of the place_schematic function.

@sfence
Copy link

sfence commented Nov 10, 2022

Please, try this mts file. It is an updated alder tree schema.

alder_mts.zip

If it will be ok, you can send me an archive of modified lua versions of the schematic, and I will convert them to mts files for you, and send them back.

So, it will not require some bigger code changes.

The cherry tree is only an example of how to place schematic soft and with moved trunk offset. Not good for copying into your code, only good to look at how to use it. But schema name and position change have to be changed individually for every tree.

@Skandarella
Copy link
Owner

This new .mts works fine. How did you add the leaf decay? I think it would be better if I can do it myself, because I cannot ask you to convert for me every single file, also for future mods.

@sfence
Copy link

sfence commented Nov 10, 2022

default.register_leafdecay({
    leaves = {"naturalbiomes:alder_leaves"},
    trunks = {"naturalbiomes:alder_trunk"},
    radius = 3,
  })

leaves is list of tree leaves ndoe names and potencionaly tree fruit node names etc.
trunks is list trunk node names.
radius is maximum distance of leaves/fruits from trunk... if trunk not will be located in distance radius or shorter, leaves decay.

Is based on the node timer and the check is started by trunk dig.

@sfence
Copy link

sfence commented Nov 10, 2022

I am using /mts2lua and /lua2mts to convert mts files, but now I test it under windows, and it looks like it does not work on windows for some reason.

/lua2mts command use minetest.serialize_schematic function to save schematic.

handle_schematic and schemaedit uses different methods to create .mts file, so it can work for you on windows.

@Skandarella
Copy link
Owner

I tried to install Ubuntu on a notebook yesteday, but I had no success. After entering the desktop after installation, it feezed. I will try again today.

Until this works, it would be nice if you can convert those for me:
schemsnaturalbiomes.zip

@Skandarella
Copy link
Owner

Sorry, I did not send you the right correted schems (param2=0}) again, the schems corrected:
schems2.zip

@sfence
Copy link

sfence commented Nov 11, 2022

Second try:
schemsnaturalbiomes_conv2.zip

First I miss that no param is edidted in lua files. :D

@Skandarella
Copy link
Owner

Thank you, it works :)

@Skandarella
Copy link
Owner

Until theres a schematic editor that supports the change of param type before saving schematics, this mods helps: https://content.minetest.net/packages/Liil/winuserleafdecay/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants