Merge branch 'development' of https://bitbucket.org/calclavia/resonant-induction into development

This commit is contained in:
Calclavia 2014-11-17 21:07:05 +08:00
commit 91322ed394
3 changed files with 251 additions and 239 deletions

View file

@ -88,12 +88,14 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece
isOpaqueCube(false)
itemBlock(classOf[ItemBlockSaved])
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
@SideOnly(Side.CLIENT)
override def getIcon(side: Int, meta: Int): IIcon =
{
return if (side == 1) TileEngineeringTable.iconTop else (if (side == meta) TileEngineeringTable.iconFront else TileEngineeringTable.iconSide)
}
@SideOnly(Side.CLIENT) override def registerIcons(iconRegister: IIconRegister)
@SideOnly(Side.CLIENT)
override def registerIcons(iconRegister: IIconRegister)
{
TileEngineeringTable.iconTop = iconRegister.registerIcon(getTextureName + "_top")
TileEngineeringTable.iconFront = iconRegister.registerIcon(getTextureName + "_front")

View file

@ -4,7 +4,6 @@ import java.util.List
import cpw.mods.fml.relauncher.{Side, SideOnly}
import io.netty.buffer.ByteBuf
import net.minecraft.block.Block
import net.minecraft.block.material.Material
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.creativetab.CreativeTabs
@ -19,13 +18,12 @@ import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.api.electric.EnergyStorage
import resonant.content.spatial.block.SpatialBlock
import resonant.content.spatial.block.{SpatialBlock, SpatialTile}
import resonant.engine.grid.thermal.{BoilEvent, ThermalPhysics}
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.content.prefab.java.TileElectricInventory
import resonant.lib.network.Synced
import resonant.lib.network.discriminator.{PacketAnnotation, PacketType}
import resonant.lib.network.handle.IPacketReceiver
import resonant.lib.content.prefab.{TElectric, TInventory}
import resonant.lib.network.ByteBufWrapper._
import resonant.lib.network.discriminator.PacketType
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
import resonant.lib.transform.vector.Vector3
import resonant.lib.utility.FluidUtility
import resonant.lib.wrapper.WrapList._
@ -36,7 +34,7 @@ import resonantinduction.core.Reference
*
* @author Calclavia
*/
class TileFirebox extends TileElectricInventory(Material.rock) with IPacketReceiver with IFluidHandler with TEnergyStorage
class TileFirebox extends SpatialTile(Material.rock) with IFluidHandler with TInventory with TElectric with TPacketSender with TPacketReceiver
{
/**
* 1KG of coal ~= 24MJ
@ -45,30 +43,32 @@ class TileFirebox extends TileElectricInventory(Material.rock) with IPacketRecei
* The power of the firebox in terms of thermal energy. The thermal energy can be transfered
* into fluids to increase their internal energy.
*/
private final val POWER: Long = 100000
private final val power: Long = 100000
protected var tank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
@Synced private var burnTime: Int = 0
private var burnTime: Int = 0
private var heatEnergy: Long = 0
private var boiledVolume: Int = 0
//TODO: Dummy
energy = new EnergyStorage(0)
energy.setCapacity(POWER)
energy.setMaxTransfer((POWER * 2) / 20)
val energy = new EnergyStorage(0)
energy.setCapacity(power)
energy.setMaxTransfer((power * 2) / 20)
setIO(ForgeDirection.UP, 0)
override def update
override def update()
{
super.update()
if (!worldObj.isRemote)
{
val drainFluid: FluidStack = tank.drain(FluidContainerRegistry.BUCKET_VOLUME, false)
val drainFluid = tank.drain(FluidContainerRegistry.BUCKET_VOLUME, false)
if (drainFluid != null && drainFluid.amount == FluidContainerRegistry.BUCKET_VOLUME && drainFluid.fluidID == FluidRegistry.LAVA.getID)
{
if (burnTime == 0)
{
tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true)
burnTime += 20000
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
sendPacket(0)
}
}
else if (isElectrical && energy.checkExtract)
@ -76,7 +76,7 @@ class TileFirebox extends TileElectricInventory(Material.rock) with IPacketRecei
energy.extractEnergy
if (burnTime == 0)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
sendPacket(0)
}
burnTime += 2
}
@ -86,17 +86,19 @@ class TileFirebox extends TileElectricInventory(Material.rock) with IPacketRecei
{
burnTime += TileEntityFurnace.getItemBurnTime(this.getStackInSlot(0))
decrStackSize(0, 1)
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
sendPacket(0)
}
}
val block: Block = worldObj.getBlock(xCoord, yCoord + 1, zCoord)
val block = worldObj.getBlock(xCoord, yCoord + 1, zCoord)
if (burnTime > 0)
{
if (block == null)
{
worldObj.setBlock(xCoord, yCoord + 1, zCoord, Blocks.fire)
}
heatEnergy += POWER / 20
heatEnergy += power / 20
var usedHeat: Boolean = false
if (block eq Blocks.water)
{
@ -121,21 +123,24 @@ class TileFirebox extends TileElectricInventory(Material.rock) with IPacketRecei
{
heatEnergy = 0
}
if (({
burnTime -= 1;
burnTime
}) == 0)
burnTime -= 1
if (burnTime == 0)
{
if (block eq Blocks.fire)
if (block == Blocks.fire)
{
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
sendPacket(0)
}
}
}
}
override def getSizeInventory = 1
/**
* Approximately 327600 + 2257000 = 2584600.
*
@ -174,14 +179,20 @@ class TileFirebox extends TileElectricInventory(Material.rock) with IPacketRecei
return i == 0 && canBurn(itemStack)
}
override def getDescPacket: PacketAnnotation =
/**
* Override this method
* Be sure to super this method or manually write the ID into the packet when sending
*/
override def write(buf: ByteBuf, id: Int)
{
return new PacketAnnotation(this)
super.write(buf, id)
buf <<< burnTime
}
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
override def read(buf: ByteBuf, id: Int, packetType: PacketType)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord)
super.read(buf, id, packetType)
markRender()
}
override def readFromNBT(nbt: NBTTagCompound)
@ -232,7 +243,8 @@ class TileFirebox extends TileElectricInventory(Material.rock) with IPacketRecei
return Array[FluidTankInfo](tank.getInfo)
}
@SideOnly(Side.CLIENT) override def registerIcons(iconReg: IIconRegister)
@SideOnly(Side.CLIENT)
override def registerIcons(iconReg: IIconRegister)
{
super.registerIcons(iconReg)
SpatialBlock.icon.put("firebox_side_on", iconReg.registerIcon(Reference.prefix + "firebox_side_on"))
@ -245,7 +257,8 @@ class TileFirebox extends TileElectricInventory(Material.rock) with IPacketRecei
SpatialBlock.icon.put("firebox_electric_top_off", iconReg.registerIcon(Reference.prefix + "firebox_electric_top_off"))
}
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
@SideOnly(Side.CLIENT)
override def getIcon(side: Int, meta: Int): IIcon =
{
if (side == 0)
{

View file

@ -11,15 +11,14 @@ import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.item.crafting.FurnaceRecipes
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.IIcon
import resonant.content.spatial.block.SpatialBlock
import resonant.lib.content.prefab.java.TileInventory
import resonant.lib.network.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.IPacketReceiver
import resonantinduction.core.Reference
import resonant.lib.transform.region.Cuboid
import resonant.lib.transform.vector.{Vector2, Vector3}
import resonantinduction.core.Reference
/**
* For smelting items.
@ -28,234 +27,232 @@ import resonant.lib.transform.vector.{Vector2, Vector3}
*/
object TileHotPlate
{
final val MAX_SMELT_TIME: Int = 200
final val MAX_SMELT_TIME: Int = 200
}
class TileHotPlate extends TileInventory(Material.iron) with IPacketReceiver
{
final val smeltTime: Array[Int] = Array[Int](0, 0, 0, 0)
final val stackSizeCache: Array[Int] = Array[Int](0, 0, 0, 0)
private final val POWER: Int = 50000
final val smeltTime: Array[Int] = Array[Int](0, 0, 0, 0)
final val stackSizeCache: Array[Int] = Array[Int](0, 0, 0, 0)
private final val POWER: Int = 50000
//Constructor
setSizeInventory(4)
bounds(new Cuboid(0, 0, 0, 1, 0.2f, 1))
normalRender(false)
forceStandardRender(true)
isOpaqueCube(false)
//Constructor
setSizeInventory(4)
bounds(new Cuboid(0, 0, 0, 1, 0.2f, 1))
forceItemToRenderAsBlock = true
isOpaqueCube = false
override def update
override def update()
{
super.update()
if (canRun)
{
if (canRun)
{
var didSmelt: Boolean = false
var didSmelt = false
for (i <- 0 to getSizeInventory)
{
if (canSmelt(this.getStackInSlot(i)))
{
if (smeltTime(i) <= 0)
{
stackSizeCache(i) = this.getStackInSlot(i).stackSize
smeltTime(i) = TileHotPlate.MAX_SMELT_TIME * stackSizeCache(i)
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
else if (smeltTime(i) > 0)
{
smeltTime(i) -= 1;
if (smeltTime(i) == 0)
{
if (!worldObj.isRemote)
{
val outputStack: ItemStack = FurnaceRecipes.smelting.getSmeltingResult(getStackInSlot(i)).copy
outputStack.stackSize = stackSizeCache(i)
setInventorySlotContents(i, outputStack)
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
}
}
didSmelt = true
}
else
{
smeltTime(i) = 0
}
}
}
}
override def onInventoryChanged
{
for (i <- 0 to getSizeInventory)
{
if (getStackInSlot(i) != null)
{
if (stackSizeCache(i) != getStackInSlot(i).stackSize)
{
if (smeltTime(i) > 0)
{
smeltTime(i) += (getStackInSlot(i).stackSize - stackSizeCache(i)) * TileHotPlate.MAX_SMELT_TIME
}
stackSizeCache(i) = getStackInSlot(i).stackSize
}
}
else
{
stackSizeCache(i) = 0
}
}
if (worldObj != null)
for (i <- 0 to getSizeInventory)
{
if (canSmelt(this.getStackInSlot(i)))
{
if (smeltTime(i) <= 0)
{
stackSizeCache(i) = this.getStackInSlot(i).stackSize
smeltTime(i) = TileHotPlate.MAX_SMELT_TIME * stackSizeCache(i)
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
}
def canRun: Boolean =
{
val tileEntity: TileEntity = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord)
if (tileEntity.isInstanceOf[TileFirebox])
{
if ((tileEntity.asInstanceOf[TileFirebox]).isBurning)
}
else if (smeltTime(i) > 0)
{
smeltTime(i) -= 1
if (smeltTime(i) == 0)
{
return true
if (!worldObj.isRemote)
{
val outputStack: ItemStack = FurnaceRecipes.smelting.getSmeltingResult(getStackInSlot(i)).copy
outputStack.stackSize = stackSizeCache(i)
setInventorySlotContents(i, outputStack)
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
}
}
didSmelt = true
}
return false
}
def canSmelt(stack: ItemStack): Boolean =
{
return FurnaceRecipes.smelting.getSmeltingResult(stack) != null
}
def isSmelting: Boolean =
{
else
{
var i: Int = 0
while (i < getSizeInventory)
{
{
if (getSmeltTime(i) > 0)
{
return true
}
}
({
i += 1;
i - 1
})
}
smeltTime(i) = 0
}
return false
}
}
}
def getSmeltTime(i: Int): Int =
override def onInventoryChanged()
{
for (i <- 0 until getSizeInventory)
{
return smeltTime(i)
}
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
{
return i < getSizeInventory && canSmelt(itemStack)
}
override def getDescPacket: PacketTile =
{
return new PacketTile(this, this.getPacketData(0).toArray)
}
/**
* 1 - Description Packet
* 2 - Energy Update
* 3 - Tesla Beam
*/
def getPacketData(`type`: Int): List[Any] =
{
val list: List[Any] = new ArrayList[Any]
val nbt: NBTTagCompound = new NBTTagCompound
this.writeToNBT(nbt)
list.add(nbt)
return list
}
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
{
try
if (getStackInSlot(i) != null)
{
if (stackSizeCache(i) != getStackInSlot(i).stackSize)
{
this.readFromNBT(ByteBufUtils.readTag(data))
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord)
if (smeltTime(i) > 0)
{
smeltTime(i) += (getStackInSlot(i).stackSize - stackSizeCache(i)) * TileHotPlate.MAX_SMELT_TIME
}
stackSizeCache(i) = getStackInSlot(i).stackSize
}
catch
{
case e: Exception =>
{
e.printStackTrace
}
}
}
else
{
stackSizeCache(i) = 0
}
}
override def readFromNBT(nbt: NBTTagCompound)
if (worldObj != null)
{
super.readFromNBT(nbt)
for (i <- 0 to getSizeInventory)
{
smeltTime(i) = nbt.getInteger("smeltTime" + i)
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
}
override def writeToNBT(nbt: NBTTagCompound)
def canRun: Boolean =
{
val tileEntity = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord)
if (tileEntity.isInstanceOf[TileFirebox])
{
super.writeToNBT(nbt)
for (i <- 0 to getSizeInventory)
{
nbt.setInteger("smeltTime" + i, smeltTime(i))
}
}
@SideOnly(Side.CLIENT) override def registerIcons(iconReg: IIconRegister)
{
super.registerIcons(iconReg)
SpatialBlock.icon.put("electricHotPlate", iconReg.registerIcon(Reference.prefix + "electricHotPlate"))
}
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
{
return if (meta == 1) SpatialBlock.icon.get("electricHotPlate") else SpatialBlock.icon.get(getTextureName)
}
override def click(player: EntityPlayer)
{
if (server)
{
extractItem(this, 0, player)
}
}
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
if (server)
{
val hitVector: Vector2 = new Vector2(hit.x, hit.z)
val regionLength: Double = 1d / 2d
var j: Int = 0
for (j <- 0 to 2)
{
for (k <- 0 to 2)
{
val check: Vector2 = new Vector2(j, k).multiply(regionLength)
if (check.distance(hitVector) < regionLength)
{
val slotID: Int = j * 2 + k
interactCurrentItem(this, slotID, player)
onInventoryChanged
return true
}
}
}
return false
}
if ((tileEntity.asInstanceOf[TileFirebox]).isBurning)
{
return true
}
}
return false
}
def canSmelt(stack: ItemStack): Boolean =
{
return FurnaceRecipes.smelting.getSmeltingResult(stack) != null
}
def isSmelting: Boolean =
{
for (i <- 0 until getSizeInventory)
{
if (getSmeltTime(i) > 0)
{
return true
}
}
return false
}
def getSmeltTime(i: Int): Int =
{
return smeltTime(i)
}
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
{
return i < getSizeInventory && canSmelt(itemStack)
}
override def getDescPacket: PacketTile =
{
return new PacketTile(this, this.getPacketData(0).toArray)
}
/**
* 1 - Description Packet
* 2 - Energy Update
* 3 - Tesla Beam
*/
def getPacketData(`type`: Int): List[Any] =
{
val list: List[Any] = new ArrayList[Any]
val nbt: NBTTagCompound = new NBTTagCompound
this.writeToNBT(nbt)
list.add(nbt)
return list
}
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
{
try
{
this.readFromNBT(ByteBufUtils.readTag(data))
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord)
}
catch
{
case e: Exception =>
{
e.printStackTrace
}
}
}
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
for (i <- 0 until getSizeInventory)
{
smeltTime(i) = nbt.getInteger("smeltTime" + i)
}
}
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
for (i <- 0 until getSizeInventory)
{
nbt.setInteger("smeltTime" + i, smeltTime(i))
}
}
@SideOnly(Side.CLIENT)
override def registerIcons(iconReg: IIconRegister)
{
super.registerIcons(iconReg)
SpatialBlock.icon.put("electricHotPlate", iconReg.registerIcon(Reference.prefix + "electricHotPlate"))
}
@SideOnly(Side.CLIENT)
override def getIcon(side: Int, meta: Int): IIcon =
{
return if (meta == 1) SpatialBlock.icon.get("electricHotPlate") else SpatialBlock.icon.get(getTextureName)
}
override def click(player: EntityPlayer)
{
if (server)
{
extractItem(this, 0, player)
}
}
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
if (server)
{
val hitVector: Vector2 = new Vector2(hit.x, hit.z)
val regionLength: Double = 1d / 2d
var j: Int = 0
for (j <- 0 until 2)
{
for (k <- 0 until 2)
{
val check = new Vector2(j, k) * regionLength
if (check.distance(hitVector) < regionLength)
{
val slotID = j * 2 + k
interactCurrentItem(this, slotID, player)
onInventoryChanged()
return true
}
}
}
return false
}
return true
}
}