Skip to content

Commit 93d4552

Browse files
committed
Add WorldArchetype
Unifies the world creation related parameters. The WorldGenerationConfig was unused in world generation previously and thus was missed.
1 parent 4584e00 commit 93d4552

File tree

2 files changed

+75
-19
lines changed

2 files changed

+75
-19
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.world.server;
26+
27+
import org.spongepowered.api.Sponge;
28+
import org.spongepowered.api.world.generation.config.WorldGenerationConfig;
29+
30+
import java.util.Optional;
31+
32+
public interface WorldArchetype {
33+
34+
static WorldArchetype.Builder builder() {
35+
return Sponge.game().builderProvider().provide(WorldArchetype.Builder.class);
36+
}
37+
38+
static WorldArchetype of(WorldArchetypeType type) {
39+
return WorldArchetype.builder().type(type).build();
40+
}
41+
42+
static WorldArchetype of(WorldArchetypeType type, WorldGenerationConfig generationConfig) {
43+
return WorldArchetype.builder().type(type).generationConfig(generationConfig).build();
44+
}
45+
46+
WorldArchetypeType type();
47+
48+
Optional<WorldGenerationConfig> generationConfig();
49+
50+
interface Builder extends org.spongepowered.api.util.Builder<WorldArchetype, Builder> {
51+
52+
Builder type(WorldArchetypeType type);
53+
54+
Builder generationConfig(WorldGenerationConfig generationConfig);
55+
}
56+
}

