mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-24 05:54:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3f8fb3c56 | ||
|
|
023ae4d77f | ||
|
|
b1e0e70fc4 | ||
|
|
5f01716310 | ||
|
|
0976fb4acc | ||
|
|
4effeafbb7 | ||
|
|
e0d3609e66 | ||
|
|
5a1c150a03 | ||
|
|
c5a7fc3d51 | ||
|
|
9787c4836e | ||
|
|
cd833163af | ||
|
|
5a9aedb4d5 | ||
|
|
2a7bbaeb97 | ||
|
|
58125ee291 | ||
|
|
d9cc8ace82 | ||
|
|
32617ff592 | ||
|
|
64683a0208 | ||
|
|
f593458511 |
No files matched your search
+1
-1
@@ -21,7 +21,7 @@ buildscript {
|
||||
apply plugin: 'scala'
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.4.3"
|
||||
version = "1.4.5"
|
||||
|
||||
if (project.hasProperty('buildnum')) {
|
||||
project.version = project.version + '.' + project.buildnum
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
bdlib.multiblock.face.north=北方
|
||||
bdlib.multiblock.face.south=南方
|
||||
bdlib.multiblock.face.east=东方
|
||||
bdlib.multiblock.face.west=西方
|
||||
bdlib.multiblock.face.up=顶部
|
||||
bdlib.multiblock.face.down=底部
|
||||
|
||||
bdlib.multiblock.disabled=停用
|
||||
bdlib.multiblock.incomplete=这台多方块结构机器未搭建完成, 它至少需要安装一个:
|
||||
bdlib.multiblock.notconnected=未连接有效机器
|
||||
bdlib.multiblock.toomanyoutputs=连接的输出接口过多, 无法连接新的接口
|
||||
|
||||
bdlib.rsmode.always=一直启用
|
||||
bdlib.rsmode.never=一直停用
|
||||
bdlib.rsmode.rs_on=接收到红石信号时启用
|
||||
bdlib.rsmode.rs_off=接收到红石信号时停用
|
||||
|
||||
bdlib.label.empty=空
|
||||
+1
-1
@@ -1 +1 @@
|
||||
rootProject.name='bdlib'
|
||||
rootProject.name = 'bdlib'
|
||||
@@ -11,7 +11,7 @@ package net.bdew.lib
|
||||
|
||||
import cpw.mods.fml.common.Mod
|
||||
import cpw.mods.fml.common.Mod.EventHandler
|
||||
import cpw.mods.fml.common.event.{FMLPreInitializationEvent, FMLServerStartingEvent}
|
||||
import cpw.mods.fml.common.event.{FMLPreInitializationEvent, FMLServerStartingEvent, FMLServerStoppingEvent}
|
||||
import net.bdew.lib.multiblock.network.NetHandler
|
||||
import net.minecraft.command.CommandHandler
|
||||
import org.apache.logging.log4j.Logger
|
||||
@@ -26,6 +26,9 @@ object BdLib {
|
||||
def logWarnException(msg: String, t: Throwable, args: Any*) = log.warn(msg.format(args: _*), t)
|
||||
def logErrorException(msg: String, t: Throwable, args: Any*) = log.error(msg.format(args: _*), t)
|
||||
|
||||
val onServerStarting = Event[FMLServerStartingEvent]
|
||||
val onServerStopping = Event[FMLServerStoppingEvent]
|
||||
|
||||
@EventHandler
|
||||
def preInit(ev: FMLPreInitializationEvent) {
|
||||
log = ev.getModLog
|
||||
@@ -37,5 +40,11 @@ object BdLib {
|
||||
def serverStarting(event: FMLServerStartingEvent) {
|
||||
val commandHandler = event.getServer.getCommandManager.asInstanceOf[CommandHandler]
|
||||
commandHandler.registerCommand(new CommandDumpRegistry)
|
||||
onServerStarting.trigger(event)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
def serverStopping(event: FMLServerStoppingEvent) {
|
||||
onServerStopping.trigger(event)
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,10 @@ object Misc {
|
||||
def asInstanceOpt[T](v: Any, cls: Class[T]) =
|
||||
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
|
||||
|
||||
// Same thing but in a way that's easier to use with map, etc.
|
||||
def asInstanceOpt[T](cls: Class[T])(v: Any) =
|
||||
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
|
||||
|
||||
def getNeighbourTile[T](origin: TileEntity, dir: ForgeDirection, cls: Class[T]) =
|
||||
Option(origin.getWorldObj.getTileEntity(origin.xCoord + dir.offsetX,
|
||||
origin.yCoord + dir.offsetY, origin.zCoord + dir.offsetZ)) flatMap (asInstanceOpt(_, cls))
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.data
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
|
||||
import net.bdew.lib.tile.inventory.BaseInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||
|
||||
case class DataSlotInventory(name: String, parent: TileDataSlots, size: Int) extends DataSlot with BaseInventory {
|
||||
setUpdate(UpdateKind.SAVE)
|
||||
|
||||
override def getSizeInventory = size
|
||||
override def markDirty() = parent.dataSlotChanged(this)
|
||||
|
||||
override def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
inv = new Array[ItemStack](getSizeInventory)
|
||||
for (nbtItem <- Misc.iterNbtCompoundList(t, name)) {
|
||||
val slot = nbtItem.getByte("Slot")
|
||||
if (slot >= 0 && slot < inv.size) {
|
||||
inv(slot) = ItemStack.loadItemStackFromNBT(nbtItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
val itemList = new NBTTagList
|
||||
for ((item, i) <- inv.view.zipWithIndex if item != null) {
|
||||
val itemNbt: NBTTagCompound = new NBTTagCompound
|
||||
itemNbt.setByte("Slot", i.asInstanceOf[Byte])
|
||||
item.writeToNBT(itemNbt)
|
||||
itemList.appendTag(itemNbt)
|
||||
}
|
||||
t.setTag(name, itemList)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
|
||||
|
||||
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
||||
|
||||
val sendCapacityOnUpdateKind = Set(UpdateKind.GUI)
|
||||
|
||||
def checkUpdate() {
|
||||
if (!isSame(oldStack, fluid)) {
|
||||
oldStack = if (fluid == null) null else fluid.copy()
|
||||
@@ -36,7 +38,7 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
|
||||
def save(t: NBTTagCompound, k: UpdateKind.Value) {
|
||||
val tag = new NBTTagCompound()
|
||||
writeToNBT(tag)
|
||||
if (k == UpdateKind.GUI)
|
||||
if (sendCapacityOnUpdateKind.contains(k))
|
||||
tag.setInteger("size", getCapacity)
|
||||
t.setTag(name, tag)
|
||||
}
|
||||
@@ -45,7 +47,7 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
|
||||
setFluid(null)
|
||||
val tag = t.getCompoundTag(name)
|
||||
readFromNBT(tag)
|
||||
if (k == UpdateKind.GUI)
|
||||
if (sendCapacityOnUpdateKind.contains(k))
|
||||
setCapacity(tag.getInteger("size"))
|
||||
}
|
||||
override def setFluid(fluid: FluidStack) = execWithChangeNotify(super.setFluid(fluid))
|
||||
|
||||
@@ -20,7 +20,7 @@ trait DrawTarget {
|
||||
def drawTextMultiline(text: String, r: Rect, color: Color)
|
||||
|
||||
def drawTextureInterpolate(r: Rect, t: Texture, x1: Float, y1: Float, x2: Float, y2: Float, color: Color = Color.white) =
|
||||
drawTexture(r.interpolate(x1, y1, x2, y2), Texture.interpolate(t, x1, y1, x2, y2))
|
||||
drawTexture(r.interpolate(x1, y1, x2, y2), Texture.interpolate(t, x1, y1, x2, y2), color)
|
||||
}
|
||||
|
||||
trait SimpleDrawTarget extends DrawTarget {
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.text.DecimalFormat
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.data.DataSlotTankBase
|
||||
import net.bdew.lib.gui.{Point, Rect, Texture}
|
||||
import net.bdew.lib.gui.{Color, Point, Rect, Texture}
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
import scala.collection.mutable
|
||||
@@ -39,19 +39,21 @@ class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase
|
||||
val icon = Texture(Texture.BLOCKS, fstack.getFluid.getStillIcon)
|
||||
var fillHeight = if (dslot.getCapacity > 0) rect.h * fstack.amount / dslot.getCapacity else 0
|
||||
var yStart: Int = 0
|
||||
val color = Color.fromInt(fstack.getFluid.getColor(fstack))
|
||||
|
||||
while (fillHeight > 0) {
|
||||
if (fillHeight > 16) {
|
||||
parent.drawTexture(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon)
|
||||
parent.drawTexture(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon, color)
|
||||
fillHeight -= 16
|
||||
} else {
|
||||
parent.drawTextureInterpolate(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon, 0, 1 - fillHeight / 16, 1, 1)
|
||||
parent.drawTextureInterpolate(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon, 0, 1 - fillHeight / 16, 1, 1, color)
|
||||
fillHeight = 0
|
||||
}
|
||||
yStart = yStart + 16
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glColor3d(1, 1, 1)
|
||||
GL11.glDisable(GL11.GL_BLEND)
|
||||
|
||||
parent.drawTexture(rect, overlay)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui._
|
||||
|
||||
case class WidgetSimpleIcon(rect: Rect, icon: Texture) extends Widget {
|
||||
override def draw(mouse: Point) = parent.drawTexture(rect, icon)
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
@@ -25,6 +25,7 @@ case class DataSlotOutputConfig(name: String, parent: TileDataSlots, slots: Int)
|
||||
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)
|
||||
@@ -39,7 +40,8 @@ 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 "fluid" => new OutputConfigFluid
|
||||
case _ => new OutputConfigInvalid
|
||||
}
|
||||
cfgObj.read(cfg)
|
||||
map += i -> cfgObj
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
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 MsgOutputCfgRSMode(_, r) => rsMode = r
|
||||
case _ => sys.error("Invalid output config packet %s to config %s".format(m, this))
|
||||
}
|
||||
}
|
||||
@@ -12,12 +12,9 @@ package net.bdew.lib.multiblock.data
|
||||
import net.bdew.lib.multiblock.network.MsgOutputCfg
|
||||
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
|
||||
|
||||
@@ -38,7 +35,7 @@ class OutputConfigPower extends OutputConfig {
|
||||
}
|
||||
|
||||
def handleConfigPacket(m: MsgOutputCfg) = m match {
|
||||
case MsgOutputCfgPower(_, r) => rsMode = r
|
||||
case MsgOutputCfgRSMode(_, r) => rsMode = r
|
||||
case _ => sys.error("Invalid output config packet %s to config %s".format(m, this))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
case class MsgOutputCfgRSMode(output: Int, rsMode: RSMode.Value) extends MsgOutputCfg
|
||||
|
||||
trait OutputConfigRSControllable extends OutputConfig {
|
||||
var rsMode: RSMode.Value
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.multiblock.gui
|
||||
|
||||
import net.bdew.lib.gui.widgets.{WidgetMultipane, WidgetSubcontainer}
|
||||
import net.bdew.lib.gui.{Rect, _}
|
||||
import net.bdew.lib.multiblock.data.OutputConfigPower
|
||||
import net.bdew.lib.multiblock.interact.CIOutputFaces
|
||||
|
||||
class WidgetOutputs(p: Point, te: CIOutputFaces, rows: Int) extends WidgetSubcontainer(new Rect(p, 92, 19 * rows)) {
|
||||
for (i <- 0 until rows)
|
||||
add(new WidgetOutputRow(Point(0, 19 * i), te, i))
|
||||
}
|
||||
|
||||
class WidgetOutputDisplay extends WidgetSubcontainer(Rect(20, 0, 72, 18))
|
||||
|
||||
class WidgetOutputRow(p: Point, te: CIOutputFaces, output: Int) extends WidgetMultipane(new Rect(p, 92, 18)) {
|
||||
add(new WidgetOutputIcon(Point(1, 1), te, output))
|
||||
val emptyPane = addPane(new WidgetSubcontainer(rect))
|
||||
val powerPane = addPane(new WidgetPowerOutput(te, output))
|
||||
|
||||
def getActivePane =
|
||||
te.outputConfig.get(output) match {
|
||||
case Some(x: OutputConfigPower) => powerPane
|
||||
case _ => emptyPane
|
||||
}
|
||||
}
|
||||
+9
-12
@@ -4,25 +4,22 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.multiblock.gui
|
||||
|
||||
import java.text.DecimalFormat
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.gui.widgets.{WidgetButtonIcon, WidgetDynLabel}
|
||||
import net.bdew.lib.gui.{Color, Point}
|
||||
import net.bdew.lib.multiblock.data.{MsgOutputCfgPower, OutputConfigPower, RSMode}
|
||||
import net.bdew.lib.gui.widgets.{WidgetButtonIcon, WidgetSubcontainer}
|
||||
import net.bdew.lib.gui.{Point, Rect}
|
||||
import net.bdew.lib.multiblock.data.{MsgOutputCfgRSMode, OutputConfigRSControllable, RSMode}
|
||||
import net.bdew.lib.multiblock.interact.CIOutputFaces
|
||||
import net.bdew.lib.multiblock.network.NetHandler
|
||||
|
||||
class WidgetPowerOutput(te: CIOutputFaces, output: Int) extends WidgetOutputDisplay {
|
||||
def cfg = te.outputConfig(output).asInstanceOf[OutputConfigPower]
|
||||
val dec = new DecimalFormat("#,##0")
|
||||
val bt = add(new WidgetButtonIcon(Point(56, 1), clicked, te.resources.btBase, te.resources.btHover))
|
||||
add(new WidgetDynLabel("%s %s/t".format(dec.format(cfg.avg), cfg.unit), 1, 5, Color.darkgray))
|
||||
class WidgetRSConfig(te: CIOutputFaces, output: Int, p: Point) extends WidgetSubcontainer(new Rect(p, 16, 16)) {
|
||||
def cfg = te.outputConfig(output).asInstanceOf[OutputConfigRSControllable]
|
||||
|
||||
val bt = add(new WidgetButtonIcon(Point(0, 0), clicked, te.resources.btBase, te.resources.btHover))
|
||||
|
||||
val icons = Map(
|
||||
RSMode.ALWAYS -> te.resources.btEnabled,
|
||||
@@ -45,6 +42,6 @@ class WidgetPowerOutput(te: CIOutputFaces, output: Int) extends WidgetOutputDisp
|
||||
}
|
||||
|
||||
def clicked(b: WidgetButtonIcon) {
|
||||
NetHandler.sendToServer(MsgOutputCfgPower(output, next(cfg.rsMode)))
|
||||
NetHandler.sendToServer(MsgOutputCfgRSMode(output, next(cfg.rsMode)))
|
||||
}
|
||||
}
|
||||
@@ -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]
|
||||
}
|
||||
@@ -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])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,11 @@ 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
|
||||
}
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.multiblock.network
|
||||
|
||||
import net.bdew.lib.network.Message
|
||||
import net.bdew.lib.network.BaseMessage
|
||||
|
||||
abstract class MsgOutputCfg extends Message {
|
||||
abstract class MsgOutputCfg extends BaseMessage[NetHandler.type] {
|
||||
val output: Int
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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}
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
trait RSControllableOutput extends TileEntity {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,9 @@ trait TileModule extends TileDataSlots {
|
||||
val kind: String
|
||||
val connected = new DataSlotPos("connected", this).setUpdate(UpdateKind.WORLD, UpdateKind.SAVE, UpdateKind.RENDER)
|
||||
|
||||
def getCoreAs[T: ClassTag] = connected flatMap (_.getTile[TileController with T](getWorldObj))
|
||||
def getCore = connected flatMap (_.getTile[TileController](getWorldObj))
|
||||
def getCoreAs[T <: TileController : ClassTag] = connected flatMap (_.getTile[T](getWorldObj))
|
||||
|
||||
def getCore = getCoreAs[TileController]
|
||||
|
||||
lazy val mypos = BlockRef(xCoord, yCoord, zCoord)
|
||||
|
||||
|
||||
@@ -9,29 +9,27 @@
|
||||
|
||||
package net.bdew.lib.multiblock.tile
|
||||
|
||||
import net.bdew.lib.multiblock.data.{OutputConfigPower, RSMode}
|
||||
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 {
|
||||
val unit: String
|
||||
|
||||
abstract class TileOutput[T <: OutputConfig] extends TileModule with MIOutput[T] {
|
||||
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): 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
|
||||
@@ -50,7 +48,11 @@ abstract class TileOutput extends TileModule with MIOutput {
|
||||
|
||||
def doRescanFaces() {
|
||||
getCore map { core =>
|
||||
val connections = ForgeDirection.VALID_DIRECTIONS.filter(canConnectoToFace).toSet
|
||||
val connections = (
|
||||
ForgeDirection.VALID_DIRECTIONS
|
||||
filterNot { dir => core.modules.contains(mypos.neighbour(dir)) }
|
||||
filter canConnectoToFace
|
||||
).toSet
|
||||
val known = core.outputFaces.filter(_._1.origin == mypos).map(_._1.face).toSet
|
||||
val toAdd = connections -- known
|
||||
val toRemove = known -- connections
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
|
||||
package net.bdew.lib.network
|
||||
|
||||
abstract class Message extends Serializable
|
||||
abstract class BaseMessage[CH <: NetChannel] extends Serializable
|
||||
@@ -13,18 +13,49 @@ import java.util
|
||||
|
||||
import cpw.mods.fml.common.network.{FMLEmbeddedChannel, FMLOutboundHandler, NetworkRegistry}
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import io.netty.channel.{ChannelFutureListener, ChannelHandler}
|
||||
import io.netty.channel.{ChannelFutureListener, ChannelHandler, ChannelHandlerContext, SimpleChannelInboundHandler}
|
||||
import net.bdew.lib.{BdLib, Misc}
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.minecraft.network.NetHandlerPlayServer
|
||||
|
||||
class NetChannel(val name: String) {
|
||||
var channels: util.EnumMap[Side, FMLEmbeddedChannel] = null
|
||||
|
||||
type Message = BaseMessage[this.type]
|
||||
|
||||
object ServerHandler extends SimpleChannelInboundHandler[Message] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: Message) {
|
||||
try {
|
||||
val player = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get.asInstanceOf[NetHandlerPlayServer].playerEntity
|
||||
if (serverChain.isDefinedAt(msg, player))
|
||||
serverChain(msg, player)
|
||||
else
|
||||
BdLib.logWarn("Unable to handle message from user %s: %s", player.getDisplayName, msg)
|
||||
} catch {
|
||||
case e: Throwable => BdLib.logErrorException("Error handling packet", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object ClientHandler extends SimpleChannelInboundHandler[Message] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: Message) {
|
||||
try {
|
||||
if (clientChain.isDefinedAt(msg))
|
||||
clientChain(msg)
|
||||
else
|
||||
BdLib.logWarn("Unable to handle message from server: %s", msg)
|
||||
} catch {
|
||||
case e: Throwable => BdLib.logErrorException("Error handling packet", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def init() {
|
||||
if (channels != null) sys.error("Attempted to initalize a channel twice (%s)".format(name))
|
||||
channels = NetworkRegistry.INSTANCE.newChannel(name, new SerializedMessageCodec)
|
||||
BdLib.logInfo("Initialized network channel '%s' for mod '%s'", name, Misc.getActiveModId)
|
||||
addHandler(Side.SERVER, new NetChannelServerHandler(this))
|
||||
addHandler(Side.CLIENT, new NetChannelClientHandler(this))
|
||||
addHandler(Side.SERVER, ServerHandler)
|
||||
addHandler(Side.CLIENT, ClientHandler)
|
||||
}
|
||||
|
||||
var clientChain = PartialFunction.empty[Message, Unit]
|
||||
@@ -38,7 +69,7 @@ class NetChannel(val name: String) {
|
||||
|
||||
private def addHandler(side: Side, handler: ChannelHandler) {
|
||||
val ch = channels.get(side)
|
||||
val name = ch.findChannelHandlerNameForType(classOf[SerializedMessageCodec])
|
||||
val name = ch.findChannelHandlerNameForType(classOf[SerializedMessageCodec[this.type]])
|
||||
ch.pipeline().addAfter(name, side + "Handler", handler)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.network
|
||||
|
||||
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
|
||||
import net.bdew.lib.BdLib
|
||||
|
||||
class NetChannelClientHandler(ch: NetChannel) extends SimpleChannelInboundHandler[Message] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: Message) {
|
||||
try {
|
||||
if (ch.clientChain.isDefinedAt(msg))
|
||||
ch.clientChain(msg)
|
||||
else
|
||||
BdLib.logWarn("Unable to handle message from server: %s", msg)
|
||||
} catch {
|
||||
case e: Throwable => BdLib.logErrorException("Error handling packet", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.network
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry
|
||||
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
|
||||
import net.bdew.lib.BdLib
|
||||
import net.minecraft.network.NetHandlerPlayServer
|
||||
|
||||
class NetChannelServerHandler(ch: NetChannel) extends SimpleChannelInboundHandler[Message] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: Message) {
|
||||
try {
|
||||
val player = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get.asInstanceOf[NetHandlerPlayServer].playerEntity
|
||||
if (ch.serverChain.isDefinedAt(msg, player))
|
||||
ch.serverChain(msg, player)
|
||||
else
|
||||
BdLib.logWarn("Unable to handle message from user %s: %s", player.getDisplayName, msg)
|
||||
} catch {
|
||||
case e: Throwable => BdLib.logErrorException("Error handling packet", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ import io.netty.handler.codec.MessageToMessageCodec
|
||||
import net.bdew.lib.BdLib
|
||||
|
||||
@Sharable
|
||||
class SerializedMessageCodec extends MessageToMessageCodec[FMLProxyPacket, Message] {
|
||||
def encode(ctx: ChannelHandlerContext, msg: Message, out: util.List[AnyRef]) {
|
||||
class SerializedMessageCodec[T <: NetChannel] extends MessageToMessageCodec[FMLProxyPacket, BaseMessage[T]] {
|
||||
def encode(ctx: ChannelHandlerContext, msg: BaseMessage[T], out: util.List[AnyRef]) {
|
||||
val buff = Unpooled.buffer()
|
||||
val writer = new ObjectOutputStream(new ByteBufOutputStream(buff))
|
||||
writer.writeObject(msg)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.player
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent._
|
||||
import net.bdew.lib.BdLib
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class PlayerCache[T] extends mutable.Map[EntityPlayer, T] {
|
||||
var map = Map.empty[EntityPlayer, T]
|
||||
|
||||
BdLib.onServerStarting.listen(x => map = map.empty)
|
||||
BdLib.onServerStopping.listen(x => map = map.empty)
|
||||
FMLCommonHandler.instance().bus().register(this)
|
||||
|
||||
def updateIfNeeded(p: EntityPlayer, v: T): Boolean = {
|
||||
if (map.get(p).contains(v)) {
|
||||
false
|
||||
} else {
|
||||
map += p -> v
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
def reset(p: EntityPlayer) {
|
||||
if (map.contains(p)) map -= p
|
||||
}
|
||||
|
||||
override def get(p: EntityPlayer) = map.get(p)
|
||||
|
||||
override def +=(kv: (EntityPlayer, T)) = {
|
||||
map += kv
|
||||
this
|
||||
}
|
||||
override def -=(key: EntityPlayer) = {
|
||||
map -= key
|
||||
this
|
||||
}
|
||||
|
||||
override def iterator = map.iterator
|
||||
|
||||
@SubscribeEvent
|
||||
def hadlePlayerLogout(ev: PlayerLoggedOutEvent) = reset(ev.player)
|
||||
|
||||
@SubscribeEvent
|
||||
def hadlePlayerChangedDimension(ev: PlayerChangedDimensionEvent) = reset(ev.player)
|
||||
|
||||
@SubscribeEvent
|
||||
def hadlePlayerRespawn(ev: PlayerRespawnEvent) = reset(ev.player)
|
||||
}
|
||||
@@ -21,9 +21,9 @@ trait GenericConfigParser extends RecipeParser {
|
||||
| ("-" ~> decimalNumber) ^^ { case x => -x.toDouble }
|
||||
)
|
||||
|
||||
def cfgStatementNum = ident ~ "=" ~ signedNumber ^^ { case id ~ eq ~ n => CfgVal(id, EntryDouble(n.toDouble)) }
|
||||
def cfgStatementStr = ident ~ "=" ~ str ^^ { case id ~ eq ~ s => CfgVal(id, EntryStr(s)) }
|
||||
def cfgStatementNumList = ident ~ ("=" ~> "{" ~> signedNumber.* <~ "}") ^^ { case id ~ l => CfgVal(id, EntryNumList(l)) }
|
||||
def cfgStatementNum = str ~ "=" ~ signedNumber ^^ { case id ~ eq ~ n => CfgVal(id, EntryDouble(n.toDouble)) }
|
||||
def cfgStatementStr = str ~ "=" ~ str ^^ { case id ~ eq ~ s => CfgVal(id, EntryStr(s)) }
|
||||
def cfgStatementNumList = str ~ ("=" ~> "{" ~> signedNumber.* <~ "}") ^^ { case id ~ l => CfgVal(id, EntryNumList(l)) }
|
||||
def cfgStatementSub = cfgBlock ^^ { case (id, st) => CfgSub(id, st) }
|
||||
|
||||
def cfgStatement = cfgStatementNum | cfgStatementStr | cfgStatementSub | cfgStatementNumList
|
||||
@@ -31,7 +31,7 @@ trait GenericConfigParser extends RecipeParser {
|
||||
// A bit of type acrobatics because this is recursive (via cfgStatementSub)
|
||||
// the tuple is translated into the proper class in either cfgStatementSub or cfg
|
||||
def cfgBlock: Parser[(String, List[CfgStatement])] =
|
||||
"cfg" ~> ident ~ ("{" ~> cfgStatement.* <~ "}") ^^ { case id ~ st => (id, st) }
|
||||
"cfg" ~> str ~ ("{" ~> cfgStatement.* <~ "}") ^^ { case id ~ st => (id, st) }
|
||||
|
||||
def statementCfg = cfgBlock ^^ { case (id, st) => StCfg(id, st) }
|
||||
}
|
||||
Reference in new issue
Block a user