Class AbstractBlockShape
java.lang.Object
net.rodofire.easierworldcreator.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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBlockShape(@NotNull net.minecraft.util.math.BlockPos centerPos) init the ShapeAbstractBlockShape(net.minecraft.util.math.BlockPos centerPos, Rotator rotator) init the shape -
Method Summary
Modifier and TypeMethodDescriptionabstract Map<net.minecraft.util.math.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.voidsetRotator(Rotator rotator)
-
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.util.math.ChunkPos,it.unimi.dsi.fastutil.longs.LongOpenHashSet> chunkMap
-
-
Constructor Details
-
AbstractBlockShape
public AbstractBlockShape(@NotNull @NotNull net.minecraft.util.math.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.util.math.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
-
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
-