Added RS control to the apiary, fixed sync after world load

This commit is contained in:
bdew committed 2014-03-24 12:17:31 +02:00
1 parent 9363aac764
commit f3697ea35f
14 files changed
+184 -14

No files matched your search

@@ -110,6 +110,7 @@ gendustry.label.mod.temperature=* Temperature
gendustry.label.mod.humidity=* Humidity
gendustry.error.power=Not enough power
gendustry.error.disabled=Disabled by settings
gendustry.label.sample.rootBees=Taken from a Bee
gendustry.label.sample.rootTrees=Taken from a Sapling
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.
+20 -2
View File
@@ -11,13 +11,31 @@ package net.bdew.gendustry.gui
import net.bdew.lib.gui._
import net.bdew.gendustry.Gendustry
import net.bdew.gendustry.gui.rscontrol.RSMode
object Textures {
val texture = new ScaledResourceLocation(Gendustry.modId, "textures/gui/widgets.png", 256)
val tankOverlay = Texture(texture, 16, 0, 16, 58)
val powerFill = Texture(texture, 0, 0, 16, 58)
val texturePowerError = Texture(texture, 32, 0, 16, 16)
val slotSelect = Texture(texture, 48, 0, 18, 18)
val slotSelect = Texture(texture, 64, 0, 18, 18)
def greenProgress(width: Float) = Texture(texture, 136 - width, 58, width, 15)
def whiteProgress(width: Float) = Texture(texture, 136 - width, 73, width, 15)
object errors {
val noPower = Texture(texture, 32, 0, 16, 16)
val disabled = Texture(texture, 48, 0, 16, 16)
}
object button16 {
val base = Texture(texture, 32, 18, 16, 16)
val hover = Texture(texture, 48, 18, 16, 16)
val iconRSMode = Map(
RSMode.ALWAYS -> Texture(texture, 65, 35, 14, 14),
RSMode.NEVER -> Texture(texture, 81, 35, 14, 14),
RSMode.RS_ON -> Texture(texture, 49, 35, 14, 14),
RSMode.RS_OFF -> Texture(texture, 33, 35, 14, 14)
)
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/gendustry
*
* 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/gendustry/master/MMPL-1.0.txt
*/
package net.bdew.gendustry.gui.rscontrol
import net.minecraft.entity.player.EntityPlayer
import net.bdew.lib.data.base.ContainerDataSlots
trait ContainerRSControllable extends ContainerDataSlots {
val dataSource: TileRSContollable
/**
* This implementation is piggybacking on vanilla Packet102WindowClick
* This is the fake slot number, and shouldn't be used by anything else
*/
final val RSMODE_SLOT_NUM = 1000
override def slotClick(slotnum: Int, button: Int, modifiers: Int, player: EntityPlayer) =
if (slotnum == RSMODE_SLOT_NUM) {
dataSource.rsmode := RSMode(button)
null
} else {
super.slotClick(slotnum, button, modifiers, player)
}
}
@@ -0,0 +1,19 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/gendustry
*
* 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/gendustry/master/MMPL-1.0.txt
*/
package net.bdew.gendustry.gui.rscontrol
import net.bdew.lib.data.base.{UpdateKind, DataSlotVal, TileDataSlots}
import net.minecraft.nbt.NBTTagCompound
case class DataslotRSMode(name: String, parent: TileDataSlots) extends DataSlotVal[RSMode.Value] {
var cval: RSMode.Value = RSMode.ALWAYS
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setByte(name, cval.id.toByte)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = RSMode(t.getByte(name))
}
@@ -0,0 +1,26 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/gendustry
*
* 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/gendustry/master/MMPL-1.0.txt
*/
package net.bdew.gendustry.gui.rscontrol
object RSMode extends Enumeration {
val ALWAYS = Value(0, "ALWAYS")
val RS_ON = Value(1, "RS_ON")
val RS_OFF = Value(2, "RS_OFF")
val NEVER = Value(3, "NEVER")
final val RSMODE_SLOT_NUM = 1000
val next = Map(
RSMode.ALWAYS -> RSMode.RS_ON,
RSMode.RS_ON -> RSMode.RS_OFF,
RSMode.RS_OFF -> RSMode.NEVER,
RSMode.NEVER -> RSMode.ALWAYS
)
}
@@ -0,0 +1,23 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/gendustry
*
* 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/gendustry/master/MMPL-1.0.txt
*/
package net.bdew.gendustry.gui.rscontrol
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots}
trait TileRSContollable extends TileDataSlots {
val rsmode = DataslotRSMode("rsmode", this).setUpdate(UpdateKind.SAVE, UpdateKind.GUI, UpdateKind.WORLD)
def canWork = {
val powered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)
(rsmode :== RSMode.ALWAYS) ||
((rsmode :== RSMode.RS_ON) && powered) ||
((rsmode :== RSMode.RS_OFF) && !powered)
}
}
@@ -0,0 +1,42 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/gendustry
*
* 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/gendustry/master/MMPL-1.0.txt
*/
package net.bdew.gendustry.gui.rscontrol
import net.bdew.lib.gui.{Texture, Rect, Point}
import net.bdew.lib.gui.widgets.Widget
import net.bdew.gendustry.gui.Textures
import scala.collection.mutable
import net.bdew.lib.{Misc, Client}
class WidgetRSModeButton(p: Point, te: TileRSContollable, container: ContainerRSControllable) extends Widget {
val rect = new Rect(p, 16, 16)
val iconRect = new Rect(p +(1, 1), 14, 14)
var icon: Texture = null
var hover: String = null
override def draw(mouse: Point) {
if (rect.contains(mouse))
parent.drawTexture(rect, Textures.button16.hover)
else
parent.drawTexture(rect, Textures.button16.base)
parent.drawTexture(iconRect, Textures.button16.iconRSMode(te.rsmode))
}
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
tip += Misc.toLocal("gendustry.rsmode." + te.rsmode.cval.toString.toLowerCase)
}
override def mouseClicked(p: Point, button: Int) {
Client.minecraft.sndManager.playSoundFX("random.click", 1.0F, 1.0F)
Client.minecraft.playerController.windowClick(container.windowId, container.RSMODE_SLOT_NUM, RSMode.next(te.rsmode).id, 0, Client.player)
}
}
@@ -16,8 +16,9 @@ import net.minecraft.inventory.{IInventory, Slot}
import net.bdew.lib.items.ItemUtils
import net.bdew.lib.data.base.ContainerDataSlots
import net.bdew.lib.Misc
import net.bdew.gendustry.gui.rscontrol.ContainerRSControllable
class ContainerApiary(val te: TileApiary, player: EntityPlayer) extends BaseContainer(te) with ContainerDataSlots {
class ContainerApiary(val te: TileApiary, player: EntityPlayer) extends BaseContainer(te) with ContainerDataSlots with ContainerRSControllable {
lazy val dataSource = te
addSlotToContainer(new SlotValidating(te, 0, 39, 29))
@@ -11,12 +11,13 @@ package net.bdew.gendustry.machines.apiary
import net.bdew.gendustry.Gendustry
import net.minecraft.entity.player.EntityPlayer
import net.bdew.lib.gui.{Texture, Color, Rect, BaseScreen}
import net.bdew.lib.gui.{Texture, Color, Rect, BaseScreen, Point}
import net.bdew.lib.gui.widgets.WidgetLabel
import net.bdew.gendustry.gui.{HintIcons, WidgetPowerCustom, Textures}
import net.bdew.lib.Misc
import net.bdew.gendustry.gui.rscontrol.WidgetRSModeButton
class GuiApiary(val te: TileApiary, player: EntityPlayer) extends BaseScreen(new ContainerApiary(te, player), 176, 166) {
class GuiApiary(val te: TileApiary, player: EntityPlayer, cont: ContainerApiary) extends BaseScreen(cont, 176, 166) {
val background = Texture(Gendustry.modId, "textures/gui/apiary.png", rect)
override def initGui() {
super.initGui()
@@ -24,6 +25,7 @@ class GuiApiary(val te: TileApiary, player: EntityPlayer) extends BaseScreen(new
widgets.add(new WidgetPowerCustom(new Rect(8, 19, 16, 58), Textures.powerFill, te.power))
widgets.add(new WidgetApiaryProgress(new Rect(69, 22, 36, 15), te.guiBreeding, te.guiProgress))
widgets.add(new WidgetLabel(Misc.toLocal("tile.gendustry.apiary.name"), 8, 6, Color.darkgray))
widgets.add(new WidgetRSModeButton(Point(137, 5), te, cont))
te.slots.upgrades.foreach(inventorySlots.getSlot(_).setBackgroundIcon(HintIcons.upgrade))
inventorySlots.getSlotFromInventory(te, te.slots.drone).setBackgroundIcon(HintIcons.drone)
@@ -21,6 +21,6 @@ class MachineApiary extends Machine("IndustrialApiary", new BlockApiary(_)) with
lazy val baseMjPerTick = tuning.getInt("BaseMjPerTick")
@SideOnly(Side.CLIENT)
def getGui(te: TileApiary, player: EntityPlayer) = new GuiApiary(te, player)
def getGui(te: TileApiary, player: EntityPlayer) = new GuiApiary(te, player, new ContainerApiary(te, player))
def getContainer(te: TileApiary, player: EntityPlayer) = new ContainerApiary(te, player)
}
@@ -32,6 +32,7 @@ import net.bdew.lib.data.DataSlotBoolean
import net.bdew.gendustry.power.TilePowered
import net.bdew.lib.power.DataSlotPower
import net.bdew.gendustry.compat.triggers.ForestryErrorSource
import net.bdew.gendustry.gui.rscontrol.TileRSContollable
class TileApiary extends TileExtended
with TileDataSlots
@@ -40,6 +41,7 @@ with SidedInventory
with BreakableInventoryTile
with TilePowered
with ForestryErrorSource
with TileRSContollable
with IBeeHousing {
object slots {
@@ -71,7 +73,7 @@ with IBeeHousing {
persistLoad.listen(x => {
updateModifiers()
queen := getStackInSlot(slots.drone)
queen := getStackInSlot(slots.queen)
})
def updateModifiers() {
@@ -108,7 +110,9 @@ with IBeeHousing {
serverTick.listen(() => {
movePrincess = false
if (power.stored >= cfg.baseMjPerTick * mods.energy) {
if (!canWork) {
setErrorState(-2)
} else if (power.stored >= cfg.baseMjPerTick * mods.energy) {
logic.update()
if ((logic.getQueen != null || logic.getBreedingTime > 0) && (errorState :== 1))
power.extract(cfg.baseMjPerTick * mods.energy, false)
@@ -21,19 +21,22 @@ class WidgetError(x: Int, y: Int, apiary: TileApiary) extends Widget {
override def draw(mouse: Point) {
val err = apiary.errorState.cval
if (err == -1) {
parent.drawTexture(rect, Textures.texturePowerError)
parent.drawTexture(rect, Textures.errors.noPower)
} else if (err == -2) {
parent.drawTexture(rect, Textures.errors.disabled)
} else if (ErrorCodes.isValid(err)) {
parent.drawTexture(rect, ErrorCodes.getIcon(err))
} else {
if (ErrorCodes.isValid(err)) {
parent.drawTexture(rect, ErrorCodes.getIcon(err))
} else {
parent.drawTexture(rect, ErrorCodes.getIcon(0))
}
parent.drawTexture(rect, ErrorCodes.getIcon(0))
}
}
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
val err = apiary.errorState.cval
if (err == -1) {
tip += Misc.toLocal(Gendustry.modId + ".error.power")
} else if (err == -2) {
tip += Misc.toLocal(Gendustry.modId + ".error.disabled")
} else if (ErrorCodes.isValid(err)) {
tip += ErrorCodes.getDescription(err)
} else {