public class SphereGen extends AbstractFillableBlockShape
Class to generate sphere 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<SphereGen> CODEC
  • Constructor Details

    • SphereGen

      public SphereGen(@NotNull @NotNull net.minecraft.util.math.BlockPos pos, Rotator rotator, int radiusX, int radiusY, int radiusZ, SphereGen.SphereType halfSphere)
      init the Sphere Shape
      Parameters:
      pos - the center of the spiral
      radiusX - the radius on the x-axis
      radiusY - the radius on the y-axis
      radiusZ - the radius on the z-axis
      halfSphere - determines if the sphere is half or not
    • SphereGen

      public SphereGen(@NotNull @NotNull net.minecraft.util.math.BlockPos pos, int radius)
      init the shape generation
      Parameters:
      pos - the pos of the structure center
      radius - the radius of the sphere
    • SphereGen

      public SphereGen(net.minecraft.util.math.BlockPos pos, Rotator rotator, int radiusX, int radiusY, int radiusZ, float customFill, AbstractFillableBlockShape.FillingType fillingType)
  • Method Details

    • setHalfSphereDirection

      public void setHalfSphereDirection(net.minecraft.util.math.Direction direction)
      Sets the direction of the half-sphere. * * @param direction The direction to set.
    • setHalfSphere

      public void setHalfSphere(SphereGen.SphereType halfSphere)
      Sets the half-sphere type. * * @param halfSphere The half-sphere type to set.
    • setRadiusX

      public void setRadiusX(int radiusX)
      Sets the X radius of the sphere. * * @param radiusX The X radius to set.
    • setRadiusY

      public void setRadiusY(int radiusY)
      Sets the Y radius of the sphere. * * @param radiusY The Y radius to set.
    • setRadiusZ

      public void setRadiusZ(int radiusZ)
      Sets the Z radius of the sphere. * * @param radiusZ The Z radius to set.
    • getShapeCoordinates

      public Map<net.minecraft.util.math.ChunkPos,it.unimi.dsi.fastutil.longs.LongOpenHashSet> getShapeCoordinates()
      Description copied from class: AbstractBlockShape
      method to get the coordinates that will be placed later
      Specified by:
      getShapeCoordinates in class AbstractBlockShape
      Returns:
      a map of ChunkPos of blockPos for every shape
    • 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.StructureWorldAccess 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
    • generateEmptyEllipsoid

      public void generateEmptyEllipsoid(int minLarge, int maxLarge, int minHeight, int maxHeight)
    • generateFullEllipsoid

      public void generateFullEllipsoid()
    • generateFullEllipsoid

      public void generateFullEllipsoid(int minX, int maxX, int minY, int maxY, int minZ, int maxZ)
      allow you to generate a full ellipsoid
      Parameters:
      minX - the start of the circle on the x-axis
      maxX - the end of the circle on the x-axis
      minY - the start of the circle on the y-axis
      maxY - the end of the circle on the y-axis
      minZ - the start of the circle on the z-axis
      maxZ - the end of the circle on the z-axis