RandomMcSomethin / fallingleaves

MIT License
43 stars 20 forks source link

Possible feature update: Only spawn from actual trees #10

Open BrekiTomasson opened 3 years ago

BrekiTomasson commented 3 years ago

This should be configurable with an on/off toggle, but somehow it feels wrong when I place a leaf block manually, that leaves begin falling from it. There should be some kind of check (similar to the leaf-decay check) which checks if the leaf block is in concact with a log (or within touching distance of other leaf blocks that touch a log). I'm sure there are already samples of code available that do this very check that we can slot in.

Fourmisain commented 3 years ago

I just found state.get(LeavesBlock.PERSISTENT) which is true exactly if it was placed manually. There's also state.get(LeavesBlock.DISTANCE), an integer between 1 and 7 telling the distance to an appropriate log.

Leaves despawn when state.get(DISTANCE) == 7 && !state.get(PERSISTENT).

So we could either use the distance or the persistence flag. I guess it makes more sense to use the persistence flag, since most of the times, leaves are placed nearby logs anyways, so there wouldn't be any actual change otherwise.

How should we name the config option? "Drop from manually placed leaves", defaulting to true? It's the shortest description I can come up with and still kinda a mouthfull

BrekiTomasson commented 3 years ago

I think LeavesBlock.DISTANCE returns 0 if you've got a leaf block touching a stone block touching a log. It should only return the distance as it travels along other leaf blocks, making it a good way to check if a leaf block is part of an actual tree or part of something else. I haven't checked if it only works in straight lines and 90-degree angles or if it supports diagonal distances, as that would be required for some modded tree types.

As for the config option, I'd probably prefer something like "Only drop from actual trees" or similar, defaulting to false. Yours is good too, although I agree that "manually" might make it a bit wordy. Maybe "Drop from player-placed leaves"?

BrekiTomasson commented 3 years ago

I believe this issue can be closed?

Fourmisain commented 3 years ago

For me, the "player placed" option is enough, though it is different from what was originally suggested. Implementing an actual tree check would be too expensive and basically impossible to get 100% right anyway. There might be some merit in looking at LeavesBlock.DISTANCE but I'm not sure if it's worth getting into.

So I'd vote close until someone has a better suggestion.

BrekiTomasson commented 3 years ago

Agreed, the "Player Placed" option should be enough. We can revisit this at a later date to see how leaf blocks placed as part of structures in Worldgen are handled.