Class AbstractBlockShape
java.lang.Object
fr.rodofire.ewc.shape.block.instanciator.AbstractBlockShape
- Direct Known Subclasses:
AbstractFillableBlockShape,LineGen,SpiralGen
Class to create custom shapes
The Main purpose of this class is to generate the coordinates based on a shape. The coordinates are organized depending on a
The Main purpose of this class is to generate the coordinates based on a shape. The coordinates are organized depending on a
Map<ChunkPos, LongOpenHashSet>.
It emply some things:
- The coordinates are divided in chunk
- It uses
LongOpenHashSetfor several reasons.- First, We use a set to avoid doing unnecessary calculations on the shape. It ensures that no duplicate is present.
- Second, it compresses the BlockPos: The
BlockPosare saved under long usingLongPosHelper. It saves some memory since that we save four bytes of data for eachBlockPos, and there should not have overhead since that we use primitive data type. - Third, since that we use primitive data types and that they take less memory,
coordinate generation, accession or deletion is much faster than using a
Set<BlockPos>. Encoding and decoding blockPos and then adding it intoLongOpenHashSetis extremely faster compared to only adding aBlockPos. ~60- 70% facter.
Dividing Coordinates into Chunk has some advantages :
- allow a multithreaded block assignement when using
LayerManager - allow to be used during WG, when using
DividedBlockListManageror when placing usingShapePlacer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected intprecomputed ints for slightly higher performanceprotected intprotected intprotected Map<net.minecraft.world.level.ChunkPos, it.unimi.dsi.fastutil.longs.LongOpenHashSet> protected it.unimi.dsi.fastutil.longs.LongOpenHashSetprotected intprotected intprotected Rotator -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBlockShape(@NotNull net.minecraft.core.BlockPos centerPos) init the ShapeAbstractBlockShape(net.minecraft.core.BlockPos centerPos, Rotator rotator) init the shape -
Method Summary
Modifier and TypeMethodDescriptionabstract it.unimi.dsi.fastutil.longs.LongOpenHashSetMethod to know the chunks that will be covered by the shape.abstract Map<net.minecraft.world.level.ChunkPos, it.unimi.dsi.fastutil.longs.LongOpenHashSet> method to get the coordinates that will be placed laterprotected voidmodifyChunkMap(long pos) Method to add a pos to the map.abstract voidplace(net.minecraft.world.level.WorldGenLevel world, BlockLayerManager blockLayerManager) if you don't need to use a shape layer, you can directly place the shape to avoid allocating unnecessary posvoidsetRotator(Rotator rotator) protected voidshouldAddChunk(int x, int z) protected voidshouldAddChunkPrecomputedX(int z, boolean different, int chunkX)
-
Field Details
-
centerPos
protected long centerPos -
centerX
protected int centerXprecomputed ints for slightly higher performance -
centerY
protected int centerY -
centerZ
protected int centerZ -
rotator
-
chunkMap
protected Map<net.minecraft.world.level.ChunkPos,it.unimi.dsi.fastutil.longs.LongOpenHashSet> chunkMap -
covered
protected it.unimi.dsi.fastutil.longs.LongOpenHashSet covered -
lastChunkX
protected int lastChunkX -
lastChunkZ
protected int lastChunkZ
-
-
Constructor Details
-
AbstractBlockShape
public AbstractBlockShape(@NotNull @NotNull net.minecraft.core.BlockPos centerPos) init the Shape- Parameters:
centerPos- the center of the spiral
-
AbstractBlockShape
init the shape- Parameters:
centerPos- the center BlockPosrotator- the rotator uses to rotate the shape
-
-
Method Details
-
setRotator
-
getShapeCoordinates
public abstract Map<net.minecraft.world.level.ChunkPos,it.unimi.dsi.fastutil.longs.LongOpenHashSet> getShapeCoordinates()method to get the coordinates that will be placed later- Returns:
- a map of ChunkPos of blockPos for every shape
-
getCoveredChunks
public abstract it.unimi.dsi.fastutil.longs.LongOpenHashSet getCoveredChunks()Method to know the chunks that will be covered by the shape. This avoids generating all the structure, enhancing performance- Returns:
- a set of chunkPos.
For performance reasons, we use long instead of
ChunkPos.To convert the long into a
ChunkPos, use the long in a constructor.
-
place
public abstract void place(net.minecraft.world.level.WorldGenLevel world, BlockLayerManager blockLayerManager) if you don't need to use a shape layer, you can directly place the shape to avoid allocating unnecessary pos -
modifyChunkMap
protected void modifyChunkMap(long pos) Method to add a pos to the map. We useMutableObjectto avoid using too muchMap.get(Object), enhancing performance- Parameters:
pos- the compressedBlockPosthat will be added
-
shouldAddChunk
protected void shouldAddChunk(int x, int z) -
shouldAddChunkPrecomputedX
protected void shouldAddChunkPrecomputedX(int z, boolean different, int chunkX)
-