cleanup after adapter simplification

This commit is contained in:
Florian Nücke 2014-02-05 23:34:35 +01:00
parent 0a6a2693ef
commit 690ea2777e
2 changed files with 8 additions and 23 deletions

View File

@ -4,8 +4,9 @@ import li.cil.oc.api.Network
import li.cil.oc.api.network._
import li.cil.oc.util.mods.RedstoneInMotion
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
class Carriage(controller: AnyRef) extends ManagedComponent {
class Carriage(controller: TileEntity) extends ManagedComponent {
val node = Network.newNode(this, Visibility.Network).
withComponent("carriage").
create()

View File

@ -1,17 +1,15 @@
package li.cil.oc.util.mods
import java.lang.reflect.InvocationTargetException
import net.minecraft.block.Block
import net.minecraft.item.{ItemBlock, ItemStack}
import net.minecraft.tileentity.TileEntity
import scala.language.existentials
object RedstoneInMotion {
private val (controller, setup, move, motionException, obstructionException, obstructionX, obstructionY, obstructionZ, directions, blocks) = try {
private val (controller, setup, move, motionException, obstructionException, obstructionX, obstructionY, obstructionZ, directions) = try {
val controller = Class.forName("JAKJ.RedstoneInMotion.CarriageControllerEntity")
val motionException = Class.forName("JAKJ.RedstoneInMotion.CarriageMotionException")
val obstructionException = Class.forName("JAKJ.RedstoneInMotion.CarriageObstructionException")
val directions = Class.forName("JAKJ.RedstoneInMotion.Directions").getEnumConstants
val blocks = Class.forName("JAKJ.RedstoneInMotion.Blocks")
val methods = controller.getDeclaredMethods
val setup = methods.find(_.getName == "SetupMotion").get
@ -21,27 +19,20 @@ object RedstoneInMotion {
val obstructionY = obstructionException.getDeclaredField("Y")
val obstructionZ = obstructionException.getDeclaredField("Z")
(Option(controller), setup, move, motionException, obstructionException, obstructionX, obstructionY, obstructionZ, directions, blocks)
(Option(controller), setup, move, motionException, obstructionException, obstructionX, obstructionY, obstructionZ, directions)
}
catch {
case _: Throwable => (None, null, null, null, null, null, null, null, null, null)
case _: Throwable => (None, null, null, null, null, null, null, null, null)
}
def available = controller.isDefined
def isCarriageController(value: AnyRef) = controller match {
def isCarriageController(value: TileEntity) = controller match {
case Some(clazz) => clazz.isAssignableFrom(value.getClass)
case _ => false
}
def isCarriageController(stack: ItemStack) = available && stack != null && (stack.getItem match {
case itemBlock: ItemBlock =>
val block = Block.blocksList(itemBlock.getBlockID)
block != null && driveBlock != null && block.blockID == driveBlock.blockID && itemBlock.getMetadata(stack.getItemDamage) == 2
case _ => false
})
def move(controller: AnyRef, direction: Int, simulating: Boolean, anchored: Boolean): (Boolean, Array[AnyRef]) = {
def move(controller: TileEntity, direction: Int, simulating: Boolean, anchored: Boolean): (Boolean, Array[AnyRef]) = {
if (!isCarriageController(controller))
throw new IllegalArgumentException("Not a carriage controller.")
@ -65,11 +56,4 @@ object RedstoneInMotion {
(false, Array(e.getMessage: AnyRef))
}
}
private def driveBlock = try {
blocks.getField("CarriageDrive").get(null).asInstanceOf[Block]
}
catch {
case _: Throwable => null
}
}