From e74365e4d7a9a59a93f595ee1993d7cf52165dfb Mon Sep 17 00:00:00 2001 From: DEDZTBH Date: Wed, 7 Aug 2019 17:41:05 +0800 Subject: [PATCH] v0.1.3-alpha - Machines configuration --- README.md | 1 + build.gradle | 2 +- .../kotlin/com/dedztbh/demagica/DEMagica.kt | 2 +- .../tileEntities/BlockMagicTileEntity.kt | 17 +++---- .../com/dedztbh/demagica/global/Config.kt | 48 +++++++++++++------ .../com/dedztbh/demagica/proxy/ClientProxy.kt | 5 -- .../com/dedztbh/demagica/proxy/CommonProxy.kt | 2 +- 7 files changed, 44 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 80d20a8..bb29bc2 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Useful Keybindings: Config: - explosionDoAffectSelf: Explosion Do Affect Creator +- Machines: machines configuration Localizations: diff --git a/build.gradle b/build.gradle index 9b18964..16dec9d 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ allOpen { annotation("com.dedztbh.demagica.util.Open") } -version = "0.1.2-alpha" +version = "0.1.3-alpha" group = "com.dedztbh.demagica" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "demagica" diff --git a/src/main/kotlin/com/dedztbh/demagica/DEMagica.kt b/src/main/kotlin/com/dedztbh/demagica/DEMagica.kt index 570e114..e80408d 100644 --- a/src/main/kotlin/com/dedztbh/demagica/DEMagica.kt +++ b/src/main/kotlin/com/dedztbh/demagica/DEMagica.kt @@ -17,7 +17,7 @@ class DEMagica { companion object { const val MODID = "demagica" const val NAME = "DEMagica" - const val VERSION = "0.1.2-alpha" + const val VERSION = "0.1.3-alpha" @JvmStatic lateinit var logger: Logger diff --git a/src/main/kotlin/com/dedztbh/demagica/blocks/tileEntities/BlockMagicTileEntity.kt b/src/main/kotlin/com/dedztbh/demagica/blocks/tileEntities/BlockMagicTileEntity.kt index 8b6d5c1..c09d87f 100644 --- a/src/main/kotlin/com/dedztbh/demagica/blocks/tileEntities/BlockMagicTileEntity.kt +++ b/src/main/kotlin/com/dedztbh/demagica/blocks/tileEntities/BlockMagicTileEntity.kt @@ -4,6 +4,10 @@ import cofh.redstoneflux.api.IEnergyProvider import cofh.redstoneflux.api.IEnergyReceiver import cofh.redstoneflux.impl.EnergyStorage import com.dedztbh.demagica.blocks.BlockMagic +import com.dedztbh.demagica.global.Config.BATTERY_RF_CAPACITY +import com.dedztbh.demagica.global.Config.MB_CONSUMED +import com.dedztbh.demagica.global.Config.RF_GENERATED +import com.dedztbh.demagica.global.Config.TANK_MB_CAPACITY import com.dedztbh.demagica.util.TickTaskManager import com.dedztbh.demagica.util.isLocal import com.dedztbh.demagica.util.oppositeBlockPosAndEnumFacings @@ -30,13 +34,6 @@ import net.minecraftforge.items.CapabilityItemHandler import net.minecraftforge.items.IItemHandlerModifiable import net.minecraftforge.items.ItemStackHandler -const val BATTERY_RF_CAPACITY = 64000 -const val TANK_MB_CAPACITY = 16000 -const val MB_CONSUMED = 50 -const val RF_GENERATED = 50 -const val CONVERT_TICKS = 1 -const val STORAGE_SIZE = 1 - class BlockMagicTileEntity : TileEntity(), IFluidHandler, @@ -79,7 +76,7 @@ class BlockMagicTileEntity : override fun canFillFluidType(fluid: FluidStack): Boolean = fluid.fluid.name == "steam" } private val battery = EnergyStorage(BATTERY_RF_CAPACITY) - private val storage = ItemStackHandler(STORAGE_SIZE) + private val storage = ItemStackHandler(1) //IEnergyProvider @@ -140,14 +137,14 @@ class BlockMagicTileEntity : var lastOutputRate = 0 private val taskManager = TickTaskManager().apply { - runTask(CONVERT_TICKS.toLong(), repeat = true, startNow = true, isEvery = true) { + runTask(1L, repeat = true, startNow = true, isEvery = true) { if (steamTank.drain(MB_CONSUMED, false)?.amount == MB_CONSUMED && battery.receiveEnergy(RF_GENERATED, true) == RF_GENERATED) { //have enough steam and tank has enough space, can convert steamTank.drain(MB_CONSUMED, true) battery.receiveEnergy(RF_GENERATED, false) dirtyFlag = true - RF_GENERATED.toDouble() / CONVERT_TICKS + RF_GENERATED.toDouble() } else { 0.0 }.also { diff --git a/src/main/kotlin/com/dedztbh/demagica/global/Config.kt b/src/main/kotlin/com/dedztbh/demagica/global/Config.kt index 2a96329..591aeea 100644 --- a/src/main/kotlin/com/dedztbh/demagica/global/Config.kt +++ b/src/main/kotlin/com/dedztbh/demagica/global/Config.kt @@ -8,34 +8,52 @@ import org.apache.logging.log4j.Level object Config { // This values below you can access elsewhere in your mod: var explosionDoAffectSelf = false + var BATTERY_RF_CAPACITY = 64000 + var TANK_MB_CAPACITY = 16000 + var MB_CONSUMED = 50 + var RF_GENERATED = 50 private val CATEGORY_GENERAL = "general" + private val CATEGORY_MACHINES = "machines" private val CATEGORY_DIMENSIONS = "dimensions" // Call this from CommonProxy.preInit(). It will create our global if it doesn't // exist yet and read the values if it does exist. fun readConfig() { - val cfg = CommonProxy.config - try { - cfg.load() - initGeneralConfig(cfg) - initDimensionConfig(cfg) - } catch (e1: Exception) { - DEMagica.logger.log(Level.ERROR, "Problem loading global file!", e1) - } finally { - if (cfg.hasChanged()) { - cfg.save() + CommonProxy.config.run { + try { + load() + initGeneralConfig() + initMachineConfig() + initDimensionConfig() + } catch (e1: Exception) { + DEMagica.logger.log(Level.ERROR, "Problem loading global file!", e1) + } finally { + if (hasChanged()) { + save() + } } } } - private fun initGeneralConfig(cfg: Configuration) { - cfg.addCustomCategoryComment(CATEGORY_GENERAL, "General configuration") - explosionDoAffectSelf = cfg.getBoolean("explosionDoAffectSelf", CATEGORY_GENERAL, explosionDoAffectSelf, "Explosion Do Affect Creator") + private fun Configuration.initGeneralConfig() { + addCustomCategoryComment(CATEGORY_GENERAL, "General configuration") + explosionDoAffectSelf = getBoolean("explosionDoAffectSelf", CATEGORY_GENERAL, explosionDoAffectSelf, "Explosion Do Affect Creator") } - private fun initDimensionConfig(cfg: Configuration) { - cfg.addCustomCategoryComment(CATEGORY_DIMENSIONS, "Dimension configuration") + private fun Configuration.initMachineConfig() { + addCustomCategoryComment(CATEGORY_MACHINES, "Machine configuration") + BATTERY_RF_CAPACITY = getInt("BATTERY_RF_CAPACITY", CATEGORY_MACHINES, BATTERY_RF_CAPACITY, "How much RF magic block holds") + TANK_MB_CAPACITY = getInt("TANK_MB_CAPACITY", CATEGORY_MACHINES, TANK_MB_CAPACITY, "How much mB of steam magic block holds") + MB_CONSUMED = getInt("MB_CONSUMED", CATEGORY_MACHINES, MB_CONSUMED, "How much mB of steam consumed per tick") + RF_GENERATED = getInt("RF_GENERATED", CATEGORY_MACHINES, RF_GENERATED, "How much RF generated per tick") + } + + private fun Configuration.initDimensionConfig() { + addCustomCategoryComment(CATEGORY_DIMENSIONS, "Dimension configuration") + } + private fun Configuration.getInt(name: String, category: String, defaultValue: Int, comment: String): Int { + return getInt(name, category, defaultValue, 0, Int.MAX_VALUE, comment) } } \ No newline at end of file diff --git a/src/main/kotlin/com/dedztbh/demagica/proxy/ClientProxy.kt b/src/main/kotlin/com/dedztbh/demagica/proxy/ClientProxy.kt index 637c1b1..2f807c0 100644 --- a/src/main/kotlin/com/dedztbh/demagica/proxy/ClientProxy.kt +++ b/src/main/kotlin/com/dedztbh/demagica/proxy/ClientProxy.kt @@ -7,7 +7,6 @@ import net.minecraftforge.client.event.ModelRegistryEvent import net.minecraftforge.fml.client.registry.ClientRegistry import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.relauncher.Side import org.lwjgl.input.Keyboard @@ -19,10 +18,6 @@ class ClientProxy : CommonProxy() { keyBindings.forEach(ClientRegistry::registerKeyBinding) } - override fun preInit(e: FMLPreInitializationEvent) { - super.preInit(e) - } - companion object { @JvmStatic @SubscribeEvent diff --git a/src/main/kotlin/com/dedztbh/demagica/proxy/CommonProxy.kt b/src/main/kotlin/com/dedztbh/demagica/proxy/CommonProxy.kt index cf64b08..65b14d4 100644 --- a/src/main/kotlin/com/dedztbh/demagica/proxy/CommonProxy.kt +++ b/src/main/kotlin/com/dedztbh/demagica/proxy/CommonProxy.kt @@ -59,7 +59,7 @@ class CommonProxy { } fun preInit(e: FMLPreInitializationEvent) { - val directory = e.modConfigurationDirectory + val directory: File = e.modConfigurationDirectory config = Configuration(File(directory.path, "demagica.cfg")) Config.readConfig()