From 023ae4d77fd4640d1491b67e9ea9a018634f2ac7 Mon Sep 17 00:00:00 2001 From: bdew Date: Tue, 23 Sep 2014 14:05:39 +0300 Subject: [PATCH] Added another version of Misc.asInstanceOpt that's easier to use with map, etc. --- src/net/bdew/lib/Misc.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/net/bdew/lib/Misc.scala b/src/net/bdew/lib/Misc.scala index db7e97b..162fc1d 100644 --- a/src/net/bdew/lib/Misc.scala +++ b/src/net/bdew/lib/Misc.scala @@ -86,6 +86,10 @@ object Misc { def asInstanceOpt[T](v: Any, cls: Class[T]) = if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None + // Same thing but in a way that's easier to use with map, etc. + def asInstanceOpt[T](cls: Class[T])(v: Any) = + if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None + def getNeighbourTile[T](origin: TileEntity, dir: ForgeDirection, cls: Class[T]) = Option(origin.getWorldObj.getTileEntity(origin.xCoord + dir.offsetX, origin.yCoord + dir.offsetY, origin.zCoord + dir.offsetZ)) flatMap (asInstanceOpt(_, cls))