mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-12 16:27:51 +00:00
Refactoring multiblock outputs, TileOutput (&co) now has a type parameter for config object type
This commit is contained in:
1 parent
2a7bbaeb97
commit
5a9aedb4d5
6 files changed
+30
-14
No files matched your search
@@ -15,7 +15,7 @@ import net.bdew.lib.render.connected.{BlockAdditionalRender, ConnectedHelper, Fa
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
trait BlockOutput[T <: TileOutput] extends BlockModule[T] with BlockAdditionalRender {
|
||||
trait BlockOutput[T <: TileOutput[_]] extends BlockModule[T] with BlockAdditionalRender {
|
||||
def getAdjancedFaces(face: ForgeDirection, bp: BlockRef) = {
|
||||
val sides = ConnectedHelper.faceAdjanced(face)
|
||||
Seq(
|
||||
|
||||
@@ -19,7 +19,7 @@ abstract class OutputConfig {
|
||||
def handleConfigPacket(m: MsgOutputCfg)
|
||||
}
|
||||
|
||||
trait OutputConfigRSControllable {
|
||||
trait OutputConfigRSControllable extends OutputConfig {
|
||||
var rsMode: RSMode.Value
|
||||
}
|
||||
|
||||
|
||||
@@ -52,13 +52,13 @@ trait CIOutputFaces extends TileController {
|
||||
}
|
||||
|
||||
def doOutputs() {
|
||||
for ((x, n) <- outputFaces) {
|
||||
val t = x.origin.getTile[MIOutput](getWorldObj)
|
||||
if (t.isDefined) {
|
||||
if (!outputConfig.isDefinedAt(n) || outputConfig(n).isInstanceOf[OutputConfigInvalid])
|
||||
outputConfig(n) = t.get.makeCfgObject(x.face)
|
||||
t.get.doOutput(x.face, outputConfig(n))
|
||||
}
|
||||
for {
|
||||
(x, n) <- outputFaces
|
||||
t <- x.origin.getTile[MIOutput[_]](getWorldObj)
|
||||
} {
|
||||
if (!outputConfig.isDefinedAt(n) || !t.outputConfigType.isInstance(outputConfig(n)))
|
||||
outputConfig(n) = t.makeCfgObject(x.face)
|
||||
t.doOutput(x.face, outputConfig(n).asInstanceOf[t.OCType])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,16 @@
|
||||
|
||||
package net.bdew.lib.multiblock.interact
|
||||
|
||||
import net.bdew.lib.BdLib
|
||||
import net.bdew.lib.multiblock.data.OutputConfig
|
||||
import net.bdew.lib.multiblock.tile.TileModule
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
trait MIOutput extends TileModule {
|
||||
def doOutput(face: ForgeDirection, cfg: OutputConfig)
|
||||
trait MIOutput[T <: OutputConfig] extends TileModule {
|
||||
val outputConfigType: Class[T]
|
||||
type OCType = T
|
||||
|
||||
def doOutput(face: ForgeDirection, cfg: OCType)
|
||||
|
||||
def makeCfgObject(face: ForgeDirection): OutputConfig
|
||||
}
|
||||
@@ -10,8 +10,9 @@
|
||||
package net.bdew.lib.multiblock.tile
|
||||
|
||||
import net.bdew.lib.multiblock.data.{OutputConfigRSControllable, RSMode}
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
trait RSControllableOutput extends TileOutput {
|
||||
trait RSControllableOutput extends TileEntity {
|
||||
def checkCanOutput(cfg: OutputConfigRSControllable): Boolean = {
|
||||
if (cfg.rsMode == RSMode.ALWAYS) return true
|
||||
if (cfg.rsMode == RSMode.NEVER) return false
|
||||
|
||||
@@ -9,17 +9,27 @@
|
||||
|
||||
package net.bdew.lib.multiblock.tile
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.BlockFace
|
||||
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 {
|
||||
abstract class TileOutput[T <: OutputConfig] extends TileModule with MIOutput[T] {
|
||||
override def getCore = getCoreAs[CIOutputFaces]
|
||||
|
||||
def makeCfgObject(face: ForgeDirection): OutputConfig
|
||||
def makeCfgObject(face: ForgeDirection): T
|
||||
|
||||
var rescanFaces = false
|
||||
|
||||
def getCfg(dir: ForgeDirection): Option[T] =
|
||||
for {
|
||||
core <- getCore
|
||||
onum <- core.outputFaces.get(BlockFace(mypos, dir))
|
||||
cfggen <- core.outputConfig.get(onum)
|
||||
cfg <- Misc.asInstanceOpt(cfggen, outputConfigType)
|
||||
} yield cfg
|
||||
|
||||
serverTick.listen(() => {
|
||||
if (rescanFaces) {
|
||||
rescanFaces = false
|
||||
|
||||
Reference in new issue
Block a user