diff --git a/src/net/bdew/lib/data/DataSlotTank.scala b/src/net/bdew/lib/data/DataSlotTank.scala index 46c6353..de3ad93 100644 --- a/src/net/bdew/lib/data/DataSlotTank.scala +++ b/src/net/bdew/lib/data/DataSlotTank.scala @@ -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) } diff --git a/src/net/bdew/lib/data/base/DataSlot.scala b/src/net/bdew/lib/data/base/DataSlot.scala index b199c95..1253b00 100644 --- a/src/net/bdew/lib/data/base/DataSlot.scala +++ b/src/net/bdew/lib/data/base/DataSlot.scala @@ -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 diff --git a/src/net/bdew/lib/resource/DataSlotResource.scala b/src/net/bdew/lib/resource/DataSlotResource.scala index 8876c6f..dd07c1a 100644 --- a/src/net/bdew/lib/resource/DataSlotResource.scala +++ b/src/net/bdew/lib/resource/DataSlotResource.scala @@ -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