Compare commits

..
4 Commits
8 changed files with 71 additions and 6 deletions

No files matched your search

+1 -1
View File
@@ -21,7 +21,7 @@ buildscript {
apply plugin: 'scala'
apply plugin: 'forge'
version = "1.6.3"
version = "1.6.5"
if (project.hasProperty('buildnum')) {
project.version = project.version + '.' + project.buildnum
+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
}
+3 -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
@@ -34,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")
}
+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)
@@ -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