From 95cc5a3405e8ec10cf8c4ecd162341c043dfc5c2 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 11 Jan 2015 14:18:21 +0800 Subject: [PATCH] Refactored and converted some classes to Scala --- .../archaic/blocks/TileImprinter.scala | 56 ++++++++--------- .../archaic/crate/TileCrate.scala | 46 +++++++------- .../engineering/TileEngineeringTable.scala | 60 +++++++++---------- .../archaic/firebox/TileFirebox.scala | 16 ++--- .../archaic/process/TileMillstone.scala | 14 ++--- .../archaic/process/mixing/TileGlassJar.scala | 30 +++++----- .../machine/boiler/TileNuclearBoiler.scala | 2 +- .../extractor/TileChemicalExtractor.scala | 2 +- .../machine/plasma/TilePlasmaHeater.scala | 58 +++++++++--------- .../core/ResonantInduction.scala | 2 +- .../core/util/ResonantUtil.scala | 2 +- .../mechanical/machine/TileDetector.scala | 4 +- 12 files changed, 146 insertions(+), 146 deletions(-) diff --git a/src/main/scala/resonantinduction/archaic/blocks/TileImprinter.scala b/src/main/scala/resonantinduction/archaic/blocks/TileImprinter.scala index c905262f0..b199494aa 100644 --- a/src/main/scala/resonantinduction/archaic/blocks/TileImprinter.scala +++ b/src/main/scala/resonantinduction/archaic/blocks/TileImprinter.scala @@ -37,7 +37,7 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory { val nbt: NBTTagCompound = new NBTTagCompound this.writeToNBT(nbt) - return ResonantEngine.instance.packetHandler.toMCPacket(new PacketTile(this, nbt)) + return ResonantEngine.packetHandler.toMCPacket(new PacketTile(this, nbt)) } /** @@ -61,6 +61,16 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory nbt.setTag("Items", var2) } + def getSizeInventory: Int = + { + return this.inventory.length + } + + def getStackInSlot(slot: Int): ItemStack = + { + return this.inventory(slot) + } + def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType) { try @@ -97,6 +107,18 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory } + /** + * Sets the given item stack to the specified slot in the inventory (can be crafting or armor + * sections). + */ + def setInventorySlotContents(slot: Int, itemStack: ItemStack) + { + if (slot < this.getSizeInventory) + { + inventory(slot) = itemStack + } + } + /** * Inventory methods. */ @@ -142,28 +164,6 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory } } - /** - * Sets the given item stack to the specified slot in the inventory (can be crafting or armor - * sections). - */ - def setInventorySlotContents(slot: Int, itemStack: ItemStack) - { - if (slot < this.getSizeInventory) - { - inventory(slot) = itemStack - } - } - - def getSizeInventory: Int = - { - return this.inventory.length - } - - def getStackInSlot(slot: Int): ItemStack = - { - return this.inventory(slot) - } - /** * When some containers are closed they call this on each slot, then drop whatever it returns as * an EntityItem - like when you close a workbench GUI. @@ -187,11 +187,6 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory this.onInventoryChanged } - def closeInventory - { - this.onInventoryChanged - } - /** * Updates all the output slots. Call this to update the Imprinter. */ @@ -250,6 +245,11 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory } } + def closeInventory + { + this.onInventoryChanged + } + def getInventoryStackLimit: Int = { return 64 diff --git a/src/main/scala/resonantinduction/archaic/crate/TileCrate.scala b/src/main/scala/resonantinduction/archaic/crate/TileCrate.scala index bfe6aae8f..856634d7b 100644 --- a/src/main/scala/resonantinduction/archaic/crate/TileCrate.scala +++ b/src/main/scala/resonantinduction/archaic/crate/TileCrate.scala @@ -77,6 +77,23 @@ class TileCrate extends TileInventory(Material.rock) with TPacketReceiver with T } } + override def writeToNBT(nbt: NBTTagCompound) + { + super.writeToNBT(nbt) + this.buildSampleStack(false) + val stack: ItemStack = this.getSampleStack + if (stack != null) + { + nbt.setInteger("Count", stack.stackSize) + nbt.setTag("stack", stack.writeToNBT(new NBTTagCompound)) + } + nbt.setBoolean("oreFilter", this.oreFilterEnabled) + if (this.filterStack != null) + { + nbt.setTag("filter", filterStack.writeToNBT(new NBTTagCompound)) + } + } + def addStackToStorage(stack: ItemStack): ItemStack = { return BlockCrate.addStackToCrate(this, stack) @@ -142,6 +159,11 @@ class TileCrate extends TileInventory(Material.rock) with TPacketReceiver with T } } + override def onInventoryChanged + { + if (worldObj != null && !worldObj.isRemote) doUpdate = true + } + override def canStore(stack: ItemStack, slot: Int, side: ForgeDirection): Boolean = { return getSampleStack == null || stack != null && (stack.isItemEqual(getSampleStack) || (this.oreFilterEnabled && OreDictionary.getOreID(getSampleStack) == OreDictionary.getOreID(stack))) @@ -175,7 +197,7 @@ class TileCrate extends TileInventory(Material.rock) with TPacketReceiver with T /** * Override this method - * Be sure to super this method or manually write the ID into the packet when sending + * Be sure to super this method or manually write the id into the packet when sending */ override def write(buf: ByteBuf, id: Int) { @@ -224,23 +246,6 @@ class TileCrate extends TileInventory(Material.rock) with TPacketReceiver with T } } - override def writeToNBT(nbt: NBTTagCompound) - { - super.writeToNBT(nbt) - this.buildSampleStack(false) - val stack: ItemStack = this.getSampleStack - if (stack != null) - { - nbt.setInteger("Count", stack.stackSize) - nbt.setTag("stack", stack.writeToNBT(new NBTTagCompound)) - } - nbt.setBoolean("oreFilter", this.oreFilterEnabled) - if (this.filterStack != null) - { - nbt.setTag("filter", filterStack.writeToNBT(new NBTTagCompound)) - } - } - def getRemovedItems(entity: EntityPlayer): List[ItemStack] = { val list = new util.ArrayList[ItemStack]() @@ -327,9 +332,4 @@ class TileCrate extends TileInventory(Material.rock) with TPacketReceiver with T this.filterStack = filter this.onInventoryChanged } - - override def onInventoryChanged - { - if (worldObj != null && !worldObj.isRemote) doUpdate = true - } } \ No newline at end of file diff --git a/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.scala b/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.scala index 57ba3a4be..f2ad2ae4b 100644 --- a/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.scala +++ b/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.scala @@ -307,7 +307,7 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece { val nbt: NBTTagCompound = new NBTTagCompound this.writeToNBT(nbt) - return ResonantEngine.instance.packetHandler.toMCPacket(new PacketTile(this, nbt)) + return ResonantEngine.packetHandler.toMCPacket(new PacketTile(this, nbt)) } /** @@ -370,6 +370,11 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece return null } + override def getSizeInventory: Int = + { + return 10 + (if (this.invPlayer != null) this.invPlayer.getSizeInventory else 0) + } + def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType) { try @@ -408,9 +413,31 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece this.searchInventories = nbt.getBoolean("searchInventories") } - override def getSizeInventory: Int = + override def decrStackSize(i: Int, amount: Int): ItemStack = { - return 10 + (if (this.invPlayer != null) this.invPlayer.getSizeInventory else 0) + if (getStackInSlot(i) != null) + { + var stack: ItemStack = null + if (getStackInSlot(i).stackSize <= amount) + { + stack = getStackInSlot(i) + setInventorySlotContents(i, null) + return stack + } + else + { + stack = getStackInSlot(i).splitStack(amount) + if (getStackInSlot(i).stackSize == 0) + { + setInventorySlotContents(i, null) + } + return stack + } + } + else + { + return null + } } override def setInventorySlotContents(slot: Int, itemStack: ItemStack) @@ -531,33 +558,6 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece return inventoryCrafting } - override def decrStackSize(i: Int, amount: Int): ItemStack = - { - if (getStackInSlot(i) != null) - { - var stack: ItemStack = null - if (getStackInSlot(i).stackSize <= amount) - { - stack = getStackInSlot(i) - setInventorySlotContents(i, null) - return stack - } - else - { - stack = getStackInSlot(i).splitStack(amount) - if (getStackInSlot(i).stackSize == 0) - { - setInventorySlotContents(i, null) - } - return stack - } - } - else - { - return null - } - } - /** * When some containers are closed they call this on each slot, then drop whatever it returns as * an EntityItem - like when you close a workbench GUI. diff --git a/src/main/scala/resonantinduction/archaic/firebox/TileFirebox.scala b/src/main/scala/resonantinduction/archaic/firebox/TileFirebox.scala index c12337156..a9e2bfbd9 100644 --- a/src/main/scala/resonantinduction/archaic/firebox/TileFirebox.scala +++ b/src/main/scala/resonantinduction/archaic/firebox/TileFirebox.scala @@ -159,11 +159,6 @@ class TileFirebox extends SpatialTile(Material.rock) with IFluidHandler with TIn return this.getBlockMetadata == 1 } - def canBurn(stack: ItemStack): Boolean = - { - return TileEntityFurnace.getItemBurnTime(stack) > 0 - } - override def randomDisplayTick(): Unit = { if (isBurning) @@ -189,8 +184,6 @@ class TileFirebox extends SpatialTile(Material.rock) with IFluidHandler with TIn } } - def isBurning: Boolean = burnTime > 0 - override def getSizeInventory = 1 def getMeltIronEnergy(volume: Float): Long = @@ -205,9 +198,14 @@ class TileFirebox extends SpatialTile(Material.rock) with IFluidHandler with TIn return i == 0 && canBurn(itemStack) } + def canBurn(stack: ItemStack): Boolean = + { + return TileEntityFurnace.getItemBurnTime(stack) > 0 + } + /** * Override this method - * Be sure to super this method or manually write the ID into the packet when sending + * Be sure to super this method or manually write the id into the packet when sending */ override def write(buf: ByteBuf, id: Int) { @@ -295,6 +293,8 @@ class TileFirebox extends SpatialTile(Material.rock) with IFluidHandler with TIn return if (isBurning) (if (isElectric) SpatialBlock.icon.get("firebox_electric_side_on") else SpatialBlock.icon.get("firebox_side_on")) else (if (isElectric) SpatialBlock.icon.get("firebox_electric_side_off") else SpatialBlock.icon.get("firebox_side_off")) } + def isBurning: Boolean = burnTime > 0 + override def click(player: EntityPlayer) { if (server) diff --git a/src/main/scala/resonantinduction/archaic/process/TileMillstone.scala b/src/main/scala/resonantinduction/archaic/process/TileMillstone.scala index 5d051862b..1742a29cd 100644 --- a/src/main/scala/resonantinduction/archaic/process/TileMillstone.scala +++ b/src/main/scala/resonantinduction/archaic/process/TileMillstone.scala @@ -68,12 +68,6 @@ class TileMillstone extends TileInventory(Material.rock) with TPacketSender with } } - override def onInventoryChanged - { - grindCount = 0 - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord) - } - override def use(player: EntityPlayer, hitSide: Int, hit: Vector3): Boolean = { val current: ItemStack = player.inventory.getCurrentItem @@ -120,6 +114,12 @@ class TileMillstone extends TileInventory(Material.rock) with TPacketSender with } } + override def onInventoryChanged + { + grindCount = 0 + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord) + } + override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean = { return MachineRecipes.instance.getOutput(RecipeType.GRINDER.name, itemStack).length > 0 @@ -131,7 +131,7 @@ class TileMillstone extends TileInventory(Material.rock) with TPacketSender with /** * Override this method - * Be sure to super this method or manually write the ID into the packet when sending + * Be sure to super this method or manually write the id into the packet when sending */ override def write(buf: ByteBuf, id: Int) { diff --git a/src/main/scala/resonantinduction/archaic/process/mixing/TileGlassJar.scala b/src/main/scala/resonantinduction/archaic/process/mixing/TileGlassJar.scala index a3daec680..28a49dbb8 100644 --- a/src/main/scala/resonantinduction/archaic/process/mixing/TileGlassJar.scala +++ b/src/main/scala/resonantinduction/archaic/process/mixing/TileGlassJar.scala @@ -51,7 +51,7 @@ class TileGlassJar extends SpatialTile(Material.wood) with TPacketReceiver with /** * Override this method - * Be sure to super this method or manually write the ID into the packet when sending + * Be sure to super this method or manually write the id into the packet when sending */ override def write(buf: ByteBuf, id: Int) { @@ -90,6 +90,20 @@ class TileGlassJar extends SpatialTile(Material.wood) with TPacketReceiver with GL11.glPopMatrix() } + @SideOnly(Side.CLIENT) + override def renderDynamic(pos: Vector3, frame: Float, pass: Int) + { + GL11.glPushMatrix() + GL11.glTranslated(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5) + renderMixture() + GL11.glPopMatrix() + + GL11.glPushMatrix() + GL11.glTranslated(pos.x + 0.5, pos.y + 0.8, pos.z + 0.5) + renderJar() + GL11.glPopMatrix() + } + def renderMixture(itemStack: ItemStack = null) { val mixture: Map[String, Int] = @@ -130,20 +144,6 @@ class TileGlassJar extends SpatialTile(Material.wood) with TPacketReceiver with RenderUtility.disableBlending() } - @SideOnly(Side.CLIENT) - override def renderDynamic(pos: Vector3, frame: Float, pass: Int) - { - GL11.glPushMatrix() - GL11.glTranslated(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5) - renderMixture() - GL11.glPopMatrix() - - GL11.glPushMatrix() - GL11.glTranslated(pos.x + 0.5, pos.y + 0.8, pos.z + 0.5) - renderJar() - GL11.glPopMatrix() - } - override protected def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean = { if (player.getCurrentEquippedItem != null) diff --git a/src/main/scala/resonantinduction/atomic/machine/boiler/TileNuclearBoiler.scala b/src/main/scala/resonantinduction/atomic/machine/boiler/TileNuclearBoiler.scala index 6a918e461..ff82607fe 100644 --- a/src/main/scala/resonantinduction/atomic/machine/boiler/TileNuclearBoiler.scala +++ b/src/main/scala/resonantinduction/atomic/machine/boiler/TileNuclearBoiler.scala @@ -183,7 +183,7 @@ class TileNuclearBoiler extends TileElectricInventory(Material.iron) with IPacke override def getDescriptionPacket: Packet = { - return ResonantEngine.instance.packetHandler.toMCPacket(getDescPacket) + return ResonantEngine.packetHandler.toMCPacket(getDescPacket) } override def getDescPacket: PacketTile = diff --git a/src/main/scala/resonantinduction/atomic/machine/extractor/TileChemicalExtractor.scala b/src/main/scala/resonantinduction/atomic/machine/extractor/TileChemicalExtractor.scala index 747535680..8953e6280 100644 --- a/src/main/scala/resonantinduction/atomic/machine/extractor/TileChemicalExtractor.scala +++ b/src/main/scala/resonantinduction/atomic/machine/extractor/TileChemicalExtractor.scala @@ -100,7 +100,7 @@ class TileChemicalExtractor extends TileProcess(Material.iron) with IFluidHandle override def getDescriptionPacket: Packet = { - return ResonantEngine.instance.packetHandler.toMCPacket(new PacketAnnotation(this)) + return ResonantEngine.packetHandler.toMCPacket(new PacketAnnotation(this)) } override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean = diff --git a/src/main/scala/resonantinduction/atomic/machine/plasma/TilePlasmaHeater.scala b/src/main/scala/resonantinduction/atomic/machine/plasma/TilePlasmaHeater.scala index 75a904f4f..ed51af216 100644 --- a/src/main/scala/resonantinduction/atomic/machine/plasma/TilePlasmaHeater.scala +++ b/src/main/scala/resonantinduction/atomic/machine/plasma/TilePlasmaHeater.scala @@ -12,14 +12,14 @@ import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.fluids._ import resonant.api.tile.ITagRender import resonant.engine.ResonantEngine +import resonant.lib.content.prefab.TEnergyStorage import resonant.lib.grid.energy.EnergyStorage import resonant.lib.mod.config.Config -import resonant.lib.content.prefab.TEnergyStorage import resonant.lib.network.discriminator.{PacketTile, PacketType} import resonant.lib.network.handle.IPacketReceiver import resonant.lib.prefab.tile.TileElectric -import resonant.lib.utility.science.UnitDisplay import resonant.lib.transform.vector.Vector3 +import resonant.lib.utility.science.UnitDisplay import resonant.lib.utility.{FluidUtility, LanguageUtility} import resonantinduction.atomic.AtomicContent @@ -72,7 +72,33 @@ class TilePlasmaHeater extends TileElectric(Material.iron) with IPacketReceiver { val nbt: NBTTagCompound = new NBTTagCompound writeToNBT(nbt) - return ResonantEngine.instance.packetHandler.toMCPacket(new PacketTile(this, nbt)) + return ResonantEngine.packetHandler.toMCPacket(new PacketTile(this, nbt)) + } + + /** + * Writes a tile entity to NBT. + */ + override def writeToNBT(nbt: NBTTagCompound) + { + super.writeToNBT(nbt) + if (tankInputDeuterium.getFluid != null) + { + val compound: NBTTagCompound = new NBTTagCompound + tankInputDeuterium.getFluid.writeToNBT(compound) + nbt.setTag("tankInputDeuterium", compound) + } + if (tankInputTritium.getFluid != null) + { + val compound: NBTTagCompound = new NBTTagCompound + tankInputTritium.getFluid.writeToNBT(compound) + nbt.setTag("tankInputTritium", compound) + } + if (tankOutput.getFluid != null) + { + val compound: NBTTagCompound = new NBTTagCompound + tankOutput.getFluid.writeToNBT(compound) + nbt.setTag("tankOutput", compound) + } } def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType) @@ -104,32 +130,6 @@ class TilePlasmaHeater extends TileElectric(Material.iron) with IPacketReceiver tankOutput.setFluid(FluidStack.loadFluidStackFromNBT(output)) } - /** - * Writes a tile entity to NBT. - */ - override def writeToNBT(nbt: NBTTagCompound) - { - super.writeToNBT(nbt) - if (tankInputDeuterium.getFluid != null) - { - val compound: NBTTagCompound = new NBTTagCompound - tankInputDeuterium.getFluid.writeToNBT(compound) - nbt.setTag("tankInputDeuterium", compound) - } - if (tankInputTritium.getFluid != null) - { - val compound: NBTTagCompound = new NBTTagCompound - tankInputTritium.getFluid.writeToNBT(compound) - nbt.setTag("tankInputTritium", compound) - } - if (tankOutput.getFluid != null) - { - val compound: NBTTagCompound = new NBTTagCompound - tankOutput.getFluid.writeToNBT(compound) - nbt.setTag("tankOutput", compound) - } - } - def addInformation(map: HashMap[String, Integer], player: EntityPlayer): Float = { if (energy != null) diff --git a/src/main/scala/resonantinduction/core/ResonantInduction.scala b/src/main/scala/resonantinduction/core/ResonantInduction.scala index 4160533ea..3badb20ed 100644 --- a/src/main/scala/resonantinduction/core/ResonantInduction.scala +++ b/src/main/scala/resonantinduction/core/ResonantInduction.scala @@ -25,7 +25,7 @@ import resonantinduction.mechanical.{MechanicalContent, MicroblockHighlightHandl final object ResonantInduction { /** Packets */ - val packetHandler = ResonantEngine.instance.packetHandler + val packetHandler = ResonantEngine.packetHandler val loadables = new LoadableHandler @SidedProxy(clientSide = "resonantinduction.core.ClientProxy", serverSide = "resonantinduction.core.CommonProxy") diff --git a/src/main/scala/resonantinduction/core/util/ResonantUtil.scala b/src/main/scala/resonantinduction/core/util/ResonantUtil.scala index c6148e077..61901f35e 100644 --- a/src/main/scala/resonantinduction/core/util/ResonantUtil.scala +++ b/src/main/scala/resonantinduction/core/util/ResonantUtil.scala @@ -18,7 +18,7 @@ object ResonantUtil } /** - * Gets the color hex code from the color's ID + * Gets the color hex code from the color's id */ def getColorHex(id: Int): Int = dyeColors(id) diff --git a/src/main/scala/resonantinduction/mechanical/machine/TileDetector.scala b/src/main/scala/resonantinduction/mechanical/machine/TileDetector.scala index 2c592eddb..656de4a22 100644 --- a/src/main/scala/resonantinduction/mechanical/machine/TileDetector.scala +++ b/src/main/scala/resonantinduction/mechanical/machine/TileDetector.scala @@ -84,7 +84,7 @@ class TileDetector extends TileFilterable with IPacketIDReceiver this.worldObj.notifyBlocksOfNeighborChange(x, this.yCoord + 1, z, MechanicalContent.blockDetector) } } - ResonantEngine.instance.packetHandler.sendToAllAround(new PacketTile(xi, yi, zi, Array[Any](0, this.isInverted)), this) + ResonantEngine.packetHandler.sendToAllAround(new PacketTile(xi, yi, zi, Array[Any](0, this.isInverted)), this) } } } @@ -110,7 +110,7 @@ class TileDetector extends TileFilterable with IPacketIDReceiver override def getDescriptionPacket: Packet = { - return ResonantEngine.instance.packetHandler.toMCPacket(new PacketTile(xi, yi, zi, Array[Any](0, this.isInverted))) + return ResonantEngine.packetHandler.toMCPacket(new PacketTile(xi, yi, zi, Array[Any](0, this.isInverted))) } override def read(data: ByteBuf, id: Int, player: EntityPlayer, `type`: PacketType): Boolean =