diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorConveyors.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorConveyors.kt index 5b96c2c18..95f6f8781 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorConveyors.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorConveyors.kt @@ -7,6 +7,7 @@ import net.torvald.terrarum.* import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameworld.fmod +import net.torvald.terrarum.modulebasegame.worldgenerator.FOUR_PI import net.torvald.terrarum.modulebasegame.worldgenerator.HALF_PI import net.torvald.terrarum.modulebasegame.worldgenerator.TWO_PI import org.lwjgl.opengl.GL11 @@ -225,9 +226,9 @@ class ActorConveyors : ActorWithBody { // if the arc overlaps the larger arc... if (arcStart in arcRange || arcEnd in arcRange) - drawArcOnWorld(cx2, cy2, r, + drawArcOnWorld2(cx2, cy2, r, arcStart.coerceIn(arcRange), // this doesn't work due to sign flipping - arcSize.coerceIn(arcRange), + arcEnd.coerceIn(arcRange), 2f ) } @@ -299,6 +300,25 @@ class ActorConveyors : ActorWithBody { } } + private fun drawArcOnWorld2(xc: Double, yc: Double, r: Double, arcStart: Double, arcEnd: Double, width: Float, useLongArc: Boolean = false) { + // Calculate the arc angle (arcDeg) from arcStart and arcEnd + var arcDeg = arcEnd - arcStart + + // Normalize arcDeg to be within [-2π, 2π] + arcDeg = ((arcDeg % TWO_PI) + TWO_PI) % TWO_PI + + // Determine whether to use the long arc or short arc based on useLongArc + if (useLongArc && arcDeg < Math.PI) { + arcDeg -= TWO_PI // Convert to negative to get the long arc + } else if (!useLongArc && arcDeg > Math.PI) { + arcDeg -= TWO_PI // Use the shorter arc + } + + // Call the original drawArcOnWorld function with the calculated arcDeg + drawArcOnWorld(xc, yc, r, arcStart, arcDeg, width) + } + + /** Real time, in nanoseconds */ @Transient var spawnRequestedTime: Long = 0L protected set diff --git a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt index d33e79a95..3a863c8a9 100644 --- a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt +++ b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt @@ -618,5 +618,8 @@ infix fun Long.shake(other: String): Long { return this shake XXHash64.hash(other.toByteArray(), this + 31) } -val TWO_PI = Math.PI * 2.0 -val HALF_PI = Math.PI / 2.0 +val ONE_HALF_PI = 4.71238898038469 +val TWO_PI = 6.283185307179586 +val HALF_PI = 1.5707963267948966 +val QUARTER_PI = 0.7853981633974483 +val FOUR_PI = 12.566370614359172