Add AbstractDhApiChunkWorldGenerator
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
||||
package com.seibel.distanthorizons.api.interfaces.override.worldGenerator;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel;
|
||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.IDhApiOverrideable;
|
||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 2023-6-22
|
||||
*/
|
||||
public abstract class AbstractDhApiChunkWorldGenerator implements Closeable, IDhApiOverrideable, IDhApiWorldGenerator
|
||||
{
|
||||
//============//
|
||||
// parameters //
|
||||
//============//
|
||||
|
||||
@Override
|
||||
public final byte getSmallestDataDetailLevel() { return EDhApiDetailLevel.BLOCK.detailLevel; }
|
||||
@Override
|
||||
public final byte getLargestDataDetailLevel() { return EDhApiDetailLevel.BLOCK.detailLevel; }
|
||||
@Override
|
||||
public final byte getMinGenerationGranularity() { return EDhApiDetailLevel.CHUNK.detailLevel; }
|
||||
@Override
|
||||
public final byte getMaxGenerationGranularity() { return (byte) (EDhApiDetailLevel.CHUNK.detailLevel + 2); }
|
||||
|
||||
|
||||
|
||||
//=================//
|
||||
// world generator //
|
||||
//=================//
|
||||
|
||||
@Override
|
||||
public final CompletableFuture<Void> generateChunks(
|
||||
int chunkPosMinX, int chunkPosMinZ,
|
||||
byte granularity, byte targetDataDetail, EDhApiDistantGeneratorMode generatorMode,
|
||||
ExecutorService worldGeneratorThreadPool, Consumer<Object[]> resultConsumer) throws ClassCastException
|
||||
{
|
||||
return CompletableFuture.runAsync(() ->
|
||||
{
|
||||
// TODO what does this mean?
|
||||
int genChunkWidth = BitShiftUtil.powerOfTwo(granularity - 4);
|
||||
|
||||
for (int chunkX = chunkPosMinX; chunkX < chunkPosMinX+genChunkWidth; chunkX++)
|
||||
{
|
||||
for (int chunkZ = chunkPosMinZ; chunkZ< chunkPosMinZ+genChunkWidth; chunkZ++)
|
||||
{
|
||||
Object[] rawMcObjectArray = this.generateChunk(chunkX, chunkZ, generatorMode);
|
||||
resultConsumer.accept(rawMcObjectArray);
|
||||
}
|
||||
}
|
||||
}, worldGeneratorThreadPool);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to generate terrain over a given area
|
||||
* from a thread defined by Distant Horizons. <br><br>
|
||||
*
|
||||
* See {@link IDhApiWorldGenerator#generateChunks(int, int, byte, byte, EDhApiDistantGeneratorMode, ExecutorService, Consumer) IDhApiWorldGenerator.generateChunks}
|
||||
* for the list of Object's this method should return along with additional documentation.
|
||||
*
|
||||
* @see IDhApiWorldGenerator#generateChunks(int, int, byte, byte, EDhApiDistantGeneratorMode, ExecutorService, Consumer) IDhApiWorldGenerator#generateChunks
|
||||
*/
|
||||
public abstract Object[] generateChunk(int chunkPosX, int chunkPosZ, EDhApiDistantGeneratorMode generatorMode);
|
||||
|
||||
}
|
||||
+4
-8
@@ -3,7 +3,6 @@ package com.seibel.distanthorizons.api.interfaces.override.worldGenerator;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.IDhApiOverrideable;
|
||||
import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel;
|
||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenThreadMode;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -12,7 +11,7 @@ import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 2023-6-5
|
||||
* @version 2023-6-22
|
||||
*/
|
||||
public interface IDhApiWorldGenerator extends Closeable, IDhApiOverrideable
|
||||
{
|
||||
@@ -82,23 +81,20 @@ public interface IDhApiWorldGenerator extends Closeable, IDhApiOverrideable
|
||||
//=================//
|
||||
|
||||
/**
|
||||
* This method is called by Distant Horizons to generate terrain over a given area
|
||||
* from a thread defined by Distant Horizons. <br><br>
|
||||
* This method is called by Distant Horizons to generate terrain over a given area. <br><br>
|
||||
*
|
||||
* After a chunk has been generated it (and any necessary supporting objects as listed below) should be passed into the
|
||||
* resultConsumer's {@link Consumer#accept} method. If the Consumer is given the wrong data
|
||||
* type(s) it will throw a {@link ClassCastException} with a list of what objects it was expecting. <br>
|
||||
* type(s) it will disable the world generator and log an error with a list of objects it was expecting. <br>
|
||||
* <strong>Note:</strong> these objects are minecraft version dependent and will change without notice!
|
||||
* Please run your generator in game at least once to confirm the objects you are returning are correct. <br><br>
|
||||
*
|
||||
* Consumer expected inputs for each minecraft version (in order): <br>
|
||||
* <strong>1.18:</strong> {@link net.minecraft.world.level.chunk.ChunkAccess} and {@link net.minecraft.world.level.LevelReader} <br>
|
||||
*
|
||||
* @throws ClassCastException if incompatible objects are passed into the resultConsumer.
|
||||
*/
|
||||
CompletableFuture<Void> generateChunks(int chunkPosMinX, int chunkPosMinZ,
|
||||
byte granularity, byte targetDataDetail, EDhApiDistantGeneratorMode generatorMode,
|
||||
ExecutorService worldGeneratorThreadPool, Consumer<Object[]> resultConsumer) throws ClassCastException;
|
||||
ExecutorService worldGeneratorThreadPool, Consumer<Object[]> resultConsumer);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,19 +19,18 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.generation;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenThreadMode;
|
||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IOverrideInjector;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvironmentWrapper;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package testItems.worldGeneratorInjection.objects;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenThreadMode;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
|
||||
Reference in New Issue
Block a user