From 173e216fa3172f1d5b1bd3c26b05e0e178af92bf Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 19 Jun 2023 22:04:10 -0500 Subject: [PATCH] Add (untested) DhApiTerrainDataRepo.overwriteChunkDataAsync() --- .../data/IDhApiTerrainDataRepo.java | 36 ++++++++++++++++--- .../methods/data/DhApiTerrainDataRepo.java | 36 ++++++++++++++++++- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/data/IDhApiTerrainDataRepo.java b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/data/IDhApiTerrainDataRepo.java index e6b838203..04f89ad17 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/data/IDhApiTerrainDataRepo.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/data/IDhApiTerrainDataRepo.java @@ -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 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 getColumnDataAtBlockPos(IDhApiLevelWrapper levelWrapper, int blockPosX, int blockPosZ); - /** * Returns every datapoint in the given chunk's X and Z position.

* @@ -29,7 +34,6 @@ public interface IDhApiTerrainDataRepo */ DhApiResult getAllTerrainDataAtChunkPos(IDhApiLevelWrapper levelWrapper, int chunkPosX, int chunkPosZ); - /** * Returns every datapoint in the given region's X and Z position.

* @@ -39,7 +43,6 @@ public interface IDhApiTerrainDataRepo */ DhApiResult getAllTerrainDataAtRegionPos(IDhApiLevelWrapper levelWrapper, int regionPosX, int regionPosZ); - /** * Returns every datapoint in the column located at the given detail level and X/Z position.
* 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 getAllTerrainDataAtDetailLevelAndPos(IDhApiLevelWrapper levelWrapper, byte detailLevel, int posX, int posZ); - /** * Returns the datapoint and position of the LOD * at the end of the given ray.

@@ -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.

+ * + * Notes:
+ * - 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.
+ * - 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 overwriteChunkDataAsync(IDhApiLevelWrapper levelWrapper, Object[] chunkObjectArray) throws ClassCastException; + } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java index f6f639925..44ea2b102 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java @@ -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 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 //