mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-19 11:59:22 +00:00
Added sensor system
Bump version
This commit is contained in:
1 parent
0929ba9278
commit
9ae4935fd9
9 files changed
+223
-1
No files matched your search
+1
-1
@@ -21,7 +21,7 @@ buildscript {
|
||||
apply plugin: 'scala'
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.6.5"
|
||||
version = "1.7.0"
|
||||
|
||||
if (project.hasProperty('buildnum')) {
|
||||
project.version = project.version + '.' + project.buildnum
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* 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.sensors
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.data.base.{DataSlotVal, UpdateKind}
|
||||
import net.bdew.lib.sensors.multiblock.TileSensorModule
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
case class DataSlotSensor(name: String, parent: TileSensorModule, default: SensorType) extends DataSlotVal[SensorPair] {
|
||||
override var value: SensorPair = SensorPair(default, default.defaultParameter)
|
||||
|
||||
setUpdate(UpdateKind.SAVE, UpdateKind.GUI)
|
||||
|
||||
override def save(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||
t.setTag(name, Misc.applyMutator(new NBTTagCompound) { tag =>
|
||||
tag.setString("uid", value.sensor.uid)
|
||||
value.sensor.saveParameter(value.param, tag)
|
||||
})
|
||||
}
|
||||
|
||||
override def load(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||
value = SensorRegistry.get(t.getCompoundTag(name).getString("uid"))
|
||||
.map(x => SensorPair(x, x.loadParameter(t.getCompoundTag(name))))
|
||||
.getOrElse(SensorPair(default, default.defaultParameter))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* 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.sensors
|
||||
|
||||
case class SensorPair(sensor: SensorType, param: SensorParameter)
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* 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.sensors
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.gui.Texture
|
||||
|
||||
trait SensorParameter {
|
||||
val uid: String
|
||||
|
||||
def localizedName = Misc.toLocal("bdew.sensor.param." + uid)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def texture: Texture
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* 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.sensors
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.gui.Texture
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
abstract class SensorType {
|
||||
def uid: String
|
||||
|
||||
def localizedName = Misc.toLocal("bdew.sensor." + uid)
|
||||
|
||||
def defaultParameter: SensorParameter
|
||||
def paramClicked(current: SensorParameter, item: ItemStack, button: Int, mod: Int): SensorParameter
|
||||
def saveParameter(p: SensorParameter, tag: NBTTagCompound)
|
||||
def loadParameter(tag: NBTTagCompound): SensorParameter
|
||||
|
||||
def isActive(param: SensorParameter, te: TileEntity): Boolean
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def texture: Texture
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* 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.sensors
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
abstract class SimpleSensor extends SensorType {
|
||||
def parameters: IndexedSeq[SensorParameter]
|
||||
|
||||
override lazy val defaultParameter = parameters.headOption.getOrElse(InvalidParameter)
|
||||
|
||||
lazy val parameterMap = (parameters map (x => x.uid -> x)).toMap
|
||||
|
||||
override def paramClicked(current: SensorParameter, item: ItemStack, button: Int, mod: Int) =
|
||||
if (item == null && button == 0 && mod == 0)
|
||||
Misc.nextInSeq(parameters, current)
|
||||
else
|
||||
current
|
||||
|
||||
override def saveParameter(p: SensorParameter, tag: NBTTagCompound) = tag.setString("param", p.uid)
|
||||
override def loadParameter(tag: NBTTagCompound) = parameterMap.getOrElse(tag.getString("param"), InvalidParameter)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* 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.sensors.multiblock
|
||||
|
||||
import net.bdew.lib.multiblock.tile.TileController
|
||||
import net.bdew.lib.sensors.SensorType
|
||||
|
||||
trait CISensors extends TileController {
|
||||
def sensorTypes: Seq[SensorType]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* 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.sensors.multiblock
|
||||
|
||||
import net.bdew.lib.multiblock.tile.TileModule
|
||||
import net.bdew.lib.sensors.DataSlotSensor
|
||||
|
||||
abstract class TileSensorModule extends TileModule {
|
||||
def config: DataSlotSensor
|
||||
override def getCore = getCoreAs[CISensors]
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* 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.sensors
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.Client
|
||||
import net.bdew.lib.gui.{IconWrapper, Texture}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
object SensorRegistry {
|
||||
val map = collection.mutable.Map.empty[String, SensorType]
|
||||
def get(uid: String) = map.get(uid)
|
||||
|
||||
def register[T <: SensorType](s: T): T = {
|
||||
if (map.isDefinedAt(s.uid))
|
||||
sys.error("Duplicate sensor ID: %s (%s / %s)".format(s.uid, map(s.uid), s))
|
||||
map += s.uid -> s
|
||||
s
|
||||
}
|
||||
|
||||
register(InvalidSensor)
|
||||
}
|
||||
|
||||
object InvalidParameter extends SensorParameter {
|
||||
override val uid = "invalid"
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override lazy val texture = new IconWrapper(Texture.BLOCKS, Client.blockMissingIcon)
|
||||
}
|
||||
|
||||
object InvalidSensor extends SensorType {
|
||||
override def uid = "invalid"
|
||||
override def defaultParameter = InvalidParameter
|
||||
override def loadParameter(tag: NBTTagCompound) = InvalidParameter
|
||||
override def saveParameter(p: SensorParameter, tag: NBTTagCompound) = {}
|
||||
override def isActive(param: SensorParameter, te: TileEntity) = false
|
||||
override def paramClicked(current: SensorParameter, item: ItemStack, button: Int, mod: Int) = InvalidParameter
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override lazy val texture = new IconWrapper(Texture.BLOCKS, Client.blockMissingIcon)
|
||||
}
|
||||
|
||||
object InvalidSensorPair extends SensorPair(InvalidSensor, InvalidParameter)
|
||||
|
||||
|
||||
Reference in new issue
Block a user