electrodynamics/src/main/scala/edx/quantum/machine/centrifuge/TileCentrifuge.scala

268 lines
7.3 KiB
Scala
Raw Normal View History

2015-01-14 12:06:03 +01:00
package edx.quantum.machine.centrifuge
2014-09-29 21:26:25 +02:00
2015-01-14 12:06:03 +01:00
import edx.core.Settings
import edx.quantum.QuantumContent
2014-09-29 21:26:25 +02:00
import io.netty.buffer.ByteBuf
import net.minecraft.block.material.Material
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.inventory.IInventory
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
2015-01-26 13:17:04 +01:00
import resonantengine.api.network.IPacketReceiver
2015-01-26 13:28:38 +01:00
import resonantengine.core.network.discriminator.{PacketTile, PacketType}
2015-01-26 12:40:32 +01:00
import resonantengine.lib.content.prefab.{TIO, TInventory}
import resonantengine.lib.grid.energy.EnergyStorage
import resonantengine.lib.grid.energy.electric.NodeElectricComponent
import resonantengine.lib.mod.compat.energy.Compatibility
2015-01-26 13:28:38 +01:00
import resonantengine.lib.modcontent.block.ResonantTile
2015-01-26 12:40:32 +01:00
import resonantengine.lib.transform.vector.Vector3
import resonantengine.prefab.block.impl.{TBlockNodeProvider, TEnergyProvider, TRotatable}
2014-09-29 21:26:25 +02:00
/**
* Centrifuge TileEntity
*/
object TileCentrifuge
{
2014-11-02 13:56:11 +01:00
final val SHI_JIAN: Int = 20 * 60
final val DIAN: Long = 500000
2014-09-29 21:26:25 +02:00
}
2015-01-26 11:17:24 +01:00
class TileCentrifuge extends ResonantTile(Material.iron) with TInventory with TBlockNodeProvider with IPacketReceiver with IFluidHandler with IInventory with TEnergyProvider with TRotatable with TIO
2014-09-29 21:26:25 +02:00
{
2014-11-02 13:56:11 +01:00
val gasTank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 5)
2015-01-26 11:13:56 +01:00
private val electricNode = new NodeElectricComponent(this)
2014-11-02 13:56:11 +01:00
var timer: Int = 0
var rotation: Float = 0
2014-09-29 21:26:25 +02:00
2015-01-21 04:13:51 +01:00
energy = new EnergyStorage
2015-01-17 06:13:26 +01:00
isOpaqueCube = false
normalRender = false
2015-01-21 04:13:51 +01:00
energy.max = TileCentrifuge.DIAN * 2
2015-01-17 06:13:26 +01:00
override def getSizeInventory: Int = 4
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
override def update
{
super.update
if (timer > 0)
2014-09-29 21:26:25 +02:00
{
2014-11-02 13:56:11 +01:00
rotation += 0.45f
}
if (!this.worldObj.isRemote)
{
if (this.ticks % 20 == 0)
{
for (i <- 0 to 6)
2014-09-29 21:26:25 +02:00
{
2014-11-02 13:56:11 +01:00
val direction: ForgeDirection = ForgeDirection.getOrientation(i)
2021-04-05 14:41:30 +02:00
val tileEntity: TileEntity = toVectorWorld.add(direction).getTileEntity(world)
2014-11-02 13:56:11 +01:00
if (tileEntity.isInstanceOf[IFluidHandler] && tileEntity.getClass != this.getClass)
{
val fluidHandler: IFluidHandler = (tileEntity.asInstanceOf[IFluidHandler])
if (fluidHandler != null)
2014-09-29 21:26:25 +02:00
{
2015-01-24 10:38:01 +01:00
val requestFluid: FluidStack = QuantumContent.fluidStackUraniumHexaflouride
2015-01-14 12:06:03 +01:00
requestFluid.amount = this.gasTank.getCapacity - QuantumContent.getFluidAmount(this.gasTank.getFluid)
2014-11-02 13:56:11 +01:00
val receiveFluid: FluidStack = fluidHandler.drain(direction.getOpposite, requestFluid, true)
if (receiveFluid != null)
{
if (receiveFluid.amount > 0)
2014-09-29 21:26:25 +02:00
{
2014-11-02 13:56:11 +01:00
if (this.gasTank.fill(receiveFluid, false) > 0)
{
this.gasTank.fill(receiveFluid, true)
}
2014-09-29 21:26:25 +02:00
}
2014-11-02 13:56:11 +01:00
}
2014-09-29 21:26:25 +02:00
}
2014-11-02 13:56:11 +01:00
}
}
}
if (this.nengYong)
{
//discharge(getStackInSlot(0))
2015-01-21 04:13:51 +01:00
if (energy >= TileCentrifuge.DIAN)
2014-11-02 13:56:11 +01:00
{
if (this.timer == 0)
{
this.timer = TileCentrifuge.SHI_JIAN
}
if (this.timer > 0)
{
this.timer -= 1
if (this.timer < 1)
2014-09-29 21:26:25 +02:00
{
2014-11-02 13:56:11 +01:00
this.yong
this.timer = 0
2014-09-29 21:26:25 +02:00
}
2014-11-02 13:56:11 +01:00
}
else
{
this.timer = 0
}
2015-01-21 04:13:51 +01:00
energy -= TileCentrifuge.DIAN
2014-09-29 21:26:25 +02:00
}
2014-11-02 13:56:11 +01:00
}
else
{
this.timer = 0
}
if (this.ticks % 10 == 0)
{
}
2014-09-29 21:26:25 +02:00
}
2014-11-02 13:56:11 +01:00
}
2014-09-29 21:26:25 +02:00
2015-01-09 05:10:44 +01:00
/**
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
*/
def yong
2014-11-02 13:56:11 +01:00
{
2015-01-09 05:10:44 +01:00
if (this.nengYong)
{
this.gasTank.drain(Settings.uraniumHexaflourideRatio, true)
if (this.worldObj.rand.nextFloat > 0.6)
{
2015-01-14 12:06:03 +01:00
this.incrStackSize(2, new ItemStack(QuantumContent.itemUranium))
2015-01-09 05:10:44 +01:00
}
else
{
2015-01-14 12:06:03 +01:00
this.incrStackSize(3, new ItemStack(QuantumContent.itemUranium, 1, 1))
2015-01-09 05:10:44 +01:00
}
}
2014-11-02 13:56:11 +01:00
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
/**
* @return If the machine can be used.
*/
def nengYong: Boolean =
{
if (this.gasTank.getFluid != null)
2014-09-29 21:26:25 +02:00
{
2014-11-02 13:56:11 +01:00
if (this.gasTank.getFluid.amount >= Settings.uraniumHexaflourideRatio)
{
2015-01-14 12:06:03 +01:00
return isItemValidForSlot(2, new ItemStack(QuantumContent.itemUranium)) && isItemValidForSlot(3, new ItemStack(QuantumContent.itemUranium, 1, 1))
2014-11-02 13:56:11 +01:00
}
2014-09-29 21:26:25 +02:00
}
2014-11-02 13:56:11 +01:00
return false
}
2014-09-29 21:26:25 +02:00
2015-01-09 05:10:44 +01:00
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
2015-01-14 12:06:03 +01:00
openGui(player, QuantumContent)
2015-01-09 05:10:44 +01:00
return true
}
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
{
this.timer = data.readInt
2021-04-05 14:41:30 +02:00
this.gasTank.setFluid(new FluidStack(QuantumContent.fluidStackUraniumHexaflouride.getFluidID, data.readInt))
2015-01-09 05:10:44 +01:00
}
override def getDescPacket: PacketTile =
{
2021-04-05 14:41:30 +02:00
return new PacketTile(x.toInt, y.toInt, z.toInt, Array[Any](this.timer, QuantumContent.getFluidAmount(this.gasTank.getFluid)))
2014-11-02 13:56:11 +01:00
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
/**
* Reads a tile entity from NBT.
*/
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
this.timer = nbt.getInteger("smeltingTicks")
val compound: NBTTagCompound = nbt.getCompoundTag("gas")
this.gasTank.setFluid(FluidStack.loadFluidStackFromNBT(compound))
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
/**
* Writes a tile entity to NBT.
*/
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
nbt.setInteger("smeltingTicks", this.timer)
if (this.gasTank.getFluid != null)
2014-09-29 21:26:25 +02:00
{
2014-11-02 13:56:11 +01:00
val compound: NBTTagCompound = new NBTTagCompound
this.gasTank.getFluid.writeToNBT(compound)
nbt.setTag("gas", compound)
2014-09-29 21:26:25 +02:00
}
2014-11-02 13:56:11 +01:00
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
/**
* Tank Methods
*/
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
2015-01-24 10:38:01 +01:00
if (QuantumContent.fluidStackUraniumHexaflouride.isFluidEqual(resource))
2014-09-29 21:26:25 +02:00
{
2014-11-02 13:56:11 +01:00
return this.gasTank.fill(resource, doFill)
2014-09-29 21:26:25 +02:00
}
2014-11-02 13:56:11 +01:00
return 0
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
{
return null
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack =
{
return null
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
{
2021-04-05 14:41:30 +02:00
return QuantumContent.fluidStackUraniumHexaflouride.getFluidID == fluid.getID
2014-11-02 13:56:11 +01:00
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
{
return false
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] =
{
return Array[FluidTankInfo](this.gasTank.getInfo)
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
/**
* Inventory
*/
override def getAccessibleSlotsFromSide(side: Int): Array[Int] =
{
return if (side == 1) Array[Int](0, 1) else Array[Int](2, 3)
}
2014-09-29 21:26:25 +02:00
2014-11-02 13:56:11 +01:00
override def canInsertItem(slotID: Int, itemStack: ItemStack, side: Int): Boolean =
{
return slotID == 1 && this.isItemValidForSlot(slotID, itemStack)
}
2014-09-29 21:26:25 +02:00
2015-01-26 11:13:56 +01:00
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
{
i match
{
case 0 =>
return Compatibility.isHandler(itemStack.getItem, null)
case 1 =>
return true
case 2 =>
return itemStack.getItem eq QuantumContent.itemUranium
case 3 =>
return itemStack.getItem eq QuantumContent.itemUranium
}
return false
}
2014-11-02 13:56:11 +01:00
override def canExtractItem(slotID: Int, itemstack: ItemStack, j: Int): Boolean =
{
return slotID == 2 || slotID == 3
}
2021-04-05 14:41:30 +02:00
}