added IStackBlock for pattern matching with ItemBlocks

This commit is contained in:
bdew committed 2014-04-30 11:18:39 +03:00
1 parent a10e90a1e1
commit d67bd24eda
1 file changed
+13 -1
+13 -1
View File
@@ -9,7 +9,8 @@
package net.bdew.lib.items
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.item.{ItemBlock, Item, ItemStack}
import net.minecraft.block.Block
/**
* Allows matching Items in ItemStacks in scala pattern matches
@@ -21,3 +22,14 @@ object IStack {
else
Some(x.getItem)
}
/**
* Allows matching Blocks in ItemStacks in scala pattern matches
*/
object IStackBlock {
def unapply(x: ItemStack): Option[Block] =
if (x == null || x.getItem == null || !x.getItem.isInstanceOf[ItemBlock])
None
else
Some(x.getItem.asInstanceOf[ItemBlock].field_150939_a)
}