22
33import com .google .common .base .Preconditions ;
44import java .util .Random ;
5+ import io .papermc .paper .math .Position ;
56import org .bukkit .command .CommandSender ;
67import org .bukkit .generator .BiomeProvider ;
78import org .bukkit .generator .ChunkGenerator ;
@@ -26,6 +27,10 @@ public class WorldCreator {
2627 private boolean hardcore = false ;
2728 private boolean bonusChest = false ;
2829
30+ private @ Nullable Position spawnPositionOverride ;
31+ private @ Nullable Float spawnYawOverride ;
32+ private @ Nullable Float spawnPitchOverride ;
33+
2934 /**
3035 * Creates an empty WorldCreationOptions for the given world name.
3136 *
@@ -261,6 +266,80 @@ public WorldCreator type(@NotNull WorldType type) {
261266 return this ;
262267 }
263268
269+ /**
270+ * Sets the forced spawn position for the world created by this {@link WorldCreator}.
271+ * <p>
272+ * This overrides vanilla and custom generator behavior without loading any chunks.
273+ * When a forced spawn is specified, the bonus chest will not be generated.
274+ *
275+ * @param position the spawn position
276+ * @param yaw the yaw rotation at spawn
277+ * @param pitch the pitch rotation at spawn
278+ * @return this object, for chaining
279+ */
280+ @ NotNull
281+ public WorldCreator forcedSpawnPosition (@ NotNull Position position , float yaw , float pitch ) {
282+ this .spawnPositionOverride = position ; // If you set this to null, it wont do anything!
283+ this .spawnYawOverride = yaw ;
284+ this .spawnPitchOverride = pitch ;
285+ return this ;
286+ }
287+
288+ /**
289+ * Clears any previously forced spawn position.
290+ * <p>
291+ * After calling this, vanilla spawn selection behavior is used.
292+ *
293+ * @return this object, for chaining
294+ */
295+ @ NotNull
296+ public WorldCreator clearForcedSpawnPosition () {
297+ this .spawnPositionOverride = null ;
298+ this .spawnYawOverride = null ;
299+ this .spawnPitchOverride = null ;
300+ return this ;
301+ }
302+
303+ /**
304+ * Gets the forced spawn position that will be applied when this world is created.
305+ * <p>
306+ * If this returns {@code null}, vanilla or custom generator behavior will be used
307+ * to determine the spawn position.
308+ *
309+ * @return the forced spawn position, or {@code null} for the vanilla behavior
310+ */
311+ public @ Nullable Position forcedSpawnPosition () {
312+ return this .spawnPositionOverride ;
313+ }
314+
315+ /**
316+ * Gets the forced spawn yaw that will be applied when this world is created.
317+ * <p>
318+ * If this returns {@code null}, the spawn yaw will be determined by vanilla behavior
319+ * or the world generator.
320+ * <p>
321+ * This value is only meaningful if a forced spawn position is present.
322+ *
323+ * @return the forced spawn yaw, or {@code null} for the vanilla behavior
324+ */
325+ public @ Nullable Float forcedSpawnYaw () {
326+ return this .spawnYawOverride ;
327+ }
328+
329+ /**
330+ * Gets the forced spawn pitch that will be applied when this world is created.
331+ * <p>
332+ * If this returns {@code null}, the spawn pitch will be determined by vanilla behavior
333+ * or the world generator.
334+ * <p>
335+ * This value is only meaningful if a forced spawn position is present.
336+ *
337+ * @return the forced spawn pitch, or {@code null} for the vanilla behavior
338+ */
339+ public @ Nullable Float forcedSpawnPitch () {
340+ return this .spawnPitchOverride ;
341+ }
342+
264343 /**
265344 * Gets the generator that will be used to create or load the world.
266345 * <p>
0 commit comments