Refactored and converted some classes to Scala

This commit is contained in:
Calclavia 2015-01-11 14:18:21 +08:00
parent 791dc832a9
commit 95cc5a3405
12 changed files with 146 additions and 146 deletions

View file

@ -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

View file

@ -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
}
}

View file

@ -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.

View file

@ -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)

View file

@ -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)
{

View file

@ -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)

View file

@ -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 =

View file

@ -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 =

View file

@ -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)

View file

@ -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")

View file

@ -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)

View file

@ -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 =