Compare commits

...
15 Commits
Author SHA1 Message Date
bdew 0929ba9278 Java 6 doesn't have System.lineSeparator *facepalm* 2015-02-26 14:55:18 +02:00
bdew 1003aa1d6a Prevent update spam in tank and resource dataslots when they don't actually change (bdew/pressure#34) 2015-02-26 14:29:04 +02:00
bdew 64c0484c2d Added ApiReporter 2015-02-24 17:23:45 +02:00
bdew 8e90643ea1 GUI update packets are now timestamped, packets from the past will be ignored 2015-02-22 11:12:16 +02:00
bdew a232ce52f3 Build against forge 10.13.2.1291 2015-02-20 13:23:11 +02:00
bdew 35b3a77582 Fixed BlockRef crash on dedicated servers (bdew/generators#26) 2015-02-20 13:23:11 +02:00
bdew be3a1cf2aa Merge pull request #10 from DragonsLover/mc1710
Adding French Canadian language
2015-02-20 06:15:21 +02:00
DragonsLover e0f5d0ceda Adding French Canadian language 2015-02-19 23:14:00 -05:00
bdew e4169f7a5d Fixed Rect.contains being off by 1 2015-02-19 17:56:50 +02:00
bdew eb75a26c40 Moving dataslot classes to bdlib 2015-02-19 12:04:13 +02:00
bdew 3431a6910e Prevent access to invalid coordinates from BlockRef 2015-02-19 01:44:07 +02:00
bdew 02598183b8 Added CIItemInput 2015-02-18 17:52:40 +02:00
bdew 70c19bff5b Lowered log level of some spammy messages in config system to Debug (bdew/gendustry#81) 2015-02-18 12:01:31 +02:00
bdew 6a78467232 Fixed DataSlotResource.drainFluid draining 2x (bdew/generators#21) 2015-02-09 00:21:38 +02:00
bdew 561833db33 Refactored SlotSet to prevent textures being initialized on dedicated servers (bdew/generators#23) 2015-02-08 23:39:37 +02:00
19 changed files with 285 additions and 41 deletions

No files matched your search

+2 -2
View File
@@ -21,7 +21,7 @@ buildscript {
apply plugin: 'scala'
apply plugin: 'forge'
version = "1.6.1"
version = "1.6.5"
if (project.hasProperty('buildnum')) {
project.version = project.version + '.' + project.buildnum
@@ -34,7 +34,7 @@ archivesBaseName = "bdlib"
ext.versuffix = "mc1710"
minecraft {
version = "1.7.10-10.13.2.1231"
version = "1.7.10-10.13.2.1291"
replace("BDLIB_VER", project.version)
}
+18
View File
@@ -0,0 +1,18 @@
bdlib.multiblock.face.north=Nord
bdlib.multiblock.face.south=Sud
bdlib.multiblock.face.east=Est
bdlib.multiblock.face.west=Ouest
bdlib.multiblock.face.up=Haut
bdlib.multiblock.face.down=Bas
bdlib.multiblock.disabled=Désactivé(e)
bdlib.multiblock.incomplete=Cette machine est incomplète, elle requiert au moins :
bdlib.multiblock.notconnected=Pas connecté(e) à une machine valide
bdlib.multiblock.toomanyoutputs=Trop de sorties connectées, incapable d'attacher de nouvelles connexions
bdlib.rsmode.always=Toujours en marche
bdlib.rsmode.never=Désactivé(e)
bdlib.rsmode.rs_on=Activer par la redstone
bdlib.rsmode.rs_off=Désactiver par la redstone
bdlib.label.empty=Vide
+33
View File
@@ -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
import java.util
import cpw.mods.fml.common.{ICrashCallable, ModAPIManager, ModContainer}
import scala.collection.JavaConversions._
object ApiReporter extends ICrashCallable {
lazy val APIs = {
val mods = new util.ArrayList[ModContainer]
val nameLookup = new util.HashMap[String, ModContainer]
ModAPIManager.INSTANCE.injectAPIModContainers(mods, nameLookup)
(for (mod <- mods.sortBy(_.getModId.toLowerCase)) yield
"\t\t* %s (%s) from %s".format(mod.getModId, mod.getVersion,
if (mod.getSource.isDirectory)
mod.getSource
else
mod.getSource.getName
)).mkString(Misc.lineSeparator)
}
override def getLabel = "List of loaded APIs"
override def call() = Misc.lineSeparator + APIs
}
+4 -1
View File
@@ -9,9 +9,9 @@
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, FMLServerStoppingEvent}
import cpw.mods.fml.common.{FMLCommonHandler, Mod}
import net.bdew.lib.multiblock.network.NetHandler
import net.minecraft.command.CommandHandler
import org.apache.logging.log4j.Logger
@@ -20,6 +20,7 @@ import org.apache.logging.log4j.Logger
object BdLib {
var log: Logger = null
def logDebug(msg: String, args: Any*) = log.debug(msg.format(args: _*))
def logInfo(msg: String, args: Any*) = log.info(msg.format(args: _*))
def logWarn(msg: String, args: Any*) = log.warn(msg.format(args: _*))
def logError(msg: String, args: Any*) = log.error(msg.format(args: _*))
@@ -33,6 +34,8 @@ object BdLib {
def preInit(ev: FMLPreInitializationEvent) {
log = ev.getModLog
log.info("bdlib BDLIB_VER loaded")
log.debug("List of loaded APIs: " + ApiReporter.APIs)
FMLCommonHandler.instance().registerCrashCallable(ApiReporter)
NetHandler.init()
}
+10
View File
@@ -105,6 +105,14 @@ object Misc {
init
}
def nextInSeq[T](seq: Seq[T], elem: T) = {
val pos = seq.indexOf(elem)
if (pos < 0 || pos == seq.size - 1)
seq(0)
else
seq(pos + 1)
}
def getFluidIcon(fs: FluidStack): IIcon =
if (fs != null && fs.getFluid != null && fs.getFluid.getIcon != null)
fs.getFluid.getIcon(fs)
@@ -119,5 +127,7 @@ object Misc {
def getFluidColor(f: Fluid): Int =
if (f != null) getFluidColor(new FluidStack(f, 1)) else 0xFFFFFF
lazy val lineSeparator = System.getProperty("line.separator")
}
+5 -3
View File
@@ -18,9 +18,11 @@ import net.minecraftforge.common.util.ForgeDirection
import scala.reflect.ClassTag
case class BlockRef(x: Int, y: Int, z: Int) {
def block(w: IBlockAccess) = Option(w.getBlock(x, y, z))
def tile(w: IBlockAccess) = Option(w.getTileEntity(x, y, z))
def meta(w: IBlockAccess) = w.getBlockMetadata(x, y, z)
def isValid(w: IBlockAccess) = y >= 0 && y < 256 // hardcoded because getHeight is unavailable on servers :(
def block(w: IBlockAccess) = if (isValid(w)) Option(w.getBlock(x, y, z)) else None
def tile(w: IBlockAccess) = if (isValid(w)) Option(w.getTileEntity(x, y, z)) else None
def meta(w: IBlockAccess) = if (isValid(w)) w.getBlockMetadata(x, y, z) else 0
def blockIs(w: IBlockAccess, other: Block) = block(w).contains(other)
@@ -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.data
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.fluids.{Fluid, FluidRegistry}
case class DataSlotFluidOption(name: String, parent: TileDataSlots) extends DataSlotOption[Fluid] {
setUpdate(UpdateKind.SAVE, UpdateKind.GUI)
override def save(t: NBTTagCompound, kind: UpdateKind.Value) {
value map { x => t.setString(name, x.getName) }
}
override def load(t: NBTTagCompound, kind: UpdateKind.Value): Unit = {
if (t.hasKey(name)) {
val fluidName = t.getString(name)
if (FluidRegistry.isFluidRegistered(fluidName)) {
value = Option(FluidRegistry.getFluid(fluidName))
} else unset()
} else unset()
}
}
@@ -0,0 +1,63 @@
/*
* 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.data
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, DataInputStream, DataOutputStream}
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
import scala.collection.mutable
case class DataSlotMovingAverage(name: String, parent: TileDataSlots, size: Int) extends DataSlot {
val values = mutable.Queue.empty[Double]
var average: Double = 0
setUpdate(UpdateKind.GUI, UpdateKind.SAVE)
def reset() {
values.clear()
average = 0
}
def update(v: Double) = {
values += v
if (values.length > size)
values.dequeue()
average = values.sum / values.length
parent.dataSlotChanged(this)
}
override def save(t: NBTTagCompound, kind: UpdateKind.Value) {
if (kind == UpdateKind.GUI) {
t.setDouble(name, average)
} else {
val b = new ByteArrayOutputStream()
val o = new DataOutputStream(b)
o.writeByte(values.size)
values.foreach(o.writeDouble)
t.setByteArray(name, b.toByteArray)
o.close()
}
}
override def load(t: NBTTagCompound, kind: UpdateKind.Value) {
if (kind == UpdateKind.GUI) {
average = t.getDouble(name)
} else {
values.clear()
if (t.hasKey(name)) {
val i = new DataInputStream(new ByteArrayInputStream(t.getByteArray(name)))
val len = i.readByte()
values ++= (for (x <- 0 until Math.min(len, size)) yield i.readDouble())
i.close()
}
}
}
}
+4 -2
View File
@@ -50,17 +50,19 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
if (sendCapacityOnUpdateKind.contains(k))
setCapacity(tag.getInteger("size"))
}
override def setFluid(fluid: FluidStack) = execWithChangeNotify(super.setFluid(fluid))
override def setCapacity(capacity: Int) = execWithChangeNotify(super.setCapacity(capacity))
override def drain(maxDrain: Int, doDrain: Boolean) =
if (doDrain)
execWithChangeNotify(super.drain(maxDrain, true))
execWithChangeNotifyConditional[FluidStack](super.drain(maxDrain, true), _ != null)
else
super.drain(maxDrain, false)
override def fill(resource: FluidStack, doFill: Boolean) =
if (doFill)
execWithChangeNotify(super.fill(resource, true))
execWithChangeNotifyConditional[Int](super.fill(resource, true), _ > 0)
else
super.fill(resource, false)
}
@@ -41,6 +41,13 @@ trait DataSlot {
v
}
def execWithChangeNotifyConditional[T](f: => T, condition: T => Boolean): T = {
val v = f
if (condition(v))
parent.dataSlotChanged(this)
v
}
def setUpdate(vals: UpdateKind.Value*): this.type = {
updateKind = vals.toSet
return this
@@ -19,10 +19,13 @@ import scala.collection.mutable
trait TileDataSlots extends TileExtended {
val dataSlots = mutable.HashMap.empty[String, DataSlot]
var lastChange = 0L
var lastGuiPacket = 0L
final val TRACE = false
def doSave(kind: UpdateKind.Value, t: NBTTagCompound) {
if (kind == UpdateKind.GUI)
t.setLong("BDLib_TS", getWorldObj.getTotalWorldTime)
for ((n, s) <- dataSlots if s.updateKind.contains(kind)) {
s.save(t, kind)
if (TRACE) printf("%s: %s S=> %s\n".format(kind, n, t.getTag(n)))
@@ -30,6 +33,14 @@ trait TileDataSlots extends TileExtended {
}
def doLoad(kind: UpdateKind.Value, t: NBTTagCompound) {
if (kind == UpdateKind.GUI) {
val ts = t.getLong("BDLib_TS")
if (ts > lastGuiPacket) {
lastGuiPacket = ts
} else {
return
}
}
for ((n, s) <- dataSlots if s.updateKind.contains(kind)) {
if (TRACE) printf("%s: %s L<= %s\n".format(kind, n, t.getTag(n)))
s.load(t, kind)
+1 -1
View File
@@ -16,7 +16,7 @@ case class BaseRect[T: Numeric](x: T, y: T, w: T, h: T) {
def this(p: BasePoint[T], w: T, h: T) = this(p.x, p.y, w, h)
def contains(p: BasePoint[T]) = n.gteq(p.x, x) && n.gteq(p.y, y) && n.lteq(p.x, x2) && n.lteq(p.y, y2)
def contains(p: BasePoint[T]) = n.gteq(p.x, x) && n.gteq(p.y, y) && n.lt(p.x, x2) && n.lt(p.y, y2)
def origin = BasePoint(x, y)
@@ -9,6 +9,7 @@
package net.bdew.lib.multiblock.data
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.lib.gui.Texture
abstract class SlotSet(val outputConfigId: String) {
@@ -16,13 +17,19 @@ abstract class SlotSet(val outputConfigId: String) {
var slotMap = Map.empty[String, Slot]
case class Slot(id: String, name: String, texture: Texture) {
case class Slot(id: String, name: String) {
slotMap += id -> this
def next = order(this)
@SideOnly(Side.CLIENT)
def texture = textures(this)
}
def default: Slot
val order: Map[Slot, Slot]
@SideOnly(Side.CLIENT)
def textures: Map[Slot, Texture]
def get(id: String) = slotMap(id)
}
@@ -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.multiblock.interact
import net.bdew.lib.multiblock.tile.TileController
import net.minecraft.inventory.IInventory
trait CIItemInput extends TileController {
def getItemInputInventory: IInventory
def canInputItemToSlot(slot: Int): Boolean
}
+26 -26
View File
@@ -172,7 +172,7 @@ class RecipeLoader {
if (l.size == 0) error("Concrete ItemStack requested for OD entry '%s' that is empty", id)
val s = l.get(0).copy()
s.stackSize = cnt
BdLib.logInfo("Concrete ItemStack for OD entry '%s' -> %s", id, s)
BdLib.logDebug("Concrete ItemStack for OD entry '%s' -> %s", id, s)
return s
case StackMacro(ch) => getConcreteStack(currCharMap(ch), cnt)
case StackGeneric(mod, id) =>
@@ -197,7 +197,7 @@ class RecipeLoader {
if (!currCharMap.contains(x)) error("Character %s is undefined", x)
val r = getRecipeComponent(currCharMap(x))
if (r.isInstanceOf[String]) needOd = true
BdLib.logInfo("%s -> %s", x, r)
BdLib.logDebug("%s -> %s", x, r)
comp += (x -> r)
}
return (comp, needOd)
@@ -213,7 +213,7 @@ class RecipeLoader {
list flatMap {
case x: CraftingStatement =>
if (res == x.result) {
BdLib.logInfo("Removing recipe %s", this)
BdLib.logDebug("Removing recipe %s", this)
None
} else Some(x)
case RsRecipes(inner) =>
@@ -248,15 +248,15 @@ class RecipeLoader {
def processConfigStatement(s: ConfigStatement): Unit = s match {
case CsConditionalConfig(cnd, thn, els) =>
if (resolveCondition(cnd)) {
BdLib.logInfo("Condition %s - TRUE", cnd)
BdLib.logDebug("Condition %s - TRUE", cnd)
processConfigStatementsSafe(thn)
} else {
BdLib.logInfo("Condition %s - FALSE", cnd)
BdLib.logDebug("Condition %s - FALSE", cnd)
processConfigStatementsSafe(els)
}
case CsClearRecipes(res) =>
BdLib.logInfo("Clearing recipes that produce %s", res)
BdLib.logDebug("Clearing recipes that produce %s", res)
recipeStatements = clearStatements(recipeStatements, res)
case CsRecipeBlock(lst) =>
@@ -273,19 +273,19 @@ class RecipeLoader {
def processRecipeStatement(st: RecipeStatement) = st match {
case RsCharAssign(c, r) =>
currCharMap += (c -> r)
BdLib.logInfo("Added %s = %s", c, r)
BdLib.logDebug("Added %s = %s", c, r)
case RsClassMacro(id, cls) =>
currClassMacros += (id -> cls)
BdLib.logInfo("Added def %s = %s", id, cls)
BdLib.logDebug("Added def %s = %s", id, cls)
case RsRecipeShaped(rec, res, cnt) =>
BdLib.logInfo("Adding shaped recipe %s => %s * %d", rec, res, cnt)
BdLib.logDebug("Adding shaped recipe %s => %s * %d", rec, res, cnt)
val (comp, needOd) = resolveRecipeComponents(rec.mkString(""))
val resStack = getConcreteStack(res, cnt)
if (resStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
BdLib.logInfo("Result meta is unset, defaulting to 0")
BdLib.logDebug("Result meta is unset, defaulting to 0")
resStack.setItemDamage(0)
}
@@ -294,16 +294,16 @@ class RecipeLoader {
else
Misc.addRecipe(resStack, rec, comp)
BdLib.logInfo("Done... result=%s, od=%s", resStack, needOd)
BdLib.logDebug("Done... result=%s, od=%s", resStack, needOd)
case RsRecipeShapeless(rec, res, cnt) =>
BdLib.logInfo("Adding shapeless recipe %s => %s * %d", rec, res, cnt)
BdLib.logDebug("Adding shapeless recipe %s => %s * %d", rec, res, cnt)
val (comp, needOd) = resolveRecipeComponents(rec)
val resStack = getConcreteStack(res, cnt)
val recTrans = rec.toCharArray.map(comp(_))
if (resStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
BdLib.logInfo("Result meta is unset, defaulting to 0")
BdLib.logDebug("Result meta is unset, defaulting to 0")
resStack.setItemDamage(0)
}
@@ -312,26 +312,26 @@ class RecipeLoader {
else
GameRegistry.addShapelessRecipe(resStack, recTrans: _*)
BdLib.logInfo("Done... result=%s, od=%s", resStack, needOd)
BdLib.logDebug("Done... result=%s, od=%s", resStack, needOd)
case RsRecipeSmelting(in, out, cnt, xp) =>
BdLib.logInfo("Adding smelting recipe %s => %s * %d (%f xp)", in, out, cnt, xp)
BdLib.logDebug("Adding smelting recipe %s => %s * %d (%f xp)", in, out, cnt, xp)
val outStack = getConcreteStack(out, cnt)
if (outStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
BdLib.logInfo("Result meta is unset, defaulting to 0")
BdLib.logDebug("Result meta is unset, defaulting to 0")
outStack.setItemDamage(0)
}
for (inStack <- getAllConcreteStacks(in, 1)) {
GameRegistry.addSmelting(inStack, outStack, xp)
BdLib.logInfo("added %s -> %s", inStack, outStack)
BdLib.logDebug("added %s -> %s", inStack, outStack)
}
case RsConditional(cnd, thn, els) =>
if (resolveCondition(cnd)) {
BdLib.logInfo("Condition %s - TRUE", cnd)
BdLib.logDebug("Condition %s - TRUE", cnd)
processRecipeStatementsInSubcontext(thn)
} else {
BdLib.logInfo("Condition %s - FALSE", cnd)
BdLib.logDebug("Condition %s - FALSE", cnd)
processRecipeStatementsInSubcontext(els)
}
@@ -339,13 +339,13 @@ class RecipeLoader {
processRecipeStatementsInSubcontext(list)
case RsRegOredict(id, spec, wildcard) =>
BdLib.logInfo("Registering ore dictionary entry: %s -> %s", spec, id)
BdLib.logDebug("Registering ore dictionary entry: %s -> %s", spec, id)
val stack = getConcreteStack(spec)
if (wildcard) {
BdLib.logInfo("Forcing wildcard damage (was %d)", stack.getItemDamage)
BdLib.logDebug("Forcing wildcard damage (was %d)", stack.getItemDamage)
stack.setItemDamage(OreDictionary.WILDCARD_VALUE)
}
BdLib.logInfo("Actual stack: %s", stack)
BdLib.logDebug("Actual stack: %s", stack)
OreDictionary.registerOre(id, stack)
case x =>
@@ -371,7 +371,7 @@ class RecipeLoader {
* Process main recipe statements list, clear the list afterwards
*/
def processRecipeStatements() {
BdLib.logInfo("Processing %d recipe statements", recipeStatements.size)
BdLib.logDebug("Processing %d recipe statements", recipeStatements.size)
processRecipeStatementsSafe(recipeStatements)
recipeStatements = List.empty
}
@@ -411,10 +411,10 @@ class RecipeLoader {
}
def load(f: Reader) {
BdLib.logInfo("Starting parsing")
BdLib.logDebug("Starting parsing")
val r = newParser().doParse(f)
BdLib.logInfo("Processing %d statements", r.size)
BdLib.logDebug("Processing %d statements", r.size)
processConfigStatementsSafe(r)
BdLib.logInfo("Done")
BdLib.logDebug("Done")
}
}
@@ -17,7 +17,7 @@ trait GenericConfigLoader extends RecipeLoader {
def processConfigStatement(section: ConfigSection, s: CfgEntry): Unit = s match {
case CfgVal(id, v) =>
BdLib.logInfo("Config: %s%s = %s", section.pfx, id, v)
BdLib.logDebug("Config: %s%s = %s", section.pfx, id, v)
section.set(id, v)
case CfgSection(id, st) => processConfigBlock(section.getOrAddSection(id), st)
case x =>
@@ -29,7 +29,7 @@ trait LootListLoader extends GenericConfigLoader {
None
} else {
if (itemStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
BdLib.logInfo("meta/damage is unset in %s, defaulting to 0", ref)
BdLib.logDebug("meta/damage is unset in %s, defaulting to 0", ref)
itemStack.setItemDamage(0)
}
Some((chance, itemStack))
@@ -36,7 +36,7 @@ class DataSlotResource(val name: String, val parent: TileDataSlots, initCapacity
val current = if (resource.isEmpty) 0D else resource.get.amount
var canFill = Misc.clamp(res.amount, 0D, capacity * res.kind.capacityMultiplier - current)
if (onlyRound) canFill = canFill.floor
if (doFill) execWithChangeNotify {
if (doFill && canFill > 0) execWithChangeNotify {
resource = Some(Resource(res.kind, current + canFill))
}
canFill
@@ -54,7 +54,7 @@ class DataSlotResource(val name: String, val parent: TileDataSlots, initCapacity
resource map { res =>
var canDrain = Misc.clamp(res.amount, 0D, maxDrain)
if (onlyRound) canDrain = canDrain.floor
if (doDrain) execWithChangeNotify {
if (doDrain && canDrain > 0) execWithChangeNotify {
resource =
if (res.amount - canDrain < 0.000001)
None
@@ -68,7 +68,7 @@ class DataSlotResource(val name: String, val parent: TileDataSlots, initCapacity
def fillFluid(resource: FluidStack, doFill: Boolean): Int = rawFill(Resource.from(resource), onlyRound = true, doFill).toInt
def drainFluid(maxDrain: Int, doDrain: Boolean): FluidStack = {
(for {
res <- rawDrain(maxDrain, true, doDrain)
res <- rawDrain(maxDrain, true, false)
rKind <- Misc.asInstanceOpt(res.kind, classOf[FluidResource])
} yield {
if (doDrain)
@@ -0,0 +1,39 @@
/*
* 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.resource
import net.bdew.lib.Misc
import net.bdew.lib.data.DataSlotOption
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
case class DataSlotResourceKindOption(name: String, parent: TileDataSlots) extends DataSlotOption[ResourceKind] {
setUpdate(UpdateKind.SAVE, UpdateKind.GUI)
override def save(t: NBTTagCompound, kind: UpdateKind.Value) {
value map { r =>
t.setTag(name,
Misc.applyMutator(new NBTTagCompound) { tag =>
r.helperObject.saveToNBT(tag, r)
tag.setString("kind", r.helperObject.id)
}
)
}
}
override def load(t: NBTTagCompound, kind: UpdateKind.Value) {
if (t.hasKey(name)) {
val tag = t.getCompoundTag(name)
value = if (tag.hasKey("kind")) {
ResourceManager.resourceHelpers.get(tag.getString("kind")).flatMap(_.loadFromNBT(tag))
} else None
} else unset()
}
}