mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 10:51:55 -04:00
computers and robots no longer start when right clicked, instead there's a button in the gui now that allows turning the computer/robot on or off (also useful for rebooting when locked in some interruptible loop); removed the 'power' slot from computer cases
This commit is contained in:
parent
4cb741fb74
commit
d17824e722
BIN
assets/opencomputers/textures/gui/computer.png
Normal file
BIN
assets/opencomputers/textures/gui/computer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
assets/opencomputers/textures/gui/power.png
Normal file
BIN
assets/opencomputers/textures/gui/power.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 332 B |
Binary file not shown.
Before Width: | Height: | Size: 649 B After Width: | Height: | Size: 650 B |
@ -13,6 +13,15 @@ object PacketSender {
|
|||||||
pb.sendToServer()
|
pb.sendToServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def sendComputerPower(t: Computer, power: Boolean) {
|
||||||
|
val pb = new PacketBuilder(PacketType.ComputerPower)
|
||||||
|
|
||||||
|
pb.writeTileEntity(t)
|
||||||
|
pb.writeBoolean(power)
|
||||||
|
|
||||||
|
pb.sendToServer()
|
||||||
|
}
|
||||||
|
|
||||||
def sendComputerStateRequest(t: Computer) {
|
def sendComputerStateRequest(t: Computer) {
|
||||||
val pb = new PacketBuilder(PacketType.ComputerStateRequest)
|
val pb = new PacketBuilder(PacketType.ComputerStateRequest)
|
||||||
|
|
||||||
|
@ -1,12 +1,39 @@
|
|||||||
package li.cil.oc.client.gui
|
package li.cil.oc.client.gui
|
||||||
|
|
||||||
|
import java.util
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
|
import li.cil.oc.client.{PacketSender => ClientPacketSender}
|
||||||
import li.cil.oc.common.container
|
import li.cil.oc.common.container
|
||||||
import li.cil.oc.common.tileentity
|
import li.cil.oc.common.tileentity
|
||||||
|
import net.minecraft.client.gui.GuiButton
|
||||||
import net.minecraft.entity.player.InventoryPlayer
|
import net.minecraft.entity.player.InventoryPlayer
|
||||||
import net.minecraft.util.StatCollector
|
import net.minecraft.util.{ResourceLocation, StatCollector}
|
||||||
|
|
||||||
class Case(playerInventory: InventoryPlayer, val computer: tileentity.Case) extends DynamicGuiContainer(new container.Case(playerInventory, computer)) {
|
class Case(playerInventory: InventoryPlayer, val computer: tileentity.Case) extends DynamicGuiContainer(new container.Case(playerInventory, computer)) {
|
||||||
|
protected val computerBackground = new ResourceLocation(Settings.resourceDomain, "textures/gui/computer.png")
|
||||||
|
protected val powerIcon = new ResourceLocation(Settings.resourceDomain, "textures/gui/power.png")
|
||||||
|
|
||||||
|
protected var powerButton: ImageButton = _
|
||||||
|
|
||||||
|
def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T])
|
||||||
|
|
||||||
|
protected override def actionPerformed(button: GuiButton) {
|
||||||
|
if (button.id == 0) {
|
||||||
|
ClientPacketSender.sendComputerPower(computer, !computer.isRunning)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) {
|
||||||
|
powerButton.toggled = computer.isRunning
|
||||||
|
super.drawScreen(mouseX, mouseY, dt)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def initGui() {
|
||||||
|
super.initGui()
|
||||||
|
powerButton = new ImageButton(0, guiLeft + 70, guiTop + 33, 18, 18, powerIcon)
|
||||||
|
add(buttonList, powerButton)
|
||||||
|
}
|
||||||
|
|
||||||
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = {
|
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = {
|
||||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY)
|
super.drawGuiContainerForegroundLayer(mouseX, mouseY)
|
||||||
fontRenderer.drawString(
|
fontRenderer.drawString(
|
||||||
@ -14,5 +41,11 @@ class Case(playerInventory: InventoryPlayer, val computer: tileentity.Case) exte
|
|||||||
8, 6, 0x404040)
|
8, 6, 0x404040)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
|
||||||
|
super.drawGuiContainerBackgroundLayer(dt, mouseX, mouseY)
|
||||||
|
mc.renderEngine.bindTexture(computerBackground)
|
||||||
|
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
|
||||||
|
}
|
||||||
|
|
||||||
override def doesGuiPauseGame = false
|
override def doesGuiPauseGame = false
|
||||||
}
|
}
|
40
li/cil/oc/client/gui/ImageButton.scala
Normal file
40
li/cil/oc/client/gui/ImageButton.scala
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package li.cil.oc.client.gui
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.{SideOnly, Side}
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
|
import net.minecraft.client.gui.GuiButton
|
||||||
|
import net.minecraft.client.renderer.Tessellator
|
||||||
|
import net.minecraft.util.ResourceLocation
|
||||||
|
import org.lwjgl.opengl.GL11
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
class ImageButton(id: Int, x: Int, y: Int, w: Int, h: Int, val image: ResourceLocation) extends GuiButton(id, x, y, w, h, null) {
|
||||||
|
|
||||||
|
var toggled = false
|
||||||
|
|
||||||
|
override def drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) {
|
||||||
|
if (drawButton) {
|
||||||
|
mc.renderEngine.bindTexture(image)
|
||||||
|
GL11.glColor4f(1, 1, 1, 1)
|
||||||
|
field_82253_i = mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height
|
||||||
|
|
||||||
|
val x0 = xPosition
|
||||||
|
val x1 = xPosition + width
|
||||||
|
val y0 = yPosition
|
||||||
|
val y1 = yPosition + height
|
||||||
|
|
||||||
|
val u0 = if (toggled) 0.5 else 0
|
||||||
|
val u1 = u0 + 0.5
|
||||||
|
val v0 = if (getHoverState(field_82253_i) == 2) 0.5 else 0
|
||||||
|
val v1 = v0 + 0.5
|
||||||
|
|
||||||
|
val t = Tessellator.instance
|
||||||
|
t.startDrawingQuads()
|
||||||
|
t.addVertexWithUV(x0, y1, zLevel, u0, v1)
|
||||||
|
t.addVertexWithUV(x1, y1, zLevel, u1, v1)
|
||||||
|
t.addVertexWithUV(x1, y0, zLevel, u1, v0)
|
||||||
|
t.addVertexWithUV(x0, y0, zLevel, u0, v0)
|
||||||
|
t.draw()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,15 @@
|
|||||||
package li.cil.oc.client.gui
|
package li.cil.oc.client.gui
|
||||||
|
|
||||||
|
import java.util
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.client.renderer.MonospaceFontRenderer
|
import li.cil.oc.client.renderer.MonospaceFontRenderer
|
||||||
import li.cil.oc.client.renderer.gui.BufferRenderer
|
import li.cil.oc.client.renderer.gui.BufferRenderer
|
||||||
|
import li.cil.oc.client.{PacketSender => ClientPacketSender}
|
||||||
import li.cil.oc.common.container
|
import li.cil.oc.common.container
|
||||||
import li.cil.oc.common.tileentity
|
import li.cil.oc.common.tileentity
|
||||||
import li.cil.oc.util.RenderState
|
import li.cil.oc.util.RenderState
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
|
import net.minecraft.client.gui.GuiButton
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer
|
import net.minecraft.client.gui.inventory.GuiContainer
|
||||||
import net.minecraft.client.renderer.Tessellator
|
import net.minecraft.client.renderer.Tessellator
|
||||||
import net.minecraft.entity.player.InventoryPlayer
|
import net.minecraft.entity.player.InventoryPlayer
|
||||||
@ -19,9 +22,12 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
|
|||||||
xSize = 256
|
xSize = 256
|
||||||
ySize = 242
|
ySize = 242
|
||||||
|
|
||||||
private val background = new ResourceLocation(Settings.resourceDomain, "textures/gui/robot.png")
|
private val robotBackground = new ResourceLocation(Settings.resourceDomain, "textures/gui/robot.png")
|
||||||
|
protected val powerIcon = new ResourceLocation(Settings.resourceDomain, "textures/gui/power.png")
|
||||||
private val selection = new ResourceLocation(Settings.resourceDomain, "textures/gui/robot_selection.png")
|
private val selection = new ResourceLocation(Settings.resourceDomain, "textures/gui/robot_selection.png")
|
||||||
|
|
||||||
|
protected var powerButton: ImageButton = _
|
||||||
|
|
||||||
protected val buffer = robot.buffer
|
protected val buffer = robot.buffer
|
||||||
|
|
||||||
private val bufferWidth = 242.0
|
private val bufferWidth = 242.0
|
||||||
@ -31,16 +37,35 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
|
|||||||
private val inventoryX = 176
|
private val inventoryX = 176
|
||||||
private val inventoryY = 140
|
private val inventoryY = 140
|
||||||
|
|
||||||
private val powerX = 8
|
private val powerX = 28
|
||||||
private val powerY = 142
|
private val powerY = 142
|
||||||
|
|
||||||
private val powerWidth = 160
|
private val powerWidth = 140
|
||||||
private val powerHeight = 12
|
private val powerHeight = 12
|
||||||
|
|
||||||
private val selectionSize = 20
|
private val selectionSize = 20
|
||||||
private val selectionsStates = 17
|
private val selectionsStates = 17
|
||||||
private val selectionStepV = 1 / selectionsStates.toDouble
|
private val selectionStepV = 1 / selectionsStates.toDouble
|
||||||
|
|
||||||
|
def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T])
|
||||||
|
|
||||||
|
protected override def actionPerformed(button: GuiButton) {
|
||||||
|
if (button.id == 0) {
|
||||||
|
ClientPacketSender.sendComputerPower(robot, !robot.isRunning)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) {
|
||||||
|
powerButton.toggled = robot.isRunning
|
||||||
|
super.drawScreen(mouseX, mouseY, dt)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def initGui() {
|
||||||
|
super.initGui()
|
||||||
|
powerButton = new ImageButton(0, guiLeft + 7, guiTop + 139, 18, 18, powerIcon)
|
||||||
|
add(buttonList, powerButton)
|
||||||
|
}
|
||||||
|
|
||||||
override def drawSlotInventory(slot: Slot) {
|
override def drawSlotInventory(slot: Slot) {
|
||||||
RenderState.makeItBlend()
|
RenderState.makeItBlend()
|
||||||
super.drawSlotInventory(slot)
|
super.drawSlotInventory(slot)
|
||||||
@ -69,7 +94,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
|
|||||||
}
|
}
|
||||||
|
|
||||||
override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
|
override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
|
||||||
mc.renderEngine.bindTexture(background)
|
mc.renderEngine.bindTexture(robotBackground)
|
||||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
|
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
|
||||||
drawPowerLevel()
|
drawPowerLevel()
|
||||||
drawSelection()
|
drawSelection()
|
||||||
|
@ -5,6 +5,8 @@ object PacketType extends Enumeration {
|
|||||||
ChargerStateRequest,
|
ChargerStateRequest,
|
||||||
ChargerStateResponse,
|
ChargerStateResponse,
|
||||||
|
|
||||||
|
ComputerPower,
|
||||||
|
|
||||||
ComputerStateRequest,
|
ComputerStateRequest,
|
||||||
ComputerStateResponse,
|
ComputerStateResponse,
|
||||||
|
|
||||||
|
@ -63,7 +63,6 @@ class Case(val parent: SimpleDelegator) extends Computer with SimpleDelegate {
|
|||||||
|
|
||||||
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
|
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
|
||||||
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
|
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
|
||||||
super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ)
|
|
||||||
if (!player.isSneaking) {
|
if (!player.isSneaking) {
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
player.openGui(OpenComputers, GuiType.Case.id, world, x, y, z)
|
player.openGui(OpenComputers, GuiType.Case.id, world, x, y, z)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package li.cil.oc.common.block
|
package li.cil.oc.common.block
|
||||||
|
|
||||||
import li.cil.oc.common.tileentity
|
import li.cil.oc.common.tileentity
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
|
||||||
import net.minecraft.world.{World, IBlockAccess}
|
import net.minecraft.world.{World, IBlockAccess}
|
||||||
import net.minecraftforge.common.ForgeDirection
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
|
||||||
@ -23,19 +22,6 @@ abstract class Computer extends Delegate {
|
|||||||
case _ => super.isProvidingWeakPower(world, x, y, z, side)
|
case _ => super.isProvidingWeakPower(world, x, y, z, side)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
|
|
||||||
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
|
|
||||||
if (!player.isSneaking) {
|
|
||||||
if (!world.isRemote) {
|
|
||||||
world.getBlockTileEntity(x, y, z) match {
|
|
||||||
case t: tileentity.Computer if !t.computer.isPaused && t.computer.canInteract(player.getCommandSenderName) => t.computer.start()
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ)
|
|
||||||
}
|
|
||||||
|
|
||||||
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) =
|
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) =
|
||||||
world.getBlockTileEntity(x, y, z) match {
|
world.getBlockTileEntity(x, y, z) match {
|
||||||
case computer: tileentity.Computer => computer.checkRedstoneInputChanged()
|
case computer: tileentity.Computer => computer.checkRedstoneInputChanged()
|
||||||
|
@ -71,7 +71,6 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele
|
|||||||
|
|
||||||
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
|
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
|
||||||
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
|
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
|
||||||
super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ)
|
|
||||||
if (!player.isSneaking) {
|
if (!player.isSneaking) {
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
player.openGui(OpenComputers, GuiType.Robot.id, world, x, y, z)
|
player.openGui(OpenComputers, GuiType.Robot.id, world, x, y, z)
|
||||||
|
@ -5,20 +5,20 @@ import li.cil.oc.common.tileentity
|
|||||||
import net.minecraft.entity.player.{EntityPlayer, InventoryPlayer}
|
import net.minecraft.entity.player.{EntityPlayer, InventoryPlayer}
|
||||||
|
|
||||||
class Case(playerInventory: InventoryPlayer, `case`: tileentity.Case) extends Player(playerInventory, `case`) {
|
class Case(playerInventory: InventoryPlayer, `case`: tileentity.Case) extends Player(playerInventory, `case`) {
|
||||||
addSlotToContainer(58, 17, api.driver.Slot.Power)
|
|
||||||
|
|
||||||
for (i <- 0 to 2) {
|
for (i <- 0 to 2) {
|
||||||
addSlotToContainer(80, 17 + i * slotSize, api.driver.Slot.Card)
|
addSlotToContainer(98, 16 + i * slotSize, api.driver.Slot.Card)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i <- 0 to 1) {
|
for (i <- 0 to 1) {
|
||||||
addSlotToContainer(102, 17 + i * slotSize, api.driver.Slot.Memory)
|
addSlotToContainer(120, 16 + i * slotSize, api.driver.Slot.Memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i <- 0 to 1) {
|
for (i <- 0 to 1) {
|
||||||
addSlotToContainer(124, 17 + i * slotSize, api.driver.Slot.HardDiskDrive)
|
addSlotToContainer(142, 16 + i * slotSize, api.driver.Slot.HardDiskDrive)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addSlotToContainer(142, 16 + 2 * slotSize, api.driver.Slot.Disk)
|
||||||
|
|
||||||
// Show the player's inventory.
|
// Show the player's inventory.
|
||||||
addPlayerInventorySlots(8, 84)
|
addPlayerInventorySlots(8, 84)
|
||||||
|
|
||||||
|
@ -16,10 +16,10 @@ class Case(isRemote: Boolean) extends Computer(isRemote) {
|
|||||||
|
|
||||||
def isItemValidForSlot(slot: Int, stack: ItemStack) = (slot, Registry.driverFor(stack)) match {
|
def isItemValidForSlot(slot: Int, stack: ItemStack) = (slot, Registry.driverFor(stack)) match {
|
||||||
case (_, None) => false // Invalid item.
|
case (_, None) => false // Invalid item.
|
||||||
case (0, Some(driver)) => driver.slot(stack) == Slot.Power
|
case (0 | 1 | 2, Some(driver)) => driver.slot(stack) == Slot.Card
|
||||||
case (1 | 2 | 3, Some(driver)) => driver.slot(stack) == Slot.Card
|
case (3 | 4, Some(driver)) => driver.slot(stack) == Slot.Memory
|
||||||
case (4 | 5, Some(driver)) => driver.slot(stack) == Slot.Memory
|
case (5 | 6, Some(driver)) => driver.slot(stack) == Slot.HardDiskDrive
|
||||||
case (6 | 7, Some(driver)) => driver.slot(stack) == Slot.HardDiskDrive
|
case (7, Some(driver)) => driver.slot(stack) == Slot.Disk
|
||||||
case _ => false // Invalid slot.
|
case _ => false // Invalid slot.
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import cpw.mods.fml.common.network.Player
|
|||||||
import li.cil.oc.common.PacketType
|
import li.cil.oc.common.PacketType
|
||||||
import li.cil.oc.common.tileentity._
|
import li.cil.oc.common.tileentity._
|
||||||
import li.cil.oc.common.{PacketHandler => CommonPacketHandler}
|
import li.cil.oc.common.{PacketHandler => CommonPacketHandler}
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraftforge.common.DimensionManager
|
import net.minecraftforge.common.DimensionManager
|
||||||
import scala.Some
|
import scala.Some
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ class PacketHandler extends CommonPacketHandler {
|
|||||||
def dispatch(p: PacketParser) =
|
def dispatch(p: PacketParser) =
|
||||||
p.packetType match {
|
p.packetType match {
|
||||||
case PacketType.ChargerStateRequest => onChargerStateRequest(p)
|
case PacketType.ChargerStateRequest => onChargerStateRequest(p)
|
||||||
|
case PacketType.ComputerPower => onComputerPower(p)
|
||||||
case PacketType.ComputerStateRequest => onComputerStateRequest(p)
|
case PacketType.ComputerStateRequest => onComputerStateRequest(p)
|
||||||
case PacketType.PowerStateRequest => onPowerStateRequest(p)
|
case PacketType.PowerStateRequest => onPowerStateRequest(p)
|
||||||
case PacketType.RedstoneStateRequest => onRedstoneStateRequest(p)
|
case PacketType.RedstoneStateRequest => onRedstoneStateRequest(p)
|
||||||
@ -27,8 +29,21 @@ class PacketHandler extends CommonPacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def onChargerStateRequest(p: PacketParser) =
|
def onChargerStateRequest(p: PacketParser) =
|
||||||
p.readTileEntity[Charger]() match {
|
p.readTileEntity[Computer]() match {
|
||||||
case Some(t) => PacketSender.sendChargerState(t, Option(p.player))
|
case Some(t) => PacketSender.sendComputerState(t, Option(p.player))
|
||||||
|
case _ => // Invalid packet.
|
||||||
|
}
|
||||||
|
|
||||||
|
def onComputerPower(p: PacketParser) =
|
||||||
|
p.readTileEntity[Computer]() match {
|
||||||
|
case Some(t) => p.player match {
|
||||||
|
case player: EntityPlayer if t.computer.canInteract(player.getCommandSenderName) =>
|
||||||
|
if (p.readBoolean()) {
|
||||||
|
if (!t.computer.isPaused) t.computer.start()
|
||||||
|
}
|
||||||
|
else t.computer.stop()
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
case _ => // Invalid packet.
|
case _ => // Invalid packet.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user