Skip to content

Commit

Permalink
Rearrange
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Mar 8, 2024
1 parent 5605bee commit 4e0bf45
Show file tree
Hide file tree
Showing 47 changed files with 233 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import io.github.addoncommunity.galactifun.api.objects.PlanetaryObject
import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld
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.base.GalactifunItems
import io.github.addoncommunity.galactifun.core.Gf2Command
import io.github.addoncommunity.galactifun.core.managers.PlanetManager
import io.github.addoncommunity.galactifun.impl.BaseUniverse
import io.github.addoncommunity.galactifun.impl.GalactifunItems
import io.github.addoncommunity.galactifun.impl.Gf2Command
import io.github.addoncommunity.galactifun.impl.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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package io.github.addoncommunity.galactifun.api.objects

import io.github.addoncommunity.galactifun.Constants
import io.github.addoncommunity.galactifun.api.objects.properties.Orbit
import io.github.addoncommunity.galactifun.units.Acceleration.Companion.metersPerSecondSquared
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.LazyDouble
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
Expand All @@ -26,6 +27,10 @@ sealed class CelestialObject(name: String, baseItem: ItemStack) {
abstract val mass: Mass
abstract val radius: Distance

val gravity by lazy {
(Constants.GRAVITATIONAL_CONSTANT * mass.kilograms / (radius.meters * radius.meters)).metersPerSecondSquared
}

val gravitationalParameter by LazyDouble { Constants.GRAVITATIONAL_CONSTANT * mass.kilograms }
val escapeVelocity by lazy { sqrt(2 * Constants.GRAVITATIONAL_CONSTANT * mass.kilograms / radius.meters).metersPerSecond }
val parkingOrbit: Orbit by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.github.addoncommunity.galactifun.api.objects.properties.Orbit
import io.github.addoncommunity.galactifun.api.objects.properties.OrbitPosition
import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atmosphere
import io.github.addoncommunity.galactifun.api.objects.properties.visVivaEquation
import io.github.addoncommunity.galactifun.core.managers.PlanetManager
import io.github.addoncommunity.galactifun.impl.managers.PlanetManager
import io.github.addoncommunity.galactifun.units.Distance
import io.github.addoncommunity.galactifun.units.Distance.Companion.meters
import io.github.addoncommunity.galactifun.units.Velocity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.addoncommunity.galactifun.api.objects.planet

import io.github.addoncommunity.galactifun.api.objects.PlanetaryObject
import io.github.addoncommunity.galactifun.core.managers.PlanetManager
import io.github.addoncommunity.galactifun.impl.managers.PlanetManager
import org.bukkit.World
import org.bukkit.inventory.ItemStack

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import io.github.addoncommunity.galactifun.units.Distance.Companion.meters
import io.github.addoncommunity.galactifun.units.Velocity.Companion.metersPerSecond
import io.github.addoncommunity.galactifun.units.coordiantes.CartesianVector
import io.github.addoncommunity.galactifun.units.coordiantes.PolarVector
import io.github.addoncommunity.galactifun.util.Either
import io.github.addoncommunity.galactifun.util.LazyDouble
import io.github.addoncommunity.galactifun.util.general.Either
import io.github.addoncommunity.galactifun.util.general.LazyDouble
import kotlinx.datetime.Instant
import java.util.*
import kotlin.math.PI
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.addoncommunity.galactifun.api.objects.properties

import io.github.addoncommunity.galactifun.core.managers.PlanetManager
import io.github.addoncommunity.galactifun.impl.managers.PlanetManager
import org.bukkit.Location
import org.bukkit.persistence.PersistentDataAdapterContext
import org.bukkit.persistence.PersistentDataType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
package io.github.addoncommunity.galactifun.api.rockets

import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas
import io.github.addoncommunity.galactifun.impl.items.RocketEngine
import io.github.addoncommunity.galactifun.impl.managers.PlanetManager
import io.github.addoncommunity.galactifun.units.Acceleration
import io.github.addoncommunity.galactifun.units.Force
import io.github.addoncommunity.galactifun.units.Mass
import io.github.addoncommunity.galactifun.units.times
import io.github.addoncommunity.galactifun.util.items.mass
import io.github.thebusybiscuit.slimefun4.libraries.dough.blocks.BlockPosition

data class RocketInfo(
val commandComputer: BlockPosition,
var blocks: Set<BlockPosition>,
val fuel: Map<Gas, Double>
)
val blocks: Set<BlockPosition>,
val fuel: Map<Gas, Double>,
val engines: List<RocketEngine>
) {
val thrust: Force
get() = engines.fold(Force.ZERO) { acc, engine -> acc + engine.thrust }
val mass: Mass
get() = blocks.fold(Mass.ZERO) { acc, block -> acc + block.block.mass }

fun twr(gravity: Acceleration): Double {
if (gravity == Acceleration.ZERO) return Double.POSITIVE_INFINITY
return thrust / (mass * gravity)
}

val info: String
get() = buildString {
val planet = PlanetManager.getByWorld(commandComputer.world) ?: error("Planet not found")
appendLine("Fuel:")
for ((gas, amount) in fuel) {
append(" ".repeat(4))
append(gas)
appendLine(": %.2f l, %.2f kg".format(amount, amount * gas.liquidDensity))
}
appendLine("Thrust: %.2f kN".format(thrust.kilonewtons))
appendLine("Mass: %.2f kg".format(mass.kilograms))
appendLine("TWR: %.2f".format(twr(planet.gravity)))
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.addoncommunity.galactifun.base
package io.github.addoncommunity.galactifun.impl

import io.github.addoncommunity.galactifun.api.objects.Star
import io.github.addoncommunity.galactifun.base.objects.earth.Earth
import io.github.addoncommunity.galactifun.base.objects.earth.Moon
import io.github.addoncommunity.galactifun.impl.objects.earth.Earth
import io.github.addoncommunity.galactifun.impl.objects.earth.Moon
import io.github.addoncommunity.galactifun.units.Angle.Companion.radians
import io.github.addoncommunity.galactifun.units.Distance.Companion.kilometers
import io.github.addoncommunity.galactifun.units.Distance.Companion.meters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.addoncommunity.galactifun.base
package io.github.addoncommunity.galactifun.impl

import io.github.addoncommunity.galactifun.util.key
import io.github.thebusybiscuit.slimefun4.api.items.groups.NestedItemGroup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.addoncommunity.galactifun.base
package io.github.addoncommunity.galactifun.impl

import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas
import io.github.addoncommunity.galactifun.base.items.CommandComputer
import io.github.addoncommunity.galactifun.base.items.FuelTank
import io.github.addoncommunity.galactifun.impl.items.CommandComputer
import io.github.addoncommunity.galactifun.impl.items.FuelTank
import io.github.addoncommunity.galactifun.pluginInstance
import io.github.addoncommunity.galactifun.util.items.MaterialType
import io.github.addoncommunity.galactifun.util.items.buildSlimefunItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.addoncommunity.galactifun.core
package io.github.addoncommunity.galactifun.impl

import co.aikar.commands.BaseCommand
import co.aikar.commands.annotation.*
import io.github.addoncommunity.galactifun.api.objects.PlanetaryObject
import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld
import io.github.addoncommunity.galactifun.core.managers.PlanetManager
import io.github.addoncommunity.galactifun.impl.managers.PlanetManager
import io.github.addoncommunity.galactifun.util.galactifunTeleport
import io.github.seggan.kfun.location.plusAssign
import kotlinx.datetime.Clock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.addoncommunity.galactifun.core
package io.github.addoncommunity.galactifun.impl

object Permissions {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
package io.github.addoncommunity.galactifun.base.items
package io.github.addoncommunity.galactifun.impl.items

import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas
import io.github.addoncommunity.galactifun.api.rockets.RocketInfo
import io.github.addoncommunity.galactifun.core.managers.RocketManager
import io.github.addoncommunity.galactifun.pluginInstance
import io.github.addoncommunity.galactifun.impl.managers.RocketManager
import io.github.addoncommunity.galactifun.util.checkBlock
import io.github.addoncommunity.galactifun.util.floodSearch
import io.github.addoncommunity.galactifun.util.general.mergeMaps
import io.github.addoncommunity.galactifun.util.items.TickingBlock
import io.github.addoncommunity.galactifun.util.mergeMaps
import io.github.addoncommunity.galactifun.util.plus
import io.github.seggan.kfun.location.position
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler
import io.github.thebusybiscuit.slimefun4.libraries.dough.blocks.BlockPosition
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
import me.mrCookieSlime.Slimefun.api.BlockStorage
import net.kyori.adventure.text.format.NamedTextColor
import org.bukkit.Material
import org.bukkit.Tag
import org.bukkit.block.Block
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.inventory.ItemStack
import java.util.*
import kotlin.jvm.optionals.getOrNull
Expand All @@ -38,23 +37,29 @@ class CommandComputer(

init {
addItemHandler(BlockUseHandler(::onRightClick))
addItemHandler(object : BlockPlaceHandler(false) {
override fun onPlayerPlace(e: BlockPlaceEvent) {
rescanRocket(e.block.position)
}
})
}

override fun tick(b: Block) {
val pos = b.position
val counter = counters.mergeInt(pos, 1, Int::plus)
if (counter % 4 == 0) {
if (counter % 8 == 0) {
rescanRocket(pos)
}
}

private fun rescanRocket(pos: BlockPosition) {
val rocketBlocks = pos.floodSearch { it.type !in notAllowedBlocks }
val rocketBlocks = pos.floodSearch { it.checkBlock<RocketEngine>() != null }
val detected = if (!rocketBlocks.exceededMax) rocketBlocks.found else emptySet()
val blocks = detected.map(BlockPosition::getBlock)
val fuel = blocks.processSlimefunBlocks(FuelTank::getFuelLevel)
.fold(emptyMap<Gas, Double>()) { acc, map -> acc.mergeMaps(map, Double::plus) }
RocketManager.register(RocketInfo(pos, detected, fuel))
val engines = blocks.processSlimefunBlocks<RocketEngine, _> { this }
RocketManager.register(RocketInfo(pos, detected, fuel, engines))
}

private fun onRightClick(e: PlayerRightClickEvent) {
Expand All @@ -65,33 +70,7 @@ class CommandComputer(
e.player.sendMessage(NamedTextColor.RED + "No rocket detected")
return
}
val infoString = buildString {
appendLine("Fuel:")
for ((gas, amount) in info.fuel) {
append(" ".repeat(4))
append(gas)
append(": ")
append("%.2f".format(amount))
append(" liters, ")
append("%.2f".format(amount * gas.liquidDensity))
append(" kg")
appendLine()
}
}
e.player.sendMessage(NamedTextColor.GOLD + infoString)
}

private val notAllowedBlocks = EnumSet.noneOf(Material::class.java).apply {
addAll(Tag.DIRT.values)
addAll(Tag.SAND.values)
add(Material.GRAVEL)
if (!pluginInstance.isTest) addAll(Tag.CONCRETE_POWDER.values) // idk why
add(Material.AIR)
add(Material.WATER)
add(Material.LAVA)
add(Material.FIRE)
addAll(SlimefunTag.FLUID_SENSITIVE_MATERIALS.values)
addAll(SlimefunTag.UNBREAKABLE_MATERIALS.values)
e.player.sendMessage(NamedTextColor.GOLD + info.info)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.github.addoncommunity.galactifun.base.items
package io.github.addoncommunity.galactifun.impl.items

import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas
import io.github.addoncommunity.galactifun.serial.EnumBlockStorageDataType
import io.github.addoncommunity.galactifun.serial.MapBlockStorageDataType
import io.github.addoncommunity.galactifun.util.adjacentFaces
import io.github.addoncommunity.galactifun.util.checkBlock
import io.github.addoncommunity.galactifun.util.enumMapOf
import io.github.addoncommunity.galactifun.util.general.enumMapOf
import io.github.addoncommunity.galactifun.util.general.mergeMaps
import io.github.addoncommunity.galactifun.util.items.TickingBlock
import io.github.addoncommunity.galactifun.util.items.buildMenu
import io.github.addoncommunity.galactifun.util.mergeMaps
import io.github.seggan.kfun.serial.BlockStorageDataType
import io.github.seggan.kfun.serial.getBlockStorage
import io.github.seggan.kfun.serial.setBlockStorage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package io.github.addoncommunity.galactifun.base.items
package io.github.addoncommunity.galactifun.impl.items

import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas
import io.github.addoncommunity.galactifun.units.Force
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType
import org.bukkit.inventory.ItemStack
import kotlin.time.Duration

class RocketEngine(
itemGroup: ItemGroup,
item: SlimefunItemStack,
recipeType: RecipeType,
recipe: Array<out ItemStack?>,
val specificImpulse: Double,
val thrust: Double
val specificImpulse: Duration,
val thrust: Force,
val fuel: Gas
) : SlimefunItem(itemGroup, item, recipeType, recipe)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.addoncommunity.galactifun.core.managers
package io.github.addoncommunity.galactifun.impl.managers

import com.jeff_media.morepersistentdatatypes.DataType
import io.github.addoncommunity.galactifun.Constants
Expand All @@ -7,8 +7,8 @@ import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld
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.Permissions
import io.github.addoncommunity.galactifun.core.space.SpaceGenerator
import io.github.addoncommunity.galactifun.impl.Permissions
import io.github.addoncommunity.galactifun.impl.space.SpaceGenerator
import io.github.addoncommunity.galactifun.pluginInstance
import io.github.addoncommunity.galactifun.runOnNextTick
import io.github.addoncommunity.galactifun.util.getNearbyEntitiesByType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.addoncommunity.galactifun.core.managers
package io.github.addoncommunity.galactifun.impl.managers

import io.github.addoncommunity.galactifun.api.rockets.RocketInfo
import io.github.thebusybiscuit.slimefun4.libraries.dough.blocks.BlockPosition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.addoncommunity.galactifun.base.objects.earth
package io.github.addoncommunity.galactifun.impl.objects.earth

import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld
import io.github.addoncommunity.galactifun.api.objects.properties.DayCycle
import io.github.addoncommunity.galactifun.api.objects.properties.Orbit
import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atmosphere
import io.github.addoncommunity.galactifun.base.BaseUniverse
import io.github.addoncommunity.galactifun.impl.BaseUniverse
import io.github.addoncommunity.galactifun.pluginInstance
import io.github.addoncommunity.galactifun.units.Angle.Companion.degrees
import io.github.addoncommunity.galactifun.units.Distance.Companion.au
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.addoncommunity.galactifun.base.objects.earth
package io.github.addoncommunity.galactifun.impl.objects.earth

import io.github.addoncommunity.galactifun.api.objects.planet.AlienWorld
import io.github.addoncommunity.galactifun.api.objects.planet.gen.WorldGenerator
import io.github.addoncommunity.galactifun.api.objects.properties.DayCycle
import io.github.addoncommunity.galactifun.api.objects.properties.Orbit
import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atmosphere
import io.github.addoncommunity.galactifun.base.BaseUniverse
import io.github.addoncommunity.galactifun.impl.BaseUniverse
import io.github.addoncommunity.galactifun.units.Angle.Companion.degrees
import io.github.addoncommunity.galactifun.units.Distance.Companion.kilometers
import io.github.addoncommunity.galactifun.units.Mass.Companion.kilograms
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.addoncommunity.galactifun.base.objects.earth
package io.github.addoncommunity.galactifun.impl.objects.earth

import io.github.addoncommunity.galactifun.api.objects.planet.gen.WorldGenerator
import io.github.addoncommunity.galactifun.util.gen.DoubleChunkGrid
import io.github.addoncommunity.galactifun.util.worldgen.DoubleChunkGrid
import org.bukkit.Material
import org.bukkit.block.Biome
import org.bukkit.generator.BiomeProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.addoncommunity.galactifun.core.space
package io.github.addoncommunity.galactifun.impl.space

import org.bukkit.World
import org.bukkit.block.Biome
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.addoncommunity.galactifun.core.space
package io.github.addoncommunity.galactifun.impl.space

import io.github.addoncommunity.galactifun.util.adjacentFaces
import io.github.addoncommunity.galactifun.util.buildRandomizedSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.github.addoncommunity.galactifun.api.objects.MilkyWay
import io.github.addoncommunity.galactifun.api.objects.PlanetaryObject
import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atmosphere
import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas
import io.github.addoncommunity.galactifun.base.BaseUniverse
import io.github.addoncommunity.galactifun.impl.BaseUniverse
import io.github.addoncommunity.galactifun.pluginInstance
import org.bukkit.Material
import org.bukkit.World
Expand Down
Loading

0 comments on commit 4e0bf45

Please sign in to comment.