mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-25 06:24:21 +00:00
reworked OutputConfig &co to be easier to extend
This commit is contained in:
1 parent
02850b9f85
commit
300726e660
4 files changed
+15
-11
No files matched your search
@@ -23,12 +23,7 @@ case class DataSlotOutputConfig(name: String, parent: TileDataSlots, slots: Int)
|
||||
for ((n, x) <- map) {
|
||||
val tmp = new NBTTagCompound()
|
||||
x.write(tmp)
|
||||
val kind = x match {
|
||||
case _: OutputConfigPower => "power"
|
||||
case _: OutputConfigFluid => "fluid"
|
||||
case _ => sys.error("Unknown output config kind: " + x)
|
||||
}
|
||||
tmp.setString("kind", kind)
|
||||
tmp.setString("kind", x.id)
|
||||
t.setTag(name + "_" + n, tmp)
|
||||
}
|
||||
}
|
||||
@@ -38,11 +33,7 @@ case class DataSlotOutputConfig(name: String, parent: TileDataSlots, slots: Int)
|
||||
for (i <- 0 until slots) {
|
||||
if (t.hasKey(name + "_" + i)) {
|
||||
val cfg = t.getCompoundTag(name + "_" + i)
|
||||
val cfgObj = cfg.getString("kind") match {
|
||||
case "power" => new OutputConfigPower
|
||||
case "fluid" => new OutputConfigFluid
|
||||
case _ => new OutputConfigInvalid
|
||||
}
|
||||
val cfgObj = OutputConfigManager.create(cfg.getString("kind"))
|
||||
cfgObj.read(cfg)
|
||||
map += i -> cfgObj
|
||||
}
|
||||
|
||||
@@ -14,13 +14,24 @@ import net.minecraft.nbt.NBTTagCompound
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
||||
|
||||
abstract class OutputConfig {
|
||||
def id: String
|
||||
def read(t: NBTTagCompound)
|
||||
def write(t: NBTTagCompound)
|
||||
def handleConfigPacket(m: MsgOutputCfg)
|
||||
}
|
||||
|
||||
class OutputConfigInvalid extends OutputConfig {
|
||||
override val id: String = "invalid"
|
||||
def read(t: NBTTagCompound) {}
|
||||
def write(t: NBTTagCompound) = throw new NotImplementedException
|
||||
def handleConfigPacket(m: MsgOutputCfg) = throw new NotImplementedException
|
||||
}
|
||||
|
||||
object OutputConfigManager {
|
||||
var loaders = Map.empty[String, () => OutputConfig]
|
||||
def register(id: String, loader: () => OutputConfig) = loaders += id -> loader
|
||||
def create(id: String) = loaders.get(id).map(_.apply()).getOrElse(new OutputConfigInvalid)
|
||||
|
||||
register("fluid", () => new OutputConfigFluid)
|
||||
register("power", () => new OutputConfigPower)
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import net.bdew.lib.multiblock.network.MsgOutputCfg
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
class OutputConfigFluid extends OutputConfig with OutputConfigRSControllable {
|
||||
override def id = "fluid"
|
||||
var avg = 0.0
|
||||
var rsMode = RSMode.ALWAYS
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.bdew.lib.multiblock.network.MsgOutputCfg
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
class OutputConfigPower(var unit: String = "MJ") extends OutputConfig with OutputConfigRSControllable {
|
||||
override val id = "power"
|
||||
var avg = 0.0
|
||||
var rsMode = RSMode.ALWAYS
|
||||
|
||||
|
||||
Reference in new issue
Block a user