java.lang.Object
net.rodofire.easierworldcreator.shape.block.instanciator.AbstractBlockShape
Direct Known Subclasses:
AbstractFillableBlockShape, LineGen, SpiralGen

public abstract class AbstractBlockShape extends Object
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 Map<ChunkPos, LongOpenHashSet>.

It emply some things:

  • The coordinates are divided in chunk
  • It uses LongOpenHashSet for 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 BlockPos are saved under long using LongPosHelper. It saves some memory since that we save four bytes of data for each BlockPos, 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 into LongOpenHashSetis extremely faster compared to only adding a BlockPos. ~60- 70% facter.

Dividing Coordinates into Chunk has some advantages :

  • Field Details

    • centerPos

      protected long centerPos
    • centerX

      protected int centerX
      precomputed ints for slightly higher performance
    • centerY

      protected int centerY
    • centerZ

      protected int centerZ
    • rotator

      protected Rotator 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

      public AbstractBlockShape(net.minecraft.util.math.BlockPos centerPos, Rotator rotator)
      init the shape
      Parameters:
      centerPos - the center BlockPos
      rotator - the rotator uses to rotate the shape
  • Method Details

    • setRotator

      public void setRotator(Rotator rotator)
    • 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 use MutableObject to avoid using too much Map.get(Object), enhancing performance
      Parameters:
      pos - the compressed BlockPos that will be added