Add IChunkWrapper
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
package com.seibel.lod.api.forge;
|
||||
|
||||
import com.seibel.lod.api.lod.EventApi;
|
||||
import com.seibel.lod.core.wrapperAdapters.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.lod.wrappers.world.DimensionTypeWrapper;
|
||||
import com.seibel.lod.wrappers.world.WorldWrapper;
|
||||
@@ -85,7 +86,7 @@ public class ForgeClientProxy
|
||||
event.getClass() == BlockEvent.FluidPlaceBlockEvent.class ||
|
||||
event.getClass() == BlockEvent.PortalSpawnEvent.class)
|
||||
{
|
||||
ChunkWrapper chunk = new ChunkWrapper(event.getWorld().getChunk(event.getPos()));
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getWorld().getChunk(event.getPos()));
|
||||
DimensionTypeWrapper dimType = DimensionTypeWrapper.getDimensionTypeWrapper(event.getWorld().dimensionType());
|
||||
|
||||
// recreate the LOD where the blocks were changed
|
||||
|
||||
@@ -31,10 +31,10 @@ import com.seibel.lod.core.util.DetailDistanceUtil;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.util.ThreadMapUtil;
|
||||
import com.seibel.lod.core.wrapperAdapters.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperAdapters.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperAdapters.world.IDimensionTypeWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.world.IWorldWrapper;
|
||||
import com.seibel.lod.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.lod.wrappers.minecraft.MinecraftWrapper;
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ public class EventApi
|
||||
// world events //
|
||||
//==============//
|
||||
|
||||
public void chunkLoadEvent(ChunkWrapper chunk, IDimensionTypeWrapper dimType)
|
||||
public void chunkLoadEvent(IChunkWrapper chunk, IDimensionTypeWrapper dimType)
|
||||
{
|
||||
ApiShared.lodBuilder.generateLodNodeAsync(chunk, ApiShared.lodWorld, dimType, DistanceGenerationMode.SERVER);
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public class EventApi
|
||||
}
|
||||
}
|
||||
|
||||
public void blockChangeEvent(ChunkWrapper chunk, IDimensionTypeWrapper dimType)
|
||||
public void blockChangeEvent(IChunkWrapper chunk, IDimensionTypeWrapper dimType)
|
||||
{
|
||||
// recreate the LOD where the blocks were changed
|
||||
ApiShared.lodBuilder.generateLodNodeAsync(chunk, ApiShared.lodWorld, dimType);
|
||||
|
||||
@@ -38,13 +38,13 @@ import com.seibel.lod.core.wrapperAdapters.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperAdapters.block.IBlockColorSingletonWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.block.IBlockColorWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.block.IBlockShapeWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperAdapters.world.IBiomeWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.world.IDimensionTypeWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.world.IWorldWrapper;
|
||||
import com.seibel.lod.wrappers.block.BlockPosWrapper;
|
||||
import com.seibel.lod.wrappers.chunk.ChunkPosWrapper;
|
||||
import com.seibel.lod.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.lod.wrappers.minecraft.MinecraftWrapper;
|
||||
|
||||
/**
|
||||
@@ -87,12 +87,12 @@ public class LodBuilder
|
||||
|
||||
}
|
||||
|
||||
public void generateLodNodeAsync(ChunkWrapper chunk, LodWorld lodWorld, IDimensionTypeWrapper dim)
|
||||
public void generateLodNodeAsync(IChunkWrapper chunk, LodWorld lodWorld, IDimensionTypeWrapper dim)
|
||||
{
|
||||
generateLodNodeAsync(chunk, lodWorld, dim, DistanceGenerationMode.SERVER);
|
||||
}
|
||||
|
||||
public void generateLodNodeAsync(ChunkWrapper chunk, LodWorld lodWorld, IDimensionTypeWrapper dim, DistanceGenerationMode generationMode)
|
||||
public void generateLodNodeAsync(IChunkWrapper chunk, LodWorld lodWorld, IDimensionTypeWrapper dim, DistanceGenerationMode generationMode)
|
||||
{
|
||||
if (lodWorld == null || lodWorld.getIsWorldNotLoaded())
|
||||
return;
|
||||
@@ -145,7 +145,7 @@ public class LodBuilder
|
||||
* Creates a LodNode for a chunk in the given world.
|
||||
* @throws IllegalArgumentException thrown if either the chunk or world is null.
|
||||
*/
|
||||
public void generateLodNodeFromChunk(LodDimension lodDim, ChunkWrapper chunk) throws IllegalArgumentException
|
||||
public void generateLodNodeFromChunk(LodDimension lodDim, IChunkWrapper chunk) throws IllegalArgumentException
|
||||
{
|
||||
generateLodNodeFromChunk(lodDim, chunk, new LodBuilderConfig());
|
||||
}
|
||||
@@ -154,7 +154,7 @@ public class LodBuilder
|
||||
* Creates a LodNode for a chunk in the given world.
|
||||
* @throws IllegalArgumentException thrown if either the chunk or world is null.
|
||||
*/
|
||||
public void generateLodNodeFromChunk(LodDimension lodDim, ChunkWrapper chunk, LodBuilderConfig config)
|
||||
public void generateLodNodeFromChunk(LodDimension lodDim, IChunkWrapper chunk, LodBuilderConfig config)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (chunk == null)
|
||||
@@ -207,7 +207,7 @@ public class LodBuilder
|
||||
}
|
||||
|
||||
/** creates a vertical DataPoint */
|
||||
private long[] createVerticalDataToMerge(HorizontalResolution detail, ChunkWrapper chunk, LodBuilderConfig config, int startX, int startZ)
|
||||
private long[] createVerticalDataToMerge(HorizontalResolution detail, IChunkWrapper chunk, LodBuilderConfig config, int startX, int startZ)
|
||||
{
|
||||
// equivalent to 2^detailLevel
|
||||
int size = 1 << detail.detailLevel;
|
||||
@@ -293,7 +293,7 @@ public class LodBuilder
|
||||
* Find the lowest valid point from the bottom.
|
||||
* Used when creating a vertical LOD.
|
||||
*/
|
||||
private short determineBottomPointFrom(ChunkWrapper chunk, LodBuilderConfig config, int xAbs, int yAbs, int zAbs, BlockPosWrapper blockPos)
|
||||
private short determineBottomPointFrom(IChunkWrapper chunk, LodBuilderConfig config, int xAbs, int yAbs, int zAbs, BlockPosWrapper blockPos)
|
||||
{
|
||||
short depth = DEFAULT_DEPTH;
|
||||
|
||||
@@ -310,7 +310,7 @@ public class LodBuilder
|
||||
}
|
||||
|
||||
/** Find the highest valid point from the Top */
|
||||
private short determineHeightPointFrom(ChunkWrapper chunk, LodBuilderConfig config, int xAbs, int yAbs, int zAbs, BlockPosWrapper blockPos)
|
||||
private short determineHeightPointFrom(IChunkWrapper chunk, LodBuilderConfig config, int xAbs, int yAbs, int zAbs, BlockPosWrapper blockPos)
|
||||
{
|
||||
short height = DEFAULT_HEIGHT;
|
||||
if (config.useHeightmap)
|
||||
@@ -340,7 +340,7 @@ public class LodBuilder
|
||||
* Generate the color for the given chunk using biome water color, foliage
|
||||
* color, and grass color.
|
||||
*/
|
||||
private int generateLodColor(ChunkWrapper chunk, LodBuilderConfig builderConfig, int xRel, int yAbs, int zRel, BlockPosWrapper blockPos)
|
||||
private int generateLodColor(IChunkWrapper chunk, LodBuilderConfig builderConfig, int xRel, int yAbs, int zRel, BlockPosWrapper blockPos)
|
||||
{
|
||||
int colorInt;
|
||||
if (builderConfig.useBiomeColors)
|
||||
@@ -378,7 +378,7 @@ public class LodBuilder
|
||||
}
|
||||
|
||||
/** Gets the light value for the given block position */
|
||||
private int getLightValue(ChunkWrapper chunk, BlockPosWrapper blockPos, boolean hasCeiling, boolean hasSkyLight, boolean topBlock)
|
||||
private int getLightValue(IChunkWrapper chunk, BlockPosWrapper blockPos, boolean hasCeiling, boolean hasSkyLight, boolean topBlock)
|
||||
{
|
||||
int skyLight = 0;
|
||||
int blockLight;
|
||||
@@ -466,7 +466,7 @@ public class LodBuilder
|
||||
}
|
||||
|
||||
/** Returns a color int for the given block. */
|
||||
private int getColorForBlock(ChunkWrapper chunk, BlockPosWrapper blockPos)
|
||||
private int getColorForBlock(IChunkWrapper chunk, BlockPosWrapper blockPos)
|
||||
{
|
||||
|
||||
|
||||
@@ -515,7 +515,7 @@ public class LodBuilder
|
||||
|
||||
|
||||
/** Is the block at the given blockPos a valid LOD point? */
|
||||
private boolean isLayerValidLodPoint(ChunkWrapper chunk, BlockPosWrapper blockPos)
|
||||
private boolean isLayerValidLodPoint(IChunkWrapper chunk, BlockPosWrapper blockPos)
|
||||
{
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.seibel.lod.core.wrapperAdapters.chunk;
|
||||
|
||||
import com.seibel.lod.core.wrapperAdapters.block.IBlockColorWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.block.IBlockShapeWrapper;
|
||||
import com.seibel.lod.wrappers.block.BlockPosWrapper;
|
||||
import com.seibel.lod.wrappers.chunk.ChunkPosWrapper;
|
||||
import com.seibel.lod.wrappers.world.BiomeWrapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ??
|
||||
* @version 11-17-2021
|
||||
*/
|
||||
public interface IChunkWrapper
|
||||
{
|
||||
public int getHeight();
|
||||
|
||||
public boolean isPositionInWater(BlockPosWrapper blockPos);
|
||||
|
||||
public int getHeightMapValue(int xRel, int zRel);
|
||||
|
||||
public BiomeWrapper getBiome(int xRel, int yAbs, int zRel);
|
||||
|
||||
public IBlockColorWrapper getBlockColorWrapper(BlockPosWrapper blockPos);
|
||||
|
||||
public IBlockShapeWrapper getBlockShapeWrapper(BlockPosWrapper blockPos);
|
||||
|
||||
public ChunkPosWrapper getPos();
|
||||
|
||||
public boolean isLightCorrect();
|
||||
|
||||
public boolean isWaterLogged(BlockPosWrapper blockPos);
|
||||
|
||||
public int getEmittedBrightness(BlockPosWrapper blockPos);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.seibel.lod.core.wrapperAdapters.block.IBlockShapeWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.wrappers.chunk.ChunkWrapper;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -30,13 +31,13 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
|
||||
private boolean noCollision;
|
||||
|
||||
/**Constructor only require for the block instance we are wrapping**/
|
||||
public BlockShapeWrapper(Block block, ChunkWrapper chunkWrapper, BlockPosWrapper blockPosWrapper)
|
||||
public BlockShapeWrapper(Block block, IChunkWrapper chunkWrapper, BlockPosWrapper blockPosWrapper)
|
||||
{
|
||||
this.block = block;
|
||||
this.nonFull = false;
|
||||
this.noCollision = false;
|
||||
this.toAvoid = ofBlockToAvoid();
|
||||
setupShapes(chunkWrapper, blockPosWrapper);
|
||||
setupShapes((ChunkWrapper) chunkWrapper, blockPosWrapper);
|
||||
//System.out.println(block + " non full " + nonFull + " no collision " + noCollision + " to avoid " + toAvoid);
|
||||
}
|
||||
|
||||
@@ -52,7 +53,7 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
|
||||
* this return a wrapper of the block in input
|
||||
* @param block Block object to wrap
|
||||
*/
|
||||
static public BlockShapeWrapper getBlockShapeWrapper(Block block, ChunkWrapper chunkWrapper, BlockPosWrapper blockPosWrapper)
|
||||
static public BlockShapeWrapper getBlockShapeWrapper(Block block, IChunkWrapper chunkWrapper, BlockPosWrapper blockPosWrapper)
|
||||
{
|
||||
//first we check if the block has already been wrapped
|
||||
if (blockShapeWrapperMap.containsKey(block) && blockShapeWrapperMap.get(block) != null)
|
||||
@@ -105,6 +106,7 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ofBlockToAvoid()
|
||||
{
|
||||
return block.equals(Blocks.AIR)
|
||||
@@ -117,16 +119,19 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
|
||||
//-----------------//
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isNonFull()
|
||||
{
|
||||
return nonFull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNoCollision()
|
||||
{
|
||||
return noCollision;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToAvoid()
|
||||
{
|
||||
return toAvoid;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.seibel.lod.wrappers.chunk;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.wrapperAdapters.block.IBlockColorWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.block.IBlockShapeWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.wrappers.block.BlockColorWrapper;
|
||||
import com.seibel.lod.wrappers.block.BlockPosWrapper;
|
||||
import com.seibel.lod.wrappers.block.BlockShapeWrapper;
|
||||
@@ -14,16 +15,23 @@ import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
|
||||
public class ChunkWrapper
|
||||
/**
|
||||
*
|
||||
* @author ??
|
||||
* @version 11-17-2021
|
||||
*/
|
||||
public class ChunkWrapper implements IChunkWrapper
|
||||
{
|
||||
|
||||
private final IChunk chunk;
|
||||
private final ChunkPosWrapper chunkPos;
|
||||
|
||||
public int getHeight(){
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
return chunk.getMaxBuildHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPositionInWater(BlockPosWrapper blockPos)
|
||||
{
|
||||
BlockState blockState = chunk.getBlockState(blockPos.getBlockPos());
|
||||
@@ -33,20 +41,25 @@ public class ChunkWrapper
|
||||
|| (blockState.hasProperty(BlockStateProperties.WATERLOGGED) && blockState.getValue(BlockStateProperties.WATERLOGGED));
|
||||
}
|
||||
|
||||
public int getHeightMapValue(int xRel, int zRel){
|
||||
@Override
|
||||
public int getHeightMapValue(int xRel, int zRel)
|
||||
{
|
||||
return chunk.getOrCreateHeightmapUnprimed(LodUtil.DEFAULT_HEIGHTMAP).getFirstAvailable(xRel, zRel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeWrapper getBiome(int xRel, int yAbs, int zRel)
|
||||
{
|
||||
return BiomeWrapper.getBiomeWrapper(chunk.getBiomes().getNoiseBiome(xRel >> 2, yAbs >> 2, zRel >> 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockColorWrapper getBlockColorWrapper(BlockPosWrapper blockPos)
|
||||
{
|
||||
return BlockColorWrapper.getBlockColorWrapper(chunk.getBlockState(blockPos.getBlockPos()).getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockShapeWrapper getBlockShapeWrapper(BlockPosWrapper blockPos)
|
||||
{
|
||||
return BlockShapeWrapper.getBlockShapeWrapper(chunk.getBlockState(blockPos.getBlockPos()).getBlock(), this, blockPos);
|
||||
@@ -58,27 +71,34 @@ public class ChunkWrapper
|
||||
this.chunkPos = new ChunkPosWrapper(chunk.getPos());
|
||||
}
|
||||
|
||||
public IChunk getChunk(){
|
||||
public IChunk getChunk()
|
||||
{
|
||||
return chunk;
|
||||
}
|
||||
public ChunkPosWrapper getPos(){
|
||||
|
||||
@Override
|
||||
public ChunkPosWrapper getPos()
|
||||
{
|
||||
return chunkPos;
|
||||
}
|
||||
|
||||
public boolean isLightCorrect(){
|
||||
@Override
|
||||
public boolean isLightCorrect()
|
||||
{
|
||||
return chunk.isLightCorrect();
|
||||
}
|
||||
|
||||
public boolean
|
||||
isWaterLogged(BlockPosWrapper blockPos)
|
||||
@Override
|
||||
public boolean isWaterLogged(BlockPosWrapper blockPos)
|
||||
{
|
||||
BlockState blockState = chunk.getBlockState(blockPos.getBlockPos());
|
||||
|
||||
//This type of block is always in water
|
||||
return ((blockState.getBlock() instanceof ILiquidContainer) && !(blockState.getBlock() instanceof IWaterLoggable))
|
||||
|| (blockState.hasProperty(BlockStateProperties.WATERLOGGED) && blockState.getValue(BlockStateProperties.WATERLOGGED));
|
||||
|| (blockState.hasProperty(BlockStateProperties.WATERLOGGED) && blockState.getValue(BlockStateProperties.WATERLOGGED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEmittedBrightness(BlockPosWrapper blockPos)
|
||||
{
|
||||
return chunk.getLightEmission(blockPos.getBlockPos());
|
||||
|
||||
Reference in New Issue
Block a user