diff --git a/src/net/bdew/lib/Misc.scala b/src/net/bdew/lib/Misc.scala index 4d04d80..db7e97b 100644 --- a/src/net/bdew/lib/Misc.scala +++ b/src/net/bdew/lib/Misc.scala @@ -64,7 +64,7 @@ object Misc { def filterType[T](from: Iterable[_], cls: Class[T]) = from.filter(cls.isInstance).asInstanceOf[Iterable[T]] - def getBiomeByName(name: String) = BiomeGenBase.getBiomeGenArray.find(x => x != null && x.biomeName == name).getOrElse(null) + def getBiomeByName(name: String) = BiomeGenBase.getBiomeGenArray.find(x => x != null && x.biomeName == name).orNull def haveModVersion(spec: String): Boolean = { val req = VersionParser.parseVersionReference(spec) @@ -89,5 +89,10 @@ object Misc { 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)) + + def applyMutator[T](f: (T) => Unit, init: T): T = { + f(init) + init + } } diff --git a/src/net/bdew/lib/block/BlockFace.scala b/src/net/bdew/lib/block/BlockFace.scala new file mode 100644 index 0000000..5bcd86c --- /dev/null +++ b/src/net/bdew/lib/block/BlockFace.scala @@ -0,0 +1,22 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/bdlib + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt + */ + +package net.bdew.lib.block + +import net.minecraftforge.common.util.ForgeDirection + +case class BlockFace(x: Int, y: Int, z: Int, face: ForgeDirection) { + def origin = BlockRef(x, y, z) + def target = origin.neighbour(face) + def opposite = face.getOpposite +} + +object BlockFace { + def apply(bp: BlockRef, face: ForgeDirection) = new BlockFace(bp.x, bp.y, bp.z, face) +} diff --git a/src/net/bdew/lib/block/BlockRef.scala b/src/net/bdew/lib/block/BlockRef.scala index c0838da..bd112fd 100644 --- a/src/net/bdew/lib/block/BlockRef.scala +++ b/src/net/bdew/lib/block/BlockRef.scala @@ -25,7 +25,7 @@ case class BlockRef(x: Int, y: Int, z: Int) { def blockIs(w: IBlockAccess, other: Block) = block(w).contains(other) def neighbour(side: ForgeDirection) = BlockRef(x + side.offsetX, y + side.offsetY, z + side.offsetZ) - def neighbours = ForgeDirection.VALID_DIRECTIONS.map(x => x -> neighbour(x)) + def neighbours = ForgeDirection.VALID_DIRECTIONS.map(x => x -> neighbour(x)).toMap override def toString = "(x=%d y=%d z=%d)".format(x, y, z) @@ -36,6 +36,8 @@ case class BlockRef(x: Int, y: Int, z: Int) { else None } + def ==(tx: Int, ty: Int, tz: Int) = x == tx && y == ty && z == tz + def getBlock[T: ClassTag](w: IBlockAccess) = block(w) flatMap { block => val cls = implicitly[ClassTag[T]].runtimeClass if (cls.isInstance(block)) diff --git a/src/net/bdew/lib/block/HasTE.scala b/src/net/bdew/lib/block/HasTE.scala index ded52d9..bd82ee1 100644 --- a/src/net/bdew/lib/block/HasTE.scala +++ b/src/net/bdew/lib/block/HasTE.scala @@ -18,6 +18,9 @@ trait HasTE[T] extends Block with ITileEntityProvider { val TEClass: Class[_ <: TileEntity] def createNewTileEntity(world: World, meta: Int): TileEntity = TEClass.newInstance() + + def getTE(w: IBlockAccess, ref: BlockRef): T = getTE(w, ref.x, ref.y, ref.z) + def getTE(w: IBlockAccess, x: Int, y: Int, z: Int): T = { var t = w.getTileEntity(x, y, z) if ((t == null) || !TEClass.isInstance(t)) { diff --git a/src/net/bdew/lib/data/DataSlotGameProfile.scala b/src/net/bdew/lib/data/DataSlotGameProfile.scala index ee831c8..7feb6f7 100644 --- a/src/net/bdew/lib/data/DataSlotGameProfile.scala +++ b/src/net/bdew/lib/data/DataSlotGameProfile.scala @@ -1,3 +1,12 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/bdlib + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt + */ + package net.bdew.lib.data import java.util.UUID diff --git a/src/net/bdew/lib/gui/widgets/WidgetSubcontainer.scala b/src/net/bdew/lib/gui/widgets/WidgetSubcontainer.scala index 7bc3b25..d7336cf 100644 --- a/src/net/bdew/lib/gui/widgets/WidgetSubcontainer.scala +++ b/src/net/bdew/lib/gui/widgets/WidgetSubcontainer.scala @@ -9,7 +9,7 @@ package net.bdew.lib.gui.widgets -import net.bdew.lib.gui.{Rect, _} +import net.bdew.lib.gui._ class WidgetSubcontainer(val rect: Rect) extends BaseWidget with WidgetContainer with SimpleDrawTarget { def getZLevel = parent.getZLevel