mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-13 16:54:11 +00:00
Initial port to MC 1.7.2
This commit is contained in:
1 parent
78a69acc44
commit
4268019935
34 files changed
+141
-178
No files matched your search
+11
-4
@@ -1,20 +1,27 @@
|
||||
buildscript {
|
||||
configurations.all {
|
||||
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "forge"
|
||||
url = "http://files.minecraftforge.net/maven"
|
||||
}
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:1.0-SNAPSHOT'
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:1.1-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'forge'
|
||||
apply plugin: 'scala'
|
||||
|
||||
version = "1.2.0"
|
||||
version = "2.0.0"
|
||||
|
||||
if (project.hasProperty('buildnum')) {
|
||||
project.version = project.version + '.' + project.buildnum
|
||||
@@ -24,10 +31,10 @@ if (project.hasProperty('buildnum')) {
|
||||
|
||||
group = "net.bdew"
|
||||
archivesBaseName = "bdlib"
|
||||
ext.versuffix = "mc164"
|
||||
ext.versuffix = "mc172"
|
||||
|
||||
minecraft {
|
||||
version = "1.6.4-9.11.1.964"
|
||||
version = "1.7.2-10.12.0.1024"
|
||||
replace("BDLIB_VER", project.version)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,18 @@ package net.bdew.lib
|
||||
|
||||
import cpw.mods.fml.common.Mod
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent
|
||||
import org.apache.logging.log4j.Logger
|
||||
|
||||
@Mod(modid = "bdlib", name = "BD lib", version = "BDLIB_VER", modLanguage = "scala")
|
||||
object BdLib {
|
||||
var log: Logger = null
|
||||
|
||||
def logInfo(msg: String, args: Any*) = log.info(msg.format(args: _*))
|
||||
def logWarn(msg: String, args: Any*) = log.warn(msg.format(args: _*))
|
||||
def logError(msg: String, args: Any*) = log.error(msg.format(args: _*))
|
||||
|
||||
def preInit(ev: FMLPreInitializationEvent) {
|
||||
ev.getModLog.info("bdlib BDLIB_VER loaded")
|
||||
log = ev.getModLog
|
||||
log.info("bdlib BDLIB_VER loaded")
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
package net.bdew.lib
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.util.StatCollector
|
||||
import net.minecraft.item.ItemStack
|
||||
import cpw.mods.fml.common.versioning.{ArtifactVersion, VersionParser}
|
||||
@@ -18,8 +18,10 @@ import cpw.mods.fml.common.Loader
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe
|
||||
|
||||
object Misc {
|
||||
def iterNbtList[X](list: NBTTagList) =
|
||||
for (i <- 0 until list.tagCount()) yield list.tagAt(i).asInstanceOf[X]
|
||||
def iterNbtCompoundList(parent: NBTTagCompound, name: String): Iterable[NBTTagCompound] = {
|
||||
val list = parent.getTagList(name, 10)
|
||||
for (i <- 0 until list.tagCount()) yield list.getCompoundTagAt(i)
|
||||
}
|
||||
|
||||
def getActiveModId = Loader.instance().activeModContainer().getModId
|
||||
|
||||
@@ -34,7 +36,7 @@ object Misc {
|
||||
def wrapTag(n: String, f: (NBTTagCompound) => Any)(t: NBTTagCompound) {
|
||||
val p = t.getCompoundTag(n)
|
||||
f(p)
|
||||
t.setCompoundTag(n, p)
|
||||
t.setTag(n, p)
|
||||
}
|
||||
|
||||
def addRecipe(result: ItemStack, pattern: Seq[String], items: Map[Char, AnyRef]) =
|
||||
|
||||
@@ -12,19 +12,19 @@ package net.bdew.lib.block
|
||||
import net.minecraft.block.{ITileEntityProvider, Block}
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import cpw.mods.fml.common.FMLCommonHandler
|
||||
import net.bdew.lib.BdLib
|
||||
|
||||
trait HasTE[T] extends Block with ITileEntityProvider {
|
||||
val TEClass: Class[_ <: TileEntity]
|
||||
def createNewTileEntity(world: World): TileEntity = TEClass.newInstance()
|
||||
def getTE(w: IBlockAccess, x: Int, y: Int, z: Int): T = {
|
||||
var t = w.getBlockTileEntity(x, y, z)
|
||||
var t = w.getTileEntity(x, y, z)
|
||||
if ((t == null) || !TEClass.isInstance(t)) {
|
||||
FMLCommonHandler.instance().getFMLLogger.severe("Tile entity for block %s at (%d,%d,%d) is corrupt or missing - recreating".format(this, x, y, z))
|
||||
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)
|
||||
ww.setBlockTileEntity(x, y, z, t)
|
||||
ww.setTileEntity(x, y, z, t)
|
||||
case _ =>
|
||||
sys.error("Unable to recreate TE")
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ import net.minecraft.block.Block
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.block.HasTE
|
||||
|
||||
class BlockManager(val ids: IdManager) {
|
||||
class BlockManager() {
|
||||
|
||||
def regBlockCls[T <: Block](blockCls: Class[T], name: String, addStack: Boolean = true): T = {
|
||||
val block = blockCls.getConstructor(classOf[Int]).newInstance(ids.getBlockId(name): Integer)
|
||||
val block = blockCls.getConstructor(classOf[Int]).newInstance()
|
||||
regBlock[T](block, name, addStack)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ package net.bdew.lib.config
|
||||
|
||||
import net.minecraftforge.fluids.{FluidRegistry, Fluid}
|
||||
|
||||
class FluidManager(val ids: IdManager) {
|
||||
class FluidManager() {
|
||||
def regFluid[T <: Fluid](fluid: T): T = {
|
||||
FluidRegistry.registerFluid(fluid)
|
||||
return fluid
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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.config
|
||||
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraftforge.common.Configuration
|
||||
|
||||
class IdManager(cfg: Configuration, itemStart: Int, blockStart: Int) {
|
||||
|
||||
class MyIter(start: Int, check: Array[_], offset: Int = 0) {
|
||||
var now = start
|
||||
def next(): Int = {
|
||||
while (check(now + offset) != null) now += 1
|
||||
return now
|
||||
}
|
||||
}
|
||||
|
||||
def getBlockId(name: String, comment: String) = cfg.getBlock(name, blockIds.next(), comment).getInt
|
||||
def getBlockId(name: String) = cfg.getBlock(name, blockIds.next()).getInt
|
||||
|
||||
def getItemId(name: String, comment: String) = cfg.getItem(name, itemIds.next(), comment).getInt
|
||||
def getItemId(name: String) = cfg.getItem(name, itemIds.next()).getInt
|
||||
|
||||
val blockIds = new MyIter(blockStart, Block.blocksList)
|
||||
val itemIds = new MyIter(itemStart, Item.itemsList, 256)
|
||||
|
||||
// figure out what's the max id we already use, because forge is stupid
|
||||
// ignore ids in the top slots as they were probably assigned to resolve conflicts
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
val maxBlock = (cfg.getCategory(Configuration.CATEGORY_BLOCK).values().asScala.map(_.getInt).filter(_ < Block.blocksList.length - 100) ++ Seq(0)).max + 1
|
||||
val maxItem = (cfg.getCategory(Configuration.CATEGORY_ITEM).values().asScala.map(_.getInt).filter(_ < Item.itemsList.length - 1000) ++ Seq(0)).max + 1
|
||||
|
||||
if (maxBlock > blockIds.now) blockIds.now = maxBlock
|
||||
if (maxItem > itemIds.now) itemIds.now = maxItem
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ import net.minecraft.item.{ItemStack, Item}
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.items.SimpleItem
|
||||
|
||||
class ItemManager(val ids: IdManager) {
|
||||
def regSimpleItem(name: String): SimpleItem = regItem(new SimpleItem(ids.getItemId(name), name), name)
|
||||
class ItemManager() {
|
||||
def regSimpleItem(name: String): SimpleItem = regItem(new SimpleItem(name), name)
|
||||
|
||||
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(ids.getItemId(name): Integer)
|
||||
val item = itemCls.getConstructor(classOf[Int]).newInstance()
|
||||
regItem[T](item, name, addStack)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
import net.bdew.lib.machine.Machine
|
||||
import net.bdew.lib.gui.{GuiProvider, GuiHandler}
|
||||
|
||||
class MachineManager(ids: IdManager, val tuning: ConfigSection, guiHandler: GuiHandler) {
|
||||
class MachineManager(val tuning: ConfigSection, guiHandler: GuiHandler) {
|
||||
def registerMachine[R <: Machine[_]](machine: R): R = {
|
||||
machine.tuning = tuning.getSection(machine.name)
|
||||
if (machine.tuning.getBoolean("Enabled")) {
|
||||
machine.enabled = true
|
||||
machine.regBlock(ids)
|
||||
machine.regBlock()
|
||||
if (machine.isInstanceOf[GuiProvider])
|
||||
guiHandler.register(machine.asInstanceOf[GuiProvider])
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlotVal}
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
case class DataSlotDirection(name: String, parent: TileDataSlots) extends DataSlotVal[ForgeDirection] {
|
||||
var cval = ForgeDirection.UP
|
||||
|
||||
@@ -26,7 +26,7 @@ case class DataSlotItemStack(name: String, parent: TileDataSlots) extends DataSl
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||
val tag = new NBTTagCompound()
|
||||
if (cval != null) cval.writeToNBT(tag)
|
||||
t.setCompoundTag(name, tag)
|
||||
t.setTag(name, tag)
|
||||
}
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = ItemStack.loadItemStackFromNBT(t.getCompoundTag(name))
|
||||
}
|
||||
@@ -38,7 +38,7 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
|
||||
writeToNBT(tag)
|
||||
if (k == UpdateKind.GUI)
|
||||
tag.setInteger("size", getCapacity)
|
||||
t.setCompoundTag(name, tag)
|
||||
t.setTag(name, tag)
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, k: UpdateKind.Value) {
|
||||
|
||||
@@ -21,19 +21,19 @@ trait ContainerDataSlots extends NoInvContainer {
|
||||
super.addCraftingToCrafters(crafter)
|
||||
if (crafter.isInstanceOf[EntityPlayerMP]) {
|
||||
val pkt = dataSource.getDataSlotPacket
|
||||
crafter.asInstanceOf[EntityPlayerMP].playerNetServerHandler.sendPacketToPlayer(pkt)
|
||||
crafter.asInstanceOf[EntityPlayerMP].playerNetServerHandler.sendPacket(pkt)
|
||||
}
|
||||
}
|
||||
|
||||
override def detectAndSendChanges() {
|
||||
super.detectAndSendChanges()
|
||||
// only send updates every 10 ticks
|
||||
if (dataSource.lastChange >= lastSentChange + 10 || (dataSource.lastChange > lastSentChange && lastSentChange + 10 < dataSource.worldObj.getTotalWorldTime)) {
|
||||
if (dataSource.lastChange >= lastSentChange + 10 || (dataSource.lastChange > lastSentChange && lastSentChange + 10 < dataSource.getWorldObj.getTotalWorldTime)) {
|
||||
lastSentChange = dataSource.lastChange
|
||||
val pkt = dataSource.getDataSlotPacket
|
||||
|
||||
for (player <- players)
|
||||
player.playerNetServerHandler.sendPacketToPlayer(pkt)
|
||||
player.playerNetServerHandler.sendPacket(pkt)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,11 @@
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
import net.minecraft.network.packet.Packet132TileEntityData
|
||||
import scala.collection.mutable
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity
|
||||
import net.minecraft.network.Packet
|
||||
|
||||
trait TileDataSlots extends TileExtended {
|
||||
val dataSlots = mutable.HashMap.empty[String, DataSlot]
|
||||
@@ -32,7 +33,7 @@ trait TileDataSlots extends TileExtended {
|
||||
if (TRACE) printf("%s: %s L<= %s\n".format(kind, n, t.getTag(n)))
|
||||
s.load(t, kind)
|
||||
if (kind == UpdateKind.WORLD && s.updateKind.contains(UpdateKind.RENDER))
|
||||
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord)
|
||||
getWorldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,20 +43,20 @@ trait TileDataSlots extends TileExtended {
|
||||
handleClientUpdate.listen(doLoad(UpdateKind.WORLD, _))
|
||||
|
||||
def dataSlotChanged(slot: DataSlot) {
|
||||
if (worldObj != null) {
|
||||
if (getWorldObj != null) {
|
||||
if (slot.updateKind.contains(UpdateKind.GUI))
|
||||
lastChange = worldObj.getTotalWorldTime
|
||||
lastChange = getWorldObj.getTotalWorldTime
|
||||
if (slot.updateKind.contains(UpdateKind.WORLD))
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
||||
getWorldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
||||
if (slot.updateKind.contains(UpdateKind.SAVE))
|
||||
worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this)
|
||||
getWorldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this)
|
||||
}
|
||||
}
|
||||
|
||||
def getDataSlotPacket: Packet132TileEntityData = {
|
||||
def getDataSlotPacket: Packet = {
|
||||
val tag = new NBTTagCompound()
|
||||
doSave(UpdateKind.GUI, tag)
|
||||
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, ACT_GUI, tag)
|
||||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, ACT_GUI, tag)
|
||||
}
|
||||
|
||||
override protected def extDataPacket(id: Int, data: NBTTagCompound) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.inventory.Container
|
||||
import scala.collection.mutable
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import org.lwjgl.opengl.GL11
|
||||
import net.minecraft.client.Minecraft
|
||||
|
||||
abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContainer(cont) {
|
||||
xSize = xSz
|
||||
@@ -25,7 +26,7 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
|
||||
|
||||
def rect = new Rect(guiLeft, guiTop, xSize, ySize)
|
||||
|
||||
def getFontRenderer = fontRenderer
|
||||
def getFontRenderer = Minecraft.getMinecraft.fontRenderer
|
||||
def getZLevel = zLevel
|
||||
|
||||
override def initGui() {
|
||||
@@ -56,7 +57,7 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
|
||||
import collection.JavaConversions._
|
||||
|
||||
if (tip.size > 0)
|
||||
drawHoveringText(tip, x, y, fontRenderer)
|
||||
drawHoveringText(tip, x, y, getFontRenderer)
|
||||
}
|
||||
|
||||
protected def drawGuiContainerBackgroundLayer(f: Float, i: Int, j: Int) {
|
||||
|
||||
@@ -24,8 +24,8 @@ class GuiHandler extends IGuiHandler {
|
||||
}
|
||||
|
||||
def getServerGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
|
||||
guis(ID).getContainer(world.getBlockTileEntity(x, y, z), player)
|
||||
guis(ID).getContainer(world.getTileEntity(x, y, z), player)
|
||||
|
||||
def getClientGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
|
||||
guis(ID).getGui(world.getBlockTileEntity(x, y, z), player)
|
||||
guis(ID).getGui(world.getTileEntity(x, y, z), player)
|
||||
}
|
||||
@@ -11,11 +11,11 @@ package net.bdew.lib.gui
|
||||
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.gui.widgets.BaseWidget
|
||||
import net.minecraft.util.Icon
|
||||
import net.minecraft.client.gui.FontRenderer
|
||||
import net.minecraft.client.Minecraft
|
||||
import org.lwjgl.opengl.GL11
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
import net.minecraft.util.IIcon
|
||||
|
||||
trait WidgetContainer {
|
||||
val rect: Rect
|
||||
@@ -76,7 +76,7 @@ trait WidgetContainer {
|
||||
def getOffsetFromWindow: Point
|
||||
|
||||
def drawTexture(r: Rect, uv: Point, color: Color = Color.white): Unit
|
||||
def drawIcon(r: Rect, i: Icon, color: Color = Color.white)
|
||||
def drawIcon(r: Rect, i: IIcon, color: Color = Color.white)
|
||||
def drawTextureScaled(r: Rect, t: TextureLocationScaled, color: Color = Color.white)
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class WidgetContainerWindow(val parent: BaseScreen, xSz: Int, ySz: Int) extends
|
||||
parent.drawTexturedModalRect(r.x, r.y, uv.x, uv.y, r.w, r.h)
|
||||
}
|
||||
|
||||
def drawIcon(r: Rect, i: Icon, color: Color = Color.white) {
|
||||
def drawIcon(r: Rect, i: IIcon, color: Color = Color.white) {
|
||||
color.activate()
|
||||
parent.drawTexturedModelRectFromIcon(r.x, r.y, i, r.w, r.h)
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ package net.bdew.lib.gui.widgets
|
||||
import net.minecraft.client.gui.GuiButton
|
||||
import net.bdew.lib.gui.{Point, Rect}
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.audio.PositionedSoundRecord
|
||||
import net.minecraft.util.ResourceLocation
|
||||
|
||||
class WidgetButton(val rect: Rect, text: String, clicked: WidgetButton => Unit)
|
||||
extends GuiButton(0, rect.x, rect.y, rect.w, rect.h, text) with Widget {
|
||||
|
||||
override def mouseClicked(p: Point, button: Int) {
|
||||
Minecraft.getMinecraft.sndManager.playSoundFX("random.click", 1.0F, 1.0F)
|
||||
Minecraft.getMinecraft.getSoundHandler.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F))
|
||||
clicked(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui._
|
||||
import net.minecraft.util.Icon
|
||||
import net.minecraft.util.IIcon
|
||||
import net.bdew.lib.gui.Rect
|
||||
|
||||
class WidgetSubcontainer(val rect: Rect) extends BaseWidget with WidgetContainer {
|
||||
def getFontRenderer = parent.getFontRenderer
|
||||
def getOffsetFromWindow = parent.getOffsetFromWindow + rect.origin
|
||||
def drawTexture(r: Rect, uv: Point, color: Color = Color.white) = parent.drawTexture(r, uv, color)
|
||||
def drawIcon(r: Rect, i: Icon, color: Color = Color.white) = parent.drawIcon(r, i, color)
|
||||
def drawIcon(r: Rect, i: IIcon, color: Color = Color.white) = parent.drawIcon(r, i, color)
|
||||
def drawTextureScaled(r: Rect, t: TextureLocationScaled, color: Color = Color.white) = parent.drawTextureScaled(r, t, color)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ object ItemUtils {
|
||||
def isSameItem(stack1: ItemStack, stack2: ItemStack): Boolean = {
|
||||
if (stack1 == null || stack2 == null)
|
||||
return stack1 == stack2
|
||||
if (stack1.itemID != stack2.itemID)
|
||||
if (stack1.getItem != stack2.getItem)
|
||||
return false
|
||||
if (stack1.getHasSubtypes && stack2.getItemDamage != stack1.getItemDamage)
|
||||
return false
|
||||
@@ -54,12 +54,12 @@ object ItemUtils {
|
||||
if (toAdd >= stack.stackSize) {
|
||||
target.stackSize += stack.stackSize
|
||||
stack.stackSize = 0
|
||||
inv.onInventoryChanged()
|
||||
inv.markDirty()
|
||||
return null
|
||||
} else if (toAdd > 0) {
|
||||
target.stackSize += toAdd
|
||||
stack.stackSize -= toAdd
|
||||
inv.onInventoryChanged()
|
||||
inv.markDirty()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,16 +10,16 @@
|
||||
package net.bdew.lib.items
|
||||
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.client.renderer.texture.IconRegister
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.Misc
|
||||
|
||||
class SimpleItem(id: Int, val name: String) extends Item(id) {
|
||||
class SimpleItem(val name: String) extends Item() {
|
||||
val modId = Misc.getActiveModId
|
||||
setUnlocalizedName(modId + "." + name)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def registerIcons(reg: IconRegister) {
|
||||
override def registerIcons(reg: IIconRegister) {
|
||||
itemIcon = reg.registerIcon(modId + ":" + name.toLowerCase)
|
||||
}
|
||||
}
|
||||
@@ -14,17 +14,16 @@ import net.minecraft.block.Block
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.bdew.lib.config.IdManager
|
||||
import net.bdew.lib.Misc
|
||||
|
||||
abstract class Machine[T <: Block](val name: String, val blockConstruct: (Int) => T) {
|
||||
abstract class Machine[T <: Block](val name: String, blockConstruct: => T) {
|
||||
var block: T = null.asInstanceOf[T]
|
||||
var tuning: ConfigSection = null
|
||||
var enabled = false
|
||||
val modId = Misc.getActiveModId
|
||||
|
||||
def regBlock(ids: IdManager) {
|
||||
block = blockConstruct(ids.getBlockId(name))
|
||||
def regBlock() {
|
||||
block = blockConstruct
|
||||
GameRegistry.registerBlock(block, name)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
|
||||
if (block.isInstanceOf[HasTE[_]]) {
|
||||
|
||||
@@ -49,7 +49,7 @@ case class DataSlotPower(name: String, parent: TileDataSlots) extends DataSlot {
|
||||
tag.setFloat("stored", stored)
|
||||
if (kind == UpdateKind.GUI)
|
||||
tag.setFloat("capacity", capacity)
|
||||
t.setCompoundTag(name, tag)
|
||||
t.setTag(name, tag)
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
|
||||
@@ -11,13 +11,10 @@ package net.bdew.lib.recipes
|
||||
|
||||
import java.io.Reader
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.{BdLib, Misc}
|
||||
import net.minecraft.block.Block
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.minecraftforge.oredict.{ShapelessOreRecipe, OreDictionary}
|
||||
import java.util.logging.Logger
|
||||
import cpw.mods.fml.common.FMLLog
|
||||
import net.minecraft.item.crafting.FurnaceRecipes
|
||||
|
||||
/**
|
||||
* Main recipe loader class
|
||||
@@ -34,9 +31,6 @@ class RecipeLoader {
|
||||
*/
|
||||
def newParser() = new RecipeParser()
|
||||
|
||||
val log: Logger = Logger.getLogger("RecipeLoader")
|
||||
log.setParent(FMLLog.getLogger)
|
||||
|
||||
/**
|
||||
* Current map of recipe characters to parser item references
|
||||
*/
|
||||
@@ -90,7 +84,7 @@ class RecipeLoader {
|
||||
val l = x.copy()
|
||||
l.stackSize = cnt
|
||||
if (meta != OreDictionary.WILDCARD_VALUE && meta != l.getItemDamage) {
|
||||
log.warning("%s requested with meta %d but specifies %d".format(source, meta, l.getItemDamage))
|
||||
BdLib.logWarn("%s requested with meta %d but specifies %d", source, meta, l.getItemDamage)
|
||||
l.setItemDamage(meta)
|
||||
}
|
||||
return l
|
||||
@@ -178,7 +172,7 @@ class RecipeLoader {
|
||||
if (l.size == 0) error("Concrete ItemStack requested for OD entry '%s' that is empty", id)
|
||||
val s = l.get(0).copy()
|
||||
s.stackSize = cnt
|
||||
log.info("Concrete ItemStack for OD entry '%s' -> %s".format(id, s))
|
||||
BdLib.logInfo("Concrete ItemStack for OD entry '%s' -> %s", id, s)
|
||||
return s
|
||||
case StackMacro(ch) => getConcreteStack(currCharMap(ch), cnt)
|
||||
case StackMod(mod, id) =>
|
||||
@@ -203,7 +197,7 @@ class RecipeLoader {
|
||||
if (!currCharMap.contains(x)) error("Character %s is undefined", x)
|
||||
val r = getRecipeComponent(currCharMap(x))
|
||||
if (r.isInstanceOf[String]) needOd = true
|
||||
log.info("%s -> %s".format(x, r))
|
||||
BdLib.logInfo("%s -> %s", x, r)
|
||||
comp += (x -> r)
|
||||
}
|
||||
return (comp, needOd)
|
||||
@@ -216,29 +210,29 @@ class RecipeLoader {
|
||||
def processStatement(s: Statement): Unit = s match {
|
||||
case StIfHaveMod(mod, thn, els) =>
|
||||
if (Misc.haveModVersion(mod)) {
|
||||
log.info("ifMod: %s found".format(mod))
|
||||
BdLib.logInfo("ifMod: %s found", mod)
|
||||
processStatementsSafe(thn)
|
||||
} else {
|
||||
log.info("ifMod: %s not found".format(mod))
|
||||
BdLib.logInfo("ifMod: %s not found", mod)
|
||||
processStatementsSafe(els)
|
||||
}
|
||||
|
||||
case StIfHaveOD(od, thn, els) =>
|
||||
if (OreDictionary.getOres(od).size() > 0) {
|
||||
log.info("ifOreDict: %s found".format(od))
|
||||
BdLib.logInfo("ifOreDict: %s found", od)
|
||||
processStatementsSafe(thn)
|
||||
} else {
|
||||
log.info("ifOreDict: %s not found".format(od))
|
||||
BdLib.logInfo("ifOreDict: %s not found", od)
|
||||
processStatementsSafe(els)
|
||||
}
|
||||
|
||||
case StClearRecipes(res) =>
|
||||
log.info("Clearing recipes that produce %s".format(res))
|
||||
BdLib.logInfo("Clearing recipes that produce %s", res)
|
||||
delayedStatements = delayedStatements.filter({
|
||||
x =>
|
||||
if (x.isInstanceOf[CraftingStatement])
|
||||
if (x.asInstanceOf[CraftingStatement].result == res) {
|
||||
log.info("Removing recipe %s".format(x))
|
||||
BdLib.logInfo("Removing recipe %s", x)
|
||||
false
|
||||
} else true
|
||||
else true
|
||||
@@ -248,7 +242,7 @@ class RecipeLoader {
|
||||
delayedStatements :+= x
|
||||
|
||||
case x =>
|
||||
log.severe("Can't process %s - this is a programing bug!".format(x))
|
||||
BdLib.logError("Can't process %s - this is a programing bug!", x)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,19 +252,19 @@ class RecipeLoader {
|
||||
def processDelayedStatement(st: DelayedStatement) = st match {
|
||||
case StCharAssign(c, r) =>
|
||||
currCharMap += (c -> r)
|
||||
log.info("Added %s = %s".format(c, r))
|
||||
BdLib.logInfo("Added %s = %s", c, r)
|
||||
|
||||
case StClassMacro(id, cls) =>
|
||||
currClassMacros += (id -> cls)
|
||||
log.info("Added def %s = %s".format(id, cls))
|
||||
BdLib.logInfo("Added def %s = %s", id, cls)
|
||||
|
||||
case StRecipeShaped(rec, res, cnt) =>
|
||||
log.info("Adding shaped recipe %s => %s * %d".format(rec, res, cnt))
|
||||
BdLib.logInfo("Adding shaped recipe %s => %s * %d", rec, res, cnt)
|
||||
val (comp, needOd) = resolveRecipeComponents(rec.mkString(""))
|
||||
val resStack = getConcreteStack(res, cnt)
|
||||
|
||||
if (resStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
|
||||
log.info("Result meta is unset, defaulting to 0")
|
||||
BdLib.logInfo("Result meta is unset, defaulting to 0")
|
||||
resStack.setItemDamage(0)
|
||||
}
|
||||
|
||||
@@ -279,16 +273,16 @@ class RecipeLoader {
|
||||
else
|
||||
Misc.addRecipe(resStack, rec, comp)
|
||||
|
||||
log.info("Done... result=%s, od=%s".format(resStack, needOd))
|
||||
BdLib.logInfo("Done... result=%s, od=%s", resStack, needOd)
|
||||
|
||||
case StRecipeShapeless(rec, res, cnt) =>
|
||||
log.info("Adding shapeless recipe %s => %s * %d".format(rec, res, cnt))
|
||||
BdLib.logInfo("Adding shapeless recipe %s => %s * %d", rec, res, cnt)
|
||||
val (comp, needOd) = resolveRecipeComponents(rec)
|
||||
val resStack = getConcreteStack(res, cnt)
|
||||
val recTrans = rec.toCharArray.map(comp(_))
|
||||
|
||||
if (resStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
|
||||
log.info("Result meta is unset, defaulting to 0")
|
||||
BdLib.logInfo("Result meta is unset, defaulting to 0")
|
||||
resStack.setItemDamage(0)
|
||||
}
|
||||
|
||||
@@ -297,42 +291,37 @@ class RecipeLoader {
|
||||
else
|
||||
GameRegistry.addShapelessRecipe(resStack, recTrans: _*)
|
||||
|
||||
log.info("Done... result=%s, od=%s".format(resStack, needOd))
|
||||
BdLib.logInfo("Done... result=%s, od=%s", resStack, needOd)
|
||||
|
||||
case StSmeltRecipe(in, out, cnt, xp) =>
|
||||
log.info("Adding smelting recipe %s => %s * %d (%f xp)".format(in, out, cnt, xp))
|
||||
BdLib.logInfo("Adding smelting recipe %s => %s * %d (%f xp)", in, out, cnt, xp)
|
||||
val outStack = getConcreteStack(out, cnt)
|
||||
if (outStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
|
||||
log.info("Result meta is unset, defaulting to 0")
|
||||
BdLib.logInfo("Result meta is unset, defaulting to 0")
|
||||
outStack.setItemDamage(0)
|
||||
}
|
||||
for (inStack <- getAllConcreteStacks(in, 1)) {
|
||||
if (inStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
|
||||
FurnaceRecipes.smelting.addSmelting(inStack.itemID, outStack, xp)
|
||||
log.info("added %d -> %s".format(inStack.itemID, outStack))
|
||||
} else {
|
||||
FurnaceRecipes.smelting.addSmelting(inStack.itemID, inStack.getItemDamage, outStack, xp)
|
||||
log.info("added %d@%d -> %s".format(inStack.itemID, inStack.getItemDamage, outStack))
|
||||
}
|
||||
GameRegistry.addSmelting(inStack, outStack, xp)
|
||||
BdLib.logInfo("added %d -> %s", inStack, outStack)
|
||||
}
|
||||
|
||||
case x =>
|
||||
log.severe("Can't process %s - this is a programing bug!".format(x))
|
||||
BdLib.logError("Can't process %s - this is a programing bug!", x)
|
||||
}
|
||||
|
||||
/**
|
||||
* Process delayed statements, clear the list afterwards
|
||||
*/
|
||||
def processDelayedStatements() {
|
||||
log.info("Processing %d delayed statements".format(delayedStatements.size))
|
||||
BdLib.logInfo("Processing %d delayed statements", delayedStatements.size)
|
||||
for (s <- delayedStatements) {
|
||||
try {
|
||||
processDelayedStatement(s)
|
||||
} catch {
|
||||
case e: StatementError =>
|
||||
log.severe("Error while processing %s: %s".format(s, e.getMessage))
|
||||
BdLib.logError("Error while processing %s: %s", s, e.getMessage)
|
||||
case e: Throwable =>
|
||||
log.severe("Error while processing %s: %s".format(s, e))
|
||||
BdLib.logError("Error while processing %s: %s", s, e)
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
@@ -349,19 +338,19 @@ class RecipeLoader {
|
||||
processStatement(s)
|
||||
} catch {
|
||||
case e: StatementError =>
|
||||
log.severe("Error while processing %s: %s".format(s, e.getMessage))
|
||||
BdLib.logError("Error while processing %s: %s", s, e.getMessage)
|
||||
case e: Throwable =>
|
||||
log.severe("Error while processing %s: %s".format(s, e))
|
||||
BdLib.logError("Error while processing %s: %s", s, e)
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def load(f: Reader) {
|
||||
log.info("Starting parsing")
|
||||
BdLib.logInfo("Starting parsing")
|
||||
val r = newParser().doParse(f)
|
||||
log.info("Processing %d statements".format(r.size))
|
||||
BdLib.logInfo("Processing %d statements", r.size)
|
||||
processStatementsSafe(r)
|
||||
log.info("Done")
|
||||
BdLib.logInfo("Done")
|
||||
}
|
||||
}
|
||||
@@ -10,17 +10,18 @@
|
||||
package net.bdew.lib.recipes.gencfg
|
||||
|
||||
import net.bdew.lib.recipes.{Statement, RecipeLoader}
|
||||
import net.bdew.lib.BdLib
|
||||
|
||||
trait GenericConfigLoader extends RecipeLoader {
|
||||
val cfgStore: ConfigSection
|
||||
|
||||
def processConfigStatement(section: ConfigSection, s: CfgStatement): Unit = s match {
|
||||
case CfgVal(id, v) =>
|
||||
log.info("Config: %s%s = %s".format(section.pfx, id, v))
|
||||
BdLib.logInfo("Config: %s%s = %s", section.pfx, id, v)
|
||||
section.set(id, v)
|
||||
case CfgSub(id, st) => processConfigBlock(section.getOrAddSection(id), st)
|
||||
case x =>
|
||||
log.severe("Can't process %s - this is a programing bug!".format(x))
|
||||
BdLib.logError("Can't process %s - this is a programing bug!", x)
|
||||
}
|
||||
|
||||
def processConfigBlock(view: ConfigSection, block: List[CfgStatement]) = for (s <- block) processConfigStatement(view, s)
|
||||
|
||||
@@ -14,12 +14,11 @@ import cpw.mods.fml.relauncher.SideOnly
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.entity.EntityLivingBase
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.Icon
|
||||
import net.minecraft.util.MathHelper
|
||||
import net.minecraft.util.{IIcon, MathHelper}
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraft.world.World
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import java.util.EnumSet
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
/**
|
||||
* Basic logic for block rotatation
|
||||
@@ -29,12 +28,12 @@ trait BaseRotateableBlock extends Block {
|
||||
/**
|
||||
* Override this method to provide your textures, also called when rendering as item
|
||||
*/
|
||||
def getIcon(meta: Int, kind: IconType.Value): Icon
|
||||
def getIcon(meta: Int, kind: IconType.Value): IIcon
|
||||
|
||||
/**
|
||||
* Override this method to provide your textures, if you need to check other state
|
||||
*/
|
||||
def getIcon(world: IBlockAccess, x: Int, y: Int, z: Int, kind: IconType.Value): Icon = getIcon(world.getBlockMetadata(x, y, z), kind)
|
||||
def getIcon(world: IBlockAccess, x: Int, y: Int, z: Int, kind: IconType.Value): IIcon = getIcon(world.getBlockMetadata(x, y, z), kind)
|
||||
|
||||
/**
|
||||
* Set of valid rotations, default is all of them
|
||||
@@ -63,10 +62,10 @@ trait BaseRotateableBlock extends Block {
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def getIcon(side: Int, meta: Int): Icon = getIcon(meta, IconType.fromSideAndDir(side, getDefaultFacing))
|
||||
override def getIcon(side: Int, meta: Int): IIcon = getIcon(meta, IconType.fromSideAndDir(side, getDefaultFacing))
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def getBlockTexture(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int): Icon = getIcon(world, x, y, z, IconType.fromSideAndDir(side, getFacing(world, x, y, z)))
|
||||
override def getIcon(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int): IIcon = getIcon(world, x, y, z, IconType.fromSideAndDir(side, getFacing(world, x, y, z)))
|
||||
|
||||
override def getValidRotations(worldObj: World, x: Int, y: Int, z: Int): Array[ForgeDirection] = getValidFacings.toArray(Array.empty[ForgeDirection])
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
package net.bdew.lib.rotate
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
object IconType extends Enumeration {
|
||||
val BACK = Value(0, "BACK")
|
||||
|
||||
@@ -12,21 +12,21 @@ package net.bdew.lib.rotate
|
||||
import net.minecraft.block.ITileEntityProvider
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraft.world.World
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import cpw.mods.fml.common.FMLCommonHandler
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
/**
|
||||
* Stores rotation data in tile entity. The TE should implement {@link RotateableTile}
|
||||
*/
|
||||
trait RotateableTileBlock extends BaseRotateableBlock with ITileEntityProvider {
|
||||
def setFacing(world: World, x: Int, y: Int, z: Int, facing: ForgeDirection) {
|
||||
world.getBlockTileEntity(x, y, z).asInstanceOf[RotateableTile].rotation := facing
|
||||
world.getTileEntity(x, y, z).asInstanceOf[RotateableTile].rotation := facing
|
||||
}
|
||||
|
||||
def getFacing(world: IBlockAccess, x: Int, y: Int, z: Int): ForgeDirection = {
|
||||
val te: RotateableTile = world.getBlockTileEntity(x, y, z).asInstanceOf[RotateableTile]
|
||||
val te: RotateableTile = world.getTileEntity(x, y, z).asInstanceOf[RotateableTile]
|
||||
if (te == null || te.rotation == null) {
|
||||
FMLCommonHandler.instance().getFMLLogger.warning("Failed gettig rocation for block at %d, %d, %d".format(x, y, z))
|
||||
FMLCommonHandler.instance().getFMLLogger.warn("Failed getting rocation for block at %d, %d, %d".format(x, y, z))
|
||||
return getDefaultFacing
|
||||
}
|
||||
return te.rotation
|
||||
|
||||
@@ -11,7 +11,7 @@ package net.bdew.lib.tile
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.fluids._
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
trait ExposeTank extends TileEntity with IFluidHandler {
|
||||
def getTankFromDirection(dir: ForgeDirection): IFluidTank
|
||||
|
||||
@@ -11,9 +11,9 @@ package net.bdew.lib.tile
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.network.INetworkManager
|
||||
import net.minecraft.network.packet.Packet132TileEntityData
|
||||
import net.minecraft.network.{NetworkManager, Packet}
|
||||
import net.bdew.lib.Event
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity
|
||||
|
||||
class TileExtended extends TileEntity {
|
||||
final val ACT_CLIENT = 1
|
||||
@@ -39,18 +39,18 @@ class TileExtended extends TileEntity {
|
||||
persistLoad.trigger(tag)
|
||||
}
|
||||
|
||||
override final def getDescriptionPacket: Packet132TileEntityData = {
|
||||
override final def getDescriptionPacket: Packet = {
|
||||
if (!sendClientUpdate.hasListeners) return null
|
||||
val tag = new NBTTagCompound
|
||||
sendClientUpdate.trigger(tag)
|
||||
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, ACT_CLIENT, tag)
|
||||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, ACT_CLIENT, tag)
|
||||
}
|
||||
|
||||
override final def onDataPacket(net: INetworkManager, pkt: Packet132TileEntityData) {
|
||||
if (pkt.actionType == ACT_CLIENT)
|
||||
handleClientUpdate.trigger(pkt.data)
|
||||
override final def onDataPacket(net: NetworkManager, pkt: S35PacketUpdateTileEntity) {
|
||||
if (pkt.func_148853_f == ACT_CLIENT)
|
||||
handleClientUpdate.trigger(pkt.func_148857_g)
|
||||
else
|
||||
extDataPacket(pkt.actionType, pkt.data)
|
||||
extDataPacket(pkt.func_148853_f, pkt.func_148857_g)
|
||||
}
|
||||
|
||||
override final def updateEntity() {
|
||||
|
||||
@@ -37,14 +37,14 @@ trait BaseInventory extends IInventory {
|
||||
if (item != null) {
|
||||
if (item.stackSize <= n) {
|
||||
inv(slot) = null
|
||||
onInventoryChanged()
|
||||
markDirty()
|
||||
return item
|
||||
} else {
|
||||
var newstack = item.splitStack(n)
|
||||
if (item.stackSize == 0) {
|
||||
inv(slot) = null
|
||||
}
|
||||
onInventoryChanged()
|
||||
markDirty()
|
||||
return newstack
|
||||
}
|
||||
} else {
|
||||
@@ -55,12 +55,12 @@ trait BaseInventory extends IInventory {
|
||||
def getStackInSlotOnClosing(slot: Int): ItemStack = {
|
||||
var tmp = inv(slot)
|
||||
inv(slot) = null
|
||||
onInventoryChanged()
|
||||
markDirty()
|
||||
return tmp
|
||||
}
|
||||
|
||||
def setInventorySlotContents(slot: Int, stack: ItemStack) = {
|
||||
inv(slot) = stack
|
||||
onInventoryChanged()
|
||||
markDirty()
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,13 @@ import net.minecraft.block.Block
|
||||
import net.minecraft.world.World
|
||||
|
||||
trait BreakableInventoryBlock extends Block {
|
||||
override def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int, meta: Int) {
|
||||
override def breakBlock(world: World, x: Int, y: Int, z: Int, block: Block, meta: Int) {
|
||||
if (!world.isRemote) {
|
||||
val te = world.getBlockTileEntity(x, y, z).asInstanceOf[BreakableInventoryTile]
|
||||
val te = world.getTileEntity(x, y, z).asInstanceOf[BreakableInventoryTile]
|
||||
if (te != null) {
|
||||
te.dropItems()
|
||||
}
|
||||
}
|
||||
super.breakBlock(world, x, y, z, blockId, meta)
|
||||
super.breakBlock(world, x, y, z, block, meta)
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,9 @@ import net.bdew.lib.items.ItemUtils
|
||||
|
||||
trait BreakableInventoryTile extends TileEntity with BaseInventory {
|
||||
def dropItems() {
|
||||
if (worldObj != null && !worldObj.isRemote) {
|
||||
if (getWorldObj != null && !getWorldObj.isRemote) {
|
||||
for (stack <- inv if stack != null) {
|
||||
ItemUtils.throwItemAt(worldObj, xCoord, yCoord, zCoord, stack)
|
||||
ItemUtils.throwItemAt(getWorldObj, xCoord, yCoord, zCoord, stack)
|
||||
}
|
||||
inv = new Array[ItemStack](inv.size)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import net.bdew.lib.tile.TileExtended
|
||||
trait PersistentInventoryTile extends TileExtended with BaseInventory {
|
||||
persistLoad.listen((tag: NBTTagCompound) => {
|
||||
inv = new Array[ItemStack](getSizeInventory)
|
||||
for (nbtItem <- Misc.iterNbtList[NBTTagCompound](tag.getTagList("Items"))) {
|
||||
for (nbtItem <- Misc.iterNbtCompoundList(tag, "Items")) {
|
||||
val slot = nbtItem.getByte("Slot")
|
||||
if (slot >= 0 && slot < inv.size) {
|
||||
inv(slot) = ItemStack.loadItemStackFromNBT(nbtItem)
|
||||
|
||||
Reference in new issue
Block a user