mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 04:06:43 -04:00
cleanup after adapter simplification
This commit is contained in:
parent
0a6a2693ef
commit
690ea2777e
@ -4,8 +4,9 @@ import li.cil.oc.api.Network
|
|||||||
import li.cil.oc.api.network._
|
import li.cil.oc.api.network._
|
||||||
import li.cil.oc.util.mods.RedstoneInMotion
|
import li.cil.oc.util.mods.RedstoneInMotion
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
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).
|
val node = Network.newNode(this, Visibility.Network).
|
||||||
withComponent("carriage").
|
withComponent("carriage").
|
||||||
create()
|
create()
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
package li.cil.oc.util.mods
|
package li.cil.oc.util.mods
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException
|
import java.lang.reflect.InvocationTargetException
|
||||||
import net.minecraft.block.Block
|
import net.minecraft.tileentity.TileEntity
|
||||||
import net.minecraft.item.{ItemBlock, ItemStack}
|
|
||||||
import scala.language.existentials
|
import scala.language.existentials
|
||||||
|
|
||||||
object RedstoneInMotion {
|
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 controller = Class.forName("JAKJ.RedstoneInMotion.CarriageControllerEntity")
|
||||||
val motionException = Class.forName("JAKJ.RedstoneInMotion.CarriageMotionException")
|
val motionException = Class.forName("JAKJ.RedstoneInMotion.CarriageMotionException")
|
||||||
val obstructionException = Class.forName("JAKJ.RedstoneInMotion.CarriageObstructionException")
|
val obstructionException = Class.forName("JAKJ.RedstoneInMotion.CarriageObstructionException")
|
||||||
val directions = Class.forName("JAKJ.RedstoneInMotion.Directions").getEnumConstants
|
val directions = Class.forName("JAKJ.RedstoneInMotion.Directions").getEnumConstants
|
||||||
val blocks = Class.forName("JAKJ.RedstoneInMotion.Blocks")
|
|
||||||
|
|
||||||
val methods = controller.getDeclaredMethods
|
val methods = controller.getDeclaredMethods
|
||||||
val setup = methods.find(_.getName == "SetupMotion").get
|
val setup = methods.find(_.getName == "SetupMotion").get
|
||||||
@ -21,27 +19,20 @@ object RedstoneInMotion {
|
|||||||
val obstructionY = obstructionException.getDeclaredField("Y")
|
val obstructionY = obstructionException.getDeclaredField("Y")
|
||||||
val obstructionZ = obstructionException.getDeclaredField("Z")
|
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 {
|
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 available = controller.isDefined
|
||||||
|
|
||||||
def isCarriageController(value: AnyRef) = controller match {
|
def isCarriageController(value: TileEntity) = controller match {
|
||||||
case Some(clazz) => clazz.isAssignableFrom(value.getClass)
|
case Some(clazz) => clazz.isAssignableFrom(value.getClass)
|
||||||
case _ => false
|
case _ => false
|
||||||
}
|
}
|
||||||
|
|
||||||
def isCarriageController(stack: ItemStack) = available && stack != null && (stack.getItem match {
|
def move(controller: TileEntity, direction: Int, simulating: Boolean, anchored: Boolean): (Boolean, Array[AnyRef]) = {
|
||||||
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]) = {
|
|
||||||
if (!isCarriageController(controller))
|
if (!isCarriageController(controller))
|
||||||
throw new IllegalArgumentException("Not a carriage controller.")
|
throw new IllegalArgumentException("Not a carriage controller.")
|
||||||
|
|
||||||
@ -65,11 +56,4 @@ object RedstoneInMotion {
|
|||||||
(false, Array(e.getMessage: AnyRef))
|
(false, Array(e.getMessage: AnyRef))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def driveBlock = try {
|
|
||||||
blocks.getField("CarriageDrive").get(null).asInstanceOf[Block]
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
case _: Throwable => null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user