From 3de3e3aed1206ed152405a03f8f498b55f2e27dc Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 2 Nov 2014 21:18:55 +0800 Subject: [PATCH] Minor refactor in TileBattery --- .../archaic/fluid/tank/TileTank.scala | 32 +++++++++---------- .../electrical/battery/ItemBlockBattery.scala | 2 +- .../electrical/battery/RenderBattery.scala | 2 +- .../electrical/battery/TileBattery.scala | 24 +++++++++----- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/main/scala/resonantinduction/archaic/fluid/tank/TileTank.scala b/src/main/scala/resonantinduction/archaic/fluid/tank/TileTank.scala index 7e9f474f6..02a9d2f76 100644 --- a/src/main/scala/resonantinduction/archaic/fluid/tank/TileTank.scala +++ b/src/main/scala/resonantinduction/archaic/fluid/tank/TileTank.scala @@ -35,26 +35,26 @@ object TileTank { def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*) { - GL11.glPushMatrix + GL11.glPushMatrix() RenderBlockUtility.tessellateBlockWithConnectedTextures(itemStack.getItemDamage, ArchaicContent.blockTank, null, RenderUtility.getIcon(Reference.prefix + "tankEdge")) - GL11.glPopMatrix - GL11.glPushMatrix + GL11.glPopMatrix() + GL11.glPushMatrix() if (itemStack.getTagCompound != null && itemStack.getTagCompound.hasKey("fluid")) { renderTank(0, 0, 0, FluidStack.loadFluidStackFromNBT(itemStack.getTagCompound.getCompoundTag("fluid")), VOLUME * FluidContainerRegistry.BUCKET_VOLUME) } - GL11.glPopMatrix + GL11.glPopMatrix() } def renderTank(x: Double, y: Double, z: Double, fluid: FluidStack, capacity: Int) { val tank: FluidTank = new FluidTank(fluid, capacity) - GL11.glPushMatrix + GL11.glPushMatrix() GL11.glTranslated(0.02, 0.02, 0.02) GL11.glScaled(0.92, 0.92, 0.92) if (fluid != null) { - GL11.glPushMatrix + GL11.glPushMatrix() if (!fluid.getFluid.isGaseous) { val percentageFilled: Double = tank.getFluidAmount.asInstanceOf[Double] / tank.getCapacity.asInstanceOf[Double] @@ -69,16 +69,16 @@ object TileTank GL11.glEnable(GL11.GL_BLEND) GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) val color: Color = new Color(fluid.getFluid.getColor) - RenderUtility.enableBlending + RenderUtility.enableBlending() GL11.glColor4d(color.getRed / 255f, color.getGreen / 255f, color.getBlue / 255f, if (fluid.getFluid.isGaseous) filledPercentage else 1) RenderUtility.bind(FluidRenderUtility.getFluidSheet(fluid)) FluidRenderUtility.renderFluidTesselation(tank, 1, 1, 1, 1) - RenderUtility.disableBlending - GL11.glPopAttrib + RenderUtility.disableBlending() + GL11.glPopAttrib() } - GL11.glPopMatrix + GL11.glPopMatrix() } - GL11.glPopMatrix + GL11.glPopMatrix() } } @@ -129,11 +129,11 @@ class TileTank extends TileTankNode(Material.iron) with ISneakPickup { if (world != null) { - GL11.glPushMatrix + GL11.glPushMatrix() GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) if (fluid != null) { - GL11.glPushMatrix + GL11.glPushMatrix() if (!fluid.getFluid.isGaseous) { GL11.glScaled(0.99, 0.99, 0.99) @@ -145,15 +145,15 @@ class TileTank extends TileTankNode(Material.iron) with ISneakPickup val yNorthWest: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, asVector3, ForgeDirection.NORTH, ForgeDirection.WEST) FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest) } - GL11.glPopMatrix + GL11.glPopMatrix() } - GL11.glPopMatrix + GL11.glPopMatrix() } } def getRemovedItems(entity: EntityPlayer): List[ItemStack] = { - val drops: List[ItemStack] = new ArrayList[ItemStack] + val drops = new ArrayList[ItemStack] val itemStack: ItemStack = new ItemStack(ArchaicContent.blockTank, 1, 0) if (itemStack != null) { diff --git a/src/main/scala/resonantinduction/electrical/battery/ItemBlockBattery.scala b/src/main/scala/resonantinduction/electrical/battery/ItemBlockBattery.scala index 1c6a7e1ad..ffdccce47 100644 --- a/src/main/scala/resonantinduction/electrical/battery/ItemBlockBattery.scala +++ b/src/main/scala/resonantinduction/electrical/battery/ItemBlockBattery.scala @@ -144,7 +144,7 @@ class ItemBlockBattery(block: Block) extends ItemBlock(block) with IEnergyItem @SuppressWarnings(Array("unchecked")) override def getSubItems(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_]) { - for (tier <- 0 to TileBattery.MAX_TIER) + for (tier <- 0 to TileBattery.maxTier) { par3List.add(Compatibility.getItemWithCharge(ItemBlockBattery.setTier(new ItemStack(this), tier.asInstanceOf[Byte]), 0)) par3List.add(Compatibility.getItemWithCharge(ItemBlockBattery.setTier(new ItemStack(this), tier.asInstanceOf[Byte]), TileBattery.getEnergyForTier(tier))) diff --git a/src/main/scala/resonantinduction/electrical/battery/RenderBattery.scala b/src/main/scala/resonantinduction/electrical/battery/RenderBattery.scala index 6a44073be..c1cccf79a 100644 --- a/src/main/scala/resonantinduction/electrical/battery/RenderBattery.scala +++ b/src/main/scala/resonantinduction/electrical/battery/RenderBattery.scala @@ -64,7 +64,7 @@ import resonant.lib.transform.vector.Vector3 GL11.glPushMatrix GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) val tile: TileBattery = t.asInstanceOf[TileBattery] - val energyLevel: Int = Math.round((tile.energy.getEnergy.asInstanceOf[Double] / TileBattery.getEnergyForTier(tile.getBlockMetadata).asInstanceOf[Double]) * 8).asInstanceOf[Int] + val energyLevel: Int = Math.round((tile.energy.getEnergy / TileBattery.getEnergyForTier(tile.getBlockMetadata).asInstanceOf[Double]) * 8).asInstanceOf[Int] RenderUtility.bind(Reference.domain, Reference.modelPath + "battery/battery.png") val disabledParts: List[String] = new ArrayList[String] val enabledParts: List[String] = new ArrayList[String] diff --git a/src/main/scala/resonantinduction/electrical/battery/TileBattery.scala b/src/main/scala/resonantinduction/electrical/battery/TileBattery.scala index 181944265..f828e8321 100644 --- a/src/main/scala/resonantinduction/electrical/battery/TileBattery.scala +++ b/src/main/scala/resonantinduction/electrical/battery/TileBattery.scala @@ -8,8 +8,9 @@ import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack import net.minecraftforge.common.util.ForgeDirection +import resonant.api.electric.EnergyStorage import resonant.content.prefab.java.TileAdvanced -import resonant.lib.content.prefab.{TEnergyStorage, TElectric} +import resonant.lib.content.prefab.{TElectric, TEnergyStorage} import resonant.lib.network.discriminator.{PacketTile, PacketType} import resonant.lib.network.handle.IPacketReceiver import resonant.lib.network.netty.AbstractPacket @@ -27,13 +28,13 @@ object TileBattery */ def getEnergyForTier(tier: Int): Long = { - return Math.round(Math.pow(500000000, (tier / (MAX_TIER + 0.7f)) + 1) / (500000000)) * (500000000) + return Math.round(Math.pow(500000000, (tier / (maxTier + 0.7f)) + 1) / (500000000)) * (500000000) } /** Tiers: 0, 1, 2 */ - final val MAX_TIER: Int = 2 + final val maxTier: Int = 2 /** The transfer rate **/ - final val DEFAULT_WATTAGE: Long = getEnergyForTier(0) + final val defaultPower: Long = getEnergyForTier(0) } class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacketReceiver with TEnergyStorage @@ -42,7 +43,7 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke private var markDistributionUpdate: Boolean = false var renderEnergyAmount: Double = 0 - //Constructor + energy = new EnergyStorage textureName = "material_metal_side" ioMap = 0 saveIOMap = true @@ -50,6 +51,8 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke isOpaqueCube = false itemBlock = classOf[ItemBlockBattery] + var doCharge = false + override def update() { super.update() @@ -59,7 +62,6 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke //TODO: Test, remove this if (doCharge) { - dcNode.positiveTerminals.addAll(getOutputDirections()) dcNode.buffer(100) doCharge = false } @@ -76,8 +78,6 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke } } - var doCharge = false - override def activate(player: EntityPlayer, side: Int, hit: Vector3): Boolean = { super.activate(player, side, hit) @@ -95,6 +95,14 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke return true } + override def toggleIO(side: Int, entityPlayer: EntityPlayer): Boolean = + { + val res = super.toggleIO(side, entityPlayer) + dcNode.positiveTerminals.clear() + dcNode.positiveTerminals.addAll(getOutputDirections()) + return res + } + override def getDescPacket: AbstractPacket = { return new PacketTile(this, Array[Any](renderEnergyAmount, ioMap))