-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
560 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
Allay-API/src/main/java/org/allaymc/api/world/generator/ChunkGenerateContext.java
This file was deleted.
Oops, something went wrong.
76 changes: 39 additions & 37 deletions
76
Allay-API/src/main/java/org/allaymc/api/world/generator/WorldGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,55 @@ | ||
package org.allaymc.api.world.generator; | ||
|
||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.allaymc.api.utils.AllayStringUtils; | ||
import org.allaymc.api.ApiInstanceHolder; | ||
import org.allaymc.api.world.Dimension; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.allaymc.api.world.chunk.Chunk; | ||
import org.allaymc.api.world.generator.function.EntitySpawner; | ||
import org.allaymc.api.world.generator.function.Noiser; | ||
import org.allaymc.api.world.generator.function.Lighter; | ||
import org.allaymc.api.world.generator.function.Populator; | ||
|
||
/** | ||
* Allay Project 2023/7/1 | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
@Getter | ||
@Slf4j | ||
public abstract class WorldGenerator { | ||
public interface WorldGenerator { | ||
|
||
protected String preset; | ||
protected Dimension dimension; | ||
ApiInstanceHolder<WorldGeneratorBuilderFactory> BUILDER_FACTORY = ApiInstanceHolder.create(); | ||
|
||
public WorldGenerator(String preset) { | ||
this.preset = preset; | ||
static WorldGeneratorBuilder builder() { | ||
return BUILDER_FACTORY.get().create(); | ||
} | ||
|
||
public void setDimension(Dimension dimension) { | ||
this.dimension = dimension; | ||
Chunk generateFinishedChunkSynchronously(int x, int z); | ||
|
||
String getName(); | ||
|
||
WorldGeneratorType getType(); | ||
|
||
String getPreset(); | ||
|
||
void setDimension(Dimension dimension); | ||
|
||
interface WorldGeneratorBuilder { | ||
WorldGeneratorBuilder name(String name); | ||
|
||
WorldGeneratorBuilder type(WorldGeneratorType type); | ||
|
||
WorldGeneratorBuilder preset(String preset); | ||
|
||
WorldGeneratorBuilder noisers(Noiser... noisers); | ||
|
||
WorldGeneratorBuilder populators(Populator... populators); | ||
|
||
WorldGeneratorBuilder lighters(Lighter... lighters); | ||
|
||
WorldGeneratorBuilder entitySpawners(EntitySpawner... entitySpawners); | ||
|
||
WorldGenerator build(); | ||
} | ||
|
||
//empty chunk -> 各种 noise-> biome -> calc height map -> generate -> carvers | ||
//feature -> structure place-> calc light -> spawn entity -> full | ||
public abstract void generate(ChunkGenerateContext context); | ||
|
||
public abstract String getGeneratorName(); | ||
|
||
public abstract WorldGeneratorType getType(); | ||
|
||
public static Map<String, String> parseOptions(String preset) { | ||
var splits = AllayStringUtils.fastSplit(preset, ";"); | ||
var options = new HashMap<String, String>(); | ||
for(var split : splits) { | ||
if (!split.contains("=")) { | ||
log.warn("Invalid option: {}", split); | ||
continue; | ||
} | ||
var kv = AllayStringUtils.fastTwoPartSplit(split, "=", ""); | ||
options.put(kv[0], kv[1]); | ||
} | ||
return options; | ||
interface WorldGeneratorBuilderFactory { | ||
WorldGeneratorBuilder create(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Allay-API/src/main/java/org/allaymc/api/world/generator/context/Context.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.allaymc.api.world.generator.context; | ||
|
||
import lombok.Getter; | ||
import org.allaymc.api.world.DimensionInfo; | ||
import org.allaymc.api.world.chunk.UnsafeChunk; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public abstract class Context { | ||
@Getter | ||
protected UnsafeChunk currentChunk; | ||
|
||
public Context(UnsafeChunk currentChunk) { | ||
this.currentChunk = currentChunk; | ||
} | ||
|
||
protected DimensionInfo getDimensionInfo() { | ||
return currentChunk.getDimensionInfo(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Allay-API/src/main/java/org/allaymc/api/world/generator/context/EntitySpawnContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.allaymc.api.world.generator.context; | ||
|
||
import org.allaymc.api.world.chunk.ChunkAccessible; | ||
import org.allaymc.api.world.chunk.UnsafeChunk; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class EntitySpawnContext extends OtherChunkAccessibleContext { | ||
|
||
public EntitySpawnContext(UnsafeChunk currentChunk, ChunkAccessible chunkAccessor) { | ||
super(currentChunk, chunkAccessor); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Allay-API/src/main/java/org/allaymc/api/world/generator/context/LightContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.allaymc.api.world.generator.context; | ||
|
||
import org.allaymc.api.world.chunk.UnsafeChunk; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class LightContext extends Context { | ||
public LightContext(UnsafeChunk currentChunk) { | ||
super(currentChunk); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Allay-API/src/main/java/org/allaymc/api/world/generator/context/NoiseContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.allaymc.api.world.generator.context; | ||
|
||
import org.allaymc.api.world.chunk.UnsafeChunk; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class NoiseContext extends Context { | ||
public NoiseContext(UnsafeChunk currentChunk) { | ||
super(currentChunk); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...PI/src/main/java/org/allaymc/api/world/generator/context/OtherChunkAccessibleContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.allaymc.api.world.generator.context; | ||
|
||
import org.allaymc.api.world.chunk.ChunkAccessible; | ||
import org.allaymc.api.world.chunk.UnsafeChunk; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public abstract class OtherChunkAccessibleContext extends Context { | ||
|
||
protected ChunkAccessible chunkAccessor; | ||
|
||
public OtherChunkAccessibleContext(UnsafeChunk currentChunk, ChunkAccessible chunkAccessor) { | ||
super(currentChunk); | ||
this.chunkAccessor = chunkAccessor; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Allay-API/src/main/java/org/allaymc/api/world/generator/context/PopulateContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.allaymc.api.world.generator.context; | ||
|
||
import org.allaymc.api.world.chunk.ChunkAccessible; | ||
import org.allaymc.api.world.chunk.UnsafeChunk; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class PopulateContext extends OtherChunkAccessibleContext { | ||
public PopulateContext(UnsafeChunk currentChunk, ChunkAccessible chunkAccessor) { | ||
super(currentChunk, chunkAccessor); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Allay-API/src/main/java/org/allaymc/api/world/generator/function/EntitySpawner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.allaymc.api.world.generator.function; | ||
|
||
import org.allaymc.api.world.generator.context.EntitySpawnContext; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public interface EntitySpawner extends Function<EntitySpawnContext, Boolean>, GenerateFunction { | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
Allay-API/src/main/java/org/allaymc/api/world/generator/function/GenerateFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.allaymc.api.world.generator.function; | ||
|
||
import org.allaymc.api.world.generator.WorldGenerator; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public interface GenerateFunction { | ||
default void init(WorldGenerator generator) {} | ||
|
||
String getName(); | ||
} |
14 changes: 14 additions & 0 deletions
14
Allay-API/src/main/java/org/allaymc/api/world/generator/function/Lighter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.allaymc.api.world.generator.function; | ||
|
||
import org.allaymc.api.world.generator.context.LightContext; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public interface Lighter extends Function<LightContext, Boolean>, GenerateFunction { | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
Allay-API/src/main/java/org/allaymc/api/world/generator/function/Noiser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.allaymc.api.world.generator.function; | ||
|
||
import org.allaymc.api.world.generator.context.NoiseContext; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Allay Project 2024/6/16 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public interface Noiser extends Function<NoiseContext, Boolean>, GenerateFunction { | ||
|
||
} |
Oops, something went wrong.