mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-10-27 06:44:05 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c275f434a | ||
|
|
f960050f9c | ||
|
|
87dd7c34c5 | ||
|
|
9fdc6bd880 | ||
|
|
490433a7f4 | ||
|
|
71bef762a6 | ||
|
|
5eef56811b | ||
|
|
5a3fa7ef75 | ||
|
|
2d799bb797 | ||
|
|
03d9b0fef0 | ||
|
|
9b0ed5b0b5 | ||
|
|
e2c7940539 | ||
|
|
cd85553fa1 | ||
|
|
bbe994c28c | ||
|
|
79e308941d | ||
|
|
7a5982bf37 | ||
|
|
5166576d30 | ||
|
|
da3e58b44b | ||
|
|
5bac374211 | ||
|
|
e41e203b7e | ||
|
|
0b87dd83e7 | ||
|
|
49a2f0baec | ||
|
|
35be9bff77 | ||
|
|
2a995f1c05 | ||
|
|
423351bfee | ||
|
|
d67bd24eda | ||
|
|
a10e90a1e1 | ||
|
|
517c3f347f | ||
|
|
0831386798 | ||
|
|
0b45c61c51 | ||
|
|
65aa8a0f66 | ||
|
|
446f2b6e60 | ||
|
|
ecdcdfb05f | ||
|
|
d1d3df184f | ||
|
|
522ac5b57b | ||
|
|
7acca5475f | ||
|
|
1b86f5f7cc | ||
|
|
819197cf1e | ||
|
|
1e71bf7dd9 | ||
|
|
0549f95088 | ||
|
|
06f0007bca | ||
|
|
54499cdb2e | ||
|
|
d80d89acf1 | ||
|
|
926f006f68 | ||
|
|
4697c96cf2 | ||
|
|
78c5ec1362 | ||
|
|
005c300d8f | ||
|
|
4754c209ae | ||
|
|
b89d445b17 | ||
|
|
7eefbb1a31 | ||
|
|
4268019935 |
No files matched your search
+9
-8
@@ -1,9 +1,10 @@
|
||||
/.gradle
|
||||
/build
|
||||
/deps
|
||||
/eclipse
|
||||
/bin
|
||||
/out
|
||||
|
||||
*.ipr
|
||||
*.iml
|
||||
*.iws
|
||||
/build
|
||||
/run
|
||||
/deps/run
|
||||
/eclipse
|
||||
/.gradle
|
||||
/*.iml
|
||||
/*.ipr
|
||||
/.idea
|
||||
+12
-5
@@ -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.2-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'forge'
|
||||
apply plugin: 'scala'
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.2.0"
|
||||
version = "1.4.2"
|
||||
|
||||
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 = "mc1710"
|
||||
|
||||
minecraft {
|
||||
version = "1.6.4-9.11.1.964"
|
||||
version = "1.7.10-10.13.0.1180"
|
||||
replace("BDLIB_VER", project.version)
|
||||
}
|
||||
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+2
-2
@@ -1,6 +1,6 @@
|
||||
#Thu Nov 28 11:30:59 IST 2013
|
||||
#Wed Jul 02 15:54:47 CDT 2014
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip
|
||||
@@ -0,0 +1 @@
|
||||
rootProject.name='bdlib'
|
||||
@@ -10,21 +10,30 @@
|
||||
package net.bdew.lib
|
||||
|
||||
import cpw.mods.fml.common.Mod
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent
|
||||
import java.util.logging.Logger
|
||||
import cpw.mods.fml.common.Mod.EventHandler
|
||||
import cpw.mods.fml.common.event.{FMLPreInitializationEvent, FMLServerStartingEvent}
|
||||
import net.minecraft.command.CommandHandler
|
||||
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.warning(msg.format(args: _*))
|
||||
def logError(msg: String, args: Any*) = log.severe(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 logWarnException(msg: String, t: Throwable, args: Any*) = log.warn(msg.format(args: _*), t)
|
||||
def logErrorException(msg: String, t: Throwable, args: Any*) = log.error(msg.format(args: _*), t)
|
||||
|
||||
@EventHandler
|
||||
def preInit(ev: FMLPreInitializationEvent) {
|
||||
log = ev.getModLog
|
||||
log.info("bdlib BDLIB_VER loaded")
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
def serverStarting(event: FMLServerStartingEvent) {
|
||||
val commandHandler = event.getServer.getCommandManager.asInstanceOf[CommandHandler]
|
||||
commandHandler.registerCommand(new CommandDumpRegistry)
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib
|
||||
|
||||
import org.lwjgl.input.Keyboard
|
||||
import net.minecraft.client.Minecraft
|
||||
import org.lwjgl.input.Keyboard
|
||||
|
||||
/**
|
||||
* Misc functions and shortcuts for clientside code
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import java.io.{BufferedWriter, File, FileWriter}
|
||||
|
||||
import com.google.common.collect.Table
|
||||
import cpw.mods.fml.common.registry.GameData
|
||||
import cpw.mods.fml.relauncher.FMLInjectionData
|
||||
import net.minecraft.command.{CommandBase, ICommandSender}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.fluids.FluidRegistry
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
|
||||
class CommandDumpRegistry extends CommandBase {
|
||||
def getCommandName = "dumpregistry"
|
||||
override def getRequiredPermissionLevel = 2
|
||||
def getCommandUsage(icommandsender: ICommandSender) = "dumpregistry"
|
||||
|
||||
def processCommand(sender: ICommandSender, params: Array[String]) {
|
||||
val mcHome = FMLInjectionData.data()(6).asInstanceOf[File] //is there a better way to get this?
|
||||
val dumpFile = new File(mcHome, "registry.dump")
|
||||
val dumpWriter = new BufferedWriter(new FileWriter(dumpFile))
|
||||
import scala.collection.JavaConversions._
|
||||
try {
|
||||
dumpWriter.write("==== BLOCKS ====\n")
|
||||
dumpWriter.write(GameData.getBlockRegistry.map(GameData.getBlockRegistry.getNameForObject).toList.sorted.mkString("\n"))
|
||||
dumpWriter.write("\n\n")
|
||||
|
||||
dumpWriter.write("==== ITEMS ====\n")
|
||||
dumpWriter.write(GameData.getItemRegistry.map(GameData.getItemRegistry.getNameForObject).toList.sorted.mkString("\n"))
|
||||
dumpWriter.write("\n\n")
|
||||
|
||||
dumpWriter.write("==== CUSTOM STACKS ====\n")
|
||||
val stacksField = classOf[GameData].getDeclaredField("customItemStacks")
|
||||
stacksField.setAccessible(true)
|
||||
val stacksData = stacksField.get(null).asInstanceOf[Table[String, String, ItemStack]]
|
||||
dumpWriter.write(stacksData.cellSet().map(x => x.getRowKey + ":" + x.getColumnKey).toList.sorted.mkString("\n"))
|
||||
dumpWriter.write("\n\n")
|
||||
|
||||
dumpWriter.write("==== ORE DICT ====\n")
|
||||
dumpWriter.write(OreDictionary.getOreNames.sorted.mkString("\n"))
|
||||
dumpWriter.write("\n\n")
|
||||
|
||||
dumpWriter.write("==== FLUIDS ====\n")
|
||||
dumpWriter.write(FluidRegistry.getRegisteredFluids.map(_._1).toList.sorted.mkString("\n"))
|
||||
dumpWriter.write("\n\n")
|
||||
|
||||
CommandBase.func_152373_a(sender, this, "Registry dumped to " + dumpFile.getCanonicalPath)
|
||||
} catch {
|
||||
case e: Throwable =>
|
||||
CommandBase.func_152373_a(sender, this, "Failed to save registry dump: " + e)
|
||||
BdLib.logErrorException("Failed to save registry dump", e)
|
||||
} finally {
|
||||
dumpWriter.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.item.Item
|
||||
|
||||
class CreativeTabContainer {
|
||||
|
||||
class Tab(name: String, item: => Item) extends CreativeTabs(name) {
|
||||
override def getTabIconItem = item
|
||||
}
|
||||
|
||||
BdLib.logInfo("Loaded creative tabs for %s", Misc.getActiveModId)
|
||||
|
||||
def init() {}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class Event2[T, R] extends EventBase[(T, R) => Unit] {
|
||||
}
|
||||
|
||||
object Event {
|
||||
def apply(t: Unit) = new Event0
|
||||
def apply() = new Event0
|
||||
def apply[T] = new Event1[T]
|
||||
def apply[T, R] = new Event2[T, R]
|
||||
}
|
||||
+37
-10
@@ -9,23 +9,33 @@
|
||||
|
||||
package net.bdew.lib
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||
import net.minecraft.util.StatCollector
|
||||
import net.minecraft.item.ItemStack
|
||||
import cpw.mods.fml.common.versioning.{ArtifactVersion, VersionParser}
|
||||
import cpw.mods.fml.common.Loader
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import cpw.mods.fml.common.versioning.{ArtifactVersion, VersionParser}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.util.StatCollector
|
||||
import net.minecraft.world.biome.BiomeGenBase
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
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 iterNbtIntArray(parent: NBTTagCompound, name: String): Iterable[Array[Int]] = {
|
||||
val list = parent.getTagList(name, 11)
|
||||
for (i <- 0 until list.tagCount()) yield list.func_150306_c(i)
|
||||
}
|
||||
|
||||
def getActiveModId = Loader.instance().activeModContainer().getModId
|
||||
|
||||
def toLocal(s: String) = StatCollector.translateToLocal(s)
|
||||
def toLocalF(s: String, params: Any*) = StatCollector.translateToLocal(s).format(params: _*)
|
||||
def hasLocal(s: String) = StatCollector.canTranslate(s)
|
||||
|
||||
def flattenRecipe(pattern: Seq[String], items: Map[Char, AnyRef]) =
|
||||
pattern ++ items.map {
|
||||
@@ -35,7 +45,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]) =
|
||||
@@ -54,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.biomeList.find(_.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)
|
||||
@@ -68,4 +78,21 @@ object Misc {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Because writing this every time is awkward
|
||||
def forgeDirection(i: Int) = ForgeDirection.values()(i)
|
||||
|
||||
// Easy replacement for various "if(foo.isInstanceOf[Bar]) foo.asInstanceOf[Bar]" constructs
|
||||
def asInstanceOpt[T](v: Any, cls: Class[T]) =
|
||||
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.minecraft.block.Block
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
case class BlockRef(x: Int, y: Int, z: Int) {
|
||||
def block(w: IBlockAccess) = Option(w.getBlock(x, y, z))
|
||||
def tile(w: IBlockAccess) = Option(w.getTileEntity(x, y, z))
|
||||
def meta(w: IBlockAccess) = w.getBlockMetadata(x, y, z)
|
||||
|
||||
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)).toMap
|
||||
|
||||
override def toString = "(x=%d y=%d z=%d)".format(x, y, z)
|
||||
|
||||
def getTile[T: ClassTag](w: IBlockAccess) = tile(w) flatMap { tile =>
|
||||
val cls = implicitly[ClassTag[T]].runtimeClass
|
||||
if (cls.isInstance(tile))
|
||||
Some(tile.asInstanceOf[T])
|
||||
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))
|
||||
Some(block.asInstanceOf[T])
|
||||
else None
|
||||
}
|
||||
|
||||
def writeToNBT(tag: NBTTagCompound) {
|
||||
tag.setInteger("x", x)
|
||||
tag.setInteger("y", y)
|
||||
tag.setInteger("z", z)
|
||||
}
|
||||
}
|
||||
|
||||
object BlockRef {
|
||||
def fromTile(te: TileEntity) = BlockRef(te.xCoord, te.yCoord, te.zCoord)
|
||||
def fromNBT(tag: NBTTagCompound) =
|
||||
BlockRef(tag.getInteger("x"), tag.getInteger("y"), tag.getInteger("z"))
|
||||
}
|
||||
@@ -9,22 +9,26 @@
|
||||
|
||||
package net.bdew.lib.block
|
||||
|
||||
import net.minecraft.block.{ITileEntityProvider, Block}
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
import net.bdew.lib.BdLib
|
||||
import net.minecraft.block.{Block, ITileEntityProvider}
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import cpw.mods.fml.common.FMLCommonHandler
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
|
||||
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, 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.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)
|
||||
t = createNewTileEntity(ww, w.getBlockMetadata(x, y, z))
|
||||
ww.setTileEntity(x, y, z, t)
|
||||
case _ =>
|
||||
sys.error("Unable to recreate TE")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
|
||||
trait NamedBlock extends Block {
|
||||
def name: String
|
||||
}
|
||||
|
||||
class SimpleBlock(val name: String, material: Material) extends Block(material) with NamedBlock {
|
||||
val modId = Misc.getActiveModId
|
||||
setBlockName(modId + "." + name)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def registerBlockIcons(reg: IIconRegister) {
|
||||
blockIcon = reg.registerIcon(modId + ":" + name.toLowerCase)
|
||||
}
|
||||
}
|
||||
@@ -9,26 +9,27 @@
|
||||
|
||||
package net.bdew.lib.config
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.block.Block
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.{HasTE, SimpleBlock}
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
class BlockManager(val ids: IdManager) {
|
||||
class BlockManager(creativeTab: CreativeTabs) {
|
||||
def regBlock[T <: SimpleBlock](block: T): T = regBlock(block, block.name)
|
||||
|
||||
def regBlockCls[T <: Block](blockCls: Class[T], name: String, addStack: Boolean = true): T = {
|
||||
val block = blockCls.getConstructor(classOf[Int]).newInstance(ids.getBlockId(name): Integer)
|
||||
regBlock[T](block, name, addStack)
|
||||
}
|
||||
|
||||
def regBlock[T <: Block](block: T, name: String, addStack: Boolean = true): T = {
|
||||
def regBlock[T <: Block](block: T, name: String, addStack: Boolean = false): T = {
|
||||
GameRegistry.registerBlock(block, name)
|
||||
|
||||
block.setCreativeTab(creativeTab)
|
||||
|
||||
if (addStack)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
|
||||
|
||||
if (block.isInstanceOf[HasTE[_]])
|
||||
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass, name)
|
||||
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass,
|
||||
"%s.%s".format(Misc.getActiveModId, name))
|
||||
|
||||
return block
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.config
|
||||
|
||||
import net.minecraftforge.fluids.{FluidRegistry, Fluid}
|
||||
import net.minecraftforge.fluids.{Fluid, FluidRegistry}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,25 +9,23 @@
|
||||
|
||||
package net.bdew.lib.config
|
||||
|
||||
import net.minecraft.item.{ItemStack, Item}
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.items.SimpleItem
|
||||
import net.bdew.lib.items.{NamedItem, SimpleItem}
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
|
||||
class ItemManager(val ids: IdManager) {
|
||||
def regSimpleItem(name: String): SimpleItem = regItem(new SimpleItem(ids.getItemId(name), name), name)
|
||||
class ItemManager(creativeTab: CreativeTabs) {
|
||||
def regSimpleItem(name: String): SimpleItem = regItem(new SimpleItem(name), name)
|
||||
|
||||
def regItem[T <: SimpleItem](item: T): T = regItem[T](item, item.name)
|
||||
def regItem[T <: NamedItem](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)
|
||||
regItem[T](item, name, addStack)
|
||||
}
|
||||
|
||||
def regItem[T <: Item](item: T, name: String, addStack: Boolean = true): T = {
|
||||
def regItem[T <: Item](item: T, name: String, addStack: Boolean = false): T = {
|
||||
GameRegistry.registerItem(item, name)
|
||||
item.setCreativeTab(creativeTab)
|
||||
if (addStack)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(item))
|
||||
return item
|
||||
}
|
||||
|
||||
def load() {}
|
||||
}
|
||||
@@ -9,16 +9,17 @@
|
||||
|
||||
package net.bdew.lib.config
|
||||
|
||||
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
import net.bdew.lib.gui.{GuiHandler, GuiProvider}
|
||||
import net.bdew.lib.machine.Machine
|
||||
import net.bdew.lib.gui.{GuiProvider, GuiHandler}
|
||||
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
|
||||
class MachineManager(ids: IdManager, val tuning: ConfigSection, guiHandler: GuiHandler) {
|
||||
class MachineManager(val tuning: ConfigSection, guiHandler: GuiHandler, creativeTab: CreativeTabs) {
|
||||
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(creativeTab)
|
||||
if (machine.isInstanceOf[GuiProvider])
|
||||
guiHandler.register(machine.asInstanceOf[GuiProvider])
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.covers
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.bdew.lib.items.ItemUtils
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
|
||||
trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
|
||||
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, face: Int, xoffs: Float, yoffs: Float, zoffs: Float): Boolean = {
|
||||
val te = getTE(world, x, y, z)
|
||||
val side = Misc.forgeDirection(face)
|
||||
|
||||
if (player.getCurrentEquippedItem == null && player.isSneaking) {
|
||||
for (cover <- Option(te.covers(side).cval)) {
|
||||
if (!world.isRemote) {
|
||||
te.covers(side) := null
|
||||
te.onCoversChanged()
|
||||
ItemUtils.dropItemToPlayer(world, player, cover)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
activeStack <- Option(player.getCurrentEquippedItem)
|
||||
activeItem <- Option(activeStack.getItem)
|
||||
coverItem <- Misc.asInstanceOpt(activeItem, classOf[ItemCover])
|
||||
if te.isValidCover(side, activeStack) && coverItem.isValidTile(te, activeStack)
|
||||
} {
|
||||
if (!world.isRemote) {
|
||||
for (cover <- Option(te.covers(side).cval))
|
||||
ItemUtils.throwItemAt(world, te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ, cover.copy())
|
||||
|
||||
te.covers(side) := activeStack.splitStack(1)
|
||||
|
||||
if (activeStack.stackSize <= 0) player.inventory.setInventorySlotContents(player.inventory.currentItem, null)
|
||||
te.onCoversChanged()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
super.onBlockActivated(world, x, y, z, player, face, xoffs, yoffs, zoffs)
|
||||
}
|
||||
|
||||
override def getIcon(w: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
|
||||
(for {
|
||||
coverStack <- Option(getTE(w, x, y, z).covers(Misc.forgeDirection(side)).cval)
|
||||
coverItem <- Option(coverStack.getItem) flatMap (Misc.asInstanceOpt(_, classOf[ItemCover]))
|
||||
} yield coverItem.getCoverIcon(coverStack)
|
||||
) getOrElse super.getIcon(w, x, y, z, side)
|
||||
|
||||
override def breakBlock(world: World, x: Int, y: Int, z: Int, block: Block, meta: Int) {
|
||||
if (!world.isRemote)
|
||||
for ((dir, covOpt) <- getTE(world, x, y, z).covers; cover <- Option(covOpt.cval))
|
||||
ItemUtils.throwItemAt(world, x, y, z, cover)
|
||||
super.breakBlock(world, x, y, z, block, meta)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.covers
|
||||
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
trait ItemCover extends Item {
|
||||
/**
|
||||
* @return Icon to render, MUST be on terrain spritesheet (0), not item!
|
||||
*/
|
||||
def getCoverIcon(stack: ItemStack): IIcon
|
||||
|
||||
/**
|
||||
* Perform tick, called on server only
|
||||
*/
|
||||
def tickCover(te: TileCoverable, side: ForgeDirection, cover: ItemStack)
|
||||
|
||||
/**
|
||||
* Checks if this cover can be installed on a specific TE
|
||||
*/
|
||||
def isValidTile(te: TileCoverable, cover: ItemStack): Boolean
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.covers
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.data.DataSlotItemStack
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
trait TileCoverable extends TileDataSlots {
|
||||
val covers = (ForgeDirection.VALID_DIRECTIONS map { x =>
|
||||
x -> DataSlotItemStack("cover_" + x.toString.toLowerCase, this).setUpdate(UpdateKind.SAVE, UpdateKind.WORLD, UpdateKind.RENDER)
|
||||
}).toMap
|
||||
|
||||
/**
|
||||
* Checks if a specific cover can be installed here
|
||||
*/
|
||||
def isValidCover(side: ForgeDirection, cover: ItemStack): Boolean
|
||||
|
||||
/**
|
||||
* Called when new covers are installed
|
||||
*/
|
||||
def onCoversChanged() {}
|
||||
|
||||
def tickCovers() =
|
||||
for {
|
||||
(dir, coverSlot) <- covers
|
||||
coverStack <- Option(coverSlot.cval)
|
||||
coverItem <- Option(coverStack.getItem) flatMap (Misc.asInstanceOpt(_, classOf[ItemCover]))
|
||||
} {
|
||||
coverItem.tickCover(this, dir, coverStack)
|
||||
}
|
||||
|
||||
serverTick.listen(tickCovers)
|
||||
}
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotVal}
|
||||
|
||||
case class DataSlotBoolean(name: String, parent: TileDataSlots, default: Boolean = false) extends DataSlotVal[Boolean] {
|
||||
var cval = default
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlotVal}
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
|
||||
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
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlotNumeric, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotNumeric}
|
||||
|
||||
case class DataSlotFloat(name: String, parent: TileDataSlots, default: Float = 0) extends DataSlotNumeric[Float](default) {
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setFloat(name, cval)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import com.mojang.authlib.GameProfile
|
||||
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
|
||||
case class DataSlotGameProfile(name: String, parent: TileDataSlots) extends DataSlotVal[GameProfile] {
|
||||
override var cval: GameProfile = null
|
||||
|
||||
override def load(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||
cval = if (t.hasKey(name + "_uid") || t.hasKey(name + "_name")) {
|
||||
val uid = if (t.hasKey(name + "_uid")) UUID.fromString(t.getString(name + "_uid")) else null
|
||||
val uname = if (t.hasKey(name + "_name")) t.getString(name + "_name") else null
|
||||
new GameProfile(uid, uname)
|
||||
} else null
|
||||
}
|
||||
|
||||
override def save(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||
if (cval != null) {
|
||||
Option(cval.getId) map (id => t.setString(name + "_uid", id.toString))
|
||||
Option(cval.getName) filterNot (name => StringUtils.isBlank(name)) map (name => t.setString(name + "_name", name))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlotNumeric, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotNumeric}
|
||||
|
||||
case class DataSlotInt(name: String, parent: TileDataSlots, default: Int = 0) extends DataSlotNumeric[Int](default) {
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setInteger(name, cval)
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlotVal}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
case class DataSlotItemStack(name: String, parent: TileDataSlots) extends DataSlotVal[ItemStack] {
|
||||
var cval: ItemStack = null
|
||||
@@ -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))
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 net.bdew.lib.data.base.DataSlotVal
|
||||
|
||||
abstract class DataSlotOption[T] extends DataSlotVal[Option[T]] {
|
||||
override var cval: Option[T] = None
|
||||
|
||||
def set(v: T) {
|
||||
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||
cval = Some(v)
|
||||
}
|
||||
|
||||
def unset() {
|
||||
cval = None
|
||||
}
|
||||
|
||||
override def isSame(v: Option[T]) = {
|
||||
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.isSame(v)
|
||||
}
|
||||
override def :=(that: Option[T]) = {
|
||||
if (that == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.:=(that)
|
||||
}
|
||||
override def :!=(that: Option[T]) = {
|
||||
if (that == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.:!=(that)
|
||||
}
|
||||
override def :==(that: Option[T]) = {
|
||||
if (that == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.:==(that)
|
||||
}
|
||||
override def update(v: Option[T]) = {
|
||||
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.update(v)
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotVal}
|
||||
|
||||
case class DataSlotString(name: String, parent: TileDataSlots, default: String = null) extends DataSlotVal[String] {
|
||||
var cval: String = default
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.minecraftforge.fluids.{IFluidTank, FluidTank, FluidStack}
|
||||
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlot}
|
||||
import net.minecraftforge.fluids.{FluidStack, FluidTank, IFluidTank}
|
||||
|
||||
abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank with DataSlot {
|
||||
var oldStack: FluidStack = null
|
||||
@@ -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) {
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.bdew.lib.gui.NoInvContainer
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.minecraft.inventory.ICrafting
|
||||
|
||||
trait ContainerDataSlots extends NoInvContainer {
|
||||
@@ -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,7 +9,7 @@
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
import language.implicitConversions
|
||||
import scala.language.implicitConversions
|
||||
|
||||
/**
|
||||
* Base trait for data slots that hold primitive values
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
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.nbt.NBTTagCompound
|
||||
import net.minecraft.network.Packet
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
trait TileDataSlots extends TileExtended {
|
||||
val dataSlots = mutable.HashMap.empty[String, DataSlot]
|
||||
@@ -32,7 +34,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 +44,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) {
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.bdew.lib.items.ItemUtils
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
abstract class BaseContainer(te: IInventory) extends NoInvContainer {
|
||||
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = {
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.inventory.GuiContainer
|
||||
import net.minecraft.inventory.Container
|
||||
import scala.collection.mutable
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContainer(cont) {
|
||||
xSize = xSz
|
||||
ySize = ySz
|
||||
@@ -24,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() {
|
||||
@@ -52,10 +54,10 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
|
||||
|
||||
widgets.handleTooltip(Point(x, y) - rect.origin, tip)
|
||||
|
||||
import collection.JavaConversions._
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
if (tip.size > 0)
|
||||
drawHoveringText(tip, x, y, fontRenderer)
|
||||
drawHoveringText(tip, x, y, getFontRenderer)
|
||||
}
|
||||
|
||||
protected def drawGuiContainerBackgroundLayer(f: Float, x: Int, y: Int) {
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import org.lwjgl.opengl.GL11
|
||||
import net.bdew.lib.Misc
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
case class Color(r: Float, g: Float, b: Float, a: Float = 1) {
|
||||
def this(c: (Float, Float, Float)) = this(c._1, c._2, c._3)
|
||||
@@ -29,6 +29,11 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1) {
|
||||
|
||||
object Color {
|
||||
def fromRGB(r: Int, g: Int, b: Int, a: Int = 255) = Color(r / 255F, g / 255F, b / 255F, a / 255F)
|
||||
def fromInt(v: Int) = Color(
|
||||
((v >> 16) & 0xFF) / 255F,
|
||||
((v >> 8) & 0xFF) / 255F,
|
||||
(v & 0xFF) / 255F
|
||||
)
|
||||
final val white = Color(1, 1, 1)
|
||||
final val black = Color(0, 0, 0)
|
||||
final val red = Color(1, 0, 0)
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
import net.minecraft.client.gui.FontRenderer
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
|
||||
trait DrawTarget {
|
||||
def getZLevel: Float
|
||||
|
||||
@@ -10,10 +10,11 @@
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler
|
||||
import scala.collection.mutable
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.world.World
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class GuiHandler extends IGuiHandler {
|
||||
val guis = mutable.Map.empty[Int, GuiProvider]
|
||||
|
||||
@@ -24,8 +25,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)
|
||||
}
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
trait GuiProvider {
|
||||
def guiId: Int
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.inventory.{Slot, Container}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.entity.player.{EntityPlayer, InventoryPlayer, EntityPlayerMP}
|
||||
import net.minecraft.entity.player.{EntityPlayer, EntityPlayerMP, InventoryPlayer}
|
||||
import net.minecraft.inventory.{Container, Slot}
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
abstract class NoInvContainer extends Container {
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
trait SlotClickable extends Slot {
|
||||
def onClick(button: Int, mods: Int, player: EntityPlayer): ItemStack
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.util.{Icon, ResourceLocation}
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.renderer.texture.TextureMap
|
||||
import net.minecraft.util.{IIcon, ResourceLocation}
|
||||
|
||||
trait Texture {
|
||||
def u1: Float
|
||||
@@ -29,7 +29,7 @@ class InterpolatedTexture(val texture: Texture, rect: Rect) extends Texture {
|
||||
def v2 = rect.y2 * (texture.v2 - texture.v1) + texture.v1
|
||||
}
|
||||
|
||||
class IconWrapper(val resource: ResourceLocation, val icon: Icon) extends Texture {
|
||||
class IconWrapper(val resource: ResourceLocation, val icon: IIcon) extends Texture {
|
||||
def u1 = icon.getMinU
|
||||
def u2 = icon.getMaxU
|
||||
def v1 = icon.getMinV
|
||||
@@ -47,7 +47,8 @@ class Sprite(val resource: ResourceLocation, r: Rect, scale: Int = 256) extends
|
||||
}
|
||||
|
||||
class ScaledResourceLocation(path: String, val scale: Int = 256) extends ResourceLocation(path) {
|
||||
def this(domain: String, path: String, scale: Int = 256) = this(domain + ":" + path, scale)
|
||||
def this(domain: String, path: String, scale: Int) = this(domain + ":" + path, scale)
|
||||
def this(domain: String, path: String) = this(domain + ":" + path, 256)
|
||||
}
|
||||
|
||||
object Texture {
|
||||
@@ -55,7 +56,7 @@ object Texture {
|
||||
val BLOCKS = TextureMap.locationBlocksTexture
|
||||
|
||||
// From minecraft Icon
|
||||
def apply(res: ResourceLocation, i: Icon) = new IconWrapper(res, i)
|
||||
def apply(res: ResourceLocation, i: IIcon) = new IconWrapper(res, i)
|
||||
|
||||
// From a ResourceLocation and position, scale optional
|
||||
def apply(res: ResourceLocation, r: Rect) = new Sprite(res, r)
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.gui.widgets.BaseWidget
|
||||
import net.minecraft.client.gui.FontRenderer
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
trait WidgetContainer extends DrawTarget {
|
||||
val rect: Rect
|
||||
val widgets = mutable.MutableList.empty[BaseWidget]
|
||||
|
||||
@@ -13,7 +13,7 @@ package object gui {
|
||||
type Rect = BaseRect[Float]
|
||||
type Point = BasePoint[Float]
|
||||
|
||||
import language.implicitConversions
|
||||
import scala.language.implicitConversions
|
||||
|
||||
implicit def awt2point(p: java.awt.Point) = BasePoint(p.x, p.y)
|
||||
implicit def point2awt(p: BasePoint[Int]): java.awt.Point = new java.awt.Point(p.x, p.y)
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.{Point, Rect, WidgetContainer}
|
||||
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.gui.{WidgetContainer, Point, Rect}
|
||||
|
||||
trait BaseWidget {
|
||||
val rect: Rect
|
||||
|
||||
@@ -9,15 +9,17 @@
|
||||
|
||||
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.client.gui.GuiButton
|
||||
import net.minecraft.util.ResourceLocation
|
||||
|
||||
class WidgetButton(val rect: Rect, text: String, clicked: WidgetButton => Unit)
|
||||
extends GuiButton(0, rect.x.round, rect.y.round, rect.w.round, rect.h.round, 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui._
|
||||
import net.bdew.lib.data.base.DataSlotNumeric
|
||||
import net.bdew.lib.gui._
|
||||
|
||||
class WidgetFillDataslot[T](val rect: Rect, val texture: Texture, dir: Direction.Direction, dslot: DataSlotNumeric[T], maxval: T)(implicit num: Numeric[T]) extends Widget {
|
||||
|
||||
|
||||
@@ -9,19 +9,21 @@
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.{Texture, Point, Rect}
|
||||
import net.bdew.lib.data.DataSlotTankBase
|
||||
import scala.collection.mutable
|
||||
import java.text.DecimalFormat
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.data.DataSlotTankBase
|
||||
import net.bdew.lib.gui.{Point, Rect, Texture}
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase) extends Widget {
|
||||
val formater = new DecimalFormat("#,###")
|
||||
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
|
||||
if (dslot.getFluid != null) {
|
||||
tip += dslot.getFluid.getFluid.getLocalizedName
|
||||
tip += dslot.getFluid.getFluid.getLocalizedName(dslot.getFluid)
|
||||
tip += "%s/%s mB".format(formater.format(dslot.getFluidAmount), formater.format(dslot.getCapacity))
|
||||
} else {
|
||||
tip += Misc.toLocal("bdlib.label.empty")
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui._
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.data.DataSlotFloat
|
||||
import net.bdew.lib.gui._
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetProgressBar(rect: Rect, texture: Texture, dslot: DataSlotFloat) extends WidgetFillDataslot[Float](rect, texture, Direction.RIGHT, dslot, 1) {
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += "%.0f".format(dslot.cval * 100) + "%"
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui._
|
||||
import net.bdew.lib.gui.Rect
|
||||
|
||||
class WidgetSubcontainer(val rect: Rect) extends BaseWidget with WidgetContainer with SimpleDrawTarget {
|
||||
def getZLevel = parent.getZLevel
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.minecraft.client.gui.{FontRenderer, GuiTextField}
|
||||
import net.bdew.lib.gui.{Point, Rect}
|
||||
import net.minecraft.client.gui.{FontRenderer, GuiTextField}
|
||||
|
||||
class WidgetTextEdit(val rect: Rect, fr: FontRenderer) extends GuiTextField(fr, rect.x.round, rect.y.round, rect.w.round, rect.h.round) with Widget {
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
|
||||
package net.bdew.lib.items
|
||||
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.{Item, ItemBlock, ItemStack}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
}
|
||||
@@ -9,12 +9,15 @@
|
||||
|
||||
package net.bdew.lib.items
|
||||
|
||||
import net.minecraft.entity.item.EntityItem
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.world.World
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.IInventory
|
||||
import java.util.Random
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.entity.item.EntityItem
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.{IInventory, ISidedInventory}
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.world.World
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
object ItemUtils {
|
||||
def throwItemAt(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
|
||||
@@ -37,7 +40,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 +57,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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,4 +79,27 @@ object ItemUtils {
|
||||
|
||||
return stack
|
||||
}
|
||||
|
||||
def getAccessibleSlotsFromSide(inv: IInventory, side: ForgeDirection) =
|
||||
(Misc.asInstanceOpt(inv, classOf[ISidedInventory])
|
||||
map (_.getAccessibleSlotsFromSide(side.ordinal()).toList)
|
||||
getOrElse (0 until inv.getSizeInventory))
|
||||
|
||||
def findItemInInventory(inv: IInventory, item: Item) =
|
||||
Range(0, inv.getSizeInventory).map(x => x -> inv.getStackInSlot(x))
|
||||
.find({ case (slot, stack) => stack != null && stack.getItem == item })
|
||||
.map({ case (slot, stack) => slot })
|
||||
|
||||
def copyWithRandomSize(template: ItemStack, max: Int, rand: Random) = {
|
||||
val newSize = rand.nextInt(max)
|
||||
val newStack = template.copy()
|
||||
newStack.stackSize =
|
||||
if (newSize > newStack.getMaxStackSize)
|
||||
newStack.getMaxStackSize
|
||||
else if (newSize <= 0)
|
||||
1
|
||||
else
|
||||
newSize
|
||||
newStack
|
||||
}
|
||||
}
|
||||
@@ -9,17 +9,21 @@
|
||||
|
||||
package net.bdew.lib.items
|
||||
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.client.renderer.texture.IconRegister
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import net.minecraft.item.Item
|
||||
|
||||
class SimpleItem(id: Int, val name: String) extends Item(id) {
|
||||
trait NamedItem extends Item {
|
||||
def name: String
|
||||
}
|
||||
|
||||
class SimpleItem(val name: String) extends Item with NamedItem {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
package net.bdew.lib.items.inventory
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.bdew.lib.gui.BaseContainer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
class ContainerItemInventory(inv: InventoryItemAdapter, player: EntityPlayer) extends BaseContainer(inv) {
|
||||
def canInteractWith(entityplayer: EntityPlayer) = entityplayer == player
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
package net.bdew.lib.items.inventory
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.bdew.lib.tile.inventory.BaseInventory
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.nbt.{NBTTagList, NBTTagCompound}
|
||||
import net.bdew.lib.tile.inventory.BaseInventory
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||
|
||||
class InventoryItemAdapter(val player: EntityPlayer, val slot: Int, val size: Int, val tagName: String) extends BaseInventory {
|
||||
def getSizeInventory = size
|
||||
@@ -24,7 +24,7 @@ class InventoryItemAdapter(val player: EntityPlayer, val slot: Int, val size: In
|
||||
|
||||
def load() {
|
||||
val tag = getStack.getTagCompound
|
||||
for (nbtItem <- Misc.iterNbtList[NBTTagCompound](tag.getTagList(tagName))) {
|
||||
for (nbtItem <- Misc.iterNbtCompoundList(tag, tagName)) {
|
||||
val slot = nbtItem.getByte("Slot")
|
||||
if (slot >= 0 && slot < inv.size) {
|
||||
inv(slot) = ItemStack.loadItemStackFromNBT(nbtItem)
|
||||
@@ -32,7 +32,7 @@ class InventoryItemAdapter(val player: EntityPlayer, val slot: Int, val size: In
|
||||
}
|
||||
}
|
||||
|
||||
def onInventoryChanged() {
|
||||
def markDirty() {
|
||||
if (!getStack.hasTagCompound) getStack.setTagCompound(new NBTTagCompound)
|
||||
val tag = getStack.getTagCompound
|
||||
val itemList = new NBTTagList
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
package net.bdew.lib.items.inventory
|
||||
|
||||
import net.minecraft.item.Item
|
||||
import net.bdew.lib.gui.GuiProvider
|
||||
import cpw.mods.fml.common.Loader
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.bdew.lib.BdLib
|
||||
import net.bdew.lib.gui.GuiProvider
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.world.World
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,24 +9,23 @@
|
||||
|
||||
package net.bdew.lib.machine
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
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
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
|
||||
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(creativeTab: CreativeTabs) {
|
||||
block = blockConstruct
|
||||
GameRegistry.registerBlock(block, name)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
|
||||
block.setCreativeTab(creativeTab)
|
||||
if (block.isInstanceOf[HasTE[_]]) {
|
||||
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass, "%s.%s".format(modId, name))
|
||||
}
|
||||
|
||||
@@ -0,0 +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.network
|
||||
|
||||
abstract class Message extends Serializable
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.network
|
||||
|
||||
import java.util
|
||||
|
||||
import cpw.mods.fml.common.network.{FMLEmbeddedChannel, FMLOutboundHandler, NetworkRegistry}
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import io.netty.channel.{ChannelFutureListener, ChannelHandler}
|
||||
import net.bdew.lib.{BdLib, Misc}
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
|
||||
class NetChannel(val name: String) {
|
||||
var channels: util.EnumMap[Side, FMLEmbeddedChannel] = null
|
||||
|
||||
def init() {
|
||||
channels = NetworkRegistry.INSTANCE.newChannel(name, new SerializedMessageCodec)
|
||||
BdLib.logInfo("Initialized network channel '%s' for mod '%s'", name, Misc.getActiveModId)
|
||||
addHandler(Side.SERVER, new NetChannelServerHandler(this))
|
||||
addHandler(Side.CLIENT, new NetChannelClientHandler(this))
|
||||
}
|
||||
|
||||
var clientChain = PartialFunction.empty[Message, Unit]
|
||||
var serverChain = PartialFunction.empty[(Message, EntityPlayerMP), Unit]
|
||||
|
||||
def regServerHandler(f: PartialFunction[(Message, EntityPlayerMP), Unit]) =
|
||||
serverChain = serverChain.orElse(f)
|
||||
|
||||
def regClientHandler(f: PartialFunction[Message, Unit]) =
|
||||
clientChain = clientChain.orElse(f)
|
||||
|
||||
private def addHandler(side: Side, handler: ChannelHandler) {
|
||||
val ch = channels.get(side)
|
||||
val name = ch.findChannelHandlerNameForType(classOf[SerializedMessageCodec])
|
||||
ch.pipeline().addAfter(name, side + "Handler", handler)
|
||||
}
|
||||
|
||||
def sendToAll(message: Message) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL)
|
||||
channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
def sendTo(message: Message, player: EntityPlayerMP) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER)
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player)
|
||||
channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
def sendToAllAround(message: Message, point: NetworkRegistry.TargetPoint) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT)
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point)
|
||||
channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
def sendToDimension(message: Message, dimensionId: Int) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION)
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(new Integer(dimensionId))
|
||||
channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
def sendToServer(message: Message) {
|
||||
channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER)
|
||||
channels.get(Side.CLIENT).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.network
|
||||
|
||||
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
|
||||
import net.bdew.lib.BdLib
|
||||
|
||||
class NetChannelClientHandler(ch: NetChannel) extends SimpleChannelInboundHandler[Message] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: Message) {
|
||||
try {
|
||||
if (ch.clientChain.isDefinedAt(msg))
|
||||
ch.clientChain(msg)
|
||||
else
|
||||
BdLib.logWarn("Unable to handle message from server: %s", msg)
|
||||
} catch {
|
||||
case e: Throwable => BdLib.logErrorException("Error handling packet", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.network
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry
|
||||
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
|
||||
import net.bdew.lib.BdLib
|
||||
import net.minecraft.network.NetHandlerPlayServer
|
||||
|
||||
class NetChannelServerHandler(ch: NetChannel) extends SimpleChannelInboundHandler[Message] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: Message) {
|
||||
try {
|
||||
val player = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get.asInstanceOf[NetHandlerPlayServer].playerEntity
|
||||
if (ch.serverChain.isDefinedAt(msg, player))
|
||||
ch.serverChain(msg, player)
|
||||
else
|
||||
BdLib.logWarn("Unable to handle message from user %s: %s", player.getDisplayName, msg)
|
||||
} catch {
|
||||
case e: Throwable => BdLib.logErrorException("Error handling packet", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.network
|
||||
|
||||
import java.io.{ObjectInputStream, ObjectOutputStream}
|
||||
import java.util
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket
|
||||
import io.netty.buffer.{ByteBufInputStream, ByteBufOutputStream, Unpooled}
|
||||
import io.netty.channel.ChannelHandler.Sharable
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import io.netty.handler.codec.MessageToMessageCodec
|
||||
import net.bdew.lib.BdLib
|
||||
|
||||
@Sharable
|
||||
class SerializedMessageCodec extends MessageToMessageCodec[FMLProxyPacket, Message] {
|
||||
def encode(ctx: ChannelHandlerContext, msg: Message, out: util.List[AnyRef]) {
|
||||
val buff = Unpooled.buffer()
|
||||
val writer = new ObjectOutputStream(new ByteBufOutputStream(buff))
|
||||
writer.writeObject(msg)
|
||||
val pkt = new FMLProxyPacket(buff, ctx.channel.attr(NetworkRegistry.FML_CHANNEL).get)
|
||||
out.add(pkt)
|
||||
}
|
||||
|
||||
def decode(ctx: ChannelHandlerContext, msg: FMLProxyPacket, out: util.List[AnyRef]) {
|
||||
try {
|
||||
val reader = new ObjectInputStream(new ByteBufInputStream(msg.payload()))
|
||||
out.add(reader.readObject())
|
||||
} catch {
|
||||
case e: Throwable => BdLib.log.error("Error decoding packet", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlot}
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
|
||||
import net.bdew.lib.machine.PoweredMachine
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
case class DataSlotPower(name: String, parent: TileDataSlots) extends DataSlot {
|
||||
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
||||
@@ -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) {
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.minecraft.item.{ItemStack, Item}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.entity.EntityLivingBase
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
trait ItemPoweredBase extends Item {
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots}
|
||||
import net.bdew.lib.tile.inventory.{BreakableInventoryTile, SidedInventory, PersistentInventoryTile}
|
||||
import net.bdew.lib.data.DataSlotFloat
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
|
||||
import net.bdew.lib.machine.ProcessorMachine
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.lib.tile.inventory.{BreakableInventoryTile, PersistentInventoryTile, SidedInventory}
|
||||
|
||||
abstract class TileBaseProcessor extends TileExtended
|
||||
with TileDataSlots
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.lib.machine.PoweredMachine
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
|
||||
trait TilePoweredBase extends TileExtended {
|
||||
def power: DataSlotPower
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.bdew.lib.gui.{Texture, Point, Rect}
|
||||
import scala.collection.mutable
|
||||
import java.text.DecimalFormat
|
||||
|
||||
import net.bdew.lib.gui.widgets.Widget
|
||||
import net.bdew.lib.gui.{Point, Rect, Texture}
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetPowerGauge(val rect: Rect, texture: Texture, dslot: DataSlotPower) extends Widget {
|
||||
val formater = new DecimalFormat("#,###")
|
||||
|
||||
@@ -28,31 +28,33 @@ abstract class StackRef
|
||||
case class StackOreDict(id: String) extends StackRef
|
||||
|
||||
/**
|
||||
* Mod item reference [[cpw.mods.fml.common.registry.GameRegistry.findItemStack]]
|
||||
* Syntax: {modID}:{name}
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specModStack]]
|
||||
* Generic Referende
|
||||
* Syntax: S:{modid}:{name}
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specGenericStack]]
|
||||
* @param mod modId of owner mod
|
||||
* @param id name of the stack
|
||||
* @param name name of the stack
|
||||
*/
|
||||
case class StackMod(mod: String, id: String) extends StackRef
|
||||
case class StackGeneric(mod: String, name: String) extends StackRef
|
||||
|
||||
/**
|
||||
* Vanilla block reference
|
||||
* Syntax: B:{name} [@ {meta}]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specMcBlock]]
|
||||
* @param name Unlocalized name (without "tile.")
|
||||
* Block reference
|
||||
* Syntax: B:[{modid}:]{name} [@ {meta}]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specBlock]]
|
||||
* @param mod modId of owner mod, default is "minecraft"
|
||||
* @param name Registered name
|
||||
* @param meta Metadata / Damage
|
||||
*/
|
||||
case class StackMCBlock(name: String, meta: Int) extends StackRef
|
||||
case class StackBlock(mod: String, name: String, meta: Int) extends StackRef
|
||||
|
||||
/**
|
||||
* Vanilla item reference
|
||||
* Syntax: I:{name} [@ {meta}]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specMcItem]]
|
||||
* @param name Unlocalized name (without "item.")
|
||||
* Item reference
|
||||
* Syntax: I:[{modid}:]{name} [@ {meta}]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.specItem]]
|
||||
* @param mod modId of owner mod, default is "minecraft"
|
||||
* @param name Registered name
|
||||
* @param meta Metadata / Damage
|
||||
*/
|
||||
case class StackMCItem(name: String, meta: Int) extends StackRef
|
||||
case class StackItem(mod: String, name: String, meta: Int) extends StackRef
|
||||
|
||||
/**
|
||||
* Reference to an Item/Block/ItemStack pulic static field
|
||||
@@ -123,6 +125,16 @@ case class StClassMacro(id: String, cls: String) extends DelayedStatement
|
||||
*/
|
||||
case class StIfHaveMod(mod: String, thn: List[Statement], els: List[Statement]) extends Statement
|
||||
|
||||
/**
|
||||
* Conditional block - checks if api is loaded
|
||||
* Syntax: ifAPI {string} { {statements} } [else { {statements} }]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.ifApi]]
|
||||
* @param mod API modid
|
||||
* @param thn Statements to run if present
|
||||
* @param els Statements to run otherwise
|
||||
*/
|
||||
case class StIfHaveAPI(mod: String, thn: List[Statement], els: List[Statement]) extends Statement
|
||||
|
||||
/**
|
||||
* Conditional block - checks if mod is loaded
|
||||
* Can contain only delayed statements
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
package net.bdew.lib.recipes
|
||||
|
||||
import java.io.Reader
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
|
||||
import cpw.mods.fml.common.ModAPIManager
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
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 net.minecraft.item.crafting.FurnaceRecipes
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraftforge.oredict.{OreDictionary, ShapelessOreRecipe}
|
||||
|
||||
/**
|
||||
* Main recipe loader class
|
||||
@@ -33,9 +33,6 @@ class RecipeLoader {
|
||||
*/
|
||||
def newParser() = new RecipeParser()
|
||||
|
||||
val log: Logger = Logger.getLogger("RecipeLoader")
|
||||
log.setParent(BdLib.log)
|
||||
|
||||
/**
|
||||
* Current map of recipe characters to parser item references
|
||||
*/
|
||||
@@ -89,7 +86,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
|
||||
@@ -164,6 +161,8 @@ class RecipeLoader {
|
||||
case _ => Seq(getConcreteStack(s))
|
||||
}
|
||||
|
||||
def notNull[T](v: T, err: => String) = if (v == null) error(err) else v
|
||||
|
||||
/**
|
||||
* Returns an ItemStack that match a reference
|
||||
* This is the main StackRef resolution method
|
||||
@@ -177,15 +176,15 @@ 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) =>
|
||||
val i = GameRegistry.findItemStack(mod, id, cnt)
|
||||
if (i == null) error("Item %s:%s not found", mod, id)
|
||||
i
|
||||
case StackMCBlock(id, meta) => new ItemStack(Vanilla.blocks(id), cnt, meta)
|
||||
case StackMCItem(id, meta) => new ItemStack(Vanilla.items(id), cnt, meta)
|
||||
case StackGeneric(mod, id) =>
|
||||
notNull(GameRegistry.findItemStack(mod, id, cnt), "Stack not found %s:%s".format(mod, id))
|
||||
case StackBlock(mod, id, meta) =>
|
||||
new ItemStack(notNull(GameRegistry.findBlock(mod, id), "Block not found %s:%s".format(mod, id)), cnt, meta)
|
||||
case StackItem(mod, id, meta) =>
|
||||
new ItemStack(notNull(GameRegistry.findItem(mod, id), "Item not found %s:%s".format(mod, id)), cnt, meta)
|
||||
case StackReflect(cls, field, meta) => reflectStack(cls, field, meta, cnt)
|
||||
case StackGetter(cls, method, param, meta) => reflectStackGetter(cls, method, param, meta, cnt)
|
||||
}
|
||||
@@ -202,7 +201,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)
|
||||
@@ -215,20 +214,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 StIfHaveAPI(mod, thn, els) =>
|
||||
if (ModAPIManager.INSTANCE.hasAPI(mod)) {
|
||||
BdLib.logInfo("ifAPI: %s found", mod)
|
||||
processStatementsSafe(thn)
|
||||
} else {
|
||||
BdLib.logInfo("ifAPI: %s not found", mod)
|
||||
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
|
||||
@@ -238,7 +246,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)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,19 +256,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)
|
||||
}
|
||||
|
||||
@@ -269,16 +277,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)
|
||||
}
|
||||
|
||||
@@ -287,43 +295,38 @@ 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 %s -> %s", inStack, outStack)
|
||||
}
|
||||
|
||||
case StIfHaveOD(od, thn, els) =>
|
||||
if (OreDictionary.getOres(od).size() > 0) {
|
||||
log.info("ifOreDict: %s found".format(od))
|
||||
BdLib.logInfo("ifOreDict: %s found".format(od))
|
||||
processDelayedStatementsSafe(thn)
|
||||
} else {
|
||||
log.info("ifOreDict: %s not found".format(od))
|
||||
BdLib.logInfo("ifOreDict: %s not found".format(od))
|
||||
processDelayedStatementsSafe(els)
|
||||
}
|
||||
|
||||
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 main delayed statements list, clear the list afterwards
|
||||
*/
|
||||
def processDelayedStatements() {
|
||||
log.info("Processing %d delayed statements".format(delayedStatements.size))
|
||||
BdLib.logInfo("Processing %d delayed statements", delayedStatements.size)
|
||||
processDelayedStatementsSafe(delayedStatements)
|
||||
delayedStatements = List.empty
|
||||
}
|
||||
@@ -338,10 +341,9 @@ class RecipeLoader {
|
||||
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))
|
||||
e.printStackTrace()
|
||||
BdLib.logErrorException("Error while processing %s", e, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -356,19 +358,18 @@ 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))
|
||||
e.printStackTrace()
|
||||
BdLib.logErrorException("Error while processing %s", e, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,10 @@ package net.bdew.lib.recipes
|
||||
|
||||
import java.io.Reader
|
||||
|
||||
import scala.util.parsing.combinator._
|
||||
import org.apache.commons.lang3.StringEscapeUtils
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
import org.apache.commons.lang3.StringEscapeUtils
|
||||
|
||||
import scala.util.parsing.combinator._
|
||||
|
||||
class RecipeParser extends JavaTokenParsers {
|
||||
// Allows C-style comments
|
||||
@@ -25,6 +26,9 @@ class RecipeParser extends JavaTokenParsers {
|
||||
// Possible metadata suffix (defaults to wildcard value)
|
||||
def maybeMeta = ("@" ~> int).? ^^ (_.getOrElse(OreDictionary.WILDCARD_VALUE))
|
||||
|
||||
// Possible modid prefix (defaults to minecraft)
|
||||
def maybeModid = (str <~ ":").? ^^ (_.getOrElse("minecraft"))
|
||||
|
||||
// Qualified class name
|
||||
def clsPath = (ident <~ ".").* ~ ident
|
||||
|
||||
@@ -46,9 +50,9 @@ class RecipeParser extends JavaTokenParsers {
|
||||
// === Item references ===
|
||||
|
||||
def specOD = "OD" ~> ":" ~> ident ^^ StackOreDict
|
||||
def specMcBlock = "B" ~> ":" ~> ident ~ maybeMeta ^^ { case b ~ m => StackMCBlock(b, m) }
|
||||
def specMcItem = "I" ~> ":" ~> ident ~ maybeMeta ^^ { case b ~ m => StackMCItem(b, m) }
|
||||
def specModStack = str ~ ":" ~ str ^^ { case m ~ c ~ n => StackMod(m, n) }
|
||||
def specBlock = "B" ~> ":" ~> maybeModid ~ str ~ maybeMeta ^^ { case m ~ n ~ i => StackBlock(m, n, i) }
|
||||
def specItem = "I" ~> ":" ~> maybeModid ~ str ~ maybeMeta ^^ { case m ~ n ~ i => StackItem(m, n, i) }
|
||||
def specGenericStack = "S" ~> ":" ~> str ~ ":" ~ str ^^ { case m ~ c ~ n => StackGeneric(m, n) }
|
||||
def specMacro = "$" ~> recipeChar ^^ StackMacro
|
||||
|
||||
def specReflect = clsPath ~ ("[" ~> ident <~ "]") ~ maybeMeta ^^ {
|
||||
@@ -59,7 +63,7 @@ class RecipeParser extends JavaTokenParsers {
|
||||
case (p ~ cl) ~ n ~ m => StackGetter(p.mkString("."), cl, n, m)
|
||||
}
|
||||
|
||||
def spec = specMcBlock | specMcItem | specOD | specModStack | specGetter | specReflect | specMacro
|
||||
def spec = specBlock | specItem | specOD | specGenericStack | specGetter | specReflect | specMacro
|
||||
|
||||
// Spec with possible number of items
|
||||
def specWithCount = spec ~ ("*" ~> int).?
|
||||
@@ -78,6 +82,10 @@ class RecipeParser extends JavaTokenParsers {
|
||||
case mod ~ thn ~ els => new StIfHaveMod(mod, thn, els.getOrElse(List.empty[Statement]))
|
||||
}
|
||||
|
||||
def ifAPI = ("ifAPI" ~> str) ~ ("{" ~> statements <~ "}") ~ ("else" ~> "{" ~> statements <~ "}").? ^^ {
|
||||
case mod ~ thn ~ els => new StIfHaveAPI(mod, thn, els.getOrElse(List.empty[Statement]))
|
||||
}
|
||||
|
||||
def ifOreDict = ("ifOreDict" ~> str) ~ ("{" ~> delayedStatements <~ "}") ~ ("else" ~> "{" ~> delayedStatements <~ "}").? ^^ {
|
||||
case id ~ thn ~ els => new StIfHaveOD(id, thn, els.getOrElse(List.empty[DelayedStatement]))
|
||||
}
|
||||
@@ -115,7 +123,7 @@ class RecipeParser extends JavaTokenParsers {
|
||||
| recipeSmelting
|
||||
)
|
||||
|
||||
def statement: Parser[Statement] = delayedStatement | ifMod | clearRecipes
|
||||
def statement: Parser[Statement] = delayedStatement | ifMod | ifAPI | clearRecipes
|
||||
|
||||
def statements = statement.*
|
||||
def delayedStatements = delayedStatement.*
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
package net.bdew.lib.recipes
|
||||
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.Item
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
object Vanilla {
|
||||
|
||||
|
||||
@@ -60,10 +60,12 @@ case class ConfigSection(pfx: String = "") extends CfgEntry with Iterable[(Strin
|
||||
def getIntList(id: String) = getDoubleList(id).map(_.round.toInt).toList
|
||||
def getFloatList(id: String) = getDoubleList(id).map(_.toFloat).toList
|
||||
|
||||
def getColor(id: String) = getFloatList(id) match {
|
||||
case r :: g :: b :: Nil => Color(r, g, b)
|
||||
case _ => sys.error("Color definition must be 3 numbers")
|
||||
}
|
||||
def getColor(id: String) =
|
||||
raw(id) match {
|
||||
case EntryDouble(c) => Color.fromInt(c.toInt)
|
||||
case EntryNumList(r :: g :: b :: Nil) => Color(r.toFloat, g.toFloat, b.toFloat)
|
||||
case x => sys.error("Invalid color definition: %s".format(x))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,18 +9,19 @@
|
||||
|
||||
package net.bdew.lib.recipes.gencfg
|
||||
|
||||
import net.bdew.lib.recipes.{Statement, RecipeLoader}
|
||||
import net.bdew.lib.BdLib
|
||||
import net.bdew.lib.recipes.{RecipeLoader, Statement}
|
||||
|
||||
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)
|
||||
|
||||
@@ -13,12 +13,17 @@ import net.bdew.lib.recipes.RecipeParser
|
||||
|
||||
trait GenericConfigParser extends RecipeParser {
|
||||
override def statement = statementCfg | super.statement
|
||||
def negativeNumber = "-" ~> decimalNumber ^^ { case x => "-" + x }
|
||||
def signedNumber = decimalNumber | negativeNumber
|
||||
|
||||
// Hex variant must come before decimalNumber, otherwise the parser breaks
|
||||
def signedNumber = (
|
||||
("0x" ~> "[0-9A-Fa-f]+".r) ^^ { case x => Integer.parseInt(x, 16).toDouble }
|
||||
| decimalNumber ^^ { case x => x.toDouble }
|
||||
| ("-" ~> decimalNumber) ^^ { case x => -x.toDouble }
|
||||
)
|
||||
|
||||
def cfgStatementNum = ident ~ "=" ~ signedNumber ^^ { case id ~ eq ~ n => CfgVal(id, EntryDouble(n.toDouble)) }
|
||||
def cfgStatementStr = ident ~ "=" ~ str ^^ { case id ~ eq ~ s => CfgVal(id, EntryStr(s)) }
|
||||
def cfgStatementNumList = ident ~ ("=" ~> "{" ~> signedNumber.* <~ "}") ^^ { case id ~ l => CfgVal(id, EntryNumList(l.map(_.toDouble))) }
|
||||
def cfgStatementNumList = ident ~ ("=" ~> "{" ~> signedNumber.* <~ "}") ^^ { case id ~ l => CfgVal(id, EntryNumList(l)) }
|
||||
def cfgStatementSub = cfgBlock ^^ { case (id, st) => CfgSub(id, st) }
|
||||
|
||||
def cfgStatement = cfgStatementNum | cfgStatementStr | cfgStatementSub | cfgStatementNumList
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.recipes.lootlist
|
||||
|
||||
import net.bdew.lib.recipes.StackRef
|
||||
import net.bdew.lib.recipes.gencfg.CfgEntry
|
||||
|
||||
/**
|
||||
* Allos definition of random-weighted loot/drop lists in config sections
|
||||
* @param list List on (chance percent, stack reference) pairs, resolve to
|
||||
* real ItemStacks with LootListLoader.resolveLootList
|
||||
*/
|
||||
case class EntryLootList(list: List[(Int, StackRef)]) extends CfgEntry
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.recipes.lootlist
|
||||
|
||||
import net.bdew.lib.BdLib
|
||||
import net.bdew.lib.recipes.StackRef
|
||||
import net.bdew.lib.recipes.gencfg.GenericConfigLoader
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
|
||||
/**
|
||||
* Loader mixin for loot lists
|
||||
*/
|
||||
trait LootListLoader extends GenericConfigLoader {
|
||||
def resolveLootList(entry: EntryLootList): List[(Int, ItemStack)] = resolveLootList(entry.list)
|
||||
def resolveLootList(list: List[(Int, StackRef)]) =
|
||||
(for ((chance, ref) <- list) yield {
|
||||
try {
|
||||
val itemStack = getConcreteStack(ref)
|
||||
if (itemStack == null) {
|
||||
BdLib.logWarn("Unable to resolve %s: null returned", ref)
|
||||
None
|
||||
} else {
|
||||
if (itemStack.getItemDamage == OreDictionary.WILDCARD_VALUE) {
|
||||
BdLib.logInfo("meta/damage is unset in %s, defaulting to 0", ref)
|
||||
itemStack.setItemDamage(0)
|
||||
}
|
||||
Some((chance, itemStack))
|
||||
}
|
||||
} catch {
|
||||
case e: Throwable =>
|
||||
BdLib.logWarn("Unable to resolve %s: %s", ref, e.getMessage)
|
||||
None
|
||||
}
|
||||
}).flatten
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.recipes.lootlist
|
||||
|
||||
import net.bdew.lib.recipes.gencfg.{CfgVal, GenericConfigParser}
|
||||
|
||||
/**
|
||||
* Parser mixin for loot lists
|
||||
* ident: DropsList(
|
||||
* {chance}% {stackRef}
|
||||
* ...
|
||||
* )
|
||||
*/
|
||||
trait LootListParser extends GenericConfigParser {
|
||||
def dropsEntry = (wholeNumber <~ "%") ~ spec ^^ { case n ~ s => (n.toInt, s) }
|
||||
def cfgDrops = ident ~ (":" ~> "DropsList" ~> "(" ~> dropsEntry.* <~ ")") ^^ { case id ~ a => CfgVal(id, EntryLootList(a)) }
|
||||
override def cfgStatement = cfgDrops | super.cfgStatement
|
||||
}
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
package net.bdew.lib.render
|
||||
|
||||
import net.minecraft.client.renderer.texture.IconRegister
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import net.minecraftforge.event.ForgeSubscribe
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import net.bdew.lib.gui.{IconWrapper, Texture}
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import net.minecraftforge.client.event.TextureStitchEvent
|
||||
import net.bdew.lib.gui.{Texture, IconWrapper}
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
|
||||
/**
|
||||
* Allows loading of texture that don't belong to specific block or item into vanilla block/item atlas
|
||||
@@ -33,18 +33,18 @@ class IconPreloader(kind: Int) {
|
||||
icons += this
|
||||
}
|
||||
|
||||
import language.implicitConversions
|
||||
import scala.language.implicitConversions
|
||||
|
||||
implicit def entry2icon(v: TextureLoc) = v.texture.icon
|
||||
implicit def entry2texture(v: TextureLoc) = v.texture
|
||||
|
||||
def registerIcons(reg: IconRegister) {}
|
||||
def registerIcons(reg: IIconRegister) {}
|
||||
|
||||
def init() {
|
||||
MinecraftForge.EVENT_BUS.register(this)
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
@SubscribeEvent
|
||||
def preTextureStitch(ev: TextureStitchEvent.Pre) {
|
||||
if (ev.map.getTextureType == kind) {
|
||||
for (x <- icons) x.texture = Texture(sheet, ev.map.registerIcon(x.loc))
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.render.connected
|
||||
|
||||
import net.bdew.lib.gui.Color
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
case class FaceOverlay(icon: IIcon, color: Color) {
|
||||
def this(icon: IIcon, color: (Float, Float, Float)) = this(icon, new Color(color._1, color._2, color._3))
|
||||
}
|
||||
|
||||
trait BlockAdditionalRender {
|
||||
def getFaceOverlays(world: IBlockAccess, x: Int, y: Int, z: Int, face: ForgeDirection): List[FaceOverlay]
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.render.connected
|
||||
|
||||
import net.bdew.lib.block.BlockRef
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
object ConnectedHelper {
|
||||
val edgeWidth = 1 / 16F
|
||||
|
||||
// Represents the rectangles of all edges/corners on a 2d pane
|
||||
// 701
|
||||
// 6 2
|
||||
// 543
|
||||
// 8 is a special case for the full face
|
||||
val faceEdges = Array(
|
||||
RectF(0, 1 - edgeWidth, 1, 1),
|
||||
RectF(1 - edgeWidth, 1 - edgeWidth, 1, 1),
|
||||
RectF(1 - edgeWidth, 0, 1, 1),
|
||||
RectF(1 - edgeWidth, 0, 1, edgeWidth),
|
||||
RectF(0, 0, 1, edgeWidth),
|
||||
RectF(0, 0, edgeWidth, edgeWidth),
|
||||
RectF(0, 0, edgeWidth, 1),
|
||||
RectF(0, 1 - edgeWidth, edgeWidth, 1),
|
||||
RectF(0, 0, 1, 1)
|
||||
)
|
||||
|
||||
val faceAdjanced = (for (x <- ForgeDirection.VALID_DIRECTIONS) yield x -> new FaceAdjanced(x)).toMap
|
||||
|
||||
// Maps edge number + face to 3d vertices
|
||||
val draw =
|
||||
(for ((rect, n) <- faceEdges.zipWithIndex; face <- ForgeDirection.VALID_DIRECTIONS)
|
||||
yield (face, n) -> new EdgeDraw(rect, face)).toMap
|
||||
|
||||
val brightnessMultiplier = Map(
|
||||
ForgeDirection.UP -> 1F,
|
||||
ForgeDirection.DOWN -> 0.5F,
|
||||
ForgeDirection.NORTH -> 0.8F,
|
||||
ForgeDirection.SOUTH -> 0.8F,
|
||||
ForgeDirection.WEST -> 0.6F,
|
||||
ForgeDirection.EAST -> 0.6F
|
||||
)
|
||||
|
||||
case class Vec3F(x: Float, y: Float, z: Float) {
|
||||
def *(m: Float) = Vec3F(x * m, y * m, z * m)
|
||||
def +(m: Vec3F) = Vec3F(x + m.x, y + m.y, z + m.z)
|
||||
def -(m: Vec3F) = Vec3F(x - m.x, y - m.y, z - m.z)
|
||||
def +(d: ForgeDirection) = Vec3F(x + d.offsetX, y + d.offsetY, z + d.offsetZ)
|
||||
def toInts = (x.toInt, y.toInt, z.toInt)
|
||||
def asBlockRef = BlockRef(x.toInt, y.toInt, z.toInt)
|
||||
}
|
||||
|
||||
case class RectF(x1: Float, y1: Float, x2: Float, y2: Float) {
|
||||
def corners = Seq(Vec2F(x1, y1), Vec2F(x2, y1), Vec2F(x2, y2), Vec2F(x1, y2))
|
||||
}
|
||||
|
||||
case class Vec2F(u: Float, v: Float)
|
||||
|
||||
case class VecPair(pos: Vec3F, tex: Vec2F)
|
||||
|
||||
class EdgeDraw(rect: RectF, face: ForgeDirection) {
|
||||
val vertices = rect.corners map { d =>
|
||||
val v = face match {
|
||||
case ForgeDirection.UP => Vec3F(d.u, 1, 1 - d.v)
|
||||
case ForgeDirection.DOWN => Vec3F(d.u, 0, d.v)
|
||||
case ForgeDirection.NORTH => Vec3F(1 - d.u, d.v, 0)
|
||||
case ForgeDirection.SOUTH => Vec3F(d.u, d.v, 1)
|
||||
case ForgeDirection.EAST => Vec3F(1, d.v, 1 - d.u)
|
||||
case ForgeDirection.WEST => Vec3F(0, d.v, d.u)
|
||||
case _ => sys.error("Invalid face")
|
||||
}
|
||||
VecPair(extend(v, 0.001F), d)
|
||||
}
|
||||
|
||||
def doDraw(pos: Vec3F, icon: IIcon) {
|
||||
for (v <- vertices)
|
||||
addVertextWithUV(v.pos + pos, mapToIcon(v.tex, icon))
|
||||
}
|
||||
}
|
||||
|
||||
def extend(v: Vec3F, o: Float) = Vec3F(
|
||||
if (v.x == 0F) -o else if (v.x == 1F) 1 + o else v.x,
|
||||
if (v.y == 0F) -o else if (v.y == 1F) 1 + o else v.y,
|
||||
if (v.z == 0F) -o else if (v.z == 1F) 1 + o else v.z
|
||||
)
|
||||
|
||||
def mapToIcon(v: Vec2F, i: IIcon) = Vec2F(i.getInterpolatedU(v.u * 16), i.getInterpolatedV((1 - v.v) * 16))
|
||||
|
||||
def addVertextWithUV(p: Vec3F, t: Vec2F) =
|
||||
Tessellator.instance.addVertexWithUV(p.x, p.y, p.z, t.u, t.v)
|
||||
|
||||
class FaceAdjanced(d: ForgeDirection) {
|
||||
val top = d match {
|
||||
case ForgeDirection.UP => ForgeDirection.NORTH
|
||||
case ForgeDirection.DOWN => ForgeDirection.SOUTH
|
||||
case _ => ForgeDirection.UP
|
||||
}
|
||||
|
||||
val right = d match {
|
||||
case ForgeDirection.UP => ForgeDirection.EAST
|
||||
case ForgeDirection.DOWN => ForgeDirection.EAST
|
||||
case ForgeDirection.NORTH => ForgeDirection.WEST
|
||||
case ForgeDirection.WEST => ForgeDirection.SOUTH
|
||||
case ForgeDirection.SOUTH => ForgeDirection.EAST
|
||||
case ForgeDirection.EAST => ForgeDirection.NORTH
|
||||
case _ => ForgeDirection.UNKNOWN
|
||||
}
|
||||
val bottom = top.getOpposite
|
||||
val left = right.getOpposite
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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.render.connected
|
||||
|
||||
import cpw.mods.fml.client.registry.{ISimpleBlockRenderingHandler, RenderingRegistry}
|
||||
import net.bdew.lib.block.BlockRef
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.client.renderer.{RenderBlocks, Tessellator}
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
object ConnectedRenderer extends ISimpleBlockRenderingHandler {
|
||||
val id = RenderingRegistry.getNextAvailableRenderId
|
||||
RenderingRegistry.registerBlockHandler(this)
|
||||
|
||||
def doRenderItemSide(d: ForgeDirection, r: RenderBlocks, block: Block, meta: Int) = {
|
||||
val icon = r.getBlockIconFromSideAndMetadata(block, d.ordinal(), meta)
|
||||
Tessellator.instance.setNormal(d.offsetX, d.offsetY, d.offsetZ)
|
||||
d match {
|
||||
case ForgeDirection.DOWN => r.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.UP => r.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.NORTH => r.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.SOUTH => r.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.WEST => r.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.EAST => r.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case _ => sys.error("Invalid side")
|
||||
}
|
||||
}
|
||||
|
||||
override def renderInventoryBlock(block: Block, metadata: Int, modelID: Int, renderer: RenderBlocks) {
|
||||
val tessellator = Tessellator.instance
|
||||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F)
|
||||
|
||||
val edge = block.asInstanceOf[ConnectedTextureBlock].edgeIcon
|
||||
|
||||
for (side <- ForgeDirection.VALID_DIRECTIONS) {
|
||||
tessellator.startDrawingQuads()
|
||||
doRenderItemSide(side, renderer, block, metadata)
|
||||
val m = ConnectedHelper.brightnessMultiplier(side)
|
||||
ConnectedHelper.draw(side, 8).doDraw(ConnectedHelper.Vec3F(0, 0, 0), edge)
|
||||
tessellator.draw()
|
||||
}
|
||||
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F)
|
||||
}
|
||||
|
||||
override def renderWorldBlock(world: IBlockAccess, x: Int, y: Int, z: Int, block: Block, modelId: Int, renderer: RenderBlocks): Boolean = {
|
||||
renderer.renderStandardBlock(block, x, y, z)
|
||||
|
||||
val pos = ConnectedHelper.Vec3F(x, y, z)
|
||||
for (face <- ForgeDirection.VALID_DIRECTIONS)
|
||||
if (block.shouldSideBeRendered(world, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal()))
|
||||
drawFaceEdges(world, pos, face, block.asInstanceOf[ConnectedTextureBlock])
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
def drawFaceEdges(world: IBlockAccess, pos: ConnectedHelper.Vec3F, face: ForgeDirection, block: ConnectedTextureBlock) {
|
||||
val edge = block.edgeIcon
|
||||
val canConnect = block.canConnect(world, pos.asBlockRef, _: BlockRef)
|
||||
val sides = ConnectedHelper.faceAdjanced(face)
|
||||
|
||||
val m = ConnectedHelper.brightnessMultiplier(face)
|
||||
Tessellator.instance.setColorOpaque_F(m, m, m)
|
||||
|
||||
val fo = pos + face
|
||||
val b = block.getMixedBrightnessForBlock(world, fo.x.toInt, fo.y.toInt, fo.z.toInt)
|
||||
Tessellator.instance.setBrightness(b)
|
||||
|
||||
val U = !canConnect((pos + sides.top).asBlockRef)
|
||||
val D = !canConnect((pos + sides.bottom).asBlockRef)
|
||||
val L = !canConnect((pos + sides.left).asBlockRef)
|
||||
val R = !canConnect((pos + sides.right).asBlockRef)
|
||||
|
||||
if (!U && !R && !canConnect((pos + sides.top + sides.right).asBlockRef))
|
||||
ConnectedHelper.draw(face, 1).doDraw(pos, edge)
|
||||
|
||||
if (!U && !L && !canConnect((pos + sides.top + sides.left).asBlockRef))
|
||||
ConnectedHelper.draw(face, 7).doDraw(pos, edge)
|
||||
|
||||
if (!D && !R && !canConnect((pos + sides.bottom + sides.right).asBlockRef))
|
||||
ConnectedHelper.draw(face, 3).doDraw(pos, edge)
|
||||
|
||||
if (!D && !L && !canConnect((pos + sides.bottom + sides.left).asBlockRef))
|
||||
ConnectedHelper.draw(face, 5).doDraw(pos, edge)
|
||||
|
||||
if (U) ConnectedHelper.draw(face, 0).doDraw(pos, edge)
|
||||
if (D) ConnectedHelper.draw(face, 4).doDraw(pos, edge)
|
||||
if (R) ConnectedHelper.draw(face, 2).doDraw(pos, edge)
|
||||
if (L) ConnectedHelper.draw(face, 6).doDraw(pos, edge)
|
||||
|
||||
if (block.isInstanceOf[BlockAdditionalRender]) {
|
||||
val overlays = block.asInstanceOf[BlockAdditionalRender].getFaceOverlays(world, pos.x.toInt, pos.y.toInt, pos.z.toInt, face)
|
||||
for (overlay <- overlays) {
|
||||
Tessellator.instance.setColorOpaque_F(overlay.color.r, overlay.color.g, overlay.color.b)
|
||||
ConnectedHelper.draw(face, 8).doDraw(pos, overlay.icon)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def shouldRender3DInInventory(modelId: Int) = true
|
||||
override def getRenderId = id
|
||||
}
|
||||
|
||||
|
||||
@@ -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.render.connected
|
||||
|
||||
import net.bdew.lib.block.BlockRef
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.world.IBlockAccess
|
||||
|
||||
trait ConnectedTextureBlock extends Block {
|
||||
def edgeIcon: IIcon
|
||||
def canConnect(world: IBlockAccess, origin: BlockRef, target: BlockRef): Boolean
|
||||
|
||||
override def getRenderType = ConnectedRenderer.id
|
||||
}
|
||||
@@ -9,17 +9,15 @@
|
||||
|
||||
package net.bdew.lib.rotate
|
||||
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import java.util.EnumSet
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, 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.world.IBlockAccess
|
||||
import net.minecraft.world.World
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import java.util.EnumSet
|
||||
import net.minecraft.util.{IIcon, MathHelper}
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
/**
|
||||
* Basic logic for block rotatation
|
||||
@@ -29,12 +27,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 +61,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")
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.rotate
|
||||
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots}
|
||||
import net.bdew.lib.data.DataSlotDirection
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
|
||||
|
||||
trait RotateableTile extends TileDataSlots {
|
||||
var rotation = DataSlotDirection("rotation", this).setUpdate(UpdateKind.SAVE, UpdateKind.WORLD)
|
||||
|
||||
@@ -9,24 +9,23 @@
|
||||
|
||||
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.minecraft.block.ITileEntityProvider
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
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
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
package net.bdew.lib.tile
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import net.minecraftforge.fluids._
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
|
||||
trait ExposeTank extends TileEntity with IFluidHandler {
|
||||
def getTankFromDirection(dir: ForgeDirection): IFluidTank
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
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.bdew.lib.Event
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity
|
||||
import net.minecraft.network.{NetworkManager, Packet}
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
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() {
|
||||
|
||||
@@ -9,42 +9,42 @@
|
||||
|
||||
package net.bdew.lib.tile.inventory
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
|
||||
trait BaseInventory extends IInventory {
|
||||
var inv: Array[ItemStack] = new Array(getSizeInventory)
|
||||
|
||||
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
|
||||
onInventoryChanged()
|
||||
markDirty()
|
||||
return item
|
||||
} else {
|
||||
var newstack = item.splitStack(n)
|
||||
val 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)
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,15 @@
|
||||
|
||||
package net.bdew.lib.tile.inventory
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.bdew.lib.items.ItemUtils
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
|
||||
package net.bdew.lib.tile.inventory
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.{NBTTagList, NBTTagCompound}
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||
|
||||
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