mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 10:51:55 -04:00
abstract card localizations; triggering events to add/remove from abstract bus network; some cleanup
This commit is contained in:
parent
88600dc25c
commit
ab1c4abc92
@ -23,6 +23,7 @@ oc:block.Screen1.name=Hochwertiger Bildschirm
|
|||||||
oc:block.Screen2.name=Ausgezeichneter Bildschirm
|
oc:block.Screen2.name=Ausgezeichneter Bildschirm
|
||||||
|
|
||||||
# Items
|
# Items
|
||||||
|
oc:item.AbstractBusCard.name=Abstrakter-Bus-Karte
|
||||||
oc:item.Acid.name=Grog
|
oc:item.Acid.name=Grog
|
||||||
oc:item.ALU.name=Arithmetisch-logische Einheit (ALU)
|
oc:item.ALU.name=Arithmetisch-logische Einheit (ALU)
|
||||||
oc:item.Analyzer.name=Messgerät
|
oc:item.Analyzer.name=Messgerät
|
||||||
@ -77,6 +78,7 @@ oc:container.Case=Computer
|
|||||||
oc:container.DiskDrive=Diskettenlaufwerk
|
oc:container.DiskDrive=Diskettenlaufwerk
|
||||||
|
|
||||||
# Item / Block Tooltips
|
# Item / Block Tooltips
|
||||||
|
oc:tooltip.AbstractBusCard=Erlaubt es LIP-Pakete des Abstrakten Busses von §fStargateTech 2§7 zu senden und zu empfangen.
|
||||||
oc:tooltip.Acid=Eine hochgiftige Möchtegernflüssigkeit, wird üblicherweise nur von gewissen Piraten konsumiert. Dank ihrer korrosiven Eigenschaften ideal zum Bedrucken von Leiterplatten geeignet.
|
oc:tooltip.Acid=Eine hochgiftige Möchtegernflüssigkeit, wird üblicherweise nur von gewissen Piraten konsumiert. Dank ihrer korrosiven Eigenschaften ideal zum Bedrucken von Leiterplatten geeignet.
|
||||||
oc:tooltip.Adapter=Erlaubt es Blöcke anzusteuern, die keine Komponentenblöcke sind, wie etwa reguläre Minecraft-Blöcke oder Blöcke anderer Mods.
|
oc:tooltip.Adapter=Erlaubt es Blöcke anzusteuern, die keine Komponentenblöcke sind, wie etwa reguläre Minecraft-Blöcke oder Blöcke anderer Mods.
|
||||||
oc:tooltip.ALU=Zählt Zahlen zum Zeitvertreib. Klingt komisch, is aber so.
|
oc:tooltip.ALU=Zählt Zahlen zum Zeitvertreib. Klingt komisch, is aber so.
|
||||||
|
@ -23,6 +23,7 @@ oc:block.Screen1.name=Advanced Screen
|
|||||||
oc:block.Screen2.name=Superior Screen
|
oc:block.Screen2.name=Superior Screen
|
||||||
|
|
||||||
# Items
|
# Items
|
||||||
|
oc:item.AbstractBusCard.name=Abstract Bus Card
|
||||||
oc:item.Acid.name=Grog
|
oc:item.Acid.name=Grog
|
||||||
oc:item.ALU.name=Arithmetic Logic Unit (ALU)
|
oc:item.ALU.name=Arithmetic Logic Unit (ALU)
|
||||||
oc:item.Analyzer.name=Analyzer
|
oc:item.Analyzer.name=Analyzer
|
||||||
@ -77,6 +78,7 @@ oc:container.Case=Computer
|
|||||||
oc:container.DiskDrive=Disk Drive
|
oc:container.DiskDrive=Disk Drive
|
||||||
|
|
||||||
# Item / Block Tooltips
|
# Item / Block Tooltips
|
||||||
|
oc:tooltip.AbstractBusCard=Allows interacting with §fStargateTech 2§7's abstract bus by sending and receiving LIP packets.
|
||||||
oc:tooltip.Acid=A highly toxic pseudo-liquid, usually only consumed by certain pirates. Thanks to its corrosive nature it is perfectly suited for etching circuit boards.
|
oc:tooltip.Acid=A highly toxic pseudo-liquid, usually only consumed by certain pirates. Thanks to its corrosive nature it is perfectly suited for etching circuit boards.
|
||||||
oc:tooltip.Adapter=Used to control non-component blocks, such as vanilla blocks or blocks from other mods.
|
oc:tooltip.Adapter=Used to control non-component blocks, such as vanilla blocks or blocks from other mods.
|
||||||
oc:tooltip.ALU=Adds number so you don't have to. It might be better this way.
|
oc:tooltip.ALU=Adds number so you don't have to. It might be better this way.
|
||||||
|
@ -1,12 +1,22 @@
|
|||||||
package li.cil.oc.common.tileentity
|
package li.cil.oc.common.tileentity
|
||||||
|
|
||||||
import cpw.mods.fml.common.Optional
|
import cpw.mods.fml.common.{Loader, Optional}
|
||||||
|
import li.cil.oc.Items
|
||||||
|
import li.cil.oc.api.network.Node
|
||||||
|
import li.cil.oc.server.component
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import stargatetech2.api.bus.IBusDevice
|
import net.minecraftforge.common.MinecraftForge
|
||||||
|
import stargatetech2.api.bus.{BusEvent, IBusDevice}
|
||||||
|
|
||||||
@Optional.Interface(iface = "stargatetech2.api.bus.IBusDevice", modid = "StargateTech2")
|
@Optional.Interface(iface = "stargatetech2.api.bus.IBusDevice", modid = "StargateTech2")
|
||||||
trait AbstractBusAware extends TileEntity with Inventory with IBusDevice {
|
trait AbstractBusAware extends TileEntity with ComponentInventory with IBusDevice {
|
||||||
def getInterfaces(side: Int) = if (hasAbstractBusCard) Array(null) else null
|
def getInterfaces(side: Int) =
|
||||||
|
if (hasAbstractBusCard) {
|
||||||
|
components collect {
|
||||||
|
case abstractBus: component.AbstractBus => abstractBus.busInterface
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else null
|
||||||
|
|
||||||
def getXCoord = x
|
def getXCoord = x
|
||||||
|
|
||||||
@ -14,15 +24,60 @@ trait AbstractBusAware extends TileEntity with Inventory with IBusDevice {
|
|||||||
|
|
||||||
def getZCoord = z
|
def getZCoord = z
|
||||||
|
|
||||||
protected def hasAbstractBusCard = false
|
protected def hasAbstractBusCard = components exists {
|
||||||
|
case abstractBus: component.AbstractBus => true
|
||||||
|
}
|
||||||
|
|
||||||
override protected def onItemAdded(slot: Int, stack: ItemStack) {
|
override protected def onItemAdded(slot: Int, stack: ItemStack) {
|
||||||
super.onItemAdded(slot, stack)
|
super.onItemAdded(slot, stack)
|
||||||
// TODO if card wasn't present, send device added event
|
if (Items.abstractBus.parent.subItem(stack) == Items.abstractBus) {
|
||||||
|
// Trigger network re-map after another interface was added.
|
||||||
|
addAbstractBus()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected def onItemRemoved(slot: Int, stack: ItemStack) {
|
override protected def onItemRemoved(slot: Int, stack: ItemStack) {
|
||||||
super.onItemRemoved(slot, stack)
|
super.onItemRemoved(slot, stack)
|
||||||
// TODO if no card is present anymore, send device removed event
|
if (Items.abstractBus.parent.subItem(stack) == Items.abstractBus) {
|
||||||
|
if (!hasAbstractBusCard) {
|
||||||
|
// Last interface was removed, trigger removal. This is the case when
|
||||||
|
// the last abstract bus card was removed.
|
||||||
|
removeAbstractBus(force = true)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Trigger network re-map if some interface still remains. This is the
|
||||||
|
// case when one of multiple abstract bus cards was removed.
|
||||||
|
addAbstractBus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract override def onConnect(node: Node) {
|
||||||
|
super.onConnect(node)
|
||||||
|
addAbstractBus()
|
||||||
|
}
|
||||||
|
|
||||||
|
override def onChunkUnload() {
|
||||||
|
super.onChunkUnload()
|
||||||
|
removeAbstractBus()
|
||||||
|
}
|
||||||
|
|
||||||
|
override def invalidate() {
|
||||||
|
super.onChunkUnload()
|
||||||
|
removeAbstractBus()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected def addAbstractBus() {
|
||||||
|
// Mod loaded check to avoid class not found errors.
|
||||||
|
if (Loader.isModLoaded("StargateTech2") && hasAbstractBusCard) {
|
||||||
|
MinecraftForge.EVENT_BUS.post(new BusEvent.AddToNetwork(world, x, y, z))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected def removeAbstractBus(force: Boolean = false) {
|
||||||
|
// Mod loaded check to avoid class not found errors.
|
||||||
|
if (Loader.isModLoaded("StargateTech2") && (hasAbstractBusCard || force)) {
|
||||||
|
MinecraftForge.EVENT_BUS.post(new BusEvent.RemoveFromNetwork(world, x, y, z))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,10 @@ import li.cil.oc.api.{Network, network}
|
|||||||
import li.cil.oc.util.ExtendedNBT._
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
import li.cil.oc.util.Persistable
|
import li.cil.oc.util.Persistable
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.minecraft.network.INetworkManager
|
|
||||||
import net.minecraft.network.packet.Packet132TileEntityData
|
|
||||||
import net.minecraftforge.common.ForgeDirection
|
import net.minecraftforge.common.ForgeDirection
|
||||||
import scala.math.ScalaNumber
|
import scala.math.ScalaNumber
|
||||||
|
|
||||||
abstract class Environment extends net.minecraft.tileentity.TileEntity with TileEntity with network.Environment with Persistable {
|
abstract class Environment extends TileEntity with network.Environment with Persistable {
|
||||||
def world = getWorldObj
|
|
||||||
|
|
||||||
def x = xCoord
|
|
||||||
|
|
||||||
def y = yCoord
|
|
||||||
|
|
||||||
def z = zCoord
|
|
||||||
|
|
||||||
def block = getBlockType
|
|
||||||
|
|
||||||
protected var addedToNetwork = false
|
protected var addedToNetwork = false
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
@ -76,18 +64,6 @@ abstract class Environment extends net.minecraft.tileentity.TileEntity with Tile
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def getDescriptionPacket = {
|
|
||||||
val nbt = new NBTTagCompound()
|
|
||||||
writeToNBTForClient(nbt)
|
|
||||||
if (nbt.hasNoTags) null else new Packet132TileEntityData(x, y, z, -1, nbt)
|
|
||||||
}
|
|
||||||
|
|
||||||
override def onDataPacket(manager: INetworkManager, packet: Packet132TileEntityData) {
|
|
||||||
readFromNBTForClient(packet.data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
|
||||||
|
|
||||||
def onMessage(message: network.Message) {}
|
def onMessage(message: network.Message) {}
|
||||||
|
|
||||||
def onConnect(node: network.Node) {}
|
def onConnect(node: network.Node) {}
|
||||||
|
@ -11,7 +11,7 @@ import net.minecraftforge.common.ForgeDirection
|
|||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
@Optional.Interface(iface = "dan200.computer.api.IPeripheral", modid = "ComputerCraft")
|
@Optional.Interface(iface = "dan200.computer.api.IPeripheral", modid = "ComputerCraft")
|
||||||
class Router extends net.minecraft.tileentity.TileEntity with api.network.SidedEnvironment with IPeripheral {
|
class Router extends TileEntity with api.network.SidedEnvironment with IPeripheral {
|
||||||
private val plugs = ForgeDirection.VALID_DIRECTIONS.map(side => new Plug(side))
|
private val plugs = ForgeDirection.VALID_DIRECTIONS.map(side => new Plug(side))
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
@ -1,25 +1,38 @@
|
|||||||
package li.cil.oc.common.tileentity
|
package li.cil.oc.common.tileentity
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||||
import net.minecraft.block.Block
|
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.minecraft.world.World
|
import net.minecraft.network.INetworkManager
|
||||||
|
import net.minecraft.network.packet.Packet132TileEntityData
|
||||||
|
import net.minecraft.tileentity.{TileEntity => MCTileEntity}
|
||||||
|
|
||||||
trait TileEntity {
|
trait TileEntity extends MCTileEntity {
|
||||||
def world: World
|
def world = getWorldObj
|
||||||
|
|
||||||
def x: Int
|
def x = xCoord
|
||||||
|
|
||||||
def y: Int
|
def y = yCoord
|
||||||
|
|
||||||
def z: Int
|
def z = zCoord
|
||||||
|
|
||||||
def block: Block
|
def block = getBlockType
|
||||||
|
|
||||||
lazy val isClient = world.isRemote
|
lazy val isClient = world.isRemote
|
||||||
|
|
||||||
lazy val isServer = !isClient
|
lazy val isServer = !isClient
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
override def getDescriptionPacket = {
|
||||||
|
val nbt = new NBTTagCompound()
|
||||||
|
writeToNBTForClient(nbt)
|
||||||
|
if (nbt.hasNoTags) null else new Packet132TileEntityData(x, y, z, -1, nbt)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def onDataPacket(manager: INetworkManager, packet: Packet132TileEntityData) {
|
||||||
|
readFromNBTForClient(packet.data)
|
||||||
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
def readFromNBTForClient(nbt: NBTTagCompound) {}
|
def readFromNBTForClient(nbt: NBTTagCompound) {}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class AbstractBus(val owner: tileentity.Computer) extends ManagedComponent with
|
|||||||
withComponent("abstract_bus").
|
withComponent("abstract_bus").
|
||||||
create()
|
create()
|
||||||
|
|
||||||
protected val busInterface: IBusInterface = StargateTechAPI.api.getFactory.getIBusInterface(owner, this)
|
val busInterface: IBusInterface = StargateTechAPI.api.getFactory.getIBusInterface(owner, this)
|
||||||
|
|
||||||
protected var isEnabled = true
|
protected var isEnabled = true
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user