From d98dcd9cd295507dd2974a2ba62222747fdbd89c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Tue, 13 Jan 2026 00:47:37 +0100 Subject: [PATCH 01/58] start the big refactor stuff louve u ender lol From c912c1a734691601322a87b87c21e35611843d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Tue, 13 Jan 2026 18:10:04 +0100 Subject: [PATCH 02/58] APIlice the module system --- .../ender_development/catalyx/api/.gitkeep | 1 + .../catalyx/api/v1/Factory.kt | 23 +++++++++ .../v1/annotations}/module/CatalyxModule.kt | 5 +- .../module/CatalyxModuleContainer.kt | 2 +- .../v1/interfaces/cast/IAsResourceLocation.kt | 47 +++++++++++++++++++ .../api/v1/interfaces/cast/ICanCastInto.kt | 33 +++++++++++++ .../v1/interfaces/cast/ICanMaybeCastInto.kt | 25 ++++++++++ .../v1/interfaces}/module/ICatalyxModule.kt | 33 +++++++------ .../v1/interfaces/module/IModuleIdentifier.kt | 14 ++++++ .../v1/interfaces/module/IModuleManager.kt | 47 +++++++++++++++++++ .../catalyx/core/module/IModuleManager.kt | 13 ----- .../catalyx/core/module/ModuleIdentifier.kt | 12 +++-- .../catalyx/core/module/ModuleManager.kt | 19 +++++--- .../catalyx/modules/CatalyxCoreModule.kt | 4 +- .../modules/CatalyxInternalModuleContainer.kt | 2 +- .../catalyx/modules/CatalyxModuleBase.kt | 2 +- .../modules/integration/IntegrationModule.kt | 2 +- .../groovyscript/ModuleGroovyScript.kt | 2 +- .../integration/top/ModuleTheOneProbe.kt | 2 +- .../modules/internal/InternalModule.kt | 4 +- .../catalyx/modules/test/DevTestModule.kt | 2 +- 21 files changed, 243 insertions(+), 51 deletions(-) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt rename src/main/kotlin/org/ender_development/catalyx/{core => api/v1/annotations}/module/CatalyxModule.kt (89%) rename src/main/kotlin/org/ender_development/catalyx/{core => api/v1/annotations}/module/CatalyxModuleContainer.kt (86%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanCastInto.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanMaybeCastInto.kt rename src/main/kotlin/org/ender_development/catalyx/{core => api/v1/interfaces}/module/ICatalyxModule.kt (60%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleIdentifier.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleManager.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/module/IModuleManager.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/api/.gitkeep b/src/main/kotlin/org/ender_development/catalyx/api/.gitkeep index e69de29..9f21392 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/.gitkeep +++ b/src/main/kotlin/org/ender_development/catalyx/api/.gitkeep @@ -0,0 +1 @@ +Do not remove until v2 package added at sometime because of IJ diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt new file mode 100644 index 0000000..18e4277 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt @@ -0,0 +1,23 @@ +package org.ender_development.catalyx.api.v1 + +/** + * API-Status: NOT-FROZEN + * Be aware + */ + +import org.ender_development.catalyx.api.v1.interfaces.module.IModuleIdentifier +import org.ender_development.catalyx.api.v1.interfaces.module.IModuleManager +import org.ender_development.catalyx.core.module.ModuleIdentifier +import org.ender_development.catalyx.core.module.ModuleManager + +/** + * Contains the current [ModuleManager] implementation + */ +val moduleManager: IModuleManager = ModuleManager + +/** + * Factories for [IModuleIdentifier] + * currently implemented by [ModuleIdentifier] + */ +fun newModuleIdentifier(identifier: String): IModuleIdentifier = ModuleIdentifier(identifier) +fun newModuleIdentifier(containerId: String, moduleId: String): IModuleIdentifier = ModuleIdentifier(containerId, moduleId) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/CatalyxModule.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModule.kt similarity index 89% rename from src/main/kotlin/org/ender_development/catalyx/core/module/CatalyxModule.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModule.kt index 4868a63..eabdfcc 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/CatalyxModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModule.kt @@ -1,9 +1,10 @@ -package org.ender_development.catalyx.core.module +package org.ender_development.catalyx.api.v1.annotations.module import org.ender_development.catalyx.core.Reference /** - * All of your [ICatalyxModule] classes must be annotated with this to be registered. + * All of your [org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule] + * classes must be annotated with this to be registered. */ @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/CatalyxModuleContainer.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModuleContainer.kt similarity index 86% rename from src/main/kotlin/org/ender_development/catalyx/core/module/CatalyxModuleContainer.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModuleContainer.kt index 6971f50..dd32b2e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/CatalyxModuleContainer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModuleContainer.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.module +package org.ender_development.catalyx.api.v1.annotations.module /** * Annotate your Module Containers with this for it to be automatically registered. diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt new file mode 100644 index 0000000..0fef0ee --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt @@ -0,0 +1,47 @@ +package org.ender_development.catalyx.api.v1.interfaces.cast + +import net.minecraft.util.ResourceLocation + +/** + * Implement this to provide capability to cast into [ResourceLocation] + * no matter if you actually inhere from [ResourceLocation] + * + * @see [ICanCastInto] + */ +interface IAsResourceLocation : + ICanCastInto, + Comparable { + + override fun compareTo(other: ResourceLocation) = other.compareTo(this.asResourceLocation()) + + override fun saveCast(): ResourceLocation = asResourceLocation() + fun asResourceLocation(): ResourceLocation + + /** + * Converts a [ResourceLocation] into [IAsResourceLocation] + * It's a Duck-Typing workaround + * + * For example: + * ``` + * fun giveMeAnyCastable(value: IAsResourceLocation) + * + * val myRL: ResourceLocation = ResourceLocation() + * giveMeAnyCastable(myRL) // does not work but + * giveMeAnyCastable(myRL.asIAsResourceLocation()) // does work + * ``` + * + * But in practice, everywhere a parameter typed of [IAsResourceLocation] is awaited, + * an overloaded variant of the same function should be provided. + * + * ``` + * fun giveMeAnyRL(value: IAsResourceLocation) + * = giveMeAnyRL(value.asResourceLocation()) + * fun giveMeAnyRL(value: ResourceLocation) + * ``` + * + * @return an [IAsResourceLocation] wrapper for this [ResourceLocation] + */ + fun ResourceLocation.asIAsResourceLocation(): IAsResourceLocation = object : IAsResourceLocation { + override fun asResourceLocation() = this@asIAsResourceLocation + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanCastInto.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanCastInto.kt new file mode 100644 index 0000000..b77e073 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanCastInto.kt @@ -0,0 +1,33 @@ +package org.ender_development.catalyx.api.v1.interfaces.cast + +/** + * Implement this to provide capability to cast into [T] + * no matter if you actually inhere from [T] + * + * This allows dynamic casting. + * + * @param T Type you can cast into + * + * @see [ICanMaybeCastInto] + */ +interface ICanCastInto : ICanMaybeCastInto { + + /** + * Allows to cast safely into [T] + * + * The default implementation shouldn't be used because it's actually not really save. + * ONLY USE THE DEFAULT IMPLEMENTATION IF YOU INHERE FROM [T]! + * + * @return Equivalent of [T] for this + */ + @Suppress("UNCHECKED_CAST") + fun saveCast(): T = try { + this as T + } catch(e: ClassCastException) { + throw IllegalStateException( + "This interface should not be implemented if you cant cast safely into T " + + "Override this to do a manuel dynamic cast.", + e + ) + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanMaybeCastInto.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanMaybeCastInto.kt new file mode 100644 index 0000000..c71bc1e --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanMaybeCastInto.kt @@ -0,0 +1,25 @@ +package org.ender_development.catalyx.api.v1.interfaces.cast + +/** + * Implement this to provide capability to try cast into [T] + * no matter if you actually inhere from [T] + * + * This allows dynamic casting. + * + * @param T Type you can maybe cast into + * + * @see [ICanCastInto] + */ +interface ICanMaybeCastInto { + /** + * Allows to cast safely into [T] + * + * @return Equivalent of [T] for this or null if fails + */ + @Suppress("UNCHECKED_CAST") + fun saveCastorNull(): T? = try { + this as T + } catch(e: ClassCastException) { + null + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ICatalyxModule.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/ICatalyxModule.kt similarity index 60% rename from src/main/kotlin/org/ender_development/catalyx/core/module/ICatalyxModule.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/ICatalyxModule.kt index 8ac98d9..e1c9fac 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ICatalyxModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/ICatalyxModule.kt @@ -1,14 +1,17 @@ -package org.ender_development.catalyx.core.module +package org.ender_development.catalyx.api.v1.interfaces.module import net.minecraftforge.fml.common.event.* import org.apache.logging.log4j.Logger +import org.ender_development.catalyx.api.v1.moduleManager /** * All modules must implement this interface. * * Provides methods for responding to FML lifecycle events and adding event bus subscribers. * - * Note: if your Module is an `object`, and other parts of your code access it, please don't have any side-effects in the class initialisation/instantiation, as any module can be disabled via the Catalyx config, or by its dependencies being unmet. + * Note: If your Module is a kotlin `object`, and other parts of your code access it, + * please don't have any side effects in the class initialisation/instantiation, + * as any module can be disabled via the Catalyx config, or by its dependencies being unmet. */ interface ICatalyxModule { /** @@ -20,37 +23,37 @@ interface ICatalyxModule { * A boolean indicating whether this module is enabled. */ val enabled: Boolean - get() = ModuleManager.isModuleEnabled(this) + get() = moduleManager.isModuleEnabled(this) /** * Called when this module is loaded. */ - fun load() {} + fun load() = Unit /** * Called before each of the other callbacks, but after the mod itself receives the event */ - fun lifecycle(event: FMLStateEvent) {} + fun lifecycle(event: FMLStateEvent) = Unit - fun construction(event: FMLConstructionEvent) {} + fun construction(event: FMLConstructionEvent) = Unit - fun preInit(event: FMLPreInitializationEvent) {} + fun preInit(event: FMLPreInitializationEvent) = Unit - fun init(event: FMLInitializationEvent) {} + fun init(event: FMLInitializationEvent) = Unit - fun postInit(event: FMLPostInitializationEvent) {} + fun postInit(event: FMLPostInitializationEvent) = Unit - fun loadComplete(event: FMLLoadCompleteEvent) {} + fun loadComplete(event: FMLLoadCompleteEvent) = Unit - fun serverAboutToStart(event: FMLServerAboutToStartEvent) {} + fun serverAboutToStart(event: FMLServerAboutToStartEvent) = Unit - fun serverStarting(event: FMLServerStartingEvent) {} + fun serverStarting(event: FMLServerStartingEvent) = Unit - fun serverStarted(event: FMLServerStartedEvent) {} + fun serverStarted(event: FMLServerStartedEvent) = Unit - fun serverStopping(event: FMLServerStoppingEvent) {} + fun serverStopping(event: FMLServerStoppingEvent) = Unit - fun serverStopped(event: FMLServerStoppedEvent) {} + fun serverStopped(event: FMLServerStoppedEvent) = Unit /** * A list of classes to subscribe to the [Forge Event Bus][net.minecraftforge.common.MinecraftForge.EVENT_BUS]. diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleIdentifier.kt new file mode 100644 index 0000000..546cf50 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleIdentifier.kt @@ -0,0 +1,14 @@ +package org.ender_development.catalyx.api.v1.interfaces.module + +import net.minecraft.util.ResourceLocation +import org.ender_development.catalyx.api.v1.interfaces.cast.IAsResourceLocation + +/** + * An identifier thet identifies a module + * Any ModuleIdentifier thet implements this, can be casted to a [ResourceLocation] + * through the [IAsResourceLocation] implementation + */ +interface IModuleIdentifier : IAsResourceLocation { + val containerId: String + val moduleId: String +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleManager.kt new file mode 100644 index 0000000..3ad95d5 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleManager.kt @@ -0,0 +1,47 @@ +package org.ender_development.catalyx.api.v1.interfaces.module + +import org.ender_development.catalyx.api.v1.newModuleIdentifier + +/** + * Interface for the actual ModulaManager + * + * @see [org.ender_development.catalyx.api.v1.moduleManager] + */ +interface IModuleManager { + /** + * Checkup if a given Module is enabled + * + * @param containerId The ID of the module container witch the module contains + * @param moduleId The id of the module to check for + * @return true if enabled else false + */ + fun isModuleEnabled(containerId: String, moduleId: String) = + isModuleEnabled(newModuleIdentifier(containerId, moduleId)) + + /** + * Checkup if a given Module is enabled + * + * @param identifier the module identifier to check for + * @return true if enabled else false + */ + fun isModuleEnabled(identifier: IModuleIdentifier): Boolean + + /** + * Checkup if module is enabled + * + * @param module the module object + * @return true if enabled else false + */ + fun isModuleEnabled(module: ICatalyxModule): Boolean + + /** + * Registers a Module Container + * TODO: Provide better documentation + */ + fun registerContainer(container: Any) + + /** + * TODO: Provide any documentation + */ + val activeContainer: Any? +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/IModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/IModuleManager.kt deleted file mode 100644 index 9c7c464..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/IModuleManager.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.ender_development.catalyx.core.module - -interface IModuleManager { - fun isModuleEnabled(containerId: String, moduleId: String) = - isModuleEnabled(ModuleIdentifier(containerId, moduleId)) - - fun isModuleEnabled(identifier: ModuleIdentifier): Boolean - fun isModuleEnabled(module: ICatalyxModule): Boolean - - fun registerContainer(container: Any) - - val activeContainer: Any? -} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt index d8481fd..6aa4627 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt @@ -1,11 +1,17 @@ package org.ender_development.catalyx.core.module import net.minecraft.util.ResourceLocation +import org.ender_development.catalyx.api.v1.interfaces.module.IModuleIdentifier -class ModuleIdentifier : ResourceLocation { - val containerId: String = namespace - val moduleId: String = path +class ModuleIdentifier : ResourceLocation, IModuleIdentifier { + override val containerId: String = namespace + override val moduleId: String = path constructor(identifier: String) : super(identifier) constructor(containerId: String, moduleId: String) : super(containerId, moduleId) + + // needed to select an implementation + override fun compareTo(other: ResourceLocation): Int = super.compareTo(other) + + override fun asResourceLocation() = this } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt index 9226ab3..4c9ead9 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt @@ -11,6 +11,11 @@ import net.minecraftforge.fml.common.ModContainer import net.minecraftforge.fml.common.discovery.ASMDataTable import net.minecraftforge.fml.common.event.* import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule +import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModuleContainer +import org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule +import org.ender_development.catalyx.api.v1.interfaces.module.IModuleIdentifier +import org.ender_development.catalyx.api.v1.interfaces.module.IModuleManager import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.module.ModuleManager.configuration import org.ender_development.catalyx.core.module.ModuleManager.discoveredContainers @@ -31,7 +36,7 @@ object ModuleManager : IModuleManager { const val MODULE_CFG_FILE_NAME = "$MODULE_CFG_CATEGORY_NAME.cfg" private val loadedModules = ReferenceLinkedOpenHashSet() - private val loadedModuleIds = hashSetOf() // ender, you can go and turn this into some fastutil bs + private val loadedModuleIds = hashSetOf() // TODO: turn this into some fastutil bs private val loadedContainers = Object2ReferenceLinkedOpenHashMap() private val configDirectory = File(Loader.instance().configDir, Reference.MODID) @@ -61,7 +66,7 @@ object ModuleManager : IModuleManager { * * @param asmDataTable the data table containing all the Module Container and Module classes */ - fun setup(asmDataTable: ASMDataTable) { + internal fun setup(asmDataTable: ASMDataTable) { discoverContainers(asmDataTable) discoverModules(asmDataTable) } @@ -69,7 +74,7 @@ object ModuleManager : IModuleManager { private val discoveredContainers = hashMapOf>() /** - * Discovers [ModuleContainers][CatalyxModuleContainer] for registration after mod construction + * Discovers [ModuleContainers][org.ender_development.catalyx.api.v1.annotations.module.CatalyxModuleContainer] for registration after mod construction * * @see [discoveredContainers] * @param asmDataTable the table containing the ModuleContainer data @@ -84,7 +89,7 @@ object ModuleManager : IModuleManager { private val discoveredModules = hashMapOf>() /** - * Discovers [Modules][CatalyxModule] for registration after their container gets registered + * Discovers [Modules][org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule] for registration after their container gets registered * * @see discoveredModules * @param asmDataTable the ASM Data Table containing the module data @@ -124,7 +129,7 @@ object ModuleManager : IModuleManager { val willLoadIds = ObjectLinkedOpenHashSet() val willLoadModules = ReferenceLinkedOpenHashSet() - toRegister.forEach { containerId, modules -> + toRegister.forEach { (containerId, modules) -> // Ensure core module exists and is first modules.indexOfFirst { it.annotation.coreModule }.let { idx -> if(idx == -1) @@ -321,7 +326,7 @@ object ModuleManager : IModuleManager { * @param loader The loader to load the class with * @param asm The ASM class to load * @param type What is being loaded - used for error messages - * @return An instance of [asm] casted to [I], or null if anything fails + * @return An instance of [asm] cast to [I], or null if anything fails */ private inline fun loadClassAndCreateInstance(loader: ModClassLoader, asm: ASMDataTable.ASMData, type: String): I? { try { @@ -356,7 +361,7 @@ object ModuleManager : IModuleManager { * @param identifier the id of the module to check * @return true if the module is enabled, false otherwise */ - override fun isModuleEnabled(identifier: ModuleIdentifier) = + override fun isModuleEnabled(identifier: IModuleIdentifier) = loadedModuleIds.contains(identifier) override fun isModuleEnabled(module: ICatalyxModule) = diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt index 443adf2..bc71beb 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt @@ -7,10 +7,10 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule +import org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.client.AreaHighlighter -import org.ender_development.catalyx.core.module.CatalyxModule -import org.ender_development.catalyx.core.module.ICatalyxModule import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.core.utils.persistence.WorldPersistentData diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt index 0fd9ff7..77d7b94 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt @@ -1,7 +1,7 @@ package org.ender_development.catalyx.modules +import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModuleContainer import org.ender_development.catalyx.core.Reference -import org.ender_development.catalyx.core.module.CatalyxModuleContainer import org.ender_development.catalyx.core.utils.Mods /** diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxModuleBase.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxModuleBase.kt index d20ac04..d18c89d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxModuleBase.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxModuleBase.kt @@ -2,7 +2,7 @@ package org.ender_development.catalyx.modules import org.apache.logging.log4j.Logger import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.core.module.ICatalyxModule +import org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule /** * Abstract base class for all builtin Catalyx modules diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt index 4f12e29..c6c3636 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt @@ -1,7 +1,7 @@ package org.ender_development.catalyx.modules.integration +import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule import org.ender_development.catalyx.core.Reference -import org.ender_development.catalyx.core.module.CatalyxModule import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.CatalyxModuleBase diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt index 6d4c309..31a2609 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt @@ -4,8 +4,8 @@ import com.cleanroommc.groovyscript.GroovyScript import com.cleanroommc.groovyscript.api.GroovyPlugin import com.cleanroommc.groovyscript.compat.mods.GroovyContainer import net.minecraftforge.fml.common.Optional +import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule import org.ender_development.catalyx.core.Reference -import org.ender_development.catalyx.core.module.CatalyxModule import org.ender_development.catalyx.core.module.ModuleManager import org.ender_development.catalyx.core.utils.Mods import org.ender_development.catalyx.core.utils.extensions.subLogger diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt index 5974f16..b0a015b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt @@ -2,8 +2,8 @@ package org.ender_development.catalyx.modules.integration.top import mcjty.theoneprobe.TheOneProbe import net.minecraftforge.fml.common.event.FMLInitializationEvent +import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule import org.ender_development.catalyx.core.Reference -import org.ender_development.catalyx.core.module.CatalyxModule import org.ender_development.catalyx.core.utils.Mods import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt index 2f39231..a04f782 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt @@ -1,10 +1,10 @@ package org.ender_development.catalyx.modules.internal import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule +import org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.items.CopyPasteTool -import org.ender_development.catalyx.core.module.CatalyxModule -import org.ender_development.catalyx.core.module.ICatalyxModule import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt index 1d4f0b7..c24628e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt @@ -5,13 +5,13 @@ import net.minecraft.util.text.TextComponentString import net.minecraftforge.client.event.ClientChatEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.blocks.IOTileBlock import org.ender_development.catalyx.core.blocks.multiblock.CenterBlock import org.ender_development.catalyx.core.blocks.multiblock.parts.CornerBlock import org.ender_development.catalyx.core.blocks.multiblock.parts.SideBlock import org.ender_development.catalyx.core.client.AreaHighlighter -import org.ender_development.catalyx.core.module.CatalyxModule import org.ender_development.catalyx.core.utils.SideUtils import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer From 06cafd8a3f29431e1bc9a970f14c8bdc1177a8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Tue, 13 Jan 2026 19:20:17 +0100 Subject: [PATCH 03/58] ModuleIdentifier is not longer a ResourceLocation I hope I didn't broke something --- .../catalyx/api/v1/Factory.kt | 1 - .../catalyx/core/module/ModuleIdentifier.kt | 16 +++++------ .../catalyx/core/module/ModuleManager.kt | 27 ++++++++++--------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt index 18e4277..5ed2c23 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt @@ -19,5 +19,4 @@ val moduleManager: IModuleManager = ModuleManager * Factories for [IModuleIdentifier] * currently implemented by [ModuleIdentifier] */ -fun newModuleIdentifier(identifier: String): IModuleIdentifier = ModuleIdentifier(identifier) fun newModuleIdentifier(containerId: String, moduleId: String): IModuleIdentifier = ModuleIdentifier(containerId, moduleId) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt index 6aa4627..f78125e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt @@ -3,15 +3,11 @@ package org.ender_development.catalyx.core.module import net.minecraft.util.ResourceLocation import org.ender_development.catalyx.api.v1.interfaces.module.IModuleIdentifier -class ModuleIdentifier : ResourceLocation, IModuleIdentifier { - override val containerId: String = namespace - override val moduleId: String = path +data class ModuleIdentifier( + override val containerId: String, + override val moduleId: String): IModuleIdentifier { - constructor(identifier: String) : super(identifier) - constructor(containerId: String, moduleId: String) : super(containerId, moduleId) - - // needed to select an implementation - override fun compareTo(other: ResourceLocation): Int = super.compareTo(other) - - override fun asResourceLocation() = this + override fun asResourceLocation(): ResourceLocation + = ResourceLocation(containerId, moduleId) } + diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt index 4c9ead9..f4b4834 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt @@ -3,6 +3,7 @@ package org.ender_development.catalyx.core.module import it.unimi.dsi.fastutil.objects.Object2ReferenceLinkedOpenHashMap import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet +import net.minecraft.util.ResourceLocation import net.minecraftforge.common.MinecraftForge import net.minecraftforge.common.config.Configuration import net.minecraftforge.fml.common.Loader @@ -16,6 +17,7 @@ import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModuleCont import org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule import org.ender_development.catalyx.api.v1.interfaces.module.IModuleIdentifier import org.ender_development.catalyx.api.v1.interfaces.module.IModuleManager +import org.ender_development.catalyx.api.v1.newModuleIdentifier import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.module.ModuleManager.configuration import org.ender_development.catalyx.core.module.ModuleManager.discoveredContainers @@ -263,33 +265,32 @@ object ModuleManager : IModuleManager { Catalyx.LOGGER.debug("> Module Container {}:{} instantiated ({})", modId, containerId, asmContainer.className) - val discoveredModules = discoveredModules.remove(containerId) - if(discoveredModules.isNullOrEmpty()) { - Catalyx.LOGGER.debug("> Module Container {}:{} has no modules", modId, containerId) + var discoveredModules = discoveredModules.remove(containerId).orEmpty() + if(discoveredModules.isEmpty()) { + Catalyx.LOGGER.warn("> Module Container {}:{} has no modules", modId, containerId) return@forEach } // Check module ids before instantiating modules val willInstantiate = mutableListOf() - val willInstantiateIds = mutableListOf() + val willInstantiateIds = mutableListOf() do { var changed = false - val iter = discoveredModules.iterator() - while(iter.hasNext()) { - val module = iter.next() - val moduleId = ModuleIdentifier(module.annotationInfo["containerId"] as String, module.annotationInfo["moduleId"] as String) + discoveredModules = discoveredModules.filter { module -> + val moduleId = newModuleIdentifier(module.annotationInfo["containerId"] as String, module.annotationInfo["moduleId"] as String) val unmetDependencies = (module.annotationInfo["moduleDependencies"] as List<*>? ?: emptyList()) .filterIsInstance() - .map(::ModuleIdentifier) + .map(ResourceLocation::splitObjectName) + .map{ newModuleIdentifier(it[0], it[1]) } .filterNot { willInstantiateIds.contains(it) || loadedModuleIds.contains(it) } - if(unmetDependencies.isEmpty()) { - iter.remove() + return@filter if(unmetDependencies.isEmpty()) { changed = true willInstantiate.add(module) willInstantiateIds.add(moduleId) - } - } + false + } else true + }.toMutableList() } while(changed) Catalyx.LOGGER.debug("> Module Container {}:{} has {} dependent modules, but will be instantiating {} of them", modId, containerId, willInstantiate.size + discoveredModules.size, willInstantiate.size) From 7291687da2cfa0c2c98dc5f12e7b411788f88963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Tue, 13 Jan 2026 19:24:35 +0100 Subject: [PATCH 04/58] Reduce casting polymorthism --- .../v1/interfaces/cast/IAsResourceLocation.kt | 35 +------------------ .../api/v1/interfaces/cast/ICanCastInto.kt | 33 ----------------- .../v1/interfaces/cast/ICanMaybeCastInto.kt | 25 ------------- 3 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanCastInto.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanMaybeCastInto.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt index 0fef0ee..c18a111 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt @@ -5,43 +5,10 @@ import net.minecraft.util.ResourceLocation /** * Implement this to provide capability to cast into [ResourceLocation] * no matter if you actually inhere from [ResourceLocation] - * - * @see [ICanCastInto] */ -interface IAsResourceLocation : - ICanCastInto, - Comparable { +interface IAsResourceLocation : Comparable { override fun compareTo(other: ResourceLocation) = other.compareTo(this.asResourceLocation()) - override fun saveCast(): ResourceLocation = asResourceLocation() fun asResourceLocation(): ResourceLocation - - /** - * Converts a [ResourceLocation] into [IAsResourceLocation] - * It's a Duck-Typing workaround - * - * For example: - * ``` - * fun giveMeAnyCastable(value: IAsResourceLocation) - * - * val myRL: ResourceLocation = ResourceLocation() - * giveMeAnyCastable(myRL) // does not work but - * giveMeAnyCastable(myRL.asIAsResourceLocation()) // does work - * ``` - * - * But in practice, everywhere a parameter typed of [IAsResourceLocation] is awaited, - * an overloaded variant of the same function should be provided. - * - * ``` - * fun giveMeAnyRL(value: IAsResourceLocation) - * = giveMeAnyRL(value.asResourceLocation()) - * fun giveMeAnyRL(value: ResourceLocation) - * ``` - * - * @return an [IAsResourceLocation] wrapper for this [ResourceLocation] - */ - fun ResourceLocation.asIAsResourceLocation(): IAsResourceLocation = object : IAsResourceLocation { - override fun asResourceLocation() = this@asIAsResourceLocation - } } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanCastInto.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanCastInto.kt deleted file mode 100644 index b77e073..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanCastInto.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.ender_development.catalyx.api.v1.interfaces.cast - -/** - * Implement this to provide capability to cast into [T] - * no matter if you actually inhere from [T] - * - * This allows dynamic casting. - * - * @param T Type you can cast into - * - * @see [ICanMaybeCastInto] - */ -interface ICanCastInto : ICanMaybeCastInto { - - /** - * Allows to cast safely into [T] - * - * The default implementation shouldn't be used because it's actually not really save. - * ONLY USE THE DEFAULT IMPLEMENTATION IF YOU INHERE FROM [T]! - * - * @return Equivalent of [T] for this - */ - @Suppress("UNCHECKED_CAST") - fun saveCast(): T = try { - this as T - } catch(e: ClassCastException) { - throw IllegalStateException( - "This interface should not be implemented if you cant cast safely into T " + - "Override this to do a manuel dynamic cast.", - e - ) - } -} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanMaybeCastInto.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanMaybeCastInto.kt deleted file mode 100644 index c71bc1e..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/ICanMaybeCastInto.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.ender_development.catalyx.api.v1.interfaces.cast - -/** - * Implement this to provide capability to try cast into [T] - * no matter if you actually inhere from [T] - * - * This allows dynamic casting. - * - * @param T Type you can maybe cast into - * - * @see [ICanCastInto] - */ -interface ICanMaybeCastInto { - /** - * Allows to cast safely into [T] - * - * @return Equivalent of [T] for this or null if fails - */ - @Suppress("UNCHECKED_CAST") - fun saveCastorNull(): T? = try { - this as T - } catch(e: ClassCastException) { - null - } -} From 14d54bbf5c1835d34bdd674a0acc005a1714922a Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Tue, 13 Jan 2026 19:55:17 +0100 Subject: [PATCH 05/58] less silly --- .../catalyx/api/v1/Factory.kt | 22 --------- .../v1/interfaces/cast/IAsResourceLocation.kt | 14 ------ .../v1/interfaces/module/IModuleIdentifier.kt | 14 ------ .../v1/interfaces/module/IModuleManager.kt | 47 ------------------- .../catalyx/api/v1/modules/Modules.kt | 28 +++++++++++ .../annotations}/CatalyxModule.kt | 4 +- .../annotations}/CatalyxModuleContainer.kt | 2 +- .../interfaces}/ICatalyxModule.kt | 32 ++++++------- .../modules/interfaces/IModuleIdentifier.kt | 9 ++++ .../v1/modules/interfaces/IModuleManager.kt | 38 +++++++++++++++ .../catalyx/core/module/ModuleIdentifier.kt | 40 ++++++++++++---- .../catalyx/core/module/ModuleManager.kt | 41 ++++++++-------- .../catalyx/modules/CatalyxCoreModule.kt | 4 +- .../modules/CatalyxInternalModuleContainer.kt | 2 +- .../catalyx/modules/CatalyxModuleBase.kt | 2 +- .../modules/integration/IntegrationModule.kt | 2 +- .../groovyscript/ModuleGroovyScript.kt | 2 +- .../integration/top/ModuleTheOneProbe.kt | 2 +- .../modules/internal/InternalModule.kt | 4 +- .../catalyx/modules/test/DevTestModule.kt | 2 +- 20 files changed, 155 insertions(+), 156 deletions(-) delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleIdentifier.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleManager.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt rename src/main/kotlin/org/ender_development/catalyx/api/v1/{annotations/module => modules/annotations}/CatalyxModule.kt (92%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{annotations/module => modules/annotations}/CatalyxModuleContainer.kt (86%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{interfaces/module => modules/interfaces}/ICatalyxModule.kt (67%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleManager.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt deleted file mode 100644 index 5ed2c23..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/Factory.kt +++ /dev/null @@ -1,22 +0,0 @@ -package org.ender_development.catalyx.api.v1 - -/** - * API-Status: NOT-FROZEN - * Be aware - */ - -import org.ender_development.catalyx.api.v1.interfaces.module.IModuleIdentifier -import org.ender_development.catalyx.api.v1.interfaces.module.IModuleManager -import org.ender_development.catalyx.core.module.ModuleIdentifier -import org.ender_development.catalyx.core.module.ModuleManager - -/** - * Contains the current [ModuleManager] implementation - */ -val moduleManager: IModuleManager = ModuleManager - -/** - * Factories for [IModuleIdentifier] - * currently implemented by [ModuleIdentifier] - */ -fun newModuleIdentifier(containerId: String, moduleId: String): IModuleIdentifier = ModuleIdentifier(containerId, moduleId) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt deleted file mode 100644 index c18a111..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/cast/IAsResourceLocation.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.ender_development.catalyx.api.v1.interfaces.cast - -import net.minecraft.util.ResourceLocation - -/** - * Implement this to provide capability to cast into [ResourceLocation] - * no matter if you actually inhere from [ResourceLocation] - */ -interface IAsResourceLocation : Comparable { - - override fun compareTo(other: ResourceLocation) = other.compareTo(this.asResourceLocation()) - - fun asResourceLocation(): ResourceLocation -} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleIdentifier.kt deleted file mode 100644 index 546cf50..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleIdentifier.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.ender_development.catalyx.api.v1.interfaces.module - -import net.minecraft.util.ResourceLocation -import org.ender_development.catalyx.api.v1.interfaces.cast.IAsResourceLocation - -/** - * An identifier thet identifies a module - * Any ModuleIdentifier thet implements this, can be casted to a [ResourceLocation] - * through the [IAsResourceLocation] implementation - */ -interface IModuleIdentifier : IAsResourceLocation { - val containerId: String - val moduleId: String -} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleManager.kt deleted file mode 100644 index 3ad95d5..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/IModuleManager.kt +++ /dev/null @@ -1,47 +0,0 @@ -package org.ender_development.catalyx.api.v1.interfaces.module - -import org.ender_development.catalyx.api.v1.newModuleIdentifier - -/** - * Interface for the actual ModulaManager - * - * @see [org.ender_development.catalyx.api.v1.moduleManager] - */ -interface IModuleManager { - /** - * Checkup if a given Module is enabled - * - * @param containerId The ID of the module container witch the module contains - * @param moduleId The id of the module to check for - * @return true if enabled else false - */ - fun isModuleEnabled(containerId: String, moduleId: String) = - isModuleEnabled(newModuleIdentifier(containerId, moduleId)) - - /** - * Checkup if a given Module is enabled - * - * @param identifier the module identifier to check for - * @return true if enabled else false - */ - fun isModuleEnabled(identifier: IModuleIdentifier): Boolean - - /** - * Checkup if module is enabled - * - * @param module the module object - * @return true if enabled else false - */ - fun isModuleEnabled(module: ICatalyxModule): Boolean - - /** - * Registers a Module Container - * TODO: Provide better documentation - */ - fun registerContainer(container: Any) - - /** - * TODO: Provide any documentation - */ - val activeContainer: Any? -} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt new file mode 100644 index 0000000..ac46e75 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt @@ -0,0 +1,28 @@ +package org.ender_development.catalyx.api.v1.modules + +/** + * API-Status: NOT-FROZEN + * Be aware + */ + +import org.ender_development.catalyx.api.v1.modules.interfaces.IModuleIdentifier +import org.ender_development.catalyx.api.v1.modules.interfaces.IModuleManager +import org.ender_development.catalyx.core.module.ModuleIdentifier +import org.ender_development.catalyx.core.module.ModuleManager + +object Modules { + /** + * Contains the current [ModuleManager] implementation + */ + val moduleManager: IModuleManager = ModuleManager + + /** + * Factories for [IModuleIdentifier] + * currently implemented by [ModuleIdentifier] + */ + fun newModuleIdentifier(containerId: String, moduleId: String): IModuleIdentifier = + ModuleIdentifier(containerId, moduleId) + + fun newModuleIdentifier(identifier: String): IModuleIdentifier = + ModuleIdentifier(identifier) +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModule.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/annotations/CatalyxModule.kt similarity index 92% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModule.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/modules/annotations/CatalyxModule.kt index eabdfcc..3127e25 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/annotations/CatalyxModule.kt @@ -1,9 +1,9 @@ -package org.ender_development.catalyx.api.v1.annotations.module +package org.ender_development.catalyx.api.v1.modules.annotations import org.ender_development.catalyx.core.Reference /** - * All of your [org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule] + * All of your [org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule] * classes must be annotated with this to be registered. */ @Target(AnnotationTarget.CLASS) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModuleContainer.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/annotations/CatalyxModuleContainer.kt similarity index 86% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModuleContainer.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/modules/annotations/CatalyxModuleContainer.kt index dd32b2e..83e4e5e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/annotations/module/CatalyxModuleContainer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/annotations/CatalyxModuleContainer.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.annotations.module +package org.ender_development.catalyx.api.v1.modules.annotations /** * Annotate your Module Containers with this for it to be automatically registered. diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/ICatalyxModule.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/ICatalyxModule.kt similarity index 67% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/ICatalyxModule.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/ICatalyxModule.kt index e1c9fac..ce93122 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/interfaces/module/ICatalyxModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/ICatalyxModule.kt @@ -1,15 +1,15 @@ -package org.ender_development.catalyx.api.v1.interfaces.module +package org.ender_development.catalyx.api.v1.modules.interfaces import net.minecraftforge.fml.common.event.* import org.apache.logging.log4j.Logger -import org.ender_development.catalyx.api.v1.moduleManager +import org.ender_development.catalyx.api.v1.modules.Modules /** * All modules must implement this interface. * * Provides methods for responding to FML lifecycle events and adding event bus subscribers. * - * Note: If your Module is a kotlin `object`, and other parts of your code access it, + * Note: If your Module is a Kotlin `object`, and other parts of your code access it, * please don't have any side effects in the class initialisation/instantiation, * as any module can be disabled via the Catalyx config, or by its dependencies being unmet. */ @@ -23,37 +23,37 @@ interface ICatalyxModule { * A boolean indicating whether this module is enabled. */ val enabled: Boolean - get() = moduleManager.isModuleEnabled(this) + get() = Modules.moduleManager.isModuleEnabled(this) /** * Called when this module is loaded. */ - fun load() = Unit + fun load() {} /** * Called before each of the other callbacks, but after the mod itself receives the event */ - fun lifecycle(event: FMLStateEvent) = Unit + fun lifecycle(event: FMLStateEvent) {} - fun construction(event: FMLConstructionEvent) = Unit + fun construction(event: FMLConstructionEvent) {} - fun preInit(event: FMLPreInitializationEvent) = Unit + fun preInit(event: FMLPreInitializationEvent) {} - fun init(event: FMLInitializationEvent) = Unit + fun init(event: FMLInitializationEvent) {} - fun postInit(event: FMLPostInitializationEvent) = Unit + fun postInit(event: FMLPostInitializationEvent) {} - fun loadComplete(event: FMLLoadCompleteEvent) = Unit + fun loadComplete(event: FMLLoadCompleteEvent) {} - fun serverAboutToStart(event: FMLServerAboutToStartEvent) = Unit + fun serverAboutToStart(event: FMLServerAboutToStartEvent) {} - fun serverStarting(event: FMLServerStartingEvent) = Unit + fun serverStarting(event: FMLServerStartingEvent) {} - fun serverStarted(event: FMLServerStartedEvent) = Unit + fun serverStarted(event: FMLServerStartedEvent) {} - fun serverStopping(event: FMLServerStoppingEvent) = Unit + fun serverStopping(event: FMLServerStoppingEvent) {} - fun serverStopped(event: FMLServerStoppedEvent) = Unit + fun serverStopped(event: FMLServerStoppedEvent) {} /** * A list of classes to subscribe to the [Forge Event Bus][net.minecraftforge.common.MinecraftForge.EVENT_BUS]. diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt new file mode 100644 index 0000000..ac24a8b --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt @@ -0,0 +1,9 @@ +package org.ender_development.catalyx.api.v1.modules.interfaces + +/** + * An identifier thet identifies a module + */ +interface IModuleIdentifier { + val containerId: String + val moduleId: String +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleManager.kt new file mode 100644 index 0000000..d019075 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleManager.kt @@ -0,0 +1,38 @@ +package org.ender_development.catalyx.api.v1.modules.interfaces + +import org.ender_development.catalyx.api.v1.modules.Modules + +/** + * Interface for the actual [ModuleManager][org.ender_development.catalyx.core.module.ModuleManager] + * + * @see [org.ender_development.catalyx.api.v1.modules.moduleManager] + */ +interface IModuleManager { + /** + * Check if a module with the given [containerId] and [moduleId] is enabled + */ + fun isModuleEnabled(containerId: String, moduleId: String) = + isModuleEnabled(Modules.newModuleIdentifier(containerId, moduleId)) + + /** + * Check if a module with the given [identifier] is enabled + */ + fun isModuleEnabled(identifier: IModuleIdentifier): Boolean + + /** + * Checkup if a given module is enabled + */ + fun isModuleEnabled(module: ICatalyxModule): Boolean + + /** + * Registers a Module Container + */ + fun registerContainer(container: Any) + + /** + * The active Module Container instance, if any. + * + * Set during initialisation and lifecycle calls. + */ + val activeContainer: Any? +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt index f78125e..1993b7c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt @@ -1,13 +1,37 @@ package org.ender_development.catalyx.core.module -import net.minecraft.util.ResourceLocation -import org.ender_development.catalyx.api.v1.interfaces.module.IModuleIdentifier +import org.ender_development.catalyx.api.v1.modules.interfaces.IModuleIdentifier -data class ModuleIdentifier( - override val containerId: String, - override val moduleId: String): IModuleIdentifier { +class ModuleIdentifier : IModuleIdentifier { + override val containerId: String + override val moduleId: String - override fun asResourceLocation(): ResourceLocation - = ResourceLocation(containerId, moduleId) -} + constructor(containerId: String, moduleId: String) { + this.containerId = containerId + this.moduleId = moduleId + } + + /** + * Format: "containerId:moduleId" + */ + constructor(identifier: String) { + if(identifier.isBlank()) + error("Identifier is blank") + + val split = identifier.split(':') + if(split.size != 2) + error("Identifier does not follow the needed format of 'containerId:moduleId'") + + containerId = split[0] + moduleId = split[1] + } + override fun equals(other: Any?) = + this === other || (other is ModuleIdentifier && containerId == other.containerId && moduleId == other.moduleId) + + override fun hashCode() = + toString().hashCode() + + override fun toString() = + "$containerId:$moduleId" +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt index f4b4834..2a6377b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt @@ -3,7 +3,6 @@ package org.ender_development.catalyx.core.module import it.unimi.dsi.fastutil.objects.Object2ReferenceLinkedOpenHashMap import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet -import net.minecraft.util.ResourceLocation import net.minecraftforge.common.MinecraftForge import net.minecraftforge.common.config.Configuration import net.minecraftforge.fml.common.Loader @@ -12,12 +11,12 @@ import net.minecraftforge.fml.common.ModContainer import net.minecraftforge.fml.common.discovery.ASMDataTable import net.minecraftforge.fml.common.event.* import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule -import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModuleContainer -import org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule -import org.ender_development.catalyx.api.v1.interfaces.module.IModuleIdentifier -import org.ender_development.catalyx.api.v1.interfaces.module.IModuleManager -import org.ender_development.catalyx.api.v1.newModuleIdentifier +import org.ender_development.catalyx.api.v1.modules.Modules +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModuleContainer +import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule +import org.ender_development.catalyx.api.v1.modules.interfaces.IModuleIdentifier +import org.ender_development.catalyx.api.v1.modules.interfaces.IModuleManager import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.module.ModuleManager.configuration import org.ender_development.catalyx.core.module.ModuleManager.discoveredContainers @@ -76,7 +75,7 @@ object ModuleManager : IModuleManager { private val discoveredContainers = hashMapOf>() /** - * Discovers [ModuleContainers][org.ender_development.catalyx.api.v1.annotations.module.CatalyxModuleContainer] for registration after mod construction + * Discovers [ModuleContainers][CatalyxModuleContainer] for registration after mod construction * * @see [discoveredContainers] * @param asmDataTable the table containing the ModuleContainer data @@ -91,7 +90,7 @@ object ModuleManager : IModuleManager { private val discoveredModules = hashMapOf>() /** - * Discovers [Modules][org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule] for registration after their container gets registered + * Discovers [Modules][CatalyxModule] for registration after their container gets registered * * @see discoveredModules * @param asmDataTable the ASM Data Table containing the module data @@ -131,7 +130,7 @@ object ModuleManager : IModuleManager { val willLoadIds = ObjectLinkedOpenHashSet() val willLoadModules = ReferenceLinkedOpenHashSet() - toRegister.forEach { (containerId, modules) -> + toRegister.forEach { containerId, modules -> // Ensure core module exists and is first modules.indexOfFirst { it.annotation.coreModule }.let { idx -> if(idx == -1) @@ -265,32 +264,30 @@ object ModuleManager : IModuleManager { Catalyx.LOGGER.debug("> Module Container {}:{} instantiated ({})", modId, containerId, asmContainer.className) - var discoveredModules = discoveredModules.remove(containerId).orEmpty() - if(discoveredModules.isEmpty()) { + val discoveredModules = discoveredModules.remove(containerId) + if(discoveredModules.isNullOrEmpty()) { Catalyx.LOGGER.warn("> Module Container {}:{} has no modules", modId, containerId) return@forEach } - // Check module ids before instantiating modules + // Check module dependencies before instantiating val willInstantiate = mutableListOf() val willInstantiateIds = mutableListOf() do { - var changed = false - discoveredModules = discoveredModules.filter { module -> - val moduleId = newModuleIdentifier(module.annotationInfo["containerId"] as String, module.annotationInfo["moduleId"] as String) + val changed = discoveredModules.removeIf { module -> + val moduleId = Modules.newModuleIdentifier(module.annotationInfo["containerId"] as String, module.annotationInfo["moduleId"] as String) val unmetDependencies = (module.annotationInfo["moduleDependencies"] as List<*>? ?: emptyList()) .filterIsInstance() - .map(ResourceLocation::splitObjectName) - .map{ newModuleIdentifier(it[0], it[1]) } + .map(Modules::newModuleIdentifier) .filterNot { willInstantiateIds.contains(it) || loadedModuleIds.contains(it) } - return@filter if(unmetDependencies.isEmpty()) { - changed = true + if(unmetDependencies.isEmpty()) { willInstantiate.add(module) willInstantiateIds.add(moduleId) + true + } else false - } else true - }.toMutableList() + } } while(changed) Catalyx.LOGGER.debug("> Module Container {}:{} has {} dependent modules, but will be instantiating {} of them", modId, containerId, willInstantiate.size + discoveredModules.size, willInstantiate.size) diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt index bc71beb..facffc2 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt @@ -7,8 +7,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule -import org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule +import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.client.AreaHighlighter import org.ender_development.catalyx.core.utils.extensions.subLogger diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt index 77d7b94..0456c3a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt @@ -1,6 +1,6 @@ package org.ender_development.catalyx.modules -import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModuleContainer +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModuleContainer import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.Mods diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxModuleBase.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxModuleBase.kt index d18c89d..69fc0ab 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxModuleBase.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxModuleBase.kt @@ -2,7 +2,7 @@ package org.ender_development.catalyx.modules import org.apache.logging.log4j.Logger import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule +import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule /** * Abstract base class for all builtin Catalyx modules diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt index c6c3636..9443e3e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt @@ -1,6 +1,6 @@ package org.ender_development.catalyx.modules.integration -import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt index 31a2609..4605d94 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt @@ -4,7 +4,7 @@ import com.cleanroommc.groovyscript.GroovyScript import com.cleanroommc.groovyscript.api.GroovyPlugin import com.cleanroommc.groovyscript.compat.mods.GroovyContainer import net.minecraftforge.fml.common.Optional -import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.module.ModuleManager import org.ender_development.catalyx.core.utils.Mods diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt index b0a015b..45e3f63 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt @@ -2,7 +2,7 @@ package org.ender_development.catalyx.modules.integration.top import mcjty.theoneprobe.TheOneProbe import net.minecraftforge.fml.common.event.FMLInitializationEvent -import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.Mods import org.ender_development.catalyx.core.utils.extensions.subLogger diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt index a04f782..3b68e73 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt @@ -1,8 +1,8 @@ package org.ender_development.catalyx.modules.internal import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule -import org.ender_development.catalyx.api.v1.interfaces.module.ICatalyxModule +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule +import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.items.CopyPasteTool import org.ender_development.catalyx.core.utils.extensions.subLogger diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt index c24628e..ac05307 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt @@ -5,7 +5,7 @@ import net.minecraft.util.text.TextComponentString import net.minecraftforge.client.event.ClientChatEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.annotations.module.CatalyxModule +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.blocks.IOTileBlock import org.ender_development.catalyx.core.blocks.multiblock.CenterBlock From d4110783b3d2d8495966fa1d8932b52fdaf1f4ef Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Tue, 13 Jan 2026 19:57:14 +0100 Subject: [PATCH 06/58] language changes --- .../org/ender_development/catalyx/api/v1/modules/Modules.kt | 6 ++++-- .../catalyx/core/module/ModuleIdentifier.kt | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt index ac46e75..5b5555e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt @@ -17,12 +17,14 @@ object Modules { val moduleManager: IModuleManager = ModuleManager /** - * Factories for [IModuleIdentifier] - * currently implemented by [ModuleIdentifier] + * Factory for [IModuleManager], currently implemented by [ModuleIdentifier] */ fun newModuleIdentifier(containerId: String, moduleId: String): IModuleIdentifier = ModuleIdentifier(containerId, moduleId) + /** + * Factory for [IModuleManager], currently implemented by [ModuleIdentifier] + */ fun newModuleIdentifier(identifier: String): IModuleIdentifier = ModuleIdentifier(identifier) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt index 1993b7c..b35e220 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt @@ -20,7 +20,7 @@ class ModuleIdentifier : IModuleIdentifier { val split = identifier.split(':') if(split.size != 2) - error("Identifier does not follow the needed format of 'containerId:moduleId'") + error("Identifier does not follow the required format of 'containerId:moduleId'") containerId = split[0] moduleId = split[1] From 34fea663f6bc2110f942f836c75bdfe823700b41 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Tue, 13 Jan 2026 20:24:16 +0100 Subject: [PATCH 07/58] IModuleIdentifier#toResourceLocation --- .../api/v1/modules/interfaces/IModuleIdentifier.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt index ac24a8b..616ac83 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt @@ -1,9 +1,17 @@ package org.ender_development.catalyx.api.v1.modules.interfaces +import net.minecraft.util.ResourceLocation + /** * An identifier thet identifies a module */ interface IModuleIdentifier { val containerId: String val moduleId: String + + /** + * Convert this to a [ResourceLocation], for whatever reason. + */ + fun toResourceLocation() = + ResourceLocation(containerId, moduleId) } From 3f7ae8c2df4d43bbfc02f88ca67f51da4adc8db8 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Tue, 13 Jan 2026 20:48:21 +0100 Subject: [PATCH 08/58] sounds reasonable --- .../catalyx/api/v1/modules/Modules.kt | 12 +++++-- .../catalyx/core/module/ModuleIdentifier.kt | 31 +------------------ 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt index 5b5555e..7a48b73 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt @@ -25,6 +25,14 @@ object Modules { /** * Factory for [IModuleManager], currently implemented by [ModuleIdentifier] */ - fun newModuleIdentifier(identifier: String): IModuleIdentifier = - ModuleIdentifier(identifier) + fun newModuleIdentifier(identifier: String): IModuleIdentifier { + if(identifier.isBlank()) + error("Identifier is blank") + + val split = identifier.split(':') + if(split.size != 2) + error("Identifier does not follow the required format of 'containerId:moduleId'") + + return ModuleIdentifier(split[0], split[1]) + } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt index b35e220..a566589 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleIdentifier.kt @@ -2,36 +2,7 @@ package org.ender_development.catalyx.core.module import org.ender_development.catalyx.api.v1.modules.interfaces.IModuleIdentifier -class ModuleIdentifier : IModuleIdentifier { - override val containerId: String - override val moduleId: String - - constructor(containerId: String, moduleId: String) { - this.containerId = containerId - this.moduleId = moduleId - } - - /** - * Format: "containerId:moduleId" - */ - constructor(identifier: String) { - if(identifier.isBlank()) - error("Identifier is blank") - - val split = identifier.split(':') - if(split.size != 2) - error("Identifier does not follow the required format of 'containerId:moduleId'") - - containerId = split[0] - moduleId = split[1] - } - - override fun equals(other: Any?) = - this === other || (other is ModuleIdentifier && containerId == other.containerId && moduleId == other.moduleId) - - override fun hashCode() = - toString().hashCode() - +data class ModuleIdentifier(override val containerId: String, override val moduleId: String) : IModuleIdentifier { override fun toString() = "$containerId:$moduleId" } From 24a5c5f169b165b270ca371219c22f7e2e6113cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Wed, 14 Jan 2026 18:14:51 +0100 Subject: [PATCH 09/58] try to make me friends lul --- .../api/v1/modules/interfaces/IModuleIdentifier.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt index 616ac83..4475c90 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt @@ -15,3 +15,13 @@ interface IModuleIdentifier { fun toResourceLocation() = ResourceLocation(containerId, moduleId) } + +/* +// TODO: Discuss that the flowing cloud be a batter solution, that cold replace the ModuleIdentifier BS: +typealias ModuleIdentifier = ResourceLocation +inline val ModuleIdentifier.containerId: String? + get() = this.namespace + +inline val ModuleIdentifier.moduleId: String? + get() = this.path +*/ From 5c5b5e003787981559980c6a5945283a951363fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Wed, 14 Jan 2026 19:21:55 +0100 Subject: [PATCH 10/58] refactor the regitry code as far as I understood it --- .../v1/registry/ICatalyxProviderRegistry.kt | 25 +++++++++++++++ .../v1}/registry/ICatalyxRegistry.kt | 11 +++++-- .../{core => api/v1}/registry/IProvider.kt | 7 +++-- .../catalyx/api/v1/registry/Registry.kt | 31 +++++++++++++++++++ .../catalyx/core/ICatalyxMod.kt | 4 +-- .../catalyx/core/blocks/BaseBlock.kt | 2 +- .../catalyx/core/items/BaseItem.kt | 2 +- .../core/registry/CatalyxBlockRegistry.kt | 4 ++- .../core/registry/CatalyxItemRegistry.kt | 4 ++- ...Registry.kt => CatalyxProviderRegistry.kt} | 23 +++++++++----- 10 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxProviderRegistry.kt rename src/main/kotlin/org/ender_development/catalyx/{core => api/v1}/registry/ICatalyxRegistry.kt (53%) rename src/main/kotlin/org/ender_development/catalyx/{core => api/v1}/registry/IProvider.kt (81%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/registry/Registry.kt rename src/main/kotlin/org/ender_development/catalyx/core/registry/{CatalyxRegistry.kt => CatalyxProviderRegistry.kt} (52%) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxProviderRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxProviderRegistry.kt new file mode 100644 index 0000000..9d88c44 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxProviderRegistry.kt @@ -0,0 +1,25 @@ +package org.ender_development.catalyx.api.v1.registry + +import net.minecraft.util.ResourceLocation + +interface ICatalyxProviderRegistry> : Map> { + + /** + * Adds a provider to this collection + * + * @return true if success + */ + fun add(provider: V): Boolean + + /** + * List of all enabled providers + */ + val enabled: List + get() = values.filter { it.second }.map { it.first } + + /** + * The lingual suffix of the plural + */ + val plural: String + get() = if(enabled.size == 1) "" else "s" // WTF +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/ICatalyxRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxRegistry.kt similarity index 53% rename from src/main/kotlin/org/ender_development/catalyx/core/registry/ICatalyxRegistry.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxRegistry.kt index 73c06f3..0710bc2 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/ICatalyxRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxRegistry.kt @@ -1,13 +1,20 @@ -package org.ender_development.catalyx.core.registry +package org.ender_development.catalyx.api.v1.registry import net.minecraftforge.event.RegistryEvent import net.minecraftforge.registries.IForgeRegistryEntry +import org.ender_development.catalyx.core.registry.CatalyxProviderRegistry +/** + * A hook for a [CatalyxProviderRegistry] that lets register their content + * + * @param E the corresponding [IForgeRegistryEntry] + * @param P the [IProvider] type + */ interface ICatalyxRegistry, P : IProvider> { /** * The set of providers to be registered. */ - val registry: CatalyxRegistry

+ val registry: CatalyxProviderRegistry

/** * Register all enabled providers with the given event. diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/IProvider.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt similarity index 81% rename from src/main/kotlin/org/ender_development/catalyx/core/registry/IProvider.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt index 91adc13..44c31ce 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/IProvider.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.registry +package org.ender_development.catalyx.api.v1.registry import net.minecraft.block.Block import net.minecraft.item.Item @@ -18,9 +18,12 @@ interface IProvider> { * The mod ID(s) required for this provider to be enabled, separated by semicolons. Prefixes of "!" can be used to indicate that a mod must NOT be present. * * Default is an empty string, meaning no dependencies. + * + * @see [org.ender_development.catalyx.core.registry.CatalyxProviderRegistry.evaluateModDependencies] */ - var modDependencies: String + var modDependencies: String // TODO: shouldn't it be a list or HashMap(mod, mod-must-NOT-be-present) or something? + // cold not open this link ↴ so why? ~Klebi // Note to self: do not make this a `val` as we wanna enforce a getter here (https://discord.com/channels/@me/1232745201009819749/1423296686691717220) /** * Whether this provider is enabled and should be registered. diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/Registry.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/Registry.kt new file mode 100644 index 0000000..52b5355 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/Registry.kt @@ -0,0 +1,31 @@ +package org.ender_development.catalyx.api.v1.registry + +import net.minecraft.block.Block +import net.minecraft.item.Item +import org.ender_development.catalyx.core.registry.CatalyxBlockRegistry +import org.ender_development.catalyx.core.registry.CatalyxItemRegistry +import org.ender_development.catalyx.core.registry.CatalyxProviderRegistry + +/** + * API-Status: NOT-FROZEN + * Be aware + */ + + +object Registry { + /** + * Factory for a new [CatalyxProviderRegistry] + */ + fun > newCatalyxProviderRegistry(): ICatalyxProviderRegistry + = CatalyxProviderRegistry() + + /** + * Contains the Catalyx implementation of the [ICatalyxRegistry] for [Item] + */ + val catalyxItemRegistry: ICatalyxRegistry = CatalyxItemRegistry + + /** + * Contains the Catalyx implementation of the [ICatalyxRegistry] for [Block] + */ + val catalyxBlockRegistry: ICatalyxRegistry = CatalyxBlockRegistry +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt b/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt index c06d6ad..ed8d802 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt @@ -2,10 +2,10 @@ package org.ender_development.catalyx.core import net.minecraft.creativetab.CreativeTabs import net.minecraftforge.fml.common.Mod +import org.ender_development.catalyx.api.v1.registry.IBlockProvider +import org.ender_development.catalyx.api.v1.registry.IItemProvider import org.ender_development.catalyx.core.registry.CatalyxBlockRegistry import org.ender_development.catalyx.core.registry.CatalyxItemRegistry -import org.ender_development.catalyx.core.registry.IBlockProvider -import org.ender_development.catalyx.core.registry.IItemProvider interface ICatalyxMod { companion object { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt index ccbb5fa..9c5f4be 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt @@ -14,9 +14,9 @@ import net.minecraft.util.math.BlockPos import net.minecraft.world.IBlockAccess import net.minecraftforge.client.model.ModelLoader import net.minecraftforge.event.RegistryEvent +import org.ender_development.catalyx.api.v1.registry.IBlockProvider import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.register -import org.ender_development.catalyx.core.registry.IBlockProvider import org.ender_development.catalyx.core.utils.SideUtils /** diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt index bdbf632..cd8ab95 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt @@ -5,9 +5,9 @@ import net.minecraft.item.Item import net.minecraft.util.ResourceLocation import net.minecraftforge.client.model.ModelLoader import net.minecraftforge.event.RegistryEvent +import org.ender_development.catalyx.api.v1.registry.IItemProvider import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.register -import org.ender_development.catalyx.core.registry.IItemProvider import org.ender_development.catalyx.core.utils.SideUtils /** diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt index 71ad83b..5bb5ccf 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt @@ -6,13 +6,15 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.registry.IBlockProvider +import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.DevUtils @Suppress("unused") @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxBlockRegistry : ICatalyxRegistry { - override val registry = CatalyxRegistry() + override val registry = CatalyxProviderRegistry() @SubscribeEvent override fun register(event: RegistryEvent.Register) { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt index 2dbab09..44991c0 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt @@ -5,13 +5,15 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry +import org.ender_development.catalyx.api.v1.registry.IItemProvider import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.DevUtils @Suppress("unused") @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxItemRegistry : ICatalyxRegistry { - override val registry = CatalyxRegistry() + override val registry = CatalyxProviderRegistry() @SubscribeEvent override fun register(event: RegistryEvent.Register) { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt similarity index 52% rename from src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxRegistry.kt rename to src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt index fb3ffda..7c60d6e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt @@ -1,23 +1,30 @@ package org.ender_development.catalyx.core.registry import net.minecraft.util.ResourceLocation +import org.ender_development.catalyx.api.v1.registry.ICatalyxProviderRegistry +import org.ender_development.catalyx.api.v1.registry.IProvider import org.ender_development.catalyx.core.utils.extensions.modLoaded -class CatalyxRegistry> : HashMap>() { - fun add(provider: V): Boolean = +/** + * Collection of all [IProvider] of a given type + * + * @param V the Type of the Provider for the things that should be managed here + */ +class CatalyxProviderRegistry> : + HashMap>(), + ICatalyxProviderRegistry { + + override fun add(provider: V): Boolean = provider.instance.registryName?.let { this[it] = provider to (provider.isEnabled() && provider.modDependencies.evaluateModDependencies()) true } ?: false - val enabled: List - get() = values.filter { it.second }.map { it.first } - - val plural - get() = if(enabled.size == 1) "" else "s" - /** * Special expansion to evaluate modDependencies strings. + * + * @return true if valid + * @see [IProvider.modDependencies] */ fun String.evaluateModDependencies(): Boolean = isEmpty() || split(',', ';').all { From 32a48fe5576315daa18d97a38f7ed7502ecb9e1a Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Wed, 14 Jan 2026 20:30:48 +0100 Subject: [PATCH 11/58] more sillyness --- .../org/ender_development/catalyx/Catalyx.kt | 5 ----- .../catalyx/api/v1/modules/Modules.kt | 2 +- .../v1/modules/interfaces/IModuleIdentifier.kt | 8 +++++--- .../api/v1/registry/ICatalyxProviderRegistry.kt | 13 +++---------- .../catalyx/api/v1/registry/IProvider.kt | 16 +++++++--------- .../catalyx/api/v1/registry/Registry.kt | 6 +++--- .../catalyx/core/blocks/BaseBlock.kt | 7 ++++--- .../catalyx/core/items/BaseItem.kt | 5 +++-- .../catalyx/core/recipes/RecipeBuilder.kt | 7 +++---- .../core/registry/CatalyxBlockRegistry.kt | 5 +++-- .../core/registry/CatalyxItemRegistry.kt | 3 ++- .../core/registry/CatalyxProviderRegistry.kt | 17 +++++------------ .../catalyx/core/utils/extensions/Int.kt | 4 ++++ .../catalyx/modules/CatalyxCoreModule.kt | 6 ++++++ 14 files changed, 49 insertions(+), 55 deletions(-) create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Int.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt b/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt index ea64be0..c616258 100644 --- a/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt +++ b/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt @@ -41,9 +41,4 @@ object Catalyx : ICatalyxMod { fun construction(e: FMLConstructionEvent) { ModuleManager.setup(e.asmHarvestedData) } - - @Mod.EventHandler - fun preInit(e: FMLPreInitializationEvent) { - PacketHandler.init() - } } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt index 7a48b73..65731d1 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/Modules.kt @@ -2,7 +2,7 @@ package org.ender_development.catalyx.api.v1.modules /** * API-Status: NOT-FROZEN - * Be aware + * Beware */ import org.ender_development.catalyx.api.v1.modules.interfaces.IModuleIdentifier diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt index 4475c90..85190df 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt @@ -17,11 +17,13 @@ interface IModuleIdentifier { } /* -// TODO: Discuss that the flowing cloud be a batter solution, that cold replace the ModuleIdentifier BS: +// TODO: Discuss whether the following woule be better than the current ModuleIdentifier bs typealias ModuleIdentifier = ResourceLocation -inline val ModuleIdentifier.containerId: String? +inline val ModuleIdentifier.containerId: String get() = this.namespace -inline val ModuleIdentifier.moduleId: String? +inline val ModuleIdentifier.moduleId: String get() = this.path + +// roz: nah ;p */ diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxProviderRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxProviderRegistry.kt index 9d88c44..5a6157d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxProviderRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxProviderRegistry.kt @@ -2,12 +2,11 @@ package org.ender_development.catalyx.api.v1.registry import net.minecraft.util.ResourceLocation -interface ICatalyxProviderRegistry> : Map> { - +interface ICatalyxProviderRegistry> : Map> { /** * Adds a provider to this collection * - * @return true if success + * @return true, unless something stupid happened */ fun add(provider: V): Boolean @@ -15,11 +14,5 @@ interface ICatalyxProviderRegistry> : Map - get() = values.filter { it.second }.map { it.first } - - /** - * The lingual suffix of the plural - */ - val plural: String - get() = if(enabled.size == 1) "" else "s" // WTF + get() = values.mapNotNull { (provider, enabled) -> provider.takeIf { enabled } } } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt index 44c31ce..d0d934a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt @@ -15,16 +15,15 @@ interface IProvider> { val instance: T /** - * The mod ID(s) required for this provider to be enabled, separated by semicolons. Prefixes of "!" can be used to indicate that a mod must NOT be present. + * The mod ID(s) required for this provider to be enabled. Prefixes of "!" can be used to indicate that a mod must NOT be present. * - * Default is an empty string, meaning no dependencies. + * Default is an empty list, meaning no dependencies. * * @see [org.ender_development.catalyx.core.registry.CatalyxProviderRegistry.evaluateModDependencies] */ - var modDependencies: String // TODO: shouldn't it be a list or HashMap(mod, mod-must-NOT-be-present) or something? + val modDependencies: Iterable - // cold not open this link ↴ so why? ~Klebi - // Note to self: do not make this a `val` as we wanna enforce a getter here (https://discord.com/channels/@me/1232745201009819749/1423296686691717220) + // Note: do not make this a `val` as we wanna enforce a getter here /** * Whether this provider is enabled and should be registered. */ @@ -38,12 +37,11 @@ interface IProvider> { fun register(event: RegistryEvent.Register) /** - * Specify that this provider requires the given mod dependency to be present. + * Specify that this provider requires the given mod dependencies to be present. * - * @param modDependencies The mod ID(s) required, separated by semicolons. Prefixes of "!" can be used to indicate that a mod must NOT be present. - * @return This instance, for chaining. + * @see IProvider.modDependencies for format */ - fun requires(modDependencies: String): T + fun requires(modDependencies: Iterable): T } interface IItemProvider : IProvider diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/Registry.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/Registry.kt index 52b5355..1ddc22e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/Registry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/Registry.kt @@ -8,7 +8,7 @@ import org.ender_development.catalyx.core.registry.CatalyxProviderRegistry /** * API-Status: NOT-FROZEN - * Be aware + * Beware */ @@ -16,8 +16,8 @@ object Registry { /** * Factory for a new [CatalyxProviderRegistry] */ - fun > newCatalyxProviderRegistry(): ICatalyxProviderRegistry - = CatalyxProviderRegistry() + fun > newCatalyxProviderRegistry(): ICatalyxProviderRegistry = + CatalyxProviderRegistry() /** * Contains the Catalyx implementation of the [ICatalyxRegistry] for [Item] diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt index 9c5f4be..73155db 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt @@ -36,7 +36,8 @@ open class BaseBlock(val mod: ICatalyxMod, name: String, material: Material = Ma override val instance = this - override var modDependencies = "" + final override var modDependencies: Iterable = emptyList() + private set override val item = ItemBlock(this) @@ -53,14 +54,14 @@ open class BaseBlock(val mod: ICatalyxMod, name: String, material: Material = Ma ModelLoader.setCustomModelResourceLocation(item, 0, ModelResourceLocation(registryName!!, "inventory")) } - override fun requires(modDependencies: String): Block { + override fun requires(modDependencies: Iterable): Block { this.modDependencies = modDependencies mod.register(this) return this } init { - // TODO: why do we have 2 init blocks? + // TODO: why do we have 2 init blocks? => so you ask questions /j; nah actually, just because of initialisation order, this made more sense mod.register(this) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt index cd8ab95..a07680f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt @@ -25,9 +25,10 @@ open class BaseItem(val mod: ICatalyxMod, val name: String) : Item(), IItemProvi override fun isEnabled() = true - override var modDependencies = "" + final override var modDependencies: Iterable = emptyList() + private set - override fun requires(modDependencies: String): Item { + override fun requires(modDependencies: Iterable): Item { this.modDependencies = modDependencies mod.register(this) return this diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt index fc46b0c..fe352ff 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt @@ -13,6 +13,7 @@ import org.ender_development.catalyx.core.recipes.validation.Result import org.ender_development.catalyx.core.recipes.validation.ValidationState import org.ender_development.catalyx.core.recipes.validation.Validator import org.ender_development.catalyx.core.utils.Mods +import org.ender_development.catalyx.core.utils.extensions.plural import org.ender_development.catalyx.modules.integration.groovyscript.ModuleGroovyScript import java.util.function.Supplier @@ -21,10 +22,8 @@ class RecipeBuilder> { fun getRequiredString(max: Int, found: Int, type: String): String { if(max <= 0) return "No ${type}s allowed, but found $found" - var out = "Must have at most $max $type" - if(max != 1) - out += "s" - return "$out, but found $found" + + return "Must have at most $max $type${max.plural}, but found $found" } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt index 5bb5ccf..2ec6de0 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt @@ -10,6 +10,7 @@ import org.ender_development.catalyx.api.v1.registry.IBlockProvider import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.DevUtils +import org.ender_development.catalyx.core.utils.extensions.plural @Suppress("unused") @Mod.EventBusSubscriber(modid = Reference.MODID) @@ -18,7 +19,7 @@ object CatalyxBlockRegistry : ICatalyxRegistry { @SubscribeEvent override fun register(event: RegistryEvent.Register) { - Catalyx.LOGGER.debug("Block Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} block${registry.plural}") + Catalyx.LOGGER.debug("Block Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} block${registry.size.plural}") registry.enabled.forEach { it.register(event) if(DevUtils.isDeobfuscated) @@ -28,7 +29,7 @@ object CatalyxBlockRegistry : ICatalyxRegistry { @SubscribeEvent fun registerItemBlocks(event: RegistryEvent.Register) { - Catalyx.LOGGER.debug("Item Block Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} block item${registry.plural}") + Catalyx.LOGGER.debug("Item Block Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} block item${registry.size.plural}") registry.enabled.forEach { it.registerItemBlock(event) if(DevUtils.isDeobfuscated) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt index 44991c0..a8fa759 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt @@ -9,6 +9,7 @@ import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.api.v1.registry.IItemProvider import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.DevUtils +import org.ender_development.catalyx.core.utils.extensions.plural @Suppress("unused") @Mod.EventBusSubscriber(modid = Reference.MODID) @@ -17,7 +18,7 @@ object CatalyxItemRegistry : ICatalyxRegistry { @SubscribeEvent override fun register(event: RegistryEvent.Register) { - Catalyx.LOGGER.debug("Item Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} item${registry.plural}") + Catalyx.LOGGER.debug("Item Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} item${registry.size.plural}") registry.enabled.forEach { it.register(event) if(DevUtils.isDeobfuscated) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt index 7c60d6e..d2258ae 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt @@ -10,10 +10,7 @@ import org.ender_development.catalyx.core.utils.extensions.modLoaded * * @param V the Type of the Provider for the things that should be managed here */ -class CatalyxProviderRegistry> : - HashMap>(), - ICatalyxProviderRegistry { - +class CatalyxProviderRegistry> : HashMap>(), ICatalyxProviderRegistry { override fun add(provider: V): Boolean = provider.instance.registryName?.let { this[it] = provider to (provider.isEnabled() && provider.modDependencies.evaluateModDependencies()) @@ -21,16 +18,12 @@ class CatalyxProviderRegistry> : } ?: false /** - * Special expansion to evaluate modDependencies strings. + * Special helper to evaluate modDependencies strings. * - * @return true if valid * @see [IProvider.modDependencies] */ - fun String.evaluateModDependencies(): Boolean = - isEmpty() || split(',', ';').all { - if(it[0] == '!') - !it.substring(1).modLoaded() - else - it.modLoaded() + fun Iterable.evaluateModDependencies() = + all { + it.removePrefix("!").modLoaded() != it.startsWith('!') } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Int.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Int.kt new file mode 100644 index 0000000..1590241 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Int.kt @@ -0,0 +1,4 @@ +package org.ender_development.catalyx.core.utils.extensions + +val Int.plural + inline get() = if(this == 1) "" else "s" diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt index facffc2..7d45a37 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt @@ -1,6 +1,7 @@ package org.ender_development.catalyx.modules import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent import net.minecraftforge.fml.common.event.FMLServerStoppedEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -11,6 +12,7 @@ import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.client.AreaHighlighter +import org.ender_development.catalyx.core.network.PacketHandler import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.core.utils.persistence.WorldPersistentData @@ -26,6 +28,10 @@ internal class CatalyxCoreModule : ICatalyxModule { override val eventBusSubscribers = listOf(this) + override fun preInit(event: FMLPreInitializationEvent) { + PacketHandler.init() + } + override fun serverAboutToStart(event: FMLServerAboutToStartEvent) = WorldPersistentData.instances.forEach(WorldPersistentData::worldJoined) From 0add07a865be2a8a92d74c4a472900fcf0b9e081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Thu, 15 Jan 2026 12:34:09 +0100 Subject: [PATCH 12/58] Reimplement some Recipe code less "sIlLy" lol --- .../catalyx/core/recipes/Recipe.kt | 55 +++++++++++-------- .../recipes/ingredients/RecipeInputCache.kt | 2 +- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt index 8031b37..6313d60 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt @@ -16,7 +16,7 @@ import org.ender_development.catalyx.core.utils.IItemStackHash import org.ender_development.catalyx.core.utils.extensions.copyOf import org.ender_development.catalyx.modules.integration.groovyscript.ModuleGroovyScript -class Recipe( +class Recipe ( inputs: List, val outputs: List, val chancedOutputs: ChancedOutputList, @@ -30,7 +30,11 @@ class Recipe( ) { val inputs = RecipeInputCache.deduplicateInputs(inputs) val fluidInputs = RecipeInputCache.deduplicateInputs(fluidInputs) - val hashCode = makeHashCode() + val hashCode = let{ + var hash = 31 * this.inputs.hashItemList() + hash = 31 * hash + this.fluidInputs.hashFluidList() + hash + } val groovyRecipe = ModuleGroovyScript.isRunning companion object { @@ -61,28 +65,41 @@ class Recipe( return currentRecipe } - fun hashFluidList(fluidList: List): Int { - var hash = 1 - fluidList.forEach { - hash = 31 * hash + it.hashCode() - } - return hash + fun List.hashFluidList() = this.fold(1) { hash, it -> + 31 * hash + it.hashCode() } - fun hashItemList(itemList: List): Int { - var hash = 1 - itemList.forEach { - when { - !it.isOreDict() -> it.getInputStacks()?.forEach { stack -> hash = 31 * hash + IItemStackHash.comparingAll.hashCode(stack) } - else -> hash = 31 * hash + it.getOreDict() + fun List.hashItemList() = this.fold(1) { hash, it -> + return if (!it.isOreDict()) { + it.getInputStacks().orEmpty().fold(hash) { hash, stack -> + 31 * hash + IItemStackHash.comparingAll.hashCode(stack) } + } else { + 31 * hash + it.getOreDict() } - return hash } } + /** + * Copy constructor + * + * @param other the object to copy data from + */ + constructor(other: Recipe) : this( + other.inputs, + other.outputs, + other.chancedOutputs, + other.fluidInputs, + other.fluidOutputs, + other.chancedFluidOutputs, + other.duration, + other.energyPerTick, + other.hidden, + other.recipeCategory + ) + fun copy() = - Recipe(inputs, outputs, chancedOutputs, fluidInputs, fluidOutputs, chancedFluidOutputs, duration, energyPerTick, hidden, recipeCategory) + Recipe(this) override fun equals(other: Any?) = this === other || (other is Recipe && hasSameInputs(other) && hasSameFluidInputs(other)) @@ -93,12 +110,6 @@ class Recipe( override fun hashCode() = hashCode - private fun makeHashCode(): Int { - var hash = 31 * hashItemList(inputs) - hash = 31 * hash + hashFluidList(fluidInputs) - return hash - } - private fun hasSameInputs(other: Recipe): Boolean { val otherStackList = ObjectArrayList(other.inputs.size) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/RecipeInputCache.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/RecipeInputCache.kt index 362e536..28db14f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/RecipeInputCache.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/RecipeInputCache.kt @@ -80,7 +80,7 @@ object RecipeInputCache { if(inputs.isEmpty()) return inputs - return inputs.map { deduplicate(it) } + return inputs.map(::deduplicate) } /** From 98754651669749e0b772848cdd9a0751990f7fef Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Thu, 15 Jan 2026 16:24:11 +0100 Subject: [PATCH 13/58] idk tasty recipes or something --- .../catalyx/core/recipes/Recipe.kt | 29 +++++++++---------- .../catalyx/core/recipes/RecipeBuilder.kt | 12 ++++---- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt index 6313d60..88f0629 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt @@ -30,11 +30,7 @@ class Recipe ( ) { val inputs = RecipeInputCache.deduplicateInputs(inputs) val fluidInputs = RecipeInputCache.deduplicateInputs(fluidInputs) - val hashCode = let{ - var hash = 31 * this.inputs.hashItemList() - hash = 31 * hash + this.fluidInputs.hashFluidList() - hash - } + private val hashCode = 31 * this.inputs.hashItemList() + this.fluidInputs.hashFluidList() val groovyRecipe = ModuleGroovyScript.isRunning companion object { @@ -65,19 +61,20 @@ class Recipe ( return currentRecipe } - fun List.hashFluidList() = this.fold(1) { hash, it -> - 31 * hash + it.hashCode() - } + private fun List.hashFluidList() = + fold(0) { hash, it -> + 31 * hash + it.hashCode() + } - fun List.hashItemList() = this.fold(1) { hash, it -> - return if (!it.isOreDict()) { - it.getInputStacks().orEmpty().fold(hash) { hash, stack -> - 31 * hash + IItemStackHash.comparingAll.hashCode(stack) - } - } else { - 31 * hash + it.getOreDict() + private fun List.hashItemList() = + fold(0) { hash, it -> + if(it.isOreDict()) + 31 * hash + it.getOreDict() + else + it.getInputStacks().orEmpty().fold(hash) { hash, stack -> + 31 * hash + IItemStackHash.comparingAll.hashCode(stack) + } } - } } /** diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt index fe352ff..ec1c84b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt @@ -48,12 +48,12 @@ class RecipeBuilder> { var recipeStatus: ValidationState = ValidationState.VALID private constructor() { - this.inputs = ArrayList() - this.outputs = ArrayList() - this.chancedOutputs = ArrayList() - this.fluidInputs = ArrayList() - this.fluidOutputs = ArrayList() - this.chancedFluidOutputs = ArrayList() + this.inputs = mutableListOf() + this.outputs = mutableListOf() + this.chancedOutputs = mutableListOf() + this.fluidInputs = mutableListOf() + this.fluidOutputs = mutableListOf() + this.chancedFluidOutputs = mutableListOf() } constructor(recipe: Recipe, recipeMap: RecipeMap) { From 464c3d83de3566f414d65fe8f64c012a09ba5782 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Thu, 15 Jan 2026 16:42:29 +0100 Subject: [PATCH 14/58] add another list util, as well as do a general extension code pass --- .../catalyx/core/utils/extensions/BlockPos.kt | 2 +- .../core/utils/extensions/IItemHandler.kt | 40 ++++++++++--------- .../catalyx/core/utils/extensions/List.kt | 17 ++++++-- .../catalyx/core/utils/extensions/String.kt | 2 +- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt index d8e312e..0ff5cde 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt @@ -35,7 +35,7 @@ inline fun BlockPos.getFacingFromEntity(entity: Entity): EnumFacing = getFacingFromEntityPosition(entity.posX.toFloat(), entity.posZ.toFloat()) /** - * @see org.ender_development.catalyx.blocks.multiblock.parts.AbstractEdgeBlock + * @see org.ender_development.catalyx.core.blocks.multiblock.parts.AbstractEdgeBlock */ fun BlockPos.getHorizontalSurroundings() = arrayOf( north().west(), north(), north().east(), diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/IItemHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/IItemHandler.kt index a0b78db..3b7d916 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/IItemHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/IItemHandler.kt @@ -9,36 +9,40 @@ operator fun IItemHandler.get(idx: Int) = fun IItemHandler.tryInsertInto(otherHandler: IItemHandler): Boolean { for(i in 0.. { - return (0.. List.validateEach(validator: (idx: Int, T) -> ValidationResult) = mapIndexed(validator) @JvmName("copyOfIS") -fun List.copyOf() = +inline fun List.copyOf() = map { if(it.isEmpty) ItemStack.EMPTY @@ -30,8 +32,8 @@ fun List.copyOf() = } @JvmName("copyOfFS") -fun List.copyOf() = - map { it.copy() } +inline fun List.copyOf() = + map(FluidStack::copy) inline fun List.mapUnique(transform: (T) -> R) = mapTo(hashSetOf(), transform) @@ -41,3 +43,12 @@ fun List.getBySeverity(severity: ValidationError.Severity) = fun List.getByMinSeverity(severity: ValidationError.Severity) = filter { it.severity >= severity } + +/** + * Get the specified [index][idx] in the list and apply the [mapper] function, or return the [default] + */ +inline fun List.getApplyOrDefault(idx: Int, crossinline mapper: (T) -> R, crossinline default: () -> R) = + if(idx in indices) + mapper(this[idx]) + else + default() diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/String.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/String.kt index eb7d9e7..477687d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/String.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/String.kt @@ -22,7 +22,7 @@ inline fun String.toOre() = fun String.toStack(quantity: Int = 1, meta: Int = 0): ItemStack { val split = split(':') - val meta = split.getOrNull(2)?.toInt() ?: meta + val meta = split.getApplyOrDefault(2, String::toInt) { meta } val location = if(split.size == 1) ResourceLocation(this) else ResourceLocation(split[0], split[1]) return Item.REGISTRY.registryObjects[location]?.toStack(quantity, meta) ?: Block.REGISTRY.registryObjects[location]?.toStack(quantity, meta) ?: ItemStack.EMPTY From 7431bfa5481d5d72efa301dc1c68f6fa5d9676db Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Fri, 16 Jan 2026 23:09:56 +0100 Subject: [PATCH 15/58] fix build --- .../org/ender_development/catalyx/core/recipes/RecipeMap.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt index c61c6c0..8f10af7 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt @@ -26,7 +26,7 @@ class RecipeMap> { internal val RECIPE_DURATION_THEN_ENERGY = Comparator .comparingInt(Recipe::duration) .thenComparingLong(Recipe::energyPerTick) - .thenComparingInt { it.hashCode } + .thenComparingInt(Recipe::hashCode) internal val INGREDIENT_ROOT = WeakHashMap>() internal var foundInvalidRecipe = false From 31d015e74feb893bd21dab5147c7c718a37c9418 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Fri, 16 Jan 2026 23:19:19 +0100 Subject: [PATCH 16/58] some slight unimportant changes --- .../catalyx/core/client/gui/CatalyxGuiHandler.kt | 2 +- .../ender_development/catalyx/core/config/ConfigHandler.kt | 4 ++-- .../org/ender_development/catalyx/core/recipes/RecipeMap.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt index c8ae7cf..1f92959 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt @@ -24,7 +24,7 @@ class CatalyxGuiHandler(mod: ICatalyxMod) : IGuiHandler { internal val tileEntities = mutableListOf>() init { - instances.put(mod, this) + instances[mod] = this } fun registerId(te: Class, container: Class, gui: () -> Class): Int { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt index 311c03f..aeebff6 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt @@ -26,7 +26,7 @@ class ConfigHandler(configData: Iterable(configData: Iterable> { ingredients.indices.forEach { i -> val mappedIngredient = ingredients[i] // attempt to use the cached version if it exists, otherwise cache it - INGREDIENT_ROOT.get(mappedIngredient)?.get()?.let { ingredients[i] = it } ?: run { + INGREDIENT_ROOT[mappedIngredient]?.get()?.let { ingredients[i] = it } ?: run { INGREDIENT_ROOT[mappedIngredient] = WeakReference(mappedIngredient) } } From f7d3122561353fce5867d61fbc492a617c3a131b Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 18 Jan 2026 12:46:03 +0100 Subject: [PATCH 17/58] fix some stuff IJ is complaining about --- .../kotlin/org/ender_development/catalyx/Catalyx.kt | 2 -- .../api/v1/modules/interfaces/IModuleManager.kt | 2 +- .../catalyx/core/blocks/BaseBlock.kt | 3 ++- .../catalyx/core/blocks/BaseMachineBlock.kt | 2 +- .../catalyx/core/blocks/BaseRotatableMachineBlock.kt | 2 +- .../catalyx/core/blocks/BaseRotatableTileBlock.kt | 2 +- .../catalyx/core/blocks/BaseTileBlock.kt | 2 +- .../core/client/button/AbstractButtonWrapper.kt | 6 +++--- .../catalyx/core/client/gui/CatalyxGuiHandler.kt | 2 +- .../catalyx/core/registry/CatalyxBlockRegistry.kt | 1 - .../catalyx/core/registry/CatalyxItemRegistry.kt | 1 - .../catalyx/core/tiles/BaseMachineTile.kt | 11 ++++++++--- .../catalyx/core/tiles/helper/ICopyPasteExtraTile.kt | 2 +- .../catalyx/core/utils/extensions/BlockPos.kt | 2 +- 14 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt b/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt index c616258..e88f310 100644 --- a/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt +++ b/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt @@ -4,12 +4,10 @@ import net.minecraft.creativetab.CreativeTabs import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLConstructionEvent -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import org.apache.logging.log4j.LogManager import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.module.ModuleManager -import org.ender_development.catalyx.core.network.PacketHandler import org.ender_development.catalyx.core.utils.persistence.ConfigPersistentData import kotlin.random.Random diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleManager.kt index d019075..d5e40a2 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleManager.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleManager.kt @@ -5,7 +5,7 @@ import org.ender_development.catalyx.api.v1.modules.Modules /** * Interface for the actual [ModuleManager][org.ender_development.catalyx.core.module.ModuleManager] * - * @see [org.ender_development.catalyx.api.v1.modules.moduleManager] + * @see [org.ender_development.catalyx.api.v1.modules.Modules.moduleManager] */ interface IModuleManager { /** diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt index 73155db..7085c65 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt @@ -75,7 +75,8 @@ open class BaseBlock(val mod: ICatalyxMod, name: String, material: Material = Ma * @param state The block state of the edge block. * @return The AABB of the edge block. */ - open fun getAABB(state: IBlockState): AxisAlignedBB = FULL_BLOCK_AABB + open fun getAABB(state: IBlockState): AxisAlignedBB = + FULL_BLOCK_AABB // We override these methods with a AABB check instead of hardcoding its return value @Deprecated("Implementation is fine.") diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseMachineBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseMachineBlock.kt index e841eb7..ce8249f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseMachineBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseMachineBlock.kt @@ -15,7 +15,7 @@ import org.ender_development.catalyx.core.tiles.BaseTile open class BaseMachineBlock : BaseTileBlock { constructor(mod: ICatalyxMod, name: String, tileClass: Class, guiId: Int) : super(mod, name, tileClass, guiId) /** - * Only use this constructor if you used a [org.ender_development.catalyx.client.gui.CatalyxGuiHandler] for the guiId + * Only use this constructor if you used a [org.ender_development.catalyx.core.client.gui.CatalyxGuiHandler] for the guiId */ constructor(mod: ICatalyxMod, name: String, guiId: Int) : super(mod, name, guiId) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseRotatableMachineBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseRotatableMachineBlock.kt index 20e45f0..0e2f4b5 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseRotatableMachineBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseRotatableMachineBlock.kt @@ -14,7 +14,7 @@ import org.ender_development.catalyx.core.ICatalyxMod open class BaseRotatableMachineBlock : BaseMachineBlock { constructor(mod: ICatalyxMod, name: String, tileClass: Class, guiId: Int) : super(mod, name, tileClass, guiId) /** - * Only use this constructor if you used a [org.ender_development.catalyx.client.gui.CatalyxGuiHandler] for the guiId + * Only use this constructor if you used a [org.ender_development.catalyx.core.client.gui.CatalyxGuiHandler] for the guiId */ constructor(mod: ICatalyxMod, name: String, guiId: Int) : super(mod, name, guiId) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseRotatableTileBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseRotatableTileBlock.kt index a51911c..c984d5e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseRotatableTileBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseRotatableTileBlock.kt @@ -14,7 +14,7 @@ import org.ender_development.catalyx.core.ICatalyxMod open class BaseRotatableTileBlock : BaseTileBlock { constructor(mod: ICatalyxMod, name: String, tileClass: Class, guiId: Int) : super(mod, name, tileClass, guiId) /** - * Only use this constructor if you used a [org.ender_development.catalyx.client.gui.CatalyxGuiHandler] for the guiId + * Only use this constructor if you used a [org.ender_development.catalyx.core.client.gui.CatalyxGuiHandler] for the guiId */ constructor(mod: ICatalyxMod, name: String, guiId: Int) : super(mod, name, guiId) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseTileBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseTileBlock.kt index 30e79b0..cdc0bc0 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseTileBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseTileBlock.kt @@ -26,7 +26,7 @@ import org.ender_development.catalyx.core.tiles.BaseTile */ open class BaseTileBlock(mod: ICatalyxMod, name: String, val tileClass: Class, val guiId: Int) : BaseBlock(mod, name), ITileEntityProvider { /** - * Only use this constructor if you used a [org.ender_development.catalyx.client.gui.CatalyxGuiHandler] for the guiId + * Only use this constructor if you used a [org.ender_development.catalyx.core.client.gui.CatalyxGuiHandler] for the guiId */ constructor(mod: ICatalyxMod, name: String, guiId: Int) : this(mod, name, CatalyxGuiHandler.instances[mod]?.tileEntities[guiId] ?: error("Tried to use the BaseTileBlock constructor without a tileClass without using a CatalyxGuiHandler to register the GUI handler"), guiId) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt index d0dcbff..8b9e730 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt @@ -24,9 +24,9 @@ import org.ender_development.catalyx.core.utils.SideUtils * - add a button to the buttonList by instantiating this class and doing [net.minecraft.client.gui.GuiScreen.buttonList].add(instance.[button]) * - override [net.minecraft.client.gui.GuiScreen.actionPerformed] and use [getWrapper] to identify/get buttons and their wrappers, if need be * - * On server-side in TEs that extend [org.ender_development.catalyx.tiles.helper.IButtonTile] - * - implement [org.ender_development.catalyx.tiles.helper.IButtonTile.handleButtonPress] and handle your button from there - * - if you cannot guarantee this class will be instantiated before any button clicks are received, call [registerWrapper] (ideally in your TE init {} block, see [org.ender_development.catalyx.tiles.BaseTile] for an example) + * On server-side in TEs that extend [org.ender_development.catalyx.core.tiles.helper.IButtonTile] + * - implement [org.ender_development.catalyx.core.tiles.helper.IButtonTile.handleButtonPress] and handle your button from there + * - if you cannot guarantee this class will be instantiated before any button clicks are received, call [registerWrapper] (ideally in your TE init {} block, see [org.ender_development.catalyx.core.tiles.BaseTile] for an example) */ abstract class AbstractButtonWrapper(x: Int, y: Int, width: Int = 16, height: Int = 16) { open val textureLocation = ResourceLocation(Reference.MODID, "textures/gui/container/gui.png") diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt index 1f92959..ef1b491 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt @@ -14,7 +14,7 @@ import org.ender_development.catalyx.core.utils.SideUtils /** * A GUI handler you can use for your machines * - * Use the return value of [registerId] in the [org.ender_development.catalyx.blocks.BaseTileBlock.guiId] field + * Use the return value of [registerId] in the [org.ender_development.catalyx.core.blocks.BaseTileBlock.guiId] field * * Remember to register it with [net.minecraftforge.fml.common.network.NetworkRegistry.registerGuiHandler] */ diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt index 2ec6de0..ea6d431 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt @@ -12,7 +12,6 @@ import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.DevUtils import org.ender_development.catalyx.core.utils.extensions.plural -@Suppress("unused") @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxBlockRegistry : ICatalyxRegistry { override val registry = CatalyxProviderRegistry() diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt index a8fa759..6642271 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt @@ -11,7 +11,6 @@ import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.DevUtils import org.ender_development.catalyx.core.utils.extensions.plural -@Suppress("unused") @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxItemRegistry : ICatalyxRegistry { override val registry = CatalyxProviderRegistry() diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseMachineTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseMachineTile.kt index c4974a3..ffab667 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseMachineTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseMachineTile.kt @@ -54,7 +54,8 @@ abstract class BaseMachineTile(mod: ICatalyxMod) : BaseTile(mod), ITickable, /** * Check if the recipe progress should reset if shouldProcess() is false */ - open fun shouldResetProgress() = true + open fun shouldResetProgress() = + true /** * Called every tick when the machine is idle. @@ -63,10 +64,14 @@ abstract class BaseMachineTile(mod: ICatalyxMod) : BaseTile(mod), ITickable, open fun onIdleTick() = updateRecipe() override fun update() { - if(world.isRemote) return + if(world.isRemote) + return + markDirtyGUIEvery(5) - if(isPaused || needsRedstonePower != this.world.isBlockPowered(this.pos)) return + if(isPaused || needsRedstonePower != world.isBlockPowered(pos)) + return + if(!shouldTick()) { progressTicks = 0 return diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraTile.kt index 9e17fdb..a1eec28 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraTile.kt @@ -8,7 +8,7 @@ interface ICopyPasteExtraTile { /** * Write data into the NBT Tag to be copied and stored * - * Note: if your TE implements [org.ender_development.catalyx.client.gui.BaseGuiTyped.IDefaultButtonVariables] (like [org.ender_development.catalyx.tiles.BaseMachineTile] does), the `isPaused` and `needsRedstonePower` fields are already copied + * Note: if your TE implements [org.ender_development.catalyx.core.client.gui.BaseGuiTyped.IDefaultButtonVariables] (like [org.ender_development.catalyx.core.tiles.BaseMachineTile] does), the `isPaused` and `needsRedstonePower` fields are already copied */ fun copyData(tag: NBTTagCompound) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt index 0ff5cde..1562844 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt @@ -25,7 +25,7 @@ inline operator fun BlockPos.plus(other: BlockPos): BlockPos = inline operator fun BlockPos.times(scalar: Int) = BlockPos(x * scalar, y * scalar, z * scalar) -inline fun Pair.getAllInBox() = +inline fun Pair.getAllInBox(): Iterable = BlockPos.getAllInBox(first, second) inline fun BlockPos.getFacingFromEntityPosition(entityX: Float, entityZ: Float): EnumFacing = From af3b16d4ba14fee2ed60920410b85f3a3ff62f56 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 18 Jan 2026 12:47:27 +0100 Subject: [PATCH 18/58] finally rename SIZE --- .../catalyx/core/client/container/BaseContainer.kt | 9 ++++----- .../org/ender_development/catalyx/core/tiles/BaseTile.kt | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/container/BaseContainer.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/container/BaseContainer.kt index 4ff938d..d44b5b8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/container/BaseContainer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/container/BaseContainer.kt @@ -64,11 +64,11 @@ abstract class BaseContainer(playerInv: IInventory, val tileEntity: IBaseContain val stack = slot.stack // transfer TE Container -> Anywhere else (Player Inventory) - if(index < tileEntity.SIZE) { - if(!mergeItemStack(stack, tileEntity.SIZE, inventorySlots.size, true)) + if(index < tileEntity.inventorySlotCount) { + if(!mergeItemStack(stack, tileEntity.inventorySlotCount, inventorySlots.size, true)) return ItemStack.EMPTY // transfer Anywhere else (Player Inventory) -> TE Container - } else if(!mergeItemStack(stack, 0, tileEntity.SIZE, false)) + } else if(!mergeItemStack(stack, 0, tileEntity.inventorySlotCount, false)) return ItemStack.EMPTY if(stack.isEmpty) @@ -80,8 +80,7 @@ abstract class BaseContainer(playerInv: IInventory, val tileEntity: IBaseContain } interface IBaseContainerCompat : IGuiTile { - // TODO rename someday - val SIZE: Int + val inventorySlotCount: Int fun canInteractWith(player: EntityPlayer): Boolean } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt index 1536417..9445481 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt @@ -40,7 +40,7 @@ import org.ender_development.catalyx.core.tiles.helper.* abstract class BaseTile(open val mod: ICatalyxMod) : TileEntity(), BaseContainer.IBaseContainerCompat { var inputSlots = 0 var outputSlots = 0 - override val SIZE + override val inventorySlotCount get() = inventory.slots var dirtyTicks = 0 From 52c21fbeedb259d4a4432915e312683d57603f45 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 18 Jan 2026 12:48:49 +0100 Subject: [PATCH 19/58] why were these getters --- .../org/ender_development/catalyx/core/tiles/BaseTile.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt index 9445481..02fce58 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt @@ -36,7 +36,7 @@ import org.ender_development.catalyx.core.tiles.helper.* /** * A base TileEntity in Catalyx, implementing separate input and output inventories; saving/loading from NBT; energy, fluid and item capability handling */ -@Suppress("UNUSED") +@Suppress("unused") abstract class BaseTile(open val mod: ICatalyxMod) : TileEntity(), BaseContainer.IBaseContainerCompat { var inputSlots = 0 var outputSlots = 0 @@ -62,11 +62,9 @@ abstract class BaseTile(open val mod: ICatalyxMod) : TileEntity(), BaseContainer open val facing: EnumFacing get() = world.getBlockState(pos).properties.getOrDefault(BlockHorizontal.FACING, EnumFacing.NORTH) as EnumFacing - open val inventory: IItemHandler - get() = CombinedInvWrapper(input, output) + open val inventory: IItemHandler = CombinedInvWrapper(input, output) - open val automationInvHandler: CombinedInvWrapper - get() = CombinedInvWrapper(automationInput, automationOutput) + open val automationInvHandler = CombinedInvWrapper(automationInput, automationOutput) override fun canInteractWith(player: EntityPlayer) = !isInvalid && player.getDistanceSq(pos.add(.5, .5, .5)) <= 64 From b1232ae5bd86f7363ff1912307bf3a21dddd5f71 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 18 Jan 2026 12:53:09 +0100 Subject: [PATCH 20/58] drawRect actually already calls GlSM#setColor --- .../catalyx/core/client/button/AbstractButtonWrapper.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt index 8b9e730..c0d0c44 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt @@ -47,7 +47,6 @@ abstract class AbstractButtonWrapper(x: Int, y: Int, width: Int = 16, height: In if(!hovered) return - GlStateManager.color(1f, 1f, 1f) // +1/-1 to account for the border and only highlight the contents drawRect(x + 1, y + 1, x + width - 1, y + height - 1, 0x64ffffff) } From b0674f16a0b91c985eef2a1a0432855ee4a2c419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Sun, 18 Jan 2026 16:27:52 +0100 Subject: [PATCH 21/58] Add docs --- .../kotlin/org/ender_development/catalyx/core/utils/Mods.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/Mods.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/Mods.kt index e0416b6..96aa12d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/Mods.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/Mods.kt @@ -2,6 +2,9 @@ package org.ender_development.catalyx.core.utils import org.ender_development.catalyx.core.Reference +/** + * ModID Database + */ object Mods { const val CATALYX = Reference.MODID const val GROOVYSCRIPT = "groovyscript" From 4ac304fdf58c330c590d5d4952179db3b37dfd71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Sun, 18 Jan 2026 16:29:52 +0100 Subject: [PATCH 22/58] Move extensions to api so they are public avalible --- .../catalyx/{core/utils => api/v1}/extensions/Any.kt | 2 +- .../{core/utils => api/v1}/extensions/AxisAlignedBB.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/Block.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/BlockPos.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/ByteBuf.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/Color.kt | 2 +- .../{core/utils => api/v1}/extensions/Container.kt | 2 +- .../utils => api/v1}/extensions/EnchantmentRarity.kt | 2 +- .../{core/utils => api/v1}/extensions/EntityPlayer.kt | 2 +- .../{core/utils => api/v1}/extensions/EnumDyeColor.kt | 2 +- .../{core/utils => api/v1}/extensions/EnumFacing.kt | 2 +- .../{core/utils => api/v1}/extensions/EnumRarity.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/Fluid.kt | 2 +- .../{core/utils => api/v1}/extensions/FluidStack.kt | 2 +- .../{core/utils => api/v1}/extensions/IItemHandler.kt | 2 +- .../ender_development/catalyx/api/v1/extensions/Int.kt | 4 ++++ .../catalyx/{core/utils => api/v1}/extensions/Item.kt | 2 +- .../{core/utils => api/v1}/extensions/ItemStack.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/List.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/Logger.kt | 2 +- .../{core/utils => api/v1}/extensions/NBTTagCompound.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/Set.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/String.kt | 2 +- .../{core/utils => api/v1}/extensions/TextFormatting.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/Vec3d.kt | 2 +- .../catalyx/{core/utils => api/v1}/extensions/Vec3i.kt | 2 +- .../catalyx/core/blocks/multiblock/CenterBlock.kt | 2 +- .../catalyx/core/client/gui/BaseGuiTyped.kt | 4 ++-- .../catalyx/core/client/tesr/HudInfoRenderer.kt | 4 ++-- .../catalyx/core/client/tesr/IORenderer.kt | 8 ++++---- .../ender_development/catalyx/core/config/ConfigParser.kt | 2 +- .../catalyx/core/module/ModuleManager.kt | 2 +- .../catalyx/core/network/ButtonPacket.kt | 4 ++-- .../org/ender_development/catalyx/core/recipes/Recipe.kt | 2 +- .../catalyx/core/recipes/RecipeBuilder.kt | 2 +- .../catalyx/core/recipes/ingredients/nbt/IMatcher.kt | 2 +- .../catalyx/core/recipes/validation/Validator.kt | 2 +- .../catalyx/core/registry/CatalyxBlockRegistry.kt | 2 +- .../catalyx/core/registry/CatalyxItemRegistry.kt | 2 +- .../catalyx/core/registry/CatalyxProviderRegistry.kt | 2 +- .../ender_development/catalyx/core/tiles/CenterTile.kt | 2 +- .../org/ender_development/catalyx/core/tiles/TESRTile.kt | 4 ++-- .../catalyx/core/tiles/helper/TileStackHandler.kt | 4 ++-- .../org/ender_development/catalyx/core/utils/Delegates.kt | 2 +- .../ender_development/catalyx/core/utils/RenderUtils.kt | 2 +- .../catalyx/core/utils/extensions/Int.kt | 4 ---- .../catalyx/core/utils/math/BlockPosUtils.kt | 6 +++--- .../catalyx/core/utils/parser/AbstractJsonParser.kt | 4 ++-- .../catalyx/modules/CatalyxCoreModule.kt | 2 +- .../catalyx/modules/integration/IntegrationModule.kt | 2 +- .../integration/groovyscript/ModuleGroovyScript.kt | 2 +- .../catalyx/modules/integration/top/FluidTileProvider.kt | 2 +- .../catalyx/modules/integration/top/ModuleTheOneProbe.kt | 2 +- .../catalyx/modules/internal/InternalModule.kt | 2 +- .../catalyx/modules/test/DevTestModule.kt | 2 +- 55 files changed, 68 insertions(+), 68 deletions(-) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Any.kt (93%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/AxisAlignedBB.kt (93%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Block.kt (83%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/BlockPos.kt (95%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/ByteBuf.kt (93%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Color.kt (89%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Container.kt (75%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/EnchantmentRarity.kt (74%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/EntityPlayer.kt (84%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/EnumDyeColor.kt (79%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/EnumFacing.kt (96%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/EnumRarity.kt (86%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Fluid.kt (71%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/FluidStack.kt (91%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/IItemHandler.kt (94%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Int.kt rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Item.kt (83%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/ItemStack.kt (92%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/List.kt (96%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Logger.kt (78%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/NBTTagCompound.kt (91%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Set.kt (78%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/String.kt (96%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/TextFormatting.kt (80%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Vec3d.kt (77%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/extensions/Vec3i.kt (83%) delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Int.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Any.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Any.kt similarity index 93% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Any.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Any.kt index 7d509bb..7822350 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Any.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Any.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import org.ender_development.catalyx.core.utils.validation.IValidator import org.ender_development.catalyx.core.utils.validation.ValidationBuilder diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/AxisAlignedBB.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/AxisAlignedBB.kt similarity index 93% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/AxisAlignedBB.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/AxisAlignedBB.kt index 1f63156..94cfc05 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/AxisAlignedBB.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/AxisAlignedBB.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.util.math.AxisAlignedBB diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Block.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Block.kt similarity index 83% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Block.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Block.kt index 78f2901..9d06141 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Block.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Block.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.block.Block import net.minecraft.item.ItemStack diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/BlockPos.kt similarity index 95% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/BlockPos.kt index 1562844..7931a88 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/BlockPos.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/BlockPos.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.entity.Entity import net.minecraft.util.EnumFacing diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/ByteBuf.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ByteBuf.kt similarity index 93% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/ByteBuf.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ByteBuf.kt index c348684..a45189b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/ByteBuf.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ByteBuf.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import io.netty.buffer.ByteBuf import net.minecraft.item.ItemStack diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Color.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Color.kt similarity index 89% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Color.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Color.kt index 8f2e8c3..afb064c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Color.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Color.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import java.awt.Color diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Container.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Container.kt similarity index 75% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Container.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Container.kt index 6dd66cb..b872dad 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Container.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Container.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.inventory.Container import net.minecraft.inventory.Slot diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnchantmentRarity.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnchantmentRarity.kt similarity index 74% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnchantmentRarity.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnchantmentRarity.kt index 52a65f6..3dda1fa 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnchantmentRarity.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnchantmentRarity.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.enchantment.Enchantment import net.minecraft.item.EnumRarity diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EntityPlayer.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EntityPlayer.kt similarity index 84% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EntityPlayer.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EntityPlayer.kt index 089317f..b7e4e8d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EntityPlayer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EntityPlayer.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.client.entity.EntityPlayerSP import net.minecraft.entity.player.EntityPlayer diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnumDyeColor.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumDyeColor.kt similarity index 79% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnumDyeColor.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumDyeColor.kt index 3d427cf..66bc6b5 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnumDyeColor.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumDyeColor.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.item.EnumDyeColor import org.ender_development.catalyx.core.utils.ColorMapping diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnumFacing.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumFacing.kt similarity index 96% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnumFacing.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumFacing.kt index f0e800b..08d8e2a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnumFacing.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumFacing.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.EnumFacing diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnumRarity.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumRarity.kt similarity index 86% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnumRarity.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumRarity.kt index 430a6d8..6229e58 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/EnumRarity.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumRarity.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.enchantment.Enchantment import net.minecraft.item.EnumRarity diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Fluid.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Fluid.kt similarity index 71% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Fluid.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Fluid.kt index d67c501..f20b157 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Fluid.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Fluid.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraftforge.fluids.Fluid import net.minecraftforge.fluids.FluidStack diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/FluidStack.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/FluidStack.kt similarity index 91% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/FluidStack.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/FluidStack.kt index 12a116b..9354d22 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/FluidStack.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/FluidStack.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraftforge.fluids.FluidRegistry import net.minecraftforge.fluids.FluidStack diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/IItemHandler.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/IItemHandler.kt similarity index 94% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/IItemHandler.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/IItemHandler.kt index 3b7d916..668cdce 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/IItemHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/IItemHandler.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.item.ItemStack import net.minecraftforge.items.IItemHandler diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Int.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Int.kt new file mode 100644 index 0000000..4289fa8 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Int.kt @@ -0,0 +1,4 @@ +package org.ender_development.catalyx.api.v1.extensions + +val Int.plural + inline get() = if(this == 1) "" else "s" diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Item.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Item.kt similarity index 83% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Item.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Item.kt index fb53491..d2d44e7 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Item.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Item.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.item.Item import net.minecraft.item.ItemStack diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/ItemStack.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ItemStack.kt similarity index 92% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/ItemStack.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ItemStack.kt index 51df51a..3ff4df2 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/ItemStack.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ItemStack.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.item.ItemStack import net.minecraft.item.crafting.Ingredient diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/List.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/List.kt similarity index 96% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/List.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/List.kt index 8dcc9f4..28ec76b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/List.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/List.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import com.google.common.collect.ImmutableList import it.unimi.dsi.fastutil.objects.ObjectLists diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Logger.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Logger.kt similarity index 78% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Logger.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Logger.kt index aa9f38b..7cafbd5 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Logger.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Logger.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/NBTTagCompound.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/NBTTagCompound.kt similarity index 91% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/NBTTagCompound.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/NBTTagCompound.kt index 0ba0d46..9a01020 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/NBTTagCompound.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/NBTTagCompound.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.nbt.NBTTagCompound import net.minecraft.nbt.NBTTagLongArray diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Set.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Set.kt similarity index 78% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Set.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Set.kt index 5d533c0..3849df6 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Set.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Set.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import it.unimi.dsi.fastutil.objects.ObjectSets import java.util.* diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/String.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/String.kt similarity index 96% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/String.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/String.kt index 477687d..0c66b5b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/String.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/String.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.block.Block import net.minecraft.client.resources.I18n diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/TextFormatting.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/TextFormatting.kt similarity index 80% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/TextFormatting.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/TextFormatting.kt index 589aa95..57e50c9 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/TextFormatting.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/TextFormatting.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.util.text.TextFormatting import org.ender_development.catalyx.core.utils.ColorMapping diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Vec3d.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3d.kt similarity index 77% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Vec3d.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3d.kt index 7d16a09..27639aa 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Vec3d.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3d.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.util.math.Vec3d diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Vec3i.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3i.kt similarity index 83% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Vec3i.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3i.kt index 4aa1ef5..f0d62f2 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Vec3i.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3i.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils.extensions +package org.ender_development.catalyx.api.v1.extensions import net.minecraft.util.math.Vec3d import net.minecraft.util.math.Vec3i diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/multiblock/CenterBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/multiblock/CenterBlock.kt index 1a55403..e07d0cd 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/multiblock/CenterBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/multiblock/CenterBlock.kt @@ -8,9 +8,9 @@ import net.minecraft.tileentity.TileEntity import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.world.World +import org.ender_development.catalyx.api.v1.extensions.getHorizontalSurroundings import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.blocks.BaseRotatableTileBlock -import org.ender_development.catalyx.core.utils.extensions.getHorizontalSurroundings open class CenterBlock(mod: ICatalyxMod, name: String, tileClass: Class, guiId: Int, vararg components: IMultiblockEdge) : BaseRotatableTileBlock( mod, name, tileClass, guiId diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt index b276f9c..8ba1762 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt @@ -5,6 +5,8 @@ import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.client.renderer.GlStateManager import net.minecraft.inventory.Container import net.minecraft.util.ResourceLocation +import org.ender_development.catalyx.api.v1.extensions.get +import org.ender_development.catalyx.api.v1.extensions.translate import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.client.button.AbstractButtonWrapper import org.ender_development.catalyx.core.client.button.PauseButtonWrapper @@ -19,8 +21,6 @@ import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.helper.IGuiTile import org.ender_development.catalyx.core.utils.RenderAlignment import org.ender_development.catalyx.core.utils.RenderUtils -import org.ender_development.catalyx.core.utils.extensions.get -import org.ender_development.catalyx.core.utils.extensions.translate // TODO fully rewrite this whole mess at some point abstract class BaseGuiTyped(container: Container, val tileEntity: T) : GuiContainer(container) where T : IGuiTile, T : BaseTile, T : BaseGuiTyped.IDefaultButtonVariables { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt index e3724fb..8775520 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt @@ -4,13 +4,13 @@ import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.EnumFacing import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import org.ender_development.catalyx.api.v1.extensions.getFacingFromEntity +import org.ender_development.catalyx.api.v1.extensions.glRotate import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.helper.HudInfoLine import org.ender_development.catalyx.core.tiles.helper.IHudInfoProvider import org.ender_development.catalyx.core.utils.RenderUtils.FONT_RENDERER import org.ender_development.catalyx.core.utils.RenderUtils.drawRectangle -import org.ender_development.catalyx.core.utils.extensions.getFacingFromEntity -import org.ender_development.catalyx.core.utils.extensions.glRotate @SideOnly(Side.CLIENT) object HudInfoRenderer : AbstractTESRenderer() { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/IORenderer.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/IORenderer.kt index d5a2be1..ba1e35e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/IORenderer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/IORenderer.kt @@ -6,16 +6,16 @@ import net.minecraft.util.EnumFacing import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import org.ender_development.catalyx.api.v1.extensions.glOffsetX +import org.ender_development.catalyx.api.v1.extensions.glOffsetZ +import org.ender_development.catalyx.api.v1.extensions.glRotate +import org.ender_development.catalyx.api.v1.extensions.glRotationAngle import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.blocks.helper.IOType import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.helper.IPortRenderer import org.ender_development.catalyx.core.utils.RenderUtils import org.ender_development.catalyx.core.utils.RenderUtils.drawScaledCustomSizeModalRect -import org.ender_development.catalyx.core.utils.extensions.glOffsetX -import org.ender_development.catalyx.core.utils.extensions.glOffsetZ -import org.ender_development.catalyx.core.utils.extensions.glRotate -import org.ender_development.catalyx.core.utils.extensions.glRotationAngle import org.lwjgl.opengl.GL11 @SideOnly(Side.CLIENT) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt index fe44990..05f3282 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt @@ -5,8 +5,8 @@ import net.minecraft.block.state.IBlockState import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.util.ResourceLocation +import org.ender_development.catalyx.api.v1.extensions.modLoaded import org.ender_development.catalyx.core.config.ConfigParser.ConfigBlockState.Companion.IGNORE_META -import org.ender_development.catalyx.core.utils.extensions.modLoaded import java.util.* /** diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt index 2a6377b..461292e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt @@ -11,6 +11,7 @@ import net.minecraftforge.fml.common.ModContainer import net.minecraftforge.fml.common.discovery.ASMDataTable import net.minecraftforge.fml.common.event.* import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.extensions.modLoaded import org.ender_development.catalyx.api.v1.modules.Modules import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModuleContainer @@ -24,7 +25,6 @@ import org.ender_development.catalyx.core.module.ModuleManager.discoveredModules import org.ender_development.catalyx.core.module.ModuleManager.stateEvent import org.ender_development.catalyx.core.utils.Delegates import org.ender_development.catalyx.core.utils.DevUtils -import org.ender_development.catalyx.core.utils.extensions.modLoaded import java.io.File import java.util.* diff --git a/src/main/kotlin/org/ender_development/catalyx/core/network/ButtonPacket.kt b/src/main/kotlin/org/ender_development/catalyx/core/network/ButtonPacket.kt index a2387c1..b4eddfd 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/network/ButtonPacket.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/network/ButtonPacket.kt @@ -8,10 +8,10 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler import net.minecraftforge.fml.common.network.simpleimpl.MessageContext import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.extensions.readString +import org.ender_development.catalyx.api.v1.extensions.writeString import org.ender_development.catalyx.core.client.button.AbstractButtonWrapper import org.ender_development.catalyx.core.tiles.helper.IButtonTile -import org.ender_development.catalyx.core.utils.extensions.readString -import org.ender_development.catalyx.core.utils.extensions.writeString class ButtonPacket() : IMessage { private lateinit var blockPos: BlockPos diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt index 88f0629..a7bf62d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt @@ -7,13 +7,13 @@ import net.minecraftforge.fluids.capability.IFluidHandler import net.minecraftforge.items.IItemHandlerModifiable import net.minecraftforge.items.ItemHandlerHelper import net.minecraftforge.oredict.OreDictionary +import org.ender_development.catalyx.api.v1.extensions.copyOf import org.ender_development.catalyx.core.recipes.chance.output.ChancedFluidOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedItemOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedOutputList import org.ender_development.catalyx.core.recipes.ingredients.RecipeInput import org.ender_development.catalyx.core.recipes.ingredients.RecipeInputCache import org.ender_development.catalyx.core.utils.IItemStackHash -import org.ender_development.catalyx.core.utils.extensions.copyOf import org.ender_development.catalyx.modules.integration.groovyscript.ModuleGroovyScript class Recipe ( diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt index ec1c84b..863d444 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt @@ -4,6 +4,7 @@ import com.cleanroommc.groovyscript.api.GroovyLog import net.minecraft.item.ItemStack import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fml.common.Optional +import org.ender_development.catalyx.api.v1.extensions.plural import org.ender_development.catalyx.core.recipes.chance.output.ChancedFluidOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedItemOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedOutputList @@ -13,7 +14,6 @@ import org.ender_development.catalyx.core.recipes.validation.Result import org.ender_development.catalyx.core.recipes.validation.ValidationState import org.ender_development.catalyx.core.recipes.validation.Validator import org.ender_development.catalyx.core.utils.Mods -import org.ender_development.catalyx.core.utils.extensions.plural import org.ender_development.catalyx.modules.integration.groovyscript.ModuleGroovyScript import java.util.function.Supplier diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt index 3f16596..02d4427 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt @@ -3,7 +3,7 @@ package org.ender_development.catalyx.core.recipes.ingredients.nbt import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.fluids.FluidStack -import org.ender_development.catalyx.core.utils.extensions.getLongArray +import org.ender_development.catalyx.api.v1.extensions.getLongArray interface IMatcher { companion object { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/validation/Validator.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/validation/Validator.kt index 294dc6c..55e1397 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/validation/Validator.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/validation/Validator.kt @@ -2,7 +2,7 @@ package org.ender_development.catalyx.core.recipes.validation import org.apache.logging.log4j.Logger import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.core.utils.extensions.validateWith +import org.ender_development.catalyx.api.v1.extensions.validateWith import org.ender_development.catalyx.core.utils.validation.ValidationError class Validator { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt index ea6d431..3e5972a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt @@ -6,11 +6,11 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.extensions.plural import org.ender_development.catalyx.api.v1.registry.IBlockProvider import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.DevUtils -import org.ender_development.catalyx.core.utils.extensions.plural @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxBlockRegistry : ICatalyxRegistry { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt index 6642271..c9f5bda 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt @@ -5,11 +5,11 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.extensions.plural import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.api.v1.registry.IItemProvider import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.DevUtils -import org.ender_development.catalyx.core.utils.extensions.plural @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxItemRegistry : ICatalyxRegistry { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt index d2258ae..3f4d039 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt @@ -1,9 +1,9 @@ package org.ender_development.catalyx.core.registry import net.minecraft.util.ResourceLocation +import org.ender_development.catalyx.api.v1.extensions.modLoaded import org.ender_development.catalyx.api.v1.registry.ICatalyxProviderRegistry import org.ender_development.catalyx.api.v1.registry.IProvider -import org.ender_development.catalyx.core.utils.extensions.modLoaded /** * Collection of all [IProvider] of a given type diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt index 7017907..6ad2837 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt @@ -7,11 +7,11 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.world.World import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.extensions.getHorizontalSurroundings import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.blocks.multiblock.IMultiblockEdge import org.ender_development.catalyx.core.blocks.multiblock.IMultiblockTile import org.ender_development.catalyx.core.utils.DevUtils -import org.ender_development.catalyx.core.utils.extensions.getHorizontalSurroundings open class CenterTile(mod: ICatalyxMod) : BaseTile(mod), IMultiblockTile { internal constructor() : this(Catalyx) { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/TESRTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/TESRTile.kt index 83914c1..5d142c1 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/TESRTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/TESRTile.kt @@ -4,14 +4,14 @@ import net.minecraft.client.Minecraft import net.minecraft.util.EnumFacing import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import org.ender_development.catalyx.api.v1.extensions.relativeDirectionTo +import org.ender_development.catalyx.api.v1.extensions.withAlpha import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.client.tesr.AbstractTESRenderer import org.ender_development.catalyx.core.client.tesr.HudInfoRenderer import org.ender_development.catalyx.core.tiles.helper.HudInfoLine import org.ender_development.catalyx.core.tiles.helper.IHudInfoProvider import org.ender_development.catalyx.core.tiles.helper.ITESRTile -import org.ender_development.catalyx.core.utils.extensions.relativeDirectionTo -import org.ender_development.catalyx.core.utils.extensions.withAlpha import java.awt.Color open class TESRTile(mod: ICatalyxMod) : BaseTile(mod), ITESRTile, IHudInfoProvider { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt index 8d04b96..6bccb1b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt @@ -3,10 +3,10 @@ package org.ender_development.catalyx.core.tiles.helper import net.minecraft.item.ItemStack import net.minecraft.util.EnumFacing import net.minecraftforge.items.ItemStackHandler +import org.ender_development.catalyx.api.v1.extensions.get +import org.ender_development.catalyx.api.v1.extensions.tryInsertInto import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.BaseTile.Companion.ITEM_CAP -import org.ender_development.catalyx.core.utils.extensions.get -import org.ender_development.catalyx.core.utils.extensions.tryInsertInto open class TileStackHandler(size: Int, val tile: BaseTile) : ItemStackHandler() { init { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt index 5684646..64a6808 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt @@ -1,6 +1,6 @@ package org.ender_development.catalyx.core.utils -import org.ender_development.catalyx.core.utils.extensions.modLoaded +import org.ender_development.catalyx.api.v1.extensions.modLoaded import kotlin.properties.ReadOnlyProperty import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt index 464412d..a13f1c5 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt @@ -12,7 +12,7 @@ import net.minecraft.util.ResourceLocation import net.minecraftforge.fluids.Fluid import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidTank -import org.ender_development.catalyx.core.utils.extensions.destructFloat +import org.ender_development.catalyx.api.v1.extensions.destructFloat import org.lwjgl.opengl.GL11 import java.awt.Color diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Int.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Int.kt deleted file mode 100644 index 1590241..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/extensions/Int.kt +++ /dev/null @@ -1,4 +0,0 @@ -package org.ender_development.catalyx.core.utils.extensions - -val Int.plural - inline get() = if(this == 1) "" else "s" diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt index 94402a0..685b755 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt @@ -1,9 +1,9 @@ package org.ender_development.catalyx.core.utils.math import net.minecraft.util.math.BlockPos -import org.ender_development.catalyx.core.utils.extensions.minus -import org.ender_development.catalyx.core.utils.extensions.plus -import org.ender_development.catalyx.core.utils.extensions.rotateY +import org.ender_development.catalyx.api.v1.extensions.minus +import org.ender_development.catalyx.api.v1.extensions.plus +import org.ender_development.catalyx.api.v1.extensions.rotateY object BlockPosUtils { /** diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt index 4197945..bdeee12 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt @@ -4,8 +4,8 @@ import com.cleanroommc.groovyscript.helper.JsonHelper import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.core.utils.extensions.getByMinSeverity -import org.ender_development.catalyx.core.utils.extensions.getBySeverity +import org.ender_development.catalyx.api.v1.extensions.getByMinSeverity +import org.ender_development.catalyx.api.v1.extensions.getBySeverity import org.ender_development.catalyx.core.utils.validation.ValidationError import org.ender_development.catalyx.core.utils.validation.ValidationResult import java.io.File diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt index 7d45a37..71648af 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt @@ -8,12 +8,12 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.client.AreaHighlighter import org.ender_development.catalyx.core.network.PacketHandler -import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.core.utils.persistence.WorldPersistentData @CatalyxModule( diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt index 9443e3e..565f797 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt @@ -1,8 +1,8 @@ package org.ender_development.catalyx.modules.integration +import org.ender_development.catalyx.api.v1.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference -import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.CatalyxModuleBase diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt index 4605d94..be28ba2 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt @@ -4,11 +4,11 @@ import com.cleanroommc.groovyscript.GroovyScript import com.cleanroommc.groovyscript.api.GroovyPlugin import com.cleanroommc.groovyscript.compat.mods.GroovyContainer import net.minecraftforge.fml.common.Optional +import org.ender_development.catalyx.api.v1.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.module.ModuleManager import org.ender_development.catalyx.core.utils.Mods -import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.integration.IntegrationModule diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt index 1c234d8..541f9ed 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt @@ -5,9 +5,9 @@ import mcjty.theoneprobe.apiimpl.styles.ProgressStyle import net.minecraft.block.state.IBlockState import net.minecraft.entity.player.EntityPlayer import net.minecraft.world.World +import org.ender_development.catalyx.api.v1.extensions.getRealColor import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.tiles.helper.IFluidTile -import org.ender_development.catalyx.core.utils.extensions.getRealColor import java.awt.Color internal class FluidTileProvider : IProbeInfoProvider { diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt index 45e3f63..f6df64f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt @@ -2,10 +2,10 @@ package org.ender_development.catalyx.modules.integration.top import mcjty.theoneprobe.TheOneProbe import net.minecraftforge.fml.common.event.FMLInitializationEvent +import org.ender_development.catalyx.api.v1.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.Mods -import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.integration.IntegrationModule diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt index 3b68e73..90e1b30 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt @@ -1,11 +1,11 @@ package org.ender_development.catalyx.modules.internal import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.items.CopyPasteTool -import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer // TODO rename, this name is silly, but couldn't come up with a better one right meow diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt index ac05307..16578a4 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt @@ -5,6 +5,7 @@ import net.minecraft.util.text.TextComponentString import net.minecraftforge.client.event.ClientChatEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.blocks.IOTileBlock @@ -13,7 +14,6 @@ import org.ender_development.catalyx.core.blocks.multiblock.parts.CornerBlock import org.ender_development.catalyx.core.blocks.multiblock.parts.SideBlock import org.ender_development.catalyx.core.client.AreaHighlighter import org.ender_development.catalyx.core.utils.SideUtils -import org.ender_development.catalyx.core.utils.extensions.subLogger import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.CatalyxModuleBase From da467c5ff2030c09caedfc70a8be29541b4b666b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Sun, 18 Jan 2026 17:39:06 +0100 Subject: [PATCH 23/58] Move extensions to common and refactor validation still things todo --- .../catalyx/api/v1/common/Severity.kt | 9 +++++ .../api/v1/{ => common}/extensions/Any.kt | 11 +++--- .../{ => common}/extensions/AxisAlignedBB.kt | 2 +- .../api/v1/{ => common}/extensions/Block.kt | 2 +- .../v1/{ => common}/extensions/BlockPos.kt | 2 +- .../api/v1/{ => common}/extensions/ByteBuf.kt | 2 +- .../api/v1/{ => common}/extensions/Color.kt | 2 +- .../v1/{ => common}/extensions/Container.kt | 2 +- .../extensions/EnchantmentRarity.kt | 2 +- .../{ => common}/extensions/EntityPlayer.kt | 2 +- .../{ => common}/extensions/EnumDyeColor.kt | 2 +- .../v1/{ => common}/extensions/EnumFacing.kt | 2 +- .../v1/{ => common}/extensions/EnumRarity.kt | 2 +- .../api/v1/{ => common}/extensions/Fluid.kt | 2 +- .../v1/{ => common}/extensions/FluidStack.kt | 2 +- .../{ => common}/extensions/IItemHandler.kt | 2 +- .../catalyx/api/v1/common/extensions/Int.kt | 4 +++ .../api/v1/{ => common}/extensions/Item.kt | 2 +- .../v1/{ => common}/extensions/ItemStack.kt | 2 +- .../api/v1/{ => common}/extensions/List.kt | 13 +++---- .../api/v1/{ => common}/extensions/Logger.kt | 2 +- .../{ => common}/extensions/NBTTagCompound.kt | 2 +- .../api/v1/{ => common}/extensions/Set.kt | 2 +- .../api/v1/{ => common}/extensions/String.kt | 2 +- .../{ => common}/extensions/TextFormatting.kt | 2 +- .../api/v1/{ => common}/extensions/Vec3d.kt | 2 +- .../api/v1/{ => common}/extensions/Vec3i.kt | 2 +- .../catalyx/api/v1/extensions/Int.kt | 4 --- .../v1}/validation/CommonValidators.kt | 3 +- .../catalyx/api/v1/validation/Validation.kt | 27 +++++++++++++++ .../interfaces/IFieldValidationBuilder.kt | 5 +++ .../interfaces/IValidationBuilder.kt | 5 +++ .../validation/interfaces/IValidationError.kt | 10 ++++++ .../interfaces/IValidationResult.kt | 12 +++++++ .../v1/validation/interfaces/IValidator.kt | 5 +++ .../core/blocks/multiblock/CenterBlock.kt | 2 +- .../catalyx/core/client/gui/BaseGuiTyped.kt | 4 +-- .../core/client/tesr/HudInfoRenderer.kt | 4 +-- .../catalyx/core/client/tesr/IORenderer.kt | 8 ++--- .../catalyx/core/config/ConfigParser.kt | 2 +- .../catalyx/core/module/ModuleManager.kt | 2 +- .../catalyx/core/network/ButtonPacket.kt | 4 +-- .../catalyx/core/recipes/Recipe.kt | 2 +- .../catalyx/core/recipes/RecipeBuilder.kt | 2 +- .../core/recipes/ingredients/nbt/IMatcher.kt | 2 +- .../core/recipes/validation/Validator.kt | 6 ++-- .../core/registry/CatalyxBlockRegistry.kt | 2 +- .../core/registry/CatalyxItemRegistry.kt | 2 +- .../core/registry/CatalyxProviderRegistry.kt | 2 +- .../catalyx/core/tiles/CenterTile.kt | 2 +- .../catalyx/core/tiles/TESRTile.kt | 4 +-- .../core/tiles/helper/TileStackHandler.kt | 4 +-- .../catalyx/core/utils/Delegates.kt | 2 +- .../catalyx/core/utils/RenderUtils.kt | 2 +- .../catalyx/core/utils/math/BlockPosUtils.kt | 6 ++-- .../core/utils/parser/AbstractJsonParser.kt | 34 +++++++++++-------- .../utils/parser/ParserRegistryBuilder.kt | 2 +- .../catalyx/core/utils/parser/ParsingStats.kt | 10 +++--- .../core/utils/validation/IValidator.kt | 5 --- .../core/utils/validation/ValidationError.kt | 26 -------------- .../core/utils/validation/ValidationResult.kt | 19 ----------- .../validation/FieldValidationBuilder.kt | 11 ++++-- .../validation/ValidationBuilder.kt | 20 ++++++----- .../core/validation/ValidationError.kt | 27 +++++++++++++++ .../core/validation/ValidationResult.kt | 22 ++++++++++++ .../catalyx/modules/CatalyxCoreModule.kt | 2 +- .../modules/integration/IntegrationModule.kt | 2 +- .../groovyscript/ModuleGroovyScript.kt | 2 +- .../integration/top/FluidTileProvider.kt | 2 +- .../integration/top/ModuleTheOneProbe.kt | 2 +- .../modules/internal/InternalModule.kt | 2 +- .../catalyx/modules/test/DevTestModule.kt | 2 +- 72 files changed, 250 insertions(+), 158 deletions(-) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/common/Severity.kt rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Any.kt (54%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/AxisAlignedBB.kt (93%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Block.kt (82%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/BlockPos.kt (95%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/ByteBuf.kt (93%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Color.kt (88%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Container.kt (74%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/EnchantmentRarity.kt (73%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/EntityPlayer.kt (83%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/EnumDyeColor.kt (78%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/EnumFacing.kt (96%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/EnumRarity.kt (85%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Fluid.kt (70%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/FluidStack.kt (90%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/IItemHandler.kt (94%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Int.kt rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Item.kt (82%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/ItemStack.kt (92%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/List.kt (71%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Logger.kt (77%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/NBTTagCompound.kt (90%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Set.kt (77%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/String.kt (96%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/TextFormatting.kt (79%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Vec3d.kt (76%) rename src/main/kotlin/org/ender_development/catalyx/api/v1/{ => common}/extensions/Vec3i.kt (83%) delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Int.kt rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1}/validation/CommonValidators.kt (94%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/validation/Validation.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IFieldValidationBuilder.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationBuilder.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationError.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationResult.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidator.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/utils/validation/IValidator.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationError.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationResult.kt rename src/main/kotlin/org/ender_development/catalyx/core/{utils => }/validation/FieldValidationBuilder.kt (69%) rename src/main/kotlin/org/ender_development/catalyx/core/{utils => }/validation/ValidationBuilder.kt (69%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationError.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationResult.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Severity.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Severity.kt new file mode 100644 index 0000000..609d0e7 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Severity.kt @@ -0,0 +1,9 @@ +package org.ender_development.catalyx.api.v1.common + +import org.apache.logging.log4j.Level + +enum class Severity(val loggerLevel: Level) { + WARNING(Level.WARN), + ERROR(Level.ERROR), + CRITICAL(Level.FATAL) +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Any.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Any.kt similarity index 54% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Any.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Any.kt index 7822350..cb27d63 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Any.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Any.kt @@ -1,10 +1,11 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions -import org.ender_development.catalyx.core.utils.validation.IValidator -import org.ender_development.catalyx.core.utils.validation.ValidationBuilder -import org.ender_development.catalyx.core.utils.validation.ValidationResult +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationResult +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidator +import org.ender_development.catalyx.core.validation.ValidationBuilder +import org.ender_development.catalyx.core.validation.ValidationResult -fun T?.validateWith(vararg validators: IValidator): ValidationResult { +fun T?.validateWith(vararg validators: IValidator): IValidationResult { val builder = ValidationBuilder() val error = validators.any { diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/AxisAlignedBB.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/AxisAlignedBB.kt similarity index 93% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/AxisAlignedBB.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/AxisAlignedBB.kt index 94cfc05..e3ba858 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/AxisAlignedBB.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/AxisAlignedBB.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.util.math.AxisAlignedBB diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Block.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Block.kt similarity index 82% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Block.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Block.kt index 9d06141..9114281 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Block.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Block.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.block.Block import net.minecraft.item.ItemStack diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/BlockPos.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/BlockPos.kt similarity index 95% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/BlockPos.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/BlockPos.kt index 7931a88..247920d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/BlockPos.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/BlockPos.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.entity.Entity import net.minecraft.util.EnumFacing diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ByteBuf.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ByteBuf.kt similarity index 93% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ByteBuf.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ByteBuf.kt index a45189b..96e5a4c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ByteBuf.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ByteBuf.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import io.netty.buffer.ByteBuf import net.minecraft.item.ItemStack diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Color.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Color.kt similarity index 88% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Color.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Color.kt index afb064c..53d0a58 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Color.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Color.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import java.awt.Color diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Container.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Container.kt similarity index 74% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Container.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Container.kt index b872dad..41dff5c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Container.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Container.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.inventory.Container import net.minecraft.inventory.Slot diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnchantmentRarity.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnchantmentRarity.kt similarity index 73% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnchantmentRarity.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnchantmentRarity.kt index 3dda1fa..10018c8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnchantmentRarity.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnchantmentRarity.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.enchantment.Enchantment import net.minecraft.item.EnumRarity diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EntityPlayer.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EntityPlayer.kt similarity index 83% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EntityPlayer.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EntityPlayer.kt index b7e4e8d..28500b4 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EntityPlayer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EntityPlayer.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.client.entity.EntityPlayerSP import net.minecraft.entity.player.EntityPlayer diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumDyeColor.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumDyeColor.kt similarity index 78% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumDyeColor.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumDyeColor.kt index 66bc6b5..6f614e5 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumDyeColor.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumDyeColor.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.item.EnumDyeColor import org.ender_development.catalyx.core.utils.ColorMapping diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumFacing.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumFacing.kt similarity index 96% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumFacing.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumFacing.kt index 08d8e2a..b78c7a4 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumFacing.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumFacing.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.EnumFacing diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumRarity.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumRarity.kt similarity index 85% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumRarity.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumRarity.kt index 6229e58..fd541d7 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/EnumRarity.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumRarity.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.enchantment.Enchantment import net.minecraft.item.EnumRarity diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Fluid.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Fluid.kt similarity index 70% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Fluid.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Fluid.kt index f20b157..569e1b6 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Fluid.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Fluid.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraftforge.fluids.Fluid import net.minecraftforge.fluids.FluidStack diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/FluidStack.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/FluidStack.kt similarity index 90% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/FluidStack.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/FluidStack.kt index 9354d22..7d4b0ff 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/FluidStack.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/FluidStack.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraftforge.fluids.FluidRegistry import net.minecraftforge.fluids.FluidStack diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/IItemHandler.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/IItemHandler.kt similarity index 94% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/IItemHandler.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/IItemHandler.kt index 668cdce..ee7b57c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/IItemHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/IItemHandler.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.item.ItemStack import net.minecraftforge.items.IItemHandler diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Int.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Int.kt new file mode 100644 index 0000000..5107ab8 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Int.kt @@ -0,0 +1,4 @@ +package org.ender_development.catalyx.api.v1.common.extensions + +val Int.plural + inline get() = if(this == 1) "" else "s" diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Item.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Item.kt similarity index 82% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Item.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Item.kt index d2d44e7..82f6c5e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Item.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Item.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.item.Item import net.minecraft.item.ItemStack diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ItemStack.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt similarity index 92% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ItemStack.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt index 3ff4df2..564f0a9 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/ItemStack.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.item.ItemStack import net.minecraft.item.crafting.Ingredient diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/List.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt similarity index 71% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/List.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt index 28ec76b..3af20d3 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/List.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt @@ -1,14 +1,15 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import com.google.common.collect.ImmutableList import it.unimi.dsi.fastutil.objects.ObjectLists import net.minecraft.item.ItemStack import net.minecraftforge.fluids.FluidStack import net.minecraftforge.oredict.OreDictionary -import org.ender_development.catalyx.core.utils.validation.ValidationError -import org.ender_development.catalyx.core.utils.validation.ValidationResult +import org.ender_development.catalyx.api.v1.common.Severity +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationError +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationResult fun List.containsItem(stack: ItemStack, strict: Boolean = false) = any { OreDictionary.itemMatches(it, stack, strict) } @@ -19,7 +20,7 @@ fun List.toImmutableList(): ImmutableList = fun List.toSingletonList(): List = ObjectLists.singleton(this[0]) -fun List.validateEach(validator: (idx: Int, T) -> ValidationResult) = +fun List.validateEach(validator: (idx: Int, T) -> IValidationResult) = mapIndexed(validator) @JvmName("copyOfIS") @@ -38,10 +39,10 @@ inline fun List.copyOf() = inline fun List.mapUnique(transform: (T) -> R) = mapTo(hashSetOf(), transform) -fun List.getBySeverity(severity: ValidationError.Severity) = +fun List.getBySeverity(severity: Severity) = filter { it.severity == severity } -fun List.getByMinSeverity(severity: ValidationError.Severity) = +fun List.getByMinSeverity(severity: Severity) = filter { it.severity >= severity } /** diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Logger.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Logger.kt similarity index 77% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Logger.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Logger.kt index 7cafbd5..e286ad5 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Logger.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Logger.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/NBTTagCompound.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/NBTTagCompound.kt similarity index 90% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/NBTTagCompound.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/NBTTagCompound.kt index 9a01020..19e077e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/NBTTagCompound.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/NBTTagCompound.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.nbt.NBTTagCompound import net.minecraft.nbt.NBTTagLongArray diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Set.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Set.kt similarity index 77% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Set.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Set.kt index 3849df6..d06d75d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Set.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Set.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import it.unimi.dsi.fastutil.objects.ObjectSets import java.util.* diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/String.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt similarity index 96% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/String.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt index 0c66b5b..c5e233f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/String.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.block.Block import net.minecraft.client.resources.I18n diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/TextFormatting.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/TextFormatting.kt similarity index 79% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/TextFormatting.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/TextFormatting.kt index 57e50c9..003bee5 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/TextFormatting.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/TextFormatting.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.util.text.TextFormatting import org.ender_development.catalyx.core.utils.ColorMapping diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3d.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Vec3d.kt similarity index 76% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3d.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Vec3d.kt index 27639aa..83232b6 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3d.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Vec3d.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.util.math.Vec3d diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3i.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Vec3i.kt similarity index 83% rename from src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3i.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Vec3i.kt index f0d62f2..d582c3e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Vec3i.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Vec3i.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.api.v1.extensions +package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.util.math.Vec3d import net.minecraft.util.math.Vec3i diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Int.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Int.kt deleted file mode 100644 index 4289fa8..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/extensions/Int.kt +++ /dev/null @@ -1,4 +0,0 @@ -package org.ender_development.catalyx.api.v1.extensions - -val Int.plural - inline get() = if(this == 1) "" else "s" diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/CommonValidators.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt similarity index 94% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/validation/CommonValidators.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt index 6ea7edd..1f583a3 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/CommonValidators.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt @@ -1,5 +1,6 @@ -package org.ender_development.catalyx.core.utils.validation +package org.ender_development.catalyx.api.v1.validation +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidator import org.ender_development.catalyx.core.config.ConfigParser @Suppress("UNUSED") diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/Validation.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/Validation.kt new file mode 100644 index 0000000..39ea664 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/Validation.kt @@ -0,0 +1,27 @@ +package org.ender_development.catalyx.api.v1.validation + +import org.ender_development.catalyx.api.v1.common.Severity +import org.ender_development.catalyx.api.v1.validation.interfaces.IFieldValidationBuilder +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationBuilder +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationError +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationResult +import org.ender_development.catalyx.core.validation.ValidationError +import org.ender_development.catalyx.core.validation.ValidationResult + +object Validation { + fun newValidationError( + field: String? = null, + message: String, + code: String? = null, + severity: Severity = Severity.ERROR, + ): IValidationError = ValidationError(field, message, code, severity) + + fun newValidationBuilder(): IValidationBuilder = TODO() + fun newFieldValidationBuilder(): IFieldValidationBuilder = TODO() + + fun IValidationResult.success(data: T): IValidationResult + = ValidationResult.success(data) + + fun IValidationResult<*>.failure(errors: List): IValidationResult<*> + = ValidationResult.failure(errors) +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IFieldValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IFieldValidationBuilder.kt new file mode 100644 index 0000000..b8c8bef --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IFieldValidationBuilder.kt @@ -0,0 +1,5 @@ +package org.ender_development.catalyx.api.v1.validation.interfaces + +interface IFieldValidationBuilder { + // TODO +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationBuilder.kt new file mode 100644 index 0000000..6fbbe5a --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationBuilder.kt @@ -0,0 +1,5 @@ +package org.ender_development.catalyx.api.v1.validation.interfaces + +interface IValidationBuilder { + // TODO +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationError.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationError.kt new file mode 100644 index 0000000..e39341c --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationError.kt @@ -0,0 +1,10 @@ +package org.ender_development.catalyx.api.v1.validation.interfaces + +import org.ender_development.catalyx.api.v1.common.Severity + +interface IValidationError { + val field: String? + val message: String + val code: String? + val severity: Severity +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationResult.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationResult.kt new file mode 100644 index 0000000..39e2683 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationResult.kt @@ -0,0 +1,12 @@ +package org.ender_development.catalyx.api.v1.validation.interfaces + +interface IValidationResult { + val data: T? + val errors: List + val success: Boolean + get() = errors.isEmpty() + val failure: Boolean + get() = !success + val errorMessages: List + get() = errors.map(IValidationError::message) +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidator.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidator.kt new file mode 100644 index 0000000..0913199 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidator.kt @@ -0,0 +1,5 @@ +package org.ender_development.catalyx.api.v1.validation.interfaces + +fun interface IValidator { + fun validate(value: T): Boolean +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/multiblock/CenterBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/multiblock/CenterBlock.kt index e07d0cd..edf9c94 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/multiblock/CenterBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/multiblock/CenterBlock.kt @@ -8,7 +8,7 @@ import net.minecraft.tileentity.TileEntity import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.world.World -import org.ender_development.catalyx.api.v1.extensions.getHorizontalSurroundings +import org.ender_development.catalyx.api.v1.common.extensions.getHorizontalSurroundings import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.blocks.BaseRotatableTileBlock diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt index 8ba1762..f1d42ab 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt @@ -5,8 +5,8 @@ import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.client.renderer.GlStateManager import net.minecraft.inventory.Container import net.minecraft.util.ResourceLocation -import org.ender_development.catalyx.api.v1.extensions.get -import org.ender_development.catalyx.api.v1.extensions.translate +import org.ender_development.catalyx.api.v1.common.extensions.get +import org.ender_development.catalyx.api.v1.common.extensions.translate import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.client.button.AbstractButtonWrapper import org.ender_development.catalyx.core.client.button.PauseButtonWrapper diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt index 8775520..f4b9c74 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt @@ -4,8 +4,8 @@ import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.EnumFacing import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -import org.ender_development.catalyx.api.v1.extensions.getFacingFromEntity -import org.ender_development.catalyx.api.v1.extensions.glRotate +import org.ender_development.catalyx.api.v1.common.extensions.getFacingFromEntity +import org.ender_development.catalyx.api.v1.common.extensions.glRotate import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.helper.HudInfoLine import org.ender_development.catalyx.core.tiles.helper.IHudInfoProvider diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/IORenderer.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/IORenderer.kt index ba1e35e..9ced2d0 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/IORenderer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/IORenderer.kt @@ -6,10 +6,10 @@ import net.minecraft.util.EnumFacing import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -import org.ender_development.catalyx.api.v1.extensions.glOffsetX -import org.ender_development.catalyx.api.v1.extensions.glOffsetZ -import org.ender_development.catalyx.api.v1.extensions.glRotate -import org.ender_development.catalyx.api.v1.extensions.glRotationAngle +import org.ender_development.catalyx.api.v1.common.extensions.glOffsetX +import org.ender_development.catalyx.api.v1.common.extensions.glOffsetZ +import org.ender_development.catalyx.api.v1.common.extensions.glRotate +import org.ender_development.catalyx.api.v1.common.extensions.glRotationAngle import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.blocks.helper.IOType import org.ender_development.catalyx.core.tiles.BaseTile diff --git a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt index 05f3282..baecb95 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt @@ -5,7 +5,7 @@ import net.minecraft.block.state.IBlockState import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.util.ResourceLocation -import org.ender_development.catalyx.api.v1.extensions.modLoaded +import org.ender_development.catalyx.api.v1.common.extensions.modLoaded import org.ender_development.catalyx.core.config.ConfigParser.ConfigBlockState.Companion.IGNORE_META import java.util.* diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt index 461292e..71724c7 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt @@ -11,7 +11,7 @@ import net.minecraftforge.fml.common.ModContainer import net.minecraftforge.fml.common.discovery.ASMDataTable import net.minecraftforge.fml.common.event.* import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.modLoaded +import org.ender_development.catalyx.api.v1.common.extensions.modLoaded import org.ender_development.catalyx.api.v1.modules.Modules import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModuleContainer diff --git a/src/main/kotlin/org/ender_development/catalyx/core/network/ButtonPacket.kt b/src/main/kotlin/org/ender_development/catalyx/core/network/ButtonPacket.kt index b4eddfd..6c4579d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/network/ButtonPacket.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/network/ButtonPacket.kt @@ -8,8 +8,8 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler import net.minecraftforge.fml.common.network.simpleimpl.MessageContext import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.readString -import org.ender_development.catalyx.api.v1.extensions.writeString +import org.ender_development.catalyx.api.v1.common.extensions.readString +import org.ender_development.catalyx.api.v1.common.extensions.writeString import org.ender_development.catalyx.core.client.button.AbstractButtonWrapper import org.ender_development.catalyx.core.tiles.helper.IButtonTile diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt index a7bf62d..516e757 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt @@ -7,7 +7,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler import net.minecraftforge.items.IItemHandlerModifiable import net.minecraftforge.items.ItemHandlerHelper import net.minecraftforge.oredict.OreDictionary -import org.ender_development.catalyx.api.v1.extensions.copyOf +import org.ender_development.catalyx.api.v1.common.extensions.copyOf import org.ender_development.catalyx.core.recipes.chance.output.ChancedFluidOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedItemOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedOutputList diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt index 863d444..2081220 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt @@ -4,7 +4,7 @@ import com.cleanroommc.groovyscript.api.GroovyLog import net.minecraft.item.ItemStack import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fml.common.Optional -import org.ender_development.catalyx.api.v1.extensions.plural +import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.core.recipes.chance.output.ChancedFluidOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedItemOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedOutputList diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt index 02d4427..4b3201a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt @@ -3,7 +3,7 @@ package org.ender_development.catalyx.core.recipes.ingredients.nbt import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.fluids.FluidStack -import org.ender_development.catalyx.api.v1.extensions.getLongArray +import org.ender_development.catalyx.api.v1.common.extensions.getLongArray interface IMatcher { companion object { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/validation/Validator.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/validation/Validator.kt index 55e1397..c7f6492 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/validation/Validator.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/validation/Validator.kt @@ -2,11 +2,11 @@ package org.ender_development.catalyx.core.recipes.validation import org.apache.logging.log4j.Logger import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.validateWith -import org.ender_development.catalyx.core.utils.validation.ValidationError +import org.ender_development.catalyx.api.v1.common.extensions.validateWith +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationError class Validator { - private val errors = mutableListOf() + private val errors = mutableListOf() fun error(condition: Boolean, message: String) = errors.addAll(message.validateWith({ !condition }).errors) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt index 3e5972a..eb7fc89 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt @@ -6,7 +6,7 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.plural +import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.api.v1.registry.IBlockProvider import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.core.Reference diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt index c9f5bda..b5c95a2 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt @@ -5,7 +5,7 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.plural +import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.api.v1.registry.IItemProvider import org.ender_development.catalyx.core.Reference diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt index 3f4d039..651a50b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt @@ -1,7 +1,7 @@ package org.ender_development.catalyx.core.registry import net.minecraft.util.ResourceLocation -import org.ender_development.catalyx.api.v1.extensions.modLoaded +import org.ender_development.catalyx.api.v1.common.extensions.modLoaded import org.ender_development.catalyx.api.v1.registry.ICatalyxProviderRegistry import org.ender_development.catalyx.api.v1.registry.IProvider diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt index 6ad2837..8f8280c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt @@ -7,7 +7,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.world.World import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.getHorizontalSurroundings +import org.ender_development.catalyx.api.v1.common.extensions.getHorizontalSurroundings import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.blocks.multiblock.IMultiblockEdge import org.ender_development.catalyx.core.blocks.multiblock.IMultiblockTile diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/TESRTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/TESRTile.kt index 5d142c1..735ce54 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/TESRTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/TESRTile.kt @@ -4,8 +4,8 @@ import net.minecraft.client.Minecraft import net.minecraft.util.EnumFacing import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -import org.ender_development.catalyx.api.v1.extensions.relativeDirectionTo -import org.ender_development.catalyx.api.v1.extensions.withAlpha +import org.ender_development.catalyx.api.v1.common.extensions.relativeDirectionTo +import org.ender_development.catalyx.api.v1.common.extensions.withAlpha import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.client.tesr.AbstractTESRenderer import org.ender_development.catalyx.core.client.tesr.HudInfoRenderer diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt index 6bccb1b..26eeac1 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt @@ -3,8 +3,8 @@ package org.ender_development.catalyx.core.tiles.helper import net.minecraft.item.ItemStack import net.minecraft.util.EnumFacing import net.minecraftforge.items.ItemStackHandler -import org.ender_development.catalyx.api.v1.extensions.get -import org.ender_development.catalyx.api.v1.extensions.tryInsertInto +import org.ender_development.catalyx.api.v1.common.extensions.get +import org.ender_development.catalyx.api.v1.common.extensions.tryInsertInto import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.BaseTile.Companion.ITEM_CAP diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt index 64a6808..2dfe66f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt @@ -1,6 +1,6 @@ package org.ender_development.catalyx.core.utils -import org.ender_development.catalyx.api.v1.extensions.modLoaded +import org.ender_development.catalyx.api.v1.common.extensions.modLoaded import kotlin.properties.ReadOnlyProperty import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt index a13f1c5..d1d4d63 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt @@ -12,7 +12,7 @@ import net.minecraft.util.ResourceLocation import net.minecraftforge.fluids.Fluid import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidTank -import org.ender_development.catalyx.api.v1.extensions.destructFloat +import org.ender_development.catalyx.api.v1.common.extensions.destructFloat import org.lwjgl.opengl.GL11 import java.awt.Color diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt index 685b755..70d1a0b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt @@ -1,9 +1,9 @@ package org.ender_development.catalyx.core.utils.math import net.minecraft.util.math.BlockPos -import org.ender_development.catalyx.api.v1.extensions.minus -import org.ender_development.catalyx.api.v1.extensions.plus -import org.ender_development.catalyx.api.v1.extensions.rotateY +import org.ender_development.catalyx.api.v1.common.extensions.minus +import org.ender_development.catalyx.api.v1.common.extensions.plus +import org.ender_development.catalyx.api.v1.common.extensions.rotateY object BlockPosUtils { /** diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt index bdeee12..54c7b58 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt @@ -4,10 +4,12 @@ import com.cleanroommc.groovyscript.helper.JsonHelper import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.getByMinSeverity -import org.ender_development.catalyx.api.v1.extensions.getBySeverity -import org.ender_development.catalyx.core.utils.validation.ValidationError -import org.ender_development.catalyx.core.utils.validation.ValidationResult +import org.ender_development.catalyx.api.v1.common.Severity +import org.ender_development.catalyx.api.v1.common.extensions.getByMinSeverity +import org.ender_development.catalyx.api.v1.common.extensions.getBySeverity +import org.ender_development.catalyx.api.v1.validation.Validation.newValidationError +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationError +import org.ender_development.catalyx.core.validation.ValidationResult import java.io.File import java.io.FileReader import java.io.FileWriter @@ -35,18 +37,22 @@ abstract class AbstractJsonParser : IParser { val results = rawData.map(::sanitize) val successfulItems = mutableListOf() - val allErrors = mutableListOf() - val allWarnings = mutableListOf() + val allErrors = mutableListOf() + val allWarnings = mutableListOf() results.forEachIndexed { idx, result -> when { result.success -> successfulItems.add(result.data!!) result.failure -> { - val errors = result.errors.getByMinSeverity(ValidationError.Severity.ERROR) - val warnings = result.errors.getBySeverity(ValidationError.Severity.WARNING) - - val contextualErrors = errors.map { it.copy(message = "Item #$idx: ${it.message}") } - val contextualWarnings = warnings.map { it.copy(message = "Item #$idx: ${it.message}") } + val errors = result.errors.getByMinSeverity(Severity.ERROR) + val warnings = result.errors.getBySeverity(Severity.WARNING) + + val contextualErrors = errors.map { + newValidationError(it.field, "Item #$idx: ${it.message}", it.code, it.severity) + } + val contextualWarnings = warnings.map { + newValidationError(it.field, "Item #$idx: ${it.message}", it.code, it.severity) + } allErrors.addAll(contextualErrors) allWarnings.addAll(contextualWarnings) logValidationIssues(idx, contextualErrors, contextualWarnings) @@ -70,7 +76,7 @@ abstract class AbstractJsonParser : IParser { override val stats: ParsingStats get() = lastParsingStats - private fun logValidationIssues(itemIndex: Int, errors: List, warnings: List) { + private fun logValidationIssues(itemIndex: Int, errors: List, warnings: List) { if(errors.isNotEmpty()) { Catalyx.LOGGER.error("❌ Failed to parse item $itemIndex from $filePath:") errors.forEach { Catalyx.LOGGER.error(" $it") } @@ -94,8 +100,8 @@ abstract class AbstractJsonParser : IParser { if(stats.hasErrors) { Catalyx.LOGGER.info(" 🔍 Validation errors: ${stats.errors.size}") - val criticalErrors = stats.errors.getBySeverity(ValidationError.Severity.CRITICAL) - val regularErrors = stats.errors.getBySeverity(ValidationError.Severity.ERROR) + val criticalErrors = stats.errors.getBySeverity(Severity.CRITICAL) + val regularErrors = stats.errors.getBySeverity(Severity.ERROR) if(criticalErrors.isNotEmpty()) Catalyx.LOGGER.info(" 🚨 Critical: ${criticalErrors.size}") diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParserRegistryBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParserRegistryBuilder.kt index 01e25a0..d71112c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParserRegistryBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParserRegistryBuilder.kt @@ -1,7 +1,7 @@ package org.ender_development.catalyx.core.utils.parser import com.google.gson.reflect.TypeToken -import org.ender_development.catalyx.core.utils.validation.ValidationResult +import org.ender_development.catalyx.core.validation.ValidationResult class ParserRegistryBuilder { private val registry = ParserRegistry() diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParsingStats.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParsingStats.kt index 713644d..6fee0ef 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParsingStats.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParsingStats.kt @@ -1,19 +1,19 @@ package org.ender_development.catalyx.core.utils.parser -import org.ender_development.catalyx.core.utils.validation.ValidationError +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationError data class ParsingStats( val totalItems: Int = 0, val successfulItems: Int = 0, val failedItems: Int = 0, - val errors: List = emptyList(), - val warnings: List = emptyList() + val errors: List = emptyList(), + val warnings: List = emptyList() ) { val hasErrors = errors.isNotEmpty() val hasWarnings = warnings.isNotEmpty() val successRate = if(totalItems == 0) .0 else successfulItems.toDouble() / totalItems - val errorMessages = errors.map(ValidationError::message) - val warningMessages = warnings.map(ValidationError::message) + val errorMessages = errors.map(IValidationError::message) + val warningMessages = warnings.map(IValidationError::message) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/IValidator.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/IValidator.kt deleted file mode 100644 index 769dc6d..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/IValidator.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.ender_development.catalyx.core.utils.validation - -fun interface IValidator { - fun validate(value: T): Boolean -} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationError.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationError.kt deleted file mode 100644 index 62e662e..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationError.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.ender_development.catalyx.core.utils.validation - -import org.apache.logging.log4j.Level -import org.apache.logging.log4j.Logger -import org.ender_development.catalyx.Catalyx - -@Suppress("UNUSED") -data class ValidationError(val field: String? = null, val message: String, val code: String? = null, val severity: Severity = Severity.ERROR) { - enum class Severity(val loggerLevel: Level) { - WARNING(Level.WARN), - ERROR(Level.ERROR), - CRITICAL(Level.FATAL) - } - - override fun toString(): String { - val prefix = when(severity) { - Severity.WARNING -> "⚠️" - Severity.ERROR -> "❌" - Severity.CRITICAL -> "🚨" - } - return field?.let { "$prefix [$field]: $message" } ?: "$prefix: $message" - } - - fun log(logger: Logger = Catalyx.LOGGER) = - logger.log(severity.loggerLevel, toString()) -} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationResult.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationResult.kt deleted file mode 100644 index 42bbba5..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationResult.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.ender_development.catalyx.core.utils.validation - -@Suppress("UNUSED") -class ValidationResult private constructor( - val data: T?, - val errors: List -) { - val success: Boolean = errors.isEmpty() - val failure: Boolean = !success - val errorMessages: List = errors.map(ValidationError::message) - - companion object { - fun success(data: T): ValidationResult = - ValidationResult(data, emptyList()) - - fun failure(errors: List): ValidationResult = - ValidationResult(null, errors) - } -} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/FieldValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt similarity index 69% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/validation/FieldValidationBuilder.kt rename to src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt index 35b6e42..78761c1 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/FieldValidationBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt @@ -1,7 +1,14 @@ -package org.ender_development.catalyx.core.utils.validation +package org.ender_development.catalyx.core.validation + +import org.ender_development.catalyx.api.v1.validation.interfaces.IFieldValidationBuilder +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidator @Suppress("UNUSED") -class FieldValidationBuilder(value: V?, private val fieldName: String, private val parentBuilder: ValidationBuilder<*>) { +class FieldValidationBuilder( + value: V?, + private val fieldName: String, + private val parentBuilder: ValidationBuilder<*> +) : IFieldValidationBuilder { private var currentValue: V? = value fun validate(validator: IValidator): FieldValidationBuilder { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt similarity index 69% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationBuilder.kt rename to src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt index 0c00e79..9943b2e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/validation/ValidationBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt @@ -1,7 +1,11 @@ -package org.ender_development.catalyx.core.utils.validation +package org.ender_development.catalyx.core.validation + +import org.ender_development.catalyx.api.v1.common.Severity +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationBuilder +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidator @Suppress("UNUSED") -class ValidationBuilder { +class ValidationBuilder : IValidationBuilder { internal val errors = mutableListOf() private var target: T? = null @@ -23,20 +27,20 @@ class ValidationBuilder { else -> value } - fun rule(condition: Boolean, message: String, severity: ValidationError.Severity = ValidationError.Severity.ERROR) { + fun rule(condition: Boolean, message: String, severity: Severity = Severity.ERROR) { if (!condition) errors.add(ValidationError(null, message, null, severity)) } - fun addError(field: String? = null, message: String, code: String? = null, severity: ValidationError.Severity = ValidationError.Severity.ERROR) = + fun addError(field: String? = null, message: String, code: String? = null, severity: Severity = Severity.ERROR) = errors.add(ValidationError(field, message, code, severity)) fun addWarning(field: String? = null, message: String, code: String? = null) = - addError(field, message, code, ValidationError.Severity.WARNING) + addError(field, message, code, Severity.WARNING) @Suppress("UNCHECKED_CAST") fun build(data: T?): ValidationResult { - val onlyWarnings = errors.none { it.severity != ValidationError.Severity.WARNING } + val onlyWarnings = errors.none { it.severity != Severity.WARNING } return if (onlyWarnings && data != null) ValidationResult.success(data) @@ -48,10 +52,10 @@ class ValidationBuilder { } fun hasErrors(): Boolean = - errors.any { it.severity != ValidationError.Severity.WARNING } + errors.any { it.severity != Severity.WARNING } fun hasWarnings(): Boolean = - errors.any { it.severity == ValidationError.Severity.WARNING } + errors.any { it.severity == Severity.WARNING } fun getErrors(): List = errors diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationError.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationError.kt new file mode 100644 index 0000000..5ced80d --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationError.kt @@ -0,0 +1,27 @@ +package org.ender_development.catalyx.core.validation + +import org.apache.logging.log4j.Logger +import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.common.Severity +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationError + +@Suppress("UNUSED") +data class ValidationError( + override val field: String? = null, + override val message: String, + override val code: String? = null, + override val severity: Severity = Severity.ERROR +) : IValidationError { + override fun toString(): String { + val prefix = when(severity) { + Severity.WARNING -> "⚠️" + Severity.ERROR -> "❌" + Severity.CRITICAL -> "🚨" + } + return field?.let { "$prefix [$field]: $message" } ?: "$prefix: $message" + } + + // TODO Add to IValidationError if publicity is needed + fun log(logger: Logger = Catalyx.LOGGER) = + logger.log(severity.loggerLevel, toString()) +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationResult.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationResult.kt new file mode 100644 index 0000000..b3adaad --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationResult.kt @@ -0,0 +1,22 @@ +package org.ender_development.catalyx.core.validation + +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationError +import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationResult + +@Suppress("UNUSED") +class ValidationResult private constructor( + override val data: T?, + override val errors: List +) : IValidationResult { + override val success: Boolean = errors.isEmpty() + override val failure: Boolean = !success + override val errorMessages: List = errors.map(IValidationError::message) + + companion object { + fun success(data: T): ValidationResult = + ValidationResult(data, emptyList()) + + fun failure(errors: List) = + ValidationResult(null, errors) + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt index 71648af..11cf8e3 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxCoreModule.kt @@ -8,7 +8,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.subLogger +import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule import org.ender_development.catalyx.core.Reference diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt index 565f797..fbe6f8b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/IntegrationModule.kt @@ -1,6 +1,6 @@ package org.ender_development.catalyx.modules.integration -import org.ender_development.catalyx.api.v1.extensions.subLogger +import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt index be28ba2..c1f3e53 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt @@ -4,7 +4,7 @@ import com.cleanroommc.groovyscript.GroovyScript import com.cleanroommc.groovyscript.api.GroovyPlugin import com.cleanroommc.groovyscript.compat.mods.GroovyContainer import net.minecraftforge.fml.common.Optional -import org.ender_development.catalyx.api.v1.extensions.subLogger +import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.module.ModuleManager diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt index 541f9ed..ada6b4c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt @@ -5,7 +5,7 @@ import mcjty.theoneprobe.apiimpl.styles.ProgressStyle import net.minecraft.block.state.IBlockState import net.minecraft.entity.player.EntityPlayer import net.minecraft.world.World -import org.ender_development.catalyx.api.v1.extensions.getRealColor +import org.ender_development.catalyx.api.v1.common.extensions.getRealColor import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.tiles.helper.IFluidTile import java.awt.Color diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt index f6df64f..44bd735 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt @@ -2,7 +2,7 @@ package org.ender_development.catalyx.modules.integration.top import mcjty.theoneprobe.TheOneProbe import net.minecraftforge.fml.common.event.FMLInitializationEvent -import org.ender_development.catalyx.api.v1.extensions.subLogger +import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.utils.Mods diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt index 90e1b30..b642192 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt @@ -1,7 +1,7 @@ package org.ender_development.catalyx.modules.internal import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.subLogger +import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule import org.ender_development.catalyx.core.Reference diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt index 16578a4..cffd471 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt @@ -5,7 +5,7 @@ import net.minecraft.util.text.TextComponentString import net.minecraftforge.client.event.ClientChatEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.extensions.subLogger +import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.blocks.IOTileBlock From 86aacf8e1c7959c9e903eef69f53d2bc8d62616f Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 18 Jan 2026 19:50:30 +0100 Subject: [PATCH 24/58] do a bit of validation eating why is it now a habit that I see a commit and then I see that the code needs a bit of eating, instead of the other way around anyways also includes a custom find-in-files profile that only searches the actual mod source code (and honestly that's something I could throw into the template soon-ish ;p), despite .idea being git-ignored --- .idea/scopes/Catalyx_Source.xml | 3 +++ .../catalyx/api/v1/common/Severity.kt | 8 ++++---- .../api/v1/validation/CommonValidators.kt | 6 +++--- .../catalyx/api/v1/validation/Validation.kt | 16 ++++++--------- .../validation/interfaces/IValidationError.kt | 4 ++++ .../catalyx/core/blocks/BaseBlock.kt | 12 +++++------ .../core/validation/FieldValidationBuilder.kt | 12 ++++------- .../core/validation/ValidationBuilder.kt | 9 ++++----- .../core/validation/ValidationError.kt | 20 ++++++++----------- .../core/validation/ValidationResult.kt | 18 +++++++---------- 10 files changed, 49 insertions(+), 59 deletions(-) create mode 100644 .idea/scopes/Catalyx_Source.xml diff --git a/.idea/scopes/Catalyx_Source.xml b/.idea/scopes/Catalyx_Source.xml new file mode 100644 index 0000000..196bc63 --- /dev/null +++ b/.idea/scopes/Catalyx_Source.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Severity.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Severity.kt index 609d0e7..a735660 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Severity.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Severity.kt @@ -2,8 +2,8 @@ package org.ender_development.catalyx.api.v1.common import org.apache.logging.log4j.Level -enum class Severity(val loggerLevel: Level) { - WARNING(Level.WARN), - ERROR(Level.ERROR), - CRITICAL(Level.FATAL) +enum class Severity(val loggerLevel: Level, val emoji: String) { + WARNING(Level.WARN, "⚠️"), + ERROR(Level.ERROR, "❌"), + CRITICAL(Level.FATAL, "🚨") } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt index 1f583a3..7bbf5c8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt @@ -35,12 +35,12 @@ object CommonValidators { fun atMost(value: Number): IValidator = IValidator { it != null && it.toDouble() <= value.toDouble() } - fun oneOf(vararg values: T): IValidator = - IValidator { it != null && values.contains(it) } + fun oneOf(vararg allowed: T): IValidator = + IValidator { it != null && it in allowed } fun listAll(elementValidator: IValidator): IValidator?> = IValidator { list -> - list != null && list.all { elementValidator.validate(it) } + list != null && list.all(elementValidator::validate) } fun mapAll(keyValidator: IValidator, valueValidator: IValidator): IValidator?> = diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/Validation.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/Validation.kt index 39ea664..84856ed 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/Validation.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/Validation.kt @@ -9,19 +9,15 @@ import org.ender_development.catalyx.core.validation.ValidationError import org.ender_development.catalyx.core.validation.ValidationResult object Validation { - fun newValidationError( - field: String? = null, - message: String, - code: String? = null, - severity: Severity = Severity.ERROR, - ): IValidationError = ValidationError(field, message, code, severity) + fun newValidationError(field: String? = null, message: String, code: String? = null, severity: Severity = Severity.ERROR): IValidationError = + ValidationError(field, message, code, severity) fun newValidationBuilder(): IValidationBuilder = TODO() fun newFieldValidationBuilder(): IFieldValidationBuilder = TODO() - fun IValidationResult.success(data: T): IValidationResult - = ValidationResult.success(data) + fun IValidationResult.success(data: T): IValidationResult = + ValidationResult.success(data) - fun IValidationResult<*>.failure(errors: List): IValidationResult<*> - = ValidationResult.failure(errors) + fun IValidationResult.failure(errors: List): IValidationResult = + ValidationResult.failure(errors) } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationError.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationError.kt index e39341c..e61f443 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationError.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IValidationError.kt @@ -1,5 +1,6 @@ package org.ender_development.catalyx.api.v1.validation.interfaces +import org.apache.logging.log4j.Logger import org.ender_development.catalyx.api.v1.common.Severity interface IValidationError { @@ -7,4 +8,7 @@ interface IValidationError { val message: String val code: String? val severity: Severity + + fun log(logger: Logger) = + logger.log(severity.loggerLevel, toString()) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt index 7085c65..9189e79 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt @@ -98,12 +98,12 @@ open class BaseBlock(val mod: ICatalyxMod, name: String, material: Material = Ma override fun getBlockFaceShape(worldIn: IBlockAccess, state: IBlockState, pos: BlockPos, face: EnumFacing): BlockFaceShape { val aabb = getAABB(state) return when (face) { - EnumFacing.UP -> if (aabb.maxY >= 1.0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED - EnumFacing.DOWN -> if (aabb.minY <= 0.0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED - EnumFacing.NORTH -> if (aabb.minZ <= 0.0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED - EnumFacing.SOUTH -> if (aabb.maxZ >= 1.0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED - EnumFacing.WEST -> if (aabb.minX <= 0.0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED - EnumFacing.EAST -> if (aabb.maxX >= 1.0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED + EnumFacing.UP -> if(aabb.maxY >= 1.0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED + EnumFacing.DOWN -> if(aabb.minY <= .0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED + EnumFacing.NORTH -> if(aabb.minZ <= .0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED + EnumFacing.SOUTH -> if(aabb.maxZ >= 1.0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED + EnumFacing.WEST -> if(aabb.minX <= .0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED + EnumFacing.EAST -> if(aabb.maxX >= 1.0) BlockFaceShape.SOLID else BlockFaceShape.UNDEFINED } } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt index 78761c1..1b1682a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt @@ -3,19 +3,15 @@ package org.ender_development.catalyx.core.validation import org.ender_development.catalyx.api.v1.validation.interfaces.IFieldValidationBuilder import org.ender_development.catalyx.api.v1.validation.interfaces.IValidator -@Suppress("UNUSED") -class FieldValidationBuilder( - value: V?, - private val fieldName: String, - private val parentBuilder: ValidationBuilder<*> -) : IFieldValidationBuilder { +@Suppress("unused") +class FieldValidationBuilder(value: V?, private val fieldName: String, private val parentBuilder: ValidationBuilder<*>) : IFieldValidationBuilder { private var currentValue: V? = value fun validate(validator: IValidator): FieldValidationBuilder { - if (currentValue != null && !validator.validate(currentValue)) { + if(currentValue != null && !validator.validate(currentValue)) { parentBuilder.addError(fieldName, "Validation failed for field '$fieldName'") currentValue = null - } else if (currentValue == null && !validator.validate(null)) + } else if(currentValue == null && !validator.validate(null)) parentBuilder.addError(fieldName, "Field '$fieldName' is required") return this } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt index 9943b2e..f488717 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt @@ -28,7 +28,7 @@ class ValidationBuilder : IValidationBuilder { } fun rule(condition: Boolean, message: String, severity: Severity = Severity.ERROR) { - if (!condition) + if(!condition) errors.add(ValidationError(null, message, null, severity)) } @@ -38,17 +38,16 @@ class ValidationBuilder : IValidationBuilder { fun addWarning(field: String? = null, message: String, code: String? = null) = addError(field, message, code, Severity.WARNING) - @Suppress("UNCHECKED_CAST") fun build(data: T?): ValidationResult { val onlyWarnings = errors.none { it.severity != Severity.WARNING } - return if (onlyWarnings && data != null) + return if(onlyWarnings && data != null) ValidationResult.success(data) else { - if (data == null && errors.isEmpty()) + if(data == null && errors.isEmpty()) errors.add(ValidationError(message = "Data construction failed")) ValidationResult.failure(errors) - } as ValidationResult + } } fun hasErrors(): Boolean = diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationError.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationError.kt index 5ced80d..36bc3b5 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationError.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationError.kt @@ -1,27 +1,23 @@ package org.ender_development.catalyx.core.validation -import org.apache.logging.log4j.Logger import org.ender_development.catalyx.Catalyx import org.ender_development.catalyx.api.v1.common.Severity import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationError -@Suppress("UNUSED") data class ValidationError( override val field: String? = null, override val message: String, override val code: String? = null, override val severity: Severity = Severity.ERROR ) : IValidationError { - override fun toString(): String { - val prefix = when(severity) { - Severity.WARNING -> "⚠️" - Severity.ERROR -> "❌" - Severity.CRITICAL -> "🚨" - } - return field?.let { "$prefix [$field]: $message" } ?: "$prefix: $message" + override fun toString() = buildString { + append(severity.emoji) + if(field != null) + append(" [$field]") + append(": $message") } - // TODO Add to IValidationError if publicity is needed - fun log(logger: Logger = Catalyx.LOGGER) = - logger.log(severity.loggerLevel, toString()) + @Suppress("NOTHING_TO_INLINE") + internal inline fun log() = + log(Catalyx.LOGGER) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationResult.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationResult.kt index b3adaad..a639a3d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationResult.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationResult.kt @@ -3,20 +3,16 @@ package org.ender_development.catalyx.core.validation import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationError import org.ender_development.catalyx.api.v1.validation.interfaces.IValidationResult -@Suppress("UNUSED") -class ValidationResult private constructor( - override val data: T?, - override val errors: List -) : IValidationResult { - override val success: Boolean = errors.isEmpty() - override val failure: Boolean = !success - override val errorMessages: List = errors.map(IValidationError::message) +class ValidationResult private constructor(override val data: T?, override val errors: List) : IValidationResult { + override val success = errors.isEmpty() + override val failure = !success + override val errorMessages = errors.map(IValidationError::message) companion object { - fun success(data: T): ValidationResult = + fun success(data: T) = ValidationResult(data, emptyList()) - fun failure(errors: List) = - ValidationResult(null, errors) + fun failure(errors: List) = + ValidationResult(null, errors) } } From 5365312607f8054e1354f4929f8c73c2feaa78b9 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 18 Jan 2026 22:06:59 +0100 Subject: [PATCH 25/58] sync template --- build.gradle.kts | 5 +- buildSrc/build.gradle.kts | 4 ++ .../src/main/kotlin/plugins/IJScopeCreator.kt | 46 +++++++++++++++++++ buildSrc/src/main/kotlin/plugins/PropSync.kt | 2 + .../main/kotlin/plugins/ReferenceCreator.kt | 36 ++++++++------- .../src/main/kotlin/plugins/ScriptSync.kt | 7 ++- buildSrc/src/main/kotlin/plugins/Secrets.kt | 24 +++++----- buildSrc/src/main/kotlin/util/OnlineUtils.kt | 4 +- 8 files changed, 92 insertions(+), 36 deletions(-) create mode 100644 buildSrc/src/main/kotlin/plugins/IJScopeCreator.kt diff --git a/build.gradle.kts b/build.gradle.kts index 9dabfa9..b32f37a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,6 +22,7 @@ plugins { id("catalyx.propsync") id("catalyx.buildfilesync") id("catalyx.referencecreator") apply false + id("catalyx.ijscopecreator") id("java") id("java-library") id("maven-publish") @@ -244,8 +245,8 @@ tasks.withType { if (propertyBoolean("coremod_includes_mod")) { attributeMap["FMLCorePluginContainsFMLMod"] = "true" val currentTask = gradle.startParameter.taskNames - val validTasks = listOf("build", "prepareObfModsFolder", "runObfClient") - if (currentTask[0] in validTasks) attributeMap["ForceLoadAsMod"] = "true" + val validTasks = arrayOf("build", "prepareObfModsFolder", "runObfClient") + if (!currentTask.isEmpty() && currentTask[0] in validTasks) attributeMap["ForceLoadAsMod"] = "true" } } if (propertyBoolean("use_access_transformer")) { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 2aabfa0..8e54b45 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -41,5 +41,9 @@ gradlePlugin { id = "catalyx.referencecreator" implementationClass = "plugins.ReferenceCreator" } + create("ijScopeCreatorPlugin") { + id = "catalyx.ijscopecreator" + implementationClass = "plugins.IJScopeCreator" + } } } diff --git a/buildSrc/src/main/kotlin/plugins/IJScopeCreator.kt b/buildSrc/src/main/kotlin/plugins/IJScopeCreator.kt new file mode 100644 index 0000000..2783c89 --- /dev/null +++ b/buildSrc/src/main/kotlin/plugins/IJScopeCreator.kt @@ -0,0 +1,46 @@ +package plugins + +import org.gradle.api.Plugin +import org.gradle.api.Project +import propertyString +import util.OnlineUtils +import kotlin.io.path.createDirectories +import kotlin.io.path.createFile +import kotlin.io.path.div +import kotlin.io.path.notExists +import kotlin.io.path.writeText + +@Suppress("UNUSED") +class IJScopeCreator : Plugin { + companion object { + const val SCOPE_FILE = "Mod_Source.xml" + + private fun createIJScope(project: Project) { + if (OnlineUtils.isTemplateProject()) { + return + } + + val modName = project.propertyString("mod_name") + val filteredModName = modName.filter(Char::isLetterOrDigit) + val outputPath = project.rootDir.toPath() / ".idea" / "scopes" / SCOPE_FILE + + val ijScope = buildString { + appendLine("") + appendLine(" ") + appendLine("") + } + + if (outputPath.notExists()) { + outputPath.parent.createDirectories() + outputPath.createFile() + } + outputPath.writeText(ijScope) + Logger.info("IntelliJ scope file created at ${outputPath.normalize()}") + } + } + + override fun apply(target: Project) { + Logger.greet(this) + createIJScope(target) + } +} diff --git a/buildSrc/src/main/kotlin/plugins/PropSync.kt b/buildSrc/src/main/kotlin/plugins/PropSync.kt index e7244b3..42dd757 100644 --- a/buildSrc/src/main/kotlin/plugins/PropSync.kt +++ b/buildSrc/src/main/kotlin/plugins/PropSync.kt @@ -135,6 +135,7 @@ class PropSync : Plugin { existingLines.forEach { when { it.startsWith("#") || it.trim().isEmpty() -> lines.add(it) + it.contains("=") -> { val key = it.substringBefore("=").trim() val newValue = properties.getProperty(key) @@ -147,6 +148,7 @@ class PropSync : Plugin { updatedKeys.add(key) } ?: lines.add(it) // Keep existing line if key not in new properties } + else -> lines.add(it) } } diff --git a/buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt b/buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt index e389bcf..6095bd6 100644 --- a/buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt +++ b/buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt @@ -18,29 +18,33 @@ class ReferenceCreator : Plugin { private fun createReference(project: Project) { val properties = Loader.loadPropertyFromFile(REFERENCE_FILE) val objectName = project.propertyString("mod_name").filter(Char::isLetterOrDigit) - val reference = arrayListOf("package ${project.propertyString("tags_package")}") - reference.add("") - reference.add("internal typealias Reference = ${objectName}Reference") - reference.add("") - reference.add("/**") - reference.add(" * Auto-generated reference object containing constants from `$REFERENCE_FILE`.") - reference.add(" * Don't change this file manually as it will be overwritten.") - reference.add(" */") - reference.add("@Suppress(\"UNUSED\")") - reference.add("object ${objectName}Reference {") - properties.forEach { (key, value) -> - val eval = (if (value is String) project.evaluate(value) else value).toString() - reference.add(" const val ${key.toString().uppercase()} = ${if (eval.all(Char::isDigit) && eval.count { it == '.' } <= 1) eval else "\"$eval\""}") + val objectPath = project.propertyString("tags_package") + val reference = buildString { + appendLine("package $objectPath") + appendLine("") + appendLine("internal typealias Reference = ${objectName}Reference") + appendLine("") + appendLine("/**") + appendLine(" * Auto-generated reference object containing constants from `$REFERENCE_FILE`.") + appendLine(" * Don't change this file manually as it will be overwritten.") + appendLine(" */") + appendLine("@Suppress(\"UNUSED\")") + appendLine("object ${objectName}Reference {") + properties.forEach { (key, value) -> + val eval = (if (value is String) project.evaluate(value) else value).toString() + val value = if (eval.toDoubleOrNull() != null) eval else "\"${eval.replace("\"", "\\\"")}\"" + // TODO: instead of hardcoding 4-space indent, could probably read .editorconfig and just check + appendLine(" const val $key = $value") + } + appendLine("}") } - reference.add("}") - reference.add("") val outputPath = "${project.rootDir}/src/main/kotlin/${project.propertyString("tags_package").replace(".", "/")}/${objectName}Reference.kt" val outputFile = Path(outputPath) if (outputFile.notExists()) { outputFile.parent.createDirectories() outputFile.createFile() } - outputFile.writeText(reference.joinToString(separator = System.lineSeparator())) + outputFile.writeText(reference.replace("\n", System.lineSeparator())) Logger.info("Reference file created at ${outputPath.replace("\\", "/")}") } } diff --git a/buildSrc/src/main/kotlin/plugins/ScriptSync.kt b/buildSrc/src/main/kotlin/plugins/ScriptSync.kt index 78b23bd..33f62e1 100644 --- a/buildSrc/src/main/kotlin/plugins/ScriptSync.kt +++ b/buildSrc/src/main/kotlin/plugins/ScriptSync.kt @@ -3,8 +3,6 @@ package plugins import org.gradle.api.Plugin import org.gradle.api.Project import util.OnlineUtils -import util.OnlineUtils.isOnline -import util.OnlineUtils.shouldDisableSync class ScriptSync : Plugin { companion object { @@ -12,6 +10,7 @@ class ScriptSync : Plugin { private val syncScripts: List = listOf( "buildSrc/src/main/kotlin/plugins/DepLoader.kt", + "buildSrc/src/main/kotlin/plugins/IJScopeCreator.kt", "buildSrc/src/main/kotlin/plugins/Loader.kt", "buildSrc/src/main/kotlin/plugins/Logger.kt", "buildSrc/src/main/kotlin/plugins/PropSync.kt", @@ -31,8 +30,8 @@ class ScriptSync : Plugin { fun syncFilesFromTemplate() { Logger.banner("Searching for Files to sync!") - if (shouldDisableSync()) return Logger.info("Sync is disabled via system.") - if (!isOnline()) return Logger.warn("No internet connection detected.") + if (OnlineUtils.shouldDisableSync()) return Logger.info("Sync is disabled via system.") + if (!OnlineUtils.isOnline()) return Logger.warn("No internet connection detected.") performSync() } diff --git a/buildSrc/src/main/kotlin/plugins/Secrets.kt b/buildSrc/src/main/kotlin/plugins/Secrets.kt index c594fe7..5988694 100644 --- a/buildSrc/src/main/kotlin/plugins/Secrets.kt +++ b/buildSrc/src/main/kotlin/plugins/Secrets.kt @@ -33,32 +33,32 @@ class Secrets : Plugin { val rootSecrets = target.rootProject.file(PROPERTIES_FILE) val userSecrets = File( System.getProperty("user.home"), - ".gradle/$PROPERTIES_FILE" + ".gradle/$PROPERTIES_FILE", ) val secretsFile = when { rootSecrets.exists() -> { - if (!getOrEnvironment("DISMISS_SECRET_FILE_WARNING").toBoolean()) { - Logger.warn("Don't store secrets inside the repo tree BECAUSE IT IS FCKN DANGEROUS!") + if (System.getenv("DISMISS_SECRET_FILE_WARNING") == null) { + Logger.warn( + "Keeping the secrets file in the project root can have security implications, as such moving the '$PROPERTIES_FILE' to ~/.gradle would be recommended. Set the DISMISS_SECRET_FILE_WARNING environment variable to disable this warning at your own risk.", + ) } rootSecrets } + userSecrets.exists() -> userSecrets - else -> null - } - if (secretsFile == null) { - if (target.rootProject.file(EXAMPLE_FILE).exists()) { - Logger.warn("No '$PROPERTIES_FILE' found. Please create one in project root or even better in ~/.gradle based on '$EXAMPLE_FILE'.") + else -> { + if (target.rootProject.file(EXAMPLE_FILE).exists()) { + Logger.warn("No '$PROPERTIES_FILE' found, please create one in ~/.gradle, or in the project root, based on '$EXAMPLE_FILE'.") + } - // Needed? - //println("WARNING: No '$PROPERTIES_FILE' found in project root or ~/.gradle. Please create one based on '$EXAMPLE_FILE'.") + return } - return } + Companion.secretsFile = secretsFile.absolutePath Logger.info("Loading secrets from: ${secretsFile.absolutePath}") Loader.loadPropertyFile(secretsFile.absolutePath) - Companion.secretsFile = secretsFile.absolutePath } } diff --git a/buildSrc/src/main/kotlin/util/OnlineUtils.kt b/buildSrc/src/main/kotlin/util/OnlineUtils.kt index b3776c7..d24ad46 100644 --- a/buildSrc/src/main/kotlin/util/OnlineUtils.kt +++ b/buildSrc/src/main/kotlin/util/OnlineUtils.kt @@ -36,7 +36,7 @@ object OnlineUtils { * Checks if the current project is the template project by examining the Git remote URL. * @return `true` if the project is the template project, `false` otherwise. */ - private fun isTemplateProject(): Boolean { + fun isTemplateProject(): Boolean { val repo = FileRepositoryBuilder() .setGitDir(File(".git")) .readEnvironment() @@ -79,7 +79,7 @@ object OnlineUtils { val connection = URI.create(url).toURL().openConnection() connection.connectTimeout = CONNECTION_TIMEOUT connection.readTimeout = CONNECTION_TIMEOUT - connection.getInputStream().readBytes().toString(Charsets.UTF_8) + connection.inputStream.use { it.readBytes().toString(Charsets.UTF_8) } } catch (e: Exception) { Logger.error("Error fetching file from '$url': ${e.message}") null From 89e3250a6f3645fd68ddc2349da9ebdf4ca3b98f Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Mon, 19 Jan 2026 16:09:12 +0100 Subject: [PATCH 26/58] sync template a69c84bf63 --- .../main/kotlin/plugins/ReferenceCreator.kt | 49 ++++++++++++++++- .../src/main/kotlin/plugins/ScriptSync.kt | 53 +++++++------------ 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt b/buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt index 6095bd6..a72e730 100644 --- a/buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt +++ b/buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt @@ -15,10 +15,56 @@ class ReferenceCreator : Plugin { companion object { const val REFERENCE_FILE = "tags.properties" + /** + * Guesses the indent style based on the .editorconfig file used. + * + * If the .editorconfig file is not present, or the required values cannot be found, the default 4-space indent is returned instead. + */ + fun guessIndent(project: Project): String { + val editorconfig = project.file(".editorconfig") + if (!editorconfig.exists()) { + return " " + } + + var indentStyle = "" + var indentSize = -1 + + // this is crude and doesn't parse everything per spec https://spec.editorconfig.org/, but it's good enough + editorconfig.useLines { lines -> + for (line in lines) { + val line = line.trim() + if (line.startsWith("indent_size", true)) { + indentSize = line.substringAfter('=').trim().toIntOrNull() ?: -1 + if (indentStyle == "") { + continue + } else { + break + } + } + + if (line.startsWith("indent_style", true)) { + indentStyle = line.substringAfter('=').trim() + if (indentSize == -1) { + continue + } else { + break + } + } + } + } + + return when { + indentStyle.equals("tab", true) -> "\t" + indentStyle.equals("space", true) -> " ".repeat(if (indentSize == -1) 4 else indentSize) + else -> " " + } + } + private fun createReference(project: Project) { val properties = Loader.loadPropertyFromFile(REFERENCE_FILE) val objectName = project.propertyString("mod_name").filter(Char::isLetterOrDigit) val objectPath = project.propertyString("tags_package") + val indent = guessIndent(project) val reference = buildString { appendLine("package $objectPath") appendLine("") @@ -33,8 +79,7 @@ class ReferenceCreator : Plugin { properties.forEach { (key, value) -> val eval = (if (value is String) project.evaluate(value) else value).toString() val value = if (eval.toDoubleOrNull() != null) eval else "\"${eval.replace("\"", "\\\"")}\"" - // TODO: instead of hardcoding 4-space indent, could probably read .editorconfig and just check - appendLine(" const val $key = $value") + appendLine("${indent}const val $key = $value") } appendLine("}") } diff --git a/buildSrc/src/main/kotlin/plugins/ScriptSync.kt b/buildSrc/src/main/kotlin/plugins/ScriptSync.kt index 33f62e1..dd03e5f 100644 --- a/buildSrc/src/main/kotlin/plugins/ScriptSync.kt +++ b/buildSrc/src/main/kotlin/plugins/ScriptSync.kt @@ -6,28 +6,10 @@ import util.OnlineUtils class ScriptSync : Plugin { companion object { + const val BASE_URL = "${OnlineUtils.GITHUB_RAW_URL}/${OnlineUtils.TEMPLATE_REPO}/${OnlineUtils.TEMPLATE_BRANCH}/" + const val FILE_LIST_NAME = "buildSrc/src/main/resources/sync-file-list.txt" private lateinit var project: Project - private val syncScripts: List = listOf( - "buildSrc/src/main/kotlin/plugins/DepLoader.kt", - "buildSrc/src/main/kotlin/plugins/IJScopeCreator.kt", - "buildSrc/src/main/kotlin/plugins/Loader.kt", - "buildSrc/src/main/kotlin/plugins/Logger.kt", - "buildSrc/src/main/kotlin/plugins/PropSync.kt", - "buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt", - "buildSrc/src/main/kotlin/plugins/ScriptSync.kt", - "buildSrc/src/main/kotlin/plugins/Secrets.kt", - "buildSrc/src/main/kotlin/util/DependencyProvider.kt", - "buildSrc/src/main/kotlin/util/OnlineUtils.kt", - "buildSrc/src/main/kotlin/BaseSetup.kt", - "buildSrc/src/main/kotlin/Dependencies.kt", - "buildSrc/src/main/kotlin/PropertyExtension.kt", - "buildSrc/src/main/kotlin/Repositories.kt", - "buildSrc/build.gradle.kts", - "build.gradle.kts", - "settings.gradle.kts", - ) - fun syncFilesFromTemplate() { Logger.banner("Searching for Files to sync!") if (OnlineUtils.shouldDisableSync()) return Logger.info("Sync is disabled via system.") @@ -35,20 +17,25 @@ class ScriptSync : Plugin { performSync() } + private fun syncFile(fileName: String) { + val fileUrl = "$BASE_URL$fileName" + val remoteContent = OnlineUtils.fetchFileContent(fileUrl) ?: throw Exception("Failed to fetch content from $fileUrl") + val localFile = project.file(fileName) + val localContent = if (localFile.exists()) localFile.readText() else "" + + if (remoteContent != localContent) { + localFile.writeText(remoteContent) + Logger.info("Synchronized file: $fileName") + } else { + Logger.info("File is up-to-date: $fileName") + } + } + private fun performSync() { - val baseUrl = "${OnlineUtils.GITHUB_RAW_URL}/${OnlineUtils.TEMPLATE_REPO}/${OnlineUtils.TEMPLATE_BRANCH}/" - syncScripts.forEach { - val fileUrl = "$baseUrl$it" - val remoteContent = OnlineUtils.fetchFileContent(fileUrl) ?: throw Exception("Failed to fetch content from $fileUrl") - val localFile = project.file(it) - val localContent = if (localFile.exists()) localFile.readText() else "" - - if (remoteContent != localContent) { - localFile.writeText(remoteContent) - Logger.info("Synchronized file: $it") - } else { - Logger.info("File is up-to-date: $it") - } + syncFile(FILE_LIST_NAME) + + project.file(FILE_LIST_NAME).useLines { lines -> + lines.filter(String::isNotBlank).forEach(::syncFile) } } } From c3a18d1486f625b96d9df582536d1463c66a334c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Rehhau=C3=9Fe?= Date: Tue, 20 Jan 2026 16:56:28 +0100 Subject: [PATCH 27/58] General refactor --- .../utils => api/v1/common}/ColorMapping.kt | 2 +- .../{core/utils => api/v1/common}/DevUtils.kt | 2 +- .../catalyx/api/v1/common/Math.kt | 4 ++ .../{core/utils => api/v1/common}/Mods.kt | 2 +- .../api/v1/common/extensions/BlockPos.kt | 40 +++++++++++--- .../api/v1/common/extensions/EnumDyeColor.kt | 2 +- .../api/v1/common/extensions/EnumRarity.kt | 2 +- .../api/v1/common/extensions/ItemStack.kt | 7 ++- .../api/v1/common/extensions/String.kt | 2 +- .../v1/common/extensions/TextFormatting.kt | 2 +- .../catalyx/api/v1/utils/SideUtils.kt | 5 ++ .../catalyx/api/v1/utils/Utils.kt | 55 +++++++++++++++++++ .../v1/utils/interfaces/IBlockPosUtils.kt} | 30 ++-------- .../v1/utils/interfaces/IFluidTankUtils.kt | 5 ++ .../api/v1/utils/interfaces/INetworkUtils.kt | 17 ++++++ .../api/v1/utils/interfaces/ISideUtils.kt | 11 ++++ .../animation/NoopAnimationStateMachine.kt | 2 +- .../catalyx/core/blocks/BaseBlock.kt | 2 +- .../catalyx/core/blocks/TESRTileBlock.kt | 2 +- .../client/button/AbstractButtonWrapper.kt | 3 +- .../core/client/gui/CatalyxGuiHandler.kt | 2 +- .../catalyx/core/items/BaseItem.kt | 2 +- .../catalyx/core/items/CopyPasteTool.kt | 2 +- .../catalyx/core/module/ModuleManager.kt | 2 +- .../catalyx/core/recipes/RecipeBuilder.kt | 2 +- .../catalyx/core/recipes/RecipeMap.kt | 2 +- .../chance/output/ChancedFluidOutput.kt | 6 +- .../chance/output/ChancedItemOutput.kt | 6 +- .../core/registry/CatalyxBlockRegistry.kt | 2 +- .../core/registry/CatalyxItemRegistry.kt | 2 +- .../catalyx/core/tiles/CenterTile.kt | 2 +- .../catalyx/core/utils/BlockPosUtils.kt | 32 +++++++++++ .../catalyx/core/utils/FluidTankUtils.kt | 40 -------------- .../catalyx/core/utils/NetworkUtils.kt | 14 +++-- .../catalyx/core/utils/SideUtils.kt | 11 ++-- .../catalyx/core/utils/math/BlockPosRotate.kt | 41 -------------- .../modules/CatalyxInternalModuleContainer.kt | 2 +- .../groovyscript/ModuleGroovyScript.kt | 2 +- .../integration/top/ModuleTheOneProbe.kt | 2 +- .../catalyx/modules/test/DevTestModule.kt | 2 +- 40 files changed, 216 insertions(+), 157 deletions(-) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1/common}/ColorMapping.kt (98%) rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1/common}/DevUtils.kt (90%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/common/Math.kt rename src/main/kotlin/org/ender_development/catalyx/{core/utils => api/v1/common}/Mods.kt (85%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/SideUtils.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt rename src/main/kotlin/org/ender_development/catalyx/{core/utils/math/BlockPosUtils.kt => api/v1/utils/interfaces/IBlockPosUtils.kt} (57%) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IFluidTankUtils.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/INetworkUtils.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/ISideUtils.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/utils/BlockPosUtils.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/utils/FluidTankUtils.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosRotate.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/ColorMapping.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/ColorMapping.kt similarity index 98% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/ColorMapping.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/ColorMapping.kt index 35c76af..719e4dc 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/ColorMapping.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/ColorMapping.kt @@ -1,6 +1,6 @@ @file:Suppress("NOTHING_TO_INLINE") -package org.ender_development.catalyx.core.utils +package org.ender_development.catalyx.api.v1.common import net.minecraft.item.EnumDyeColor import net.minecraft.item.EnumRarity diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/DevUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/DevUtils.kt similarity index 90% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/DevUtils.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/DevUtils.kt index 229e382..3833bcb 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/DevUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/DevUtils.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils +package org.ender_development.catalyx.api.v1.common import net.minecraft.launchwrapper.Launch diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Math.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Math.kt new file mode 100644 index 0000000..5fa1ea9 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Math.kt @@ -0,0 +1,4 @@ +package org.ender_development.catalyx.api.v1.common + +object Math { +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/Mods.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Mods.kt similarity index 85% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/Mods.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/common/Mods.kt index 96aa12d..9bddd49 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/Mods.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Mods.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.core.utils +package org.ender_development.catalyx.api.v1.common import org.ender_development.catalyx.core.Reference diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/BlockPos.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/BlockPos.kt index 247920d..f6f9ced 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/BlockPos.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/BlockPos.kt @@ -5,16 +5,42 @@ package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.entity.Entity import net.minecraft.util.EnumFacing import net.minecraft.util.math.BlockPos -import org.ender_development.catalyx.core.utils.math.BlockPosRotate +import kotlin.math.cos +import kotlin.math.roundToInt +import kotlin.math.sin -inline fun BlockPos.rotateX(degrees: Int) = - BlockPosRotate.rotateX(this, degrees) +fun BlockPos.rotateX(degrees: Int): BlockPos { + val rad = Math.toRadians(degrees.toDouble()) + val cos = cos(rad) + val sin = sin(rad) + return BlockPos( + this.x, + (this.y * cos - this.z * sin).roundToInt(), + (this.y * sin + this.z * cos).roundToInt() + ) +} -inline fun BlockPos.rotateY(degrees: Int) = - BlockPosRotate.rotateY(this, degrees) +fun BlockPos.rotateY(degrees: Int): BlockPos { + val rad = Math.toRadians(degrees.toDouble()) + val cos = cos(rad) + val sin = sin(rad) + return BlockPos( + (this.x * cos - this.z * sin).roundToInt(), + this.y, + (this.x * sin + this.z * cos).roundToInt() + ) +} -inline fun BlockPos.rotateZ(degrees: Int) = - BlockPosRotate.rotateZ(this, degrees) +fun BlockPos.rotateZ(degrees: Int): BlockPos { + val rad = Math.toRadians(degrees.toDouble()) + val cos = cos(rad) + val sin = sin(rad) + return BlockPos( + (this.x * cos - this.y * sin).roundToInt(), + (this.x * sin + this.y * cos).roundToInt(), + this.z + ) +} inline operator fun BlockPos.minus(other: BlockPos): BlockPos = subtract(other) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumDyeColor.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumDyeColor.kt index 6f614e5..eadcbb9 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumDyeColor.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumDyeColor.kt @@ -1,7 +1,7 @@ package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.item.EnumDyeColor -import org.ender_development.catalyx.core.utils.ColorMapping +import org.ender_development.catalyx.api.v1.common.ColorMapping val EnumDyeColor.colorValue inline get() = ColorMapping[this] diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumRarity.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumRarity.kt index fd541d7..8550b0e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumRarity.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/EnumRarity.kt @@ -2,7 +2,7 @@ package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.enchantment.Enchantment import net.minecraft.item.EnumRarity -import org.ender_development.catalyx.core.utils.ColorMapping +import org.ender_development.catalyx.api.v1.common.ColorMapping val EnumRarity.colorValue inline get() = ColorMapping[this] diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt index 564f0a9..052ee55 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt @@ -1,8 +1,13 @@ +@file:Suppress("NOTHING_TO_INLINE") + package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.item.ItemStack import net.minecraft.item.crafting.Ingredient +inline fun ItemStack?.orEmpty(): ItemStack = + this ?: ItemStack.EMPTY + fun ItemStack.areStacksEqualIgnoreQuantity(other: ItemStack) = item === other.item && metadata == other.metadata && ItemStack.areItemStackTagsEqual(this, other) @@ -12,7 +17,7 @@ fun ItemStack.canMergeWith(target: ItemStack, allowEmpty: Boolean) = else item === target.item && count + target.count <= maxStackSize && itemDamage == target.itemDamage && tagCompound == target.tagCompound -fun ItemStack.toIngredient(): Ingredient = +inline fun ItemStack.toIngredient(): Ingredient = Ingredient.fromStacks(this) fun ItemStack.equalsIgnoreMeta(other: ItemStack) = diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt index c5e233f..42033d8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt @@ -12,7 +12,7 @@ import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.common.Loader import net.minecraftforge.oredict.OreDictionary import net.minecraftforge.oredict.OreIngredient -import org.ender_development.catalyx.core.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.SideUtils inline fun String.toPotion(): Potion = Potion.getPotionFromResourceLocation(this)!! diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/TextFormatting.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/TextFormatting.kt index 003bee5..0104cd8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/TextFormatting.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/TextFormatting.kt @@ -1,7 +1,7 @@ package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.util.text.TextFormatting -import org.ender_development.catalyx.core.utils.ColorMapping +import org.ender_development.catalyx.api.v1.common.ColorMapping val TextFormatting.colorValue inline get() = ColorMapping[this] diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/SideUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/SideUtils.kt new file mode 100644 index 0000000..322b0cf --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/SideUtils.kt @@ -0,0 +1,5 @@ +package org.ender_development.catalyx.api.v1.utils + +import org.ender_development.catalyx.api.v1.utils.interfaces.ISideUtils + +val SideUtils: ISideUtils = org.ender_development.catalyx.core.utils.SideUtils diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt new file mode 100644 index 0000000..5b67413 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt @@ -0,0 +1,55 @@ +package org.ender_development.catalyx.api.v1.utils + +import net.minecraft.tileentity.TileEntity +import net.minecraftforge.fluids.Fluid +import net.minecraftforge.fluids.FluidStack +import net.minecraftforge.fluids.FluidTank +import org.ender_development.catalyx.api.v1.utils.interfaces.IBlockPosUtils +import org.ender_development.catalyx.api.v1.utils.interfaces.IFluidTankUtils +import org.ender_development.catalyx.api.v1.utils.interfaces.INetworkUtils +import org.ender_development.catalyx.core.utils.BlockPosUtils +import org.ender_development.catalyx.core.utils.NetworkUtils + +object Utils { + val forBlockPos: IBlockPosUtils = + BlockPosUtils + + val forNetwork: INetworkUtils = + NetworkUtils + + // bruh... + // TODO fund am abstraction + val forFluidTanks = object : IFluidTankUtils { + // These cannot be an extension as there's currently no way to create a static extension for a JVM class afact (see https://youtrack.jetbrains.com/issue/KT-11968) + + inline fun create(tile: TileEntity, capacity: Int, canFill: Boolean, canDrain: Boolean, crossinline onContentsChangedCallback: () -> Unit) = + object : FluidTank(capacity) { + init { + setTileEntity(tile) + setCanFill(canFill) + setCanDrain(canDrain) + } + + override fun onContentsChanged() = + onContentsChangedCallback() + } + + inline fun create(tile: TileEntity, capacity: Int, canFill: Boolean, canDrain: Boolean, vararg fluidWhitelist: Fluid, crossinline onContentsChangedCallback: () -> Unit) = + object : FluidTank(capacity) { + init { + setTileEntity(tile) + setCanFill(canFill) + setCanDrain(canDrain) + } + + override fun onContentsChanged() = + onContentsChangedCallback() + + override fun canFillFluidType(fluid: FluidStack?) = + fluid != null && fluidWhitelist.any { fluid.fluid === it } + + override fun canDrainFluidType(fluid: FluidStack?) = + canFillFluidType(fluid) + } + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IBlockPosUtils.kt similarity index 57% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt rename to src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IBlockPosUtils.kt index 70d1a0b..65b9d06 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IBlockPosUtils.kt @@ -1,11 +1,8 @@ -package org.ender_development.catalyx.core.utils.math +package org.ender_development.catalyx.api.v1.utils.interfaces import net.minecraft.util.math.BlockPos -import org.ender_development.catalyx.api.v1.common.extensions.minus -import org.ender_development.catalyx.api.v1.common.extensions.plus -import org.ender_development.catalyx.api.v1.common.extensions.rotateY -object BlockPosUtils { +interface IBlockPosUtils { /** * Creates a wall shape centered at [center] with radius [r] and height [h]. * @@ -17,23 +14,7 @@ object BlockPosUtils { * @param shrink Reduces wall width by shrink blocks on its far end to avoid corner overlaps. * @return A [Pair] of [BlockPos] representing the minimum and maximum corners of the wall. */ - fun wall(center: BlockPos, r: Int, h: Int, offset: Int = 0, degrees: Int = 0, shrink: Int = 0): Pair { - val baseOrigin = BlockPos(center.x - r, center.y, center.z + r + offset) - val v1 = BlockPos(2 * r - shrink, 0, 0) - val v2 = BlockPos(0, h, 0) - - val origin = (baseOrigin - center).rotateY(degrees) + center - val v1Rot = v1.rotateY(degrees) - - val corners = listOf( - origin, - origin + v1Rot, - origin + v2, - origin + v1Rot + v2 - ) - - return BlockPos(corners.minOf { it.x }, corners.minOf { it.y }, corners.minOf { it.z }) to BlockPos(corners.maxOf { it.x }, corners.maxOf { it.y }, corners.maxOf { it.z }) - } + fun wall(center: BlockPos, r: Int, h: Int, offset: Int = 0, degrees: Int = 0, shrink: Int = 0): Pair /** * Creates a hollow cuboid shape centered at [center] with radius [r] and height [h]. @@ -45,8 +26,5 @@ object BlockPosUtils { * @param offset An optional vertical offset to apply to the base of the cuboid. * @return A [List] of [Pair]`s` of [BlockPos] representing the minimum and maximum corners of each wall. */ - fun hollowCuboid(center: BlockPos, r: Int, h: Int, offset: Int = 1, shrink: Int = 1) = - (0..3).map { - wall(center, r, h, offset, it * 90, shrink) - } + fun hollowCuboid(center: BlockPos, r: Int, h: Int, offset: Int = 1, shrink: Int = 1): List> } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IFluidTankUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IFluidTankUtils.kt new file mode 100644 index 0000000..61ccb67 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IFluidTankUtils.kt @@ -0,0 +1,5 @@ +package org.ender_development.catalyx.api.v1.utils.interfaces + +interface IFluidTankUtils { + +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/INetworkUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/INetworkUtils.kt new file mode 100644 index 0000000..0ca3117 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/INetworkUtils.kt @@ -0,0 +1,17 @@ +package org.ender_development.catalyx.api.v1.utils.interfaces + +import net.minecraft.item.ItemStack +import net.minecraft.network.PacketBuffer +import net.minecraftforge.fluids.FluidStack + +/** + * Utility functions for reading and writing ItemStacks and FluidStacks to PacketBuffers. + * Handles potential IOExceptions and logs them using the Catalyx logger. + * Loosely based on code from [ModularUI](https://github.com/CleanroomMC/ModularUI/blob/master/src/main/java/com/cleanroommc/modularui/network/NetworkUtils.java) licensed under GNU LGPL-3.0 + */ +interface INetworkUtils { + fun writeItemStack(buffer: PacketBuffer, itemStack: ItemStack?): PacketBuffer + fun readItemStack(buffer: PacketBuffer): ItemStack + fun writeFluidStack(buffer: PacketBuffer, fluidStack: FluidStack?) + fun readFluidStack(buffer: PacketBuffer): FluidStack? +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/ISideUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/ISideUtils.kt new file mode 100644 index 0000000..733a8b7 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/ISideUtils.kt @@ -0,0 +1,11 @@ +package org.ender_development.catalyx.api.v1.utils.interfaces + +/** + * Utility object for checking the current side (client or server). + */ +interface ISideUtils { + val isClient: Boolean + val isServer: Boolean + val isDedicatedClient: Boolean + val isDedicatedServer: Boolean +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt b/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt index 2deea36..62808d7 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt @@ -5,7 +5,7 @@ import net.minecraft.util.ResourceLocation import net.minecraftforge.client.model.ModelLoaderRegistry import net.minecraftforge.common.animation.ITimeValue import net.minecraftforge.common.model.animation.IAnimationStateMachine -import org.ender_development.catalyx.core.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.SideUtils class NoopAnimationStateMachine() : IAnimationStateMachine { companion object { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt index 9189e79..93512ff 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt @@ -15,9 +15,9 @@ import net.minecraft.world.IBlockAccess import net.minecraftforge.client.model.ModelLoader import net.minecraftforge.event.RegistryEvent import org.ender_development.catalyx.api.v1.registry.IBlockProvider +import org.ender_development.catalyx.api.v1.utils.SideUtils import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.register -import org.ender_development.catalyx.core.utils.SideUtils /** * A base Catalyx Block diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt index 25aa692..5e83192 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt @@ -1,10 +1,10 @@ package org.ender_development.catalyx.core.blocks import net.minecraftforge.fml.client.registry.ClientRegistry +import org.ender_development.catalyx.api.v1.utils.SideUtils import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.client.tesr.TileRenderer import org.ender_development.catalyx.core.tiles.TESRTile -import org.ender_development.catalyx.core.utils.SideUtils /** * A rotatable block that has a TESR. Binds the [TileRenderer] to the tile entity on the client side. diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt index c0d0c44..de8ba0b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt @@ -3,15 +3,14 @@ package org.ender_development.catalyx.core.client.button import io.netty.buffer.ByteBuf import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiButton -import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.common.network.simpleimpl.MessageContext import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import org.ender_development.catalyx.api.v1.utils.SideUtils import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.client.button.AbstractButtonWrapper.Companion.getWrapper import org.ender_development.catalyx.core.client.button.AbstractButtonWrapper.Companion.registerWrapper -import org.ender_development.catalyx.core.utils.SideUtils /** * Wrapper class for stateful buttons sent from client-side to server-side diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt index ef1b491..10f0981 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt @@ -8,8 +8,8 @@ import net.minecraft.tileentity.TileEntity import net.minecraft.util.math.BlockPos import net.minecraft.world.World import net.minecraftforge.fml.common.network.IGuiHandler +import org.ender_development.catalyx.api.v1.utils.SideUtils import org.ender_development.catalyx.core.ICatalyxMod -import org.ender_development.catalyx.core.utils.SideUtils /** * A GUI handler you can use for your machines diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt index a07680f..a3d13aa 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt @@ -6,9 +6,9 @@ import net.minecraft.util.ResourceLocation import net.minecraftforge.client.model.ModelLoader import net.minecraftforge.event.RegistryEvent import org.ender_development.catalyx.api.v1.registry.IItemProvider +import org.ender_development.catalyx.api.v1.utils.SideUtils import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.register -import org.ender_development.catalyx.core.utils.SideUtils /** * A base Catalyx item diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt index ea89130..5483a54 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt @@ -10,10 +10,10 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.world.World import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.common.DevUtils import org.ender_development.catalyx.core.client.gui.BaseGuiTyped import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.helper.ICopyPasteExtraTile -import org.ender_development.catalyx.core.utils.DevUtils class CopyPasteTool() : BaseItem(Catalyx, "copy_paste_tool") { private companion object { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt index 71724c7..b8cfcfd 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt @@ -11,6 +11,7 @@ import net.minecraftforge.fml.common.ModContainer import net.minecraftforge.fml.common.discovery.ASMDataTable import net.minecraftforge.fml.common.event.* import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.common.DevUtils import org.ender_development.catalyx.api.v1.common.extensions.modLoaded import org.ender_development.catalyx.api.v1.modules.Modules import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule @@ -24,7 +25,6 @@ import org.ender_development.catalyx.core.module.ModuleManager.discoveredContain import org.ender_development.catalyx.core.module.ModuleManager.discoveredModules import org.ender_development.catalyx.core.module.ModuleManager.stateEvent import org.ender_development.catalyx.core.utils.Delegates -import org.ender_development.catalyx.core.utils.DevUtils import java.io.File import java.util.* diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt index 2081220..414758e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeBuilder.kt @@ -4,6 +4,7 @@ import com.cleanroommc.groovyscript.api.GroovyLog import net.minecraft.item.ItemStack import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fml.common.Optional +import org.ender_development.catalyx.api.v1.common.Mods import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.core.recipes.chance.output.ChancedFluidOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedItemOutput @@ -13,7 +14,6 @@ import org.ender_development.catalyx.core.recipes.ingredients.RecipeInput import org.ender_development.catalyx.core.recipes.validation.Result import org.ender_development.catalyx.core.recipes.validation.ValidationState import org.ender_development.catalyx.core.recipes.validation.Validator -import org.ender_development.catalyx.core.utils.Mods import org.ender_development.catalyx.modules.integration.groovyscript.ModuleGroovyScript import java.util.function.Supplier diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt index 99a2935..8455d0d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt @@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap import it.unimi.dsi.fastutil.objects.ObjectArrayList import it.unimi.dsi.fastutil.objects.ObjectLists import net.minecraft.util.SoundEvent +import org.ender_development.catalyx.api.v1.common.Mods import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.module.ModuleManager import org.ender_development.catalyx.core.recipes.chance.boost.IBoostFunction @@ -14,7 +15,6 @@ import org.ender_development.catalyx.core.recipes.validation.Result import org.ender_development.catalyx.core.recipes.validation.ValidationState import org.ender_development.catalyx.core.recipes.validation.Validator import org.ender_development.catalyx.core.utils.Delegates -import org.ender_development.catalyx.core.utils.Mods import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.integration.groovyscript.VirtualizedRecipeMap import java.lang.ref.WeakReference diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedFluidOutput.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedFluidOutput.kt index dfb7add..432e8ba 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedFluidOutput.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedFluidOutput.kt @@ -2,15 +2,15 @@ package org.ender_development.catalyx.core.recipes.chance.output import net.minecraft.network.PacketBuffer import net.minecraftforge.fluids.FluidStack -import org.ender_development.catalyx.core.utils.NetworkUtils +import org.ender_development.catalyx.api.v1.utils.Utils class ChancedFluidOutput(ingredient: FluidStack, chance: Int, boost: Int) : BoostableChancedOutput(ingredient, chance, boost) { companion object { fun fromBuffer(buffer: PacketBuffer) = - ChancedFluidOutput(NetworkUtils.readFluidStack(buffer)!!, buffer.readVarInt(), buffer.readVarInt()) + ChancedFluidOutput(Utils.forNetwork.readFluidStack(buffer)!!, buffer.readVarInt(), buffer.readVarInt()) fun toBuffer(buffer: PacketBuffer, output: ChancedFluidOutput) { - NetworkUtils.writeFluidStack(buffer, output.ingredient) + Utils.forNetwork.writeFluidStack(buffer, output.ingredient) buffer.writeVarInt(output.chance) buffer.writeVarInt(output.boost) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedItemOutput.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedItemOutput.kt index 3923f8e..b46785e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedItemOutput.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedItemOutput.kt @@ -2,15 +2,15 @@ package org.ender_development.catalyx.core.recipes.chance.output import net.minecraft.item.ItemStack import net.minecraft.network.PacketBuffer -import org.ender_development.catalyx.core.utils.NetworkUtils +import org.ender_development.catalyx.api.v1.utils.Utils class ChancedItemOutput(ingredient: ItemStack, chance: Int, boost: Int) : BoostableChancedOutput(ingredient, chance, boost) { companion object { fun fromBuffer(buffer: PacketBuffer) = - ChancedItemOutput(NetworkUtils.readItemStack(buffer), buffer.readVarInt(), buffer.readVarInt()) + ChancedItemOutput(Utils.forNetwork.readItemStack(buffer), buffer.readVarInt(), buffer.readVarInt()) fun toBuffer(buffer: PacketBuffer, output: ChancedItemOutput) { - NetworkUtils.writeItemStack(buffer, output.ingredient) + Utils.forNetwork.writeItemStack(buffer, output.ingredient) buffer.writeVarInt(output.chance) buffer.writeVarInt(output.boost) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt index eb7fc89..780a091 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt @@ -6,11 +6,11 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.common.DevUtils import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.api.v1.registry.IBlockProvider import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.core.Reference -import org.ender_development.catalyx.core.utils.DevUtils @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxBlockRegistry : ICatalyxRegistry { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt index b5c95a2..a7f9645 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt @@ -5,11 +5,11 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.common.DevUtils import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.api.v1.registry.IItemProvider import org.ender_development.catalyx.core.Reference -import org.ender_development.catalyx.core.utils.DevUtils @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxItemRegistry : ICatalyxRegistry { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt index 8f8280c..66534bf 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt @@ -7,11 +7,11 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.world.World import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.common.DevUtils import org.ender_development.catalyx.api.v1.common.extensions.getHorizontalSurroundings import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.blocks.multiblock.IMultiblockEdge import org.ender_development.catalyx.core.blocks.multiblock.IMultiblockTile -import org.ender_development.catalyx.core.utils.DevUtils open class CenterTile(mod: ICatalyxMod) : BaseTile(mod), IMultiblockTile { internal constructor() : this(Catalyx) { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/BlockPosUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/BlockPosUtils.kt new file mode 100644 index 0000000..72a3601 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/BlockPosUtils.kt @@ -0,0 +1,32 @@ +package org.ender_development.catalyx.core.utils + +import net.minecraft.util.math.BlockPos +import org.ender_development.catalyx.api.v1.common.extensions.minus +import org.ender_development.catalyx.api.v1.common.extensions.plus +import org.ender_development.catalyx.api.v1.common.extensions.rotateY +import org.ender_development.catalyx.api.v1.utils.interfaces.IBlockPosUtils + +object BlockPosUtils : IBlockPosUtils { + override fun wall(center: BlockPos, r: Int, h: Int, offset: Int, degrees: Int, shrink: Int): Pair { + val baseOrigin = BlockPos(center.x - r, center.y, center.z + r + offset) + val v1 = BlockPos(2 * r - shrink, 0, 0) + val v2 = BlockPos(0, h, 0) + + val origin = (baseOrigin - center).rotateY(degrees) + center + val v1Rot = v1.rotateY(degrees) + + val corners = listOf( + origin, + origin + v1Rot, + origin + v2, + origin + v1Rot + v2 + ) + + return BlockPos(corners.minOf { it.x }, corners.minOf { it.y }, corners.minOf { it.z }) to BlockPos(corners.maxOf { it.x }, corners.maxOf { it.y }, corners.maxOf { it.z }) + } + + override fun hollowCuboid(center: BlockPos, r: Int, h: Int, offset: Int, shrink: Int) = + (0..3).map { + wall(center, r, h, offset, it * 90, shrink) + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/FluidTankUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/FluidTankUtils.kt deleted file mode 100644 index c57e929..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/FluidTankUtils.kt +++ /dev/null @@ -1,40 +0,0 @@ -package org.ender_development.catalyx.core.utils - -import net.minecraft.tileentity.TileEntity -import net.minecraftforge.fluids.Fluid -import net.minecraftforge.fluids.FluidStack -import net.minecraftforge.fluids.FluidTank - -object FluidTankUtils { - // These cannot be an extension as there's currently no way to create a static extension for a JVM class afact (see https://youtrack.jetbrains.com/issue/KT-11968) - - inline fun create(tile: TileEntity, capacity: Int, canFill: Boolean, canDrain: Boolean, crossinline onContentsChangedCallback: () -> Unit) = - object : FluidTank(capacity) { - init { - setTileEntity(tile) - setCanFill(canFill) - setCanDrain(canDrain) - } - - override fun onContentsChanged() = - onContentsChangedCallback() - } - - inline fun create(tile: TileEntity, capacity: Int, canFill: Boolean, canDrain: Boolean, vararg fluidWhitelist: Fluid, crossinline onContentsChangedCallback: () -> Unit) = - object : FluidTank(capacity) { - init { - setTileEntity(tile) - setCanFill(canFill) - setCanDrain(canDrain) - } - - override fun onContentsChanged() = - onContentsChangedCallback() - - override fun canFillFluidType(fluid: FluidStack?) = - fluid != null && fluidWhitelist.any { fluid.fluid === it } - - override fun canDrainFluidType(fluid: FluidStack?) = - canFillFluidType(fluid) - } -} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/NetworkUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/NetworkUtils.kt index b600c81..010d548 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/NetworkUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/NetworkUtils.kt @@ -5,6 +5,8 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.network.PacketBuffer import net.minecraftforge.fluids.FluidStack import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.common.extensions.orEmpty +import org.ender_development.catalyx.api.v1.utils.interfaces.INetworkUtils import java.io.IOException /** @@ -12,11 +14,11 @@ import java.io.IOException * Handles potential IOExceptions and logs them using the Catalyx logger. * Loosely based on code from [ModularUI](https://github.com/CleanroomMC/ModularUI/blob/master/src/main/java/com/cleanroommc/modularui/network/NetworkUtils.java) licensed under GNU LGPL-3.0 */ -object NetworkUtils { - fun writeItemStack(buffer: PacketBuffer, itemStack: ItemStack): PacketBuffer = - buffer.writeItemStack(itemStack) +object NetworkUtils : INetworkUtils { + override fun writeItemStack(buffer: PacketBuffer, itemStack: ItemStack?): PacketBuffer = + buffer.writeItemStack(itemStack.orEmpty()) - fun readItemStack(buffer: PacketBuffer): ItemStack = + override fun readItemStack(buffer: PacketBuffer): ItemStack = try { buffer.readItemStack() } catch(e: IOException) { @@ -24,14 +26,14 @@ object NetworkUtils { ItemStack.EMPTY } - fun writeFluidStack(buffer: PacketBuffer, fluidStack: FluidStack?) { + override fun writeFluidStack(buffer: PacketBuffer, fluidStack: FluidStack?) { buffer.writeBoolean(fluidStack == null) fluidStack?.let { buffer.writeCompoundTag(it.writeToNBT(NBTTagCompound())) } } - fun readFluidStack(buffer: PacketBuffer): FluidStack? = + override fun readFluidStack(buffer: PacketBuffer): FluidStack? = try { if(buffer.readBoolean()) null diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/SideUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/SideUtils.kt index 8d711c9..71d9f63 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/SideUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/SideUtils.kt @@ -1,15 +1,16 @@ package org.ender_development.catalyx.core.utils import net.minecraftforge.fml.common.FMLCommonHandler +import org.ender_development.catalyx.api.v1.utils.interfaces.ISideUtils /** * Utility object for checking the current side (client or server). */ -object SideUtils { +object SideUtils : ISideUtils { private val handler = FMLCommonHandler.instance() - val isClient = handler.effectiveSide.isClient - val isServer = handler.effectiveSide.isServer - val isDedicatedClient = handler.side.isClient - val isDedicatedServer = handler.side.isServer + override val isClient = handler.effectiveSide.isClient + override val isServer = handler.effectiveSide.isServer + override val isDedicatedClient = handler.side.isClient + override val isDedicatedServer = handler.side.isServer } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosRotate.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosRotate.kt deleted file mode 100644 index 2695ea8..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/math/BlockPosRotate.kt +++ /dev/null @@ -1,41 +0,0 @@ -package org.ender_development.catalyx.core.utils.math - -import net.minecraft.util.math.BlockPos -import kotlin.math.cos -import kotlin.math.roundToInt -import kotlin.math.sin - -object BlockPosRotate { - fun rotateX(vec: BlockPos, degrees: Int): BlockPos { - val rad = Math.toRadians(degrees.toDouble()) - val cos = cos(rad) - val sin = sin(rad) - return BlockPos( - vec.x, - (vec.y * cos - vec.z * sin).roundToInt(), - (vec.y * sin + vec.z * cos).roundToInt() - ) - } - - fun rotateY(vec: BlockPos, degrees: Int): BlockPos { - val rad = Math.toRadians(degrees.toDouble()) - val cos = cos(rad) - val sin = sin(rad) - return BlockPos( - (vec.x * cos - vec.z * sin).roundToInt(), - vec.y, - (vec.x * sin + vec.z * cos).roundToInt() - ) - } - - fun rotateZ(vec: BlockPos, degrees: Int): BlockPos { - val rad = Math.toRadians(degrees.toDouble()) - val cos = cos(rad) - val sin = sin(rad) - return BlockPos( - (vec.x * cos - vec.y * sin).roundToInt(), - (vec.x * sin + vec.y * cos).roundToInt(), - vec.z - ) - } -} diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt index 0456c3a..7d4f6fe 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt @@ -1,8 +1,8 @@ package org.ender_development.catalyx.modules +import org.ender_development.catalyx.api.v1.common.Mods import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModuleContainer import org.ender_development.catalyx.core.Reference -import org.ender_development.catalyx.core.utils.Mods /** * Module Container for all internal Catalyx modules diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt index c1f3e53..3d00d8f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt @@ -4,11 +4,11 @@ import com.cleanroommc.groovyscript.GroovyScript import com.cleanroommc.groovyscript.api.GroovyPlugin import com.cleanroommc.groovyscript.compat.mods.GroovyContainer import net.minecraftforge.fml.common.Optional +import org.ender_development.catalyx.api.v1.common.Mods import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.module.ModuleManager -import org.ender_development.catalyx.core.utils.Mods import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.integration.IntegrationModule diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt index 44bd735..1decdd7 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/ModuleTheOneProbe.kt @@ -2,10 +2,10 @@ package org.ender_development.catalyx.modules.integration.top import mcjty.theoneprobe.TheOneProbe import net.minecraftforge.fml.common.event.FMLInitializationEvent +import org.ender_development.catalyx.api.v1.common.Mods import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.core.Reference -import org.ender_development.catalyx.core.utils.Mods import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.integration.IntegrationModule diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt index cffd471..5011cb6 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt @@ -7,13 +7,13 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule +import org.ender_development.catalyx.api.v1.utils.SideUtils import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.blocks.IOTileBlock import org.ender_development.catalyx.core.blocks.multiblock.CenterBlock import org.ender_development.catalyx.core.blocks.multiblock.parts.CornerBlock import org.ender_development.catalyx.core.blocks.multiblock.parts.SideBlock import org.ender_development.catalyx.core.client.AreaHighlighter -import org.ender_development.catalyx.core.utils.SideUtils import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.CatalyxModuleBase From 9992b3a05f220677944ada8bbc1fa10d0cfa38c3 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Wed, 21 Jan 2026 11:30:32 +0100 Subject: [PATCH 28/58] remove NetworkUtils in favour of extensions, other smaller thingies --- .../catalyx/api/v1/common/Mods.kt | 2 +- .../api/v1/common/extensions/PacketBuffer.kt | 45 ++++++++++++++++++ .../catalyx/api/v1/utils/Utils.kt | 5 -- .../api/v1/utils/interfaces/IBlockPosUtils.kt | 4 +- .../api/v1/utils/interfaces/INetworkUtils.kt | 17 ------- .../chance/output/ChancedFluidOutput.kt | 6 ++- .../chance/output/ChancedItemOutput.kt | 6 +-- .../catalyx/core/utils/BlockPosUtils.kt | 4 +- .../catalyx/core/utils/NetworkUtils.kt | 46 ------------------- 9 files changed, 57 insertions(+), 78 deletions(-) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/PacketBuffer.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/INetworkUtils.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/utils/NetworkUtils.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Mods.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Mods.kt index 9bddd49..67b8eb0 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Mods.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/Mods.kt @@ -3,7 +3,7 @@ package org.ender_development.catalyx.api.v1.common import org.ender_development.catalyx.core.Reference /** - * ModID Database + * Common mod ids for integration and other things */ object Mods { const val CATALYX = Reference.MODID diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/PacketBuffer.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/PacketBuffer.kt new file mode 100644 index 0000000..031d11c --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/PacketBuffer.kt @@ -0,0 +1,45 @@ +@file:Suppress("NOTHING_TO_INLINE") + +package org.ender_development.catalyx.api.v1.common.extensions + +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NBTTagCompound +import net.minecraft.network.PacketBuffer +import net.minecraftforge.fluids.FluidStack +import org.ender_development.catalyx.Catalyx +import java.io.IOException + +/* + * Utility functions for reading and writing ItemStacss and FluidStacks to PacketBuffers. + * Handles potential IOExceptions and logs them using the Catalyx logger. + * Loosely based on code from [ModularUI](https://github.com/CleanroomMC/ModularUI/blob/master/src/main/java/com/cleanroommc/modularui/network/NetworkUtils.java) licensed under GNU LGPL-3.0 + */ + +inline fun PacketBuffer.writeItemStackOrEmpty(stack: ItemStack?) = + writeItemStack(stack.orEmpty()) + +fun PacketBuffer.readItemStackOrEmpty(): ItemStack = + try { + readItemStack() + } catch(e: IOException) { + Catalyx.LOGGER.catching(e) + ItemStack.EMPTY + } + +fun PacketBuffer.writeFluidStack(fluidStack: FluidStack?) { + writeBoolean(fluidStack == null) + fluidStack?.let { + writeCompoundTag(it.writeToNBT(NBTTagCompound())) + } +} + +fun PacketBuffer.readFluidStack(): FluidStack? = + try { + if(readBoolean()) + null + else + FluidStack.loadFluidStackFromNBT(readCompoundTag()) + } catch(e: IOException) { + Catalyx.LOGGER.catching(e) + null + } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt index 5b67413..adce16c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt @@ -6,17 +6,12 @@ import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidTank import org.ender_development.catalyx.api.v1.utils.interfaces.IBlockPosUtils import org.ender_development.catalyx.api.v1.utils.interfaces.IFluidTankUtils -import org.ender_development.catalyx.api.v1.utils.interfaces.INetworkUtils import org.ender_development.catalyx.core.utils.BlockPosUtils -import org.ender_development.catalyx.core.utils.NetworkUtils object Utils { val forBlockPos: IBlockPosUtils = BlockPosUtils - val forNetwork: INetworkUtils = - NetworkUtils - // bruh... // TODO fund am abstraction val forFluidTanks = object : IFluidTankUtils { diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IBlockPosUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IBlockPosUtils.kt index 65b9d06..e3c84dc 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IBlockPosUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IBlockPosUtils.kt @@ -24,7 +24,7 @@ interface IBlockPosUtils { * @param r The radius from the center to the edges of the cuboid. * @param h The height of the cuboid. * @param offset An optional vertical offset to apply to the base of the cuboid. - * @return A [List] of [Pair]`s` of [BlockPos] representing the minimum and maximum corners of each wall. + * @return A length 4 array of [Pair]s of [BlockPos] representing the minimum and maximum corners of each wall, see [BlockPosUtils#wall][wall]. */ - fun hollowCuboid(center: BlockPos, r: Int, h: Int, offset: Int = 1, shrink: Int = 1): List> + fun hollowCuboid(center: BlockPos, r: Int, h: Int, offset: Int = 1, shrink: Int = 1): Array> } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/INetworkUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/INetworkUtils.kt deleted file mode 100644 index 0ca3117..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/INetworkUtils.kt +++ /dev/null @@ -1,17 +0,0 @@ -package org.ender_development.catalyx.api.v1.utils.interfaces - -import net.minecraft.item.ItemStack -import net.minecraft.network.PacketBuffer -import net.minecraftforge.fluids.FluidStack - -/** - * Utility functions for reading and writing ItemStacks and FluidStacks to PacketBuffers. - * Handles potential IOExceptions and logs them using the Catalyx logger. - * Loosely based on code from [ModularUI](https://github.com/CleanroomMC/ModularUI/blob/master/src/main/java/com/cleanroommc/modularui/network/NetworkUtils.java) licensed under GNU LGPL-3.0 - */ -interface INetworkUtils { - fun writeItemStack(buffer: PacketBuffer, itemStack: ItemStack?): PacketBuffer - fun readItemStack(buffer: PacketBuffer): ItemStack - fun writeFluidStack(buffer: PacketBuffer, fluidStack: FluidStack?) - fun readFluidStack(buffer: PacketBuffer): FluidStack? -} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedFluidOutput.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedFluidOutput.kt index 432e8ba..47ead13 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedFluidOutput.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedFluidOutput.kt @@ -2,15 +2,17 @@ package org.ender_development.catalyx.core.recipes.chance.output import net.minecraft.network.PacketBuffer import net.minecraftforge.fluids.FluidStack +import org.ender_development.catalyx.api.v1.common.extensions.readFluidStack +import org.ender_development.catalyx.api.v1.common.extensions.writeFluidStack import org.ender_development.catalyx.api.v1.utils.Utils class ChancedFluidOutput(ingredient: FluidStack, chance: Int, boost: Int) : BoostableChancedOutput(ingredient, chance, boost) { companion object { fun fromBuffer(buffer: PacketBuffer) = - ChancedFluidOutput(Utils.forNetwork.readFluidStack(buffer)!!, buffer.readVarInt(), buffer.readVarInt()) + ChancedFluidOutput(buffer.readFluidStack()!!, buffer.readVarInt(), buffer.readVarInt()) fun toBuffer(buffer: PacketBuffer, output: ChancedFluidOutput) { - Utils.forNetwork.writeFluidStack(buffer, output.ingredient) + buffer.writeFluidStack(output.ingredient) buffer.writeVarInt(output.chance) buffer.writeVarInt(output.boost) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedItemOutput.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedItemOutput.kt index b46785e..5cdfcbd 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedItemOutput.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/ChancedItemOutput.kt @@ -2,15 +2,15 @@ package org.ender_development.catalyx.core.recipes.chance.output import net.minecraft.item.ItemStack import net.minecraft.network.PacketBuffer -import org.ender_development.catalyx.api.v1.utils.Utils +import org.ender_development.catalyx.api.v1.common.extensions.readItemStackOrEmpty class ChancedItemOutput(ingredient: ItemStack, chance: Int, boost: Int) : BoostableChancedOutput(ingredient, chance, boost) { companion object { fun fromBuffer(buffer: PacketBuffer) = - ChancedItemOutput(Utils.forNetwork.readItemStack(buffer), buffer.readVarInt(), buffer.readVarInt()) + ChancedItemOutput(buffer.readItemStackOrEmpty(), buffer.readVarInt(), buffer.readVarInt()) fun toBuffer(buffer: PacketBuffer, output: ChancedItemOutput) { - Utils.forNetwork.writeItemStack(buffer, output.ingredient) + buffer.writeItemStack(output.ingredient) buffer.writeVarInt(output.chance) buffer.writeVarInt(output.boost) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/BlockPosUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/BlockPosUtils.kt index 72a3601..d3599af 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/BlockPosUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/BlockPosUtils.kt @@ -15,7 +15,7 @@ object BlockPosUtils : IBlockPosUtils { val origin = (baseOrigin - center).rotateY(degrees) + center val v1Rot = v1.rotateY(degrees) - val corners = listOf( + val corners = arrayOf( origin, origin + v1Rot, origin + v2, @@ -26,7 +26,7 @@ object BlockPosUtils : IBlockPosUtils { } override fun hollowCuboid(center: BlockPos, r: Int, h: Int, offset: Int, shrink: Int) = - (0..3).map { + Array(4) { wall(center, r, h, offset, it * 90, shrink) } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/NetworkUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/NetworkUtils.kt deleted file mode 100644 index 010d548..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/NetworkUtils.kt +++ /dev/null @@ -1,46 +0,0 @@ -package org.ender_development.catalyx.core.utils - -import net.minecraft.item.ItemStack -import net.minecraft.nbt.NBTTagCompound -import net.minecraft.network.PacketBuffer -import net.minecraftforge.fluids.FluidStack -import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.common.extensions.orEmpty -import org.ender_development.catalyx.api.v1.utils.interfaces.INetworkUtils -import java.io.IOException - -/** - * Utility functions for reading and writing ItemStacks and FluidStacks to PacketBuffers. - * Handles potential IOExceptions and logs them using the Catalyx logger. - * Loosely based on code from [ModularUI](https://github.com/CleanroomMC/ModularUI/blob/master/src/main/java/com/cleanroommc/modularui/network/NetworkUtils.java) licensed under GNU LGPL-3.0 - */ -object NetworkUtils : INetworkUtils { - override fun writeItemStack(buffer: PacketBuffer, itemStack: ItemStack?): PacketBuffer = - buffer.writeItemStack(itemStack.orEmpty()) - - override fun readItemStack(buffer: PacketBuffer): ItemStack = - try { - buffer.readItemStack() - } catch(e: IOException) { - Catalyx.LOGGER.catching(e) - ItemStack.EMPTY - } - - override fun writeFluidStack(buffer: PacketBuffer, fluidStack: FluidStack?) { - buffer.writeBoolean(fluidStack == null) - fluidStack?.let { - buffer.writeCompoundTag(it.writeToNBT(NBTTagCompound())) - } - } - - override fun readFluidStack(buffer: PacketBuffer): FluidStack? = - try { - if(buffer.readBoolean()) - null - else - FluidStack.loadFluidStackFromNBT(buffer.readCompoundTag()) - } catch(e: IOException) { - Catalyx.LOGGER.catching(e) - null - } -} From d0cba059324244fe5504be329be5d1733faa95ef Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Thu, 22 Jan 2026 13:28:49 +0100 Subject: [PATCH 29/58] fix mixin --- buildSrc/src/main/resources/utilities.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/resources/utilities.properties b/buildSrc/src/main/resources/utilities.properties index 79412f3..5f35372 100644 --- a/buildSrc/src/main/resources/utilities.properties +++ b/buildSrc/src/main/resources/utilities.properties @@ -23,7 +23,7 @@ use_dependency_at_files = true # You MUST state a class name for `coremod_plugin_class_name` if you are making a coremod, the class should implement `IFMLLoadingPlugin` is_coremod = true coremod_includes_mod = true -coremod_plugin_class_name = org.ender_development.catalyx.core.CatalyxCore +coremod_plugin_class_name = org.ender_development.catalyx.core.CatalyxCoreMod From aa29cabb3ecc2c9711ded5bfbfeba1de40667333 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Thu, 22 Jan 2026 13:30:00 +0100 Subject: [PATCH 30/58] remove this thing and hopefully we all forget about it --- .../api/v1/modules/interfaces/IModuleIdentifier.kt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt index 85190df..616ac83 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/modules/interfaces/IModuleIdentifier.kt @@ -15,15 +15,3 @@ interface IModuleIdentifier { fun toResourceLocation() = ResourceLocation(containerId, moduleId) } - -/* -// TODO: Discuss whether the following woule be better than the current ModuleIdentifier bs -typealias ModuleIdentifier = ResourceLocation -inline val ModuleIdentifier.containerId: String - get() = this.namespace - -inline val ModuleIdentifier.moduleId: String - get() = this.path - -// roz: nah ;p -*/ From 69a70f26a8740079625132cda658a0a2fd866a5a Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Thu, 22 Jan 2026 13:30:23 +0100 Subject: [PATCH 31/58] fix fluidutils not being usable --- .../org/ender_development/catalyx/api/v1/utils/Utils.kt | 6 +++--- .../catalyx/api/v1/utils/interfaces/IFluidTankUtils.kt | 5 ----- 2 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IFluidTankUtils.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt index adce16c..8e4624f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt @@ -5,7 +5,6 @@ import net.minecraftforge.fluids.Fluid import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidTank import org.ender_development.catalyx.api.v1.utils.interfaces.IBlockPosUtils -import org.ender_development.catalyx.api.v1.utils.interfaces.IFluidTankUtils import org.ender_development.catalyx.core.utils.BlockPosUtils object Utils { @@ -13,8 +12,9 @@ object Utils { BlockPosUtils // bruh... - // TODO fund am abstraction - val forFluidTanks = object : IFluidTankUtils { + // TODO find an abstraction + @Suppress("ClassName") + object forFluidTanks { // These cannot be an extension as there's currently no way to create a static extension for a JVM class afact (see https://youtrack.jetbrains.com/issue/KT-11968) inline fun create(tile: TileEntity, capacity: Int, canFill: Boolean, canDrain: Boolean, crossinline onContentsChangedCallback: () -> Unit) = diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IFluidTankUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IFluidTankUtils.kt deleted file mode 100644 index 61ccb67..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IFluidTankUtils.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.ender_development.catalyx.api.v1.utils.interfaces - -interface IFluidTankUtils { - -} From c22c066cd3caa6e39d49f47b4a61a1155ece04f6 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Thu, 22 Jan 2026 13:31:11 +0100 Subject: [PATCH 32/58] small amount of rendering bs --- .../catalyx/core/client/gui/BaseGuiTyped.kt | 6 +- .../core/client/tesr/HudInfoRenderer.kt | 9 +- .../catalyx/core/tiles/BaseTile.kt | 8 +- .../catalyx/core/utils/RenderUtils.kt | 170 +++++++++--------- 4 files changed, 99 insertions(+), 94 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt index f1d42ab..044b772 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/BaseGuiTyped.kt @@ -108,11 +108,11 @@ abstract class BaseGuiTyped(container: Container, val tileEntity: T) : GuiCon PacketHandler.channel.sendToServer(ButtonPacket(tileEntity.pos, button.wrapper)) } - fun drawFluidTank(wrapper: CapabilityFluidDisplayWrapper, x: Int, y: Int, width: Int = 16, height: Int = 70) { + open fun drawFluidTank(wrapper: CapabilityFluidDisplayWrapper, x: Int, y: Int, width: Int = 16, height: Int = 70) { // draw the actual fluid texture if(wrapper.stored > 5) { RenderUtils.bindBlockTexture() - RenderUtils.renderGuiTank(wrapper.fluid, wrapper.capacity, wrapper.stored, x.toDouble(), y.toDouble(), zLevel.toDouble(), width.toDouble(), height.toDouble()) + RenderUtils.renderGuiTank(wrapper.fluid, wrapper.capacity, x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble()) } // draw the empty tank overlay overtop @@ -155,7 +155,7 @@ abstract class BaseGuiTyped(container: Container, val tileEntity: T) : GuiCon } } - fun isHovered(x: Int, y: Int, width: Int, height: Int, mouseX: Int, mouseY: Int) = + open fun isHovered(x: Int, y: Int, width: Int, height: Int, mouseX: Int, mouseY: Int) = mouseX >= x && mouseX < x + width && mouseY >= y && mouseY < y + height interface IDefaultButtonVariables { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt index f4b9c74..b9ba768 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/tesr/HudInfoRenderer.kt @@ -9,7 +9,6 @@ import org.ender_development.catalyx.api.v1.common.extensions.glRotate import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.helper.HudInfoLine import org.ender_development.catalyx.core.tiles.helper.IHudInfoProvider -import org.ender_development.catalyx.core.utils.RenderUtils.FONT_RENDERER import org.ender_development.catalyx.core.utils.RenderUtils.drawRectangle @SideOnly(Side.CLIENT) @@ -70,17 +69,17 @@ object HudInfoRenderer : AbstractTESRenderer() { drawRectangle(padding, y, blockSize, height, message.border, false, -.01) val maxWidth = blockSize.toInt() - 2 - val line = FONT_RENDERER.trimStringToWidth(message.text, maxWidth) + val line = fontRenderer.trimStringToWidth(message.text, maxWidth) val colour = message.color?.let { it.rgb and 0xFFFFFF } ?: 0xFFFFFF println("colour=$colour; GlSM state={r=${GlStateManager.colorState.red}; g=${GlStateManager.colorState.green}; b=${GlStateManager.colorState.blue}; a=${GlStateManager.colorState.alpha}}") if(message.alignment == HudInfoLine.TextAlign.LEFT) - FONT_RENDERER.drawString(line, padding.toInt() + 1, y.toInt() + 2, colour) + fontRenderer.drawString(line, padding.toInt() + 1, y.toInt() + 2, colour) else { - var x = FONT_RENDERER.getStringWidth(line).coerceAtMost(maxWidth) + var x = fontRenderer.getStringWidth(line).coerceAtMost(maxWidth) if(message.alignment == HudInfoLine.TextAlign.CENTER) x = x shr 1 - FONT_RENDERER.drawString(line, x, y.toInt() + 2, colour) + fontRenderer.drawString(line, x, y.toInt() + 2, colour) } y += height } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt index 02fce58..33c2bb9 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt @@ -62,9 +62,13 @@ abstract class BaseTile(open val mod: ICatalyxMod) : TileEntity(), BaseContainer open val facing: EnumFacing get() = world.getBlockState(pos).properties.getOrDefault(BlockHorizontal.FACING, EnumFacing.NORTH) as EnumFacing - open val inventory: IItemHandler = CombinedInvWrapper(input, output) + // note: this has to be a getter + open val inventory + get() = CombinedInvWrapper(input, output) - open val automationInvHandler = CombinedInvWrapper(automationInput, automationOutput) + // note: this has to be a getter + open val automationInvHandler + get() = CombinedInvWrapper(automationInput, automationOutput) override fun canInteractWith(player: EntityPlayer) = !isInvalid && player.getDistanceSq(pos.add(.5, .5, .5)) <= 64 diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt index d1d4d63..3a32bc0 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/RenderUtils.kt @@ -1,3 +1,5 @@ +@file:Suppress("NOTHING_TO_INLINE") + package org.ender_development.catalyx.core.utils import net.minecraft.client.Minecraft @@ -5,6 +7,7 @@ import net.minecraft.client.gui.FontRenderer import net.minecraft.client.renderer.BufferBuilder import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.Tessellator +import net.minecraft.client.renderer.texture.TextureAtlasSprite import net.minecraft.client.renderer.texture.TextureManager import net.minecraft.client.renderer.texture.TextureMap import net.minecraft.client.renderer.vertex.DefaultVertexFormats @@ -13,82 +16,62 @@ import net.minecraftforge.fluids.Fluid import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidTank import org.ender_development.catalyx.api.v1.common.extensions.destructFloat +import org.ender_development.catalyx.api.v1.common.extensions.getColor import org.lwjgl.opengl.GL11 import java.awt.Color object RenderUtils { val minecraft: Minecraft = Minecraft.getMinecraft() - val TESSELLATOR: Tessellator = Tessellator.getInstance() - val BUFFER_BUILDER: BufferBuilder = TESSELLATOR.buffer - val FONT_RENDERER: FontRenderer = minecraft.fontRenderer - val renderEngine: TextureManager = minecraft.renderEngine - - val BLOCK_TEX: ResourceLocation = TextureMap.LOCATION_BLOCKS_TEXTURE + val tessellator: Tessellator = Tessellator.getInstance() + val bufferBuilder: BufferBuilder = tessellator.buffer + val fontRenderer: FontRenderer = minecraft.fontRenderer + val textureManager: TextureManager = minecraft.renderEngine - fun bindBlockTexture() = - renderEngine.bindTexture(BLOCK_TEX) + val blockTexture: ResourceLocation = TextureMap.LOCATION_BLOCKS_TEXTURE - fun bindTexture(string: String) = - renderEngine.bindTexture(ResourceLocation(string)) + inline fun bindBlockTexture() = + bindTexture(blockTexture) - fun bindTexture(tex: ResourceLocation) = - renderEngine.bindTexture(tex) + inline fun bindTexture(tex: ResourceLocation) = + textureManager.bindTexture(tex) fun getStillTexture(fluid: FluidStack?) = - fluid?.fluid?.let { - getStillTexture(it) - } + fluid?.fluid?.let(::getStillTexture) fun getStillTexture(fluid: Fluid) = - fluid.still?.let { - minecraft.textureMapBlocks.getTextureExtry("$it") - } + fluid.still?.toString()?.let(minecraft.textureMapBlocks::getTextureExtry) - fun renderGuiTank(tank: FluidTank, x: Double, y: Double, zLevel: Double, width: Double, height: Double) = - renderGuiTank(tank.fluid, tank.capacity, tank.fluidAmount, x, y, zLevel, width, height) + inline fun renderGuiTank(tank: FluidTank, x: Double, y: Double, width: Double, height: Double) = + renderGuiTank(tank.fluid, tank.capacity, x, y, width, height) - fun renderGuiTank(fluid: FluidStack?, capacity: Int, amount: Int, x: Double, y: Double, zLevel: Double, width: Double, height: Double) { - if(fluid == null || fluid.fluid == null || fluid.amount <= 0) + fun renderGuiTank(fluid: FluidStack?, capacity: Int, x: Double, y: Double, width: Double, height: Double) { + if(fluid == null || fluid.amount <= 0) return - val icon = getStillTexture(fluid) ?: return + val sprite = getStillTexture(fluid) ?: return - val renderAmount = (amount * height / capacity).coerceIn(.0, height) - val posY = (y + height - renderAmount) + val bottomY = y + height + val topY = bottomY - height * fluid.amount.coerceAtMost(capacity) / capacity + + val (red, green, blue) = Color(fluid.getColor()).destructFloat() + GlStateManager.color(red, green, blue, 1f) + GlStateManager.enableBlend() bindBlockTexture() - val color = fluid.fluid.getColor(fluid) - GL11.glColor3ub((color shr 16 and 0xFF).toByte(), (color shr 8 and 0xFF).toByte(), (color and 0xFF).toByte()) - // TODO clean up this mess - GlStateManager.enableBlend() - var i = 0 - while(i < width) { - var j = 0 - while(j < renderAmount) { - val drawWidth = (width - i).coerceAtMost(16.0) - val drawHeight = (renderAmount - j).coerceAtMost(16.0) - - val drawX = x + i - val drawY = posY + j - - val minU = icon.minU.toDouble() - val maxU = icon.maxU.toDouble() - val minV = icon.minV.toDouble() - val maxV = icon.maxV.toDouble() - - val tessellator = Tessellator.getInstance() - val tes = tessellator.buffer - tes.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX) - tes.pos(drawX, drawY + drawHeight, 0.0).tex(minU, minV + (maxV - minV) * drawHeight / 16f).endVertex() - tes.pos(drawX + drawWidth, drawY + drawHeight, 0.0).tex(minU + (maxU - minU) * drawWidth / 16f, minV + (maxV - minV) * drawHeight / 16f).endVertex() - tes.pos(drawX + drawWidth, drawY, 0.0).tex(minU + (maxU - minU) * drawWidth / 16f, minV).endVertex() - tes.pos(drawX, drawY, 0.0).tex(minU, minV).endVertex() - tessellator.draw() - j += 16 + // in any normal programming language, this would just be something like `for(double drawY = topY; drawY < bottomY; drawY += 16)` + var drawY = topY + while(drawY < bottomY) { + var xOffset = 0 + while(xOffset < width) { + val drawWidth = (width - xOffset).coerceAtMost(16.0) + val drawHeight = (bottomY - drawY).coerceAtMost(16.0) + + drawTexturedModalRect(x + xOffset, drawY, sprite, drawWidth, drawHeight) + xOffset += 16 } - i += 16 + drawY += 16 } GlStateManager.disableBlend() } @@ -105,7 +88,7 @@ object RenderUtils { GlStateManager.pushMatrix() GlStateManager.translate(x, y, .0) GlStateManager.scale(scale, scale, .0) - FONT_RENDERER.drawString(text, 0f, 0f, color, shadow) + fontRenderer.drawString(text, 0f, 0f, color, shadow) GlStateManager.popMatrix() } @@ -138,12 +121,12 @@ object RenderUtils { val tw = 1 / tileWidth val th = 1 / tileHeight val (red, green, blue, alpha) = color.destructFloat() - BUFFER_BUILDER.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR) - BUFFER_BUILDER.pos(x, y + height, zOffset).tex(u * tw, (v + vHeight) * th).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x + width, y + height, zOffset).tex((u + uWidth) * tw, (v + vHeight) * th).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x + width, y, zOffset).tex((u + uWidth) * tw, v * th).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x, y, zOffset).tex(u * tw, v * th).color(red, green, blue, alpha).endVertex() - TESSELLATOR.draw() + bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR) + bufferBuilder.pos(x, y + height, zOffset).tex(u * tw, (v + vHeight) * th).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x + width, y + height, zOffset).tex((u + uWidth) * tw, (v + vHeight) * th).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x + width, y, zOffset).tex((u + uWidth) * tw, v * th).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x, y, zOffset).tex(u * tw, v * th).color(red, green, blue, alpha).endVertex() + tessellator.draw() } /** @@ -157,23 +140,23 @@ object RenderUtils { GlStateManager.pushMatrix() if(!filled) { - BUFFER_BUILDER.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR) - - BUFFER_BUILDER.pos(x, y, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x, y + height, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x, y + height, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x + width, y + height, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x + width, y + height, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x + width, y, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x + width, y, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x, y, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR) + + bufferBuilder.pos(x, y, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x, y + height, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x, y + height, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x + width, y + height, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x + width, y + height, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x + width, y, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x + width, y, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x, y, .0).color(red, green, blue, alpha).endVertex() } else { - BUFFER_BUILDER.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR) + bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR) - BUFFER_BUILDER.pos(x, y + 0, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x, y + height, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x + width, y + height, .0).color(red, green, blue, alpha).endVertex() - BUFFER_BUILDER.pos(x + width, y + 0, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x, y + 0, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x, y + height, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x + width, y + height, .0).color(red, green, blue, alpha).endVertex() + bufferBuilder.pos(x + width, y + 0, .0).color(red, green, blue, alpha).endVertex() } GlStateManager.translate(.0, .0, zTranslate) @@ -182,7 +165,7 @@ object RenderUtils { GlStateManager.disableLighting() GlStateManager.disableTexture2D() GlStateManager.depthMask(false) - TESSELLATOR.draw() + tessellator.draw() GlStateManager.depthMask(true) GlStateManager.enableTexture2D() GlStateManager.enableLighting() @@ -190,17 +173,36 @@ object RenderUtils { GlStateManager.popMatrix() } - const val MAGIC_NUMBER = 0.00390625 + const val MAGIC_NUMBER = 1.0 / 256.0 /** * Draw a 2D textured rectangle. Adapted from [Gui#drawTexturedModalRect][net.minecraft.client.gui.Gui.drawTexturedModalRect]. */ fun drawTexturedModalRect(x: Double, y: Double, u: Float, v: Float, width: Double, height: Double, zLevel: Double = .0) { - BUFFER_BUILDER.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX) - BUFFER_BUILDER.pos(x, y + height, zLevel).tex(u * MAGIC_NUMBER, (v + height) * MAGIC_NUMBER).endVertex() - BUFFER_BUILDER.pos(x + width, y + height, zLevel).tex((u + width) * MAGIC_NUMBER, (v + height) * MAGIC_NUMBER).endVertex() - BUFFER_BUILDER.pos(x + width, y, zLevel).tex((u + width) * MAGIC_NUMBER, v * MAGIC_NUMBER).endVertex() - BUFFER_BUILDER.pos(x, y, zLevel).tex(u * MAGIC_NUMBER, v * MAGIC_NUMBER).endVertex() - TESSELLATOR.draw() + bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX) + bufferBuilder.pos(x, y + height, zLevel).tex(u * MAGIC_NUMBER, (v + height) * MAGIC_NUMBER).endVertex() + bufferBuilder.pos(x + width, y + height, zLevel).tex((u + width) * MAGIC_NUMBER, (v + height) * MAGIC_NUMBER).endVertex() + bufferBuilder.pos(x + width, y, zLevel).tex((u + width) * MAGIC_NUMBER, v * MAGIC_NUMBER).endVertex() + bufferBuilder.pos(x, y, zLevel).tex(u * MAGIC_NUMBER, v * MAGIC_NUMBER).endVertex() + tessellator.draw() + } + + /** + * Draw a textured rectangle using the [sprite]. Adapted from [Gui#drawTexturedModalRect][net.minecraft.client.gui.Gui.drawTexturedModalRect] + * + * @param sprite Sprite to render + * @param zLevel Z level to render at + */ + fun drawTexturedModalRect(x: Double, y: Double, sprite: TextureAtlasSprite, width: Double, height: Double, zLevel: Double = .0) { + val minU = sprite.minU.toDouble() + val maxU = sprite.maxU.toDouble() + val minV = sprite.minV.toDouble() + val maxV = sprite.maxV.toDouble() + bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX) + bufferBuilder.pos(x, y + height, zLevel).tex(minU, maxV).endVertex() + bufferBuilder.pos(x + width, y + height, zLevel).tex(maxU, maxV).endVertex() + bufferBuilder.pos(x + width, y, zLevel).tex(maxU, minV).endVertex() + bufferBuilder.pos(x, y, zLevel).tex(minU, minV).endVertex() + tessellator.draw() } } From 24a8a1c3682d00cae42f5d31d1e8a32cae5252b8 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Thu, 22 Jan 2026 13:46:48 +0100 Subject: [PATCH 33/58] some more extension sillyness --- .../catalyx/api/v1/common/extensions/IItemHandler.kt | 7 ++++--- .../catalyx/api/v1/common/extensions/ItemStack.kt | 8 +++++++- .../catalyx/api/v1/common/extensions/List.kt | 5 +---- .../catalyx/api/v1/common/extensions/String.kt | 4 ++-- .../ender_development/catalyx/core/tiles/BaseTile.kt | 9 ++++++--- .../catalyx/core/tiles/helper/TileStackHandler.kt | 11 +++++++---- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/IItemHandler.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/IItemHandler.kt index ee7b57c..b460763 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/IItemHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/IItemHandler.kt @@ -1,9 +1,11 @@ +@file:Suppress("NOTHING_TO_INLINE") + package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.item.ItemStack import net.minecraftforge.items.IItemHandler -operator fun IItemHandler.get(idx: Int) = +inline operator fun IItemHandler.get(idx: Int) = getStackInSlot(idx) fun IItemHandler.tryInsertInto(otherHandler: IItemHandler): Boolean { @@ -43,6 +45,5 @@ fun IItemHandler.tryInsert(stack: ItemStack): ItemStack { fun IItemHandler.toStackList() = (0.. ItemStack): ItemStack = + if(isEmpty) + ItemStack.EMPTY + else + notEmpty(this) fun ItemStack.areStacksEqualIgnoreQuantity(other: ItemStack) = item === other.item && metadata == other.metadata && ItemStack.areItemStackTagsEqual(this, other) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt index 3af20d3..201a10b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt @@ -26,10 +26,7 @@ fun List.validateEach(validator: (idx: Int, T) -> IValidationResult) = @JvmName("copyOfIS") inline fun List.copyOf() = map { - if(it.isEmpty) - ItemStack.EMPTY - else - it.copy() + it.orIfNotEmpty(ItemStack::copy) } @JvmName("copyOfFS") diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt index 42033d8..1abae59 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt @@ -25,7 +25,7 @@ fun String.toStack(quantity: Int = 1, meta: Int = 0): ItemStack { val meta = split.getApplyOrDefault(2, String::toInt) { meta } val location = if(split.size == 1) ResourceLocation(this) else ResourceLocation(split[0], split[1]) - return Item.REGISTRY.registryObjects[location]?.toStack(quantity, meta) ?: Block.REGISTRY.registryObjects[location]?.toStack(quantity, meta) ?: ItemStack.EMPTY + return Item.REGISTRY.registryObjects[location]?.toStack(quantity, meta) ?: Block.REGISTRY.registryObjects[location]?.toStack(quantity, meta).orEmpty() } inline fun String.toIngredient(meta: Int = 0): Ingredient = @@ -35,7 +35,7 @@ inline fun String.toDict(prefix: String) = "$prefix${replaceFirstChar(Char::uppercaseChar)}" inline fun String.firstOre(): ItemStack = - OreDictionary.getOres(this).firstOrNull() ?: ItemStack.EMPTY + OreDictionary.getOres(this).firstOrNull().orEmpty() fun String.translate(vararg format: Any): String = if(SideUtils.isServer) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt index 33c2bb9..ce66e92 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/BaseTile.kt @@ -25,6 +25,7 @@ import net.minecraftforge.items.CapabilityItemHandler import net.minecraftforge.items.IItemHandler import net.minecraftforge.items.IItemHandlerModifiable import net.minecraftforge.items.wrapper.CombinedInvWrapper +import org.ender_development.catalyx.api.v1.common.extensions.orIfNotEmpty import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.client.button.AbstractButtonWrapper import org.ender_development.catalyx.core.client.button.PauseButtonWrapper @@ -82,16 +83,18 @@ abstract class BaseTile(open val mod: ICatalyxMod) : TileEntity(), BaseContainer initInventoryInputCapability() automationInput = object : WrappedItemHandler(input) { - override fun extractItem(slot: Int, amount: Int, simulate: Boolean) = ItemStack.EMPTY + override fun extractItem(slot: Int, amount: Int, simulate: Boolean) = + ItemStack.EMPTY } output = object : TileStackHandler(outputSlots, this) { - override fun insertItem(slot: Int, stack: ItemStack, simulate: Boolean) = stack + override fun insertItem(slot: Int, stack: ItemStack, simulate: Boolean) = + stack } automationOutput = object : WrappedItemHandler(output) { override fun extractItem(slot: Int, amount: Int, simulate: Boolean) = - if(!getStackInSlot(slot).isEmpty) super.extractItem(slot, amount, simulate) else ItemStack.EMPTY + getStackInSlot(slot).orIfNotEmpty { super.extractItem(slot, amount, simulate) } } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt index 26eeac1..2755eed 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/TileStackHandler.kt @@ -4,6 +4,7 @@ import net.minecraft.item.ItemStack import net.minecraft.util.EnumFacing import net.minecraftforge.items.ItemStackHandler import org.ender_development.catalyx.api.v1.common.extensions.get +import org.ender_development.catalyx.api.v1.common.extensions.orEmpty import org.ender_development.catalyx.api.v1.common.extensions.tryInsertInto import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.BaseTile.Companion.ITEM_CAP @@ -18,7 +19,10 @@ open class TileStackHandler(size: Int, val tile: BaseTile) : ItemStackHandler() tile.markDirty() } - fun clear() = (0.. 0) { incrementSlot(slot, increaseBy) stack.shrink(increaseBy) - if(stack.count <= 0 || stack.isEmpty) + if(stack.isEmpty) return ItemStack.EMPTY } } @@ -64,8 +68,7 @@ open class TileStackHandler(size: Int, val tile: BaseTile) : ItemStackHandler() if(temp.count - amount < 0) return temp.shrink(amount) - if(temp.count <= 0) this.setStackInSlot(slot, ItemStack.EMPTY) - else this.setStackInSlot(slot, temp) + setStackInSlot(slot, temp.orEmpty()) } fun eject(direction: EnumFacing): Boolean { From da1027e4091d3b07d3f7fd9299058637c7e8fcb4 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Fri, 23 Jan 2026 22:29:33 +0100 Subject: [PATCH 34/58] eat SideUtils into Utils --- .../ender_development/catalyx/api/v1/utils/SideUtils.kt | 5 ----- .../org/ender_development/catalyx/api/v1/utils/Utils.kt | 7 +++++-- 2 files changed, 5 insertions(+), 7 deletions(-) delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/SideUtils.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/SideUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/SideUtils.kt deleted file mode 100644 index 322b0cf..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/SideUtils.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.ender_development.catalyx.api.v1.utils - -import org.ender_development.catalyx.api.v1.utils.interfaces.ISideUtils - -val SideUtils: ISideUtils = org.ender_development.catalyx.core.utils.SideUtils diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt index 8e4624f..e8b6dea 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt @@ -5,11 +5,14 @@ import net.minecraftforge.fluids.Fluid import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidTank import org.ender_development.catalyx.api.v1.utils.interfaces.IBlockPosUtils +import org.ender_development.catalyx.api.v1.utils.interfaces.ISideUtils import org.ender_development.catalyx.core.utils.BlockPosUtils +import org.ender_development.catalyx.core.utils.SideUtils object Utils { - val forBlockPos: IBlockPosUtils = - BlockPosUtils + val forBlockPos: IBlockPosUtils = BlockPosUtils + + val side: ISideUtils = SideUtils // bruh... // TODO find an abstraction From 7bb4e3898b84b00ac3f15ca8f1daa271b5130cda Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Fri, 23 Jan 2026 22:37:07 +0100 Subject: [PATCH 35/58] try to do some FieldValidationBuilder shenanigans --- .../interfaces/IFieldValidationBuilder.kt | 25 ++++++++++++++++++- .../core/validation/FieldValidationBuilder.kt | 9 +++---- .../core/validation/ValidationBuilder.kt | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IFieldValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IFieldValidationBuilder.kt index b8c8bef..4895f4f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IFieldValidationBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/interfaces/IFieldValidationBuilder.kt @@ -1,5 +1,28 @@ package org.ender_development.catalyx.api.v1.validation.interfaces +import org.ender_development.catalyx.core.validation.FieldValidationBuilder + interface IFieldValidationBuilder { - // TODO + // TODO ask Ender for whether these KDocs are accurate/correct, this is his system after all + // this is kinda confusing to document + + /** + * Validate the current value of this builder with the [validator]. + */ + fun validate(validator: IValidator): IFieldValidationBuilder + + /** + * If the last message in the parent validator is related to this field, replace it with the passed in [message]. + */ + fun withMessage(message: String): FieldValidationBuilder + + /** + * Get the final validated field, or, if null, the specified [defaultValue]. + */ + fun orElse(defaultValue: V): V + + /** + * Get the final validated field. + */ + fun get(): V? } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt index 1b1682a..ab33542 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt @@ -3,11 +3,10 @@ package org.ender_development.catalyx.core.validation import org.ender_development.catalyx.api.v1.validation.interfaces.IFieldValidationBuilder import org.ender_development.catalyx.api.v1.validation.interfaces.IValidator -@Suppress("unused") class FieldValidationBuilder(value: V?, private val fieldName: String, private val parentBuilder: ValidationBuilder<*>) : IFieldValidationBuilder { private var currentValue: V? = value - fun validate(validator: IValidator): FieldValidationBuilder { + override fun validate(validator: IValidator): FieldValidationBuilder { if(currentValue != null && !validator.validate(currentValue)) { parentBuilder.addError(fieldName, "Validation failed for field '$fieldName'") currentValue = null @@ -16,7 +15,7 @@ class FieldValidationBuilder(value: V?, private val fieldName: String, privat return this } - fun withMessage(message: String): FieldValidationBuilder { + override fun withMessage(message: String): FieldValidationBuilder { // Remove the last error and replace with custom message parentBuilder.getErrors().lastOrNull()?.let { if(it.field == fieldName) { @@ -27,9 +26,9 @@ class FieldValidationBuilder(value: V?, private val fieldName: String, privat return this } - fun orElse(defaultValue: V): V = + override fun orElse(defaultValue: V): V = currentValue ?: defaultValue - fun get(): V? = + override fun get(): V? = currentValue } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt index f488717..41c3206 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt @@ -56,6 +56,6 @@ class ValidationBuilder : IValidationBuilder { fun hasWarnings(): Boolean = errors.any { it.severity == Severity.WARNING } - fun getErrors(): List = + fun getErrors(): List = // TODO replace with new kt 2.3.0 feature errors } From a32d4fac618f92dfab18b42b5820cb46f9f1c205 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Fri, 23 Jan 2026 22:59:04 +0100 Subject: [PATCH 36/58] make it build --- .../catalyx/api/v1/common/extensions/String.kt | 4 ++-- .../catalyx/core/animation/NoopAnimationStateMachine.kt | 4 ++-- .../org/ender_development/catalyx/core/blocks/BaseBlock.kt | 4 ++-- .../ender_development/catalyx/core/blocks/TESRTileBlock.kt | 4 ++-- .../catalyx/core/client/button/AbstractButtonWrapper.kt | 4 ++-- .../catalyx/core/client/gui/CatalyxGuiHandler.kt | 4 ++-- .../org/ender_development/catalyx/core/items/BaseItem.kt | 4 ++-- .../ender_development/catalyx/modules/test/DevTestModule.kt | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt index 1abae59..44000d7 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt @@ -12,7 +12,7 @@ import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.common.Loader import net.minecraftforge.oredict.OreDictionary import net.minecraftforge.oredict.OreIngredient -import org.ender_development.catalyx.api.v1.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.Utils inline fun String.toPotion(): Potion = Potion.getPotionFromResourceLocation(this)!! @@ -38,7 +38,7 @@ inline fun String.firstOre(): ItemStack = OreDictionary.getOres(this).firstOrNull().orEmpty() fun String.translate(vararg format: Any): String = - if(SideUtils.isServer) + if(Utils.side.isServer) this else I18n.format(this, *format) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt b/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt index 62808d7..aae9931 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt @@ -5,12 +5,12 @@ import net.minecraft.util.ResourceLocation import net.minecraftforge.client.model.ModelLoaderRegistry import net.minecraftforge.common.animation.ITimeValue import net.minecraftforge.common.model.animation.IAnimationStateMachine -import org.ender_development.catalyx.api.v1.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.Utils class NoopAnimationStateMachine() : IAnimationStateMachine { companion object { fun loadASM(location: ResourceLocation, customParameters: Map): IAnimationStateMachine = - if(SideUtils.isDedicatedServer) + if(Utils.side.isDedicatedServer) NoopAnimationStateMachine() else ModelLoaderRegistry.loadASM(location, ImmutableMap.copyOf(customParameters)) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt index 93512ff..29e2d1e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt @@ -15,7 +15,7 @@ import net.minecraft.world.IBlockAccess import net.minecraftforge.client.model.ModelLoader import net.minecraftforge.event.RegistryEvent import org.ender_development.catalyx.api.v1.registry.IBlockProvider -import org.ender_development.catalyx.api.v1.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.register @@ -50,7 +50,7 @@ open class BaseBlock(val mod: ICatalyxMod, name: String, material: Material = Ma override fun registerItemBlock(event: RegistryEvent.Register) { item.registryName = registryName event.registry.register(item) - if(SideUtils.isClient) + if(Utils.side.isClient) ModelLoader.setCustomModelResourceLocation(item, 0, ModelResourceLocation(registryName!!, "inventory")) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt index 5e83192..29022c6 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt @@ -1,7 +1,7 @@ package org.ender_development.catalyx.core.blocks import net.minecraftforge.fml.client.registry.ClientRegistry -import org.ender_development.catalyx.api.v1.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.client.tesr.TileRenderer import org.ender_development.catalyx.core.tiles.TESRTile @@ -11,7 +11,7 @@ import org.ender_development.catalyx.core.tiles.TESRTile */ open class TESRTileBlock(mod: ICatalyxMod, name: String, tileClass: Class, guiId: Int) : BaseRotatableTileBlock(mod, name, tileClass, guiId) { init { - if(SideUtils.isClient) + if(Utils.side.isClient) ClientRegistry.bindTileEntitySpecialRenderer(tileClass, TileRenderer) } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt index de8ba0b..de38d03 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt @@ -7,7 +7,7 @@ import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.common.network.simpleimpl.MessageContext import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -import org.ender_development.catalyx.api.v1.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.client.button.AbstractButtonWrapper.Companion.getWrapper import org.ender_development.catalyx.core.client.button.AbstractButtonWrapper.Companion.registerWrapper @@ -80,7 +80,7 @@ abstract class AbstractButtonWrapper(x: Int, y: Int, width: Int = 16, height: In } /** Guaranteed to be non-null on client-side */ - open val button = if(SideUtils.isClient) + open val button = if(Utils.side.isClient) WrappedGuiButton(x, y, width, height, this) else null diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt index 10f0981..9a1e6d1 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt @@ -8,7 +8,7 @@ import net.minecraft.tileentity.TileEntity import net.minecraft.util.math.BlockPos import net.minecraft.world.World import net.minecraftforge.fml.common.network.IGuiHandler -import org.ender_development.catalyx.api.v1.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.ICatalyxMod /** @@ -30,7 +30,7 @@ class CatalyxGuiHandler(mod: ICatalyxMod) : IGuiHandler { fun registerId(te: Class, container: Class, gui: () -> Class): Int { tileEntities.add(te) containers.add(container) - if(SideUtils.isClient) + if(Utils.side.isClient) guis.add(gui()) return tileEntities.size - 1 } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt index a3d13aa..20d3a2d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt @@ -6,7 +6,7 @@ import net.minecraft.util.ResourceLocation import net.minecraftforge.client.model.ModelLoader import net.minecraftforge.event.RegistryEvent import org.ender_development.catalyx.api.v1.registry.IItemProvider -import org.ender_development.catalyx.api.v1.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.register @@ -36,7 +36,7 @@ open class BaseItem(val mod: ICatalyxMod, val name: String) : Item(), IItemProvi override fun register(event: RegistryEvent.Register) { event.registry.register(this) - if(SideUtils.isClient) + if(Utils.side.isClient) ModelLoader.setCustomModelResourceLocation(this, 0, ModelResourceLocation(registryName!!, "inventory")) } diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt index 5011cb6..b531acd 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt @@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule -import org.ender_development.catalyx.api.v1.utils.SideUtils +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.blocks.IOTileBlock import org.ender_development.catalyx.core.blocks.multiblock.CenterBlock @@ -36,7 +36,7 @@ internal class DevTestModule : CatalyxModuleBase() { override fun load() = logger.info("Detected deobfuscated environment, adding some testing features") - override val eventBusSubscribers = if(SideUtils.isClient) listOf(TestEventHandler()) else emptyList() + override val eventBusSubscribers = if(Utils.side.isClient) listOf(TestEventHandler()) else emptyList() class TestEventHandler { val areaHighlighter = AreaHighlighter() From 2b6fb7b9104660d0d30f24c168d1ca4eaac12968 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Fri, 23 Jan 2026 23:01:33 +0100 Subject: [PATCH 37/58] explicit backing fields test basically new feature in Kotlin 2.3.0, see https://kotlinlang.org/docs/whatsnew23.html#explicit-backing-fields only issues are: - it's experimental - it required me to change build.gradle.kts, which will be overwritten after syncTemplate - my IJ is confused because it's too old to understand this lol as such, kinda asking ender and klebe to give feedback on this, and hopefully that won't turn into another ModuleIdentifier :blobcatcosystars: I'm fine with reverting this tbh. --- build.gradle.kts | 7 ++++++- gradle.properties | 2 +- .../catalyx/core/validation/FieldValidationBuilder.kt | 4 ++-- .../catalyx/core/validation/ValidationBuilder.kt | 10 +++++----- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b32f37a..ef2421c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,7 +63,12 @@ checkSubPropertiesExist("use_groovyscript", "groovyscript_version") checkSubPropertiesExist("use_hei", "hei_version") checkSubPropertiesExist("use_top", "top_version") -kotlin { jvmToolchain(8) } +kotlin { + jvmToolchain(8) + compilerOptions { + freeCompilerArgs.add("-Xexplicit-backing-fields") + } +} minecraft { mcVersion = propertyString("minecraft_version") diff --git a/gradle.properties b/gradle.properties index e94d044..5852456 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,7 @@ generate_javadocs_jar = true # <-- Kotlin --> # <------------> # The version of Kotlin to use. -kotlin_version = 2.2.20 +kotlin_version = 2.3.0 diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt index ab33542..e038d54 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/FieldValidationBuilder.kt @@ -17,9 +17,9 @@ class FieldValidationBuilder(value: V?, private val fieldName: String, privat override fun withMessage(message: String): FieldValidationBuilder { // Remove the last error and replace with custom message - parentBuilder.getErrors().lastOrNull()?.let { + parentBuilder.errors.lastOrNull()?.let { if(it.field == fieldName) { - parentBuilder.errors.removeLast() + parentBuilder.mutableErrors.removeLast() parentBuilder.addError(fieldName, message) } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt index 41c3206..ecdc48c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/validation/ValidationBuilder.kt @@ -6,9 +6,12 @@ import org.ender_development.catalyx.api.v1.validation.interfaces.IValidator @Suppress("UNUSED") class ValidationBuilder : IValidationBuilder { - internal val errors = mutableListOf() + val errors: List + field = mutableListOf() private var target: T? = null + internal val mutableErrors: MutableList = errors + fun field(value: V?, fieldName: String, vararg validators: IValidator): FieldValidationBuilder = FieldValidationBuilder(value, fieldName, this).apply { validators.forEach(::validate) @@ -39,7 +42,7 @@ class ValidationBuilder : IValidationBuilder { addError(field, message, code, Severity.WARNING) fun build(data: T?): ValidationResult { - val onlyWarnings = errors.none { it.severity != Severity.WARNING } + val onlyWarnings = !errors.any { it.severity != Severity.WARNING } return if(onlyWarnings && data != null) ValidationResult.success(data) @@ -55,7 +58,4 @@ class ValidationBuilder : IValidationBuilder { fun hasWarnings(): Boolean = errors.any { it.severity == Severity.WARNING } - - fun getErrors(): List = // TODO replace with new kt 2.3.0 feature - errors } From 35274167c500e554d3e87684e02af70e61dff062 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 25 Jan 2026 11:00:01 +0100 Subject: [PATCH 38/58] slight IItemStackHash cleanup and also new extension idk why the IISH thingies were inline making new instances, when the instances themselves are immutable --- .../api/v1/common/extensions/ItemStack.kt | 11 ++++ .../catalyx/core/recipes/Recipe.kt | 7 +-- .../core/recipes/ingredients/ItemInput.kt | 3 +- .../core/recipes/ingredients/OreInput.kt | 3 +- .../catalyx/core/utils/IItemStackHash.kt | 52 ++++++++----------- 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt index 04868eb..420c42f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/ItemStack.kt @@ -4,10 +4,21 @@ package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.item.ItemStack import net.minecraft.item.crafting.Ingredient +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract inline fun ItemStack?.orEmpty(): ItemStack = this?.takeIf { !isEmpty } ?: ItemStack.EMPTY +@OptIn(ExperimentalContracts::class) +inline fun ItemStack?.isNullOrEmpty(): Boolean { + contract { + // yes this is needed + returns(false) implies (this@isNullOrEmpty is ItemStack) + } + return this?.isEmpty != false +} + inline fun ItemStack.orIfNotEmpty(crossinline notEmpty: (ItemStack) -> ItemStack): ItemStack = if(isEmpty) ItemStack.EMPTY diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt index 516e757..b9c8def 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/Recipe.kt @@ -8,6 +8,7 @@ import net.minecraftforge.items.IItemHandlerModifiable import net.minecraftforge.items.ItemHandlerHelper import net.minecraftforge.oredict.OreDictionary import org.ender_development.catalyx.api.v1.common.extensions.copyOf +import org.ender_development.catalyx.api.v1.common.extensions.isNullOrEmpty import org.ender_development.catalyx.core.recipes.chance.output.ChancedFluidOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedItemOutput import org.ender_development.catalyx.core.recipes.chance.output.ChancedOutputList @@ -154,10 +155,10 @@ class Recipe ( val inputStack = inputs[i] if(i == indexed) { ++indexed - itemAmountInSlot[i] = if(inputStack?.isEmpty != false) 0 else inputStack.count + itemAmountInSlot[i] = if(inputStack.isNullOrEmpty()) 0 else inputStack.count } - if(inputStack?.isEmpty != false || !it.acceptsStack(inputStack)) + if(inputStack.isNullOrEmpty() || !it.acceptsStack(inputStack)) continue val itemAmountToConsume = itemAmountInSlot[i].coerceAtMost(ingredientAmount) @@ -428,7 +429,7 @@ class Recipe ( inputs.forEachIndexed { index, itemStack -> val itemAmount = itemAmountInSlot[index] - if(itemStack?.isEmpty != false || itemStack.count == itemAmount) + if(itemStack.isNullOrEmpty() || itemStack.count == itemAmount) return@forEachIndexed itemStack.count = itemAmount diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/ItemInput.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/ItemInput.kt index ed9e693..0f279eb 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/ItemInput.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/ItemInput.kt @@ -5,6 +5,7 @@ import net.minecraft.creativetab.CreativeTabs import net.minecraft.item.ItemStack import net.minecraft.util.NonNullList import net.minecraftforge.oredict.OreDictionary +import org.ender_development.catalyx.api.v1.common.extensions.isNullOrEmpty import org.ender_development.catalyx.core.recipes.ingredients.entries.ItemToMetaList import java.util.* @@ -68,7 +69,7 @@ class ItemInput : RecipeInput { inputStacks override fun acceptsStack(stack: ItemStack?): Boolean { - if(stack == null || stack.isEmpty) + if(stack.isNullOrEmpty()) return false itemList.forEach { metaList -> diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/OreInput.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/OreInput.kt index 1cbab02..44603e3 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/OreInput.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/OreInput.kt @@ -2,6 +2,7 @@ package org.ender_development.catalyx.core.recipes.ingredients import net.minecraft.item.ItemStack import net.minecraftforge.oredict.OreDictionary +import org.ender_development.catalyx.api.v1.common.extensions.isNullOrEmpty import java.util.* class OreInput : RecipeInput { @@ -65,7 +66,7 @@ class OreInput : RecipeInput { ore override fun acceptsStack(stack: ItemStack?): Boolean { - if(stack == null || stack.isEmpty) + if(stack.isNullOrEmpty()) return false nbtMatcher?.let { matcher -> diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/IItemStackHash.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/IItemStackHash.kt index 4c5d9d2..ac6b0f8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/IItemStackHash.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/IItemStackHash.kt @@ -2,6 +2,7 @@ package org.ender_development.catalyx.core.utils import it.unimi.dsi.fastutil.Hash import net.minecraft.item.ItemStack +import org.ender_development.catalyx.api.v1.common.extensions.isNullOrEmpty import java.util.* /** @@ -17,42 +18,33 @@ interface IItemStackHash : Hash.Strategy { inline get() = Builder() /** - * Generates an [IItemStackHash] instance configured to compare every aspect of ItemStacks. - * - * @return a new [IItemStackHash] instance as described above. + * An [IItemStackHash] instance configured to compare every aspect of ItemStacks. */ - val comparingAll: IItemStackHash - inline get() = builder.apply { - item = true - meta = true - damage = true - nbt = true - amount = true - }.build() + val comparingAll = builder.apply { + item = true + meta = true + damage = true + nbt = true + amount = true + }.build() /** - * Generates an [IItemStackHash] instance configured to compare every aspect of ItemStacks except the quantity and meta. - * - * @return a new [IItemStackHash] instance as described above. + * An [IItemStackHash] instance configured to compare item type, damage and NBT (ergo everything except quantity and meta). */ - val comparingAllButCount: IItemStackHash - inline get() = builder.apply { - item = true - damage = true - nbt = true - }.build() + val comparingAllButCount = builder.apply { + item = true + damage = true + nbt = true + }.build() /** - * Generates an [IItemStackHash] instance configured to compare Item type and metadata only. - * - * @return a new [IItemStackHash] instance as described above. + * An [IItemStackHash] instance configured to compare item type, damage and quantity. */ - val comparingItemDamageCount: IItemStackHash - inline get() = builder.apply { - item = true - damage = true - amount = true - }.build() + val comparingItemDamageCount = builder.apply { + item = true + damage = true + amount = true + }.build() } /** @@ -89,7 +81,7 @@ interface IItemStackHash : Hash.Strategy { } override fun hashCode(stack: ItemStack?): Int { - if(stack == null || stack.isEmpty) + if(stack.isNullOrEmpty()) return 0 return Objects.hash( From 454a65d2bbcba38db24b77b0b6895ae7b7c85391 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 25 Jan 2026 11:00:10 +0100 Subject: [PATCH 39/58] spotless complaining --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 13c525c..eec9b58 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ link(shield("License", "License", "LGPL-3.0", "blue"), "{{mod_url}}/blob/master/ "{{mod_description}}".replace("Kotlin", link("Kotlin", "https://kotlinlang.org/")).replace("Ender-Development's mods", link("Ender-Development's mods", "https://www.curseforge.com/members/enderdevelopment/projects")) ].join("\n") --> -[![Kotlin](https://img.shields.io/badge/Kotlin-2.2.20-blue.svg)](https://kotlinlang.org/) +[![Kotlin](https://img.shields.io/badge/Kotlin-2.3.0-blue.svg)](https://kotlinlang.org/) [![Maven artifact](https://img.shields.io/badge/Maven-org.ender__development%3Acatalyx-blue.svg)](https://maven.ender-development.org/org/ender_development/catalyx/) [![Version](https://img.shields.io/badge/Version-0.1.0-blue.svg)](https://github.com/Ender-Development/Catalyx/commits/master) [![License](https://img.shields.io/badge/License-LGPL--3.0-blue.svg)](https://github.com/Ender-Development/Catalyx/blob/master/LICENSE) From 2e8ca6570c36380aa236862d82ab7b076f8f645f Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 25 Jan 2026 11:08:22 +0100 Subject: [PATCH 40/58] idk why not --- .../catalyx/api/v1/common/extensions/Container.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Container.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Container.kt index 41dff5c..da33444 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Container.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Container.kt @@ -4,6 +4,10 @@ package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.inventory.Container import net.minecraft.inventory.Slot +import net.minecraft.item.ItemStack inline operator fun Container.get(slotId: Int): Slot = getSlot(slotId) + +inline operator fun Container.set(slotId: Int, stack: ItemStack) = + putStackInSlot(slotId, stack) From 7d3951fea371a37378d24c1bb5b8400f84935654 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 25 Jan 2026 11:17:01 +0100 Subject: [PATCH 41/58] merge DevUtils into SideUtils, rename to EnvironmentUtils --- .../catalyx/api/v1/common/DevUtils.kt | 17 ----------------- .../catalyx/api/v1/common/extensions/String.kt | 2 +- .../catalyx/api/v1/utils/Utils.kt | 6 +++--- .../v1/utils/interfaces/IEnvironmentUtils.kt | 17 +++++++++++++++++ .../api/v1/utils/interfaces/ISideUtils.kt | 11 ----------- .../core/animation/NoopAnimationStateMachine.kt | 2 +- .../catalyx/core/blocks/BaseBlock.kt | 2 +- .../catalyx/core/blocks/TESRTileBlock.kt | 2 +- .../core/client/button/AbstractButtonWrapper.kt | 2 +- .../core/client/gui/CatalyxGuiHandler.kt | 2 +- .../catalyx/core/items/BaseItem.kt | 2 +- .../catalyx/core/items/CopyPasteTool.kt | 6 +++--- .../catalyx/core/module/ModuleManager.kt | 4 ++-- .../core/registry/CatalyxBlockRegistry.kt | 6 +++--- .../core/registry/CatalyxItemRegistry.kt | 4 ++-- .../catalyx/core/tiles/CenterTile.kt | 4 ++-- .../utils/{SideUtils.kt => EnvironmentUtils.kt} | 6 ++++-- .../catalyx/modules/test/DevTestModule.kt | 2 +- 18 files changed, 44 insertions(+), 53 deletions(-) delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/common/DevUtils.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IEnvironmentUtils.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/ISideUtils.kt rename src/main/kotlin/org/ender_development/catalyx/core/utils/{SideUtils.kt => EnvironmentUtils.kt} (64%) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/DevUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/DevUtils.kt deleted file mode 100644 index 3833bcb..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/DevUtils.kt +++ /dev/null @@ -1,17 +0,0 @@ -package org.ender_development.catalyx.api.v1.common - -import net.minecraft.launchwrapper.Launch - -/** - * Utility object for checking whether you're in a dev instance - */ -object DevUtils { - /** - * Whether the environment is deobfuscated (dev environment) - * @see net.minecraftforge.fml.relauncher.CoreModManager#L208 - * @return true if deobfuscated, false if obfuscated - */ - val isDeobfuscated: Boolean - //inline get() = CoreModManager.deobfuscatedEnvironment - inline get() = Launch.blackboard["fml.deobfuscatedEnvironment"] as Boolean -} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt index 44000d7..dca310a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt @@ -38,7 +38,7 @@ inline fun String.firstOre(): ItemStack = OreDictionary.getOres(this).firstOrNull().orEmpty() fun String.translate(vararg format: Any): String = - if(Utils.side.isServer) + if(Utils.environment.isServer) this else I18n.format(this, *format) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt index e8b6dea..95178ff 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt @@ -5,14 +5,14 @@ import net.minecraftforge.fluids.Fluid import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidTank import org.ender_development.catalyx.api.v1.utils.interfaces.IBlockPosUtils -import org.ender_development.catalyx.api.v1.utils.interfaces.ISideUtils +import org.ender_development.catalyx.api.v1.utils.interfaces.IEnvironmentUtils import org.ender_development.catalyx.core.utils.BlockPosUtils -import org.ender_development.catalyx.core.utils.SideUtils +import org.ender_development.catalyx.core.utils.EnvironmentUtils object Utils { val forBlockPos: IBlockPosUtils = BlockPosUtils - val side: ISideUtils = SideUtils + val environment: IEnvironmentUtils = EnvironmentUtils // bruh... // TODO find an abstraction diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IEnvironmentUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IEnvironmentUtils.kt new file mode 100644 index 0000000..48f08ef --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/IEnvironmentUtils.kt @@ -0,0 +1,17 @@ +package org.ender_development.catalyx.api.v1.utils.interfaces + +/** + * Utility object for checking the current environment - side (client or server) and deobfuscation. + */ +interface IEnvironmentUtils { + val isClient: Boolean + val isServer: Boolean + val isDedicatedClient: Boolean + val isDedicatedServer: Boolean + + /** + * Whether you're in a deobfuscated (dev) environment + * @see [CoreModManager:208][net.minecraftforge.fml.relauncher.CoreModManager] + */ + val isDeobfuscated: Boolean +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/ISideUtils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/ISideUtils.kt deleted file mode 100644 index 733a8b7..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/interfaces/ISideUtils.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.ender_development.catalyx.api.v1.utils.interfaces - -/** - * Utility object for checking the current side (client or server). - */ -interface ISideUtils { - val isClient: Boolean - val isServer: Boolean - val isDedicatedClient: Boolean - val isDedicatedServer: Boolean -} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt b/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt index aae9931..3fa5138 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/animation/NoopAnimationStateMachine.kt @@ -10,7 +10,7 @@ import org.ender_development.catalyx.api.v1.utils.Utils class NoopAnimationStateMachine() : IAnimationStateMachine { companion object { fun loadASM(location: ResourceLocation, customParameters: Map): IAnimationStateMachine = - if(Utils.side.isDedicatedServer) + if(Utils.environment.isDedicatedServer) NoopAnimationStateMachine() else ModelLoaderRegistry.loadASM(location, ImmutableMap.copyOf(customParameters)) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt index 29e2d1e..283184e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt @@ -50,7 +50,7 @@ open class BaseBlock(val mod: ICatalyxMod, name: String, material: Material = Ma override fun registerItemBlock(event: RegistryEvent.Register) { item.registryName = registryName event.registry.register(item) - if(Utils.side.isClient) + if(Utils.environment.isClient) ModelLoader.setCustomModelResourceLocation(item, 0, ModelResourceLocation(registryName!!, "inventory")) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt index 29022c6..2e665df 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/TESRTileBlock.kt @@ -11,7 +11,7 @@ import org.ender_development.catalyx.core.tiles.TESRTile */ open class TESRTileBlock(mod: ICatalyxMod, name: String, tileClass: Class, guiId: Int) : BaseRotatableTileBlock(mod, name, tileClass, guiId) { init { - if(Utils.side.isClient) + if(Utils.environment.isClient) ClientRegistry.bindTileEntitySpecialRenderer(tileClass, TileRenderer) } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt index de38d03..7ac5676 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/button/AbstractButtonWrapper.kt @@ -80,7 +80,7 @@ abstract class AbstractButtonWrapper(x: Int, y: Int, width: Int = 16, height: In } /** Guaranteed to be non-null on client-side */ - open val button = if(Utils.side.isClient) + open val button = if(Utils.environment.isClient) WrappedGuiButton(x, y, width, height, this) else null diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt index 9a1e6d1..42ee25e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/gui/CatalyxGuiHandler.kt @@ -30,7 +30,7 @@ class CatalyxGuiHandler(mod: ICatalyxMod) : IGuiHandler { fun registerId(te: Class, container: Class, gui: () -> Class): Int { tileEntities.add(te) containers.add(container) - if(Utils.side.isClient) + if(Utils.environment.isClient) guis.add(gui()) return tileEntities.size - 1 } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt index 20d3a2d..a82e091 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt @@ -36,7 +36,7 @@ open class BaseItem(val mod: ICatalyxMod, val name: String) : Item(), IItemProvi override fun register(event: RegistryEvent.Register) { event.registry.register(this) - if(Utils.side.isClient) + if(Utils.environment.isClient) ModelLoader.setCustomModelResourceLocation(this, 0, ModelResourceLocation(registryName!!, "inventory")) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt index 5483a54..cc183b6 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt @@ -10,7 +10,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.world.World import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.common.DevUtils +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.client.gui.BaseGuiTyped import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.helper.ICopyPasteExtraTile @@ -82,7 +82,7 @@ class CopyPasteTool() : BaseItem(Catalyx, "copy_paste_tool") { tooltip as MutableList tooltip.add("TODO ;p") - if(DevUtils.isDeobfuscated) { + if(Utils.environment.isDeobfuscated) { tooltip.add("") tooltip.add("${stack.tagCompound?.getString(NBT_COPIED_BLOCK_KEY)}") tooltip.add("${stack.tagCompound?.getCompoundTag(NBT_COPIED_DATA_KEY)}") @@ -94,5 +94,5 @@ class CopyPasteTool() : BaseItem(Catalyx, "copy_paste_tool") { * TODO tooltip, name translation, maybe signify what blocks you can actually copy across ;p */ override fun isEnabled() = - DevUtils.isDeobfuscated + Utils.environment.isDeobfuscated } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt index b8cfcfd..8d8cb85 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/module/ModuleManager.kt @@ -11,7 +11,6 @@ import net.minecraftforge.fml.common.ModContainer import net.minecraftforge.fml.common.discovery.ASMDataTable import net.minecraftforge.fml.common.event.* import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.common.DevUtils import org.ender_development.catalyx.api.v1.common.extensions.modLoaded import org.ender_development.catalyx.api.v1.modules.Modules import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule @@ -19,6 +18,7 @@ import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModuleCon import org.ender_development.catalyx.api.v1.modules.interfaces.ICatalyxModule import org.ender_development.catalyx.api.v1.modules.interfaces.IModuleIdentifier import org.ender_development.catalyx.api.v1.modules.interfaces.IModuleManager +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.module.ModuleManager.configuration import org.ender_development.catalyx.core.module.ModuleManager.discoveredContainers @@ -386,7 +386,7 @@ object ModuleManager : IModuleManager { private fun shouldModuleBeEnabled(module: ICatalyxModule): Boolean { val annotation = module.annotation val prop = configuration.get(MODULE_CFG_CATEGORY_NAME, "${annotation.containerId}:${annotation.moduleId}", true, getConfigComment(module)) - return prop.boolean && (!annotation.testModule || DevUtils.isDeobfuscated) + return prop.boolean && (!annotation.testModule || Utils.environment.isDeobfuscated) } // --- Helper properties --- diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt index 780a091..c8eb530 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt @@ -6,10 +6,10 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.common.DevUtils import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.api.v1.registry.IBlockProvider import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.Reference @Mod.EventBusSubscriber(modid = Reference.MODID) @@ -21,7 +21,7 @@ object CatalyxBlockRegistry : ICatalyxRegistry { Catalyx.LOGGER.debug("Block Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} block${registry.size.plural}") registry.enabled.forEach { it.register(event) - if(DevUtils.isDeobfuscated) + if(Utils.environment.isDeobfuscated) Catalyx.LOGGER.debug("Registered block: {}", it.instance.registryName) } } @@ -31,7 +31,7 @@ object CatalyxBlockRegistry : ICatalyxRegistry { Catalyx.LOGGER.debug("Item Block Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} block item${registry.size.plural}") registry.enabled.forEach { it.registerItemBlock(event) - if(DevUtils.isDeobfuscated) + if(Utils.environment.isDeobfuscated) Catalyx.LOGGER.debug("Registered block item: {}", it.item.registryName) } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt index a7f9645..55ff01a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt @@ -5,10 +5,10 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.common.DevUtils import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.api.v1.registry.IItemProvider +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.Reference @Mod.EventBusSubscriber(modid = Reference.MODID) @@ -20,7 +20,7 @@ object CatalyxItemRegistry : ICatalyxRegistry { Catalyx.LOGGER.debug("Item Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} item${registry.size.plural}") registry.enabled.forEach { it.register(event) - if(DevUtils.isDeobfuscated) + if(Utils.environment.isDeobfuscated) Catalyx.LOGGER.debug("Registered item: {}", it.instance.registryName) } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt index 66534bf..1f88977 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/CenterTile.kt @@ -7,15 +7,15 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.world.World import org.ender_development.catalyx.Catalyx -import org.ender_development.catalyx.api.v1.common.DevUtils import org.ender_development.catalyx.api.v1.common.extensions.getHorizontalSurroundings +import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.blocks.multiblock.IMultiblockEdge import org.ender_development.catalyx.core.blocks.multiblock.IMultiblockTile open class CenterTile(mod: ICatalyxMod) : BaseTile(mod), IMultiblockTile { internal constructor() : this(Catalyx) { - if(!DevUtils.isDeobfuscated) + if(!Utils.environment.isDeobfuscated) error("use the full constructor") } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/SideUtils.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/EnvironmentUtils.kt similarity index 64% rename from src/main/kotlin/org/ender_development/catalyx/core/utils/SideUtils.kt rename to src/main/kotlin/org/ender_development/catalyx/core/utils/EnvironmentUtils.kt index 71d9f63..beb74da 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/SideUtils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/EnvironmentUtils.kt @@ -1,16 +1,18 @@ package org.ender_development.catalyx.core.utils +import net.minecraft.launchwrapper.Launch import net.minecraftforge.fml.common.FMLCommonHandler -import org.ender_development.catalyx.api.v1.utils.interfaces.ISideUtils +import org.ender_development.catalyx.api.v1.utils.interfaces.IEnvironmentUtils /** * Utility object for checking the current side (client or server). */ -object SideUtils : ISideUtils { +object EnvironmentUtils : IEnvironmentUtils { private val handler = FMLCommonHandler.instance() override val isClient = handler.effectiveSide.isClient override val isServer = handler.effectiveSide.isServer override val isDedicatedClient = handler.side.isClient override val isDedicatedServer = handler.side.isServer + override val isDeobfuscated = Launch.blackboard["fml.deobfuscatedEnvironment"] as Boolean } diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt index b531acd..81e4b37 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt @@ -36,7 +36,7 @@ internal class DevTestModule : CatalyxModuleBase() { override fun load() = logger.info("Detected deobfuscated environment, adding some testing features") - override val eventBusSubscribers = if(Utils.side.isClient) listOf(TestEventHandler()) else emptyList() + override val eventBusSubscribers = if(Utils.environment.isClient) listOf(TestEventHandler()) else emptyList() class TestEventHandler { val areaHighlighter = AreaHighlighter() From 5301d6bf86b676ea150d571d01100f7bedec265c Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Sun, 25 Jan 2026 11:17:43 +0100 Subject: [PATCH 42/58] =?UTF-8?q?I=20can=20spell=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt index 95178ff..5e2088c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt @@ -18,7 +18,7 @@ object Utils { // TODO find an abstraction @Suppress("ClassName") object forFluidTanks { - // These cannot be an extension as there's currently no way to create a static extension for a JVM class afact (see https://youtrack.jetbrains.com/issue/KT-11968) + // These cannot be an extension as there's currently no way to create a static extension for a JVM class afaict (see https://youtrack.jetbrains.com/issue/KT-11968) inline fun create(tile: TileEntity, capacity: Int, canFill: Boolean, canDrain: Boolean, crossinline onContentsChangedCallback: () -> Unit) = object : FluidTank(capacity) { From 51f7a98c5e0cc846dc2e50f01032defff2373808 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Mon, 26 Jan 2026 10:22:44 +0100 Subject: [PATCH 43/58] some small annoying changes for no reason --- .../catalyx/core/recipes/RecipeMap.kt | 2 +- .../core/recipes/ingredients/nbt/IMatcher.kt | 55 ++++++++----------- .../core/recipes/ingredients/nbt/TagType.kt | 12 ++-- .../catalyx/core/utils/Delegates.kt | 4 +- 4 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt index 8455d0d..163bb50 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt @@ -272,7 +272,7 @@ class RecipeMap> { return true if(index >= ingredients.size) - throw IllegalStateException("Index $index is out of bounds for ingredients list of size ${ingredients.size}") + error("Index $index is out of bounds for ingredients list of size ${ingredients.size}") val current = ingredients[index] val branchRight = Branch() diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt index 4b3201a..8d8b6c8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/IMatcher.kt @@ -32,7 +32,7 @@ interface IMatcher { if(tag == null || condition == null || condition.tagType == null) return false - if(!TagType.isNumeric(condition.tagType) || !hasKey(tag, condition.nbtKey!!, condition.tagType.typeId)) + if(!condition.tagType.isNumeric() || !hasKey(tag, condition.nbtKey!!, condition.tagType.typeId)) return false return inequality(tag.getLong(condition.nbtKey), (condition.value as Number).toLong()) @@ -73,10 +73,7 @@ interface IMatcher { tagValue >= conditionValue } - /** - * Check if the NBT tag contains the key specified in the condition and if its value is equal to the value specified in the condition. - */ - object EQUAL_TO : IMatcher { + private interface EqualityBase : IMatcher { override fun evaluate(tag: NBTTagCompound?, condition: NBTCondition?): Boolean { if(tag == null || condition == null || condition.tagType == null) return false @@ -84,7 +81,7 @@ interface IMatcher { if(!hasKey(tag, condition.nbtKey!!, condition.tagType.typeId)) return false - return if(TagType.isNumeric(condition.tagType)) + return if(condition.tagType.isNumeric()) tag.getLong(condition.nbtKey) == (condition.value as Number).toLong() else when(condition.tagType) { @@ -93,39 +90,31 @@ interface IMatcher { TagType.LONG_ARRAY -> tag.getLongArray(condition.nbtKey) contentEquals condition.value as LongArray TagType.LIST -> condition is NBTListCondition && tag.getTagList(condition.nbtKey, condition.listTagType.typeId).tagList == condition.value TagType.STRING -> tag.getString(condition.nbtKey) == condition.value - TagType.COMPOUND -> tag.getCompoundTag(condition.nbtKey) == condition.value - else -> throw IllegalStateException("TagType#isNumeric returned false on a numeric TagType") + TagType.COMPOUND -> compound(tag, condition) + else -> error("TagType#isNumeric returned false on a numeric TagType") } } + + fun compound(tag: NBTTagCompound, condition: NBTCondition): Boolean } /** * Check if the NBT tag contains the key specified in the condition and if its value is equal to the value specified in the condition. - * If the value is a compound tag, it will recursively check if all keys and values match. */ - object RECURSIVE_EQUAL_TO : IMatcher { // TODO: this and EQUAL_TO are basically the same matcher except for TagType.COMPOUND, could abstract them away to not basically duplicate the same code twice - override fun evaluate(tag: NBTTagCompound?, condition: NBTCondition?): Boolean { - if(tag == null || condition == null || condition.tagType == null) - return false - - if(!hasKey(tag, condition.nbtKey!!, condition.tagType.typeId)) - return false + object EQUAL_TO : EqualityBase { + override fun compound(tag: NBTTagCompound, condition: NBTCondition) = + tag.getCompoundTag(condition.nbtKey!!) == condition.value + } - return if(TagType.isNumeric(condition.tagType)) - tag.getLong(condition.nbtKey) == (condition.value as Number).toLong() - else - when(condition.tagType) { - TagType.BYTE_ARRAY -> tag.getByteArray(condition.nbtKey) contentEquals condition.value as ByteArray - TagType.INT_ARRAY -> tag.getIntArray(condition.nbtKey) contentEquals condition.value as IntArray - TagType.LONG_ARRAY -> tag.getLongArray(condition.nbtKey) contentEquals condition.value as LongArray - TagType.LIST -> condition is NBTListCondition && tag.getTagList(condition.nbtKey, condition.listTagType.typeId).tagList == condition.value - TagType.STRING -> tag.getString(condition.nbtKey).equals(condition.value as String) - TagType.COMPOUND -> tag.getCompoundTag(condition.nbtKey).let { tag -> - condition.value is NBTCondition && evaluate(tag, condition.value) || tag == condition.value - } - else -> throw IllegalStateException("TagType#isNumeric returned false on a numeric TagType") - } - } + /** + * Check if the NBT tag contains the key specified in the condition and if its value is equal to the value specified in the condition. + * If the value is a compound tag, it will recursively check if all keys and values match. + */ + object RECURSIVE_EQUAL_TO : EqualityBase { + override fun compound(tag: NBTTagCompound, condition: NBTCondition) = + tag.getCompoundTag(condition.nbtKey!!).let { tag -> + condition.value is NBTCondition && evaluate(tag, condition.value) || tag == condition.value + } } /** @@ -140,7 +129,7 @@ interface IMatcher { if(!hasKey(tag, condition.nbtKey!!, condition.tagType.typeId)) return true - return if(TagType.isNumeric(condition.tagType)) + return if(condition.tagType.isNumeric()) tag.getLong(condition.nbtKey) == 0L else { when(condition.tagType) { @@ -150,7 +139,7 @@ interface IMatcher { TagType.LIST -> condition is NBTListCondition && tag.getTagList(condition.nbtKey, condition.listTagType.typeId).isEmpty TagType.STRING -> tag.getString(condition.nbtKey).isEmpty() TagType.COMPOUND -> tag.getCompoundTag(condition.nbtKey).isEmpty - else -> throw IllegalStateException("TagType#isNumeric returned false on a numeric TagType") + else -> error("TagType#isNumeric returned false on a numeric TagType") } } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/TagType.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/TagType.kt index 241650e..b39a1f1 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/TagType.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/TagType.kt @@ -16,11 +16,9 @@ enum class TagType(val typeId: Int) { LONG_ARRAY(12), NUMBER(99); - companion object { - fun isNumeric(tagType: TagType) = - when(tagType) { - BOOLEAN, BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, NUMBER -> true - else -> false - } - } + fun isNumeric() = + when(this) { + BOOLEAN, BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, NUMBER -> true + else -> false + } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt index 2dfe66f..fe85c55 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/Delegates.kt @@ -24,7 +24,7 @@ object Delegates { private class OnlyIfFalse(val modName: String) : ReadWriteProperty { override fun getValue(thisRef: Any?, property: KProperty<*>): V { - throw IllegalStateException("Tried to get property '${property.name}' without mod '$modName' being loaded") + error("Tried to get property '${property.name}' without mod '$modName' being loaded") } override fun setValue(thisRef: Any?, property: KProperty<*>, value: V) {} @@ -34,7 +34,7 @@ object Delegates { var value: V? = null override fun getValue(thisRef: Any?, property: KProperty<*>): V { - return value ?: throw IllegalStateException("Tried to get property '${property.name}' before initializing it") + return value ?: error("Tried to get property '${property.name}' before initializing it") } override fun setValue(thisRef: Any?, property: KProperty<*>, value: V) { From c1c3caaeecea8860c07a1002cc08e871dcb97f69 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Mon, 26 Jan 2026 10:23:02 +0100 Subject: [PATCH 44/58] more stuff from earlier kt versions idk --- build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index ef2421c..00dee5c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -67,6 +67,8 @@ kotlin { jvmToolchain(8) compilerOptions { freeCompilerArgs.add("-Xexplicit-backing-fields") + freeCompilerArgs.add("-Xcontext-sensitive-resolution") + extraWarnings.set(true) } } From 65913fdaaccc15c38a41128b863beaa1d2d715c9 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Mon, 26 Jan 2026 16:42:48 +0100 Subject: [PATCH 45/58] some other smaller changes --- .../catalyx/core/config/ConfigHandler.kt | 4 +- .../catalyx/core/config/ConfigParser.kt | 42 +++++++++---------- .../catalyx/core/items/CopyPasteTool.kt | 2 +- .../recipes/ingredients/nbt/NBTCondition.kt | 2 +- .../ingredients/nbt/NBTListCondition.kt | 2 +- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt index aeebff6..c5ca6a8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt @@ -18,7 +18,7 @@ class ConfigHandler(configData: Iterable(configData: Iterable if(meta == IGNORE_META) other.isItemEqualIgnoreDurability(toItemStack()) else other.isItemEqual(toItemStack()) - is ConfigItemStack -> modid == other.modid && itemid == other.itemid && meta == other.meta - else -> super.equals(other) + is ConfigItemStack -> modId == other.modId && itemId == other.itemId && meta == other.meta + else -> this === other } open fun toItemStack() = - ItemStack(item ?: throw NullPointerException("Item not found: $modid:$itemid"), 1, meta) + ItemStack(item ?: throw NullPointerException("Item not found: $modId:$itemId"), 1, meta) protected fun parseConfigString(configString: String) { val parts = configString.split(":") if(parts.size != 2 && parts.size != 3) throw IllegalArgumentException("Invalid config string format: $configString") - modid = parts[0] - itemid = parts[1] + modId = parts[0] + itemId = parts[1] if(parts.size == 3) meta = parts[2].toInt() - item = Item.getByNameOrId("$modid:$itemid") // check this in validateConfigItem? + item = Item.getByNameOrId("$modId:$itemId") // check this in validateConfigItem? } protected fun validateConfigItem() { - if(modid == null || itemid == null) + if(modId == null || itemId == null) throw IllegalArgumentException("Mod ID and item name cannot be null") - if(!modid.modLoaded()) - throw IllegalArgumentException("Mod ID is not loaded: $modid") + if(!modId.modLoaded()) + throw IllegalArgumentException("Mod ID is not loaded: $modId") if(meta < IGNORE_META) throw IllegalArgumentException("Meta value cannot be negative") } + + override fun hashCode() = + Objects.hash(modId, itemId, meta) } /** @@ -131,17 +134,12 @@ object ConfigParser { internal const val IGNORE_META = -1 } - private var modId: String? = null - private var blockId: String? = null - private var meta: Int = IGNORE_META + protected var modId: String? = null + protected var blockId: String? = null + protected var meta: Int = IGNORE_META - open val block: Block? - get() { - val id = ResourceLocation(modId ?: return null, blockId ?: return null) - if(!Block.REGISTRY.containsKey(id)) - return null - return Block.REGISTRY.getObject(id) - } + open val block: Block? // my IJ might say this (v) is an error, but this is actually allowed by default since Kotlin 2.3 + get() = Block.REGISTRY.registryObjects[ResourceLocation(modId ?: return null, blockId ?: return null)] open val state: IBlockState? @Suppress("DEPRECATION") diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt index cc183b6..e05c621 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt @@ -84,7 +84,7 @@ class CopyPasteTool() : BaseItem(Catalyx, "copy_paste_tool") { if(Utils.environment.isDeobfuscated) { tooltip.add("") - tooltip.add("${stack.tagCompound?.getString(NBT_COPIED_BLOCK_KEY)}") + tooltip.add(stack.tagCompound?.getString(NBT_COPIED_BLOCK_KEY)) tooltip.add("${stack.tagCompound?.getCompoundTag(NBT_COPIED_DATA_KEY)}") } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/NBTCondition.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/NBTCondition.kt index abe8696..c036633 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/NBTCondition.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/NBTCondition.kt @@ -34,5 +34,5 @@ open class NBTCondition { Objects.hash(tagType, nbtKey, value) override fun equals(other: Any?) = - this === other || (other is NBTCondition && tagType == other.tagType && nbtKey.equals(other.nbtKey) && value == other.value) + this === other || (other is NBTCondition && tagType == other.tagType && nbtKey == other.nbtKey && value == other.value) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/NBTListCondition.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/NBTListCondition.kt index 0fcfa88..d5d6747 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/NBTListCondition.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/ingredients/nbt/NBTListCondition.kt @@ -22,5 +22,5 @@ class NBTListCondition : NBTCondition { Objects.hash(tagType, nbtKey, value, listTagType) override fun equals(other: Any?) = - this === other || (other is NBTListCondition && tagType == other.tagType && nbtKey.equals(other.nbtKey) && value == other.value && listTagType == other.listTagType) + this === other || (other is NBTListCondition && tagType == other.tagType && nbtKey == other.nbtKey && value == other.value && listTagType == other.listTagType) } From be24c519dd669dca8d6bc74d3ac220342ff67abd Mon Sep 17 00:00:00 2001 From: MasterEnderman Date: Mon, 26 Jan 2026 23:40:41 +0100 Subject: [PATCH 46/58] update build scripts --- build.gradle.kts | 12 +-- buildSrc/CHANGELOG.md | 80 +++++++++++++++++++ buildSrc/src/main/kotlin/plugins/PropSync.kt | 19 +++-- .../src/main/resources/integration.properties | 4 +- .../src/main/resources/sync-file-list.txt | 18 +++++ 5 files changed, 118 insertions(+), 15 deletions(-) create mode 100644 buildSrc/CHANGELOG.md create mode 100644 buildSrc/src/main/resources/sync-file-list.txt diff --git a/build.gradle.kts b/build.gradle.kts index 00dee5c..fc5999f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -64,12 +64,12 @@ checkSubPropertiesExist("use_hei", "hei_version") checkSubPropertiesExist("use_top", "top_version") kotlin { - jvmToolchain(8) - compilerOptions { - freeCompilerArgs.add("-Xexplicit-backing-fields") - freeCompilerArgs.add("-Xcontext-sensitive-resolution") - extraWarnings.set(true) - } + jvmToolchain(8) + compilerOptions { + freeCompilerArgs.add("-Xexplicit-backing-fields") + freeCompilerArgs.add("-Xcontext-sensitive-resolution") + extraWarnings.set(true) + } } minecraft { diff --git a/buildSrc/CHANGELOG.md b/buildSrc/CHANGELOG.md new file mode 100644 index 0000000..9fb5717 --- /dev/null +++ b/buildSrc/CHANGELOG.md @@ -0,0 +1,80 @@ +# Catalyx Buildscripts Changelog + + + +## [0.5.1] - 2026-01-26 + +_this is fine._ + +- update dependencies +- enable a few experimental kotlin features +- experimental: sync kotlin version from template + +## [0.5.0] - 2026-01-19 + +_Happy new year._ + +- extend secrets management +- fix package name in reference creator +- add indent guesser for reference creator +- update dependencies +- auto create IntelliJ scope file +- improve sync plugin + +## [0.4.1] - 2025-11-26 + +_that one is on me._ + +- fix dependency loader + +## [0.4.0] - 2025-11-17 + +_sync scripts_ + +- implement local plugin updater +- add .gitattributes +- fix new tag implementation + +## [0.3.0] - 2025-11-08 + +_spotless flex_ + +- utilize flexmark +- update docs +- replace RFG tag system with a new implementation + +## [0.2.0] - 2025-10-29 + +_Look at this pretty image._ + +- organization assets +- update dependencies +- .editorconfig profiles + +## [0.1.0] - 2025-10-18 + +_You could almost call it usable._ + +- spotless formatting +- .editorconfig +- property sync from template +- groovyscript jvm argument management +- proper dependency manager + +## [0.0.2] - 2025-10-14 + +_The second iteration..._ + +- change license +- we now use a local plugin structure + +## [0.0.1] - 2025-10-13 + +_The first iteration..._ + +## [0.0.0] - 2025-10-09 + +_Initial commit._ diff --git a/buildSrc/src/main/kotlin/plugins/PropSync.kt b/buildSrc/src/main/kotlin/plugins/PropSync.kt index 42dd757..54ad0ee 100644 --- a/buildSrc/src/main/kotlin/plugins/PropSync.kt +++ b/buildSrc/src/main/kotlin/plugins/PropSync.kt @@ -12,7 +12,7 @@ import java.nio.file.StandardCopyOption import java.util.Properties class PropSync : Plugin { - data class SyncConfig(val keysToSync: List = emptyList(), val syncAll: Boolean = false) + data class SyncConfig(val keysToSync: List = emptyList(), val syncAll: Boolean = false, val path: String = "buildSrc/src/main/resources/") companion object { private var foundUpdate = false @@ -46,6 +46,11 @@ class PropSync : Plugin { "tags.properties" to SyncConfig( syncAll = true, ), + // This one is new, still needs to be tested + "gradle.properties" to SyncConfig( + keysToSync = listOf("kotlin_version"), + path = "", + ), ) fun syncPropertiesFromTemplate() { @@ -59,12 +64,12 @@ class PropSync : Plugin { Logger.info("Syncing with template repository: ${OnlineUtils.TEMPLATE_REPO}") syncConfig.forEach { (file, cfg) -> try { - val templateProperties = fetchTemplateProperties(file) + val templateProperties = fetchTemplateProperties(file, cfg.path) val localProperties = Loader.loadPropertyFromFile(file) val mergedProperties = mergeProperties(localProperties, templateProperties, cfg) if (foundUpdate) { - updateLocalPropertiesFile(file, mergedProperties) + updateLocalPropertiesFile(cfg.path, file, mergedProperties) Logger.info("Synchronized properties for '$file'") } else { Logger.info("No changes detected for '$file'") @@ -75,8 +80,8 @@ class PropSync : Plugin { } } - private fun fetchTemplateProperties(fileName: PropertyFile): Properties { - val url = "${OnlineUtils.GITHUB_RAW_URL}/${OnlineUtils.TEMPLATE_REPO}/${OnlineUtils.TEMPLATE_BRANCH}/buildSrc/src/main/resources/$fileName" + private fun fetchTemplateProperties(fileName: PropertyFile, path: String): Properties { + val url = "${OnlineUtils.GITHUB_RAW_URL}/${OnlineUtils.TEMPLATE_REPO}/${OnlineUtils.TEMPLATE_BRANCH}/$path$fileName" val properties = Properties() val content = OnlineUtils.fetchFileContent(url) ?: throw Exception("Failed to fetch content from $url") properties.load(ByteArrayInputStream(content.toByteArray())) @@ -110,8 +115,8 @@ class PropSync : Plugin { return merged } - private fun updateLocalPropertiesFile(fileName: PropertyFile, properties: Properties) { - val buildSrcDirectory = project.rootProject.file("buildSrc/src/main/resources") + private fun updateLocalPropertiesFile(path: String, fileName: PropertyFile, properties: Properties) { + val buildSrcDirectory = project.rootProject.file(path.removeSuffix("/")) val propertyFile = File(buildSrcDirectory, fileName) if (propertyFile.exists().not()) { return Logger.warn("Property file '$fileName' does not exist at ${propertyFile.absolutePath}, skipping update.") diff --git a/buildSrc/src/main/resources/integration.properties b/buildSrc/src/main/resources/integration.properties index 56e902d..8f94901 100644 --- a/buildSrc/src/main/resources/integration.properties +++ b/buildSrc/src/main/resources/integration.properties @@ -24,7 +24,7 @@ use_groovyscript = true groovy_version = 4.0.26 # The version of GroovyScript to use. Check https://repo.cleanroommc.com/#/releases/com/cleanroommc/groovyscript for the latest version. -groovyscript_version = 1.3.3 +groovyscript_version = 1.3.4 # Should the GroovyScript language server be run when executing the 'runClient' task? grs_run_ls = false @@ -55,7 +55,7 @@ use_hei = true # The version of HadEnoughItems to use, should be compatible with the Minecraft version you are using # Check https://repo.cleanroommc.com/#/releases/mezz/jei -hei_version = 4.29.14 +hei_version = 4.29.15 diff --git a/buildSrc/src/main/resources/sync-file-list.txt b/buildSrc/src/main/resources/sync-file-list.txt new file mode 100644 index 0000000..b55d2da --- /dev/null +++ b/buildSrc/src/main/resources/sync-file-list.txt @@ -0,0 +1,18 @@ +buildSrc/src/main/kotlin/plugins/DepLoader.kt +buildSrc/src/main/kotlin/plugins/IJScopeCreator.kt +buildSrc/src/main/kotlin/plugins/Loader.kt +buildSrc/src/main/kotlin/plugins/Logger.kt +buildSrc/src/main/kotlin/plugins/PropSync.kt +buildSrc/src/main/kotlin/plugins/ReferenceCreator.kt +buildSrc/src/main/kotlin/plugins/ScriptSync.kt +buildSrc/src/main/kotlin/plugins/Secrets.kt +buildSrc/src/main/kotlin/util/DependencyProvider.kt +buildSrc/src/main/kotlin/util/OnlineUtils.kt +buildSrc/src/main/kotlin/BaseSetup.kt +buildSrc/src/main/kotlin/Dependencies.kt +buildSrc/src/main/kotlin/PropertyExtension.kt +buildSrc/src/main/kotlin/Repositories.kt +buildSrc/build.gradle.kts +buildSrc/CHANGELOG.md +build.gradle.kts +settings.gradle.kts From d00dc528e11c88500c93bdabb420cc81c4593468 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Tue, 27 Jan 2026 15:42:56 +0100 Subject: [PATCH 47/58] me when the kotlin compiler warnings lie --- .../org/ender_development/catalyx/core/items/CopyPasteTool.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt index e05c621..a528271 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt @@ -84,7 +84,7 @@ class CopyPasteTool() : BaseItem(Catalyx, "copy_paste_tool") { if(Utils.environment.isDeobfuscated) { tooltip.add("") - tooltip.add(stack.tagCompound?.getString(NBT_COPIED_BLOCK_KEY)) + tooltip.add(stack.tagCompound?.getString(NBT_COPIED_BLOCK_KEY).toString()) tooltip.add("${stack.tagCompound?.getCompoundTag(NBT_COPIED_DATA_KEY)}") } } From 85606c9fc56dc8a463be270f84656dc6ab563fd2 Mon Sep 17 00:00:00 2001 From: MasterEnderman Date: Mon, 2 Feb 2026 17:18:37 +0100 Subject: [PATCH 48/58] I did some things. meow. :3 - overhauled registries - separated model registration - cleaned up models - fixed tesr and mb models - Block Item models are still broken and need to be debugged - added item auto model generation - start on some random CraftTweaker integration --- .../org/ender_development/catalyx/Catalyx.kt | 4 +- .../api/v1/registry/ICatalyxRegistry.kt | 16 +++- .../catalyx/api/v1/registry/IProvider.kt | 79 +++++++++++++++---- .../catalyx/api/v1/utils/Utils.kt | 6 +- .../catalyx/core/blocks/BaseBlock.kt | 33 +------- .../catalyx/core/client/ICustomModel.kt | 44 +++++++++++ .../core/client/sprite/DefaultSprite.kt | 6 ++ .../catalyx/core/items/BaseItem.kt | 24 +----- .../catalyx/core/items/CopyPasteTool.kt | 11 ++- .../core/registry/CatalyxBlockRegistry.kt | 32 +++++++- .../core/registry/CatalyxItemRegistry.kt | 32 +++++++- .../core/registry/CatalyxProviderRegistry.kt | 13 +-- .../integration/crafttweaker/CatalyxBlock.kt | 67 ++++++++++++++++ .../crafttweaker/ModuleCraftTweaker.kt | 31 ++++++++ .../groovyscript/ModuleGroovyScript.kt | 2 + .../catalyx/blockstates/test_corner.json | 18 ++--- .../catalyx/blockstates/test_middle.json | 5 +- .../assets/catalyx/blockstates/test_side.json | 18 ++--- .../assets/catalyx/blockstates/test_tesr.json | 5 +- .../assets/catalyx/models/block/cat_cube.json | 12 +++ .../models/block/layered_cube_all.json | 18 ----- .../models/block/layered_cube_base.json | 30 ------- .../models/block/layered_cube_merged.json | 18 ----- .../models/block/layered_orientable.json | 25 ------ .../catalyx/models/item/copy_paste_tool.json | 6 -- .../catalyx/models/item/test_middle.json | 3 + 26 files changed, 338 insertions(+), 220 deletions(-) create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/client/ICustomModel.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/client/sprite/DefaultSprite.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/CatalyxBlock.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/ModuleCraftTweaker.kt create mode 100644 src/main/resources/assets/catalyx/models/block/cat_cube.json delete mode 100644 src/main/resources/assets/catalyx/models/block/layered_cube_all.json delete mode 100644 src/main/resources/assets/catalyx/models/block/layered_cube_base.json delete mode 100644 src/main/resources/assets/catalyx/models/block/layered_cube_merged.json delete mode 100644 src/main/resources/assets/catalyx/models/block/layered_orientable.json delete mode 100644 src/main/resources/assets/catalyx/models/item/copy_paste_tool.json create mode 100644 src/main/resources/assets/catalyx/models/item/test_middle.json diff --git a/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt b/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt index e88f310..e13fb9a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt +++ b/src/main/kotlin/org/ender_development/catalyx/Catalyx.kt @@ -2,11 +2,12 @@ package org.ender_development.catalyx import net.minecraft.creativetab.CreativeTabs import net.minecraft.util.ResourceLocation +import net.minecraftforge.common.ForgeVersion import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLConstructionEvent import org.apache.logging.log4j.LogManager -import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.Reference +import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.module.ModuleManager import org.ender_development.catalyx.core.utils.persistence.ConfigPersistentData import kotlin.random.Random @@ -17,6 +18,7 @@ import kotlin.random.Random version = Reference.VERSION, dependencies = ICatalyxMod.DEPENDENCIES, modLanguageAdapter = ICatalyxMod.MOD_LANGUAGE_ADAPTER, + acceptedMinecraftVersions = ForgeVersion.mcVersion, acceptableRemoteVersions = "*" ) @Mod.EventBusSubscriber(modid = Reference.MODID) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxRegistry.kt index 0710bc2..b24a937 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/ICatalyxRegistry.kt @@ -1,6 +1,11 @@ package org.ender_development.catalyx.api.v1.registry +import net.minecraftforge.client.event.ModelBakeEvent +import net.minecraftforge.client.event.ModelRegistryEvent +import net.minecraftforge.client.event.TextureStitchEvent import net.minecraftforge.event.RegistryEvent +import net.minecraftforge.fml.relauncher.Side +import net.minecraftforge.fml.relauncher.SideOnly import net.minecraftforge.registries.IForgeRegistryEntry import org.ender_development.catalyx.core.registry.CatalyxProviderRegistry @@ -21,5 +26,14 @@ interface ICatalyxRegistry, P : IProvider> { * * @param event The registry event. */ - fun register(event: RegistryEvent.Register) + fun registerProvider(event: RegistryEvent.Register) + + @SideOnly(Side.CLIENT) + fun registerModel(event: ModelRegistryEvent) + + @SideOnly(Side.CLIENT) + fun bakeModel(event: ModelBakeEvent) + + @SideOnly(Side.CLIENT) + fun stitchTexture(event: TextureStitchEvent.Pre) } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt index d0d934a..216532f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt @@ -1,8 +1,15 @@ package org.ender_development.catalyx.api.v1.registry import net.minecraft.block.Block +import net.minecraft.client.renderer.block.model.ModelResourceLocation import net.minecraft.item.Item +import net.minecraft.item.ItemBlock +import net.minecraft.util.ResourceLocation +import net.minecraftforge.client.event.ModelRegistryEvent +import net.minecraftforge.client.model.ModelLoader import net.minecraftforge.event.RegistryEvent +import net.minecraftforge.fml.relauncher.Side +import net.minecraftforge.fml.relauncher.SideOnly import net.minecraftforge.registries.IForgeRegistryEntry /** @@ -14,48 +21,86 @@ interface IProvider> { */ val instance: T - /** - * The mod ID(s) required for this provider to be enabled. Prefixes of "!" can be used to indicate that a mod must NOT be present. - * - * Default is an empty list, meaning no dependencies. - * - * @see [org.ender_development.catalyx.core.registry.CatalyxProviderRegistry.evaluateModDependencies] - */ - val modDependencies: Iterable - - // Note: do not make this a `val` as we wanna enforce a getter here /** * Whether this provider is enabled and should be registered. */ - fun isEnabled(): Boolean + val enabled: () -> Boolean + get() = { true } /** * Register this provider's item/block with the given event. + * This will only be called, when the provider is [enabled]. * * @param event The registry event. */ - fun register(event: RegistryEvent.Register) + fun register(event: RegistryEvent.Register) = + event.registry.register(instance) /** - * Specify that this provider requires the given mod dependencies to be present. + * Register this provider's model, this comes with a default implementation. * - * @see IProvider.modDependencies for format + * @param event The registry event. + */ + @SideOnly(Side.CLIENT) + fun registerModel(event: ModelRegistryEvent) + + /** + * [ResourceLocation] of the model parent + */ + val modelParent: ResourceLocation + + /** + * [ResourceLocation] of the model file */ - fun requires(modDependencies: Iterable): T + val modelLocation: ResourceLocation + + /** + * [ResourceLocation] of the texture file + */ + val textureLocation: ResourceLocation } -interface IItemProvider : IProvider +interface IItemProvider : IProvider { + @SideOnly(Side.CLIENT) + override fun registerModel(event: ModelRegistryEvent) = + ModelLoader.setCustomModelResourceLocation(instance, 0, ModelResourceLocation(instance.registryName!!, "inventory")) + + override val modelParent: ResourceLocation + get() = ResourceLocation("minecraft", "item/generated") + + override val modelLocation: ResourceLocation + get() = ResourceLocation(instance.registryName!!.namespace, "item/${instance.registryName!!.path}") + + override val textureLocation: ResourceLocation + get() = ResourceLocation(instance.registryName!!.namespace, "items/${instance.registryName!!.path}") +} interface IBlockProvider : IProvider { /** * Override this instead of [registerItemBlock] if you only want to change the registered Item associated with this Block (like with a [org.ender_development.catalyx.core.items.TooltipItemBlock]) */ val item: Item + get() = ItemBlock(instance).setRegistryName(instance.registryName) /** * Register the Item for this Block with the given event. + * This will only be called, when the provider is [enabled]. * * @param event The registry event for Items. */ - fun registerItemBlock(event: RegistryEvent.Register) + fun registerItemBlock(event: RegistryEvent.Register) = + event.registry.register(item) + + @SideOnly(Side.CLIENT) + override fun registerModel(event: ModelRegistryEvent) = + ModelLoader.setCustomModelResourceLocation(item, 0, ModelResourceLocation(item.registryName!!, "inventory")) + + override val textureLocation: ResourceLocation + get() = ResourceLocation(instance.registryName!!.namespace, "blocks/${instance.registryName!!.path}") + + override val modelLocation: ResourceLocation + get() = ResourceLocation(instance.registryName!!.namespace, "block/${instance.registryName!!.path}") + + override val modelParent: ResourceLocation + get() = ResourceLocation("minecraft", "block/cube_all") } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt index 5e2088c..31b812e 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt @@ -14,12 +14,12 @@ object Utils { val environment: IEnvironmentUtils = EnvironmentUtils - // bruh... // TODO find an abstraction + /** + * [This can't be an extension as of right now there is no way to create a static extension of a JVM class.](https://youtrack.jetbrains.com/issue/KT-11968) + */ @Suppress("ClassName") object forFluidTanks { - // These cannot be an extension as there's currently no way to create a static extension for a JVM class afaict (see https://youtrack.jetbrains.com/issue/KT-11968) - inline fun create(tile: TileEntity, capacity: Int, canFill: Boolean, canDrain: Boolean, crossinline onContentsChangedCallback: () -> Unit) = object : FluidTank(capacity) { init { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt index 283184e..e214304 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt @@ -4,18 +4,12 @@ import net.minecraft.block.Block import net.minecraft.block.material.Material import net.minecraft.block.state.BlockFaceShape import net.minecraft.block.state.IBlockState -import net.minecraft.client.renderer.block.model.ModelResourceLocation -import net.minecraft.item.Item -import net.minecraft.item.ItemBlock import net.minecraft.util.EnumFacing import net.minecraft.util.ResourceLocation import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.world.IBlockAccess -import net.minecraftforge.client.model.ModelLoader -import net.minecraftforge.event.RegistryEvent import org.ender_development.catalyx.api.v1.registry.IBlockProvider -import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.register @@ -25,7 +19,7 @@ import org.ender_development.catalyx.core.register open class BaseBlock(val mod: ICatalyxMod, name: String, material: Material = Material.ROCK, hardness: Float = 3f) : Block(material), IBlockProvider { init { registryName = ResourceLocation(mod.modId, name) - translationKey = "$registryName" + translationKey = "${mod.modId}.$name" blockHardness = hardness creativeTab = mod.creativeTab } @@ -36,32 +30,7 @@ open class BaseBlock(val mod: ICatalyxMod, name: String, material: Material = Ma override val instance = this - final override var modDependencies: Iterable = emptyList() - private set - - override val item = ItemBlock(this) - - override fun isEnabled() = - true - - override fun register(event: RegistryEvent.Register) = - event.registry.register(this) - - override fun registerItemBlock(event: RegistryEvent.Register) { - item.registryName = registryName - event.registry.register(item) - if(Utils.environment.isClient) - ModelLoader.setCustomModelResourceLocation(item, 0, ModelResourceLocation(registryName!!, "inventory")) - } - - override fun requires(modDependencies: Iterable): Block { - this.modDependencies = modDependencies - mod.register(this) - return this - } - init { - // TODO: why do we have 2 init blocks? => so you ask questions /j; nah actually, just because of initialisation order, this made more sense mod.register(this) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/ICustomModel.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/ICustomModel.kt new file mode 100644 index 0000000..9ba0724 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/ICustomModel.kt @@ -0,0 +1,44 @@ +package org.ender_development.catalyx.core.client + +import com.google.common.collect.ImmutableMap +import net.minecraft.client.renderer.block.model.ModelResourceLocation +import net.minecraft.client.renderer.block.model.ModelRotation +import net.minecraft.client.renderer.vertex.DefaultVertexFormats +import net.minecraftforge.client.event.ModelBakeEvent +import net.minecraftforge.client.event.TextureStitchEvent +import net.minecraftforge.client.model.ModelLoader +import net.minecraftforge.client.model.ModelLoaderRegistry +import net.minecraftforge.fml.relauncher.Side +import net.minecraftforge.fml.relauncher.SideOnly +import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.registry.IItemProvider +import org.ender_development.catalyx.core.client.sprite.DefaultSprite + +interface ICustomModel { + @SideOnly(Side.CLIENT) + fun onBakeModel(event: ModelBakeEvent) + + @SideOnly(Side.CLIENT) + fun onTextureStitch(event: TextureStitchEvent.Pre) +} + +interface IAutoModel : ICustomModel, IItemProvider { + @SideOnly(Side.CLIENT) + override fun onTextureStitch(event: TextureStitchEvent.Pre) { + val sprite = DefaultSprite(textureLocation) + event.map.setTextureEntry(sprite) + } + + @SideOnly(Side.CLIENT) + override fun onBakeModel(event: ModelBakeEvent) { + try { + val baseModel = ModelLoaderRegistry.getModel(modelParent) + val retexturedModel = baseModel.retexture(ImmutableMap.of("layer0", textureLocation.toString())) + val bakedModel = retexturedModel.bake(ModelRotation.X0_Y0, DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()) + val bakedModelLoc = ModelResourceLocation(instance.delegate.name(), "inventory") + event.modelRegistry.putObject(bakedModelLoc, bakedModel) + } catch (e: Exception) { + Catalyx.LOGGER.error(e.stackTrace) + } + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/sprite/DefaultSprite.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/sprite/DefaultSprite.kt new file mode 100644 index 0000000..2f9cb3b --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/sprite/DefaultSprite.kt @@ -0,0 +1,6 @@ +package org.ender_development.catalyx.core.client.sprite + +import net.minecraft.client.renderer.texture.TextureAtlasSprite +import net.minecraft.util.ResourceLocation + +class DefaultSprite(loc: ResourceLocation) : TextureAtlasSprite(loc.toString()) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt index a82e091..929fe78 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt @@ -1,12 +1,8 @@ package org.ender_development.catalyx.core.items -import net.minecraft.client.renderer.block.model.ModelResourceLocation import net.minecraft.item.Item import net.minecraft.util.ResourceLocation -import net.minecraftforge.client.model.ModelLoader -import net.minecraftforge.event.RegistryEvent import org.ender_development.catalyx.api.v1.registry.IItemProvider -import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.ICatalyxMod import org.ender_development.catalyx.core.register @@ -16,30 +12,12 @@ import org.ender_development.catalyx.core.register open class BaseItem(val mod: ICatalyxMod, val name: String) : Item(), IItemProvider { init { registryName = ResourceLocation(mod.modId, name) - translationKey = "$registryName" + translationKey = "${mod.modId}.$name" creativeTab = mod.creativeTab } override val instance = this - override fun isEnabled() = - true - - final override var modDependencies: Iterable = emptyList() - private set - - override fun requires(modDependencies: Iterable): Item { - this.modDependencies = modDependencies - mod.register(this) - return this - } - - override fun register(event: RegistryEvent.Register) { - event.registry.register(this) - if(Utils.environment.isClient) - ModelLoader.setCustomModelResourceLocation(this, 0, ModelResourceLocation(registryName!!, "inventory")) - } - init { mod.register(this) } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt index a528271..13f911c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt @@ -7,15 +7,17 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.EnumActionResult import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand +import net.minecraft.util.ResourceLocation import net.minecraft.util.math.BlockPos import net.minecraft.world.World import org.ender_development.catalyx.Catalyx import org.ender_development.catalyx.api.v1.utils.Utils +import org.ender_development.catalyx.core.client.IAutoModel import org.ender_development.catalyx.core.client.gui.BaseGuiTyped import org.ender_development.catalyx.core.tiles.BaseTile import org.ender_development.catalyx.core.tiles.helper.ICopyPasteExtraTile -class CopyPasteTool() : BaseItem(Catalyx, "copy_paste_tool") { +class CopyPasteTool : BaseItem(Catalyx, "copy_paste_tool"), IAutoModel { private companion object { const val NBT_COPIED_BLOCK_KEY = "CopiedBlock" const val NBT_COPIED_DATA_KEY = "CopiedData" @@ -93,6 +95,9 @@ class CopyPasteTool() : BaseItem(Catalyx, "copy_paste_tool") { * don't register if this isn't a dev environment, as this item is not finished * TODO tooltip, name translation, maybe signify what blocks you can actually copy across ;p */ - override fun isEnabled() = - Utils.environment.isDeobfuscated + override val enabled: () -> Boolean + get() = { Utils.environment.isDeobfuscated } + + override val textureLocation: ResourceLocation = + ResourceLocation(mod.modId, "logo") } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt index c8eb530..a9a7f7f 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxBlockRegistry.kt @@ -2,22 +2,28 @@ package org.ender_development.catalyx.core.registry import net.minecraft.block.Block import net.minecraft.item.Item +import net.minecraftforge.client.event.ModelBakeEvent +import net.minecraftforge.client.event.ModelRegistryEvent +import net.minecraftforge.client.event.TextureStitchEvent import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.relauncher.Side +import net.minecraftforge.fml.relauncher.SideOnly import org.ender_development.catalyx.Catalyx import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.api.v1.registry.IBlockProvider import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.Reference +import org.ender_development.catalyx.core.client.ICustomModel @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxBlockRegistry : ICatalyxRegistry { override val registry = CatalyxProviderRegistry() @SubscribeEvent - override fun register(event: RegistryEvent.Register) { + override fun registerProvider(event: RegistryEvent.Register) { Catalyx.LOGGER.debug("Block Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} block${registry.size.plural}") registry.enabled.forEach { it.register(event) @@ -35,4 +41,28 @@ object CatalyxBlockRegistry : ICatalyxRegistry { Catalyx.LOGGER.debug("Registered block item: {}", it.item.registryName) } } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + override fun registerModel(event: ModelRegistryEvent) { + registry.enabled.forEach { + it.registerModel(event) + } + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + override fun bakeModel(event: ModelBakeEvent) { + registry.enabled.filterIsInstance().forEach { + it.onBakeModel(event) + } + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + override fun stitchTexture(event: TextureStitchEvent.Pre) { + registry.enabled.filterIsInstance().forEach { + it.onTextureStitch(event) + } + } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt index 55ff01a..210a9f0 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxItemRegistry.kt @@ -1,22 +1,28 @@ package org.ender_development.catalyx.core.registry import net.minecraft.item.Item +import net.minecraftforge.client.event.ModelBakeEvent +import net.minecraftforge.client.event.ModelRegistryEvent +import net.minecraftforge.client.event.TextureStitchEvent import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.relauncher.Side +import net.minecraftforge.fml.relauncher.SideOnly import org.ender_development.catalyx.Catalyx import org.ender_development.catalyx.api.v1.common.extensions.plural import org.ender_development.catalyx.api.v1.registry.ICatalyxRegistry import org.ender_development.catalyx.api.v1.registry.IItemProvider import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.Reference +import org.ender_development.catalyx.core.client.ICustomModel @Mod.EventBusSubscriber(modid = Reference.MODID) object CatalyxItemRegistry : ICatalyxRegistry { override val registry = CatalyxProviderRegistry() @SubscribeEvent - override fun register(event: RegistryEvent.Register) { + override fun registerProvider(event: RegistryEvent.Register) { Catalyx.LOGGER.debug("Item Registry has ${registry.size} entries, but only gonna register ${registry.enabled.size} item${registry.size.plural}") registry.enabled.forEach { it.register(event) @@ -24,4 +30,28 @@ object CatalyxItemRegistry : ICatalyxRegistry { Catalyx.LOGGER.debug("Registered item: {}", it.instance.registryName) } } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + override fun registerModel(event: ModelRegistryEvent) { + registry.enabled.forEach { + it.registerModel(event) + } + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + override fun bakeModel(event: ModelBakeEvent) { + registry.enabled.filterIsInstance().forEach { + it.onBakeModel(event) + } + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + override fun stitchTexture(event: TextureStitchEvent.Pre) { + registry.enabled.filterIsInstance().forEach { + it.onTextureStitch(event) + } + } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt index 651a50b..64561fa 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt @@ -4,6 +4,7 @@ import net.minecraft.util.ResourceLocation import org.ender_development.catalyx.api.v1.common.extensions.modLoaded import org.ender_development.catalyx.api.v1.registry.ICatalyxProviderRegistry import org.ender_development.catalyx.api.v1.registry.IProvider +import kotlin.let /** * Collection of all [IProvider] of a given type @@ -13,17 +14,7 @@ import org.ender_development.catalyx.api.v1.registry.IProvider class CatalyxProviderRegistry> : HashMap>(), ICatalyxProviderRegistry { override fun add(provider: V): Boolean = provider.instance.registryName?.let { - this[it] = provider to (provider.isEnabled() && provider.modDependencies.evaluateModDependencies()) + this[it] = provider to provider.enabled() true } ?: false - - /** - * Special helper to evaluate modDependencies strings. - * - * @see [IProvider.modDependencies] - */ - fun Iterable.evaluateModDependencies() = - all { - it.removePrefix("!").modLoaded() != it.startsWith('!') - } } diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/CatalyxBlock.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/CatalyxBlock.kt new file mode 100644 index 0000000..a57b696 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/CatalyxBlock.kt @@ -0,0 +1,67 @@ +package org.ender_development.catalyx.modules.integration.crafttweaker + +import crafttweaker.annotations.ZenRegister +import crafttweaker.api.block.IMaterial +import crafttweaker.api.minecraft.CraftTweakerMC +import net.minecraft.block.Block +import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.core.Reference +import org.ender_development.catalyx.core.blocks.BaseBlock +import stanhebben.zenscript.annotations.ZenClass +import stanhebben.zenscript.annotations.ZenMethod + +@Suppress("UNUSED") +@ZenRegister +@ZenClass("${Reference.MODID}.content.Block") +class CatalyxBlock(private val block: Block) { + companion object { + private fun init(block: Block, name: String): CatalyxBlock = + CatalyxBlock(block.setRegistryName(Reference.MODID, name).setTranslationKey("tile.${Reference.MODID}.$name.name")) + + @ZenMethod + fun createBlock(name: String, material: IMaterial): CatalyxBlock = + init(BaseBlock(Catalyx, name, CraftTweakerMC.getMaterial(material)), name) + } + + @ZenMethod + fun setHardness(hardness: Float): CatalyxBlock { + block.setHardness(hardness) + return this + } + + @ZenMethod + fun setResistance(resistance: Float): CatalyxBlock { + block.setResistance(resistance) + return this + } + + @ZenMethod + fun setUnbreakable(): CatalyxBlock { + block.setBlockUnbreakable() + return this + } + + @ZenMethod + fun setLightOpacity(opacity: Int): CatalyxBlock { + block.setLightOpacity(opacity) + return this + } + + @ZenMethod + fun setLightLevel(light: Float): CatalyxBlock { + block.setLightLevel(light) + return this + } + + @ZenMethod + fun setSlipperiness(slipperiness: Float): CatalyxBlock { + block.setDefaultSlipperiness(slipperiness) + return this + } + + @ZenMethod + fun setHarvestLevel(tool: String, level: Int): CatalyxBlock { + block.setHarvestLevel(tool, level) + return this + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/ModuleCraftTweaker.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/ModuleCraftTweaker.kt new file mode 100644 index 0000000..55b4a81 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/ModuleCraftTweaker.kt @@ -0,0 +1,31 @@ +package org.ender_development.catalyx.modules.integration.crafttweaker + +import crafttweaker.CraftTweakerAPI +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent +import org.ender_development.catalyx.api.v1.common.Mods +import org.ender_development.catalyx.api.v1.common.extensions.subLogger +import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule +import org.ender_development.catalyx.core.Reference +import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer +import org.ender_development.catalyx.modules.integration.IntegrationModule +import kotlin.properties.Delegates + +@CatalyxModule( + moduleId = CatalyxInternalModuleContainer.MODULE_CT, + containerId = Reference.MODID, + modDependencies = [Mods.CRAFTTWEAKER], + name = "Catalyx CraftTweaker Integration Module", + description = "Adds CT bindings to content creation functions.", + moduleDependencies = ["${Reference.MODID}:${CatalyxInternalModuleContainer.MODULE_INTEGRATION}"] +) +internal class ModuleCraftTweaker: IntegrationModule() { + override val logger = super.logger.subLogger("CraftTweaker") + + var scriptsSuccessful by Delegates.notNull() + + override fun preInit(event: FMLPreInitializationEvent) { + logger.info("CraftTweaker found. Loading scripts...") + CraftTweakerAPI.logInfo("${Reference.MOD_NAME} says meow :3") + scriptsSuccessful = CraftTweakerAPI.tweaker.loadScript(false, Reference.MODID); + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt index 3d00d8f..39fa4a3 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/groovyscript/ModuleGroovyScript.kt @@ -35,9 +35,11 @@ internal class ModuleGroovyScript : IntegrationModule(), GroovyPlugin { modSupportContainer = container!! } + @Optional.Method(modid = Mods.GROOVYSCRIPT) override fun getModId() = Reference.MODID + @Optional.Method(modid = Mods.GROOVYSCRIPT) override fun getContainerName() = Reference.MOD_NAME } diff --git a/src/main/resources/assets/catalyx/blockstates/test_corner.json b/src/main/resources/assets/catalyx/blockstates/test_corner.json index 6708f14..0ec0110 100644 --- a/src/main/resources/assets/catalyx/blockstates/test_corner.json +++ b/src/main/resources/assets/catalyx/blockstates/test_corner.json @@ -1,15 +1,9 @@ { "forge_marker": 1, "defaults": { - "model": "catalyx:layered_cube_merged", + "model": "minecraft:cube_all", "textures": { - "particle": "catalyx:blocks/mb_inner", - "down": "", - "up": "", - "north": "", - "east": "", - "south": "", - "west": "" + "all": "catalyx:blocks/mb_inner" } }, "variants": { @@ -23,7 +17,7 @@ }, "position": { "0": { - "model": "catalyx:layered_cube_merged", + "model": "catalyx:cat_cube", "textures": { "down": "catalyx:blocks/mb_down_right_lower", "up": "catalyx:blocks/mb_top_right_upper", @@ -34,7 +28,7 @@ } }, "1": { - "model": "catalyx:layered_cube_merged", + "model": "catalyx:cat_cube", "textures": { "down": "catalyx:blocks/mb_down_right_upper", "up": "catalyx:blocks/mb_top_right_lower", @@ -45,7 +39,7 @@ } }, "2": { - "model": "catalyx:layered_cube_merged", + "model": "catalyx:cat_cube", "textures": { "down": "catalyx:blocks/mb_down_left_upper", "up": "catalyx:blocks/mb_top_left_lower", @@ -56,7 +50,7 @@ } }, "3": { - "model": "catalyx:layered_cube_merged", + "model": "catalyx:cat_cube", "textures": { "down": "catalyx:blocks/mb_down_left_lower", "up": "catalyx:blocks/mb_top_left_upper", diff --git a/src/main/resources/assets/catalyx/blockstates/test_middle.json b/src/main/resources/assets/catalyx/blockstates/test_middle.json index 602736f..352946d 100644 --- a/src/main/resources/assets/catalyx/blockstates/test_middle.json +++ b/src/main/resources/assets/catalyx/blockstates/test_middle.json @@ -1,10 +1,9 @@ { "forge_marker": 1, "defaults": { - "model": "catalyx:layered_cube_all", + "model": "minecraft:cube_all", "textures": { - "bot_all": "catalyx:blocks/mb_inner", - "top_all": "catalyx:blocks/mb_inner" + "all": "catalyx:blocks/mb_inner" } }, "variants": { diff --git a/src/main/resources/assets/catalyx/blockstates/test_side.json b/src/main/resources/assets/catalyx/blockstates/test_side.json index da46e69..e8fa47e 100644 --- a/src/main/resources/assets/catalyx/blockstates/test_side.json +++ b/src/main/resources/assets/catalyx/blockstates/test_side.json @@ -1,15 +1,9 @@ { "forge_marker": 1, "defaults": { - "model": "catalyx:layered_cube_merged", + "model": "minecraft:cube_all", "textures": { - "particle": "catalyx:blocks/mb_inner", - "down": "", - "up": "", - "north": "", - "east": "", - "south": "", - "west": "" + "all": "catalyx:blocks/mb_inner" } }, "variants": { @@ -23,7 +17,7 @@ }, "position": { "0": { - "model": "catalyx:layered_cube_merged", + "model": "catalyx:cat_cube", "textures": { "down": "catalyx:blocks/mb_down3", "up": "catalyx:blocks/mb_top1", @@ -34,7 +28,7 @@ } }, "1": { - "model": "catalyx:layered_cube_merged", + "model": "catalyx:cat_cube", "textures": { "down": "catalyx:blocks/mb_down2", "up": "catalyx:blocks/mb_top2", @@ -45,7 +39,7 @@ } }, "2": { - "model": "catalyx:layered_cube_merged", + "model": "catalyx:cat_cube", "textures": { "down": "catalyx:blocks/mb_down1", "up": "catalyx:blocks/mb_top3", @@ -56,7 +50,7 @@ } }, "3": { - "model": "catalyx:layered_cube_merged", + "model": "catalyx:cat_cube", "textures": { "down": "catalyx:blocks/mb_down4", "up": "catalyx:blocks/mb_top4", diff --git a/src/main/resources/assets/catalyx/blockstates/test_tesr.json b/src/main/resources/assets/catalyx/blockstates/test_tesr.json index 2d109f3..2d76299 100644 --- a/src/main/resources/assets/catalyx/blockstates/test_tesr.json +++ b/src/main/resources/assets/catalyx/blockstates/test_tesr.json @@ -1,10 +1,9 @@ { "forge_marker": 1, "defaults": { - "model": "catalyx:layered_cube_all", + "model": "minecraft:cube_all", "textures": { - "bot_all": "catalyx:blocks/mb_inner", - "top_all": "catalyx:blocks/mb_inner" + "all": "catalyx:blocks/mb_inner" } }, "variants": { diff --git a/src/main/resources/assets/catalyx/models/block/cat_cube.json b/src/main/resources/assets/catalyx/models/block/cat_cube.json new file mode 100644 index 0000000..40d386d --- /dev/null +++ b/src/main/resources/assets/catalyx/models/block/cat_cube.json @@ -0,0 +1,12 @@ +{ + "parent": "block/cube", + "textures": { + "particle": "#up", + "down": "#down", + "up": "#up", + "north": "#north", + "east": "#east", + "south": "#south", + "west": "#west" + } +} diff --git a/src/main/resources/assets/catalyx/models/block/layered_cube_all.json b/src/main/resources/assets/catalyx/models/block/layered_cube_all.json deleted file mode 100644 index cc87f95..0000000 --- a/src/main/resources/assets/catalyx/models/block/layered_cube_all.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "parent": "catalyx:block/layered_cube_base", - "textures": { - "particle": "#bot_all", - "bot_down": "#bot_all", - "bot_up": "#bot_all", - "bot_north": "#bot_all", - "bot_east": "#bot_all", - "bot_south": "#bot_all", - "bot_west": "#bot_all", - "top_down": "#top_all", - "top_up": "#top_all", - "top_north": "#top_all", - "top_east": "#top_all", - "top_south": "#top_all", - "top_west": "#top_all" - } -} diff --git a/src/main/resources/assets/catalyx/models/block/layered_cube_base.json b/src/main/resources/assets/catalyx/models/block/layered_cube_base.json deleted file mode 100644 index d8b8f0a..0000000 --- a/src/main/resources/assets/catalyx/models/block/layered_cube_base.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "parent": "minecraft:block/cube", - "elements": [ - { - "from": [ 0, 0, 0 ], - "to": [ 16, 16, 16 ], - "faces": { - "down": { "texture": "#bot_down", "cullface": "down" }, - "up": { "texture": "#bot_up", "cullface": "up" }, - "north": { "texture": "#bot_north", "cullface": "north" }, - "south": { "texture": "#bot_south", "cullface": "south" }, - "west": { "texture": "#bot_west", "cullface": "west" }, - "east": { "texture": "#bot_east", "cullface": "east" } - } - }, - { - "from": [ 0, 0, 0 ], - "to": [ 16, 16, 16 ], - "shade": false, - "faces": { - "down": { "texture": "#top_down", "cullface": "down" }, - "up": { "texture": "#top_up", "cullface": "up" }, - "north": { "texture": "#top_north", "cullface": "north" }, - "south": { "texture": "#top_south", "cullface": "south" }, - "west": { "texture": "#top_west", "cullface": "west" }, - "east": { "texture": "#top_east", "cullface": "east" } - } - } - ] -} diff --git a/src/main/resources/assets/catalyx/models/block/layered_cube_merged.json b/src/main/resources/assets/catalyx/models/block/layered_cube_merged.json deleted file mode 100644 index 7449806..0000000 --- a/src/main/resources/assets/catalyx/models/block/layered_cube_merged.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "parent": "catalyx:block/layered_cube_base", - "textures": { - "particle": "#particle", - "bot_down": "#down", - "bot_up": "#up", - "bot_north": "#north", - "bot_east": "#east", - "bot_south": "#south", - "bot_west": "#west", - "top_down": "#down", - "top_up": "#up", - "top_north": "#north", - "top_east": "#east", - "top_south": "#south", - "top_west": "#west" - } -} diff --git a/src/main/resources/assets/catalyx/models/block/layered_orientable.json b/src/main/resources/assets/catalyx/models/block/layered_orientable.json deleted file mode 100644 index e27d305..0000000 --- a/src/main/resources/assets/catalyx/models/block/layered_orientable.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "parent": "catalyx:block/layered_cube_base", - "display": { - "firstperson_righthand": { - "rotation": [ 0, 135, 0 ], - "translation": [ 0, 0, 0 ], - "scale": [ 0.40, 0.40, 0.40 ] - } - }, - "textures": { - "particle": "#bot_front", - "bot_down": "#top_all", - "bot_up": "#top_all", - "bot_north": "#bot_front", - "bot_east": "#side_all", - "bot_south": "#side_all", - "bot_west": "#side_all", - "top_down": "#top_all", - "top_up": "#top_all", - "top_north": "#top_front", - "top_east": "#side_all", - "top_south": "#side_all", - "top_west": "#side_all" - } -} diff --git a/src/main/resources/assets/catalyx/models/item/copy_paste_tool.json b/src/main/resources/assets/catalyx/models/item/copy_paste_tool.json deleted file mode 100644 index 0f3bd15..0000000 --- a/src/main/resources/assets/catalyx/models/item/copy_paste_tool.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "catalyx:logo" - } -} diff --git a/src/main/resources/assets/catalyx/models/item/test_middle.json b/src/main/resources/assets/catalyx/models/item/test_middle.json new file mode 100644 index 0000000..6e8e19e --- /dev/null +++ b/src/main/resources/assets/catalyx/models/item/test_middle.json @@ -0,0 +1,3 @@ +{ + "parent": "block/cobblestone" +} From bed9c177477090e73c22e9ee034b5d5d3430e208 Mon Sep 17 00:00:00 2001 From: MasterEnderman Date: Mon, 2 Feb 2026 22:05:36 +0100 Subject: [PATCH 49/58] Update ICatalyxMod.kt more helper methods Signed-off-by: MasterEnderman --- .../org/ender_development/catalyx/core/ICatalyxMod.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt b/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt index ed8d802..eded1bc 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt @@ -43,3 +43,11 @@ inline fun ICatalyxMod.register(item: IItemProvider) = @Suppress("NOTHING_TO_INLINE") inline fun ICatalyxMod.register(block: IBlockProvider) = CatalyxBlockRegistry.registry.add(block) + +@Suppress("NOTHING_TO_INLINE") +inline fun ICatalyxMod.toRL(name: String): ResourceLocation = + ResourceLocation(it.modId, name) + +@Suppress("NOTHING_TO_INLINE") +inline fun ICatalyxMod.toLK(langKey: String): String = + "${it.modId}.$langKey" From e28a3c45ae182df61456f849495c38799014b444 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Mon, 2 Feb 2026 22:55:02 +0100 Subject: [PATCH 50/58] eat ender's code as usual --- .../catalyx/api/v1/registry/IProvider.kt | 8 ++++---- .../catalyx/api/v1/utils/Utils.kt | 4 ++-- .../ender_development/catalyx/core/ICatalyxMod.kt | 15 +++++++-------- .../catalyx/core/client/ICustomModel.kt | 7 +++---- .../catalyx/core/items/CopyPasteTool.kt | 4 ++-- .../core/registry/CatalyxProviderRegistry.kt | 4 +--- .../crafttweaker/ModuleCraftTweaker.kt | 4 ++-- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt index 216532f..e3799d5 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/registry/IProvider.kt @@ -24,12 +24,12 @@ interface IProvider> { /** * Whether this provider is enabled and should be registered. */ - val enabled: () -> Boolean - get() = { true } + fun isEnabled() = + true /** * Register this provider's item/block with the given event. - * This will only be called, when the provider is [enabled]. + * This will only be called when the provider is [enabled][isEnabled]. * * @param event The registry event. */ @@ -84,7 +84,7 @@ interface IBlockProvider : IProvider { /** * Register the Item for this Block with the given event. - * This will only be called, when the provider is [enabled]. + * This will only be called, when the provider is [enabled][isEnabled]. * * @param event The registry event for Items. */ diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt index 31b812e..874f920 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/utils/Utils.kt @@ -10,7 +10,7 @@ import org.ender_development.catalyx.core.utils.BlockPosUtils import org.ender_development.catalyx.core.utils.EnvironmentUtils object Utils { - val forBlockPos: IBlockPosUtils = BlockPosUtils + val blockPos: IBlockPosUtils = BlockPosUtils val environment: IEnvironmentUtils = EnvironmentUtils @@ -19,7 +19,7 @@ object Utils { * [This can't be an extension as of right now there is no way to create a static extension of a JVM class.](https://youtrack.jetbrains.com/issue/KT-11968) */ @Suppress("ClassName") - object forFluidTanks { + object fluidTank { inline fun create(tile: TileEntity, capacity: Int, canFill: Boolean, canDrain: Boolean, crossinline onContentsChangedCallback: () -> Unit) = object : FluidTank(capacity) { init { diff --git a/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt b/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt index eded1bc..28163f3 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/ICatalyxMod.kt @@ -1,6 +1,9 @@ +@file:Suppress("NOTHING_TO_INLINE", "UnusedReceiverParameter") + package org.ender_development.catalyx.core import net.minecraft.creativetab.CreativeTabs +import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.common.Mod import org.ender_development.catalyx.api.v1.registry.IBlockProvider import org.ender_development.catalyx.api.v1.registry.IItemProvider @@ -36,18 +39,14 @@ interface ICatalyxMod { } // helper functions -@Suppress("NOTHING_TO_INLINE") inline fun ICatalyxMod.register(item: IItemProvider) = CatalyxItemRegistry.registry.add(item) -@Suppress("NOTHING_TO_INLINE") inline fun ICatalyxMod.register(block: IBlockProvider) = CatalyxBlockRegistry.registry.add(block) -@Suppress("NOTHING_TO_INLINE") -inline fun ICatalyxMod.toRL(name: String): ResourceLocation = - ResourceLocation(it.modId, name) +inline fun ICatalyxMod.toResourceLocation(name: String) = + ResourceLocation(modId, name) -@Suppress("NOTHING_TO_INLINE") -inline fun ICatalyxMod.toLK(langKey: String): String = - "${it.modId}.$langKey" +inline fun ICatalyxMod.toLanguageKey(langKey: String) = + "$modId.$langKey" diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/ICustomModel.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/ICustomModel.kt index 9ba0724..b1b8eb0 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/ICustomModel.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/ICustomModel.kt @@ -25,8 +25,7 @@ interface ICustomModel { interface IAutoModel : ICustomModel, IItemProvider { @SideOnly(Side.CLIENT) override fun onTextureStitch(event: TextureStitchEvent.Pre) { - val sprite = DefaultSprite(textureLocation) - event.map.setTextureEntry(sprite) + event.map.setTextureEntry(DefaultSprite(textureLocation)) } @SideOnly(Side.CLIENT) @@ -37,8 +36,8 @@ interface IAutoModel : ICustomModel, IItemProvider { val bakedModel = retexturedModel.bake(ModelRotation.X0_Y0, DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()) val bakedModelLoc = ModelResourceLocation(instance.delegate.name(), "inventory") event.modelRegistry.putObject(bakedModelLoc, bakedModel) - } catch (e: Exception) { - Catalyx.LOGGER.error(e.stackTrace) + } catch(e: Throwable) { + Catalyx.LOGGER.catching(e) } } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt index 13f911c..723ec0a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt @@ -95,8 +95,8 @@ class CopyPasteTool : BaseItem(Catalyx, "copy_paste_tool"), IAutoModel { * don't register if this isn't a dev environment, as this item is not finished * TODO tooltip, name translation, maybe signify what blocks you can actually copy across ;p */ - override val enabled: () -> Boolean - get() = { Utils.environment.isDeobfuscated } + override fun isEnabled() = + Utils.environment.isDeobfuscated override val textureLocation: ResourceLocation = ResourceLocation(mod.modId, "logo") diff --git a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt index 64561fa..9d0ad80 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/registry/CatalyxProviderRegistry.kt @@ -1,10 +1,8 @@ package org.ender_development.catalyx.core.registry import net.minecraft.util.ResourceLocation -import org.ender_development.catalyx.api.v1.common.extensions.modLoaded import org.ender_development.catalyx.api.v1.registry.ICatalyxProviderRegistry import org.ender_development.catalyx.api.v1.registry.IProvider -import kotlin.let /** * Collection of all [IProvider] of a given type @@ -14,7 +12,7 @@ import kotlin.let class CatalyxProviderRegistry> : HashMap>(), ICatalyxProviderRegistry { override fun add(provider: V): Boolean = provider.instance.registryName?.let { - this[it] = provider to provider.enabled() + this[it] = provider to provider.isEnabled() true } ?: false } diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/ModuleCraftTweaker.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/ModuleCraftTweaker.kt index 55b4a81..70b756c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/ModuleCraftTweaker.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/ModuleCraftTweaker.kt @@ -15,10 +15,10 @@ import kotlin.properties.Delegates containerId = Reference.MODID, modDependencies = [Mods.CRAFTTWEAKER], name = "Catalyx CraftTweaker Integration Module", - description = "Adds CT bindings to content creation functions.", + description = "Adds CT bindings to content creation functions", moduleDependencies = ["${Reference.MODID}:${CatalyxInternalModuleContainer.MODULE_INTEGRATION}"] ) -internal class ModuleCraftTweaker: IntegrationModule() { +internal class ModuleCraftTweaker : IntegrationModule() { override val logger = super.logger.subLogger("CraftTweaker") var scriptsSuccessful by Delegates.notNull() From 43c2bbd848b3560baf997ee4875f0a50ae4fb809 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Tue, 3 Feb 2026 00:55:28 +0100 Subject: [PATCH 51/58] is this how to make the api --- .../catalyx/api/v1/client/Client.kt | 9 +++ .../v1/client/interfaces/IAreaHighlighter.kt | 80 +++++++++++++++++++ .../catalyx/core/client/AreaHighlighter.kt | 80 ++++++------------- 3 files changed, 114 insertions(+), 55 deletions(-) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/client/Client.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/client/Client.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/client/Client.kt new file mode 100644 index 0000000..18a932c --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/client/Client.kt @@ -0,0 +1,9 @@ +package org.ender_development.catalyx.api.v1.client + +import org.ender_development.catalyx.api.v1.client.interfaces.IAreaHighlighter +import org.ender_development.catalyx.core.client.AreaHighlighter + +object Client { + fun newAreaHighlighter(): IAreaHighlighter = + AreaHighlighter() +} diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt new file mode 100644 index 0000000..7878f54 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt @@ -0,0 +1,80 @@ +package org.ender_development.catalyx.api.v1.client.interfaces + +import net.minecraft.util.math.BlockPos + +/** + * A helper allowing you to highlight an area, block or blocks in 3D space + * @see [highlightBlock] + * @see [highlightBlocks] + * @see [highlightArea] + */ +interface IAreaHighlighter { + /** + * Whether this AreaHighlighter is actually rendering anything + */ + val shown: Boolean + + // Starting X, Y, Z + val x1: Double + val y1: Double + val z1: Double + /** + * A BlockPos instance from the integer part of the (starting) [x1] [y1] [z1] coordinates. + * + * N/A when [highlightBlocks] is used. + */ + val pos1 + get() = BlockPos(x1, y1, z1) + + // Ending X, Y, Z + val x2: Double + val y2: Double + val z2: Double + + /** + * A BlockPos instance from the integer part of the (ending) [x2] [y2] [z2] coordinates. + * + * N/A when [highlightBlocks] is used. + */ + val pos2 + get() = BlockPos(x2, y2, z2) + + val drawBlockPositions: Boolean + val drawnBlockPositions: Array + + // R, G, B colour channels + val r: Float + val g: Float + val b: Float + + /** + * Absolute time in milliseconds when this AreaHighlighter will automatically [hide] + */ + val until: Long + + /** + * Line thickness used in the renderer + */ + var thickness: Float + + /** + * Highlight a [block position][pos] with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds + */ + fun highlightBlock(pos: BlockPos, r: Float, g: Float, b: Float, time: Int) = + highlightArea(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble(), pos.x + 1.0, pos.y + 1.0, pos.z + 1.0, r, g, b, time) + + /** + * Highlight an area between ([x1], [y1], [z1]) and ([x2], [y2], [z2]) with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds + */ + fun highlightArea(x1: Double, y1: Double, z1: Double, x2: Double, y2: Double, z2: Double, r: Float, g: Float, b: Float, time: Int) + + /** + * Highlight the specified [blocks][blockPositions] with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds + */ + fun highlightBlocks(blockPositions: Array, r: Float, g: Float, b: Float, time: Int) + + /** + * Stop this AreaHighlighter from rendering anything, does nothing when not [shown] + */ + fun hide() +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/AreaHighlighter.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/AreaHighlighter.kt index b950bb3..feea8fd 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/AreaHighlighter.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/AreaHighlighter.kt @@ -10,72 +10,47 @@ import net.minecraft.util.math.BlockPos import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import org.ender_development.catalyx.api.v1.client.interfaces.IAreaHighlighter import org.lwjgl.opengl.GL11 -/** - * A helper class allowing you to highlight an area or a block in 3D space - * @see [highlightBlock] - * @see [highlightBlocks] - * @see [highlightArea] - */ @SideOnly(Side.CLIENT) -class AreaHighlighter { +internal class AreaHighlighter : IAreaHighlighter { private var counter = 0 private var counterDirection = 1 - var shown = false + override var shown = false private set - var x1 = .0 + override var x1 = .0 private set - var y1 = .0 + override var y1 = .0 private set - var z1 = .0 + override var z1 = .0 private set - val pos1 + override val pos1 get() = BlockPos(x1, y1, z1) - var x2 = .0 + override var x2 = .0 private set - var y2 = .0 + override var y2 = .0 private set - var z2 = .0 + override var z2 = .0 private set - val pos2 + override val pos2 get() = BlockPos(x2, y2, z2) - var drawBlockPositions = false + override var drawBlockPositions = false private set - var drawnBlockPositions = emptyArray() + override var drawnBlockPositions = emptyArray() private set - var r = 1f + override var r = 1f private set - var g = 1f + override var g = 1f private set - var b = 1f + override var b = 1f private set - var until = 0L + override var until = 0L private set - var thickness = 3f - - /** - * r, g, b are colours between 0 and 1, time is in milliseconds - */ - fun highlightBlock(pos: BlockPos, r: Float, g: Float, b: Float, time: Int) { - x1 = pos.x.toDouble() - y1 = pos.y.toDouble() - z1 = pos.z.toDouble() - x2 = x1 + 1 - y2 = y1 + 1 - z2 = z1 + 1 - this.r = r - this.g = g - this.b = b - until = System.currentTimeMillis() + time.toLong() - show() - } + override var thickness = 3f - /** - * r, g, b are colours between 0 and 1, time is in milliseconds - */ - fun highlightArea(x1: Double, y1: Double, z1: Double, x2: Double, y2: Double, z2: Double, r: Float, g: Float, b: Float, time: Int) { + override fun highlightArea(x1: Double, y1: Double, z1: Double, x2: Double, y2: Double, z2: Double, r: Float, g: Float, b: Float, time: Int) { this.x1 = x1 this.y1 = y1 this.z1 = z1 @@ -89,10 +64,7 @@ class AreaHighlighter { show() } - /** - * r, g, b are colours between 0 and 1, time is in milliseconds - */ - fun highlightBlocks(blockPositions: Array, r: Float, g: Float, b: Float, time: Int) { + override fun highlightBlocks(blockPositions: Array, r: Float, g: Float, b: Float, time: Int) { drawBlockPositions = true drawnBlockPositions = blockPositions this.r = r @@ -102,17 +74,15 @@ class AreaHighlighter { show() } - /** - * call this if you want to prematurely hide the block highlight; - * otherwise, this is automatically called after the {time} passes - */ - fun hide() { + override fun hide() { eventHandlers.remove(::eventHandler) shown = false counter = 0 counterDirection = 1 - drawBlockPositions = false - drawnBlockPositions = emptyArray() + if(drawBlockPositions) { + drawBlockPositions = false + drawnBlockPositions = emptyArray() + } } internal fun show() { From 6f171f3fac62eac68b0f1ac8bbf36a02e35312fa Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Tue, 3 Feb 2026 01:21:12 +0100 Subject: [PATCH 52/58] take this chance to eat AreaHighlighter --- .../v1/client/interfaces/IAreaHighlighter.kt | 56 ++++--- .../catalyx/core/client/AreaHighlighter.kt | 148 +++++++----------- 2 files changed, 89 insertions(+), 115 deletions(-) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt index 7878f54..d85005d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt @@ -1,6 +1,7 @@ package org.ender_development.catalyx.api.v1.client.interfaces import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3d /** * A helper allowing you to highlight an area, block or blocks in 3D space @@ -14,33 +15,26 @@ interface IAreaHighlighter { */ val shown: Boolean - // Starting X, Y, Z - val x1: Double - val y1: Double - val z1: Double /** - * A BlockPos instance from the integer part of the (starting) [x1] [y1] [z1] coordinates. - * - * N/A when [highlightBlocks] is used. + * Array of outlines that are currently being drawn */ - val pos1 - get() = BlockPos(x1, y1, z1) - - // Ending X, Y, Z - val x2: Double - val y2: Double - val z2: Double + val drawOutlinesFor: Array> /** - * A BlockPos instance from the integer part of the (ending) [x2] [y2] [z2] coordinates. + * A BlockPos instance from the integer part of the starting coordinates for the first outline from [drawOutlinesFor] * - * N/A when [highlightBlocks] is used. + * Returns [BlockPos.ORIGIN] (0, 0, 0) when not [drawing][shown] anything */ - val pos2 - get() = BlockPos(x2, y2, z2) + val pos1: BlockPos + get() = BlockPos((drawOutlinesFor.getOrNull(0) ?: return BlockPos.ORIGIN).first) - val drawBlockPositions: Boolean - val drawnBlockPositions: Array + /** + * A BlockPos instance from the integer part of the ending coordinates for the first outline from [drawOutlinesFor] + * + * Returns [BlockPos.ORIGIN] (0, 0, 0) when not [drawing][shown] anything + */ + val pos2: BlockPos + get() = BlockPos((drawOutlinesFor.getOrNull(0) ?: return BlockPos.ORIGIN).second) // R, G, B colour channels val r: Float @@ -61,20 +55,36 @@ interface IAreaHighlighter { * Highlight a [block position][pos] with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds */ fun highlightBlock(pos: BlockPos, r: Float, g: Float, b: Float, time: Int) = - highlightArea(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble(), pos.x + 1.0, pos.y + 1.0, pos.z + 1.0, r, g, b, time) + highlightAreas(arrayOf(pos.area()), r, g, b, time) /** * Highlight an area between ([x1], [y1], [z1]) and ([x2], [y2], [z2]) with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds */ - fun highlightArea(x1: Double, y1: Double, z1: Double, x2: Double, y2: Double, z2: Double, r: Float, g: Float, b: Float, time: Int) + fun highlightArea(x1: Double, y1: Double, z1: Double, x2: Double, y2: Double, z2: Double, r: Float, g: Float, b: Float, time: Int) = + highlightAreas(arrayOf(Vec3d(x1, y1, z1) to Vec3d(x2, y2, z2)), r, g, b, time) /** * Highlight the specified [blocks][blockPositions] with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds */ - fun highlightBlocks(blockPositions: Array, r: Float, g: Float, b: Float, time: Int) + fun highlightBlocks(blockPositions: Array, r: Float, g: Float, b: Float, time: Int) = + highlightAreas(Array(blockPositions.size) { blockPositions[it].area() }, r, g, b, time) + + /** + * Highlight the specified [areas] with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds + */ + fun highlightAreas(areas: Array>, r: Float, g: Float, b: Float, time: Int) + + /** + * Highlight the specified [areas] with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds + */ + fun highlightAreas(areas: Collection>, r: Float, g: Float, b: Float, time: Int) = + highlightAreas(areas.toTypedArray(), r, g, b, time) /** * Stop this AreaHighlighter from rendering anything, does nothing when not [shown] */ fun hide() } + +private fun BlockPos.area(): Pair = + Vec3d(x.toDouble(), y.toDouble(), z.toDouble()) to Vec3d(x + 1.0, y + 1.0, z + 1.0) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/client/AreaHighlighter.kt b/src/main/kotlin/org/ender_development/catalyx/core/client/AreaHighlighter.kt index feea8fd..42a7853 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/client/AreaHighlighter.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/client/AreaHighlighter.kt @@ -4,41 +4,20 @@ import io.netty.util.internal.ConcurrentSet import net.minecraft.client.Minecraft import net.minecraft.client.renderer.BufferBuilder import net.minecraft.client.renderer.GlStateManager -import net.minecraft.client.renderer.Tessellator import net.minecraft.client.renderer.vertex.DefaultVertexFormats -import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3d import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly import org.ender_development.catalyx.api.v1.client.interfaces.IAreaHighlighter +import org.ender_development.catalyx.core.utils.RenderUtils import org.lwjgl.opengl.GL11 @SideOnly(Side.CLIENT) internal class AreaHighlighter : IAreaHighlighter { - private var counter = 0 - private var counterDirection = 1 - override var shown = false private set - override var x1 = .0 - private set - override var y1 = .0 - private set - override var z1 = .0 - private set - override val pos1 - get() = BlockPos(x1, y1, z1) - override var x2 = .0 - private set - override var y2 = .0 - private set - override var z2 = .0 - private set - override val pos2 - get() = BlockPos(x2, y2, z2) - override var drawBlockPositions = false - private set - override var drawnBlockPositions = emptyArray() + override var drawOutlinesFor = emptyArray>() private set override var r = 1f private set @@ -50,27 +29,16 @@ internal class AreaHighlighter : IAreaHighlighter { private set override var thickness = 3f - override fun highlightArea(x1: Double, y1: Double, z1: Double, x2: Double, y2: Double, z2: Double, r: Float, g: Float, b: Float, time: Int) { - this.x1 = x1 - this.y1 = y1 - this.z1 = z1 - this.x2 = x2 - this.y2 = y2 - this.z2 = z2 - this.r = r - this.g = g - this.b = b - until = System.currentTimeMillis() + time.toLong() - show() - } + override fun highlightAreas(areas: Array>, r: Float, g: Float, b: Float, time: Int) { + if(areas.isEmpty()) + return - override fun highlightBlocks(blockPositions: Array, r: Float, g: Float, b: Float, time: Int) { - drawBlockPositions = true - drawnBlockPositions = blockPositions + drawOutlinesFor = areas + shown = true this.r = r this.g = g this.b = b - until = System.currentTimeMillis() + time.toLong() + until = System.currentTimeMillis() + time show() } @@ -79,10 +47,7 @@ internal class AreaHighlighter : IAreaHighlighter { shown = false counter = 0 counterDirection = 1 - if(drawBlockPositions) { - drawBlockPositions = false - drawnBlockPositions = emptyArray() - } + drawOutlinesFor = emptyArray() } internal fun show() { @@ -90,10 +55,9 @@ internal class AreaHighlighter : IAreaHighlighter { shown = true } - internal companion object { - val eventHandlers = ConcurrentSet<(RenderWorldLastEvent) -> Unit>() - } - + private var counter = 0 + private var counterDirection = 1 + private fun eventHandler(event: RenderWorldLastEvent) { if(!shown) return hide() @@ -111,30 +75,26 @@ internal class AreaHighlighter : IAreaHighlighter { val alpha = .5f + counter / 100f val p = Minecraft.getMinecraft().player - val doubleX = p.lastTickPosX + (p.posX - p.lastTickPosX) * event.partialTicks - val doubleY = p.lastTickPosY + (p.posY - p.lastTickPosY) * event.partialTicks - val doubleZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * event.partialTicks + val translateX = p.lastTickPosX + (p.posX - p.lastTickPosX) * event.partialTicks + val translateY = p.lastTickPosY + (p.posY - p.lastTickPosY) * event.partialTicks + val translateZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * event.partialTicks GlStateManager.pushMatrix() GlStateManager.enableBlend() GlStateManager.color(r, g, b, alpha) GlStateManager.glLineWidth(thickness) - GlStateManager.translate(-doubleX, -doubleY, -doubleZ) + GlStateManager.translate(-translateX, -translateY, -translateZ) GlStateManager.disableDepth() GlStateManager.disableTexture2D() + + RenderUtils.bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR) + + drawOutlinesFor.forEach { (from, to) -> + renderOutline(RenderUtils.bufferBuilder, from.x, from.y, from.z, to.x, to.y, to.z, r, g, b, alpha) + } - val tessellator = Tessellator.getInstance() - val buffer = tessellator.buffer - buffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR) - if(!drawBlockPositions) - renderOutline(buffer, x1, y1, z1, x2 - x1, y2 - y1, z2 - z1, r, g, b, alpha) - else - drawnBlockPositions.forEach { - renderOutline(buffer, it.x.toDouble(), it.y.toDouble(), it.z.toDouble(), 1.0, 1.0, 1.0, r, g, b, alpha) - } - - tessellator.draw() + RenderUtils.tessellator.draw() GlStateManager.enableTexture2D() GlStateManager.enableDepth() @@ -142,33 +102,37 @@ internal class AreaHighlighter : IAreaHighlighter { GlStateManager.popMatrix() } - private fun renderOutline(buffer: BufferBuilder, mx: Double, my: Double, mz: Double, dx: Double, dy: Double, dz: Double, red: Float, green: Float, blue: Float, alpha: Float) { - buffer.pos(mx, my, mz ).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my, mz ).color(red, green, blue, alpha).endVertex() - buffer.pos(mx, my, mz ).color(red, green, blue, alpha).endVertex() - buffer.pos(mx, my + dy, mz ).color(red, green, blue, alpha).endVertex() - buffer.pos(mx, my, mz ).color(red, green, blue, alpha).endVertex() - buffer.pos(mx, my, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my + dy, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx, my + dy, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my + dy, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my + dy, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my + dy, mz ).color(red, green, blue, alpha).endVertex() - - buffer.pos(mx, my + dy, mz ).color(red, green, blue, alpha).endVertex() - buffer.pos(mx, my + dy, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx, my + dy, mz ).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my + dy, mz ).color(red, green, blue, alpha).endVertex() - - buffer.pos(mx + dx, my, mz ).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my, mz ).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my + dy, mz ).color(red, green, blue, alpha).endVertex() - - buffer.pos(mx, my, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx + dx, my, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx, my, mz + dz).color(red, green, blue, alpha).endVertex() - buffer.pos(mx, my + dy, mz + dz).color(red, green, blue, alpha).endVertex() + private fun renderOutline(buffer: BufferBuilder, mx: Double, my: Double, mz: Double, tx: Double, ty: Double, tz: Double, red: Float, green: Float, blue: Float, alpha: Float) { + buffer.pos(mx, my, mz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, my, mz).color(red, green, blue, alpha).endVertex() + buffer.pos(mx, my, mz).color(red, green, blue, alpha).endVertex() + buffer.pos(mx, ty, mz).color(red, green, blue, alpha).endVertex() + buffer.pos(mx, my, mz).color(red, green, blue, alpha).endVertex() + buffer.pos(mx, my, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, ty, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(mx, ty, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, ty, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, my, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, ty, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, ty, mz).color(red, green, blue, alpha).endVertex() + + buffer.pos(mx, ty, mz).color(red, green, blue, alpha).endVertex() + buffer.pos(mx, ty, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(mx, ty, mz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, ty, mz).color(red, green, blue, alpha).endVertex() + + buffer.pos(tx, my, mz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, my, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, my, mz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, ty, mz).color(red, green, blue, alpha).endVertex() + + buffer.pos(mx, my, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(tx, my, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(mx, my, tz).color(red, green, blue, alpha).endVertex() + buffer.pos(mx, ty, tz).color(red, green, blue, alpha).endVertex() + } + + internal companion object { + val eventHandlers = ConcurrentSet<(RenderWorldLastEvent) -> Unit>() } } From 04e99e5f474bd6dd5c0783c66f53b78e11e66c57 Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Tue, 3 Feb 2026 01:26:16 +0100 Subject: [PATCH 53/58] kinda silly that this isn't a stdlib function or, at least, I couldn't find it --- .../catalyx/api/v1/client/interfaces/IAreaHighlighter.kt | 3 ++- .../catalyx/api/v1/common/extensions/Array.kt | 4 ++++ .../catalyx/api/v1/common/extensions/List.kt | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Array.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt index d85005d..6a8b820 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/client/interfaces/IAreaHighlighter.kt @@ -2,6 +2,7 @@ package org.ender_development.catalyx.api.v1.client.interfaces import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d +import org.ender_development.catalyx.api.v1.common.extensions.mapToArray /** * A helper allowing you to highlight an area, block or blocks in 3D space @@ -67,7 +68,7 @@ interface IAreaHighlighter { * Highlight the specified [blocks][blockPositions] with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds */ fun highlightBlocks(blockPositions: Array, r: Float, g: Float, b: Float, time: Int) = - highlightAreas(Array(blockPositions.size) { blockPositions[it].area() }, r, g, b, time) + highlightAreas(blockPositions.mapToArray(BlockPos::area), r, g, b, time) /** * Highlight the specified [areas] with a specific colour ([red][r], [green][g], [blue][b]) for a specified [time] in milliseconds diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Array.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Array.kt new file mode 100644 index 0000000..e030b2a --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/Array.kt @@ -0,0 +1,4 @@ +package org.ender_development.catalyx.api.v1.common.extensions + +inline fun Array.mapToArray(crossinline mapper: (T) -> R) = + Array(size) { mapper(this[it]) } diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt index 201a10b..6f0ce60 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/List.kt @@ -50,3 +50,6 @@ inline fun List.getApplyOrDefault(idx: Int, crossinline mapper: (T) -> mapper(this[idx]) else default() + +inline fun List.mapToArray(crossinline mapper: (T) -> R) = + Array(size) { mapper(this[it]) } From f2e422bcbf13f4ad157e3785ce840d05a1f8cfad Mon Sep 17 00:00:00 2001 From: rozbrajaczpoziomow Date: Wed, 4 Feb 2026 14:45:25 +0100 Subject: [PATCH 54/58] work a bit on the copy-paste tool --- .../catalyx/core/blocks/BaseBlock.kt | 2 +- .../catalyx/core/items/BaseItem.kt | 2 +- .../catalyx/core/items/CopyPasteTool.kt | 50 +++++++++++++------ .../catalyx/core/recipes/RecipeMap.kt | 2 +- .../chance/output/IChancedOutputLogic.kt | 8 +-- ...xtraTile.kt => ICopyPasteExtraDataTile.kt} | 9 ++-- .../integration/crafttweaker/CatalyxBlock.kt | 2 +- .../integration/top/FluidTileProvider.kt | 2 +- .../catalyx/modules/test/DevTestModule.kt | 34 +++++++++++++ .../resources/assets/catalyx/lang/en_us.lang | 6 +++ 10 files changed, 89 insertions(+), 28 deletions(-) rename src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/{ICopyPasteExtraTile.kt => ICopyPasteExtraDataTile.kt} (51%) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt index e214304..8ed7f1d 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/blocks/BaseBlock.kt @@ -19,7 +19,7 @@ import org.ender_development.catalyx.core.register open class BaseBlock(val mod: ICatalyxMod, name: String, material: Material = Material.ROCK, hardness: Float = 3f) : Block(material), IBlockProvider { init { registryName = ResourceLocation(mod.modId, name) - translationKey = "${mod.modId}.$name" + translationKey = "${mod.modId}:$name" blockHardness = hardness creativeTab = mod.creativeTab } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt index 929fe78..1f250c6 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/BaseItem.kt @@ -12,7 +12,7 @@ import org.ender_development.catalyx.core.register open class BaseItem(val mod: ICatalyxMod, val name: String) : Item(), IItemProvider { init { registryName = ResourceLocation(mod.modId, name) - translationKey = "${mod.modId}.$name" + translationKey = "${mod.modId}:$name" creativeTab = mod.creativeTab } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt index 723ec0a..ed1f0f8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/items/CopyPasteTool.kt @@ -1,5 +1,7 @@ package org.ender_development.catalyx.core.items +import net.minecraft.block.Block +import net.minecraft.client.gui.GuiScreen import net.minecraft.client.util.ITooltipFlag import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack @@ -9,16 +11,21 @@ import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.ResourceLocation import net.minecraft.util.math.BlockPos +import net.minecraft.util.text.Style +import net.minecraft.util.text.TextComponentString +import net.minecraft.util.text.TextFormatting import net.minecraft.world.World import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.api.v1.common.extensions.translate import org.ender_development.catalyx.api.v1.utils.Utils +import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.client.IAutoModel import org.ender_development.catalyx.core.client.gui.BaseGuiTyped import org.ender_development.catalyx.core.tiles.BaseTile -import org.ender_development.catalyx.core.tiles.helper.ICopyPasteExtraTile +import org.ender_development.catalyx.core.tiles.helper.ICopyPasteExtraDataTile class CopyPasteTool : BaseItem(Catalyx, "copy_paste_tool"), IAutoModel { - private companion object { + companion object { const val NBT_COPIED_BLOCK_KEY = "CopiedBlock" const val NBT_COPIED_DATA_KEY = "CopiedData" const val NBT_IS_PAUSED_KEY = "IsPaused" @@ -32,7 +39,7 @@ class CopyPasteTool : BaseItem(Catalyx, "copy_paste_tool"), IAutoModel { val clickedBlockId = world.getBlockState(pos).block.registryName!!.toString() val copy = player.isSneaking - if(!copy && (copiedBlock.isEmpty() || copiedBlock != clickedBlockId)) + if(!copy && (copiedBlock.isBlank() || copiedBlock != clickedBlockId)) return EnumActionResult.PASS val te = world.getTileEntity(pos) @@ -47,11 +54,13 @@ class CopyPasteTool : BaseItem(Catalyx, "copy_paste_tool"), IAutoModel { copyTag.setBoolean(NBT_NEEDS_REDSTONE_KEY, te.needsRedstonePower) } - if(te is ICopyPasteExtraTile) + if(te is ICopyPasteExtraDataTile) te.copyData(copyTag) - if(copyTag.isEmpty) // don't copy emptiness + if(copyTag.isEmpty) { // don't copy emptiness + player.sendMessage(TextComponentString("Couldn't copy anything from this block").setStyle(Style().setColor(TextFormatting.RED))) return EnumActionResult.PASS + } tag.setTag(NBT_COPIED_DATA_KEY, copyTag) tag.setString(NBT_COPIED_BLOCK_KEY, clickedBlockId) @@ -70,11 +79,11 @@ class CopyPasteTool : BaseItem(Catalyx, "copy_paste_tool"), IAutoModel { te.needsRedstonePower = pasteTag.getBoolean(NBT_NEEDS_REDSTONE_KEY) } - if(te is ICopyPasteExtraTile) + if(te is ICopyPasteExtraDataTile) te.pasteData(pasteTag, player) } - if(!stack.hasTagCompound()) + if(!stack.hasTagCompound() && !tag.isEmpty) stack.tagCompound = tag return EnumActionResult.SUCCESS @@ -82,22 +91,31 @@ class CopyPasteTool : BaseItem(Catalyx, "copy_paste_tool"), IAutoModel { override fun addInformation(stack: ItemStack, world: World?, tooltip: List, flag: ITooltipFlag) { tooltip as MutableList - tooltip.add("TODO ;p") - - if(Utils.environment.isDeobfuscated) { - tooltip.add("") - tooltip.add(stack.tagCompound?.getString(NBT_COPIED_BLOCK_KEY).toString()) - tooltip.add("${stack.tagCompound?.getCompoundTag(NBT_COPIED_DATA_KEY)}") + tooltip.add("$translationKey.desc.1".translate()) + tooltip.add("$translationKey.desc.2".translate()) + + val tag = stack.tagCompound + val copiedBlock = tag?.getString(NBT_COPIED_BLOCK_KEY) + if(tag == null || copiedBlock.isNullOrBlank()) { + tooltip.add("$translationKey.desc.empty".translate()) + return } + + val shift = GuiScreen.isShiftKeyDown() + + val block = Block.REGISTRY.registryObjects[ResourceLocation(copiedBlock)] + tooltip.add("$translationKey.desc.copying".translate(if(shift || block == null) copiedBlock else block.localizedName)) + + if(shift) + tooltip.add(tag.getCompoundTag(NBT_COPIED_DATA_KEY).toString()) } /** * don't register if this isn't a dev environment, as this item is not finished - * TODO tooltip, name translation, maybe signify what blocks you can actually copy across ;p + * TODO texture */ override fun isEnabled() = Utils.environment.isDeobfuscated - override val textureLocation: ResourceLocation = - ResourceLocation(mod.modId, "logo") + override val textureLocation = ResourceLocation(Reference.MODID, "logo") } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt index 163bb50..ae96648 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/RecipeMap.kt @@ -114,7 +114,7 @@ class RecipeMap> { this.maxFluidInputs = maxFluidInputs this.maxOutputs = maxOutputs this.maxFluidOutputs = maxFluidOutputs - translationKey = "recipemap.${mod.modId}.$unlocalizedName.name" + translationKey = "recipemap.${mod.modId}:$unlocalizedName.name" primaryRecipeCategory = RecipeCategory.create(mod.modId, unlocalizedName, translationKey, this) defaultRecipeBuilder.recipeMap = this diff --git a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/IChancedOutputLogic.kt b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/IChancedOutputLogic.kt index a56234e..05c037c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/IChancedOutputLogic.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/recipes/chance/output/IChancedOutputLogic.kt @@ -43,7 +43,7 @@ interface IChancedOutputLogic { override fun > roll(chancedEntries: List, boostFunction: IBoostFunction, baseTier: Int, machineTier: Int) = null - override val translationKey = "${Reference.MODID}.chance_logic.none" + override val translationKey = "chance_logic.${Reference.MODID}:none" override fun toString() = "ChancedOutputLogic{type=NONE}" @@ -58,7 +58,7 @@ interface IChancedOutputLogic { passesChance(getChance(it, boostFunction, baseTier, machineTier)) } - override val translationKey = "${Reference.MODID}.chance_logic.or" + override val translationKey = "chance_logic.${Reference.MODID}:or" override fun toString() = "ChancedOutputLogic{type=OR}" @@ -76,7 +76,7 @@ interface IChancedOutputLogic { else null - override val translationKey = "${Reference.MODID}.chance_logic.and" + override val translationKey = "chance_logic.${Reference.MODID}:and" override fun toString() = "ChancedOutputLogic{type=AND}" @@ -94,7 +94,7 @@ interface IChancedOutputLogic { null } - override val translationKey = "${Reference.MODID}.chance_logic.first" + override val translationKey = "chance_logic.${Reference.MODID}:first" override fun toString() = "ChancedOutputLogic{type=FIRST}" diff --git a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraTile.kt b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraDataTile.kt similarity index 51% rename from src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraTile.kt rename to src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraDataTile.kt index a1eec28..7f5b921 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraTile.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/tiles/helper/ICopyPasteExtraDataTile.kt @@ -3,12 +3,15 @@ package org.ender_development.catalyx.core.tiles.helper import net.minecraft.entity.player.EntityPlayer import net.minecraft.nbt.NBTTagCompound -/** TODO come up with a better name lmfao */ -interface ICopyPasteExtraTile { +// TODO move somewhere into API +/** + * An interface for Tile Entities to implement if they want to copy/paste extra data with the Catalyx [CopyPasteTool][org.ender_development.catalyx.core.items.CopyPasteTool] + */ +interface ICopyPasteExtraDataTile { /** * Write data into the NBT Tag to be copied and stored * - * Note: if your TE implements [org.ender_development.catalyx.core.client.gui.BaseGuiTyped.IDefaultButtonVariables] (like [org.ender_development.catalyx.core.tiles.BaseMachineTile] does), the `isPaused` and `needsRedstonePower` fields are already copied + * Note: if your TE implements [BaseGuiTyped.IDefaultButtonVariables][org.ender_development.catalyx.core.client.gui.BaseGuiTyped.IDefaultButtonVariables] (like [BaseMachineTile][org.ender_development.catalyx.core.tiles.BaseMachineTile] does), the `isPaused` and `needsRedstonePower` fields are already copied */ fun copyData(tag: NBTTagCompound) diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/CatalyxBlock.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/CatalyxBlock.kt index a57b696..15e2884 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/CatalyxBlock.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/crafttweaker/CatalyxBlock.kt @@ -16,7 +16,7 @@ import stanhebben.zenscript.annotations.ZenMethod class CatalyxBlock(private val block: Block) { companion object { private fun init(block: Block, name: String): CatalyxBlock = - CatalyxBlock(block.setRegistryName(Reference.MODID, name).setTranslationKey("tile.${Reference.MODID}.$name.name")) + CatalyxBlock(block.setRegistryName(Reference.MODID, name).setTranslationKey("tile.${Reference.MODID}:$name.name")) @ZenMethod fun createBlock(name: String, material: IMaterial): CatalyxBlock = diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt index ada6b4c..39642c8 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/integration/top/FluidTileProvider.kt @@ -11,7 +11,7 @@ import org.ender_development.catalyx.core.tiles.helper.IFluidTile import java.awt.Color internal class FluidTileProvider : IProbeInfoProvider { - override fun getID() = "${Reference.MODID}.auto.ifluidtile_provider" + override fun getID() = "${Reference.MODID}:auto.ifluidtile_provider" override fun addProbeInfo(mode: ProbeMode, info: IProbeInfo, player: EntityPlayer, world: World, state: IBlockState, data: IProbeHitData) { val tile = world.getTileEntity(data.pos) as? IFluidTile ?: return diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt index 81e4b37..2ef534b 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/test/DevTestModule.kt @@ -1,22 +1,32 @@ package org.ender_development.catalyx.modules.test +import net.minecraft.block.state.IBlockState import net.minecraft.client.Minecraft +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.nbt.NBTTagCompound +import net.minecraft.util.ResourceLocation import net.minecraft.util.text.TextComponentString +import net.minecraft.world.World import net.minecraftforge.client.event.ClientChatEvent +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.ender_development.catalyx.Catalyx import org.ender_development.catalyx.api.v1.common.extensions.subLogger import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModule import org.ender_development.catalyx.api.v1.utils.Utils import org.ender_development.catalyx.core.Reference +import org.ender_development.catalyx.core.blocks.BaseTileBlock import org.ender_development.catalyx.core.blocks.IOTileBlock import org.ender_development.catalyx.core.blocks.multiblock.CenterBlock import org.ender_development.catalyx.core.blocks.multiblock.parts.CornerBlock import org.ender_development.catalyx.core.blocks.multiblock.parts.SideBlock import org.ender_development.catalyx.core.client.AreaHighlighter +import org.ender_development.catalyx.core.tiles.BaseTile +import org.ender_development.catalyx.core.tiles.helper.ICopyPasteExtraDataTile import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer import org.ender_development.catalyx.modules.CatalyxModuleBase +@Suppress("unused") @CatalyxModule( moduleId = CatalyxInternalModuleContainer.MODULE_TEST, containerId = Reference.MODID, @@ -33,6 +43,30 @@ internal class DevTestModule : CatalyxModuleBase() { val testMultiBlock = CenterBlock(Catalyx, "test_middle", DummyClass1::class.java, 1, testCorner, testSide) val testTesrBlock = IOTileBlock(Catalyx, "test_tesr", DummyClass2::class.java, 0) + // yes, this needs to be in preInit, otherwise a crash happens because CapabilityEnergy.ENERGY is still null lmao + override fun preInit(event: FMLPreInitializationEvent) { + class TestCopyPasteTile() : BaseTile(Catalyx), ICopyPasteExtraDataTile { + override fun copyData(tag: NBTTagCompound) { + repeat(10) { + tag.setInteger("Copy$it", it + Catalyx.RANDOM.nextInt(100, 1000)) + } + } + + override fun pasteData(tag: NBTTagCompound, player: EntityPlayer) { + logger.info("Received:") + logger.info(tag.toString()) + } + } + + val testCopyPasteBlock = object : BaseTileBlock(Catalyx, "test_copy_paste", TestCopyPasteTile::class.java, -1) { + override val textureLocation = ResourceLocation(Reference.MODID, "logo") + override val modelLocation = ResourceLocation("minecraft", "block/cobblestone") + + override fun createTileEntity(world: World, state: IBlockState) = + TestCopyPasteTile() + } + } + override fun load() = logger.info("Detected deobfuscated environment, adding some testing features") diff --git a/src/main/resources/assets/catalyx/lang/en_us.lang b/src/main/resources/assets/catalyx/lang/en_us.lang index 1c02300..6228a03 100644 --- a/src/main/resources/assets/catalyx/lang/en_us.lang +++ b/src/main/resources/assets/catalyx/lang/en_us.lang @@ -1,3 +1,9 @@ +item.catalyx:copy_paste_tool.name=Copy-Paste Tool +item.catalyx:copy_paste_tool.desc.1=Allows you to copy-paste settings and other data between supported blocks +item.catalyx:copy_paste_tool.desc.2=Shift+right-click to copy, right-click to paste +item.catalyx:copy_paste_tool.desc.copying=Copying data from %s - shift to see data +item.catalyx:copy_paste_tool.desc.empty=Not copying any data + tooltip.catalyx:running=Click to pause tooltip.catalyx:paused=Click to resume tooltip.catalyx:redstone_high=Works with a redstone signal From 1210569985bdcda5adfdd758af48fcd9329e600d Mon Sep 17 00:00:00 2001 From: MasterEnderman Date: Fri, 13 Feb 2026 16:14:26 +0100 Subject: [PATCH 55/58] statemachine for future TileEntities --- .../core/common/statemachine/StateMachine.kt | 51 +++++++++++++++++++ .../statemachine/StateMachineBuilder.kt | 44 ++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/common/statemachine/StateMachine.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/common/statemachine/StateMachineBuilder.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/core/common/statemachine/StateMachine.kt b/src/main/kotlin/org/ender_development/catalyx/core/common/statemachine/StateMachine.kt new file mode 100644 index 0000000..2205a19 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/common/statemachine/StateMachine.kt @@ -0,0 +1,51 @@ +package org.ender_development.catalyx.core.common.statemachine + +import org.ender_development.catalyx.Catalyx +import org.ender_development.catalyx.core.utils.EnvironmentUtils + +typealias StateTransition = (S, E) -> S? +typealias StateAction = (S) -> Unit + +class StateMachine(initialState: S) { + private val transitions = mutableMapOf, StateTransition>() + private val onEnterActions = mutableMapOf>>() + private val onExitActions = mutableMapOf>>() + + var currentState = initialState + private set + + fun transition(from: S, on: E, to: S) { + transitions[from to on] = { _, _ -> to } + } + + fun transition(from: S, on: E, handler: StateTransition) { + transitions[from to on] = handler + } + + fun onEnter(state: S, action: StateAction) { + onEnterActions.getOrPut(state) { mutableListOf() }.add(action) + } + + fun onExit(state: S, action: StateAction) { + onExitActions.getOrPut(state) { mutableListOf() }.add(action) + } + + fun sendEvent(event: E): Boolean { + val transition = transitions[currentState to event] + val newState = transition?.invoke(currentState, event) + + return if(newState != null && newState != currentState) { + // Exit current state + onExitActions[currentState]?.forEach { it(currentState) } + + val previousState = currentState + currentState = newState + + // Enter new state + onEnterActions[currentState]?.forEach { it(currentState) } + if(EnvironmentUtils.isDeobfuscated) + Catalyx.LOGGER.debug("Transition: $previousState -> $event -> $currentState") + true + } else false + } +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/common/statemachine/StateMachineBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/common/statemachine/StateMachineBuilder.kt new file mode 100644 index 0000000..3bb1379 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/common/statemachine/StateMachineBuilder.kt @@ -0,0 +1,44 @@ +package org.ender_development.catalyx.core.common.statemachine + +class StateMachineDSL(initialState: S) { + private val machine = StateMachine(initialState) + + fun state(state: S, block: StateBuilder.() -> Unit) { + val builder = StateBuilder(state, machine) + builder.block() + } + + fun build(): StateMachine = + machine +} + +class StateBuilder(private val state: S, private val machine: StateMachine) { + + fun on(event: E, block: TransitionBuilder.() -> Unit) { + val builder = TransitionBuilder(state, event, machine) + builder.block() + } + + fun onEnter(action: StateAction) = + machine.onEnter(state, action) + + fun onExit(action: StateAction) = + machine.onExit(state, action) +} + +class TransitionBuilder(private val from: S, private val event: E, private val machine: StateMachine) { + + fun goto(to: S) = + machine.transition(from, event, to) + + fun gotoIf(condition: (S, E) -> Boolean, to: S) = + machine.transition(from, event) { s, e -> + if (condition(s, e)) to else null + } +} + +fun stateMachine(initialState: S, block: StateMachineDSL.() -> Unit): StateMachine { + val dsl = StateMachineDSL(initialState) + dsl.block() + return dsl.build() +} From afb16d822be4840d509584621a46601c0c6f1e35 Mon Sep 17 00:00:00 2001 From: MasterEnderman Date: Fri, 13 Feb 2026 16:14:49 +0100 Subject: [PATCH 56/58] update buildscripts --- buildSrc/CHANGELOG.md | 7 ++ buildSrc/src/main/kotlin/Repositories.kt | 66 ++++++++++++++++--- buildSrc/src/main/resources/deps.properties | 2 +- .../src/main/resources/utilities.properties | 2 +- 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/buildSrc/CHANGELOG.md b/buildSrc/CHANGELOG.md index 9fb5717..f80bab8 100644 --- a/buildSrc/CHANGELOG.md +++ b/buildSrc/CHANGELOG.md @@ -5,6 +5,13 @@ Writing a changelog is a good practice for maintaining a clear history of change Try to follow the [Common Changelog](https://common-changelog.org/) conventions. --> +## [0.5.2] - 2026-02-03 + +_general maintenance._ + +- update dependencies +- add a few more mavens + ## [0.5.1] - 2026-01-26 _this is fine._ diff --git a/buildSrc/src/main/kotlin/Repositories.kt b/buildSrc/src/main/kotlin/Repositories.kt index 5a543ff..a7577ca 100644 --- a/buildSrc/src/main/kotlin/Repositories.kt +++ b/buildSrc/src/main/kotlin/Repositories.kt @@ -4,14 +4,33 @@ import org.gradle.kotlin.dsl.repositories fun Project.loadDefaultRepositories() { repositories { mavenCentral() + // RetroFuturaGradle maven { - name = "CleanroomMC Maven" - url = uri("https://maven.cleanroommc.com") + name = "GTNH Maven" + url = uri("https://nexus.gtnewhorizons.com/repository/public/") + } + // JitPack is a novel package repository for JVM and Android projects. + // It builds Git projects on demand and provides you with ready-to-use artifacts (jar, aar). + // Docs: https://docs.jitpack.io/ + maven { + name = "JitPack" + url = uri("https://jitpack.io") } maven { name = "SpongePowered Maven" url = uri("https://repo.spongepowered.org/maven") } + // HEI, MixinBooter, GroovyScript, Forgelin Continuous, ... + maven { + name = "CleanroomMC Maven" + url = uri("https://maven.cleanroommc.com") + } + // Our own maven, meow :3 + maven { + name = "Ender-Development Maven" + url = uri("https://maven.ender-development.org/") + } + // Better implementation of the curseforge maven, which allows adding mods that disable third party downloads exclusiveContent { forRepository { maven { @@ -34,25 +53,52 @@ fun Project.loadDefaultRepositories() { includeGroup("maven.modrinth") } } + // CraftTweaker, ContentTweaker, BWM, JEI, ... maven { name = "BlameJared's Maven" url = uri("https://maven.blamejared.com/") } + // GTCE, GTCEu, AE2uel, EnderIO maven { - name = "JitPack" - url = uri("https://jitpack.io") + name = "GTCEu Maven" + url = uri("https://maven.gtceu.com") } + // AE2, Mekanism, ProjectE, ComputerCraft, OpenComputers, ... maven { - name = "Ender-Development Maven" - url = uri("https://maven.ender-development.org/") + name = "Thiakil's Maven" + url = uri("https://maven.thiakil.com/") } maven { - name = "GTNH Maven" - url = uri("https://nexus.gtnewhorizons.com/repository/public/") + name = "AppleCore's Maven" + url = uri("https://www.ryanliptak.com/maven/") } + // TiCo, Mantle, HungerOverhaul, Natura, IronChest, ... maven { - name = "GTCEu Maven" - url = uri("https://maven.gtceu.com") + name = "Mantle's Maven" + url = uri("https://dvs1.progwml6.com/files/maven") + } + // CTM + maven { + name = "tterrag's Maven" + url = uri("https://maven.tterrag.com/") + } + // cofh, codechicken, ProjectRed, p455w0rd, brandon3055, ... + maven { + name = "covers1624's Maven" + url = uri("https://maven.covers1624.net/") + } + maven { + name = "modmuss50's Maven" + url = uri("https://maven.modmuss50.me/") + } + maven { + name = "BuildCraft's Maven" + url = uri("https://mod-buildcraft.com/maven/") + } + // Large collection of mods from various authors, curseforge maven precursor + maven { + name = "ModMaven" + url = uri("https://modmaven.dev/") } mavenLocal() // Must be last for caching to work } diff --git a/buildSrc/src/main/resources/deps.properties b/buildSrc/src/main/resources/deps.properties index 9beea51..edd5463 100644 --- a/buildSrc/src/main/resources/deps.properties +++ b/buildSrc/src/main/resources/deps.properties @@ -76,4 +76,4 @@ use_modularui = true # The version of ModularUI to use, should be compatible with the Minecraft version you are using # Check https://repo.cleanroommc.com/#/releases/com/cleanroommc/modularui -modularui_version = 3.0.8 +modularui_version = 3.1.2 diff --git a/buildSrc/src/main/resources/utilities.properties b/buildSrc/src/main/resources/utilities.properties index 5f35372..377556b 100644 --- a/buildSrc/src/main/resources/utilities.properties +++ b/buildSrc/src/main/resources/utilities.properties @@ -39,7 +39,7 @@ use_spotless = true # - roz: Uses a heavily customized .editorconfig created by rozbrajaczpoziomow editorconfig = roz flexmark_version = 0.64.8 -google_java_format_version = 1.33.0 +google_java_format_version = 1.34.0 ktlint_version = 1.8.0 From 0b94ee41a61d9ef2a75c4d0238cd9a24e9f49cbf Mon Sep 17 00:00:00 2001 From: MasterEnderman Date: Thu, 26 Feb 2026 14:17:35 +0100 Subject: [PATCH 57/58] refactor various things --- .../api/v1/common/extensions/String.kt | 25 +++++++++-- .../api/v1/validation/CommonValidators.kt | 43 ++++++------------- .../core/utils/parser/AbstractJsonParser.kt | 8 ++-- .../catalyx/core/utils/parser/IParser.kt | 2 +- .../utils/parser/ParserRegistryBuilder.kt | 2 +- .../modules/CatalyxInternalModuleContainer.kt | 4 +- .../CommonModule.kt} | 11 +++-- 7 files changed, 48 insertions(+), 47 deletions(-) rename src/main/kotlin/org/ender_development/catalyx/modules/{internal/InternalModule.kt => common/CommonModule.kt} (67%) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt index dca310a..fdb2bcc 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/common/extensions/String.kt @@ -3,6 +3,7 @@ package org.ender_development.catalyx.api.v1.common.extensions import net.minecraft.block.Block +import net.minecraft.block.state.IBlockState import net.minecraft.client.resources.I18n import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -20,12 +21,29 @@ inline fun String.toPotion(): Potion = inline fun String.toOre() = OreIngredient(this) +fun String.toResourceLocation(): ResourceLocation { + val split = split(':') + return if(split.size == 1) ResourceLocation(this) else ResourceLocation(split[0], split[1]) +} + fun String.toStack(quantity: Int = 1, meta: Int = 0): ItemStack { val split = split(':') val meta = split.getApplyOrDefault(2, String::toInt) { meta } - val location = if(split.size == 1) ResourceLocation(this) else ResourceLocation(split[0], split[1]) - return Item.REGISTRY.registryObjects[location]?.toStack(quantity, meta) ?: Block.REGISTRY.registryObjects[location]?.toStack(quantity, meta).orEmpty() + return toItem()?.toStack(quantity, meta) ?: toBlock()?.toStack(quantity, meta).orEmpty() +} + +inline fun String.toItem(): Item? = + Item.REGISTRY.registryObjects[toResourceLocation()] + +inline fun String.toBlock(): Block? = + Block.REGISTRY.registryObjects[toResourceLocation()] + +fun String.toBlockState(meta: Int = 0): IBlockState? { + val split = split(':') + val meta = split.getApplyOrDefault(2, String::toInt) { meta } + @Suppress("DEPRECATION") + return toBlock()?.getStateFromMeta(meta) } inline fun String.toIngredient(meta: Int = 0): Ingredient = @@ -39,7 +57,8 @@ inline fun String.firstOre(): ItemStack = fun String.translate(vararg format: Any): String = if(Utils.environment.isServer) - this + @Suppress("DEPRECATION") + net.minecraft.util.text.translation.I18n.translateToLocalFormatted(this, *format) else I18n.format(this, *format) diff --git a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt index 7bbf5c8..b684fc9 100644 --- a/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt +++ b/src/main/kotlin/org/ender_development/catalyx/api/v1/validation/CommonValidators.kt @@ -1,5 +1,10 @@ package org.ender_development.catalyx.api.v1.validation +import net.minecraft.item.ItemStack +import org.ender_development.catalyx.api.v1.common.extensions.toBlock +import org.ender_development.catalyx.api.v1.common.extensions.toBlockState +import org.ender_development.catalyx.api.v1.common.extensions.toItem +import org.ender_development.catalyx.api.v1.common.extensions.toStack import org.ender_development.catalyx.api.v1.validation.interfaces.IValidator import org.ender_development.catalyx.core.config.ConfigParser @@ -50,37 +55,15 @@ object CommonValidators { } } - fun isItemStack(): IValidator = IValidator { - if(it == null) - return@IValidator false + fun isItemStack(): IValidator = + IValidator { it != null && it.toStack() != ItemStack.EMPTY } - return@IValidator try { - ConfigParser.ConfigItemStack(it).toItemStack() - true - } catch(_: Exception) { - false - } - } - - fun isBlockState(): IValidator = IValidator { - if(it == null) - return@IValidator false + fun isBlockState(): IValidator = + IValidator { it != null && it.toBlockState() != null } - return@IValidator try { - ConfigParser.ConfigBlockState(it).state != null - } catch(_: Exception) { - false - } - } + fun isBlock(): IValidator = + IValidator { it != null && it.toBlock() != null } - fun isBlock(): IValidator = IValidator { - if(it == null) - return@IValidator false - - return@IValidator try { - ConfigParser.ConfigBlockState(it).block != null - } catch(_: Exception) { - false - } - } + fun isItem(): IValidator = + IValidator { it != null && it.toItem() != null } } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt index 54c7b58..e802b93 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/AbstractJsonParser.kt @@ -23,7 +23,7 @@ abstract class AbstractJsonParser : IParser { abstract fun sanitize(rawData: TRaw): ValidationResult override fun parse(): List { - val file = File(filePath) + val file = File(input) if(!file.exists()) createDefaultFile(file) @@ -78,12 +78,12 @@ abstract class AbstractJsonParser : IParser { private fun logValidationIssues(itemIndex: Int, errors: List, warnings: List) { if(errors.isNotEmpty()) { - Catalyx.LOGGER.error("❌ Failed to parse item $itemIndex from $filePath:") + Catalyx.LOGGER.error("❌ Failed to parse item $itemIndex from $input:") errors.forEach { Catalyx.LOGGER.error(" $it") } } if(warnings.isNotEmpty()) { - Catalyx.LOGGER.warn("⚠️ Warnings for item $itemIndex from $filePath:") + Catalyx.LOGGER.warn("⚠️ Warnings for item $itemIndex from $input:") warnings.forEach { Catalyx.LOGGER.warn(" $it") } } } @@ -92,7 +92,7 @@ abstract class AbstractJsonParser : IParser { val stats = lastParsingStats val successRate = stats.successRate * 100 - Catalyx.LOGGER.info("📊 Parsing Summary for $filePath:") + Catalyx.LOGGER.info("📊 Parsing Summary for $input:") Catalyx.LOGGER.info(" Total items: ${stats.totalItems}") Catalyx.LOGGER.info(" ✅ Successful: ${stats.successfulItems}") Catalyx.LOGGER.info(" ❌ Failed: ${stats.failedItems}") diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/IParser.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/IParser.kt index 028e46f..2fd0a0c 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/IParser.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/IParser.kt @@ -2,6 +2,6 @@ package org.ender_development.catalyx.core.utils.parser interface IParser { fun parse(): List - val filePath: String + val input: String val stats: ParsingStats } diff --git a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParserRegistryBuilder.kt b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParserRegistryBuilder.kt index d71112c..a52eb3a 100644 --- a/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParserRegistryBuilder.kt +++ b/src/main/kotlin/org/ender_development/catalyx/core/utils/parser/ParserRegistryBuilder.kt @@ -11,7 +11,7 @@ class ParserRegistryBuilder { fun jsonParser(key: String, filePath: String, defaultData: () -> List, sanitizer: (T) -> ValidationResult) { val parser = object : AbstractJsonParser() { - override val filePath = filePath + override val input = filePath override val defaultRawData: List get() = defaultData() diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt index 7d4f6fe..f3ba436 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/CatalyxInternalModuleContainer.kt @@ -5,12 +5,12 @@ import org.ender_development.catalyx.api.v1.modules.annotations.CatalyxModuleCon import org.ender_development.catalyx.core.Reference /** - * Module Container for all internal Catalyx modules + * Module Container for all modules inside Catalyx */ @CatalyxModuleContainer(Reference.MODID, Reference.MODID) object CatalyxInternalModuleContainer { const val MODULE_CORE = "core" - const val MODULE_INTERNAL = "internal" + const val MODULE_COMMON = "common" const val MODULE_TEST = "test" const val MODULE_INTEGRATION = "integration" diff --git a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt b/src/main/kotlin/org/ender_development/catalyx/modules/common/CommonModule.kt similarity index 67% rename from src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt rename to src/main/kotlin/org/ender_development/catalyx/modules/common/CommonModule.kt index b642192..12af3e7 100644 --- a/src/main/kotlin/org/ender_development/catalyx/modules/internal/InternalModule.kt +++ b/src/main/kotlin/org/ender_development/catalyx/modules/common/CommonModule.kt @@ -1,4 +1,4 @@ -package org.ender_development.catalyx.modules.internal +package org.ender_development.catalyx.modules.common import org.ender_development.catalyx.Catalyx import org.ender_development.catalyx.api.v1.common.extensions.subLogger @@ -8,14 +8,13 @@ import org.ender_development.catalyx.core.Reference import org.ender_development.catalyx.core.items.CopyPasteTool import org.ender_development.catalyx.modules.CatalyxInternalModuleContainer -// TODO rename, this name is silly, but couldn't come up with a better one right meow @CatalyxModule( - moduleId = CatalyxInternalModuleContainer.MODULE_INTERNAL, + moduleId = CatalyxInternalModuleContainer.MODULE_COMMON, containerId = Reference.MODID, - name = "Internal", - description = "An internal module for Catalyx, used for stuff that can can be used in all mods that use Catalyx." + name = "Common", + description = "The default module for Catalyx, used for stuff that can can be used in all mods that use Catalyx." ) -class InternalModule() : ICatalyxModule { +class CommonModule() : ICatalyxModule { override val logger = Catalyx.LOGGER.subLogger("Internal") val copyPasteTool = CopyPasteTool() From 98e8986ab33531b8595cb45a078935187acab7a5 Mon Sep 17 00:00:00 2001 From: MasterEnderman Date: Thu, 26 Feb 2026 15:58:00 +0100 Subject: [PATCH 58/58] refactor config helpers --- .../catalyx/core/common/config/ConfigEntry.kt | 74 ++++++ .../core/common/config/ConfigHandler.kt | 47 ++++ .../catalyx/core/config/ConfigHandler.kt | 46 ---- .../catalyx/core/config/ConfigParser.kt | 230 ------------------ 4 files changed, 121 insertions(+), 276 deletions(-) create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/common/config/ConfigEntry.kt create mode 100644 src/main/kotlin/org/ender_development/catalyx/core/common/config/ConfigHandler.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt delete mode 100644 src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt diff --git a/src/main/kotlin/org/ender_development/catalyx/core/common/config/ConfigEntry.kt b/src/main/kotlin/org/ender_development/catalyx/core/common/config/ConfigEntry.kt new file mode 100644 index 0000000..b6ebb7f --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/common/config/ConfigEntry.kt @@ -0,0 +1,74 @@ +package org.ender_development.catalyx.core.common.config + +import net.minecraft.block.Block +import net.minecraft.block.state.IBlockState +import net.minecraft.item.Item +import net.minecraft.item.ItemStack +import org.ender_development.catalyx.api.v1.common.extensions.toBlock +import org.ender_development.catalyx.api.v1.common.extensions.toBlockState +import org.ender_development.catalyx.api.v1.common.extensions.toItem +import org.ender_development.catalyx.api.v1.common.extensions.toStack +import java.util.Objects + +open class GenericConfigEntry { + companion object { + const val IGNORE_META = -1 + } + + val mod: String + val id: String + val meta: Int + val value: T? + + val item: Item? + get() = "$mod:$id".toItem() + + val itemStack: ItemStack + get() = "$mod:$id".toStack(meta = meta) + + val block: Block? + get() = "$mod:$id".toBlock() + + val blockState: IBlockState? + get() = "$mod:$id".toBlockState(if(meta == IGNORE_META) 0 else meta) + + constructor(input: String, parser: (String) -> T) { + var split = input.split(";") + if(split.size > 2) + error("Invalid Config Entry: $input") + value = if(split.size == 2) + parser.invoke(split[1]) + else + null + split = split[0].split(":") + if(split.size !in 2..3) + error("Invalid Config Entry: $input") + mod = split[0] + id = split[1] + meta = if(split.size != 3 || split[2] == "-1") + IGNORE_META + else + split[2].toInt() + } + + override fun equals(other: Any?): Boolean { + return when (other) { + is Item -> other == item + is ItemStack -> if(meta == IGNORE_META) + other.isItemEqualIgnoreDurability(itemStack) + else + other.isItemEqual(itemStack) + is Block -> other == block + is IBlockState -> other == blockState + else -> this === other + } + } + + override fun hashCode(): Int = + Objects.hash(mod, id, meta, value) +} + +class ConfigEntry(input: String) : GenericConfigEntry(input, String::toString) +class ConfigEntryWithInt(input: String) : GenericConfigEntry(input, String::toInt) +class ConfigEntryWithFloat(input: String) : GenericConfigEntry(input, String::toFloat) +class ConfigEntryWithBoolean(input: String) : GenericConfigEntry(input, String::toBoolean) diff --git a/src/main/kotlin/org/ender_development/catalyx/core/common/config/ConfigHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/common/config/ConfigHandler.kt new file mode 100644 index 0000000..618d944 --- /dev/null +++ b/src/main/kotlin/org/ender_development/catalyx/core/common/config/ConfigHandler.kt @@ -0,0 +1,47 @@ +package org.ender_development.catalyx.core.common.config + +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.item.ItemStack +import org.ender_development.catalyx.Catalyx + +class ConfigHandler>(configData: Iterable, parser: (String) -> T) { + private val configEntries = try { + configData.map { parser } + } catch (e: Exception) { + Catalyx.LOGGER.error("Error parsing config data", e) + emptyList() + } + + /** + * Check if the list contains the given input. + * @param stack The object to check. + * @return True if the list contains the item stack, false otherwise. + */ + fun contains(stack: Any) = + configEntries.any { it == stack } + + /** + * Check if the player has any of the entries in the list equipped. + * @param player The player to check. + * @return True if the player has any of the entries equipped, false otherwise. + */ + fun equipped(player: EntityPlayer) = + player.equipmentAndArmor.any(::contains) + + /** + * Get the first equipped config entry that matches any of the entries in the list. + * @param player The player to check. + * @return The first matching entry, or null if none found. + */ + fun getEquipped(player: EntityPlayer) = + player.equipmentAndArmor.firstOrNull(::contains)?.let(::get) + + /** + * Get the first config entry in the list that matches the given item stack. + * @param stack The item stack to check. + * @return The first matching entry, or null if none found. + */ + operator fun get(stack: ItemStack) = + configEntries.firstOrNull { it == stack } + +} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt deleted file mode 100644 index c5ca6a8..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigHandler.kt +++ /dev/null @@ -1,46 +0,0 @@ -package org.ender_development.catalyx.core.config - -import net.minecraft.entity.player.EntityPlayer -import net.minecraft.item.ItemStack -import org.ender_development.catalyx.Catalyx - -class ConfigHandler(configData: Iterable, parser: (String) -> T) { - private val configItems = try { - configData.map(parser) - } catch(e: Exception) { - Catalyx.LOGGER.error("Error parsing config data", e) - emptyList() - } - - /** - * Check if the list contains the given item stack. - * @param stack The item stack to check. - * @return True if the list contains the item stack, false otherwise. - */ - fun contains(stack: ItemStack) = - configItems.any { it == stack } - - /** - * Check if the player has any of the items in the list equipped. - * @param player The player to check. - * @return True if the player has any of the items equipped, false otherwise. - */ - fun equipped(player: EntityPlayer) = - player.equipmentAndArmor.any(::contains) - - /** - * Get the first equipped config item that matches any of the items in the list. - * @param player The player to check. - * @return The first matching ConfigItem, or null if none found. - */ - fun getEquipped(player: EntityPlayer) = - player.equipmentAndArmor.firstOrNull(::contains)?.let(::get) - - /** - * Get the first config item in the list that matches the given item stack. - * @param stack The item stack to check. - * @return The first matching ConfigItem, or null if none found. - */ - operator fun get(stack: ItemStack) = - configItems.firstOrNull { it == stack } -} diff --git a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt b/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt deleted file mode 100644 index 537b5c3..0000000 --- a/src/main/kotlin/org/ender_development/catalyx/core/config/ConfigParser.kt +++ /dev/null @@ -1,230 +0,0 @@ -package org.ender_development.catalyx.core.config - -import net.minecraft.block.Block -import net.minecraft.block.state.IBlockState -import net.minecraft.item.Item -import net.minecraft.item.ItemStack -import net.minecraft.util.ResourceLocation -import org.ender_development.catalyx.api.v1.common.extensions.modLoaded -import org.ender_development.catalyx.core.config.ConfigParser.ConfigBlockState.Companion.IGNORE_META -import java.util.* - -/** - * Utility object for parsing configuration strings into different representations. - * - * This object provides classes to handle items with different configurations, - * including those with additional values. - */ -object ConfigParser { - open class ConfigItemStack { - companion object { - internal const val IGNORE_META = -1 - } - - protected var modId: String? = null - protected var itemId: String? = null - protected var item: Item? = null - protected var meta: Int = IGNORE_META - - /* - * Default constructor for ConfigItem. - * It initializes the object without any specific configuration. - * Use the constructor with a config string for actual item configuration. - * Parsing and validation need to be done in the specific constructors. - */ - constructor() - - /** - * Constructor that takes a configuration string in the format "modid:item:meta" or "modid:item". - * The meta value is optional and defaults to -1 if not provided. - * Should be used if config consists of a single item or list of items. - * - * @param configString The configuration string to parse. - */ - constructor(configString: String) { - parseConfigString(configString) - validateConfigItem() - } - - override fun equals(other: Any?) = - when(other) { - is ItemStack -> - if(meta == IGNORE_META) - other.isItemEqualIgnoreDurability(toItemStack()) - else - other.isItemEqual(toItemStack()) - is ConfigItemStack -> modId == other.modId && itemId == other.itemId && meta == other.meta - else -> this === other - } - - open fun toItemStack() = - ItemStack(item ?: throw NullPointerException("Item not found: $modId:$itemId"), 1, meta) - - protected fun parseConfigString(configString: String) { - val parts = configString.split(":") - if(parts.size != 2 && parts.size != 3) - throw IllegalArgumentException("Invalid config string format: $configString") - - modId = parts[0] - itemId = parts[1] - if(parts.size == 3) - meta = parts[2].toInt() - - item = Item.getByNameOrId("$modId:$itemId") // check this in validateConfigItem? - } - - protected fun validateConfigItem() { - if(modId == null || itemId == null) - throw IllegalArgumentException("Mod ID and item name cannot be null") - - if(!modId.modLoaded()) - throw IllegalArgumentException("Mod ID is not loaded: $modId") - - if(meta < IGNORE_META) - throw IllegalArgumentException("Meta value cannot be negative") - } - - override fun hashCode() = - Objects.hash(modId, itemId, meta) - } - - /** - * Constructor that takes a configuration string in the format "modid:item:meta;value". - * - * @param configString The configuration string to parse. - * @param parser The parser with which the value should be parsed to produce the expected value - */ - open class ConfigItemStackWith(configString: String, parser: (String) -> T) : ConfigItemStack() { - val value: T - - init { - val parts = configString.split(';', ',') - if(parts.size != 2) - throw IllegalArgumentException("Invalid config string format: $configString") - - parseConfigString(parts[0]) - validateConfigItem() - value = parser(parts[1]) - } - } - - /** - * Constructor that takes a configuration string in the format "modid:item:meta;value". - * - * @param configString The configuration string to parse. - */ - class ConfigItemStackWithFloat(configString: String) : ConfigItemStackWith(configString, String::toFloat) - - /** - * Constructor that takes a configuration string in the format "modid:item:meta;value". - * - * @param configString The configuration string to parse. - */ - class ConfigItemStackWithInt(configString: String) : ConfigItemStackWith(configString, String::toInt) - - /** - * Constructor that takes a configuration string in the format "modid:item:meta;value". - * - * @param configString The configuration string to parse. - */ - class ConfigItemStackWithBoolean(configString: String) : ConfigItemStackWith(configString, String::toBoolean) - - open class ConfigBlockState() { - companion object { - internal const val IGNORE_META = -1 - } - - protected var modId: String? = null - protected var blockId: String? = null - protected var meta: Int = IGNORE_META - - open val block: Block? // my IJ might say this (v) is an error, but this is actually allowed by default since Kotlin 2.3 - get() = Block.REGISTRY.registryObjects[ResourceLocation(modId ?: return null, blockId ?: return null)] - - open val state: IBlockState? - @Suppress("DEPRECATION") - get() = block?.getStateFromMeta(if(meta == IGNORE_META) 0 else meta) - - /** - * Constructor that takes a configuration string in the format "modId:blockId:meta" or "modId:blockId" - * Meta defaults to [IGNORE_META] if not set - * Should be used if config consists of a single block or list of blocks. - * - * @param configString The configuration string to parse. - */ - constructor(configString: String) : this() { - parseConfigString(configString) - validate() - } - - override fun equals(other: Any?) = - when { - this === other -> true - other is IBlockState -> block === other.block && (meta == IGNORE_META || block?.getMetaFromState(other) == meta) - other is ConfigBlockState -> modId == other.modId && blockId == other.blockId && meta == other.meta - else -> false - } - - override fun hashCode() = - Objects.hash(modId, blockId, meta) - - open fun parseConfigString(configString: String) { - val parts = configString.split(":") - if(parts.size != 2 && parts.size != 3) - error("Invalid config string format: '$configString'") - - modId = parts[0] - blockId = parts[1] - if(parts.size == 3) - meta = parts[2].toInt() - } - - open fun validate() { - if(modId == null || blockId == null) - error("Mod Id and Block Id cannot be null") - - if(!modId.modLoaded()) - error("Mod ID is not loaded: $modId") - - if(meta < IGNORE_META) - error("Meta value cannot be negative") - } - } - - /** - * Helper class - * - * @param configString The configuration string to parse in the format "modId:blockId:meta;value" - * @param optional Whether the argument is optional or not - * @param parser The parser with which the value should be parsed to produce the expected value - */ - open class ConfigBlockStateWith(configString: String, optional: Boolean, parser: (String) -> T) : ConfigBlockState() { - /** - * Only nullable when [optional] is true - */ - val value: T? - - init { - val parts = configString.split(';', ',') - if(parts.size == 2) { - parseConfigString(parts[0]) - value = parser(parts[1]) - } else { - if(!optional) - error("Invalid config string format: '$configString'") - else { - parseConfigString(configString) - value = null - } - } - validate() - } - } - - class ConfigBlockStateWithInt(configString: String, optional: Boolean) : ConfigBlockStateWith(configString, optional, String::toInt) - - class ConfigBlockStateWithFloat(configString: String, optional: Boolean) : ConfigBlockStateWith(configString, optional, String::toFloat) - - class ConfigBlockStateWithBoolean(configString: String, optional: Boolean) : ConfigBlockStateWith(configString, optional, String::toBoolean) -} -