mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-21 04:32:32 +00:00
Merge remote-tracking branch 'remotes/origin/master' into mc172
This commit is contained in:
commit
d80d89acf1
12 files changed
+119
-26
No files matched your search
@@ -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
|
||||
|
||||
import org.lwjgl.input.Keyboard
|
||||
import net.minecraft.client.Minecraft
|
||||
|
||||
/**
|
||||
* Misc functions and shortcuts for clientside code
|
||||
*/
|
||||
object Client {
|
||||
def minecraft = Minecraft.getMinecraft
|
||||
def fontRenederer = Minecraft.getMinecraft.fontRenderer
|
||||
def renderEngine = Minecraft.getMinecraft.renderEngine
|
||||
def world = Minecraft.getMinecraft.theWorld
|
||||
def player = Minecraft.getMinecraft.thePlayer
|
||||
|
||||
def shiftDown: Boolean = {
|
||||
return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@ 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 net.minecraft.world.biome.BiomeGenBase
|
||||
|
||||
object Misc {
|
||||
def iterNbtCompoundList(parent: NBTTagCompound, name: String): Iterable[NBTTagCompound] = {
|
||||
@@ -55,6 +56,8 @@ 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 haveModVersion(spec: String): Boolean = {
|
||||
val req = VersionParser.parseVersionReference(spec)
|
||||
val modid = req.getLabel
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.client.gui.inventory.GuiContainer
|
||||
import net.minecraft.inventory.Container
|
||||
import scala.collection.mutable
|
||||
import net.minecraft.client.Minecraft
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContainer(cont) {
|
||||
xSize = xSz
|
||||
@@ -61,6 +62,10 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
|
||||
protected def drawGuiContainerBackgroundLayer(f: Float, x: Int, y: Int) {
|
||||
if (background != null)
|
||||
widgets.drawTexture(rect, background)
|
||||
widgets.drawBackground(Point(x, y))
|
||||
|
||||
GL11.glPushMatrix()
|
||||
GL11.glTranslatef(rect.x, rect.y, 0)
|
||||
widgets.drawBackground(Point(x, y) - rect.origin)
|
||||
GL11.glPopMatrix()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.{IInventory, Slot}
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
class BaseSlot(inv: IInventory, slot: Int, x: Int, y: Int) extends Slot(inv, slot, x, y) {
|
||||
override def getBackgroundIconIndex = {
|
||||
// Workaround for bug in GuiContainer, color isn't reset if previous slot had an item with color.
|
||||
GL11.glColor4d(1, 1, 1, 1)
|
||||
super.getBackgroundIconIndex
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,8 @@
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
class SlotValidating(inv: IInventory, slot: Int, x: Int, y: Int) extends Slot(inv, slot, x, y) {
|
||||
class SlotValidating(inv: IInventory, slot: Int, x: Int, y: Int) extends BaseSlot(inv, slot, x, y) {
|
||||
override def isItemValid(stack: ItemStack) = inventory.isItemValidForSlot(getSlotIndex, stack)
|
||||
}
|
||||
@@ -11,8 +11,6 @@ package net.bdew.lib.gui.widgets
|
||||
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.gui.{WidgetContainer, Point, Rect}
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraft.client.Minecraft
|
||||
|
||||
trait BaseWidget {
|
||||
val rect: Rect
|
||||
|
||||
@@ -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.items
|
||||
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
|
||||
/**
|
||||
* Allows matching Items in ItemStacks in scala pattern matches
|
||||
*/
|
||||
object IStack {
|
||||
def unapply(x: ItemStack): Option[Item] =
|
||||
if (x == null || x.getItem == null)
|
||||
None
|
||||
else
|
||||
Some(x.getItem)
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
package net.bdew.lib.items
|
||||
|
||||
import net.minecraft.entity.item.EntityItem
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.world.World
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.IInventory
|
||||
@@ -76,4 +76,9 @@ object ItemUtils {
|
||||
|
||||
return stack
|
||||
}
|
||||
|
||||
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 })
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
package net.bdew.lib.items.inventory
|
||||
|
||||
import net.minecraft.item.Item
|
||||
import net.bdew.lib.gui.{BaseScreen, GuiProvider}
|
||||
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
|
||||
@@ -29,7 +29,7 @@ trait ItemInventory extends Item with GuiProvider {
|
||||
val modObj = Loader.instance().activeModContainer().getMod
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def makeGui(inv: InventoryItemAdapter, player: EntityPlayer): BaseScreen
|
||||
def makeGui(inv: InventoryItemAdapter, player: EntityPlayer): AnyRef
|
||||
def makeContainer(inv: InventoryItemAdapter, player: EntityPlayer): ContainerItemInventory
|
||||
|
||||
def makeAdaptor(player: EntityPlayer) = new InventoryItemAdapter(player, player.inventory.currentItem, invSize, invTagName)
|
||||
|
||||
@@ -127,13 +127,14 @@ case class StIfHaveMod(mod: String, thn: List[Statement], els: List[Statement])
|
||||
|
||||
/**
|
||||
* Conditional block - checks if mod is loaded
|
||||
* Can contain only delayed statements
|
||||
* Syntax: ifOreDict {string} { {statements} } [else { {statements} }]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.ifOreDict]]
|
||||
* @param id Ore Dictionary Entry
|
||||
* @param thn Statements to run if present
|
||||
* @param els Statements to run otherwise
|
||||
*/
|
||||
case class StIfHaveOD(id: String, thn: List[Statement], els: List[Statement]) extends Statement
|
||||
case class StIfHaveOD(id: String, thn: List[DelayedStatement], els: List[DelayedStatement]) extends DelayedStatement
|
||||
|
||||
/**
|
||||
* Removes previously defined recieps for a specific result
|
||||
|
||||
@@ -219,15 +219,6 @@ class RecipeLoader {
|
||||
processStatementsSafe(els)
|
||||
}
|
||||
|
||||
case StIfHaveOD(od, thn, els) =>
|
||||
if (OreDictionary.getOres(od).size() > 0) {
|
||||
BdLib.logInfo("ifOreDict: %s found", od)
|
||||
processStatementsSafe(thn)
|
||||
} else {
|
||||
BdLib.logInfo("ifOreDict: %s not found", od)
|
||||
processStatementsSafe(els)
|
||||
}
|
||||
|
||||
case StClearRecipes(res) =>
|
||||
BdLib.logInfo("Clearing recipes that produce %s", res)
|
||||
delayedStatements = delayedStatements.filter({
|
||||
@@ -307,16 +298,34 @@ class RecipeLoader {
|
||||
BdLib.logInfo("added %d -> %s", inStack, outStack)
|
||||
}
|
||||
|
||||
case StIfHaveOD(od, thn, els) =>
|
||||
if (OreDictionary.getOres(od).size() > 0) {
|
||||
BdLib.logInfo("ifOreDict: %s found".format(od))
|
||||
processDelayedStatementsSafe(thn)
|
||||
} else {
|
||||
BdLib.logInfo("ifOreDict: %s not found".format(od))
|
||||
processDelayedStatementsSafe(els)
|
||||
}
|
||||
|
||||
case x =>
|
||||
BdLib.logError("Can't process %s - this is a programing bug!", x)
|
||||
}
|
||||
|
||||
/**
|
||||
* Process delayed statements, clear the list afterwards
|
||||
* Process main delayed statements list, clear the list afterwards
|
||||
*/
|
||||
def processDelayedStatements() {
|
||||
BdLib.logInfo("Processing %d delayed statements", delayedStatements.size)
|
||||
for (s <- delayedStatements) {
|
||||
processDelayedStatementsSafe(delayedStatements)
|
||||
delayedStatements = List.empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a list of delayed statements and catch all exceptions
|
||||
* @param list The list to process
|
||||
*/
|
||||
def processDelayedStatementsSafe(list: List[DelayedStatement]) {
|
||||
for (s <- list) {
|
||||
try {
|
||||
processDelayedStatement(s)
|
||||
} catch {
|
||||
@@ -327,7 +336,6 @@ class RecipeLoader {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
delayedStatements = List.empty
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,8 +81,8 @@ class RecipeParser extends JavaTokenParsers {
|
||||
case mod ~ thn ~ els => new StIfHaveMod(mod, thn, els.getOrElse(List.empty[Statement]))
|
||||
}
|
||||
|
||||
def ifOreDict = ("ifOreDict" ~> str) ~ ("{" ~> statements <~ "}") ~ ("else" ~> "{" ~> statements <~ "}").? ^^ {
|
||||
case id ~ thn ~ els => new StIfHaveOD(id, 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]))
|
||||
}
|
||||
|
||||
def recipeShaped3x3 = recipeTriplet ~ recipeTriplet ~ ("=>" ~> specWithCount) ~ recipeTriplet ^^ {
|
||||
@@ -107,20 +107,21 @@ class RecipeParser extends JavaTokenParsers {
|
||||
|
||||
def clearRecipes = "clearRecipes" ~> ":" ~> spec ^^ { case sp => StClearRecipes(sp) }
|
||||
|
||||
def statement: Parser[Statement] = (
|
||||
def delayedStatement: Parser[DelayedStatement] = (
|
||||
charSpec
|
||||
| classMacro
|
||||
| ifMod
|
||||
| ifOreDict
|
||||
| recipeShaped3x3
|
||||
| recipeShaped2x2
|
||||
| recipeShaped9
|
||||
| recipeShapeless
|
||||
| recipeSmelting
|
||||
| clearRecipes
|
||||
)
|
||||
|
||||
def statement: Parser[Statement] = delayedStatement | ifMod | clearRecipes
|
||||
|
||||
def statements = statement.*
|
||||
def delayedStatements = delayedStatement.*
|
||||
|
||||
def doParse(r: Reader): List[Statement] = {
|
||||
parseAll(statements, r) match {
|
||||
|
||||
Reference in new issue
Block a user