electrodynamics/src/main/scala/edx/core/prefab/part/connector/PartAbstract.scala

101 lines
2.2 KiB
Scala
Raw Normal View History

2015-01-14 12:06:03 +01:00
package edx.core.prefab.part.connector
2014-07-15 00:09:56 +02:00
2014-11-10 14:20:42 +01:00
import codechicken.lib.data.{MCDataInput, MCDataOutput}
2014-07-15 00:09:56 +02:00
import codechicken.multipart.{IRedstonePart, TMultiPart}
2015-01-14 12:06:03 +01:00
import edx.core.ResonantPartFactory
2014-07-15 00:09:56 +02:00
import net.minecraft.item.ItemStack
import net.minecraft.util.MovingObjectPosition
2015-01-26 12:40:32 +01:00
import resonantengine.lib.prefab.tile.traits.TTicker
2014-07-15 00:09:56 +02:00
2014-07-21 17:47:39 +02:00
import scala.collection.convert.wrapAll._
import scala.collection.mutable
2014-07-21 17:47:39 +02:00
2015-01-17 06:13:26 +01:00
abstract class PartAbstract extends TMultiPart with TTicker
2014-07-15 00:09:56 +02:00
{
2014-07-21 15:15:22 +02:00
override def update()
2014-07-15 00:09:56 +02:00
{
2015-01-17 06:13:26 +01:00
super[TTicker].update()
2014-07-15 00:09:56 +02:00
}
2014-07-21 15:15:22 +02:00
protected def getItem: ItemStack
protected def getDrops(drops: mutable.Set[ItemStack])
{
drops += getItem
}
override def getDrops: java.lang.Iterable[ItemStack] =
{
val drops = mutable.Set.empty[ItemStack]
getDrops(drops)
return drops
}
2014-07-21 15:15:22 +02:00
2014-07-15 00:09:56 +02:00
override def pickItem(hit: MovingObjectPosition): ItemStack =
{
return getItem
}
protected def checkRedstone(side: Int): Boolean =
{
if (this.world.isBlockIndirectlyGettingPowered(x, y, z))
{
return true
}
else
{
for (tp <- tile.partList)
{
if (tp.isInstanceOf[IRedstonePart])
{
val rp: IRedstonePart = tp.asInstanceOf[IRedstonePart]
if ((Math.max(rp.strongPowerLevel(side), rp.weakPowerLevel(side)) << 4) > 0)
{
return true
}
}
}
}
return false
}
2014-09-13 15:57:24 +02:00
2014-11-10 14:20:42 +01:00
/**
* Packet methods
*
* Zero is always the description packet.
*/
def sendPacket(id: Int)
{
assert(!world.isRemote, "[PartAbstract] Attempt to send packet from client side!")
write(getWriteStream, id)
}
2014-11-10 14:41:46 +01:00
override final def writeDesc(packet: MCDataOutput)
2014-11-10 14:20:42 +01:00
{
write(packet, 0)
}
2014-11-10 14:41:46 +01:00
override final def readDesc(packet: MCDataInput)
2014-11-10 14:20:42 +01:00
{
2014-11-11 13:51:23 +01:00
read(packet, packet.readUByte)
2014-11-10 14:20:42 +01:00
}
2014-11-10 14:41:46 +01:00
override final def read(packet: MCDataInput)
{
read(packet, packet.readUByte)
}
2014-11-10 14:41:46 +01:00
def write(packet: MCDataOutput, id: Int)
{
packet.writeByte(id)
}
2014-11-10 14:20:42 +01:00
def read(packet: MCDataInput, id: Int)
{
}
2014-09-14 05:19:54 +02:00
override def toString: String = "[" + getClass.getSimpleName + "]" + x + "x " + y + "y " + z + "z"
final override def getType: String = ResonantPartFactory.prefix + getClass.getSimpleName
2014-07-15 00:09:56 +02:00
}