Skip to content

Commit

Permalink
v0.1.3-alpha
Browse files Browse the repository at this point in the history
- Machines configuration
  • Loading branch information
dedztbh committed Aug 7, 2019
1 parent a7189f2 commit e74365e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 33 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Useful Keybindings:

Config:
- explosionDoAffectSelf: Explosion Do Affect Creator
- Machines: machines configuration


Localizations:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/dedztbh/demagica/DEMagica.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
48 changes: 33 additions & 15 deletions src/main/kotlin/com/dedztbh/demagica/global/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
5 changes: 0 additions & 5 deletions src/main/kotlin/com/dedztbh/demagica/proxy/ClientProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,10 +18,6 @@ class ClientProxy : CommonProxy() {
keyBindings.forEach(ClientRegistry::registerKeyBinding)
}

override fun preInit(e: FMLPreInitializationEvent) {
super.preInit(e)
}

companion object {
@JvmStatic
@SubscribeEvent
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/dedztbh/demagica/proxy/CommonProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit e74365e

Please sign in to comment.