2014-09-29 21:26:25 +02:00
|
|
|
package resonantinduction.atomic.machine.centrifuge
|
|
|
|
|
|
|
|
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._
|
2014-11-02 13:56:11 +01:00
|
|
|
import resonant.api.electric.EnergyStorage
|
2014-11-02 12:33:59 +01:00
|
|
|
import resonant.lib.content.prefab.TEnergyStorage
|
2014-09-29 21:26:25 +02:00
|
|
|
import resonant.lib.content.prefab.java.TileElectricInventory
|
2014-10-27 18:31:42 +01:00
|
|
|
import resonant.lib.grid.Compatibility
|
2014-09-29 21:26:25 +02:00
|
|
|
import resonant.lib.network.discriminator.{PacketTile, PacketType}
|
|
|
|
import resonant.lib.network.handle.IPacketReceiver
|
2014-11-02 13:56:11 +01:00
|
|
|
import resonant.lib.transform.vector.Vector3
|
2014-10-05 02:14:55 +02:00
|
|
|
import resonantinduction.atomic.AtomicContent
|
2014-09-29 21:26:25 +02:00
|
|
|
import resonantinduction.core.Settings
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|
|
|
|
|
2014-11-02 12:33:59 +01:00
|
|
|
class TileCentrifuge extends TileElectricInventory(Material.iron) with IPacketReceiver with IFluidHandler with IInventory with TEnergyStorage
|
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)
|
|
|
|
var timer: Int = 0
|
|
|
|
var rotation: Float = 0
|
2014-09-29 21:26:25 +02:00
|
|
|
|
2014-11-02 13:56:11 +01:00
|
|
|
//TODO: Dummy
|
|
|
|
energy = new EnergyStorage(0)
|
|
|
|
isOpaqueCube(false)
|
|
|
|
normalRender(false)
|
|
|
|
energy.setCapacity(TileCentrifuge.DIAN * 2)
|
|
|
|
setSizeInventory(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)
|
|
|
|
val tileEntity: TileEntity = asVector3.add(direction).getTileEntity(world)
|
|
|
|
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
|
|
|
{
|
2014-11-02 13:56:11 +01:00
|
|
|
val requestFluid: FluidStack = AtomicContent.FLUIDSTACK_URANIUM_HEXAFLOURIDE
|
|
|
|
requestFluid.amount = this.gasTank.getCapacity - AtomicContent.getFluidAmount(this.gasTank.getFluid)
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
this.discharge(getStackInSlot(0))
|
|
|
|
if (energy.extractEnergy(TileCentrifuge.DIAN, false) >= TileCentrifuge.DIAN)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
}
|
|
|
|
energy.extractEnergy(TileCentrifuge.DIAN, true)
|
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
|
|
|
|
2014-11-02 13:56:11 +01:00
|
|
|
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
|
|
|
|
{
|
|
|
|
openGui(player, AtomicContent)
|
|
|
|
return true
|
|
|
|
}
|
2014-09-29 21:26:25 +02:00
|
|
|
|
2014-11-02 13:56:11 +01:00
|
|
|
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
|
|
|
|
{
|
|
|
|
this.timer = data.readInt
|
|
|
|
this.gasTank.setFluid(new FluidStack(AtomicContent.FLUIDSTACK_URANIUM_HEXAFLOURIDE.fluidID, data.readInt))
|
2014-10-08 01:01:08 +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
|
|
|
override def getDescPacket: PacketTile =
|
|
|
|
{
|
|
|
|
return new PacketTile(xi, yi, zi, Array[Any](this.timer, AtomicContent.getFluidAmount(this.gasTank.getFluid)))
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
return isItemValidForSlot(2, new ItemStack(AtomicContent.itemUranium)) && isItemValidForSlot(3, new ItemStack(AtomicContent.itemUranium, 1, 1))
|
|
|
|
}
|
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
|
|
|
|
2014-11-02 13:56:11 +01:00
|
|
|
/**
|
|
|
|
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
|
|
|
|
*/
|
|
|
|
def yong
|
|
|
|
{
|
|
|
|
if (this.nengYong)
|
2014-09-29 21:26:25 +02:00
|
|
|
{
|
2014-11-02 13:56:11 +01:00
|
|
|
this.gasTank.drain(Settings.uraniumHexaflourideRatio, true)
|
|
|
|
if (this.worldObj.rand.nextFloat > 0.6)
|
|
|
|
{
|
|
|
|
this.incrStackSize(2, new ItemStack(AtomicContent.itemUranium))
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.incrStackSize(3, new ItemStack(AtomicContent.itemUranium, 1, 1))
|
|
|
|
}
|
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
|
|
|
/**
|
|
|
|
* 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 =
|
|
|
|
{
|
|
|
|
if (AtomicContent.FLUIDSTACK_URANIUM_HEXAFLOURIDE.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 =
|
|
|
|
{
|
|
|
|
return AtomicContent.FLUIDSTACK_URANIUM_HEXAFLOURIDE.fluidID == fluid.getID
|
|
|
|
}
|
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
|
|
|
|
2014-11-02 13:56:11 +01:00
|
|
|
override def canExtractItem(slotID: Int, itemstack: ItemStack, j: Int): Boolean =
|
|
|
|
{
|
|
|
|
return slotID == 2 || slotID == 3
|
|
|
|
}
|
2014-09-29 21:26:25 +02:00
|
|
|
|
2014-11-02 13:56:11 +01:00
|
|
|
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
|
|
|
|
{
|
|
|
|
i match
|
2014-09-29 21:26:25 +02:00
|
|
|
{
|
2014-11-02 13:56:11 +01:00
|
|
|
case 0 =>
|
|
|
|
return Compatibility.isHandler(itemStack.getItem, null)
|
|
|
|
case 1 =>
|
|
|
|
return true
|
|
|
|
case 2 =>
|
|
|
|
return itemStack.getItem eq AtomicContent.itemUranium
|
|
|
|
case 3 =>
|
|
|
|
return itemStack.getItem eq AtomicContent.itemUranium
|
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
|
|
|
}
|