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

    • TorusGen

      public TorusGen(@NotNull @NotNull net.minecraft.util.math.BlockPos pos, Rotator rotator, int innerRadiusX, int outerRadiusX, int innerRadiusZ, int outerRadiusZ)
      init the Torus Shape
      Parameters:
      pos - the center of the spiral
      innerRadiusX - the radius of the inner circle on the x-axis
      outerRadiusX - the radius of the outer circle on the x-axis
      innerRadiusZ - the radius of the inner circle on the z-axis
      outerRadiusZ - the radius of the outer circle on the z-axis
    • TorusGen

      public TorusGen(@NotNull @NotNull net.minecraft.util.math.BlockPos pos, int innerRadius, int outerRadius)
      init the Torus Shape
      Parameters:
      pos - the center of the spiral
      innerRadius - the radius of the inner circle
      outerRadius - the radius of the outer circle
    • TorusGen

      public TorusGen(net.minecraft.util.math.BlockPos pos, Rotator rotator, int innerRadiusX, int innerRadiusZ, int outerRadiusX, int outerRadiusZ, float customFill, float verticalTorus, float horizontalTorus, AbstractFillableBlockShape.FillingType fillingType, TorusGen.TorusType torusType)
  • Method Details

    • setInnerRadiusX

      public void setInnerRadiusX(int innerRadiusX)
      Sets the inner radius of the torus along the X-axis.
      Parameters:
      innerRadiusX - the inner radius to set along the X-axis.
    • setOuterRadiusX

      public void setOuterRadiusX(int outerRadiusX)
      Sets the outer radius of the torus along the X-axis.
      Parameters:
      outerRadiusX - the outer radius to set along the X-axis.
    • setInnerRadiusZ

      public void setInnerRadiusZ(int innerRadiusZ)
      Sets the inner radius of the torus along the Z-axis.
      Parameters:
      innerRadiusZ - the inner radius to set along the Z-axis.
    • setOuterRadiusZ

      public void setOuterRadiusZ(int outerRadiusZ)
      Sets the outer radius of the torus along the Z-axis.
      Parameters:
      outerRadiusZ - the outer radius to set along the Z-axis.
    • setTorusType

      public void setTorusType(TorusGen.TorusType torusType)
      Sets the type of the torus.

      The torus type determines the configuration of the torus, such as whether it is hollow, solid, or has other specific properties.

      Parameters:
      torusType - the TorusGen.TorusType to set.
    • setVerticalTorus

      public void setVerticalTorus(float verticalTorus)
      Sets the vertical torus ratio.

      The vertical torus determines the percentage of the torus's height relative to its overall dimensions.

      Parameters:
      verticalTorus - the vertical torus ratio to set, as a float.
    • setHorizontalTorus

      public void setHorizontalTorus(float horizontalTorus)
      Sets the horizontal torus ratio.

      The horizontal torus determines the percentage of the torus's width relative to its overall dimensions.

      Parameters:
      horizontalTorus - the horizontal torus ratio to set, as a float.
    • getShapeCoordinates

      public Map<net.minecraft.util.math.ChunkPos,it.unimi.dsi.fastutil.longs.LongOpenHashSet> getShapeCoordinates()
      Method to get all the BlockPos needed to place the shape
      Specified by:
      getShapeCoordinates in class AbstractBlockShape
      Returns:
      a list that contain divided BlockPos depending in the 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.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