1
0
Fork
You've already forked alone
0

Does not work with new Mineclonia singlenode mode #3

Closed
opened 2025年10月25日 05:30:20 +02:00 by Codiac · 7 comments

Mieclonia recently added a new singlenode map generator which changes how players spawn, Alone doesn't work with this.

  1. the player spawns and can dies before the area is loaded
  2. the house spawns before the area is loaded, which can trash house
  3. the player moves after the area is loaded
  4. the player spawn is not randomised

IIUIC need to:

  1. Leave player in limbo until after area loads
  2. Prevent house spawning until after area loaded
  3. Override mcl_biome_dispatch.next_respawn_position and local function respawn_set_pos to randomize and load area before picking a spawn point
  4. Spawn house if required
  5. Spawn player
Mieclonia recently added a new singlenode map generator which changes how players spawn, Alone doesn't work with this. 1. the player spawns and can dies before the area is loaded 2. the house spawns before the area is loaded, which can trash house 3. the player moves after the area is loaded 4. the player spawn is not randomised IIUIC need to: 1. Leave player in limbo until after area loads 2. Prevent house spawning until after area loaded 3. Override `mcl_biome_dispatch.next_respawn_position` and `local function respawn_set_pos` to randomize and load area before picking a spawn point 4. Spawn house if required 5. Spawn player

I believe what you have already written in here is a sound approach. All that remains for me to add is that spawning the house must take place within the callback provided to mcl_biome_dispatch.emerged_teleport_prepare, and the area you provide this function should encompass all possible positions the house might modify.

I believe what you have already written in here is a sound approach. All that remains for me to add is that spawning the house must take place within the callback provided to mcl_biome_dispatch.emerged_teleport_prepare, and the area you provide this function should encompass all possible positions the house might modify.
Author
Owner
Copy link

@halon, would you accept a patch liek below to make it so mods don't have to copy a lot of code or re-implement a lot of stuff?

Also in the callback should it load a template or use the structure API to add a house?

iff --git a/mods/MAPGEN/mcl_biome_dispatch/init.lua b/mods/MAPGEN/mcl_biome_dispatch/init.lua
index 21159d5b1..734b825b8 100644
--- a/mods/MAPGEN/mcl_biome_dispatch/init.lua
+++ b/mods/MAPGEN/mcl_biome_dispatch/init.lua
@@ -460,7 +460,7 @@ local LIMBO_POSITION = vector.new (31007, 31007, 31007)
 local get_dimension = mcl_levelgen.get_dimension
 local global_spawnpoint = core.setting_get_pos ("static_spawnpoint")
 
-function mcl_biome_dispatch.get_spawn_point_2d ()
+function mcl_biome_dispatch.get_spawn_point_2d (obj)
 if levelgen_enabled and global_spawnpoint then
 return global_spawnpoint
 elseif levelgen_enabled then
@@ -547,13 +547,13 @@ end
 
 local floor = math.floor
 
-local function respawn_set_pos (player, _)
+function mcl_biome_dispatch.respawn_set_pos (player, _)
 local pos = mcl_biome_dispatch.next_respawn_position (nil)
 player:set_pos (pos)
 end
 
-function mcl_biome_dispatch.next_respawn_position (obj)
- local spawn_pos = mcl_biome_dispatch.get_spawn_point_2d ()
+function mcl_biome_dispatch.next_respawn_position (obj, in_limbo)
+ local spawn_pos = mcl_biome_dispatch.get_spawn_point_2d(obj)
 local spawn_radius = tonumber (core.settings:get ("mcl_spawn_radius")) or 24
 local dim = get_dimension ("mcl_levelgen:overworld")
 local v1 = vector.offset (spawn_pos, -spawn_radius, 0, -spawn_radius)
@@ -562,13 +562,13 @@ function mcl_biome_dispatch.next_respawn_position (obj)
 v2.y = dim.y_max
 if not mcl_levelgen.is_area_fully_regenerated (dim, v1.x, v1.y, v1.z,
 v2.x, v2.y, v2.z) then
- if not obj then
+ if (not obj) or in_limbo then
 return LIMBO_POSITION
 end
 return mcl_biome_dispatch.emerged_teleport_prepare (obj,
 v1, v2,
 nil,
- respawn_set_pos,
+ mcl_biome_dispatch.respawn_set_pos,
 nil)
 end
 
diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua
index 7a891cb29..6b22a73e9 100644
--- a/mods/PLAYER/mcl_spawn/init.lua
+++ b/mods/PLAYER/mcl_spawn/init.lua
@@ -68,7 +68,7 @@ end
 
 function mcl_spawn.get_world_spawn_pos (obj)
 if mcl_biome_dispatch.use_detailed_spawning_mechanics () then
- return mcl_biome_dispatch.next_respawn_position (obj), 0
+ return mcl_biome_dispatch.next_respawn_position (obj), false
 end
 return start_pos, false
 end
@halon, would you accept a patch liek below to make it so mods don't have to copy a lot of code or re-implement a lot of stuff? Also in the callback should it load a template or use the structure API to add a house? ```diff iff --git a/mods/MAPGEN/mcl_biome_dispatch/init.lua b/mods/MAPGEN/mcl_biome_dispatch/init.lua index 21159d5b1..734b825b8 100644 --- a/mods/MAPGEN/mcl_biome_dispatch/init.lua +++ b/mods/MAPGEN/mcl_biome_dispatch/init.lua @@ -460,7 +460,7 @@ local LIMBO_POSITION = vector.new (31007, 31007, 31007) local get_dimension = mcl_levelgen.get_dimension local global_spawnpoint = core.setting_get_pos ("static_spawnpoint") -function mcl_biome_dispatch.get_spawn_point_2d () +function mcl_biome_dispatch.get_spawn_point_2d (obj) if levelgen_enabled and global_spawnpoint then return global_spawnpoint elseif levelgen_enabled then @@ -547,13 +547,13 @@ end local floor = math.floor -local function respawn_set_pos (player, _) +function mcl_biome_dispatch.respawn_set_pos (player, _) local pos = mcl_biome_dispatch.next_respawn_position (nil) player:set_pos (pos) end -function mcl_biome_dispatch.next_respawn_position (obj) - local spawn_pos = mcl_biome_dispatch.get_spawn_point_2d () +function mcl_biome_dispatch.next_respawn_position (obj, in_limbo) + local spawn_pos = mcl_biome_dispatch.get_spawn_point_2d(obj) local spawn_radius = tonumber (core.settings:get ("mcl_spawn_radius")) or 24 local dim = get_dimension ("mcl_levelgen:overworld") local v1 = vector.offset (spawn_pos, -spawn_radius, 0, -spawn_radius) @@ -562,13 +562,13 @@ function mcl_biome_dispatch.next_respawn_position (obj) v2.y = dim.y_max if not mcl_levelgen.is_area_fully_regenerated (dim, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z) then - if not obj then + if (not obj) or in_limbo then return LIMBO_POSITION end return mcl_biome_dispatch.emerged_teleport_prepare (obj, v1, v2, nil, - respawn_set_pos, + mcl_biome_dispatch.respawn_set_pos, nil) end diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index 7a891cb29..6b22a73e9 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -68,7 +68,7 @@ end function mcl_spawn.get_world_spawn_pos (obj) if mcl_biome_dispatch.use_detailed_spawning_mechanics () then - return mcl_biome_dispatch.next_respawn_position (obj), 0 + return mcl_biome_dispatch.next_respawn_position (obj), false end return start_pos, false end ```

@Codiac wrote in #3 (comment):

@halon, would you accept a patch liek below to make it so mods don't have to copy a lot of code or re-implement a lot of stuff?

Also in the callback should it load a template or use the structure API to add a house?

The structure and template generation facilities are only capable of operating in async or mapgen environments, for which reason you must place the house manually, I'm afraid. The patch is satisfactory, excepting this:

function mcl_spawn.get_world_spawn_pos (obj)
if mcl_biome_dispatch.use_detailed_spawning_mechanics () then

  •  return mcl_biome_dispatch.next_respawn_position (obj), 0
    
  •  return mcl_biome_dispatch.next_respawn_position (obj), false
    

The existing value of 0 (which is a truthy value) must be retained to signal to callers of mcl_spawn.get_player_spawn_pos that the position must be set immediately and without adjustment.

@Codiac wrote in https://codeberg.org/Codiac/alone/issues/3#issuecomment-8145986: > @halon, would you accept a patch liek below to make it so mods don't have to copy a lot of code or re-implement a lot of stuff? > > Also in the callback should it load a template or use the structure API to add a house? The structure and template generation facilities are only capable of operating in async or mapgen environments, for which reason you must place the house manually, I'm afraid. The patch is satisfactory, excepting this: > function mcl_spawn.get_world_spawn_pos (obj) > if mcl_biome_dispatch.use_detailed_spawning_mechanics () then > - return mcl_biome_dispatch.next_respawn_position (obj), 0 > + return mcl_biome_dispatch.next_respawn_position (obj), false The existing value of 0 (which is a truthy value) must be retained to signal to callers of mcl_spawn.get_player_spawn_pos that the position must be set immediately and without adjustment.
Author
Owner
Copy link

