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 Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
     
    protected int
    precomputed ints for slightly higher performance
    protected int
     
    protected int
     
    protected Map<net.minecraft.util.math.ChunkPos,it.unimi.dsi.fastutil.longs.LongOpenHashSet>
     
    protected it.unimi.dsi.fastutil.longs.LongOpenHashSet
     
    protected int
     
    protected int
     
    protected Rotator
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractBlockShape(@NotNull net.minecraft.util.math.BlockPos centerPos)
    init the Shape
    AbstractBlockShape(net.minecraft.util.math.BlockPos centerPos, Rotator rotator)
    init the shape
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract it.unimi.dsi.fastutil.longs.LongOpenHashSet
    Method to know the chunks that will be covered by the shape.
    abstract Map<net.minecraft.util.math.ChunkPos,it.unimi.dsi.fastutil.longs.LongOpenHashSet>
    method to get the coordinates that will be placed later
    protected void
    modifyChunkMap(long pos)
    Method to add a pos to the map.
    abstract void
    place(net.minecraft.world.StructureWorldAccess world, BlockLayerManager blockLayerManager)
    if you don't need to use a shape layer, you can directly place the shape to avoid allocating unnecessary pos
    void
     
    protected void
    shouldAddChunk(int x, int z)
     
    protected void
    shouldAddChunkPrecomputedX(int z, boolean different, int chunkX)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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
    • 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.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
    • 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.StructureWorldAccess 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 use MutableObject to avoid using too much Map.get(Object), enhancing performance
      Parameters:
      pos - the compressed BlockPos that will be added
    • shouldAddChunk

      protected void shouldAddChunk(int x, int z)
    • shouldAddChunkPrecomputedX

      protected void shouldAddChunkPrecomputedX(int z, boolean different, int chunkX)