mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 10:21:45 -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
|
||||
|
||||
# Items
|
||||
oc:item.AbstractBusCard.name=Abstrakter-Bus-Karte
|
||||
oc:item.Acid.name=Grog
|
||||
oc:item.ALU.name=Arithmetisch-logische Einheit (ALU)
|
||||
oc:item.Analyzer.name=Messgerät
|
||||
@ -77,6 +78,7 @@ oc:container.Case=Computer
|
||||
oc:container.DiskDrive=Diskettenlaufwerk
|
||||
|
||||
# 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.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.
|
||||
|
@ -23,6 +23,7 @@ oc:block.Screen1.name=Advanced Screen
|
||||
oc:block.Screen2.name=Superior Screen
|
||||
|
||||
# Items
|
||||
oc:item.AbstractBusCard.name=Abstract Bus Card
|
||||
oc:item.Acid.name=Grog
|
||||
oc:item.ALU.name=Arithmetic Logic Unit (ALU)
|
||||
oc:item.Analyzer.name=Analyzer
|
||||
@ -77,6 +78,7 @@ oc:container.Case=Computer
|
||||
oc:container.DiskDrive=Disk Drive
|
||||
|
||||
# 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.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.
|
||||
|
@ -1,12 +1,22 @@
|
||||
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 stargatetech2.api.bus.IBusDevice
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import stargatetech2.api.bus.{BusEvent, IBusDevice}
|
||||
|
||||
@Optional.Interface(iface = "stargatetech2.api.bus.IBusDevice", modid = "StargateTech2")
|
||||
trait AbstractBusAware extends TileEntity with Inventory with IBusDevice {
|
||||
def getInterfaces(side: Int) = if (hasAbstractBusCard) Array(null) else null
|
||||
trait AbstractBusAware extends TileEntity with ComponentInventory with IBusDevice {
|
||||
def getInterfaces(side: Int) =
|
||||
if (hasAbstractBusCard) {
|
||||
components collect {
|
||||
case abstractBus: component.AbstractBus => abstractBus.busInterface
|
||||
}
|
||||
}
|
||||
else null
|
||||
|
||||
def getXCoord = x
|
||||
|
||||
@ -14,15 +24,60 @@ trait AbstractBusAware extends TileEntity with Inventory with IBusDevice {
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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.Persistable
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.network.INetworkManager
|
||||
import net.minecraft.network.packet.Packet132TileEntityData
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import scala.math.ScalaNumber
|
||||
|
||||
abstract class Environment extends net.minecraft.tileentity.TileEntity with TileEntity with network.Environment with Persistable {
|
||||
def world = getWorldObj
|
||||
|
||||
def x = xCoord
|
||||
|
||||
def y = yCoord
|
||||
|
||||
def z = zCoord
|
||||
|
||||
def block = getBlockType
|
||||
|
||||
abstract class Environment extends TileEntity with network.Environment with Persistable {
|
||||
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 onConnect(node: network.Node) {}
|
||||
|
@ -11,7 +11,7 @@ import net.minecraftforge.common.ForgeDirection
|
||||
import scala.collection.mutable
|
||||
|
||||
@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))
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
@ -1,25 +1,38 @@
|
||||
package li.cil.oc.common.tileentity
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.block.Block
|
||||
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 {
|
||||
def world: World
|
||||
trait TileEntity extends MCTileEntity {
|
||||
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 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)
|
||||
def readFromNBTForClient(nbt: NBTTagCompound) {}
|
||||
|
||||
|
@ -13,7 +13,7 @@ class AbstractBus(val owner: tileentity.Computer) extends ManagedComponent with
|
||||
withComponent("abstract_bus").
|
||||
create()
|
||||
|
||||
protected val busInterface: IBusInterface = StargateTechAPI.api.getFactory.getIBusInterface(owner, this)
|
||||
val busInterface: IBusInterface = StargateTechAPI.api.getFactory.getIBusInterface(owner, this)
|
||||
|
||||
protected var isEnabled = true
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user