Updated HasTE, BaseInventory and Block/Item Manager for 1.7.2 changes

This commit is contained in:
bdew committed 2014-02-12 12:39:10 +02:00
1 parent 4268019935
commit 7eefbb1a31
4 files changed
+11 -10

No files matched your search

+3 -2
View File
@@ -16,14 +16,15 @@ import net.bdew.lib.BdLib
trait HasTE[T] extends Block with ITileEntityProvider {
val TEClass: Class[_ <: TileEntity]
def createNewTileEntity(world: World): TileEntity = TEClass.newInstance()
def createNewTileEntity(world: World, meta: Int): TileEntity = TEClass.newInstance()
def getTE(w: IBlockAccess, x: Int, y: Int, z: Int): T = {
var t = w.getTileEntity(x, y, z)
if ((t == null) || !TEClass.isInstance(t)) {
BdLib.logError("Tile entity for block %s at (%d,%d,%d) is corrupt or missing - recreating", this, x, y, z)
w match {
case ww: World =>
t = createNewTileEntity(ww)
t = createNewTileEntity(ww, w.getBlockMetadata(x, y, z))
ww.setTileEntity(x, y, z, t)
case _ =>
sys.error("Unable to recreate TE")
+1 -1
View File
@@ -17,7 +17,7 @@ import net.bdew.lib.block.HasTE
class BlockManager() {
def regBlockCls[T <: Block](blockCls: Class[T], name: String, addStack: Boolean = true): T = {
val block = blockCls.getConstructor(classOf[Int]).newInstance()
val block = blockCls.newInstance()
regBlock[T](block, name, addStack)
}
+1 -1
View File
@@ -19,7 +19,7 @@ class ItemManager() {
def regItem[T <: SimpleItem](item: T): T = regItem[T](item, item.name)
def regItemCls[T <: Item](itemCls: Class[T], name: String, addStack: Boolean = true): T = {
val item = itemCls.getConstructor(classOf[Int]).newInstance()
val item = itemCls.newInstance()
regItem[T](item, name, addStack)
}
@@ -18,29 +18,29 @@ trait BaseInventory extends IInventory {
def getStackInSlot(i: Int): ItemStack = inv(i)
def getInvName = ""
def getInventoryName = ""
def isInvNameLocalized = false
def hasCustomInventoryName = false
def getInventoryStackLimit = 64
def isUseableByPlayer(player: EntityPlayer) = true
def openChest() = Unit
def openInventory() {}
def closeChest() = Unit
def closeInventory() {}
def isItemValidForSlot(slot: Int, stack: ItemStack) = true
def decrStackSize(slot: Int, n: Int): ItemStack = {
var item = inv(slot)
val item = inv(slot)
if (item != null) {
if (item.stackSize <= n) {
inv(slot) = null
markDirty()
return item
} else {
var newstack = item.splitStack(n)
val newstack = item.splitStack(n)
if (item.stackSize == 0) {
inv(slot) = null
}