Skip to content

Commit

Permalink
Every planet has an orbit now
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Feb 8, 2024
1 parent 65ba60a commit 4ffffe1
Show file tree
Hide file tree
Showing 16 changed files with 261 additions and 176 deletions.
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ plugins {
repositories {
mavenCentral()
maven(url = "https://papermc.io/repo/repository/maven-public/")
maven(url = "https://jitpack.io")
maven(url = "https://jitpack.io/")
maven(url = "https://repo.aikar.co/content/groups/aikar/")
maven(url = "https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
}

dependencies {
Expand All @@ -26,6 +27,7 @@ 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("com.github.Seggan:kfun:0.1.0")
}
Expand All @@ -47,8 +49,9 @@ tasks.shadowJar {
relocate("org.bstats", "io.github.addoncommunity.galactifun.bstats")
relocate("co.aikar.commands", "io.github.addoncommunity.galactifun.acf")
relocate("co.aikar.locales", "io.github.addoncommunity.galactifun.acf.locales")
relocate("com.jeff_media.morepersistentdatatypes", "io.github.addoncommunity.galactifun.pdts")

dependencies {
dependencies {
exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib"))
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github.addoncommunity.galactifun

import co.aikar.commands.PaperCommandManager
import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryObject
import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld
import io.github.addoncommunity.galactifun.api.objects.properties.Distance.Companion.au
import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas
import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.composition
import io.github.addoncommunity.galactifun.base.BaseUniverse
import io.github.addoncommunity.galactifun.core.Gf2Command
import io.github.addoncommunity.galactifun.core.managers.WorldManager
import io.github.addoncommunity.galactifun.core.managers.PlanetManager
import io.github.addoncommunity.galactifun.scripting.PlanetScript
import io.github.addoncommunity.galactifun.scripting.dsl.*
import io.github.addoncommunity.galactifun.scripting.dsl.gen.*
Expand Down Expand Up @@ -73,12 +74,19 @@ class Galactifun2 : AbstractAddon() {

manager = PaperCommandManager(this)
manager.enableUnstableAPI("help")
manager.commandCompletions.registerAsyncCompletion("worlds") { _ ->
PlanetManager.allPlanetaryWorlds.map { it.name }.sorted()
}
manager.commandCompletions.registerAsyncCompletion("planets") { _ ->
WorldManager.allPlanetaryWorlds.map { it.name }.sorted()
PlanetManager.allPlanets.map { it.name }.sorted()
}
manager.commandContexts.registerContext(PlanetaryWorld::class.java) { context ->
val arg = context.popFirstArg()
WorldManager.allPlanetaryWorlds.find { it.name == arg }
PlanetManager.allPlanetaryWorlds.find { it.name == arg }
}
manager.commandContexts.registerContext(PlanetaryObject::class.java) { context ->
val arg = context.popFirstArg()
PlanetManager.allPlanets.find { it.name == arg }
}
manager.registerCommand(Gf2Command)

Expand Down Expand Up @@ -202,7 +210,7 @@ class Galactifun2 : AbstractAddon() {
private var instance: Galactifun2? = null

val pluginInstance: Galactifun2
get() = instance ?: error("Plugin is not enabled")
get() = checkNotNull(instance) { "Plugin is not enabled" }

fun JavaPlugin.log(level: Level, vararg messages: String) {
for (message in messages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package io.github.addoncommunity.galactifun.api.objects.planet
import io.github.addoncommunity.galactifun.api.objects.planet.gen.WorldGenerator
import io.github.addoncommunity.galactifun.log
import io.github.addoncommunity.galactifun.pluginInstance
import io.github.addoncommunity.galactifun.util.set
import org.bukkit.GameRule
import org.bukkit.Material
import org.bukkit.World
import org.bukkit.WorldCreator
import org.bukkit.inventory.ItemStack
import java.util.*
import kotlin.collections.set

abstract class AlienWorld(name: String, baseItem: ItemStack) : PlanetaryWorld(name, baseItem) {

Expand All @@ -26,17 +26,6 @@ abstract class AlienWorld(name: String, baseItem: ItemStack) : PlanetaryWorld(na
.environment(atmosphere.environment)
.createWorld() ?: error("Could not create world world_galactifun_$id")

if (world.environment == World.Environment.THE_END) {
// Prevents ender dragon spawn using portal, surrounds portal with bedrock
world[0, 0, 0] = Material.END_PORTAL
world[0, 1, 0] = Material.BEDROCK
world[0, -1, 0] = Material.BEDROCK
world[1, 0, 0] = Material.BEDROCK
world[-1, 0, 0] = Material.BEDROCK
world[0, 0, 1] = Material.BEDROCK
world[0, 0, -1] = Material.BEDROCK
}

atmosphere.applyEffects(world)
dayCycle.applyEffects(world)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ package io.github.addoncommunity.galactifun.api.objects.planet

import io.github.addoncommunity.galactifun.api.objects.UniversalObject
import io.github.addoncommunity.galactifun.api.objects.properties.DayCycle
import io.github.addoncommunity.galactifun.api.objects.properties.OrbitPosition
import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atmosphere
import io.github.addoncommunity.galactifun.core.managers.PlanetManager
import io.github.seggan.kfun.location.plus
import org.bukkit.Location
import org.bukkit.inventory.ItemStack

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

abstract val dayCycle: DayCycle
abstract val atmosphere: Atmosphere

val orbitPosition: OrbitPosition
get() = PlanetManager.getOrbit(this)

fun getOrbitOffset(location: Location): Location {
return orbitPosition.centerLocation + location
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.addoncommunity.galactifun.api.objects.planet

import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atmosphere
import io.github.addoncommunity.galactifun.core.managers.WorldManager
import io.github.addoncommunity.galactifun.core.managers.PlanetManager
import org.bukkit.World
import org.bukkit.inventory.ItemStack

Expand All @@ -17,14 +16,12 @@ abstract class PlanetaryWorld(
baseItem: ItemStack
) : PlanetaryObject(name, baseItem) {

abstract val atmosphere: Atmosphere

lateinit var world: World
private set

fun register() {
world = loadWorld()
WorldManager.registerWorld(this)
PlanetManager.register(this)
}

abstract fun loadWorld(): World
Expand Down
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)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package io.github.addoncommunity.galactifun.api.objects.properties.atmosphere

import io.github.addoncommunity.galactifun.util.set
import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.RandomizedSet
import org.bukkit.GameRule
import org.bukkit.Material
import org.bukkit.World

class Atmosphere private constructor(
private val weatherEnabled: Boolean,
private val storming: Boolean,
private val thundering: Boolean,
private val pressure: Double,
val environment: World.Environment,
private val composition: Map<Gas, Double>
) {

val environment = when {
pressure > 2.0 -> World.Environment.NETHER
pressure < 0.001 -> World.Environment.THE_END
else -> World.Environment.NORMAL
}

private val flammable = composition.getOrDefault(Gas.OXYGEN, 0.0) > 5

private val growthAttempts = (pressurizedCompositionOf(Gas.CARBON_DIOXIDE) / earthCo2).toInt()

val weightedCompositionSet = RandomizedSet<Gas>().apply {
Expand Down Expand Up @@ -43,6 +51,17 @@ class Atmosphere private constructor(
world.thunderDuration = Int.MAX_VALUE
}
world.setGameRule(GameRule.DO_FIRE_TICK, flammable)

if (world.environment == World.Environment.THE_END) {
// Prevents ender dragon spawn using portal, surrounds portal with bedrock
world[0, 0, 0] = Material.END_PORTAL
world[0, 1, 0] = Material.BEDROCK
world[0, -1, 0] = Material.BEDROCK
world[1, 0, 0] = Material.BEDROCK
world[-1, 0, 0] = Material.BEDROCK
world[0, 0, 1] = Material.BEDROCK
world[0, 0, -1] = Material.BEDROCK
}
}

companion object {
Expand All @@ -62,7 +81,6 @@ class Atmosphere private constructor(
atmosphereBuilder.storming,
atmosphereBuilder.thundering,
atmosphereBuilder.pressure,
atmosphereBuilder.environment,
atmosphereBuilder.composition
)
}
Expand All @@ -83,7 +101,6 @@ class Atmosphere private constructor(
val NONE = buildAtmosphere {
weatherEnabled = false
pressure = 0.0
environment = World.Environment.NORMAL
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.addoncommunity.galactifun.api.objects.properties.atmosphere

import io.github.addoncommunity.galactifun.scripting.PlanetDsl
import org.bukkit.World
import java.util.*

@PlanetDsl
Expand All @@ -12,7 +11,6 @@ class AtmosphereBuilder internal constructor() {
var storming = false
var thundering = false
var pressure = 1.0
var environment = World.Environment.NORMAL

internal val composition = EnumMap<Gas, Double>(Gas::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package io.github.addoncommunity.galactifun.core

import co.aikar.commands.BaseCommand
import co.aikar.commands.annotation.*
import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryObject
import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld
import io.github.addoncommunity.galactifun.core.managers.WorldManager
import io.github.addoncommunity.galactifun.util.galactifunTeleport
import io.github.seggan.kfun.location.plusAssign
import org.bukkit.Location
import org.bukkit.entity.Player

Expand All @@ -13,7 +14,7 @@ import org.bukkit.entity.Player
object Gf2Command : BaseCommand() {

@Subcommand("planet")
@CommandCompletion("@planets")
@CommandCompletion("@worlds")
@CommandPermission(Permissions.TELEPORT)
@Description("Teleport to a planet")
fun tpPlanet(player: Player, planet: PlanetaryWorld, @Optional location: Location?) {
Expand All @@ -22,12 +23,15 @@ object Gf2Command : BaseCommand() {
player.galactifunTeleport(loc)
}

@Subcommand("space")
@Subcommand("orbit")
@CommandCompletion("@planets")
@CommandPermission(Permissions.TELEPORT)
@Description("Teleport to space")
fun tpSpace(player: Player, @Optional location: Location?) {
val loc = location ?: WorldManager.spaceWorld.spawnLocation
loc.world = WorldManager.spaceWorld
player.galactifunTeleport(loc)
@Description("Teleport to orbit")
fun tpSpace(player: Player, planet: PlanetaryObject, @Optional offset: Location?) {
val location = planet.orbitPosition.centerLocation
if (offset != null) {
location += offset
}
player.galactifunTeleport(location)
}
}
Loading

0 comments on commit 4ffffe1

Please sign in to comment.