Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion common/src/main/kotlin/com/lambda/core/Loadable.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.lambda.core

/**
* Represents a loadable object.
*/
interface Loadable {
fun load() = this::class.simpleName?.let { "Loaded $it" } ?: "Loaded"
}
}
2 changes: 1 addition & 1 deletion common/src/main/kotlin/com/lambda/core/PingManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ object PingManager : Loadable {
pings.add(Util.getMeasuringTimeMs() - event.packet.startTime)
}
}
}
}
2 changes: 1 addition & 1 deletion common/src/main/kotlin/com/lambda/core/TimerManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ object TimerManager : Loadable {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.lambda.core.registry

import net.minecraft.registry.Registry
import net.minecraft.registry.RegistryKey
import net.minecraft.util.Identifier


object RegistryController {
private val REGISTRIES = HashMap<RegistryKey<out Registry<*>?>, MutableList<RegistryHolder<*>>>()

fun <T> register(registry: Registry<T>, id: Identifier, value: T): RegistryHolder<T> {
val holder = RegistryHolder(id, value)

REGISTRIES.computeIfAbsent(registry.key) { mutableListOf(holder) }
return holder
}

/**
* Loads the temporary registry holders into the actual registry.
* This should be called after all registry holders have been created.
*/
fun register(resourceKey: RegistryKey<out Registry<*>?>, registry: RegistryWrapper<*>) {
REGISTRIES[resourceKey]?.forEach { it.handleRegister(registry) }
REGISTRIES.remove(resourceKey)
}
}
25 changes: 25 additions & 0 deletions common/src/main/kotlin/com/lambda/core/registry/RegistryHolder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.lambda.core.registry

import net.minecraft.registry.entry.RegistryEntry
import net.minecraft.util.Identifier
import java.util.function.Supplier


class RegistryHolder<T> internal constructor(
val id: Identifier,
var value: T,
) : Supplier<T> {
private var holder: RegistryEntry<T>? = null

override fun get(): T {
with(holder) {
checkNotNull(this) { "RegistryHolder not populated" }

return this.value()
}
}

fun handleRegister(registry: RegistryWrapper<*>) {
this.holder = registry.registerForHolder(id, value)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.lambda.core.registry

import net.minecraft.registry.entry.RegistryEntry
import net.minecraft.util.Identifier

interface RegistryWrapper<T> {
fun <T> registerForHolder(id: Identifier?, value: T): RegistryEntry<T>
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ enum class LambdaFont(private val fontName: String) {
return "Loaded ${entries.size} fonts"
}
}
}
}
15 changes: 8 additions & 7 deletions common/src/main/kotlin/com/lambda/gui/AbstractGuiConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ abstract class AbstractGuiConfigurable(
var mainWindows by setting("windows", defaultWindows)
open var customWindows = mutableListOf<CustomModuleWindow>()

private val defaultWindows get() =
tags.mapIndexed { index, tag ->
TagWindow(tag, ownerGui).apply {
val step = 5.0
position = Vec2d((width + step) * index, 0.0) + step
private val defaultWindows
get() =
tags.mapIndexed { index, tag ->
TagWindow(tag, ownerGui).apply {
val step = 5.0
position = Vec2d((width + step) * index, 0.0) + step
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.lambda.interaction

import com.lambda.Lambda.mc
import com.lambda.config.groups.IRotationConfig
import com.lambda.config.groups.RotationSettings
import com.lambda.core.Loadable
import com.lambda.context.SafeContext
import com.lambda.core.Loadable
import com.lambda.event.EventFlow.post
import com.lambda.event.events.*
import com.lambda.event.listener.SafeListener.Companion.listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import net.minecraft.item.ItemStack
import net.minecraft.screen.GenericContainerScreenHandler
import net.minecraft.screen.ScreenHandler
import net.minecraft.screen.ScreenHandlerType
import java.util.TreeSet
import java.util.*

// ToDo: Make this a Configurable to save container caches. Should use a cached region based storage system.
object ContainerManager : Loadable {
Expand Down Expand Up @@ -121,4 +121,4 @@ object ContainerManager : Loadable {
// fun SafeContext.nextDisposable() = player.combined.firstOrNull { it.item in TaskFlow.disposables }

class NoContainerFound(selection: StackSelection): Exception("No container found matching $selection")
}
}
4 changes: 2 additions & 2 deletions common/src/main/kotlin/com/lambda/sound/SoundRegistry.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.lambda.sound

import com.lambda.core.Loadable
import com.lambda.core.registry.RegistryController
import net.minecraft.registry.Registries
import net.minecraft.registry.Registry

object SoundRegistry : Loadable {
override fun load(): String {
LambdaSound.entries.forEach {
Registry.register(Registries.SOUND_EVENT, it.id, it.event)
RegistryController.register(Registries.SOUND_EVENT, it.id, it.event)
}

return "Loaded ${LambdaSound.entries.size} sounds"
Expand Down
14 changes: 14 additions & 0 deletions fabric/src/main/kotlin/com/lambda/fabric/LambdaFabric.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ import com.lambda.Lambda
import com.lambda.Lambda.LOG
import com.lambda.Lambda.MOD_NAME
import com.lambda.Lambda.VERSION
import com.lambda.core.registry.RegistryController
import com.lambda.core.registry.RegistryWrapper
import net.fabricmc.api.ClientModInitializer
import net.minecraft.registry.Registries
import net.minecraft.registry.Registry
import net.minecraft.registry.entry.RegistryEntry
import net.minecraft.util.Identifier

object LambdaFabric : ClientModInitializer {
override fun onInitializeClient() {
Lambda.initialize()
LOG.info("$MOD_NAME Fabric $VERSION initialized.")

Registries.REGISTRIES.forEach { registry ->
RegistryController.register(registry.key, object : RegistryWrapper<Any> {
override fun <T> registerForHolder(id: Identifier?, value: T): RegistryEntry<T> {
return Registry.registerReference(registry as Registry<T>, id, value)
}
})
}
}
}
2 changes: 2 additions & 0 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ val shadowBundle: Configuration by configurations.creating {

fun DependencyHandlerScope.setupConfigurations() {
includeLib.dependencies.forEach {
implementation(it)
forgeRuntimeLibrary(it)
include(it)
}

includeMod.dependencies.forEach {
modImplementation(it)
forgeRuntimeLibrary(it)
include(it)
}
Expand Down
18 changes: 18 additions & 0 deletions forge/src/main/kotlin/com/lambda/forge/LambdaForge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,31 @@ import com.lambda.Lambda
import com.lambda.Lambda.LOG
import com.lambda.Lambda.MOD_NAME
import com.lambda.Lambda.VERSION
import com.lambda.core.registry.RegistryController
import com.lambda.core.registry.RegistryWrapper
import net.minecraft.registry.Registry
import net.minecraft.registry.entry.RegistryEntry
import net.minecraft.util.Identifier
import net.minecraftforge.eventbus.api.SubscribeEvent
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.Mod.EventBusSubscriber
import net.minecraftforge.registries.RegisterEvent


@Mod(Lambda.MOD_ID)
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
object LambdaForge {
init {
Lambda.initialize()
LOG.info("$MOD_NAME Forge $VERSION initialized.")
}

@SubscribeEvent
fun onRegistrySetup(event: RegisterEvent) {
RegistryController.register(event.registryKey, object : RegistryWrapper<Any> {
override fun <T> registerForHolder(id: Identifier?, value: T): RegistryEntry<T> {
return Registry.registerReference(event.getVanillaRegistry(), id, value)
}
})
}
}
20 changes: 19 additions & 1 deletion neoforge/src/main/kotlin/com/lambda/neoforge/LambdaNeoForge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,30 @@ import com.lambda.Lambda
import com.lambda.Lambda.LOG
import com.lambda.Lambda.MOD_NAME
import com.lambda.Lambda.VERSION
import com.lambda.core.registry.RegistryController
import com.lambda.core.registry.RegistryWrapper
import net.minecraft.registry.Registry
import net.minecraft.registry.entry.RegistryEntry
import net.minecraft.util.Identifier
import net.neoforged.bus.api.SubscribeEvent
import net.neoforged.fml.common.Mod
import net.neoforged.fml.common.Mod.EventBusSubscriber
import net.neoforged.neoforge.registries.RegisterEvent

@Mod(Lambda.MOD_ID)
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
object LambdaNeoForge {
init {
Lambda.initialize()
LOG.info("$MOD_NAME NeoForge $VERSION initialized.")
LOG.info("$MOD_NAME Forge $VERSION initialized.")
}

@SubscribeEvent
fun onRegistrySetup(event: RegisterEvent) {
RegistryController.register(event.registryKey, object : RegistryWrapper<Any> {
override fun <T> registerForHolder(id: Identifier?, value: T): RegistryEntry<T> {
return Registry.registerReference(event.registry as Registry<T>, id, value)
}
})
}
}