-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
261 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/OrbitPosition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.addoncommunity.galactifun.api.objects.properties | ||
|
||
import io.github.addoncommunity.galactifun.core.managers.PlanetManager | ||
import org.bukkit.Location | ||
import org.bukkit.persistence.PersistentDataAdapterContext | ||
import org.bukkit.persistence.PersistentDataType | ||
|
||
data class OrbitPosition(val x: Int, val z: Int) { | ||
|
||
companion object { | ||
|
||
const val ORBIT_SIZE = 535714 | ||
|
||
fun fromLocation(x: Int, z: Int) = OrbitPosition(x.floorDiv(ORBIT_SIZE), z.floorDiv(ORBIT_SIZE)) | ||
|
||
fun fromLocation(location: Location) = fromLocation(location.blockX, location.blockZ) | ||
} | ||
|
||
val centerLocation: Location | ||
get() = Location( | ||
PlanetManager.spaceWorld, | ||
x * ORBIT_SIZE + ORBIT_SIZE / 2.0, | ||
0.0, | ||
z * ORBIT_SIZE + ORBIT_SIZE / 2.0 | ||
) | ||
|
||
object DataType : PersistentDataType<IntArray, OrbitPosition> { | ||
override fun getPrimitiveType() = IntArray::class.java | ||
override fun getComplexType() = OrbitPosition::class.java | ||
|
||
override fun fromPrimitive(primitive: IntArray, context: PersistentDataAdapterContext): OrbitPosition { | ||
return OrbitPosition(primitive[0], primitive[1]) | ||
} | ||
override fun toPrimitive(complex: OrbitPosition, context: PersistentDataAdapterContext): IntArray { | ||
return intArrayOf(complex.x, complex.z) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.