Class CylinderGen


public class CylinderGen extends AbstractFillableBlockShape
Class to generate cylinder related 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

    • CODEC

      public static final com.mojang.serialization.Codec<CylinderGen> CODEC
  • Constructor Details

    • CylinderGen

      public CylinderGen(@NotNull @NotNull net.minecraft.core.BlockPos pos, Rotator rotator, int radiusX, int radiusZ, int height)
      init a Cylinder object
      Parameters:
      pos - the center of the spiral
      radiusX - the radius of the cylinder on the x-axis
      radiusZ - the radius of the cylinder on the z-axis
      height - the height of the cylinder
    • CylinderGen

      public CylinderGen(@NotNull @NotNull net.minecraft.core.BlockPos pos, int radius, int height)
      init a cylinder object
      Parameters:
      pos - the center of the spiral
      radius - the radius of the cylinder
      height - the height of the cylinder
    • CylinderGen

      public CylinderGen(net.minecraft.core.BlockPos pos, Rotator rotator, Integer radiusX, Integer radiusZ, Integer height, Float customFill, AbstractFillableBlockShape.FillingType fillingType)
  • Method Details

    • setHeight

      public void setHeight(int height)
      Sets the height of the cylinder.

      The height defines the vertical size of the cylinder.

      Parameters:
      height - the height of the cylinder, in units.
    • setRadiusX

      public void setRadiusX(int radius)
      Sets the radius of the cylinder along the X-axis.

      The radius along the X-axis determines the horizontal size of the cylinder in the X direction.

      Parameters:
      radius - the radius of the cylinder along the X-axis, in units.
    • setRadiusZ

      public void setRadiusZ(int radius)
      Sets the radius of the cylinder along the Z-axis.

      The radius along the Z-axis determines the horizontal size of the cylinder in the Z direction.

      Parameters:
      radius - the radius of the cylinder along the Z-axis, in units.
    • getShapeCoordinates

      public Map<net.minecraft.world.level.ChunkPos,it.unimi.dsi.fastutil.longs.LongOpenHashSet> getShapeCoordinates()
      Method to get the BlockPos of the shape
      Specified by:
      getShapeCoordinates in class AbstractBlockShape
      Returns:
      the blockPos divided into chunkPos
    • getCoveredChunks

      public it.unimi.dsi.fastutil.longs.LongOpenHashSet getCoveredChunks()
      Description copied from class: AbstractBlockShape
      Method to know the chunks that will be covered by the shape. This avoids generating all the structure, enhancing performance
      Specified by:
      getCoveredChunks in class AbstractBlockShape
      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 void place(net.minecraft.world.level.WorldGenLevel world, BlockLayerManager blockLayerManager)
      Description copied from class: AbstractBlockShape
      if you don't need to use a shape layer, you can directly place the shape to avoid allocating unnecessary pos
      Specified by:
      place in class AbstractBlockShape