charger texture and fixed power distributor synchronization when the max failed as well as when there are multiple distributors in a network

This commit is contained in:
Florian Nücke 2013-11-26 21:41:43 +01:00
parent 643a25fc53
commit 7cf14ed7fd
3 changed files with 14 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

View File

@ -13,16 +13,22 @@ import net.minecraftforge.common.ForgeDirection
class Charger(val parent: SimpleDelegator) extends SimpleDelegate {
val unlocalizedName = "Charger"
var icon: Icon = null
private val icons = Array.fill[Icon](6)(null)
override def addInformation(player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
}
override def icon(side: ForgeDirection) = Some(icon)
override def icon(side: ForgeDirection) = Some(icons(side.ordinal()))
override def registerIcons(iconRegister: IconRegister) = {
icon = iconRegister.registerIcon(Settings.resourceDomain + ":charger")
icons(ForgeDirection.DOWN.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":case_top")
icons(ForgeDirection.UP.ordinal) = icons(ForgeDirection.DOWN.ordinal)
icons(ForgeDirection.NORTH.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":charger")
icons(ForgeDirection.SOUTH.ordinal) = icons(ForgeDirection.NORTH.ordinal)
icons(ForgeDirection.WEST.ordinal) = icons(ForgeDirection.NORTH.ordinal)
icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal)
}
override def hasTileEntity = true

View File

@ -18,7 +18,7 @@ class PowerDistributor(val owner: PowerInformation) extends ManagedComponent {
var globalBufferSize = 0.0
private var lastSentBuffer = 0.0
private var lastSentRatio = 0.0
private val buffers = mutable.Set.empty[Connector]
@ -170,7 +170,8 @@ class PowerDistributor(val owner: PowerInformation) extends ManagedComponent {
// Only send updates if the state changed by more than 5%, more won't be
// noticeable "from the outside" anyway. We send more frequent updates in
// the gui/container of a block that needs it (like robots).
val shouldSend = (lastSentBuffer - sumBuffer).abs > globalBufferSize * (5.0 / 100.0)
val fillRatio = sumBuffer / sumBufferSize
val shouldSend = (lastSentRatio - fillRatio).abs > (5.0 / 100.0)
for (distributor <- distributors) distributor.synchronized {
distributor.dirty = false
distributor.globalBuffer = sumBuffer
@ -178,8 +179,8 @@ class PowerDistributor(val owner: PowerInformation) extends ManagedComponent {
distributor.owner.globalBuffer = sumBuffer
distributor.owner.globalBufferSize = sumBufferSize
if (shouldSend) {
distributor.lastSentBuffer = sumBuffer
ServerPacketSender.sendPowerState(owner)
distributor.lastSentRatio = fillRatio
ServerPacketSender.sendPowerState(distributor.owner)
}
}
}