mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-24 05:54:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a232ce52f3 | ||
|
|
35b3a77582 | ||
|
|
be3a1cf2aa | ||
|
|
e0f5d0ceda | ||
|
|
e4169f7a5d | ||
|
|
eb75a26c40 | ||
|
|
3431a6910e | ||
|
|
02598183b8 | ||
|
|
70c19bff5b | ||
|
|
6a78467232 | ||
|
|
561833db33 | ||
|
|
0e345e6675 | ||
|
|
e78e565ec8 | ||
|
|
573330efd3 |
No files matched your search
+4
-3
@@ -21,7 +21,7 @@ buildscript {
|
||||
apply plugin: 'scala'
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.6.0"
|
||||
version = "1.6.3"
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,8 @@ task sourceJar(type: Jar) {
|
||||
}
|
||||
|
||||
task deobfJar(type: Jar) {
|
||||
from sourceSets.main.output.classesDir
|
||||
from sourceSets.main.output
|
||||
duplicatesStrategy "exclude"
|
||||
}
|
||||
|
||||
jar {
|
||||
|
||||
@@ -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
|
||||
@@ -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: _*))
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.text.DecimalFormat
|
||||
object DecFormat {
|
||||
val thousandsFmt = new DecimalFormat("#,##0")
|
||||
val dec2Fmt = new DecimalFormat("#,##0.00")
|
||||
val dec1Fmt = new DecimalFormat("#,##0.0")
|
||||
|
||||
def round(x: Double) = thousandsFmt.format(x)
|
||||
def round(x: Float) = thousandsFmt.format(x)
|
||||
@@ -22,4 +23,8 @@ object DecFormat {
|
||||
def dec2(x: Double) = dec2Fmt.format(x)
|
||||
def dec2(x: Float) = dec2Fmt.format(x)
|
||||
def dec2(x: Int) = dec2Fmt.format(x)
|
||||
|
||||
def short(x: Double) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
|
||||
def short(x: Float) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
|
||||
def short(x: Int) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
@@ -56,7 +56,7 @@ class DataSlotResource(val name: String, val parent: TileDataSlots, initCapacity
|
||||
if (onlyRound) canDrain = canDrain.floor
|
||||
if (doDrain) execWithChangeNotify {
|
||||
resource =
|
||||
if (canDrain == res.amount)
|
||||
if (res.amount - canDrain < 0.000001)
|
||||
None
|
||||
else
|
||||
Some(Resource(res.kind, res.amount - canDrain))
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user