Minor refactor in TileBattery

This commit is contained in:
Calclavia 2014-11-02 21:18:55 +08:00
parent bece427c1e
commit 3de3e3aed1
4 changed files with 34 additions and 26 deletions

View file

@ -35,26 +35,26 @@ object TileTank
{ {
def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*) 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")) RenderBlockUtility.tessellateBlockWithConnectedTextures(itemStack.getItemDamage, ArchaicContent.blockTank, null, RenderUtility.getIcon(Reference.prefix + "tankEdge"))
GL11.glPopMatrix GL11.glPopMatrix()
GL11.glPushMatrix GL11.glPushMatrix()
if (itemStack.getTagCompound != null && itemStack.getTagCompound.hasKey("fluid")) if (itemStack.getTagCompound != null && itemStack.getTagCompound.hasKey("fluid"))
{ {
renderTank(0, 0, 0, FluidStack.loadFluidStackFromNBT(itemStack.getTagCompound.getCompoundTag("fluid")), VOLUME * FluidContainerRegistry.BUCKET_VOLUME) 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) def renderTank(x: Double, y: Double, z: Double, fluid: FluidStack, capacity: Int)
{ {
val tank: FluidTank = new FluidTank(fluid, capacity) val tank: FluidTank = new FluidTank(fluid, capacity)
GL11.glPushMatrix GL11.glPushMatrix()
GL11.glTranslated(0.02, 0.02, 0.02) GL11.glTranslated(0.02, 0.02, 0.02)
GL11.glScaled(0.92, 0.92, 0.92) GL11.glScaled(0.92, 0.92, 0.92)
if (fluid != null) if (fluid != null)
{ {
GL11.glPushMatrix GL11.glPushMatrix()
if (!fluid.getFluid.isGaseous) if (!fluid.getFluid.isGaseous)
{ {
val percentageFilled: Double = tank.getFluidAmount.asInstanceOf[Double] / tank.getCapacity.asInstanceOf[Double] val percentageFilled: Double = tank.getFluidAmount.asInstanceOf[Double] / tank.getCapacity.asInstanceOf[Double]
@ -69,16 +69,16 @@ object TileTank
GL11.glEnable(GL11.GL_BLEND) GL11.glEnable(GL11.GL_BLEND)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
val color: Color = new Color(fluid.getFluid.getColor) 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) GL11.glColor4d(color.getRed / 255f, color.getGreen / 255f, color.getBlue / 255f, if (fluid.getFluid.isGaseous) filledPercentage else 1)
RenderUtility.bind(FluidRenderUtility.getFluidSheet(fluid)) RenderUtility.bind(FluidRenderUtility.getFluidSheet(fluid))
FluidRenderUtility.renderFluidTesselation(tank, 1, 1, 1, 1) FluidRenderUtility.renderFluidTesselation(tank, 1, 1, 1, 1)
RenderUtility.disableBlending RenderUtility.disableBlending()
GL11.glPopAttrib 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) if (world != null)
{ {
GL11.glPushMatrix GL11.glPushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
if (fluid != null) if (fluid != null)
{ {
GL11.glPushMatrix GL11.glPushMatrix()
if (!fluid.getFluid.isGaseous) if (!fluid.getFluid.isGaseous)
{ {
GL11.glScaled(0.99, 0.99, 0.99) 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) val yNorthWest: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, asVector3, ForgeDirection.NORTH, ForgeDirection.WEST)
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest) FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest)
} }
GL11.glPopMatrix GL11.glPopMatrix()
} }
GL11.glPopMatrix GL11.glPopMatrix()
} }
} }
def getRemovedItems(entity: EntityPlayer): List[ItemStack] = 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) val itemStack: ItemStack = new ItemStack(ArchaicContent.blockTank, 1, 0)
if (itemStack != null) if (itemStack != null)
{ {

View file

@ -144,7 +144,7 @@ class ItemBlockBattery(block: Block) extends ItemBlock(block) with IEnergyItem
@SuppressWarnings(Array("unchecked")) @SuppressWarnings(Array("unchecked"))
override def getSubItems(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_]) 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]), 0))
par3List.add(Compatibility.getItemWithCharge(ItemBlockBattery.setTier(new ItemStack(this), tier.asInstanceOf[Byte]), TileBattery.getEnergyForTier(tier))) par3List.add(Compatibility.getItemWithCharge(ItemBlockBattery.setTier(new ItemStack(this), tier.asInstanceOf[Byte]), TileBattery.getEnergyForTier(tier)))

View file

@ -64,7 +64,7 @@ import resonant.lib.transform.vector.Vector3
GL11.glPushMatrix GL11.glPushMatrix
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
val tile: TileBattery = t.asInstanceOf[TileBattery] 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") RenderUtility.bind(Reference.domain, Reference.modelPath + "battery/battery.png")
val disabledParts: List[String] = new ArrayList[String] val disabledParts: List[String] = new ArrayList[String]
val enabledParts: List[String] = new ArrayList[String] val enabledParts: List[String] = new ArrayList[String]

View file

@ -8,8 +8,9 @@ import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
import resonant.api.electric.EnergyStorage
import resonant.content.prefab.java.TileAdvanced 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.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.IPacketReceiver import resonant.lib.network.handle.IPacketReceiver
import resonant.lib.network.netty.AbstractPacket import resonant.lib.network.netty.AbstractPacket
@ -27,13 +28,13 @@ object TileBattery
*/ */
def getEnergyForTier(tier: Int): Long = 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 */ /** Tiers: 0, 1, 2 */
final val MAX_TIER: Int = 2 final val maxTier: Int = 2
/** The transfer rate **/ /** 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 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 private var markDistributionUpdate: Boolean = false
var renderEnergyAmount: Double = 0 var renderEnergyAmount: Double = 0
//Constructor energy = new EnergyStorage
textureName = "material_metal_side" textureName = "material_metal_side"
ioMap = 0 ioMap = 0
saveIOMap = true saveIOMap = true
@ -50,6 +51,8 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke
isOpaqueCube = false isOpaqueCube = false
itemBlock = classOf[ItemBlockBattery] itemBlock = classOf[ItemBlockBattery]
var doCharge = false
override def update() override def update()
{ {
super.update() super.update()
@ -59,7 +62,6 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke
//TODO: Test, remove this //TODO: Test, remove this
if (doCharge) if (doCharge)
{ {
dcNode.positiveTerminals.addAll(getOutputDirections())
dcNode.buffer(100) dcNode.buffer(100)
doCharge = false 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 = override def activate(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{ {
super.activate(player, side, hit) super.activate(player, side, hit)
@ -95,6 +95,14 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke
return true 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 = override def getDescPacket: AbstractPacket =
{ {
return new PacketTile(this, Array[Any](renderEnergyAmount, ioMap)) return new PacketTile(this, Array[Any](renderEnergyAmount, ioMap))