@halon wrote in #3 (comment):

@Codiac wrote in #3 (comment):

@halon, would you accept a patch liek below to make it so mods don't have to copy a lot of code or re-implement a lot of stuff?
Also in the callback should it load a template or use the structure API to add a house?

The structure and template generation facilities are only capable of operating in async or mapgen environments, for which reason you must place the house manually,

Cool.

I'm afraid. The patch is satisfactory, excepting this:

function mcl_spawn.get_world_spawn_pos (obj)
if mcl_biome_dispatch.use_detailed_spawning_mechanics () then

  •  return mcl_biome_dispatch.next_respawn_position (obj), 0
    
  •  return mcl_biome_dispatch.next_respawn_position (obj), false
    

The existing value of 0 (which is a truthy value) must be retained to signal to callers of mcl_spawn.get_player_spawn_pos that the position must be set immediately and without adjustment.

Ok, I'll just override that as well. Without changing it overriding respawning is blocked by the bed code, so you either have to override this or that.

@halon wrote in https://codeberg.org/Codiac/alone/issues/3#issuecomment-8147165: > @Codiac wrote in #3 (comment): > > > @halon, would you accept a patch liek below to make it so mods don't have to copy a lot of code or re-implement a lot of stuff? > > Also in the callback should it load a template or use the structure API to add a house? > > The structure and template generation facilities are only capable of operating in async or mapgen environments, for which reason you must place the house manually, Cool. > I'm afraid. The patch is satisfactory, excepting this: > > > function mcl_spawn.get_world_spawn_pos (obj) > > if mcl_biome_dispatch.use_detailed_spawning_mechanics () then > > > > * ``` > > return mcl_biome_dispatch.next_respawn_position (obj), 0 > > ``` > > > > > > * ``` > > return mcl_biome_dispatch.next_respawn_position (obj), false > > ``` > > The existing value of 0 (which is a truthy value) must be retained to signal to callers of mcl_spawn.get_player_spawn_pos that the position must be set immediately and without adjustment. Ok, I'll just override that as well. Without changing it overriding respawning is blocked by the bed code, so you either have to override this or that.
Author
Owner
Copy link

@halon is there a way to get the village template for the biome a node is in? I'm trying to make it so the house you get is based on the village template that's right for the biome your spawn is in.

@halon is there a way to get the village template for the biome a node is in? I'm trying to make it so the house you get is based on the village template that's right for the biome your spawn is in.

@Codiac wrote in #3 (comment):

@halon is there a way to get the village template for the biome a node is in? I'm trying to make it so the house you get is based on the village template that's right for the biome your spawn is in.

I'd suggest maintaining a list of relations between biome tags and biome templates, after which you could create a biome test with:

 plains_village_p = mcl_biome_dispatch.make_biome_test ({"#has_village_plains",});
 desert_village_p = mcl_biome_dispatch.make_biome_test ({"#has_village_desert",});
 -- etc.
 local biome = mcl_biome_dispatch.get_biome_name (pos);
 if plains_village_p (biome) then
 return plains_village_template
 elseif desert_vilage_p (biome) then
 return desert_village_template
 -- and so forth
@Codiac wrote in https://codeberg.org/Codiac/alone/issues/3#issuecomment-8414580: > @halon is there a way to get the village template for the biome a node is in? I'm trying to make it so the house you get is based on the village template that's right for the biome your spawn is in. I'd suggest maintaining a list of relations between biome tags and biome templates, after which you could create a biome test with: ```lua plains_village_p = mcl_biome_dispatch.make_biome_test ({"#has_village_plains",}); desert_village_p = mcl_biome_dispatch.make_biome_test ({"#has_village_desert",}); -- etc. local biome = mcl_biome_dispatch.get_biome_name (pos); if plains_village_p (biome) then return plains_village_template elseif desert_vilage_p (biome) then return desert_village_template -- and so forth ```
Author
Owner
Copy link

I changed this to throw an assert when the new levelgen is used.

I changed this to throw an assert when the new levelgen is used.
Sign in to join this conversation.
No Branch/Tag specified
main
v0.2.0
v0.1.0
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Codiac/alone#3
Reference in a new issue
Codiac/alone
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?