Refactored output config for multiblocks, added config object for fluid outputs

This commit is contained in:
bdew committed 2014-09-02 14:10:36 +03:00
1 parent f593458511
commit 64683a0208
8 files changed
+89 -18

No files matched your search

+1 -1
View File
@@ -1 +1 @@
rootProject.name='bdlib'
rootProject.name = 'bdlib'
@@ -39,7 +39,7 @@ case class DataSlotOutputConfig(name: String, parent: TileDataSlots, slots: Int)
val cfg = t.getCompoundTag(name + "_" + i)
val cfgObj = cfg.getString("kind") match {
case "power" => new OutputConfigPower
case x => new OutputConfigInvalid
case _ => new OutputConfigInvalid
}
cfgObj.read(cfg)
map += i -> cfgObj
@@ -0,0 +1,41 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.multiblock.data
import net.bdew.lib.multiblock.network.MsgOutputCfg
import net.minecraft.nbt.NBTTagCompound
case class MsgOutputCfgFluid(output: Int, rsMode: RSMode.Value) extends MsgOutputCfg
class OutputConfigFluid extends OutputConfig with OutputConfigRSControllable {
var avg = 0.0
var rsMode = RSMode.ALWAYS
final val decay = 0.5
def updateAvg(v: Double) {
avg = avg * decay + (1 - decay) * v
}
def read(t: NBTTagCompound) {
avg = t.getDouble("avg")
rsMode = RSMode(t.getInteger("rsMode"))
}
def write(t: NBTTagCompound) {
t.setDouble("avg", avg)
t.setInteger("rsMode", rsMode.id)
}
def handleConfigPacket(m: MsgOutputCfg) = m match {
case MsgOutputCfgFluid(_, r) => rsMode = r
case _ => sys.error("Invalid output config packet %s to config %s".format(m, this))
}
}
@@ -19,6 +19,10 @@ abstract class OutputConfig {
def handleConfigPacket(m: MsgOutputCfg)
}
trait OutputConfigRSControllable {
var rsMode: RSMode.Value
}
class OutputConfigInvalid extends OutputConfig {
def read(t: NBTTagCompound) {}
def write(t: NBTTagCompound) = throw new NotImplementedException
@@ -14,10 +14,9 @@ import net.minecraft.nbt.NBTTagCompound
case class MsgOutputCfgPower(output: Int, rsMode: RSMode.Value) extends MsgOutputCfg
class OutputConfigPower extends OutputConfig {
class OutputConfigPower(var unit: String = "MJ") extends OutputConfig with OutputConfigRSControllable {
var avg = 0.0
var rsMode = RSMode.ALWAYS
var unit = "MJ"
final val decay = 0.5
@@ -0,0 +1,19 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.multiblock.interact
import net.minecraftforge.fluids.{Fluid, FluidStack, FluidTankInfo}
trait CIFluidOutput extends CIOutputFaces {
def outputFluid(resource: FluidStack, doDrain: Boolean): FluidStack
def outputFluid(ammount: Int, doDrain: Boolean): FluidStack
def canOutputFluid(fluid: Fluid): Boolean
def getTankInfo: Array[FluidTankInfo]
}
@@ -0,0 +1,20 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.multiblock.tile
import net.bdew.lib.multiblock.data.{OutputConfigRSControllable, RSMode}
trait RSControllableOutput extends TileOutput {
def checkCanOutput(cfg: OutputConfigRSControllable): Boolean = {
if (cfg.rsMode == RSMode.ALWAYS) return true
if (cfg.rsMode == RSMode.NEVER) return false
return getWorldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) ^ (cfg.rsMode == RSMode.RS_OFF)
}
}
@@ -9,26 +9,14 @@
package net.bdew.lib.multiblock.tile
import net.bdew.lib.multiblock.data.{OutputConfigPower, RSMode}
import net.bdew.lib.multiblock.data.OutputConfig
import net.bdew.lib.multiblock.interact.{CIOutputFaces, MIOutput}
import net.minecraftforge.common.util.ForgeDirection
abstract class TileOutput extends TileModule with MIOutput {
val unit: String
override def getCore = getCoreAs[CIOutputFaces]
def checkCanOutput(cfg: OutputConfigPower): Boolean = {
if (cfg.rsMode == RSMode.ALWAYS) return true
if (cfg.rsMode == RSMode.NEVER) return false
return worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) ^ (cfg.rsMode == RSMode.RS_OFF)
}
def makeCfgObject(face: ForgeDirection) = {
val cfg = new OutputConfigPower
cfg.unit = unit
cfg
}
def makeCfgObject(face: ForgeDirection): OutputConfig
var rescanFaces = false