Added another version of Misc.asInstanceOpt that's easier to use with map, etc.

This commit is contained in:
bdew committed 2014-09-23 14:12:13 +03:00
1 parent b1e0e70fc4
commit 023ae4d77f
1 file changed
+4
+4
View File
@@ -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))