src/main/java/org/spongepowered/api/world/server/storage/ServerWorldProperties.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import org.spongepowered.api.world.gamerule.GameRuleHolder;
4545
import org.spongepowered.api.world.generation.config.WorldGenerationConfig;
4646
import org.spongepowered.api.world.server.ServerWorld;
47-
import org.spongepowered.api.world.server.WorldArchetypeType;
47+
import org.spongepowered.api.world.server.WorldArchetype;
4848
import org.spongepowered.api.world.storage.WorldProperties;
4949
import org.spongepowered.api.world.weather.Weather;
5050
import org.spongepowered.api.world.weather.WeatherUniverse;
@@ -493,15 +493,15 @@ static LoadOptions getOrLoad(Consumer<ServerWorldProperties> getCallback, Consum
493493

494494
/**
495495
* Load a new {@link ServerWorldProperties} from disk
496-
* or create a new one with the provided {@link WorldArchetypeType}.
496+
* or create a new one with the provided {@link WorldArchetype}.
497497
* Do not attempt to use the already loaded instance.
498498
*
499499
* <p>This operation fails if properties were already loaded.</p>
500500
*
501501
* @param worldArchetype The archetype to use for creation.
502502
* @return The load options.
503503
*/
504-
static LoadOptions loadOrCreate(WorldArchetypeType worldArchetype) {
504+
static LoadOptions loadOrCreate(WorldArchetype worldArchetype) {
505505
return LoadOptions.builder()
506506
.load()
507507
.create(worldArchetype)
@@ -510,7 +510,7 @@ static LoadOptions loadOrCreate(WorldArchetypeType worldArchetype) {
510510

511511
/**
512512
* Load a new {@link ServerWorldProperties} from disk
513-
* or create a new one with the provided {@link WorldArchetypeType}.
513+
* or create a new one with the provided {@link WorldArchetype}.
514514
* Do not attempt to use the already loaded instance.
515515
*
516516
* <p>This operation fails if properties were already loaded.</p>
@@ -520,7 +520,7 @@ static LoadOptions loadOrCreate(WorldArchetypeType worldArchetype) {
520520
* creation for additional configuration.
521521
* @return The load options.
522522
*/
523-
static LoadOptions loadOrCreate(WorldArchetypeType worldArchetype, Consumer<ServerWorldProperties> createCallback) {
523+
static LoadOptions loadOrCreate(WorldArchetype worldArchetype, Consumer<ServerWorldProperties> createCallback) {
524524
return LoadOptions.builder()
525525
.load()
526526
.create(worldArchetype)
@@ -530,7 +530,7 @@ static LoadOptions loadOrCreate(WorldArchetypeType worldArchetype, Consumer<Serv
530530

531531
/**
532532
* Load a new {@link ServerWorldProperties} from disk
533-
* or create a new one with the provided {@link WorldArchetypeType}.
533+
* or create a new one with the provided {@link WorldArchetype}.
534534
* Do not attempt to use the already loaded instance.
535535
*
536536
* <p>This operation fails if properties were already loaded.</p>
@@ -542,7 +542,7 @@ static LoadOptions loadOrCreate(WorldArchetypeType worldArchetype, Consumer<Serv
542542
* creation for additional configuration.
543543
* @return The load options.
544544
*/
545-
static LoadOptions loadOrCreate(Consumer<ServerWorldProperties> loadCallback, WorldArchetypeType worldArchetype, Consumer<ServerWorldProperties> createCallback) {
545+
static LoadOptions loadOrCreate(Consumer<ServerWorldProperties> loadCallback, WorldArchetype worldArchetype, Consumer<ServerWorldProperties> createCallback) {
546546
return LoadOptions.builder()
547547
.load()
548548
.loadCallback(loadCallback)
@@ -554,12 +554,12 @@ static LoadOptions loadOrCreate(Consumer<ServerWorldProperties> loadCallback, Wo
554554
/**
555555
* Get the already loaded {@link ServerWorldProperties} or
556556
* attempt to load it from disk. If not found, create a new one
557-
* with the provided {@link WorldArchetypeType}.
557+
* with the provided {@link WorldArchetype}.
558558
*
559559
* @param worldArchetype The archetype to use for creation.
560560
* @return The load options.
561561
*/
562-
static LoadOptions getLoadOrCreate(WorldArchetypeType worldArchetype) {
562+
static LoadOptions getLoadOrCreate(WorldArchetype worldArchetype) {
563563
return LoadOptions.builder()
564564
.get()
565565
.load()
@@ -570,14 +570,14 @@ static LoadOptions getLoadOrCreate(WorldArchetypeType worldArchetype) {
570570
/**
571571
* Get the already loaded {@link ServerWorldProperties} or
572572
* attempt to load it from disk. If not found, create a new one
573-
* with the provided {@link WorldArchetypeType}.
573+
* with the provided {@link WorldArchetype}.
574574
*
575575
* @param worldArchetype The archetype to use for creation.
576576
* @param createCallback The consumer to call after successful
577577
* creation for additional configuration.
578578
* @return The load options.
579579
*/
580-
static LoadOptions getLoadOrCreate(WorldArchetypeType worldArchetype, Consumer<ServerWorldProperties> createCallback) {
580+
static LoadOptions getLoadOrCreate(WorldArchetype worldArchetype, Consumer<ServerWorldProperties> createCallback) {
581581
return LoadOptions.builder()
582582
.get()
583583
.load()
@@ -589,7 +589,7 @@ static LoadOptions getLoadOrCreate(WorldArchetypeType worldArchetype, Consumer<S
589589
/**
590590
* Get the already loaded {@link ServerWorldProperties} or
591591
* attempt to load it from disk. If not found, create a new one
592-
* with the provided {@link WorldArchetypeType}.
592+
* with the provided {@link WorldArchetype}.
593593
*
594594
* @param getCallback The consumer to call after successful
595595
* get operation for additional configuration.
@@ -600,7 +600,7 @@ static LoadOptions getLoadOrCreate(WorldArchetypeType worldArchetype, Consumer<S
600600
* creation for additional configuration.
601601
* @return The load options.
602602
*/
603-
static LoadOptions getLoadOrCreate(Consumer<ServerWorldProperties> getCallback, Consumer<ServerWorldProperties> loadCallback, WorldArchetypeType worldArchetype, Consumer<ServerWorldProperties> createCallback) {
603+
static LoadOptions getLoadOrCreate(Consumer<ServerWorldProperties> getCallback, Consumer<ServerWorldProperties> loadCallback, WorldArchetype worldArchetype, Consumer<ServerWorldProperties> createCallback) {
604604
return LoadOptions.builder()
605605
.get()
606606
.getCallback(getCallback)
@@ -613,23 +613,23 @@ static LoadOptions getLoadOrCreate(Consumer<ServerWorldProperties> getCallback,
613613

614614
/**
615615
* Create a new {@link ServerWorldProperties} with the given
616-
* {@link WorldArchetypeType} but do not attempt to load
616+
* {@link WorldArchetype} but do not attempt to load
617617
* it from disk or use the already loaded instance.
618618
*
619619
* <p>The operation fails if properties could not be created.</p>
620620
*
621621
* @param worldArchetype The archetype to use.
622622
* @return The load options.
623623
*/
624-
static LoadOptions create(WorldArchetypeType worldArchetype) {
624+
static LoadOptions create(WorldArchetype worldArchetype) {
625625
return LoadOptions.builder()
626626
.create(worldArchetype)
627627
.build();
628628
}
629629

630630
/**
631631
* Create a new {@link ServerWorldProperties} with the given
632-
* {@link WorldArchetypeType} but do not attempt to load
632+
* {@link WorldArchetype} but do not attempt to load
633633
* it from disk or use the already loaded instance.
634634
*
635635
* <p>The operation fails if properties could not be created.</p>
@@ -639,7 +639,7 @@ static LoadOptions create(WorldArchetypeType worldArchetype) {
639639
* creation for additional configuration.
640640
* @return The load options.
641641
*/
642-
static LoadOptions create(WorldArchetypeType worldArchetype, Consumer<ServerWorldProperties> createCallback) {
642+
static LoadOptions create(WorldArchetype worldArchetype, Consumer<ServerWorldProperties> createCallback) {
643643
return LoadOptions.builder()
644644
.create(worldArchetype)
645645
.createCallback(createCallback)
@@ -685,7 +685,7 @@ interface LoadOperation {
685685

686686
interface CreateOperation {
687687

688-
WorldArchetypeType worldArchetype();
688+
WorldArchetype worldArchetype();
689689

690690
Optional<Consumer<ServerWorldProperties>> createCallback();
691691
}
@@ -696,7 +696,7 @@ interface Builder extends org.spongepowered.api.util.Builder<LoadOptions, Builde
696696

697697
Builder.LoadStep load();
698698

699-
Builder.CreateStep create(WorldArchetypeType worldArchetype);
699+
Builder.CreateStep create(WorldArchetype worldArchetype);
700700

701701
interface GetStep extends Builder {
702702

0 commit comments

Comments
 (0)