Compare commits

...
8 Commits
19 changed files with 225 additions and 89 deletions

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ buildscript {
apply plugin: 'forge'
apply plugin: 'scala'
version = "1.0.1"
version = "1.1.0"
if (project.hasProperty('buildnum')) {
project.version = project.version + '.' + project.buildnum
+4 -4
View File
@@ -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)
@@ -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
@@ -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)
}
}
@@ -13,4 +13,5 @@ object UpdateKind extends Enumeration {
val WORLD = Value("WORLD")
val GUI = Value("GUI")
val SAVE = Value("SAVE")
val RENDER = Value("RENDER")
}
+3 -26
View File
@@ -9,35 +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))
}
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)
}
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) {
+10 -31
View File
@@ -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._
+41
View File
@@ -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 -1
View File
@@ -9,7 +9,7 @@
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)
+1 -1
View File
@@ -9,7 +9,7 @@
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)
@@ -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)
}
+15 -4
View File
@@ -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)
}
@@ -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))
}
}
}
@@ -29,7 +29,7 @@ class WidgetFluidGauge(val rect: Rect, overlay: TextureLocation, dslot: DataSlot
}
}
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)
}
}
@@ -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)
}
}
@@ -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()
}
@@ -18,10 +18,10 @@ 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() {
override def draw(mouse: Point) {
Minecraft.getMinecraft.renderEngine.bindTexture(texture.resource)
val fill = (dslot.stored / dslot.capacity * rect.h).round
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))
}
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += formater.format(dslot.stored) + "/" + formater.format(dslot.capacity) + " MJ"
@@ -38,6 +38,8 @@ case class ConfigSection(pfx: String = "") extends CfgEntry with Iterable[(Strin
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])