diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt index 405832b..6f11d1f 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt @@ -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.* diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/CelestialObject.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/CelestialObject.kt index 9e0e987..0b80ee8 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/CelestialObject.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/CelestialObject.kt @@ -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 @@ -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 { diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/PlanetaryObject.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/PlanetaryObject.kt index 91b05ef..c0f28f6 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/PlanetaryObject.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/PlanetaryObject.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/planet/PlanetaryWorld.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/planet/PlanetaryWorld.kt index 3c996f3..4bbd956 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/planet/PlanetaryWorld.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/planet/PlanetaryWorld.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/Orbit.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/Orbit.kt index cbc1b17..34f70ca 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/Orbit.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/Orbit.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/OrbitPosition.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/OrbitPosition.kt index 35d87a8..688d088 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/OrbitPosition.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/OrbitPosition.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/rockets/RocketInfo.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/rockets/RocketInfo.kt index 20f40bd..d9d2e1f 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/rockets/RocketInfo.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/rockets/RocketInfo.kt @@ -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, - val fuel: Map -) + val blocks: Set, + val fuel: Map, + val engines: List +) { + 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))) + } +} diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/BaseUniverse.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/BaseUniverse.kt similarity index 82% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/BaseUniverse.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/BaseUniverse.kt index 11d0c5d..37d7c24 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/BaseUniverse.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/BaseUniverse.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/GalactifunCategories.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunCategories.kt similarity index 93% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/GalactifunCategories.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunCategories.kt index d34fb78..86897c3 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/GalactifunCategories.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunCategories.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/GalactifunItems.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunItems.kt similarity index 87% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/GalactifunItems.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunItems.kt index dbf3349..1b5dfaf 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/GalactifunItems.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunItems.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/Gf2Command.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/Gf2Command.kt similarity index 93% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/Gf2Command.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/Gf2Command.kt index 80c2152..59533b8 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/Gf2Command.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/Gf2Command.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/Permissions.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/Permissions.kt similarity index 59% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/Permissions.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/Permissions.kt index 51fcd67..9298f34 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/Permissions.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/Permissions.kt @@ -1,4 +1,4 @@ -package io.github.addoncommunity.galactifun.core +package io.github.addoncommunity.galactifun.impl object Permissions { diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/items/CommandComputer.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/CommandComputer.kt similarity index 64% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/items/CommandComputer.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/CommandComputer.kt index 009ce5f..dcd364a 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/items/CommandComputer.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/CommandComputer.kt @@ -1,12 +1,12 @@ -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 @@ -14,15 +14,14 @@ 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 @@ -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() != null } val detected = if (!rocketBlocks.exceededMax) rocketBlocks.found else emptySet() val blocks = detected.map(BlockPosition::getBlock) val fuel = blocks.processSlimefunBlocks(FuelTank::getFuelLevel) .fold(emptyMap()) { acc, map -> acc.mergeMaps(map, Double::plus) } - RocketManager.register(RocketInfo(pos, detected, fuel)) + val engines = blocks.processSlimefunBlocks { this } + RocketManager.register(RocketInfo(pos, detected, fuel, engines)) } private fun onRightClick(e: PlayerRightClickEvent) { @@ -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) } } diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/items/FuelTank.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/FuelTank.kt similarity index 95% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/items/FuelTank.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/FuelTank.kt index 15b5fa2..121c8e0 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/items/FuelTank.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/FuelTank.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/items/RocketEngine.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/RocketEngine.kt similarity index 62% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/items/RocketEngine.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/RocketEngine.kt index ca2576f..3331a6d 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/items/RocketEngine.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/RocketEngine.kt @@ -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, - val specificImpulse: Double, - val thrust: Double + val specificImpulse: Duration, + val thrust: Force, + val fuel: Gas ) : SlimefunItem(itemGroup, item, recipeType, recipe) \ No newline at end of file diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/PlanetManager.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/PlanetManager.kt similarity index 96% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/PlanetManager.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/PlanetManager.kt index 179ff08..d31f3b9 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/PlanetManager.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/PlanetManager.kt @@ -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 @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/RocketManager.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/RocketManager.kt similarity index 90% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/RocketManager.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/RocketManager.kt index cb10d4b..6944f98 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/RocketManager.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/RocketManager.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/objects/earth/Earth.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Earth.kt similarity index 92% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/objects/earth/Earth.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Earth.kt index c177197..0173a78 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/objects/earth/Earth.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Earth.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/objects/earth/Moon.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Moon.kt similarity index 91% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/objects/earth/Moon.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Moon.kt index 9b22bcc..c6cee1a 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/objects/earth/Moon.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Moon.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/objects/earth/MoonGenerator.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/MoonGenerator.kt similarity index 96% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/objects/earth/MoonGenerator.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/MoonGenerator.kt index 89163a9..1b4561d 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/base/objects/earth/MoonGenerator.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/MoonGenerator.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/space/SpaceGenerator.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/space/SpaceGenerator.kt similarity index 92% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/space/SpaceGenerator.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/space/SpaceGenerator.kt index 7228dd8..8748521 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/space/SpaceGenerator.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/space/SpaceGenerator.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/space/SpacePopulator.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/space/SpacePopulator.kt similarity index 98% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/space/SpacePopulator.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/space/SpacePopulator.kt index cfab0a8..3207d0c 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/core/space/SpacePopulator.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/space/SpacePopulator.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/ScriptDef.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/ScriptDef.kt index 578554d..44a1b51 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/ScriptDef.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/ScriptDef.kt @@ -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 diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/OrbitBuilder.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/OrbitBuilder.kt index ba17973..1b3b420 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/OrbitBuilder.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/OrbitBuilder.kt @@ -5,7 +5,7 @@ import io.github.addoncommunity.galactifun.api.objects.properties.Orbit import io.github.addoncommunity.galactifun.scripting.PlanetDsl import io.github.addoncommunity.galactifun.units.Angle import io.github.addoncommunity.galactifun.units.Distance -import io.github.addoncommunity.galactifun.util.RequiredProperty +import io.github.addoncommunity.galactifun.util.general.RequiredProperty import kotlinx.datetime.Instant @PlanetDsl diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/PlanetBuilder.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/PlanetBuilder.kt index fb70014..95e0f09 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/PlanetBuilder.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/PlanetBuilder.kt @@ -12,7 +12,7 @@ import io.github.addoncommunity.galactifun.scripting.PlanetDsl import io.github.addoncommunity.galactifun.scripting.PlanetScript import io.github.addoncommunity.galactifun.units.Distance import io.github.addoncommunity.galactifun.units.Mass -import io.github.addoncommunity.galactifun.util.RequiredProperty +import io.github.addoncommunity.galactifun.util.general.RequiredProperty import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.World diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/WorldBuilder.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/WorldBuilder.kt index 24cdf58..f8d97db 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/WorldBuilder.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/WorldBuilder.kt @@ -4,7 +4,7 @@ import io.github.addoncommunity.galactifun.api.objects.planet.gen.WorldGenerator import io.github.addoncommunity.galactifun.scripting.PlanetDsl import io.github.addoncommunity.galactifun.scripting.dsl.gen.GeneratorBuilder import io.github.addoncommunity.galactifun.scripting.dsl.gen.GeneratorBuilderProvider -import io.github.addoncommunity.galactifun.util.RequiredProperty +import io.github.addoncommunity.galactifun.util.general.RequiredProperty import org.bukkit.Material import org.bukkit.inventory.ItemStack import java.util.* diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/AbstractPerlin.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/AbstractPerlin.kt index d0b9efe..76461bb 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/AbstractPerlin.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/AbstractPerlin.kt @@ -1,7 +1,7 @@ package io.github.addoncommunity.galactifun.scripting.dsl.gen import io.github.addoncommunity.galactifun.scripting.PlanetDsl -import io.github.addoncommunity.galactifun.util.RequiredProperty +import io.github.addoncommunity.galactifun.util.general.RequiredProperty abstract class AbstractPerlin : GeneratorBuilder() { var generateBedrock = true diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/GeneratorBuilder.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/GeneratorBuilder.kt index a013c8d..3d1e948 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/GeneratorBuilder.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/GeneratorBuilder.kt @@ -1,7 +1,7 @@ package io.github.addoncommunity.galactifun.scripting.dsl.gen import io.github.addoncommunity.galactifun.api.objects.planet.gen.WorldGenerator -import io.github.addoncommunity.galactifun.util.RequiredProperty +import io.github.addoncommunity.galactifun.util.general.RequiredProperty import org.bukkit.block.Biome import org.bukkit.generator.BiomeProvider import org.bukkit.generator.WorldInfo diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/NoiseMap.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/NoiseMap.kt index 5682e70..6f834c9 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/NoiseMap.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/NoiseMap.kt @@ -1,6 +1,6 @@ package io.github.addoncommunity.galactifun.scripting.dsl.gen -import io.github.addoncommunity.galactifun.util.gen.DoubleChunkGrid +import io.github.addoncommunity.galactifun.util.worldgen.DoubleChunkGrid import org.bukkit.util.noise.OctaveGenerator import org.bukkit.util.noise.SimplexOctaveGenerator diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/PerlinBuilder.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/PerlinBuilder.kt index 2503869..fd4eb71 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/PerlinBuilder.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/PerlinBuilder.kt @@ -2,7 +2,7 @@ package io.github.addoncommunity.galactifun.scripting.dsl.gen import io.github.addoncommunity.galactifun.api.objects.planet.gen.WorldGenerator import io.github.addoncommunity.galactifun.scripting.PlanetDsl -import io.github.addoncommunity.galactifun.util.RequiredProperty +import io.github.addoncommunity.galactifun.util.general.RequiredProperty import org.bukkit.Material import org.bukkit.block.Biome import org.bukkit.generator.BiomeProvider diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/SimplePerlinBuilder.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/SimplePerlinBuilder.kt index 38cf2f8..c88db51 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/SimplePerlinBuilder.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/dsl/gen/SimplePerlinBuilder.kt @@ -2,7 +2,7 @@ package io.github.addoncommunity.galactifun.scripting.dsl.gen import io.github.addoncommunity.galactifun.api.objects.planet.gen.WorldGenerator import io.github.addoncommunity.galactifun.scripting.PlanetDsl -import io.github.addoncommunity.galactifun.util.RequiredProperty +import io.github.addoncommunity.galactifun.util.general.RequiredProperty import org.bukkit.Material import org.bukkit.generator.WorldInfo import org.bukkit.util.noise.OctaveGenerator diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/units/Angle.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/units/Angle.kt index aebed5b..6c15b20 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/units/Angle.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/units/Angle.kt @@ -6,7 +6,7 @@ import io.github.seggan.uom.Measure import kotlin.math.PI @Measure(base = "radians") -@AlternateUnit(unit = "degrees", ratio = 180.0 / Math.PI) +@AlternateUnit(unit = "degrees", ratio = Math.PI / 180) private class AAngle val Angle.standardForm: Angle diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/units/UnitsOfMeasure.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/units/UnitsOfMeasure.kt index cf8e4bf..b71c23b 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/units/UnitsOfMeasure.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/units/UnitsOfMeasure.kt @@ -19,7 +19,7 @@ import kotlin.time.Duration private class ADistance @Measure(base = "kilograms") -@AlternateUnit(unit = "pounds", ratio = 2.20462) +@AlternateUnit(unit = "tons", ratio = 1000.0) private class AMass @Measure(base = "metersPerSecond") diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/Curry.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/Curry.kt deleted file mode 100644 index c9c51ac..0000000 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/Curry.kt +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.addoncommunity.galactifun.util - -fun ((A) -> R).curry(a: A): () -> R = { this(a) } - -fun ((A, B) -> R).curry(a: A): (B) -> R = { b -> this(a, b) } - -fun ((A, B, C) -> R).curry(a: A): (B, C) -> R = { b, c -> this(a, b, c) } - -fun ((A, B, C, D) -> R).curry(a: A): (B, C, D) -> R = { b, c, d -> this(a, b, c, d) } - -fun ((A, B, C, D, E) -> R).curry(a: A): (B, C, D, E) -> R = { b, c, d, e -> this(a, b, c, d, e) } \ No newline at end of file diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/RandomUtils.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/McUtils.kt similarity index 58% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/RandomUtils.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/McUtils.kt index 3045661..4c5cf79 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/RandomUtils.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/McUtils.kt @@ -1,18 +1,13 @@ package io.github.addoncommunity.galactifun.util import io.github.addoncommunity.galactifun.pluginInstance -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem -import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.RandomizedSet -import me.mrCookieSlime.Slimefun.api.BlockStorage import net.kyori.adventure.text.Component import net.kyori.adventure.text.TextComponent import net.kyori.adventure.text.format.TextColor import org.bukkit.* -import org.bukkit.block.Block import org.bukkit.entity.Entity import org.bukkit.event.player.PlayerTeleportEvent import org.bukkit.metadata.FixedMetadataValue -import java.util.* import java.util.concurrent.CompletableFuture fun String.key(): NamespacedKey = NamespacedKey(pluginInstance, this) @@ -39,25 +34,6 @@ operator fun RegionAccessor.get(location: Location): Material = getType(location operator fun RegionAccessor.set(x: Int, y: Int, z: Int, material: Material) = setType(x, y, z, material) operator fun RegionAccessor.set(location: Location, material: Material) = setType(location, material) -inline fun > enumSetOf(vararg elements: E): EnumSet { - val set = EnumSet.noneOf(E::class.java) - set.addAll(elements) - return set -} - -inline fun , V> enumMapOf(vararg pairs: Pair): EnumMap { - val map: EnumMap = EnumMap(K::class.java) - map.putAll(pairs) - return map -} - -inline fun > enumSetOf(): EnumSet = EnumSet.noneOf(E::class.java) - -inline fun , V> enumMapOf(): EnumMap = EnumMap(K::class.java) - -inline fun buildRandomizedSet(builder: RandomizedSet.() -> Unit): RandomizedSet = - RandomizedSet().apply(builder) - /** * Teleports while telling Galactifun that the teleport should not be blocked */ @@ -72,19 +48,6 @@ fun Entity.galactifunTeleport( } } -inline fun Location.checkBlock(): Block? { - return if (BlockStorage.check(this) is I) block else null -} - -inline fun Block.checkBlock(): Block? = location.checkBlock() - -inline fun Map.mergeMaps(other: Map, merge: (V, V) -> V): Map { - val result = this.toMutableMap() - for ((k, v) in other) { - val thisVal = this[k] - result[k] = if (thisVal != null) merge(thisVal, v) else v - } - return result -} - operator fun TextColor.plus(s: String): TextComponent = Component.text().color(this).content(s).build() + +operator fun Tag.contains(item: T): Boolean = isTagged(item) diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/Mover.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/Mover.kt deleted file mode 100644 index 0921a39..0000000 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/Mover.kt +++ /dev/null @@ -1,106 +0,0 @@ -package io.github.addoncommunity.galactifun.util - -import com.jeff_media.morepersistentdatatypes.DataType -import me.mrCookieSlime.Slimefun.api.BlockStorage -import net.kyori.adventure.text.serializer.json.JSONComponentSerializer -import org.bukkit.Bukkit -import org.bukkit.Material -import org.bukkit.block.Block -import org.bukkit.block.Container -import org.bukkit.block.Sign -import org.bukkit.block.Skull -import org.bukkit.block.sign.Side -import org.bukkit.entity.BlockDisplay -import org.bukkit.inventory.ItemStack -import org.bukkit.persistence.PersistentDataType - - -private val sfDataKey = "sfData".key() -private val extraDataKey = "extraData".key() -private val extraData2Key = "extraData2".key() - -private val bytesListPdt = DataType.asList(DataType.BYTE_ARRAY) -private val stringListPdt = DataType.asList(DataType.STRING) - -fun Block.convertToDisplayEntity(): BlockDisplay { - val location = location - val world = location.world - val display = world.spawn(location) - - display.block = this.blockData - - val pdc = display.persistentDataContainer - pdc[sfDataKey, PersistentDataType.STRING] = BlockStorage.getBlockInfoAsJson(this) - - val state = this.state - if (state is Container) { - pdc[extraDataKey, bytesListPdt] = state.inventory.contents.map { - it?.serializeAsBytes() ?: byteArrayOf() - } - } - if (state is Sign) { - pdc[extraDataKey, stringListPdt] = state.getSide(Side.FRONT) - .lines() - .map(JSONComponentSerializer.json()::serialize) - pdc[extraData2Key, stringListPdt] = state.getSide(Side.BACK) - .lines() - .map(JSONComponentSerializer.json()::serialize) - } - if (state is Skull) { - val player = state.owningPlayer - if (player != null) { - pdc[extraDataKey, DataType.UUID] = player.uniqueId - } - } - - this.type = Material.AIR - BlockStorage.clearBlockInfo(this) - return display -} - -fun BlockDisplay.convertToBlock(): Block { - val location = location.toBlockLocation() - val world = location.world - val block = world.getBlockAt(location) - - block.blockData = this.block - - val pdc = persistentDataContainer - val blockInfo = pdc[sfDataKey, PersistentDataType.STRING] - if (blockInfo != null) { - BlockStorage.setBlockInfo(block, blockInfo, true) - } - - val state = block.state - if (state is Container) { - val contents = pdc[extraDataKey, bytesListPdt] - if (contents != null) { - state.inventory.contents = contents.map { - if (it.isEmpty()) null else ItemStack.deserializeBytes(it) - }.toTypedArray() - } - } - if (state is Sign) { - val front = pdc[extraDataKey, stringListPdt] ?: emptyList() - val back = pdc[extraData2Key, stringListPdt] ?: emptyList() - - val frontSide = state.getSide(Side.FRONT) - for ((i, line) in front.withIndex()) { - frontSide.line(i, JSONComponentSerializer.json().deserialize(line)) - } - val backSide = state.getSide(Side.BACK) - for ((i, line) in back.withIndex()) { - backSide.line(i, JSONComponentSerializer.json().deserialize(line)) - } - } - if (state is Skull) { - val uuid = pdc[extraDataKey, DataType.UUID] - if (uuid != null) { - // What is wrong with you Kotlin??? - state.setOwningPlayer(Bukkit.getOfflinePlayer(uuid)) - } - } - - remove() - return block -} \ No newline at end of file diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/SfUtils.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/SfUtils.kt new file mode 100644 index 0000000..88893ea --- /dev/null +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/SfUtils.kt @@ -0,0 +1,23 @@ +package io.github.addoncommunity.galactifun.util + +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem +import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.RandomizedSet +import me.mrCookieSlime.Slimefun.api.BlockStorage +import org.bukkit.Location +import org.bukkit.block.Block + +/** + * Checks if the block at the given location is a Slimefun item of the given type. + * + * @param I the type of Slimefun item to check for + * + * @return the block at the given location if it is a Slimefun item of the given type, or `null` if it is not + */ +inline fun Location.checkBlock(): Block? { + return if (BlockStorage.check(this) is I) block else null +} + +inline fun Block.checkBlock(): Block? = location.checkBlock() + +inline fun buildRandomizedSet(builder: RandomizedSet.() -> Unit): RandomizedSet = + RandomizedSet().apply(builder) \ No newline at end of file diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/Either.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/Either.kt similarity index 83% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/Either.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/Either.kt index ae294ce..107bdc8 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/Either.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/Either.kt @@ -1,4 +1,4 @@ -package io.github.addoncommunity.galactifun.util +package io.github.addoncommunity.galactifun.util.general sealed interface Either { diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/GeneralUtils.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/GeneralUtils.kt new file mode 100644 index 0000000..d5f6cc3 --- /dev/null +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/GeneralUtils.kt @@ -0,0 +1,28 @@ +package io.github.addoncommunity.galactifun.util.general + +import java.util.* + +inline fun Map.mergeMaps(other: Map, merge: (V, V) -> V): Map { + val result = this.toMutableMap() + for ((k, v) in other) { + val thisVal = this[k] + result[k] = if (thisVal != null) merge(thisVal, v) else v + } + return result +} + +inline fun > enumSetOf(vararg elements: E): EnumSet { + val set = EnumSet.noneOf(E::class.java) + set.addAll(elements) + return set +} + +inline fun , V> enumMapOf(vararg pairs: Pair): EnumMap { + val map: EnumMap = EnumMap(K::class.java) + map.putAll(pairs) + return map +} + +inline fun > enumSetOf(): EnumSet = EnumSet.noneOf(E::class.java) + +inline fun , V> enumMapOf(): EnumMap = EnumMap(K::class.java) \ No newline at end of file diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/LazyDouble.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/LazyDouble.kt similarity index 89% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/LazyDouble.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/LazyDouble.kt index e4720a2..69cecaf 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/LazyDouble.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/LazyDouble.kt @@ -1,4 +1,4 @@ -package io.github.addoncommunity.galactifun.util +package io.github.addoncommunity.galactifun.util.general import kotlin.reflect.KProperty diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/RequiredProperty.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/RequiredProperty.kt similarity index 90% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/RequiredProperty.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/RequiredProperty.kt index e4a2c68..fd31e29 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/RequiredProperty.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/RequiredProperty.kt @@ -1,4 +1,4 @@ -package io.github.addoncommunity.galactifun.util +package io.github.addoncommunity.galactifun.util.general import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/ItemBuilder.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/ItemBuilder.kt index f133e4d..4aabc1f 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/ItemBuilder.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/ItemBuilder.kt @@ -1,7 +1,7 @@ package io.github.addoncommunity.galactifun.util.items import io.github.addoncommunity.galactifun.pluginInstance -import io.github.addoncommunity.galactifun.util.RequiredProperty +import io.github.addoncommunity.galactifun.util.general.RequiredProperty import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack @@ -37,7 +37,7 @@ class ItemBuilder { SlimefunItemStack::class.java, RecipeType::class.java, Array::class.java, - *otherArgs.map { it!!::class.java }.toTypedArray() + *otherArgs.map { it!!::class.javaPrimitiveType ?: it::class.java }.toTypedArray() ) constructor.newInstance(category, sfi, recipeType, recipe, *otherArgs).register(pluginInstance) return sfi diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/Mass.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/Mass.kt new file mode 100644 index 0000000..0ae6099 --- /dev/null +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/Mass.kt @@ -0,0 +1,41 @@ +package io.github.addoncommunity.galactifun.util.items + +import io.github.addoncommunity.galactifun.units.Mass +import io.github.addoncommunity.galactifun.units.Mass.Companion.kilograms +import io.github.addoncommunity.galactifun.units.Mass.Companion.tons +import io.github.addoncommunity.galactifun.util.contains +import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag +import org.bukkit.Material +import org.bukkit.block.Block + +private val INFINITE_MASS = Double.POSITIVE_INFINITY.kilograms + +val Block.mass: Mass + get() = when { + type == Material.AIR || type == Material.CAVE_AIR || type == Material.VOID_AIR -> Mass.ZERO + type in SlimefunTag.UNBREAKABLE_MATERIALS -> INFINITE_MASS + type in SlimefunTag.FLUID_SENSITIVE_MATERIALS -> 100.kilograms + type in SlimefunTag.SENSITIVE_MATERIALS -> 100.kilograms + !type.isCollidable -> 200.kilograms + type == Material.IRON_BLOCK -> 7.9.tons + type == Material.GOLD_BLOCK -> 19.3.tons + type == Material.DIAMOND_BLOCK -> 3.5.tons + type == Material.EMERALD_BLOCK -> 2.8.tons + type == Material.QUARTZ_BLOCK -> 2.6.tons + type == Material.NETHERITE_BLOCK -> 19.3.tons + type == Material.GRANITE -> 2.6.tons + type == Material.DIORITE -> 2.8.tons + type == Material.ANDESITE -> 2.4.tons + type == Material.CALCITE -> 2.7.tons + type == Material.STONE || type == Material.COBBLESTONE -> 2.7.tons + type in SlimefunTag.WOODEN_DOORS + || type in SlimefunTag.WOODEN_SLABS + || type in SlimefunTag.WOODEN_STAIRS + || type in SlimefunTag.WOODEN_TRAPDOORS + || type in SlimefunTag.WOODEN_FENCES + || type in SlimefunTag.WOODEN_PRESSURE_PLATES + || type in SlimefunTag.WOODEN_BUTTONS + -> 0.3.tons + type in SlimefunTag.LOGS || type in SlimefunTag.PLANKS -> 0.6.tons + else -> 2.5.tons + } \ No newline at end of file diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/gen/ChunkPosition.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/ChunkPosition.kt similarity index 85% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/gen/ChunkPosition.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/ChunkPosition.kt index defa547..92580f0 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/gen/ChunkPosition.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/ChunkPosition.kt @@ -1,4 +1,4 @@ -package io.github.addoncommunity.galactifun.util.gen +package io.github.addoncommunity.galactifun.util.worldgen import org.bukkit.Chunk import org.bukkit.Location diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/gen/DoubleChunkGrid.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/DoubleChunkGrid.kt similarity index 98% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/gen/DoubleChunkGrid.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/DoubleChunkGrid.kt index 1919593..13c6c9c 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/gen/DoubleChunkGrid.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/DoubleChunkGrid.kt @@ -1,4 +1,4 @@ -package io.github.addoncommunity.galactifun.util.gen +package io.github.addoncommunity.galactifun.util.worldgen import com.google.common.util.concurrent.AtomicDoubleArray import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap diff --git a/plugin/src/test/kotlin/io/github/addoncommunity/test/api/objects/properties/OrbitTest.kt b/plugin/src/test/kotlin/io/github/addoncommunity/test/api/objects/properties/OrbitTest.kt index 0376587..0821e30 100644 --- a/plugin/src/test/kotlin/io/github/addoncommunity/test/api/objects/properties/OrbitTest.kt +++ b/plugin/src/test/kotlin/io/github/addoncommunity/test/api/objects/properties/OrbitTest.kt @@ -2,7 +2,7 @@ package io.github.addoncommunity.test.api.objects.properties import io.github.addoncommunity.galactifun.api.objects.properties.Orbit import io.github.addoncommunity.galactifun.api.objects.properties.visVivaEquation -import io.github.addoncommunity.galactifun.base.BaseUniverse +import io.github.addoncommunity.galactifun.impl.BaseUniverse import io.github.addoncommunity.galactifun.units.Angle import io.github.addoncommunity.galactifun.units.Angle.Companion.degrees import io.github.addoncommunity.galactifun.units.Angle.Companion.radians diff --git a/uom-processor/src/main/kotlin/io/github/seggan/uom/UomProcessor.kt b/uom-processor/src/main/kotlin/io/github/seggan/uom/UomProcessor.kt index e1ff184..d566b66 100644 --- a/uom-processor/src/main/kotlin/io/github/seggan/uom/UomProcessor.kt +++ b/uom-processor/src/main/kotlin/io/github/seggan/uom/UomProcessor.kt @@ -11,6 +11,7 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.jvm.jvmInline import com.squareup.kotlinpoet.ksp.addOriginatingKSFile import com.squareup.kotlinpoet.ksp.writeTo +import java.math.BigDecimal class UomProcessor( private val generator: CodeGenerator, @@ -62,6 +63,14 @@ class UomProcessor( .addOperator("minus", "-", baseUnit, clazzName) .addScalarOperator("times", "*", baseUnit, clazzName) .addScalarOperator("div", "/", baseUnit, clazzName) + .addFunction( + FunSpec.builder("div") + .addModifiers(KModifier.OPERATOR) + .addParameter("other", clazzName) + .returns(Double::class) + .addStatement("return %L / other.%L", baseUnit, baseUnit) + .build() + ) .addScalarOperator("rem", "%", baseUnit, clazzName) .addFunction( FunSpec.builder("unaryMinus") @@ -85,6 +94,18 @@ class UomProcessor( .addStatement("return %L.compareTo(other.%L)", baseUnit, baseUnit) .build() ) + .addFunction( + FunSpec.builder("toString") + .addModifiers(KModifier.OVERRIDE) + .returns(String::class) + .addStatement( + "return %T(%L.toString()).toPlainString() + %S", + BigDecimal::class.java, + baseUnit, + " $baseUnit" + ) + .build() + ) val companion = TypeSpec.companionObjectBuilder() .addProperty( @@ -272,7 +293,7 @@ private fun TypeSpec.Builder.addScalarOperator( return this } -fun KSDeclaration.getBaseUnit(): String? { +private fun KSDeclaration.getBaseUnit(): String? { return annotations.find { it.shortName.asString() == "Measure" } ?.arguments?.firstOrNull()?.value as? String } \ No newline at end of file