Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Beds logical flow
Beds Flowchart:
|- 1) on_rightclick() (beds:bed_name or any node:here) (function call beds.bed_rightclick(pos, player))
|
|
|--- i) Is it night time and a player? (Gone 6pm in local clock?)
| |
| |
|------ I) else, return, end
| |
| |
|------ II) beds.set_respawn_point(player, pos)
| |
| |
|------ III) beds.sleep(pos, player)
|- 2) beds.sleep(pos, player, height_offset)
|
|
|--- i) Set player to bed's center position. (Check rotation first!)
|
|
|--- ii) Set player animation to "lay_bed", player rotation to match the bed and use height_offset incase the bed stands higher off the ground
|
|
|--- iii) Display bed exit formspec
|
|
|--- iv) Check if all players are sleeping; or sleeping players is higher than set percentage;
|
|
|------ I) Are ifs valid?; then
|
|
|----------- a) beds.pass_night()
| | |
| | |
|----------- b) else, return, end
|- 3) beds.set_respawn_point(pos, player)
|
|
|--- i) Check left and right side of bed, including if there is a spot under that space for safe spawning.
| |
| |
|------- I) If there is no safe spawn point, set it on top of the bed.
|
|
|--- ii) Set player's respawn attributes to minetest.serialize({x=pos.x+safe_spawn_x, y=pos.y+0.5, z=pos.z+safe_spawn_z}) (With correct side from each individual bed)
|
|
|--- iii) Tell player if spawnpoint is beside the bed or on top of it due to unsafe respawns.
|
|
|--- iv) Use a "spawnpoint set!" message after the spawnpoint has been saved to player attributes.
|- 4) beds.pass_night() (uses on_globalstep per ~20 seconds)
|
|
|--- i) Set time to morning (6am by default), configurable.
|
|
|--- ii) Loop through all players with attribute: "beds_sleeping", "true"
| |
| |
|------ I) if the check clears, then spawn player to the positon specified by beds.set_respawn_point()
| |
| |
|------ II) set the sleeping player's attribute to "beds_sleeping", false"
| |
| |
|------ III) else, return, end (Ignore an awake player at all times)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.