Skip to content

Instantly share code, notes, and snippets.

@Cazzar
Created December 15, 2014 15:13
Show Gist options
  • Save Cazzar/9c1ff838f99ce098e00d to your computer and use it in GitHub Desktop.
Save Cazzar/9c1ff838f99ce098e00d to your computer and use it in GitHub Desktop.
scala> import net.minecraft.tileentity.TileEntity
import net.minecraft.util.BlockPos
import net.minecraft.world.IBlockAccess
def getTile[T <: TileEntity](world: IBlockAccess, pos: BlockPos): T = world.getTileEntity(pos) match {
case t: T => t
case _ => null
}
import net.minecraft.tileentity.TileEntity
scala> import net.minecraft.util.BlockPos
scala> import net.minecraft.world.IBlockAccess
scala> | | | <console>:11: warning: abstract type pattern T is unchecked since it is eliminated by erasure
case t: T => t
^
<console>:12: error: type mismatch;
found : Null(null)
required: T
case _ => null
^
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment