Skip to content

Commit

Permalink
Move to sf4k
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Mar 12, 2024
1 parent 4e0bf45 commit 6583372
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ launch.cmd
/paper/
.gradle/
build/
/run
run/
3 changes: 2 additions & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ dependencies {
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")
implementation("io.github.seggan:sf4k:0.1.1")

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

testImplementation(kotlin("test"))
testImplementation("io.kotest:kotest-assertions-core:5.8.0")
testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.78.0")
testImplementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-test:2.14.0")
}

group = "io.github.addoncommunity.galactifun"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.github.addoncommunity.galactifun.units.Angle.Companion.degrees
import io.github.addoncommunity.galactifun.units.Distance.Companion.au
import io.github.addoncommunity.galactifun.units.Distance.Companion.kilometers
import io.github.addoncommunity.galactifun.units.Mass.Companion.kilograms
import io.github.seggan.kfun.AbstractAddon
import io.github.seggan.sf4k.AbstractAddon
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun
import io.github.thebusybiscuit.slimefun4.libraries.paperlib.PaperLib
Expand All @@ -42,13 +42,13 @@ open class Galactifun2 : AbstractAddon() {

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

override fun onLoad() {
override suspend fun onLoadAsync() {
if (!isTest) {
Bukkit.spigot().config["world-settings.default.verbose"] = false
}
}

override fun onEnable() {
override suspend fun onEnableAsync() {
instance = this

var shouldDisable = false
Expand Down Expand Up @@ -152,7 +152,7 @@ open class Galactifun2 : AbstractAddon() {
doTestingStuff()
}

override fun onDisable() {
override suspend fun onDisableAsync() {
instance = null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.github.addoncommunity.galactifun.units.Velocity
import io.github.addoncommunity.galactifun.units.Velocity.Companion.metersPerSecond
import io.github.addoncommunity.galactifun.units.abs
import io.github.addoncommunity.galactifun.units.cos
import io.github.seggan.kfun.location.plus
import io.github.seggan.sf4k.location.plus
import kotlinx.datetime.Instant
import org.bukkit.Location
import org.bukkit.inventory.ItemStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.github.addoncommunity.galactifun.api.objects.PlanetaryObject
import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld
import io.github.addoncommunity.galactifun.impl.managers.PlanetManager
import io.github.addoncommunity.galactifun.util.galactifunTeleport
import io.github.seggan.kfun.location.plusAssign
import io.github.seggan.sf4k.location.plusAssign
import kotlinx.datetime.Clock
import org.bukkit.Location
import org.bukkit.entity.Player
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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.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.plus
import io.github.seggan.kfun.location.position
import io.github.seggan.sf4k.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
Expand Down Expand Up @@ -53,13 +51,13 @@ class CommandComputer(
}

private fun rescanRocket(pos: BlockPosition) {
val rocketBlocks = pos.floodSearch { it.checkBlock<RocketEngine>() != null }
val rocketBlocks = pos.floodSearch { this.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) }
val engines = blocks.processSlimefunBlocks<RocketEngine, _> { this }
RocketManager.register(RocketInfo(pos, detected, fuel, engines))
val engines = blocks.processSlimefunBlocks<RocketEngine, _> {
this to it.position.floodSearch { this.checkBlock<FuelTank>() != null }.found
}
RocketManager.register(RocketInfo(pos, detected, engines))
}

private fun onRightClick(e: PlayerRightClickEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
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.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.seggan.kfun.serial.BlockStorageDataType
import io.github.seggan.kfun.serial.getBlockStorage
import io.github.seggan.kfun.serial.setBlockStorage
import io.github.seggan.sf4k.serial.*
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.github.addoncommunity.galactifun.util.worldgen

import com.github.shynixn.mccoroutine.bukkit.launch
import com.google.common.util.concurrent.AtomicDoubleArray
import io.github.addoncommunity.galactifun.pluginInstance
import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import java.lang.ref.WeakReference
import java.util.concurrent.locks.ReentrantReadWriteLock

Expand All @@ -21,7 +24,7 @@ class DoubleChunkGrid {

init {
val ref = WeakReference(this)
coroScope.launch {
pluginInstance.launch(Dispatchers.IO) {
while (true) {
val time = System.currentTimeMillis()
val grid = ref.get() ?: break
Expand Down Expand Up @@ -92,11 +95,6 @@ class DoubleChunkGrid {

fun getOrSet(x: Int, y: Int, value: () -> Double) =
getOrSet(x shr 4, y shr 4, x and 15, y and 15, value)

companion object {
@OptIn(DelicateCoroutinesApi::class)
private val coroScope = CoroutineScope(newFixedThreadPoolContext(4, "Galactifun2-DoubleChunkGrid"))
}
}

private infix fun Int.pack(other: Int) = (this.toLong() shl 32) or (other.toLong() and 0xFFFFFFFFL)
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ package io.github.addoncommunity.test

import be.seeseemelk.mockbukkit.MockBukkit
import be.seeseemelk.mockbukkit.UnimplementedOperationException
import com.github.shynixn.mccoroutine.bukkit.MCCoroutine
import com.github.shynixn.mccoroutine.bukkit.test.TestMCCoroutine
import io.github.addoncommunity.galactifun.Galactifun2
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach

abstract class CommonTest {

private lateinit var driver: String

@BeforeEach
fun setUp() {
MockBukkit.mock()
MockBukkit.load(Slimefun::class.java)
driver = MCCoroutine.Driver
MCCoroutine.Driver = TestMCCoroutine.Driver
try {
MockBukkit.load(Galactifun2::class.java)
} catch (e: UnimplementedOperationException) {
Expand All @@ -23,5 +29,6 @@ abstract class CommonTest {
@AfterEach
fun tearDown() {
MockBukkit.unmock()
MCCoroutine.Driver = driver
}
}

This file was deleted.

0 comments on commit 6583372

Please sign in to comment.