Add (untested) DhApiTerrainDataRepo.overwriteChunkDataAsync()
This commit is contained in:
+31
-5
@@ -1,6 +1,7 @@
|
||||
package com.seibel.distanthorizons.api.interfaces.data;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
|
||||
import com.seibel.distanthorizons.api.interfaces.world.IDhApiLevelWrapper;
|
||||
import com.seibel.distanthorizons.api.objects.DhApiResult;
|
||||
import com.seibel.distanthorizons.api.objects.data.DhApiRaycastResult;
|
||||
@@ -10,16 +11,20 @@ import com.seibel.distanthorizons.api.objects.data.DhApiTerrainDataPoint;
|
||||
* Used to interface with Distant Horizons' terrain data.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-11-19
|
||||
* @version 2023-6-16
|
||||
*/
|
||||
public interface IDhApiTerrainDataRepo
|
||||
{
|
||||
|
||||
//=========//
|
||||
// getters //
|
||||
//=========//
|
||||
|
||||
/** Returns the terrain datapoint at the given block position, at or containing the given Y position. */
|
||||
DhApiResult<DhApiTerrainDataPoint> getSingleDataPointAtBlockPos(IDhApiLevelWrapper levelWrapper, int blockPosX, int blockPosY, int blockPosZ);
|
||||
/** Returns every datapoint in the column located at the given block X and Z position top to bottom. */
|
||||
DhApiResult<DhApiTerrainDataPoint[]> getColumnDataAtBlockPos(IDhApiLevelWrapper levelWrapper, int blockPosX, int blockPosZ);
|
||||
|
||||
|
||||
/**
|
||||
* Returns every datapoint in the given chunk's X and Z position. <br><br>
|
||||
*
|
||||
@@ -29,7 +34,6 @@ public interface IDhApiTerrainDataRepo
|
||||
*/
|
||||
DhApiResult<DhApiTerrainDataPoint[][][]> getAllTerrainDataAtChunkPos(IDhApiLevelWrapper levelWrapper, int chunkPosX, int chunkPosZ);
|
||||
|
||||
|
||||
/**
|
||||
* Returns every datapoint in the given region's X and Z position. <br><br>
|
||||
*
|
||||
@@ -39,7 +43,6 @@ public interface IDhApiTerrainDataRepo
|
||||
*/
|
||||
DhApiResult<DhApiTerrainDataPoint[][][]> getAllTerrainDataAtRegionPos(IDhApiLevelWrapper levelWrapper, int regionPosX, int regionPosZ);
|
||||
|
||||
|
||||
/**
|
||||
* Returns every datapoint in the column located at the given detail level and X/Z position. <br>
|
||||
* This can be used to return terrain data for non-standard sizes (IE 2x2 blocks or 2x2 chunks).
|
||||
@@ -51,7 +54,6 @@ public interface IDhApiTerrainDataRepo
|
||||
*/
|
||||
DhApiResult<DhApiTerrainDataPoint[][][]> getAllTerrainDataAtDetailLevelAndPos(IDhApiLevelWrapper levelWrapper, byte detailLevel, int posX, int posZ);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the datapoint and position of the LOD
|
||||
* at the end of the given ray. <br><br>
|
||||
@@ -63,4 +65,28 @@ public interface IDhApiTerrainDataRepo
|
||||
float rayDirectionX, float rayDirectionY, float rayDirectionZ,
|
||||
int maxRayBlockLength);
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// setters //
|
||||
//=========//
|
||||
|
||||
/**
|
||||
* Sets the LOD data for the given chunk at the chunk's position. <br><br>
|
||||
*
|
||||
* Notes: <br>
|
||||
* - Only works if the given {@link IDhApiLevelWrapper} points to a loaded level.
|
||||
* - If the player travels to this chunk, or the chunk is updated is some other way; your data will be replaced
|
||||
* by whatever the current chunk is. <br>
|
||||
* - This method may not update the LOD data immediately. Any other chunks have
|
||||
* been queued to update, they will be handled first.
|
||||
*
|
||||
* @param levelWrapper the level wrapper that the chunk should be saved to.
|
||||
* @param chunkObjectArray see {@link IDhApiWorldGenerator#generateChunks} for what objects are expected.
|
||||
*
|
||||
* @throws ClassCastException if chunkObjectArray doesn't contain the right objects.
|
||||
* The exception will contain the expected object(s).
|
||||
*/
|
||||
public DhApiResult<Void> overwriteChunkDataAsync(IDhApiLevelWrapper levelWrapper, Object[] chunkObjectArray) throws ClassCastException;
|
||||
|
||||
}
|
||||
|
||||
+35
-1
@@ -1,5 +1,6 @@
|
||||
package com.seibel.distanthorizons.core.api.external.methods.data;
|
||||
|
||||
import com.seibel.distanthorizons.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
|
||||
import com.seibel.distanthorizons.api.interfaces.world.IDhApiLevelWrapper;
|
||||
import com.seibel.distanthorizons.api.objects.DhApiResult;
|
||||
import com.seibel.distanthorizons.api.objects.data.DhApiRaycastResult;
|
||||
@@ -18,11 +19,12 @@ import com.seibel.distanthorizons.core.util.FullDataPointUtil;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.RayCastUtil;
|
||||
import com.seibel.distanthorizons.core.world.AbstractDhWorld;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.core.util.*;
|
||||
import com.seibel.distanthorizons.coreapi.util.BitShiftUtil;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Vec3d;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Vec3f;
|
||||
@@ -418,6 +420,38 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// setter methods //
|
||||
//================//
|
||||
|
||||
public DhApiResult<Void> overwriteChunkDataAsync(IDhApiLevelWrapper levelWrapper, Object[] chunkObjectArray) throws ClassCastException
|
||||
{
|
||||
if (!(levelWrapper instanceof ILevelWrapper))
|
||||
{
|
||||
return DhApiResult.createFail("Level wrapper needs to be an instance of ["+IDhApiLevelWrapper.class.getSimpleName()+"].");
|
||||
}
|
||||
AbstractDhWorld dhWorld = SharedApi.getAbstractDhWorld();
|
||||
if (dhWorld == null)
|
||||
{
|
||||
return DhApiResult.createFail("No world loaded. This method can only be called while in a loaded world.");
|
||||
}
|
||||
|
||||
IDhLevel dhLevel = dhWorld.getLevel((ILevelWrapper) levelWrapper);
|
||||
if (dhLevel == null)
|
||||
{
|
||||
return DhApiResult.createFail("No level exists for the given level wrapper. This either means the level hasn't been loaded yet, or was unloaded.");
|
||||
}
|
||||
|
||||
|
||||
// this will throw a cast exception if the chunk object array isn't correct
|
||||
IChunkWrapper chunk = SingletonInjector.INSTANCE.get(IWrapperFactory.class).createChunkWrapper(chunkObjectArray);
|
||||
dhLevel.updateChunkAsync(chunk);
|
||||
|
||||
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// debug methods //
|
||||
|
||||
Reference in New Issue
Block a user