From 6dfe2d0af25b158d939dadc59cf132d95bfa970c Mon Sep 17 00:00:00 2001 From: Niklas Widmann Date: Wed, 9 Aug 2023 09:12:08 +0200 Subject: [PATCH] fix forge runtime --- .../skygrid/api/xml/DeserializationException.kt | 4 ++-- build.gradle.kts | 2 +- .../skygrid/extensions/SourcedRandom.kt | 15 +++++++++++++++ .../skygrid/world/SkygridChunkGenerator.kt | 17 ++++++++++------- .../skygrid/xml/XMLResource.kt | 3 +-- forge/build.gradle.kts | 15 +++++++++++++++ .../skygrid/forge/SkygridForge.kt | 2 ++ .../skygrid/forge/platform/ForgeEvents.kt | 4 ++-- forge/src/main/resources/META-INF/mods.toml | 11 ++--------- gradle.properties | 3 ++- settings.gradle.kts | 1 + 11 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 common/src/main/kotlin/com/possible_triangle/skygrid/extensions/SourcedRandom.kt diff --git a/api/src/main/kotlin/com/possible_triangle/skygrid/api/xml/DeserializationException.kt b/api/src/main/kotlin/com/possible_triangle/skygrid/api/xml/DeserializationException.kt index 6ab1f48..ead7d0f 100644 --- a/api/src/main/kotlin/com/possible_triangle/skygrid/api/xml/DeserializationException.kt +++ b/api/src/main/kotlin/com/possible_triangle/skygrid/api/xml/DeserializationException.kt @@ -1,10 +1,10 @@ package com.possible_triangle.skygrid.api.xml -import nl.adaptivity.xmlutil.serialization.XmlSerialException +import kotlinx.serialization.SerializationException class DeserializationException( val location: String?, val field: String, val candidates: Collection = emptyList(), ) : - XmlSerialException("Unknown field $field at $location") \ No newline at end of file + SerializationException("Unknown field $field at $location") \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index f2b652d..1ccd905 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ val xmlutil_version: String by extra plugins { idea - id("net.somethingcatchy.gradle") version ("0.0.7") + id("net.somethingcatchy.gradle") version ("0.0.0-dev") } withKotlin() diff --git a/common/src/main/kotlin/com/possible_triangle/skygrid/extensions/SourcedRandom.kt b/common/src/main/kotlin/com/possible_triangle/skygrid/extensions/SourcedRandom.kt new file mode 100644 index 0000000..c6255ec --- /dev/null +++ b/common/src/main/kotlin/com/possible_triangle/skygrid/extensions/SourcedRandom.kt @@ -0,0 +1,15 @@ +package com.possible_triangle.skygrid.extensions + +import net.minecraft.util.RandomSource +import net.minecraft.world.level.levelgen.XoroshiroRandomSource +import kotlin.random.Random + +class SourcedRandom(private val source: RandomSource) : Random { + + override fun nextBits(bitCount: Int) = when(source) { + is XoroshiroRandomSource -> source.nextBits + } + + + +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/possible_triangle/skygrid/world/SkygridChunkGenerator.kt b/common/src/main/kotlin/com/possible_triangle/skygrid/world/SkygridChunkGenerator.kt index f686a38..6309d2e 100644 --- a/common/src/main/kotlin/com/possible_triangle/skygrid/world/SkygridChunkGenerator.kt +++ b/common/src/main/kotlin/com/possible_triangle/skygrid/world/SkygridChunkGenerator.kt @@ -1,11 +1,12 @@ package com.possible_triangle.skygrid.world -import com.google.common.base.Suppliers import com.mojang.datafixers.util.Function5 import com.mojang.serialization.Codec import com.mojang.serialization.Lifecycle import com.mojang.serialization.codecs.RecordCodecBuilder import com.possible_triangle.skygrid.api.SkygridConstants +import com.possible_triangle.skygrid.xml.resources.DimensionConfigs +import com.possible_triangle.skygrid.xml.resources.Presets import net.minecraft.core.BlockPos import net.minecraft.core.MappedRegistry import net.minecraft.core.Registry @@ -38,8 +39,6 @@ import net.minecraft.world.level.levelgen.WorldGenSettings import net.minecraft.world.level.levelgen.blending.Blender import net.minecraft.world.level.levelgen.structure.StructureSet import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement -import com.possible_triangle.skygrid.xml.resources.DimensionConfigs -import com.possible_triangle.skygrid.xml.resources.Presets import java.util.* import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor @@ -161,7 +160,8 @@ class SkygridChunkGenerator( ) else null - fun endPortalPositions(random: Random): List = Suppliers.memoize { + private var cachedEndPortalPositions: List? = null + fun endPortalPositions(random: Random): List = cachedEndPortalPositions ?: run { val strongholdRandom = Random(random.nextLong()) strongholdSettings?.let { val distance = it.distance() @@ -195,7 +195,9 @@ class SkygridChunkGenerator( ChunkPos(degX, degZ) } } ?: emptyList() - }.get() + }.also { + cachedEndPortalPositions = it + } override fun fillFromNoise( executor: Executor, @@ -204,7 +206,7 @@ class SkygridChunkGenerator( structures: StructureManager, chunk: ChunkAccess, ): CompletableFuture { - val random = randomState.random() + val randomFactory = randomState.getOrCreateRandomFactory(ResourceLocation(SkygridConstants.MOD_ID, "generator")) val gap = config.gap.map { it.block.defaultBlockState() } val createCeiling = false // TODO region.dimensionType().hasCeiling() @@ -241,12 +243,13 @@ class SkygridChunkGenerator( } } - val hasEndPortal = endPortalPositions(random).contains(chunk.pos) + val hasEndPortal = endPortalPositions(randomState.random()).contains(chunk.pos) var generatedPortal = false for (x in 0 until 16) for (z in 0 until 16) for (y in minY..(maxY + 2)) { mutable.set(x, y, z) + val random = randomFactory.at(mutable).nextBoolean() val isFloor = y == minY if (config.distance.isBlock(mutable.offset(origin))) { diff --git a/common/src/main/kotlin/com/possible_triangle/skygrid/xml/XMLResource.kt b/common/src/main/kotlin/com/possible_triangle/skygrid/xml/XMLResource.kt index ae13a91..49d3f20 100644 --- a/common/src/main/kotlin/com/possible_triangle/skygrid/xml/XMLResource.kt +++ b/common/src/main/kotlin/com/possible_triangle/skygrid/xml/XMLResource.kt @@ -1,6 +1,5 @@ package com.possible_triangle.skygrid.xml -import com.google.common.base.Suppliers import com.possible_triangle.skygrid.SkygridMod.LOGGER import com.possible_triangle.skygrid.api.SkygridConstants import com.possible_triangle.skygrid.api.xml.DeserializationException @@ -22,7 +21,7 @@ abstract class XMLResource(val path: String, private val serializer: () -> KS @ExperimentalXmlUtilApi @ExperimentalSerializationApi companion object { - val LOADER: StringFormat get() = Suppliers.memoize(::createXMLModule).get() + val LOADER: StringFormat by lazy(::createXMLModule) private val RESOURCES = arrayListOf>() diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 7fd59ab..f14e670 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -1,14 +1,29 @@ +val kotlin_forge_version: String by extra val curios_forge_version: String by extra val botania_version: String by extra forge { enableMixins() + kotlinForgeVersion = null + dependOn(project(":api")) dependOn(project(":common")) } +// required because of duplicate package export +configurations.named("minecraftLibrary") { + exclude(group = "org.jetbrains", module = "annotations") +} + dependencies { + // required because of duplicate package export by thedarkcolour:kotlinforforge:all + implementation("thedarkcolour:kffmod:${kotlin_forge_version}") + implementation("thedarkcolour:kfflang:${kotlin_forge_version}") + implementation("thedarkcolour:kfflib:${kotlin_forge_version}") + + add("minecraftLibrary", "org.jetbrains.kotlin:kotlin-reflect:${kotlin.coreLibrariesVersion}") + if (!env.isCI) { //modRuntimeOnly("vazkii.autoreglib:AutoRegLib:${arl_version}") diff --git a/forge/src/main/kotlin/com/possible_triangle/skygrid/forge/SkygridForge.kt b/forge/src/main/kotlin/com/possible_triangle/skygrid/forge/SkygridForge.kt index 8ea0883..62db3eb 100644 --- a/forge/src/main/kotlin/com/possible_triangle/skygrid/forge/SkygridForge.kt +++ b/forge/src/main/kotlin/com/possible_triangle/skygrid/forge/SkygridForge.kt @@ -32,6 +32,8 @@ object SkygridForge { val BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MOD_ID)!! init { + nl.adaptivity.xmlutil.serialization.XML.defaultInstance + ForgeConfig.register() SkygridMod.init() diff --git a/forge/src/main/kotlin/com/possible_triangle/skygrid/forge/platform/ForgeEvents.kt b/forge/src/main/kotlin/com/possible_triangle/skygrid/forge/platform/ForgeEvents.kt index 0001c93..c3c17aa 100644 --- a/forge/src/main/kotlin/com/possible_triangle/skygrid/forge/platform/ForgeEvents.kt +++ b/forge/src/main/kotlin/com/possible_triangle/skygrid/forge/platform/ForgeEvents.kt @@ -9,12 +9,12 @@ import kotlin.reflect.KClass class ForgeEvents : IEvents { - private class ForgeEvent(val event: TEvent) : GenericEvent() + private class ForgeEvent(val event: TEvent, type: KClass) : GenericEvent(type.java) override fun createEvent(clazz: KClass): EventInvoker { return object : EventInvoker { override fun invoke(event: TEvent) { - FORGE_BUS.post(ForgeEvent(event)) + FORGE_BUS.post(ForgeEvent(event, clazz)) } override fun addListener(callback: EventCallback) { diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index be89da5..d2ab765 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -1,7 +1,7 @@ modLoader = "kotlinforforge" loaderVersion = "[3.9,)" -license = 'https://github.com/PssbleTrngle/${repository}/blob/1.19.x/LICENSE.txt' -issueTrackerURL = "https://github.com/PssbleTrngle/${repository}/issues" +license = 'https://github.com/${repository}/blob/1.19.x/LICENSE.txt' +issueTrackerURL = "https://github.com/${repository}/issues" showAsResourcePack = false [[mods]] @@ -25,10 +25,3 @@ showAsResourcePack = false versionRange = "[1.19.2,)" ordering = "NONE" side = "BOTH" - -[[dependencies.${mod_id}]] - modId="kotlinforforge" - mandatory=true - versionRange="[3.9.1,)" - ordering="NONE" - side="BOTH" diff --git a/gradle.properties b/gradle.properties index a6b1ce1..df28ce4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,6 +2,7 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false kotlin.code.style=official +kotlin.stdlib.default.dependency=false # Project mod_id=skygrid @@ -25,7 +26,7 @@ fabric_loader_version=0.14.21 xmlutil_version=0.86.1 kotlin_fabric_version=1.9.2+kotlin.1.8.10 -kotlin_forge_version=3.9.1 +kotlin_forge_version=3.12.0 jei_version=11.0.0.206 #arl_version=1.7-53.110 diff --git a/settings.gradle.kts b/settings.gradle.kts index bf0f942..a0a2416 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,6 +5,7 @@ pluginManagement { gradlePluginPortal() maven { url = uri("https://maven.fabricmc.net/") } maven { url = uri("https://repo.spongepowered.org/repository/maven-public/") } + maven { url = uri(System.getenv()["LOCAL_MAVEN"]!!) } } }