diff --git a/src/main/resources/assets/opencomputers/lang/de_DE.lang b/src/main/resources/assets/opencomputers/lang/de_DE.lang index a285ffcc5..999e05b04 100644 --- a/src/main/resources/assets/opencomputers/lang/de_DE.lang +++ b/src/main/resources/assets/opencomputers/lang/de_DE.lang @@ -73,8 +73,16 @@ oc:item.Server2.name=Server (Stufe 3) oc:item.Terminal.name=Fernbedienung oc:item.Transistor.name=Transistor oc:item.UpgradeAngel.name=Schwebe-Upgrade +oc:item.UpgradeContainerCard0.name=Karten-Behälter (Stufe 1) +oc:item.UpgradeContainerCard1.name=Karten-Behälter (Stufe 2) +oc:item.UpgradeContainerCard2.name=Karten-Behälter (Stufe 3) +oc:item.UpgradeContainerUpgrade0.name=Upgrade-Behälter (Stufe 1) +oc:item.UpgradeContainerUpgrade1.name=Upgrade-Behälter (Stufe 2) +oc:item.UpgradeContainerUpgrade2.name=Upgrade-Behälter (Stufe 3) oc:item.UpgradeCrafting.name=Fertigungs-Upgrade +oc:item.UpgradeExperience.name=Erfahrungs-Upgrade oc:item.UpgradeGenerator.name=Generator-Upgrade +oc:item.UpgradeInventory.name=Inventar-Upgrade oc:item.UpgradeNavigation.name=Navigationsupgrade oc:item.UpgradeSign.name=Schild-I/O-Upgrade oc:item.UpgradeSolarGenerator.name=Solargenerator-Upgrade @@ -189,8 +197,12 @@ oc:tooltip.Terminal=Erlaubt es, einen Server aus der Ferne zu steuern, so lange oc:tooltip.TooLong=Halte [§f%s§7] gedrückt für mehr Infos. oc:tooltip.Transistor=Elementarer Baustein der meisten Computerkomponenten. Nicht zu verwechseln mit Steinelementaren. oc:tooltip.UpgradeAngel=Erlaubt es Robotern, Blöcke in die Luft zu setzen, selbst wenn kein Referenzblock daneben existiert. +oc:tooltip.UpgradeContainerCard=Dieses Behälter-Upgrade erlaubt es eine Karte in einem bereits zusammengebauten Roboter zu installieren und wieder zu entfernen. [nl] Maximale Stufe: §f%s§7. +oc:tooltip.UpgradeContainerUpgrade=Dieses Behälter-Upgrade erlaubt es ein Upgrade in einem bereits zusammengebauten Roboter zu installieren und wieder zu entfernen. [nl] Maximale Stufe: §f%s§7. oc:tooltip.UpgradeCrafting=Ermöglicht Robotern, in dem oberen linken Bereich ihres Inventars Dinge zu fertigen. Gegenstände müssen so angeordnet sein, wie sie es in einer Werkbank wären. +oc:tooltip.UpgradeExperience=Dieses Upgrade erlaubt es Robotern durch verschiedene Aktionen Erfahrung zu sammeln. Je mehr Erfahrung ein Roboter hat, desto mehr Energie kann er speichern, desto schneller kann er Blöcke abbauen und desto effizienter kann er mit Werkzeugen umgehen. oc:tooltip.UpgradeGenerator=Kann verwendet werden, um unterwegs Energie aus Brennstoffen zu erzeugen. Verbraucht Gegenstände über einen ihrem Brennwert gemäßen Zeitraum.[nl] §fEffizienz§7: §a%s%%§7 +oc:tooltip.UpgradeInventory=Dieses Upgrade gibt Robotern ein internes Inventar. Ohne ein solches Upgrade können Roboter keine Gegenstände verwahren. oc:tooltip.UpgradeNavigation=Erlaubt es Robotern, ihre Position und Ausrichtung zu bestimmen. Die Position ist relativ zur Mitte der Karte, die in diesem Upgrade verbaut wurde. oc:tooltip.UpgradeSign=Erlaubt das Lesen und Schreiben von Text auf Schildern. oc:tooltip.UpgradeSolarGenerator=Kann verwendet werden, um unterwegs Energie aus Sonnenlicht zu generieren. Benötigt eine ungehinderte Sicht zum Himmel über dem Roboter. Generiert Energie mit %s%% der Geschwindigkeit eines Stirlingmotors. diff --git a/src/main/resources/assets/opencomputers/lang/en_US.lang b/src/main/resources/assets/opencomputers/lang/en_US.lang index 72dfcf3f3..1f4a1a56f 100644 --- a/src/main/resources/assets/opencomputers/lang/en_US.lang +++ b/src/main/resources/assets/opencomputers/lang/en_US.lang @@ -73,8 +73,16 @@ oc:item.Server2.name=Server (Tier 3) oc:item.Terminal.name=Remote Terminal oc:item.Transistor.name=Transistor oc:item.UpgradeAngel.name=Angel Upgrade +oc:item.UpgradeContainerCard0.name=Card Container (Tier 1) +oc:item.UpgradeContainerCard1.name=Card Container (Tier 2) +oc:item.UpgradeContainerCard2.name=Card Container (Tier 3) +oc:item.UpgradeContainerUpgrade0.name=Upgrade Container (Tier 1) +oc:item.UpgradeContainerUpgrade1.name=Upgrade Container (Tier 2) +oc:item.UpgradeContainerUpgrade2.name=Upgrade Container (Tier 3) oc:item.UpgradeCrafting.name=Crafting Upgrade +oc:item.UpgradeExperience.name=Experience Upgrade oc:item.UpgradeGenerator.name=Generator Upgrade +oc:item.UpgradeInventory.name=Inventory Upgrade oc:item.UpgradeNavigation.name=Navigation Upgrade oc:item.UpgradeSign.name=Sign I/O Upgrade oc:item.UpgradeSolarGenerator.name=Solar Generator Upgrade @@ -189,8 +197,12 @@ oc:tooltip.Terminal=Allows controlling a server remotely, as long as you are in oc:tooltip.TooLong=Hold [§f%s§7] for a detailed tooltip. oc:tooltip.Transistor=A basic element in most other computer parts. It's a bit twisted, but it does the job. oc:tooltip.UpgradeAngel=Allows robots to place blocks in thin air, even if there is no point of reference. +oc:tooltip.UpgradeContainerCard=This container upgrade allows dynamically installing and removing a card from an assembled robot. [nl] Maximum Tier: §f%s§7. +oc:tooltip.UpgradeContainerUpgrade=This container upgrade allows dynamically installing and removing another upgrade from an assembled robot. [nl] Maximum Tier: §f%s§7. oc:tooltip.UpgradeCrafting=Enables robots to use the top left area of their inventory for crafting objects. Items have to be aligned as they would be in a crafting table. +oc:tooltip.UpgradeExperience=This upgrade allows robots to accumulate experience by performing various operations. The more experience they have, the more energy they can store, the faster they can harvest blocks and the more efficiently they can use tools. oc:tooltip.UpgradeGenerator=Can be used to generate energy from fuel on the go. Burns items to generate energy over time, based on their fuel value.[nl] §fEfficiency§7: §a%s%%§7 +oc:tooltip.UpgradeInventory=This upgrade provides inventory space to the robot. Without one of these, robots will not be able to store items internally. oc:tooltip.UpgradeNavigation=Can be used to determine the position and orientation of the robot. The position is relative to the center of the map that was used to craft this upgrade. oc:tooltip.UpgradeSign=Allows reading text on and writing text to signs. oc:tooltip.UpgradeSolarGenerator=Can be used to generate energy from sunlight on the go. Requires a clear line of sight to the sky above the robot. Generates energy at %s%% of the speed of a Stirling Engine. diff --git a/src/main/scala/li/cil/oc/client/PacketSender.scala b/src/main/scala/li/cil/oc/client/PacketSender.scala index 44c670795..d77b29114 100644 --- a/src/main/scala/li/cil/oc/client/PacketSender.scala +++ b/src/main/scala/li/cil/oc/client/PacketSender.scala @@ -97,6 +97,11 @@ object PacketSender { } def sendRobotAssemblerStart(t: RobotAssembler) { + val pb = new PacketBuilder(PacketType.RobotAssemblerStart) + + pb.writeTileEntity(t) + + pb.sendToServer() } def sendRobotStateRequest(dimension: Int, x: Int, y: Int, z: Int) { diff --git a/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala b/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala index 91ace13ce..cc0c6bd78 100644 --- a/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala +++ b/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala @@ -19,13 +19,14 @@ class RobotAssembler(playerInventory: InventoryPlayer, val assembler: tileentity def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T]) protected override def actionPerformed(button: GuiButton) { - if (button.id == 0 && !assembler.isAssembling) { + if (button.id == 0 && !assembler.isAssembling && assembler.complexity < assembler.maxComplexity) { ClientPacketSender.sendRobotAssemblerStart(assembler) } } override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) { - runButton.toggled = assembler.isAssembling + runButton.enabled = assembler.complexity < assembler.maxComplexity && !assembler.isAssembling + runButton.toggled = !runButton.enabled super.drawScreen(mouseX, mouseY, dt) } diff --git a/src/main/scala/li/cil/oc/common/InventorySlots.scala b/src/main/scala/li/cil/oc/common/InventorySlots.scala index 971fe713c..169117bb0 100644 --- a/src/main/scala/li/cil/oc/common/InventorySlots.scala +++ b/src/main/scala/li/cil/oc/common/InventorySlots.scala @@ -75,15 +75,15 @@ object InventorySlots { Array( InventorySlot(Slot.None, Tier.None), - InventorySlot(Slot.Upgrade, Tier.Three), - InventorySlot(Slot.Upgrade, Tier.Three), - InventorySlot(Slot.Upgrade, Tier.Three), InventorySlot(Slot.Upgrade, Tier.Two), InventorySlot(Slot.Upgrade, Tier.Two), InventorySlot(Slot.Upgrade, Tier.Two), InventorySlot(Slot.Upgrade, Tier.One), InventorySlot(Slot.Upgrade, Tier.One), InventorySlot(Slot.Upgrade, Tier.One), + InventorySlot(Slot.Upgrade, Tier.None), + InventorySlot(Slot.Upgrade, Tier.None), + InventorySlot(Slot.Upgrade, Tier.None), InventorySlot(Slot.UpgradeContainer, Tier.Three), InventorySlot(Slot.UpgradeContainer, Tier.Two), InventorySlot(Slot.UpgradeContainer, Tier.One), diff --git a/src/main/scala/li/cil/oc/common/PacketType.scala b/src/main/scala/li/cil/oc/common/PacketType.scala index 8ab519100..d4ddc4440 100644 --- a/src/main/scala/li/cil/oc/common/PacketType.scala +++ b/src/main/scala/li/cil/oc/common/PacketType.scala @@ -44,6 +44,7 @@ object PacketType extends Enumeration { MouseScroll, MouseUp, MultiPartPlace, + RobotAssemblerStart, RobotStateRequest, ServerSide, ServerRange = Value diff --git a/src/main/scala/li/cil/oc/common/container/ComponentSlot.scala b/src/main/scala/li/cil/oc/common/container/ComponentSlot.scala index 71c40e4b6..2e8448527 100644 --- a/src/main/scala/li/cil/oc/common/container/ComponentSlot.scala +++ b/src/main/scala/li/cil/oc/common/container/ComponentSlot.scala @@ -1,11 +1,16 @@ package li.cil.oc.common.container import li.cil.oc.api -import net.minecraft.util.Icon -import net.minecraft.inventory.Slot import li.cil.oc.common.InventorySlots.Tier +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.inventory.Slot +import net.minecraft.item.ItemStack +import net.minecraft.util.Icon +import scala.collection.convert.WrapAsScala._ trait ComponentSlot extends Slot { + def container: Player + def slot: api.driver.Slot def tier: Int @@ -13,4 +18,22 @@ trait ComponentSlot extends Slot { def tierIcon: Icon override def func_111238_b() = tier != Tier.None && super.func_111238_b() + + override def onPickupFromSlot(player: EntityPlayer, stack: ItemStack) { + super.onPickupFromSlot(player, stack) + for (slot <- container.inventorySlots) slot match { + case dynamic: ComponentSlot => dynamic.clearIfInvalid(player) + case _ => + } + } + + override def onSlotChanged() { + super.onSlotChanged() + for (slot <- container.inventorySlots) slot match { + case dynamic: ComponentSlot => dynamic.clearIfInvalid(container.playerInventory.player) + case _ => + } + } + + protected def clearIfInvalid(player: EntityPlayer) {} } diff --git a/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala b/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala index 778f0a1c7..076927b46 100644 --- a/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala +++ b/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala @@ -1,12 +1,13 @@ package li.cil.oc.common.container import li.cil.oc.api +import li.cil.oc.client.gui.Icons +import li.cil.oc.common.InventorySlots.{Tier, InventorySlot} +import net.minecraft.entity.player.EntityPlayer import net.minecraft.inventory.{Slot, IInventory} import net.minecraft.item.ItemStack -import li.cil.oc.client.gui.Icons -import li.cil.oc.common.InventorySlots.InventorySlot -class DynamicComponentSlot(inventory: IInventory, index: Int, x: Int, y: Int, val info: Array[Array[InventorySlot]], val tierGetter: () => Int) extends Slot(inventory, index, x, y) with ComponentSlot { +class DynamicComponentSlot(val container: Player, inventory: IInventory, index: Int, x: Int, y: Int, val info: Array[Array[InventorySlot]], val tierGetter: () => Int) extends Slot(inventory, index, x, y) with ComponentSlot { override def tier = { val mainTier = tierGetter() if (mainTier >= 0) info(mainTier)(slotNumber).tier @@ -32,4 +33,14 @@ class DynamicComponentSlot(inventory: IInventory, index: Int, x: Int, y: Int, va override def isItemValid(stack: ItemStack) = { inventory.isItemValidForSlot(index, stack) } + + override protected def clearIfInvalid(player: EntityPlayer) { + if (getHasStack && !isItemValid(getStack)) { + val stack = getStack + putStack(null) + if (!player.inventory.addItemStackToInventory(stack)) { + player.dropPlayerItem(stack) + } + } + } } diff --git a/src/main/scala/li/cil/oc/common/container/Player.scala b/src/main/scala/li/cil/oc/common/container/Player.scala index 0334ba754..c6064214c 100644 --- a/src/main/scala/li/cil/oc/common/container/Player.scala +++ b/src/main/scala/li/cil/oc/common/container/Player.scala @@ -10,7 +10,7 @@ import net.minecraft.inventory.Slot import net.minecraft.item.ItemStack import li.cil.oc.common.InventorySlots.{Tier, InventorySlot} -abstract class Player(protected val playerInventory: InventoryPlayer, val otherInventory: IInventory) extends Container { +abstract class Player(val playerInventory: InventoryPlayer, val otherInventory: IInventory) extends Container { /** Number of player inventory slots to display horizontally. */ protected val playerInventorySizeX = InventoryPlayer.getHotbarSize @@ -100,12 +100,12 @@ abstract class Player(protected val playerInventory: InventoryPlayer, val otherI def addSlotToContainer(x: Int, y: Int, slot: api.driver.Slot = api.driver.Slot.None, tier: Int = Tier.Any) { val index = getInventory.size - addSlotToContainer(new StaticComponentSlot(otherInventory, index, x, y, slot, tier)) + addSlotToContainer(new StaticComponentSlot(this, otherInventory, index, x, y, slot, tier)) } def addSlotToContainer(x: Int, y: Int, info: Array[Array[InventorySlot]], tierGetter: () => Int) { val index = getInventory.size - addSlotToContainer(new DynamicComponentSlot(otherInventory, index, x, y,info, tierGetter)) + addSlotToContainer(new DynamicComponentSlot(this, otherInventory, index, x, y, info, tierGetter)) } /** Render player inventory at the specified coordinates. */ diff --git a/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala b/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala index 8741dc98c..eb61ca8fe 100644 --- a/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala +++ b/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala @@ -5,7 +5,7 @@ import li.cil.oc.client.gui.Icons import net.minecraft.inventory.{IInventory, Slot} import net.minecraft.item.ItemStack -class StaticComponentSlot(inventory: IInventory, index: Int, x: Int, y: Int, val slot: api.driver.Slot, val tier: Int) extends Slot(inventory, index, x, y) with ComponentSlot { +class StaticComponentSlot(val container: Player, inventory: IInventory, index: Int, x: Int, y: Int, val slot: api.driver.Slot, val tier: Int) extends Slot(inventory, index, x, y) with ComponentSlot { setBackgroundIcon(Icons.get(slot)) val tierIcon = Icons.get(tier) diff --git a/src/main/scala/li/cil/oc/common/item/UpgradeContainerCard.scala b/src/main/scala/li/cil/oc/common/item/UpgradeContainerCard.scala index d9d3371a8..50e9d3315 100644 --- a/src/main/scala/li/cil/oc/common/item/UpgradeContainerCard.scala +++ b/src/main/scala/li/cil/oc/common/item/UpgradeContainerCard.scala @@ -14,7 +14,7 @@ class UpgradeContainerCard(val parent: Delegator, val tier: Int) extends Delegat override def rarity = Rarity.byTier(server.driver.item.UpgradeContainerCard.tier(createItemStack())) override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) { - tooltip.addAll(Tooltip.get(unlocalizedName)) + tooltip.addAll(Tooltip.get(baseName, tier + 1)) super.tooltipLines(stack, player, tooltip, advanced) } diff --git a/src/main/scala/li/cil/oc/common/item/UpgradeContainerUpgrade.scala b/src/main/scala/li/cil/oc/common/item/UpgradeContainerUpgrade.scala index 268d48f51..7ce0e4c34 100644 --- a/src/main/scala/li/cil/oc/common/item/UpgradeContainerUpgrade.scala +++ b/src/main/scala/li/cil/oc/common/item/UpgradeContainerUpgrade.scala @@ -14,7 +14,7 @@ class UpgradeContainerUpgrade(val parent: Delegator, val tier: Int) extends Dele override def rarity = Rarity.byTier(server.driver.item.UpgradeContainerUpgrade.tier(createItemStack())) override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) { - tooltip.addAll(Tooltip.get(unlocalizedName)) + tooltip.addAll(Tooltip.get(baseName, tier + 1)) super.tooltipLines(stack, player, tooltip, advanced) } diff --git a/src/main/scala/li/cil/oc/common/tileentity/RobotAssembler.scala b/src/main/scala/li/cil/oc/common/tileentity/RobotAssembler.scala index 331c757a6..aa3f36b9e 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/RobotAssembler.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/RobotAssembler.scala @@ -7,7 +7,7 @@ import li.cil.oc.api.Driver import li.cil.oc.common.InventorySlots.Tier import li.cil.oc.common.InventorySlots import li.cil.oc.util.ItemUtils -import li.cil.oc.api.driver.UpgradeContainer +import li.cil.oc.api.driver.{Slot, UpgradeContainer} class RobotAssembler extends traits.Environment with traits.Inventory with traits.Rotatable { val node = api.Network.newNode(this, Visibility.None). @@ -27,6 +27,12 @@ class RobotAssembler extends traits.Environment with traits.Inventory with trait if (caseTier >= 0) Settings.robotComplexityByTier(caseTier) else 0 } + def start() { + if (complexity < maxComplexity) { + + } + } + // ----------------------------------------------------------------------- // override def getInvName = Settings.namespace + "container.RobotAssembler" @@ -47,7 +53,7 @@ class RobotAssembler extends traits.Environment with traits.Inventory with trait caseTier != Tier.None && { val info = InventorySlots.assembler(caseTier)(slot) Option(Driver.driverFor(stack)) match { - case Some(driver) => driver.slot(stack) == info.slot && driver.tier(stack) <= info.tier + case Some(driver) if info.slot != Slot.None && info.tier != Tier.None => driver.slot(stack) == info.slot && driver.tier(stack) <= info.tier case _ => false } } diff --git a/src/main/scala/li/cil/oc/server/PacketHandler.scala b/src/main/scala/li/cil/oc/server/PacketHandler.scala index 0b3f253c0..5d0b7a63e 100644 --- a/src/main/scala/li/cil/oc/server/PacketHandler.scala +++ b/src/main/scala/li/cil/oc/server/PacketHandler.scala @@ -27,6 +27,7 @@ class PacketHandler extends CommonPacketHandler { case PacketType.MouseScroll => onMouseScroll(p) case PacketType.MouseUp => onMouseUp(p) case PacketType.MultiPartPlace => onMultiPartPlace(p) + case PacketType.RobotAssemblerStart => onRobotAssemblerStart(p) case PacketType.RobotStateRequest => onRobotStateRequest(p) case PacketType.ServerRange => onServerRange(p) case PacketType.ServerSide => onServerSide(p) @@ -117,9 +118,14 @@ class PacketHandler extends CommonPacketHandler { case player: EntityPlayerMP => EventHandler.place(player) case _ => // Invalid packet. } - } + def onRobotAssemblerStart(p: PacketParser) = + p.readTileEntity[RobotAssembler]() match { + case Some(assembler) => assembler.start() + case _ => // Invalid packet. + } + def onRobotStateRequest(p: PacketParser) = p.readTileEntity[RobotProxy]() match { case Some(proxy) => proxy.world.markBlockForUpdate(proxy.x, proxy.y, proxy.z)