2014-07-29 21:47:22 +02:00
|
|
|
package resonantinduction.atomic.gate
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
import java.lang.{Iterable => JIterable}
|
2014-08-11 07:44:06 +02:00
|
|
|
import java.util.{ArrayList, List, Set}
|
|
|
|
|
|
|
|
import codechicken.lib.data.{MCDataInput, MCDataOutput}
|
|
|
|
import codechicken.lib.vec.{Cuboid6, Vector3}
|
|
|
|
import codechicken.multipart.{JCuboidPart, JNormalOcclusion, TSlottedPart}
|
|
|
|
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
2014-07-29 21:47:22 +02:00
|
|
|
import net.minecraft.entity.Entity
|
|
|
|
import net.minecraft.entity.player.EntityPlayer
|
|
|
|
import net.minecraft.item.ItemStack
|
|
|
|
import net.minecraft.nbt.NBTTagCompound
|
|
|
|
import net.minecraft.tileentity.TileEntity
|
2014-08-11 07:44:06 +02:00
|
|
|
import net.minecraft.util.{ChatComponentText, MovingObjectPosition}
|
2014-07-29 21:47:22 +02:00
|
|
|
import resonant.api.blocks.IBlockFrequency
|
|
|
|
import resonant.api.mffs.fortron.FrequencyGridRegistry
|
2014-08-11 14:13:27 +02:00
|
|
|
import resonantinduction.atomic.AtomicContent
|
2014-07-29 21:47:22 +02:00
|
|
|
import universalelectricity.core.transform.vector.VectorWorld
|
2014-08-11 09:47:13 +02:00
|
|
|
|
2014-08-11 07:44:06 +02:00
|
|
|
import scala.collection.JavaConversions._
|
2014-07-29 21:47:22 +02:00
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
object PartQuantumGlyph
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
final val MAX_GLYPH: Int = 4
|
|
|
|
private[gate] final val bounds: Array[Cuboid6] = new Array[Cuboid6](15)
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
class PartQuantumGlyph extends JCuboidPart with TSlottedPart with JNormalOcclusion with IQuantumGate
|
|
|
|
{
|
2014-08-11 07:44:06 +02:00
|
|
|
|
|
|
|
private var slot: Byte = 0
|
|
|
|
private[gate] var number: Byte = 0
|
|
|
|
private[gate] var ticks: Int = 0
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
def preparePlacement(side: Int, itemDamage: Int)
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
this.slot = side.asInstanceOf[Byte]
|
|
|
|
this.number = itemDamage.asInstanceOf[Byte]
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def onWorldJoin
|
|
|
|
{
|
|
|
|
if ((tile.asInstanceOf[IQuantumGate]).getFrequency != -1)
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
FrequencyGridRegistry.instance.add(tile.asInstanceOf[IQuantumGate])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def preRemove
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
FrequencyGridRegistry.instance.remove(tile.asInstanceOf[IQuantumGate])
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def onEntityCollision(entity: Entity)
|
|
|
|
{
|
|
|
|
if (!world.isRemote)
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
if (entity.isInstanceOf[EntityPlayer]) if (!(entity.asInstanceOf[EntityPlayer]).isSneaking) return
|
|
|
|
transport(entity)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def update
|
|
|
|
{
|
|
|
|
if (ticks == 0) FrequencyGridRegistry.instance.add(tile.asInstanceOf[IQuantumGate])
|
|
|
|
ticks += 1
|
|
|
|
}
|
|
|
|
|
|
|
|
override def activate(player: EntityPlayer, hit: MovingObjectPosition, itemStack: ItemStack): Boolean =
|
|
|
|
{
|
|
|
|
if (player.isSneaking)
|
|
|
|
{
|
|
|
|
if (!world.isRemote)
|
|
|
|
{
|
|
|
|
transport(player)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val frequency: Int = (tile.asInstanceOf[IBlockFrequency]).getFrequency
|
|
|
|
if (frequency > -1)
|
|
|
|
{
|
|
|
|
if (!world.isRemote)
|
|
|
|
{
|
|
|
|
player.addChatMessage(new ChatComponentText("Quantum Gate Frequency: " + frequency))
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2014-08-11 07:44:06 +02:00
|
|
|
def transport(`ob`: scala.Any)
|
|
|
|
{
|
|
|
|
if (ticks % 10 == 0 && (tile.asInstanceOf[IQuantumGate]).getFrequency != -1)
|
|
|
|
{
|
2014-07-30 00:48:32 +02:00
|
|
|
val frequencyBlocks: Set[IBlockFrequency] = FrequencyGridRegistry.instance.getNodes((tile.asInstanceOf[IQuantumGate]).getFrequency)
|
2014-07-29 21:47:22 +02:00
|
|
|
val gates: List[IQuantumGate] = new ArrayList[IQuantumGate]
|
2014-08-11 07:44:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
for (frequencyBlock <- frequencyBlocks)
|
|
|
|
{
|
|
|
|
if (frequencyBlock.isInstanceOf[IQuantumGate])
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
gates.add(frequencyBlock.asInstanceOf[IQuantumGate])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gates.remove(tile)
|
2014-08-11 07:44:06 +02:00
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
if (gates.size > 0)
|
|
|
|
{
|
2014-08-11 07:44:06 +02:00
|
|
|
if (ob.isInstanceOf[Entity])
|
|
|
|
{
|
|
|
|
val gate: IQuantumGate = gates.get(if (gates.size > 1) ob.asInstanceOf[Entity].worldObj.rand.nextInt(gates.size - 1) else 0)
|
|
|
|
val position: VectorWorld = new VectorWorld(gate.asInstanceOf[TileEntity]).add(0.5, 2, 0.5)
|
|
|
|
|
|
|
|
if (QuantumGateManager.moveEntity(ob.asInstanceOf[Entity], position)) world.playSoundAtEntity(ob.asInstanceOf[Entity], "mob.endermen.portal", 1.0F, 1.0F)
|
|
|
|
}
|
2014-07-29 21:47:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
def getType: String =
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
return "resonant_induction_quantum_glyph"
|
|
|
|
}
|
|
|
|
|
2014-09-16 06:50:42 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
2014-09-07 05:50:03 +02:00
|
|
|
{
|
2014-09-16 06:50:42 +02:00
|
|
|
RenderQuantumGlyph.render(this, pos.x, pos.y, pos.z)
|
2014-07-29 21:47:22 +02:00
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def getOcclusionBoxes: JIterable[codechicken.lib.vec.Cuboid6] = Seq[Cuboid6](getBounds)
|
|
|
|
|
|
|
|
def getBounds: Cuboid6 =
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
if (slot < PartQuantumGlyph.bounds.length) if (PartQuantumGlyph.bounds(slot) != null) return PartQuantumGlyph.bounds(slot)
|
|
|
|
return new Cuboid6(0, 0, 0, 0.5, 0.5, 0.5)
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
def getSlotMask: Int =
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
return 1 << slot
|
|
|
|
}
|
|
|
|
|
2014-08-11 15:34:00 +02:00
|
|
|
override def getDrops: JIterable[ItemStack] = Seq[ItemStack](getItem)
|
2014-07-29 21:47:22 +02:00
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def pickItem(hit: MovingObjectPosition): ItemStack =
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
return getItem
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
protected def getItem: ItemStack =
|
|
|
|
{
|
|
|
|
return new ItemStack(AtomicContent.itemQuantumGlyph, 1, number)
|
2014-07-29 21:47:22 +02:00
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
/** Packet Code. */
|
|
|
|
override def readDesc(packet: MCDataInput)
|
|
|
|
{
|
|
|
|
load(packet.readNBTTagCompound)
|
2014-07-29 21:47:22 +02:00
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def load(nbt: NBTTagCompound)
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
slot = nbt.getByte("side")
|
|
|
|
number = nbt.getByte("number")
|
2014-09-07 05:50:03 +02:00
|
|
|
if (nbt.hasKey("frequency"))
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
val frequency: Int = nbt.getInteger("frequency")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def writeDesc(packet: MCDataOutput)
|
|
|
|
{
|
|
|
|
val nbt: NBTTagCompound = new NBTTagCompound
|
|
|
|
save(nbt)
|
|
|
|
packet.writeNBTTagCompound(nbt)
|
|
|
|
}
|
|
|
|
|
|
|
|
override def save(nbt: NBTTagCompound)
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
nbt.setByte("side", slot)
|
|
|
|
nbt.setByte("number", number)
|
2014-09-07 05:50:03 +02:00
|
|
|
if (tile != null)
|
|
|
|
{
|
2014-07-29 21:47:22 +02:00
|
|
|
nbt.setInteger("frequency", (tile.asInstanceOf[IQuantumGate]).getFrequency)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 07:44:06 +02:00
|
|
|
override def getFrequency: Int = ???
|
2014-09-07 05:50:03 +02:00
|
|
|
|
|
|
|
override def setFrequency(frequency: Int): Unit = ???
|
2014-07-29 21:47:22 +02:00
|
|
|
}
|