Skip to content

Commit

Permalink
Broken rockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Jul 16, 2024
1 parent 90a7162 commit 532e098
Show file tree
Hide file tree
Showing 37 changed files with 775 additions and 154 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
kotlin("jvm") version "2.0.0" apply false
kotlin("plugin.serialization") version "1.9.23" apply false
}

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
27 changes: 18 additions & 9 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
kotlin("jvm")
kotlin("plugin.serialization") version "1.9.23"
kotlin("plugin.serialization")
id("com.google.devtools.ksp") version "2.0.0-1.0.21"

id("com.github.johnrengelman.shadow") version "8.1.1"
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
id("xyz.jpenilla.run-paper") version "2.2.0"
id("xyz.jpenilla.run-paper") version "2.3.0"
}

repositories {
Expand Down Expand Up @@ -41,15 +41,14 @@ dependencies {

implementation("org.bstats:bstats-bukkit:3.0.2")
implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT")
implementation("com.jeff_media:MorePersistentDataTypes:2.4.0")

implementation("io.github.seggan:sf4k:0.3.2")
implementation("io.github.seggan:sf4k:0.4.1")

implementation(project(":uom"))
ksp(project(":uom-processor"))

testImplementation(kotlin("test"))
testImplementation("io.kotest:kotest-assertions-core:5.8.0")
testImplementation("io.strikt:strikt-core:0.34.0")
testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.80.0")
testImplementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-test:2.14.0")
}
Expand Down Expand Up @@ -81,11 +80,15 @@ tasks.shadowJar {
relocate(from, "io.github.addoncommunity.galactifun.shadowlibs.$last")
}

doRelocate("io.github.seggan.kfun")
// Relocate if true or not set, always relocate bstats
doRelocate("org.bstats")
doRelocate("co.aikar.commands")
doRelocate("co.aikar.locales")
doRelocate("com.jeff_media.morepersistentdatatypes")
if (System.getenv("RELOCATE") != "false") {
doRelocate("io.github.seggan.kfun")
doRelocate("co.aikar.commands")
doRelocate("co.aikar.locales")
} else {
archiveClassifier = "unrelocated"
}

dependencies {
exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib"))
Expand All @@ -109,6 +112,12 @@ bukkit {
}

tasks.runServer {
javaLauncher = javaToolchains.launcherFor {
@Suppress("UnstableApiUsage")
vendor = JvmVendorSpec.JETBRAINS
languageVersion = JavaLanguageVersion.of(17)
}
jvmArgs("-XX:+AllowEnhancedClassRedefinition", "-XX:+AllowRedefinitionToAddDeleteMethods")
downloadPlugins {
url("https://blob.build/dl/Slimefun4/Dev/1116")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import io.github.addoncommunity.galactifun.units.Angle.Companion.degrees
import io.github.addoncommunity.galactifun.units.Distance.Companion.au
import io.github.addoncommunity.galactifun.units.Distance.Companion.kilometers
import io.github.addoncommunity.galactifun.units.Mass.Companion.kilograms
import io.github.addoncommunity.galactifun.util.bukkit.plus
import io.github.addoncommunity.galactifun.util.general.log
import io.github.addoncommunity.galactifun.util.plus
import io.github.seggan.sf4k.AbstractAddon
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun
Expand All @@ -29,7 +29,10 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.withContext
import kotlinx.datetime.Instant
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.Style
import net.kyori.adventure.text.format.TextDecoration
import org.bstats.bukkit.Metrics
import org.bukkit.Bukkit
import org.bukkit.Material
Expand All @@ -47,6 +50,7 @@ import kotlin.time.Duration.Companion.hours
open class Galactifun2 : AbstractAddon() {

private lateinit var manager: PaperCommandManager
lateinit var launchMessages: List<String> private set

var isTest = classLoader.javaClass.packageName.startsWith("be.seeseemelk.mockbukkit")

Expand All @@ -61,7 +65,7 @@ open class Galactifun2 : AbstractAddon() {

var shouldDisable = false
if (!PaperLib.isPaper() && !isTest) {
logger.log(Level.SEVERE, "Galactifun2 only supports Paper and its forks (e.x. Airplane and Purpur)")
logger.log(Level.SEVERE, "Galactifun2 only supports Paper and its forks (e.x. Airplane or Purpur)")
logger.log(Level.SEVERE, "Please use Paper or a fork of Paper")
shouldDisable = true
}
Expand Down Expand Up @@ -108,6 +112,8 @@ open class Galactifun2 : AbstractAddon() {
}
manager.registerCommand(Gf2Command)

launchMessages = config.getStringList("rockets.launch-msgs")

BaseUniverse.init()

val scriptsFolder = dataFolder.resolve("planets")
Expand Down Expand Up @@ -161,8 +167,9 @@ open class Galactifun2 : AbstractAddon() {

override suspend fun onDisableAsync() {
Bukkit.getConsoleSender().sendMessage(
NamedTextColor.GREEN +
"YOU MAY SAFELY IGNORE THE COROUTINE CANCELLATION EXCEPTION BELOW, I HAVE NO IDEA HOW TO FIX IT"
Component.text()
.content("YOU MAY SAFELY IGNORE THE COROUTINE CANCELLATION EXCEPTION BELOW, I HAVE NO IDEA HOW TO FIX IT")
.style(Style.style(NamedTextColor.GREEN, TextDecoration.BOLD))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType
import io.github.thebusybiscuit.slimefun4.core.handlers.*
import io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker
import org.bukkit.block.Block
import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.block.BlockPlaceEvent
Expand Down Expand Up @@ -97,11 +99,24 @@ open class BetterSlimefunItem : SlimefunItem {
for (method in javaClass.getAllMethods()) {
if (method.isAnnotationPresent(ItemHandler::class.java)) {
method.isAccessible = true
val handle = MethodHandles.lookup().unreflect(method)
val handle = MethodHandles.lookup().unreflect(method).bindTo(this)
val handler = method.getAnnotation(ItemHandler::class.java).handler
val handlerInstance = handlerMap[handler]?.invoke(handle.bindTo(this))
val handlerInstance = handlerMap[handler]?.invoke(handle)
?: throw IllegalStateException("Handler $handler is not registered for BetterSlimefunItem")
addItemHandler(handlerInstance)
} else if (method.isAnnotationPresent(Ticker::class.java)) {
method.isAccessible = true
val handle = MethodHandles.lookup().unreflect(method).bindTo(this)
val ticker = method.getAnnotation(Ticker::class.java)
addItemHandler(object : BlockTicker() {
override fun tick(b: Block, item: SlimefunItem, data: Config) {
handle.invoke(b)
}

override fun isSynchronized(): Boolean {
return !ticker.async
}
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.addoncommunity.galactifun.api.betteritem

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class Ticker(val async: Boolean = false)
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import io.github.addoncommunity.galactifun.units.Angle.Companion.degrees
import io.github.addoncommunity.galactifun.units.Distance
import io.github.addoncommunity.galactifun.units.Mass
import io.github.addoncommunity.galactifun.units.Velocity.Companion.metersPerSecond
import io.github.addoncommunity.galactifun.util.bukkit.plus
import io.github.addoncommunity.galactifun.util.general.LazyDouble
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils
import kotlinx.datetime.Instant
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import org.bukkit.inventory.ItemStack
import kotlin.math.sqrt

Expand All @@ -19,7 +22,14 @@ sealed class CelestialObject(name: String, baseItem: ItemStack) {
val name = ChatUtils.removeColorCodes(name)
val id = this.name.lowercase().replace(' ', '_')

val item = CustomItemStack(baseItem, name)
val item: ItemStack by lazy {
CustomItemStack(baseItem) { meta ->
meta.displayName(Component.text(name))
val lore = mutableListOf<String>()
addLoreProperties(lore)
meta.lore(lore.map { NamedTextColor.GRAY + it })
}
}

abstract val mass: Mass
abstract val radius: Distance
Expand Down Expand Up @@ -49,6 +59,13 @@ sealed class CelestialObject(name: String, baseItem: ItemStack) {

abstract fun distanceTo(other: CelestialObject, time: Instant): Distance

protected open fun addLoreProperties(lore: MutableList<String>) {
lore.add("Mass: $mass")
lore.add("Radius: $radius")
lore.add("Gravity: $gravity")
lore.add("Escape Velocity: $escapeVelocity")
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is CelestialObject) return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.github.addoncommunity.galactifun.units.Velocity.Companion.metersPerSec
import kotlinx.datetime.Instant
import org.bukkit.inventory.ItemStack
import kotlin.math.sqrt
import kotlin.time.Duration

abstract class PlanetaryObject(name: String, baseItem: ItemStack) : CelestialObject(name, baseItem) {

Expand Down Expand Up @@ -114,4 +115,44 @@ abstract class PlanetaryObject(name: String, baseItem: ItemStack) : CelestialObj
return thisSibling.orbit.arbitraryTransfer(otherSibling.orbit, time) + thisDeltaV + otherDeltaV
}
}

override fun addLoreProperties(lore: MutableList<String>) {
super.addLoreProperties(lore)
lore.add("")
lore.add("Day length: $dayCycle")
lore.add("")
lore.add("Semimajor axis: %,d kilometers".format(orbit.semimajorAxis.kilometers))
val c = orbit.semimajorAxis * orbit.eccentricity
lore.add("Periapasis: %,d kilometers".format((orbit.semimajorAxis - c).kilometers))
lore.add("Apoapsis: %,d kilometers".format((orbit.semimajorAxis + c).kilometers))
lore.add("Eccentricity: %.2f".format(orbit.eccentricity))
lore.add("Longitude of periapsis: %.2f°".format(orbit.longitudeOfPeriapsis.degrees))
lore.add("Orbital period (year length): ${durationToYearsAndDays(orbit.period)}")
if (atmosphere.pressure > 0) {
lore.add("")
lore.add("Atmospheric pressure: %.2f atmospheres".format(atmosphere.pressure))
}
if (orbiters.isNotEmpty()) {
lore.add("")
lore.add("Number of moons: ${orbiters.size}")
}
}
}

private fun durationToYearsAndDays(duration: Duration): String {
val sb = StringBuilder()
val years = duration.inWholeDays / 365
val days = duration.inWholeDays % 365
if (years > 0) {
sb.append(years)
sb.append(" year")
if (years > 1) sb.append('s')
}
if (days > 0) {
if (years > 0) sb.append(", ")
sb.append(days)
sb.append(" day")
if (days > 1) sb.append('s')
}
return sb.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ class DayCycle(val duration: Duration) {
fun tick(world: World) {
world.time += perFiveSeconds
}

override fun toString(): String {
val sb = StringBuilder()
if (duration.inWholeDays > 0) {
sb.append(duration.inWholeDays)
sb.append(" day")
if (duration.inWholeDays > 1) sb.append('s')
}
if (duration.inWholeHours > 0) {
if (sb.isNotEmpty()) sb.append(", ")
sb.append(duration.inWholeHours % 24)
sb.append(" hour")
if (duration.inWholeHours % 24 > 1) sb.append('s')
}
return sb.toString()
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.addoncommunity.galactifun.api.objects.properties

import io.github.addoncommunity.galactifun.impl.managers.PlanetManager
import io.github.seggan.sf4k.location.plus
import io.github.addoncommunity.galactifun.util.bukkit.copy
import kotlinx.serialization.Serializable
import org.bukkit.Location
import org.bukkit.persistence.PersistentDataAdapterContext
import org.bukkit.persistence.PersistentDataType

@Serializable
data class OrbitPosition(val x: Int, val z: Int) {

companion object {
Expand All @@ -25,17 +25,9 @@ data class OrbitPosition(val x: Int, val z: Int) {
z * ORBIT_SIZE + ORBIT_SIZE / 2.0
)

fun offset(location: Location): Location = centerLocation + location

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)
}
}
fun offset(x: Double, y: Double, z: Double) = centerLocation.copy(
x = centerLocation.x + x,
y = centerLocation.y + y,
z = centerLocation.z + z
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.addoncommunity.galactifun.api.objects.properties.atmosphere

import io.github.addoncommunity.galactifun.util.set
import io.github.addoncommunity.galactifun.util.bukkit.set
import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.RandomizedSet
import org.bukkit.GameRule
import org.bukkit.Material
Expand All @@ -10,7 +10,7 @@ class Atmosphere private constructor(
private val weatherEnabled: Boolean,
private val storming: Boolean,
private val thundering: Boolean,
private val pressure: Double,
val pressure: Double,
private val composition: Map<Gas, Double>
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ enum class Gas(texture: String?, val liquidDensity: Density) {

val item = texture?.let {
SlimefunItemStack(
"ATMOSPHERIC_GAS_$name",
"GF2_ATMOSPHERIC_GAS_$name",
SlimefunUtils.getCustomHead(texture),
"&f$this Gas Canister",
"",
"&7Contains one kilogram of $this",
"",
"&f&oTexture by Sefiraat"
)
}
Expand Down
Loading

0 comments on commit 532e098

Please sign in to comment.