Skip to content

Commit

Permalink
fix forge runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Aug 9, 2023
1 parent 6c61b49 commit 6dfe2d0
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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<Any> = emptyList(),
) :
XmlSerialException("Unknown field $field at $location")
SerializationException("Unknown field $field at $location")
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}



}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -161,7 +160,8 @@ class SkygridChunkGenerator(
)
else null

fun endPortalPositions(random: Random): List<ChunkPos> = Suppliers.memoize {
private var cachedEndPortalPositions: List<ChunkPos>? = null
fun endPortalPositions(random: Random): List<ChunkPos> = cachedEndPortalPositions ?: run {
val strongholdRandom = Random(random.nextLong())
strongholdSettings?.let {
val distance = it.distance()
Expand Down Expand Up @@ -195,7 +195,9 @@ class SkygridChunkGenerator(
ChunkPos(degX, degZ)
}
} ?: emptyList()
}.get()
}.also {
cachedEndPortalPositions = it
}

override fun fillFromNoise(
executor: Executor,
Expand All @@ -204,7 +206,7 @@ class SkygridChunkGenerator(
structures: StructureManager,
chunk: ChunkAccess,
): CompletableFuture<ChunkAccess> {
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()
Expand Down Expand Up @@ -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))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +21,7 @@ abstract class XMLResource<T>(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<XMLResource<*>>()

Expand Down
15 changes: 15 additions & 0 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import kotlin.reflect.KClass

class ForgeEvents : IEvents {

private class ForgeEvent<TEvent>(val event: TEvent) : GenericEvent<TEvent>()
private class ForgeEvent<TEvent : Any>(val event: TEvent, type: KClass<TEvent>) : GenericEvent<TEvent>(type.java)

override fun <TEvent : Any> createEvent(clazz: KClass<TEvent>): EventInvoker<TEvent> {
return object : EventInvoker<TEvent> {
override fun invoke(event: TEvent) {
FORGE_BUS.post(ForgeEvent(event))
FORGE_BUS.post(ForgeEvent(event, clazz))
}

override fun addListener(callback: EventCallback<TEvent>) {
Expand Down
11 changes: 2 additions & 9 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -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]]
Expand All @@ -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"
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]!!) }
}
}

Expand Down

0 comments on commit 6dfe2d0

Please sign in to comment.