mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-24 05:54:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9819600b15 | ||
|
|
12a1327e53 | ||
|
|
c495fb8b33 | ||
|
|
0b94b006ec | ||
|
|
c4dbda8a20 | ||
|
|
2698d93444 | ||
|
|
b4cc77d3cc | ||
|
|
2c94505c97 | ||
|
|
2c3607e113 | ||
|
|
b34192d8c2 | ||
|
|
0212f20f69 | ||
|
|
3b31e285d2 | ||
|
|
041f570109 | ||
|
|
745cf43928 | ||
|
|
914815fee7 | ||
|
|
bed3149880 | ||
|
|
302429f340 | ||
|
|
b6fe2dc14d | ||
|
|
377fe3c27a |
No files matched your search
+4
-25
@@ -1,10 +1,6 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "bdew"
|
||||
url = "http://jenkins.bdew.net/maven"
|
||||
}
|
||||
maven {
|
||||
name = "forge"
|
||||
url = "http://files.minecraftforge.net/maven"
|
||||
@@ -18,7 +14,7 @@ buildscript {
|
||||
apply plugin: 'forge'
|
||||
apply plugin: 'scala'
|
||||
|
||||
version = "0.9.1"
|
||||
version = "1.1.0"
|
||||
|
||||
if (project.hasProperty('buildnum')) {
|
||||
project.version = project.version + '.' + project.buildnum
|
||||
@@ -32,11 +28,11 @@ ext.versuffix = "mc164"
|
||||
|
||||
minecraft {
|
||||
version = "1.6.4-9.11.1.964"
|
||||
replace("BDLIB_VER", project.version)
|
||||
}
|
||||
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
def myTokens = [BdLibVer: project.version]
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
@@ -47,30 +43,13 @@ sourceSets {
|
||||
srcDir 'resources'
|
||||
}
|
||||
}
|
||||
processed {
|
||||
scala {
|
||||
srcDir 'build/stage'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task stage(type: Sync) {
|
||||
inputs.property "tokens", myTokens
|
||||
from sourceSets.main.scala
|
||||
into 'build/stage'
|
||||
filter(ReplaceTokens, tokens: myTokens)
|
||||
}
|
||||
|
||||
compileScala {
|
||||
source = sourceSets.processed.scala
|
||||
dependsOn stage
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "tokens", myTokens
|
||||
inputs.property "tokens", minecraft.replacements
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'mcmod.info'
|
||||
filter(ReplaceTokens, tokens: myTokens)
|
||||
filter(ReplaceTokens, tokens: minecraft.replacements)
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"modid": "bdlib",
|
||||
"name": "BD Lib",
|
||||
"description": "",
|
||||
"version": "@BdLibVer@",
|
||||
"version": "@BDLIB_VER@",
|
||||
"url": "bdew.net/mods/",
|
||||
"updateUrl": "",
|
||||
"authorList": [
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
/*
|
||||
* 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 cpw.mods.fml.common.Mod
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent
|
||||
|
||||
@Mod(modid = "bdlib", version = "@BdLibVer@", modLanguage = "scala")
|
||||
@Mod(modid = "bdlib", name = "BD lib", version = "BDLIB_VER", modLanguage = "scala")
|
||||
object BdLib {
|
||||
def preInit(ev: FMLPreInitializationEvent) {
|
||||
ev.getModLog.info("bdlib @BdLibVer@ loaded")
|
||||
ev.getModLog.info("bdlib BDLIB_VER loaded")
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -21,6 +21,8 @@ object Misc {
|
||||
def iterNbtList[X](list: NBTTagList) =
|
||||
for (i <- 0 until list.tagCount()) yield list.tagAt(i).asInstanceOf[X]
|
||||
|
||||
def getActiveModId = Loader.instance().activeModContainer().getModId
|
||||
|
||||
def toLocal(s: String) = StatCollector.translateToLocal(s)
|
||||
def toLocalF(s: String, params: Any*) = StatCollector.translateToLocal(s).format(params: _*)
|
||||
|
||||
@@ -44,7 +46,7 @@ object Misc {
|
||||
def min[T](vals: T*)(implicit o: Ordering[T]): T = vals.min(o)
|
||||
def max[T](vals: T*)(implicit o: Ordering[T]): T = vals.max(o)
|
||||
|
||||
def clamp[T](value: T, min: T, max: T)(implicit o: Ordering[T]): T = if (o.gt(value,max)) max else if (o.lt(value,min)) min else value
|
||||
def clamp[T](value: T, min: T, max: T)(implicit o: Ordering[T]): T = if (o.gt(value, max)) max else if (o.lt(value, min)) min else value
|
||||
|
||||
def iterSome[T](list: Seq[T], indexes: Iterable[Int]): Iterable[T] = for (i <- indexes) yield list(i)
|
||||
def iterSomeEnum[T](list: Seq[T], indexes: Iterable[Int]): Iterable[(Int, T)] = for (i <- indexes) yield i -> list(i)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.item.ItemStack
|
||||
import net.minecraft.block.Block
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.block.HasTE
|
||||
|
||||
class BlockManager(val ids: IdManager) {
|
||||
|
||||
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 = {
|
||||
GameRegistry.registerBlock(block, name)
|
||||
|
||||
if (addStack)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
|
||||
|
||||
if (block.isInstanceOf[HasTE[_]])
|
||||
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass, name)
|
||||
|
||||
return block
|
||||
}
|
||||
|
||||
def load() {}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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.minecraftforge.fluids.{FluidRegistry, Fluid}
|
||||
|
||||
class FluidManager(val ids: IdManager) {
|
||||
def regFluid[T <: Fluid](fluid: T): T = {
|
||||
FluidRegistry.registerFluid(fluid)
|
||||
return fluid
|
||||
}
|
||||
def load() {}
|
||||
}
|
||||
@@ -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.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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.item.{ItemStack, Item}
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.items.SimpleItem
|
||||
|
||||
class ItemManager(val ids: IdManager) {
|
||||
def regSimpleItem(name: String): SimpleItem = regItem(new SimpleItem(ids.getItemId(name), name), name)
|
||||
|
||||
def regItem[T <: SimpleItem](item: T): T = regItem[T](item, item.name)
|
||||
|
||||
def regItemCls[T <: Item](itemCls: Class[T], name: String, addStack: Boolean = true): T = {
|
||||
val item = itemCls.getConstructor(classOf[Int]).newInstance(ids.getItemId(name): Integer)
|
||||
regItem[T](item, name, addStack)
|
||||
}
|
||||
|
||||
def regItem[T <: Item](item: T, name: String, addStack: Boolean = true): T = {
|
||||
GameRegistry.registerItem(item, name)
|
||||
if (addStack)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(item))
|
||||
return item
|
||||
}
|
||||
def load() {}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.bdew.lib.recipes.gencfg.ConfigSection
|
||||
import net.bdew.lib.machine.Machine
|
||||
import net.bdew.lib.gui.{GuiProvider, GuiHandler}
|
||||
|
||||
class MachineManager(ids: IdManager, val tuning: ConfigSection, guiHandler: GuiHandler) {
|
||||
def registerMachine[R <: Machine[_]](machine: R): R = {
|
||||
machine.tuning = tuning.getSection(machine.name)
|
||||
if (machine.tuning.getBoolean("Enabled")) {
|
||||
machine.enabled = true
|
||||
machine.regBlock(ids)
|
||||
if (machine.isInstanceOf[GuiProvider])
|
||||
guiHandler.register(machine.asInstanceOf[GuiProvider])
|
||||
}
|
||||
return machine
|
||||
}
|
||||
def load() {}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -15,7 +15,6 @@ import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlot}
|
||||
|
||||
abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank with DataSlot {
|
||||
var oldStack: FluidStack = null
|
||||
var size: Int
|
||||
|
||||
parent.serverTick.listen(checkUpdate)
|
||||
|
||||
@@ -38,19 +37,20 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
|
||||
val tag = new NBTTagCompound()
|
||||
writeToNBT(tag)
|
||||
if (k == UpdateKind.GUI)
|
||||
tag.setInteger("size", size)
|
||||
tag.setInteger("size", getCapacity)
|
||||
t.setCompoundTag(name, tag)
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, k: UpdateKind.Value) {
|
||||
setFluid(null)
|
||||
val tag = t.getCompoundTag(name)
|
||||
readFromNBT(tag)
|
||||
if (k == UpdateKind.GUI)
|
||||
size = tag.getInteger("size")
|
||||
setCapacity(tag.getInteger("size"))
|
||||
}
|
||||
}
|
||||
|
||||
case class DataSlotTank(name: String, parent: TileDataSlots, var size: Int) extends DataSlotTankBase(size)
|
||||
case class DataSlotTank(name: String, parent: TileDataSlots, size: Int) extends DataSlotTankBase(size)
|
||||
|
||||
case class DataSlotTankRestricted(name: String, parent: TileDataSlots, var size: Int, fluidID: Int) extends DataSlotTankBase(size) {
|
||||
def fill(amount: Int, doFill: Boolean) = super.fill(new FluidStack(fluidID, amount), doFill)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -10,10 +10,10 @@
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.bdew.lib.gui.BaseContainer
|
||||
import net.bdew.lib.gui.NoInvContainer
|
||||
import net.minecraft.inventory.ICrafting
|
||||
|
||||
trait ContainerDataSlots extends BaseContainer {
|
||||
trait ContainerDataSlots extends NoInvContainer {
|
||||
val dataSource: TileDataSlots
|
||||
var lastSentChange = dataSource.lastChange
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -31,6 +31,8 @@ trait TileDataSlots extends TileExtended {
|
||||
for ((n, s) <- dataSlots if s.updateKind.contains(kind)) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -13,4 +13,5 @@ object UpdateKind extends Enumeration {
|
||||
val WORLD = Value("WORLD")
|
||||
val GUI = Value("GUI")
|
||||
val SAVE = Value("SAVE")
|
||||
val RENDER = Value("RENDER")
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -9,26 +9,12 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.inventory.{IInventory, Slot, Container}
|
||||
import net.minecraft.entity.player.{EntityPlayerMP, EntityPlayer, InventoryPlayer}
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.bdew.lib.items.ItemUtils
|
||||
import net.bdew.lib.Misc
|
||||
|
||||
abstract class BaseContainer(te: IInventory) extends Container {
|
||||
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
def players = Misc.filterType(crafters, classOf[EntityPlayerMP])
|
||||
|
||||
protected def bindPlayerInventory(inv: InventoryPlayer, xOffs: Int, yOffsInv: Int, yOffsHotbar: Int) {
|
||||
for (i <- 0 until 3; j <- 0 until 9)
|
||||
addSlotToContainer(new Slot(inv, j + i * 9 + 9, xOffs + j * 18, yOffsInv + i * 18))
|
||||
|
||||
for (i <- 0 until 9)
|
||||
addSlotToContainer(new Slot(inv, i, xOffs + i * 18, yOffsHotbar))
|
||||
}
|
||||
|
||||
abstract class BaseContainer(te: IInventory) extends NoInvContainer {
|
||||
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = {
|
||||
var stack = getSlot(slot).getStack
|
||||
if (getSlot(slot).inventory == player.inventory) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -12,8 +12,6 @@ package net.bdew.lib.gui
|
||||
import net.minecraft.client.gui.inventory.GuiContainer
|
||||
import net.minecraft.inventory.Container
|
||||
import scala.collection.mutable
|
||||
import net.minecraft.client.gui.GuiButton
|
||||
import net.bdew.lib.gui.widgets.Widget
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
@@ -21,7 +19,8 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
|
||||
xSize = xSz
|
||||
ySize = ySz
|
||||
|
||||
val widgets = mutable.MutableList.empty[Widget]
|
||||
val widgets = new WidgetContainerWindow(this, xSz, ySz)
|
||||
|
||||
val texture: ResourceLocation
|
||||
|
||||
def rect = new Rect(guiLeft, guiTop, xSize, ySize)
|
||||
@@ -34,44 +33,24 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
|
||||
buttonList.clear()
|
||||
}
|
||||
|
||||
def addButton[T <: GuiButton](w: T): T = {
|
||||
buttonList.asInstanceOf[java.util.ArrayList[GuiButton]].add(w)
|
||||
return w
|
||||
}
|
||||
|
||||
def addWidget[T <: Widget](w: T): T = {
|
||||
widgets += w
|
||||
w.parent = this
|
||||
return w
|
||||
}
|
||||
|
||||
protected override def keyTyped(c: Char, i: Int) {
|
||||
for (w <- widgets)
|
||||
if (w.keyTyped(c, i))
|
||||
return
|
||||
super.keyTyped(c, i)
|
||||
}
|
||||
|
||||
protected override def mouseClicked(x: Int, y: Int, bt: Int) {
|
||||
super.mouseClicked(x, y, bt)
|
||||
val p = new Point(x, y) - rect.origin
|
||||
for (w <- widgets if w.rect.contains(p))
|
||||
w.mouseClicked(p - w.rect.origin, bt)
|
||||
widgets.mouseClicked(Point(x, y) - rect.origin, bt)
|
||||
}
|
||||
|
||||
protected override def drawGuiContainerForegroundLayer(x: Int, y: Int) {
|
||||
for (w <- widgets)
|
||||
w.draw()
|
||||
}
|
||||
protected override def keyTyped(c: Char, i: Int) =
|
||||
if (!widgets.keyTyped(c, i))
|
||||
super.keyTyped(c, i)
|
||||
|
||||
protected override def drawGuiContainerForegroundLayer(x: Int, y: Int) =
|
||||
widgets.draw(Point(x, y) - rect.origin)
|
||||
|
||||
protected override def drawScreen(x: Int, y: Int, f: Float) {
|
||||
super.drawScreen(x, y, f)
|
||||
|
||||
val tip = mutable.MutableList.empty[String]
|
||||
|
||||
val p = new Point(x, y) - rect.origin
|
||||
for (w <- widgets if w.rect.contains(p))
|
||||
w.handleTooltip(p - w.rect.origin, tip)
|
||||
widgets.handleTooltip(Point(x, y) - rect.origin, tip)
|
||||
|
||||
import collection.JavaConversions._
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -12,7 +12,7 @@ package net.bdew.lib.gui
|
||||
object Direction extends Enumeration {
|
||||
type Direction = Value
|
||||
val UP = Value("UP")
|
||||
val DOWN = Value("UP")
|
||||
val LEFT = Value("UP")
|
||||
val RIGHT = Value("UP")
|
||||
val DOWN = Value("DOWN")
|
||||
val LEFT = Value("LEFT")
|
||||
val RIGHT = Value("RIGHT")
|
||||
}
|
||||
@@ -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.gui
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler
|
||||
import scala.collection.mutable
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.world.World
|
||||
|
||||
class GuiHandler extends IGuiHandler {
|
||||
val guis = mutable.Map.empty[Int, GuiProvider]
|
||||
|
||||
def register(p: GuiProvider) = {
|
||||
if (guis.isDefinedAt(p.guiId))
|
||||
sys.error("GUI ID Collision - %d was registered for %s and attemted to register by %s".format(p.guiId, guis(p.guiId), p))
|
||||
guis += (p.guiId -> p)
|
||||
}
|
||||
|
||||
def getServerGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
|
||||
guis(ID).getContainer(world.getBlockTileEntity(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)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.gui
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
|
||||
trait GuiProvider {
|
||||
def guiId: Int
|
||||
|
||||
type TEClass
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def getGui(te: TEClass, player: EntityPlayer): AnyRef
|
||||
def getContainer(te: TEClass, player: EntityPlayer): AnyRef
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def getGui(te: TileEntity, player: EntityPlayer): AnyRef = getGui(te.asInstanceOf[TEClass], player)
|
||||
def getContainer(te: TileEntity, player: EntityPlayer): AnyRef = getContainer(te.asInstanceOf[TEClass], player)
|
||||
}
|
||||
@@ -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.gui
|
||||
|
||||
import net.minecraft.inventory.{Slot, Container}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.entity.player.{EntityPlayer, InventoryPlayer, EntityPlayerMP}
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
abstract class NoInvContainer extends Container {
|
||||
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
def players = Misc.filterType(crafters, classOf[EntityPlayerMP])
|
||||
|
||||
protected def bindPlayerInventory(inv: InventoryPlayer, xOffs: Int, yOffsInv: Int, yOffsHotbar: Int) {
|
||||
for (i <- 0 until 3; j <- 0 until 9)
|
||||
addSlotToContainer(new Slot(inv, j + i * 9 + 9, xOffs + j * 18, yOffsInv + i * 18))
|
||||
|
||||
for (i <- 0 until 9)
|
||||
addSlotToContainer(new Slot(inv, i, xOffs + i * 18, yOffsHotbar))
|
||||
}
|
||||
|
||||
override def slotClick(slotnum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
|
||||
if (inventorySlots.isDefinedAt(slotnum)) {
|
||||
val slot = getSlot(slotnum)
|
||||
if (slot != null && slot.isInstanceOf[SlotClickable])
|
||||
return slot.asInstanceOf[SlotClickable].onClick(button, modifiers, player)
|
||||
}
|
||||
return super.slotClick(slotnum, button, modifiers, player)
|
||||
}
|
||||
|
||||
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = null
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -9,8 +9,17 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
class Point(val x: Int, val y: Int) {
|
||||
case class Point(x: Int, y: Int) {
|
||||
def this(p: Point) = this(p.x, p.y)
|
||||
def +(that: Point) = new Point(this.x + that.x, this.y + that.y)
|
||||
def -(that: Point) = new Point(this.x - that.x, this.y - that.y)
|
||||
}
|
||||
|
||||
object Point {
|
||||
|
||||
import language.implicitConversions
|
||||
|
||||
implicit def awt2point(p: java.awt.Point): Point = new Point(p.x, p.y)
|
||||
implicit def point2awt(p: Point): java.awt.Point = new java.awt.Point(p.x, p.y)
|
||||
implicit def tuple2point(p: (Int, Int)): Point = new Point(p._1, p._2)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -9,8 +9,10 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
class Rect(val x: Int, val y: Int, val w: Int, val h: Int) {
|
||||
case class Rect(x: Int, y: Int, w: Int, h: Int) {
|
||||
def this(p: Point, w: Int, h: Int) = this(p.x, p.y, w, h)
|
||||
def contains(p: Point) = p.x >= x && p.y >= y && p.x <= x + w && p.y <= y + h
|
||||
def origin = new Point(x, y)
|
||||
def +(p: Point) = new Rect(origin + p, w, h)
|
||||
def -(p: Point) = new Rect(origin - p, w, h)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.gui
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
|
||||
trait SlotClickable extends Slot {
|
||||
def onClick(button: Int, mods: Int, player: EntityPlayer): ItemStack
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.gui
|
||||
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.gui.widgets.BaseWidget
|
||||
import net.minecraft.util.Icon
|
||||
import net.minecraft.client.gui.FontRenderer
|
||||
import net.minecraft.client.Minecraft
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
trait WidgetContainer {
|
||||
val rect: Rect
|
||||
val widgets = mutable.MutableList.empty[BaseWidget]
|
||||
|
||||
def getFontRenderer: FontRenderer
|
||||
|
||||
def clear() = widgets.clear()
|
||||
|
||||
def add[T <: BaseWidget](w: T): T = {
|
||||
widgets += w
|
||||
w.init(this)
|
||||
return w
|
||||
}
|
||||
|
||||
def mouseClicked(p: Point, bt: Int) {
|
||||
for (w <- widgets)
|
||||
if (w.rect.contains(p))
|
||||
w.mouseClicked(p - w.rect.origin, bt)
|
||||
else
|
||||
w.looseFocus()
|
||||
}
|
||||
|
||||
def keyTyped(c: Char, i: Int): Boolean = {
|
||||
for (w <- widgets)
|
||||
if (w.keyTyped(c, i))
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
def draw(mouse: Point) {
|
||||
val p = mouse - rect.origin
|
||||
for (w <- widgets) {
|
||||
GL11.glPushMatrix()
|
||||
GL11.glTranslatef(rect.origin.x, rect.origin.y, 0)
|
||||
w.draw(p)
|
||||
GL11.glPopMatrix()
|
||||
}
|
||||
}
|
||||
|
||||
def handleTooltip(op: Point, tip: mutable.MutableList[String]) {
|
||||
val p = op
|
||||
for (w <- widgets if w.rect.contains(p))
|
||||
w.handleTooltip(p - w.rect.origin, tip)
|
||||
}
|
||||
|
||||
def drawTexture(r: Rect, t: TextureLocation) {
|
||||
Minecraft.getMinecraft.renderEngine.bindTexture(t.resource)
|
||||
drawTexture(r, t.p)
|
||||
}
|
||||
|
||||
def looseFocus() =
|
||||
for (w <- widgets)
|
||||
w.looseFocus()
|
||||
|
||||
def getOffsetFromWindow: Point
|
||||
|
||||
def drawTexture(r: Rect, uv: Point): Unit
|
||||
def drawIcon(r: Rect, i: Icon)
|
||||
}
|
||||
|
||||
class WidgetContainerWindow(val parent: BaseScreen, xSz: Int, ySz: Int) extends WidgetContainer {
|
||||
def getFontRenderer = parent.getFontRenderer
|
||||
def getOffsetFromWindow = Point(0, 0)
|
||||
val rect = Rect(0, 0, xSz, ySz)
|
||||
def drawTexture(r: Rect, uv: Point) =
|
||||
parent.drawTexturedModalRect(r.x, r.y, uv.x, uv.y, r.w, r.h)
|
||||
def drawIcon(r: Rect, i: Icon) =
|
||||
parent.drawTexturedModelRectFromIcon(r.x, r.y, i, r.w, r.h)
|
||||
}
|
||||
|
||||
class WidgetSubcontainer(val rect: Rect) extends BaseWidget with WidgetContainer {
|
||||
def getFontRenderer = parent.getFontRenderer
|
||||
def getOffsetFromWindow = parent.getOffsetFromWindow + rect.origin
|
||||
def drawTexture(r: Rect, uv: Point) = parent.drawTexture(r, uv)
|
||||
def drawIcon(r: Rect, i: Icon) = parent.drawIcon(r, i)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -10,17 +10,28 @@
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.gui.{Point, BaseScreen, Rect}
|
||||
import net.bdew.lib.gui.{WidgetContainer, Point, Rect}
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraft.client.Minecraft
|
||||
|
||||
trait Widget {
|
||||
trait BaseWidget {
|
||||
val rect: Rect
|
||||
var parent: WidgetContainer = null
|
||||
def init(p: WidgetContainer) = parent = p
|
||||
def handleTooltip(p: Point, tip: mutable.MutableList[String])
|
||||
def mouseClicked(p: Point, button: Int)
|
||||
def keyTyped(c: Char, i: Int): Boolean
|
||||
def draw(mouse: Point)
|
||||
def looseFocus()
|
||||
}
|
||||
|
||||
trait Widget extends BaseWidget {
|
||||
val rect: Rect
|
||||
var parent: BaseScreen = null
|
||||
def handleTooltip(p: Point, tip: mutable.MutableList[String]) {}
|
||||
def mouseClicked(p: Point, button: Int) {}
|
||||
def keyTyped(c: Char, i: Int): Boolean = false
|
||||
def draw() {}
|
||||
def draw(mouse: Point) {}
|
||||
def looseFocus() {}
|
||||
|
||||
def bindTexture(res: ResourceLocation) = Minecraft.getMinecraft.renderEngine.bindTexture(res)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2014
|
||||
* https://github.com/bdew/teleporter
|
||||
*
|
||||
* 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/teleporter/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.minecraft.client.gui.GuiButton
|
||||
import net.bdew.lib.gui.{Point, Rect}
|
||||
import net.minecraft.client.Minecraft
|
||||
|
||||
class WidgetButton(val rect: Rect, text: String, clicked: WidgetButton => Unit)
|
||||
extends GuiButton(0, rect.x, rect.y, rect.w, rect.h, text) with Widget {
|
||||
|
||||
override def mouseClicked(p: Point, button: Int) {
|
||||
Minecraft.getMinecraft.sndManager.playSoundFX("random.click", 1.0F, 1.0F)
|
||||
clicked(this)
|
||||
}
|
||||
|
||||
override def draw(mouse: Point) = drawButton(Minecraft.getMinecraft, mouse.x, mouse.y)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -9,29 +9,28 @@
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.{TextureLocation, Rect}
|
||||
import net.bdew.lib.gui.Direction
|
||||
import net.bdew.lib.gui.{Point, TextureLocation, Rect, Direction}
|
||||
import net.bdew.lib.data.base.DataSlotNumeric
|
||||
|
||||
class WidgetFillDataslot[T](val rect: Rect, val texture: TextureLocation, dir: Direction.Direction, dslot: DataSlotNumeric[T], maxval: T)(implicit num: Numeric[T]) extends Widget {
|
||||
|
||||
def getFillArea(max: Int): Int = (num.toFloat(dslot) / num.toFloat(maxval) * max).round
|
||||
|
||||
override def draw() {
|
||||
override def draw(mouse: Point) {
|
||||
bindTexture(texture.resource)
|
||||
dir match {
|
||||
case Direction.UP =>
|
||||
val fill = getFillArea(rect.h)
|
||||
parent.drawTexturedModalRect(rect.x, rect.y + rect.h - fill, texture.x, texture.y + rect.h - fill, rect.w, fill)
|
||||
parent.drawTexture(Rect(rect.x, rect.y + rect.h - fill, rect.w, fill), Point(texture.x, texture.y + rect.h - fill))
|
||||
case Direction.DOWN =>
|
||||
val fill = getFillArea(rect.h)
|
||||
parent.drawTexturedModalRect(rect.x, rect.y, texture.x, texture.y, rect.w, fill)
|
||||
parent.drawTexture(Rect(rect.x, rect.y, rect.w, fill), Point(texture.x, texture.y))
|
||||
case Direction.LEFT =>
|
||||
val fill = getFillArea(rect.w)
|
||||
parent.drawTexturedModalRect(rect.x + rect.w - fill, rect.y, texture.x + rect.w - fill, texture.y, fill, rect.h)
|
||||
parent.drawTexture(Rect(rect.x + rect.w - fill, rect.y, fill, rect.h), Point(texture.x + rect.w - fill, texture.y))
|
||||
case Direction.RIGHT =>
|
||||
val fill = getFillArea(rect.w)
|
||||
parent.drawTexturedModalRect(rect.x, rect.y, texture.x, texture.y, fill, rect.h)
|
||||
parent.drawTexture(Rect(rect.x, rect.y, fill, rect.h), Point(texture.x, texture.y))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -25,11 +25,11 @@ class WidgetFluidGauge(val rect: Rect, overlay: TextureLocation, dslot: DataSlot
|
||||
tip += dslot.getFluid.getFluid.getLocalizedName
|
||||
tip += "%s/%s mB".format(formater.format(dslot.getFluidAmount), formater.format(dslot.getCapacity))
|
||||
} else {
|
||||
tip += Misc.toLocal("gendustry.label.empty")
|
||||
tip += Misc.toLocal("bdlib.label.empty")
|
||||
}
|
||||
}
|
||||
|
||||
override def draw() {
|
||||
override def draw(mouse: Point) {
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
@@ -37,15 +37,15 @@ class WidgetFluidGauge(val rect: Rect, overlay: TextureLocation, dslot: DataSlot
|
||||
if (fstack != null && fstack.getFluid.getStillIcon != null) {
|
||||
val icon = fstack.getFluid.getStillIcon
|
||||
bindTexture(TextureMap.locationBlocksTexture)
|
||||
var fillHeight: Int = (rect.h * fstack.amount / dslot.getCapacity).round
|
||||
var fillHeight: Int = if (dslot.getCapacity > 0) (rect.h * fstack.amount / dslot.getCapacity).round else 0
|
||||
var yStart: Int = 0
|
||||
|
||||
while (fillHeight > 0) {
|
||||
if (fillHeight > 16) {
|
||||
parent.drawTexturedModelRectFromIcon(rect.x, rect.y + rect.h - 16 - yStart, icon, 16, 16)
|
||||
parent.drawIcon(Rect(rect.x, rect.y + rect.h - 16 - yStart, rect.w, 16), icon)
|
||||
fillHeight -= 16
|
||||
} else {
|
||||
parent.drawTexturedModelRectFromIcon(rect.x, rect.y + rect.h - fillHeight - yStart, icon, 16, fillHeight)
|
||||
parent.drawIcon(Rect(rect.x, rect.y + rect.h - fillHeight - yStart, rect.w, fillHeight), icon)
|
||||
fillHeight = 0
|
||||
}
|
||||
yStart = yStart + 16
|
||||
@@ -54,7 +54,6 @@ class WidgetFluidGauge(val rect: Rect, overlay: TextureLocation, dslot: DataSlot
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND)
|
||||
|
||||
bindTexture(overlay.resource)
|
||||
parent.drawTexturedModalRect(rect.x, rect.y, overlay.x, overlay.y, rect.w, rect.h)
|
||||
parent.drawTexture(rect, overlay)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.Rect
|
||||
import net.bdew.lib.gui.{Point, Rect}
|
||||
|
||||
class WidgetLabel(text: String, x: Int, y: Int, color: Int) extends Widget {
|
||||
val rect: Rect = new Rect(x, y, 0, 0)
|
||||
override def draw() {
|
||||
override def draw(mouse: Point) {
|
||||
parent.getFontRenderer.drawString(text, x, y, color)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -13,7 +13,13 @@ import net.minecraft.client.gui.{FontRenderer, GuiTextField}
|
||||
import net.bdew.lib.gui.{Point, Rect}
|
||||
|
||||
class WidgetTextEdit(val rect: Rect, fr: FontRenderer) extends GuiTextField(fr, rect.x, rect.y, rect.w, rect.h) with Widget {
|
||||
override def mouseClicked(p: Point, button: Int) = super.mouseClicked(p.x + rect.x, p.y + rect.y, button)
|
||||
|
||||
override def mouseClicked(p: Point, button: Int) = {
|
||||
val pp = p + rect.origin
|
||||
super.mouseClicked(pp.x, pp.y, button)
|
||||
}
|
||||
|
||||
override def looseFocus() = setFocused(false)
|
||||
override def keyTyped(c: Char, i: Int): Boolean = super.textboxKeyTyped(c, i)
|
||||
override def draw() = super.drawTextBox()
|
||||
override def draw(mouse: Point) = super.drawTextBox()
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -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.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
|
||||
|
||||
class SimpleItem(id: Int, val name: String) extends Item(id) {
|
||||
val modId = Misc.getActiveModId
|
||||
setUnlocalizedName(modId + "." + name)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def registerIcons(reg: IconRegister) {
|
||||
itemIcon = reg.registerIcon(modId + ":" + name.toLowerCase)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.machine
|
||||
|
||||
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
|
||||
|
||||
abstract class Machine[T <: Block](val name: String, val blockConstruct: (Int) => 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))
|
||||
GameRegistry.registerBlock(block, name)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
|
||||
if (block.isInstanceOf[HasTE[_]]) {
|
||||
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass, "%s.%s".format(modId, name))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.machine
|
||||
|
||||
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
|
||||
trait PoweredMachine {
|
||||
def tuning: ConfigSection
|
||||
lazy val maxReceivedEnergy = tuning.getFloat("MaxReceivedEnergy")
|
||||
lazy val activationEnergy = tuning.getFloat("ActivationEnergy")
|
||||
lazy val maxStoredEnergy = tuning.getFloat("MaxStoredEnergy")
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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.machine
|
||||
|
||||
trait ProcessorMachine extends PoweredMachine {
|
||||
lazy val mjPerItem = tuning.getFloat("MjPerItem")
|
||||
lazy val powerUseRate = tuning.getFloat("PowerUseRate")
|
||||
}
|
||||
@@ -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.power
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlot}
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.machine.PoweredMachine
|
||||
|
||||
case class DataSlotPower(name: String, parent: TileDataSlots) extends DataSlot {
|
||||
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
||||
|
||||
var stored = 0F
|
||||
var capacity = 0F
|
||||
var maxReceive = 0F
|
||||
|
||||
def inject(v: Float, simulate: Boolean): Float = {
|
||||
val canAdd = Misc.clamp(v, 0F, Misc.min(capacity - stored, maxReceive))
|
||||
if ((canAdd > 0) && !simulate) {
|
||||
stored += canAdd
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
return canAdd
|
||||
}
|
||||
|
||||
def extract(v: Float, simulate: Boolean): Float = {
|
||||
val canExtract = Misc.clamp(v, 0F, stored)
|
||||
if ((canExtract > 0) && !simulate) {
|
||||
stored -= canExtract
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
return canExtract
|
||||
}
|
||||
|
||||
def configure(cfg: PoweredMachine) {
|
||||
capacity = cfg.maxStoredEnergy
|
||||
maxReceive = cfg.maxReceivedEnergy
|
||||
}
|
||||
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
val tag = new NBTTagCompound()
|
||||
tag.setFloat("stored", stored)
|
||||
if (kind == UpdateKind.GUI)
|
||||
tag.setFloat("capacity", capacity)
|
||||
t.setCompoundTag(name, tag)
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
if (t.hasKey(name)) {
|
||||
val tag = t.getCompoundTag(name)
|
||||
stored = tag.getFloat("stored")
|
||||
if (kind == UpdateKind.GUI)
|
||||
capacity = tag.getFloat("capacity")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.power
|
||||
|
||||
import net.minecraft.item.{ItemStack, Item}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.entity.EntityLivingBase
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
trait ItemPoweredBase extends Item {
|
||||
def maxCharge: Int
|
||||
def mjPerCharge: Int
|
||||
|
||||
def getCharge(stack: ItemStack): Int = {
|
||||
if (!stack.hasTagCompound) setCharge(stack, 0)
|
||||
return Misc.clamp(stack.getTagCompound.getInteger("charge"), 0, maxCharge)
|
||||
}
|
||||
|
||||
def useCharge(stack: ItemStack, uses: Int = 1, player: EntityLivingBase) {
|
||||
setCharge(stack, Misc.clamp(getCharge(stack) - uses * mjPerCharge, 0, maxCharge))
|
||||
}
|
||||
|
||||
def hasCharges(stack: ItemStack) = getCharge(stack) >= mjPerCharge
|
||||
|
||||
def setCharge(stack: ItemStack, charge: Int) {
|
||||
if (!stack.hasTagCompound) stack.setTagCompound(new NBTTagCompound())
|
||||
stack.getTagCompound.setInteger("charge", charge)
|
||||
updateDamage(stack)
|
||||
}
|
||||
|
||||
def updateDamage(stack: ItemStack) {
|
||||
setDamage(stack, Misc.clamp((100 * (1 - getCharge(stack).toFloat / maxCharge)).round, 1, 100))
|
||||
}
|
||||
|
||||
def stackWithCharge(charge: Int): ItemStack = {
|
||||
val n = new ItemStack(this)
|
||||
setCharge(n, charge)
|
||||
return n
|
||||
}
|
||||
|
||||
override def setDamage(stack: ItemStack, damage: Int) = super.setDamage(stack, Misc.clamp(damage, 1, 100))
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.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.machine.ProcessorMachine
|
||||
|
||||
abstract class TileBaseProcessor extends TileExtended
|
||||
with TileDataSlots
|
||||
with PersistentInventoryTile
|
||||
with BreakableInventoryTile
|
||||
with SidedInventory
|
||||
with TilePoweredBase {
|
||||
def cfg: ProcessorMachine
|
||||
val power = DataSlotPower("power", this)
|
||||
val progress = DataSlotFloat("progress", this).setUpdate(UpdateKind.SAVE, UpdateKind.GUI)
|
||||
|
||||
configurePower(cfg)
|
||||
|
||||
override def tickServer() {
|
||||
if (power.stored > cfg.activationEnergy) {
|
||||
|
||||
if (!isWorking)
|
||||
if (tryStart())
|
||||
progress := 0
|
||||
|
||||
if (isWorking) {
|
||||
|
||||
if ((progress < 1) && (power.stored > cfg.activationEnergy)) {
|
||||
val maxConsume = Math.min(Math.max(cfg.powerUseRate * power.stored, cfg.activationEnergy), cfg.mjPerItem * (1 - progress))
|
||||
val consumed = power.extract(maxConsume, false)
|
||||
progress += consumed / cfg.mjPerItem
|
||||
}
|
||||
|
||||
if (progress >= 1) {
|
||||
if (tryFinish())
|
||||
progress := 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true when an operation is in progress
|
||||
*/
|
||||
def isWorking: Boolean
|
||||
|
||||
/**
|
||||
* Try starting a new operation, return true if succesful
|
||||
*/
|
||||
def tryStart(): Boolean
|
||||
|
||||
/**
|
||||
* Perform output when operation is done, return true if succesful
|
||||
*/
|
||||
def tryFinish(): Boolean
|
||||
}
|
||||
@@ -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.power
|
||||
|
||||
import net.bdew.lib.data.DataSlotItemStack
|
||||
import net.bdew.lib.data.base.UpdateKind
|
||||
import net.bdew.lib.items.ItemUtils
|
||||
|
||||
abstract class TileItemProcessor extends TileBaseProcessor {
|
||||
val output = DataSlotItemStack("output", this).setUpdate(UpdateKind.SAVE)
|
||||
val outputSlots: Seq[Int]
|
||||
|
||||
def isWorking = output :!= null
|
||||
|
||||
def tryFinish(): Boolean = {
|
||||
output := ItemUtils.addStackToSlots(output, this, outputSlots, false)
|
||||
return output :== null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.power
|
||||
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.lib.machine.PoweredMachine
|
||||
|
||||
trait TilePoweredBase extends TileExtended {
|
||||
def power: DataSlotPower
|
||||
def configurePower(cfg: PoweredMachine) = power.configure(cfg)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.power
|
||||
|
||||
import net.bdew.lib.gui.{Point, TextureLocation, Rect}
|
||||
import scala.collection.mutable
|
||||
import java.text.DecimalFormat
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.bdew.lib.gui.widgets.Widget
|
||||
|
||||
class WidgetPowerGauge(val rect: Rect, texture: TextureLocation, dslot: DataSlotPower) extends Widget {
|
||||
val formater = new DecimalFormat("#,###")
|
||||
|
||||
override def draw(mouse: Point) {
|
||||
Minecraft.getMinecraft.renderEngine.bindTexture(texture.resource)
|
||||
val fill = (dslot.stored / dslot.capacity * rect.h).round
|
||||
parent.drawTexture(Rect(rect.x, rect.y + rect.h - fill, rect.w, fill), Point(texture.x, texture.y + rect.h - fill))
|
||||
}
|
||||
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += formater.format(dslot.stored) + "/" + formater.format(dslot.capacity) + " MJ"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -89,6 +89,12 @@ case class StackMacro(id: Char) extends StackRef
|
||||
*/
|
||||
abstract class Statement
|
||||
|
||||
/**
|
||||
* Base class for delayed statements (executed after everything is parsed)
|
||||
* Actual processing is in [[net.bdew.lib.recipes.RecipeLoader.processDelayedStatements]]
|
||||
*/
|
||||
abstract class DelayedStatement extends Statement
|
||||
|
||||
/**
|
||||
* Character assignment
|
||||
* Syntax: {char} = {ref}
|
||||
@@ -96,7 +102,7 @@ abstract class Statement
|
||||
* @param char Character to assign
|
||||
* @param spec ItemStack Reference
|
||||
*/
|
||||
case class StCharAssign(char: Char, spec: StackRef) extends Statement
|
||||
case class StCharAssign(char: Char, spec: StackRef) extends DelayedStatement
|
||||
|
||||
/**
|
||||
* Define class macro
|
||||
@@ -105,7 +111,7 @@ case class StCharAssign(char: Char, spec: StackRef) extends Statement
|
||||
* @param id Macro identifier
|
||||
* @param cls Class name
|
||||
*/
|
||||
case class StClassMacro(id: String, cls: String) extends Statement
|
||||
case class StClassMacro(id: String, cls: String) extends DelayedStatement
|
||||
|
||||
/**
|
||||
* Conditional block - checks if mod is loaded
|
||||
@@ -127,6 +133,19 @@ case class StIfHaveMod(mod: String, thn: List[Statement], els: List[Statement])
|
||||
*/
|
||||
case class StIfHaveOD(id: String, thn: List[Statement], els: List[Statement]) extends Statement
|
||||
|
||||
/**
|
||||
* Removes previously defined recieps for a specific result
|
||||
* @param res Recipes that produce this result will be cleared
|
||||
*/
|
||||
case class StClearRecipes(res: StackRef) extends Statement
|
||||
|
||||
/**
|
||||
* Base class for staments that represent a crafting recipe
|
||||
*/
|
||||
abstract class CraftingStatement extends DelayedStatement {
|
||||
def result: StackRef
|
||||
}
|
||||
|
||||
/**
|
||||
* Shaped recipe definition
|
||||
*
|
||||
@@ -147,10 +166,10 @@ case class StIfHaveOD(id: String, thn: List[Statement], els: List[Statement]) ex
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.recipeShaped9]]
|
||||
*
|
||||
* @param rec Recipe pattern
|
||||
* @param res Result reference
|
||||
* @param result Result reference
|
||||
* @param cnt Number of output items
|
||||
*/
|
||||
case class StRecipeShaped(rec: Seq[String], res: StackRef, cnt: Int) extends Statement
|
||||
case class StRecipeShaped(rec: Seq[String], result: StackRef, cnt: Int) extends CraftingStatement
|
||||
|
||||
/**
|
||||
* Shapeless recipe definition
|
||||
@@ -158,10 +177,10 @@ case class StRecipeShaped(rec: Seq[String], res: StackRef, cnt: Int) extends Sta
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.recipeShapeless]]
|
||||
*
|
||||
* @param rec Recipe pattehrn
|
||||
* @param res Result reference
|
||||
* @param result Result reference
|
||||
* @param cnt Number of output items
|
||||
*/
|
||||
case class StRecipeShapeless(rec: String, res: StackRef, cnt: Int) extends Statement
|
||||
case class StRecipeShapeless(rec: String, result: StackRef, cnt: Int) extends CraftingStatement
|
||||
|
||||
/**
|
||||
* Smelting recipe definition
|
||||
@@ -169,11 +188,11 @@ case class StRecipeShapeless(rec: String, res: StackRef, cnt: Int) extends State
|
||||
* Parser [[net.bdew.lib.recipes.RecipeParser.recipeSmelting]]
|
||||
*
|
||||
* @param in Input Stack
|
||||
* @param out Output Stack
|
||||
* @param result Output Stack
|
||||
* @param cnt Output Count
|
||||
* @param xp XP for smelting
|
||||
*/
|
||||
case class StSmeltRecipe(in: StackRef, out: StackRef, cnt: Int, xp: Float) extends Statement
|
||||
case class StSmeltRecipe(in: StackRef, result: StackRef, cnt: Int, xp: Float) extends CraftingStatement
|
||||
|
||||
/**
|
||||
* Used in statement processing to abort the current statement and show an error without a stack trace
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -40,18 +40,23 @@ class RecipeLoader {
|
||||
/**
|
||||
* Current map of recipe characters to parser item references
|
||||
*/
|
||||
val currCharMap = collection.mutable.Map.empty[Char, StackRef].withDefault(x => error("Undefined recipe character '%s'", x))
|
||||
var currCharMap = Map.empty[Char, StackRef].withDefault(x => error("Undefined recipe character '%s'", x))
|
||||
|
||||
/**
|
||||
* Current map of class macros
|
||||
*/
|
||||
val currClassMacros = collection.mutable.Map.empty[String, String].withDefault(x => error("Undefined class macro '%s'", x))
|
||||
var currClassMacros = Map.empty[String, String].withDefault(x => error("Undefined class macro '%s'", x))
|
||||
|
||||
/**
|
||||
* Triggers an error with formatted string
|
||||
*/
|
||||
def error(msg: String, params: Any*) = throw new StatementError(msg.format(params: _*))
|
||||
|
||||
/**
|
||||
* List of unprocessed delayed statements
|
||||
*/
|
||||
var delayedStatements = List.empty[DelayedStatement]
|
||||
|
||||
/**
|
||||
* Looks up a recipe component
|
||||
* @param s Parser ItemStack reference
|
||||
@@ -209,14 +214,6 @@ class RecipeLoader {
|
||||
* @param s The statement
|
||||
*/
|
||||
def processStatement(s: Statement): Unit = s match {
|
||||
case StCharAssign(c, r) =>
|
||||
currCharMap(c) = r
|
||||
log.info("Added %s = %s".format(c, r))
|
||||
|
||||
case StClassMacro(id, cls) =>
|
||||
currClassMacros(id) = cls
|
||||
log.info("Added def %s = %s".format(id, cls))
|
||||
|
||||
case StIfHaveMod(mod, thn, els) =>
|
||||
if (Misc.haveModVersion(mod)) {
|
||||
log.info("ifMod: %s found".format(mod))
|
||||
@@ -235,6 +232,38 @@ class RecipeLoader {
|
||||
processStatementsSafe(els)
|
||||
}
|
||||
|
||||
case StClearRecipes(res) =>
|
||||
log.info("Clearing recipes that produce %s".format(res))
|
||||
delayedStatements = delayedStatements.filter({
|
||||
x =>
|
||||
if (x.isInstanceOf[CraftingStatement])
|
||||
if (x.asInstanceOf[CraftingStatement].result == res) {
|
||||
log.info("Removing recipe %s".format(x))
|
||||
false
|
||||
} else true
|
||||
else true
|
||||
})
|
||||
|
||||
case x: DelayedStatement =>
|
||||
delayedStatements :+= x
|
||||
|
||||
case x =>
|
||||
log.severe("Can't process %s - this is a programing bug!".format(x))
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a single delayed statement
|
||||
* @param st The statement
|
||||
*/
|
||||
def processDelayedStatement(st: DelayedStatement) = st match {
|
||||
case StCharAssign(c, r) =>
|
||||
currCharMap += (c -> r)
|
||||
log.info("Added %s = %s".format(c, r))
|
||||
|
||||
case StClassMacro(id, cls) =>
|
||||
currClassMacros += (id -> cls)
|
||||
log.info("Added def %s = %s".format(id, cls))
|
||||
|
||||
case StRecipeShaped(rec, res, cnt) =>
|
||||
log.info("Adding shaped recipe %s => %s * %d".format(rec, res, cnt))
|
||||
val (comp, needOd) = resolveRecipeComponents(rec.mkString(""))
|
||||
@@ -291,6 +320,25 @@ class RecipeLoader {
|
||||
log.severe("Can't process %s - this is a programing bug!".format(x))
|
||||
}
|
||||
|
||||
/**
|
||||
* Process delayed statements, clear the list afterwards
|
||||
*/
|
||||
def processDelayedStatements() {
|
||||
log.info("Processing %d delayed statements".format(delayedStatements.size))
|
||||
for (s <- delayedStatements) {
|
||||
try {
|
||||
processDelayedStatement(s)
|
||||
} catch {
|
||||
case e: StatementError =>
|
||||
log.severe("Error while processing %s: %s".format(s, e.getMessage))
|
||||
case e: Throwable =>
|
||||
log.severe("Error while processing %s: %s".format(s, e))
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
delayedStatements = List.empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a list of statements and catch all exceptions
|
||||
* @param r The list to process
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -102,15 +102,19 @@ class RecipeParser extends JavaTokenParsers {
|
||||
case in ~ (out ~ n) ~ xp => StSmeltRecipe(in, out, n.getOrElse(1), xp.getOrElse("0").toFloat)
|
||||
}
|
||||
|
||||
def clearRecipes = "clearRecipes" ~> ":" ~> spec ^^ { case sp => StClearRecipes(sp) }
|
||||
|
||||
def statement: Parser[Statement] = (
|
||||
charSpec
|
||||
| classMacro
|
||||
| ifMod
|
||||
| ifOreDict
|
||||
| recipeShaped3x3
|
||||
| recipeShaped2x2
|
||||
| recipeShaped9
|
||||
| recipeShapeless
|
||||
| recipeSmelting
|
||||
| clearRecipes
|
||||
)
|
||||
|
||||
def statements = statement.*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
@@ -16,10 +16,10 @@ case class EntryDouble(v: Double) extends CfgEntry
|
||||
case class EntryStr(v: String) extends CfgEntry
|
||||
|
||||
case class ConfigSection(pfx: String = "") extends CfgEntry with Iterable[(String, CfgEntry)] {
|
||||
var raw = Map.empty[String, CfgEntry].withDefault(x => sys.error("Config value '%s%s' is missing".format(pfx,x)))
|
||||
var raw = Map.empty[String, CfgEntry].withDefault(x => sys.error("Config value '%s%s' is missing".format(pfx, x)))
|
||||
|
||||
def iterator: Iterator[(String, CfgEntry)] = raw.iterator
|
||||
def filterType[T<:CfgEntry](cls: Class[T]): Iterable[(String,T)] = raw.filter(x=>cls.isInstance(x._2)).map(x=>x.asInstanceOf[(String,T)])
|
||||
def filterType[T <: CfgEntry](cls: Class[T]): Iterable[(String, T)] = raw.filter(x => cls.isInstance(x._2)).map(x => x.asInstanceOf[(String, T)])
|
||||
|
||||
def rawget[T](id: String, t: Class[T]): T = {
|
||||
val v = raw(id)
|
||||
@@ -35,10 +35,11 @@ case class ConfigSection(pfx: String = "") extends CfgEntry with Iterable[(Strin
|
||||
def getString(id: String) = rawget(id, classOf[EntryStr]).v
|
||||
def getSection(id: String) = rawget(id, classOf[ConfigSection])
|
||||
|
||||
|
||||
final val trueVals = Set("y", "true", "yes", "on")
|
||||
def getBoolean(id: String) = trueVals.contains(getString(id).toLowerCase)
|
||||
|
||||
def hasValue(id: String) = raw.isDefinedAt(id)
|
||||
|
||||
def getOrAddSection(id: String) = {
|
||||
if (raw.isDefinedAt(id)) {
|
||||
rawget(id, classOf[ConfigSection])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
|
||||
Reference in new issue
Block a user