Fixed wires not connecting at all
This commit is contained in:
parent
3de3e3aed1
commit
04d37537cc
4 changed files with 58 additions and 45 deletions
|
@ -52,7 +52,7 @@ trait TNodePartConnector extends PartAbstract with INodeProvider
|
||||||
|
|
||||||
override def getNode[N <: INode](nodeType: Class[_ <: N], from: ForgeDirection): N =
|
override def getNode[N <: INode](nodeType: Class[_ <: N], from: ForgeDirection): N =
|
||||||
{
|
{
|
||||||
if (nodeType.isAssignableFrom(node.getClass) || node.getClass == nodeType)
|
if (node.getClass.isAssignableFrom(nodeType))
|
||||||
return node.asInstanceOf[N]
|
return node.asInstanceOf[N]
|
||||||
|
|
||||||
return null.asInstanceOf[N]
|
return null.asInstanceOf[N]
|
||||||
|
|
|
@ -19,7 +19,11 @@ object MultipartUtil
|
||||||
def getMultipartTile(access: IBlockAccess, pos: Vector3): TileMultipart =
|
def getMultipartTile(access: IBlockAccess, pos: Vector3): TileMultipart =
|
||||||
{
|
{
|
||||||
val te = pos.getTileEntity(access)
|
val te = pos.getTileEntity(access)
|
||||||
return if (te.isInstanceOf[TileMultipart]) te.asInstanceOf[TileMultipart] else null
|
|
||||||
|
if (te.isInstanceOf[TileMultipart])
|
||||||
|
return te.asInstanceOf[TileMultipart]
|
||||||
|
else
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
def getMultipart(world: World, vector: Vector3, partMap: Int): TMultiPart =
|
def getMultipart(world: World, vector: Vector3, partMap: Int): TMultiPart =
|
||||||
|
|
|
@ -98,26 +98,30 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke
|
||||||
override def toggleIO(side: Int, entityPlayer: EntityPlayer): Boolean =
|
override def toggleIO(side: Int, entityPlayer: EntityPlayer): Boolean =
|
||||||
{
|
{
|
||||||
val res = super.toggleIO(side, entityPlayer)
|
val res = super.toggleIO(side, entityPlayer)
|
||||||
|
|
||||||
|
dcNode.connectionMask = ForgeDirection.VALID_DIRECTIONS.filter(getIO(_) > 0).map(d => 1 << d.ordinal()).foldLeft(0)(_ | _)
|
||||||
dcNode.positiveTerminals.clear()
|
dcNode.positiveTerminals.clear()
|
||||||
dcNode.positiveTerminals.addAll(getOutputDirections())
|
dcNode.positiveTerminals.addAll(getOutputDirections())
|
||||||
|
notifyChange()
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
override def getDescPacket: AbstractPacket =
|
override def getDescPacket: AbstractPacket =
|
||||||
{
|
{
|
||||||
return new PacketTile(this, Array[Any](renderEnergyAmount, ioMap))
|
return new PacketTile(this) <<< renderEnergyAmount <<< ioMap
|
||||||
}
|
}
|
||||||
|
|
||||||
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
|
override def read(buf: ByteBuf, player: EntityPlayer, packet: PacketType)
|
||||||
{
|
{
|
||||||
this.energy.setEnergy(data.readLong)
|
energy.setEnergy(buf.readLong)
|
||||||
this.ioMap_$eq(data.readShort)
|
ioMap == buf.readShort
|
||||||
}
|
}
|
||||||
|
|
||||||
override def setIO(dir: ForgeDirection, `type`: Int)
|
override def setIO(dir: ForgeDirection, packet: Int)
|
||||||
{
|
{
|
||||||
super.setIO(dir, `type`)
|
super.setIO(dir, packet)
|
||||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
markUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
override def onPlaced(entityliving: EntityLivingBase, itemStack: ItemStack)
|
override def onPlaced(entityliving: EntityLivingBase, itemStack: ItemStack)
|
||||||
|
|
|
@ -277,10 +277,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
/**
|
/**
|
||||||
* Multipart Methods
|
* Multipart Methods
|
||||||
*/
|
*/
|
||||||
override def getStrength(hit: MovingObjectPosition, player: EntityPlayer): Float =
|
override def getStrength(hit: MovingObjectPosition, player: EntityPlayer): Float = 4
|
||||||
{
|
|
||||||
return 4
|
|
||||||
}
|
|
||||||
|
|
||||||
def getSlotMask: Int = 1 << side
|
def getSlotMask: Int = 1 << side
|
||||||
|
|
||||||
|
@ -347,8 +344,11 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
{
|
{
|
||||||
override def reconstruct()
|
override def reconstruct()
|
||||||
{
|
{
|
||||||
|
super.reconstruct()
|
||||||
|
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
{
|
||||||
|
directionMap.clear()
|
||||||
updateOpenConnections()
|
updateOpenConnections()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -368,7 +368,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
val absDir = Rotation.rotateSide(side, r)
|
val absDir = Rotation.rotateSide(side, r)
|
||||||
|
|
||||||
if (setExternalConnection(r, absDir) || setCornerConnection(r, absDir))
|
if (setExternalConnection(r, absDir) || setCornerConnection(r, absDir))
|
||||||
calculatedMask = calculatedMask | (1 << absDir)
|
calculatedMask |= 1 << absDir
|
||||||
|
|
||||||
if ((calculatedMask & (1 << absDir)) == 0)
|
if ((calculatedMask & (1 << absDir)) == 0)
|
||||||
disconnect(absDir)
|
disconnect(absDir)
|
||||||
|
@ -416,14 +416,13 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
val pos = new BlockCoord(tile).offset(absDir)
|
val pos = new BlockCoord(tile).offset(absDir)
|
||||||
val tilePart = MultipartUtil.getMultipartTile(world, pos)
|
val tilePart = MultipartUtil.getMultipartTile(world, pos)
|
||||||
|
|
||||||
val forgeDir = ForgeDirection.getOrientation(absDir)
|
val toDir = ForgeDirection.getOrientation(absDir)
|
||||||
val fromDir = ForgeDirection.getOrientation(absDir).getOpposite
|
val fromDir = ForgeDirection.getOrientation(absDir).getOpposite
|
||||||
|
|
||||||
if (tilePart != null && r != -1)
|
if (tilePart != null && r != -1)
|
||||||
{
|
{
|
||||||
val part = tilePart.partMap(side)
|
val part = tilePart.partMap(side)
|
||||||
|
|
||||||
|
|
||||||
if (canConnectTo(part, ForgeDirection.getOrientation(absDir)))
|
if (canConnectTo(part, ForgeDirection.getOrientation(absDir)))
|
||||||
{
|
{
|
||||||
val otherR = (r + 2) % 4
|
val otherR = (r + 2) % 4
|
||||||
|
@ -439,13 +438,13 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
|
|
||||||
if (wire.canConnectTo(PartFlatWire.this, fromDir) && wire.maskOpen(otherR))
|
if (wire.canConnectTo(PartFlatWire.this, fromDir) && wire.maskOpen(otherR))
|
||||||
{
|
{
|
||||||
connect(dcNode, forgeDir)
|
connect(dcNode, toDir)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (canConnectTo(part))
|
else if (canConnectTo(part))
|
||||||
{
|
{
|
||||||
connect(dcNode, forgeDir)
|
connect(dcNode, toDir)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,12 +457,12 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
/**
|
/**
|
||||||
* Can't find another wire. Try TileEntity.
|
* Can't find another wire. Try TileEntity.
|
||||||
*/
|
*/
|
||||||
val tileEntity = world.getTileEntity(pos.x, pos.y, pos.z)
|
val tileEntity = pos.getTileEntity(world)
|
||||||
val tileComponent = getComponent(tileEntity, fromDir)
|
val tileComponent = getComponent(tileEntity, fromDir)
|
||||||
|
|
||||||
if (canConnectTo(tileEntity, forgeDir))
|
if (canConnectTo(tileEntity, fromDir))
|
||||||
{
|
{
|
||||||
connect(tileComponent, forgeDir)
|
connect(tileComponent, toDir)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,12 +484,13 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
if (tpCorner != null)
|
if (tpCorner != null)
|
||||||
{
|
{
|
||||||
val part = tpCorner.partMap(absDir ^ 1)
|
val part = tpCorner.partMap(absDir ^ 1)
|
||||||
val absForgeDir = ForgeDirection.getOrientation(absDir)
|
val absToDir = ForgeDirection.getOrientation(absDir)
|
||||||
|
val absFromDir = ForgeDirection.getOrientation(absDir).getOpposite
|
||||||
|
|
||||||
if (canConnectTo(part, absForgeDir))
|
if (canConnectTo(part, absFromDir))
|
||||||
{
|
{
|
||||||
//TODO: Check dir
|
//TODO: Check dir
|
||||||
connect(part.asInstanceOf[INodeProvider].getNode(classOf[DCNode], absForgeDir.getOpposite).asInstanceOf[DCNode], absForgeDir)
|
connect(part.asInstanceOf[INodeProvider].getNode(classOf[DCNode], absFromDir), absToDir)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -551,10 +551,10 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newConn != (connectionMask & 0xF000FF))
|
if (newConn != (PartFlatWire.this.connectionMask & 0xF000FF))
|
||||||
{
|
{
|
||||||
val diff: Int = connectionMask ^ newConn
|
val diff: Int = PartFlatWire.this.connectionMask ^ newConn
|
||||||
connectionMask = connectionMask & ~0xF000FF | newConn
|
PartFlatWire.this.connectionMask = PartFlatWire.this.connectionMask & ~0xF000FF | newConn
|
||||||
|
|
||||||
for (r <- 0 until 4)
|
for (r <- 0 until 4)
|
||||||
{
|
{
|
||||||
|
@ -590,9 +590,9 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
{
|
{
|
||||||
newConn |= 0x10000
|
newConn |= 0x10000
|
||||||
}
|
}
|
||||||
if (newConn != (connectionMask & 0x10F00))
|
if (newConn != (PartFlatWire.this.connectionMask & 0x10F00))
|
||||||
{
|
{
|
||||||
connectionMask = connectionMask & ~0x10F00 | newConn
|
PartFlatWire.this.connectionMask = PartFlatWire.this.connectionMask & ~0x10F00 | newConn
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -615,9 +615,9 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newConn != (connectionMask & 0xF000))
|
if (newConn != (PartFlatWire.this.connectionMask & 0xF000))
|
||||||
{
|
{
|
||||||
connectionMask = connectionMask & ~0xF000 | newConn
|
PartFlatWire.this.connectionMask = PartFlatWire.this.connectionMask & ~0xF000 | newConn
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,9 +626,11 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
|
|
||||||
def connectionOpen(r: Int): Boolean =
|
def connectionOpen(r: Int): Boolean =
|
||||||
{
|
{
|
||||||
val absDir: Int = Rotation.rotateSide(side, r)
|
val absDir = Rotation.rotateSide(side, r)
|
||||||
val facePart: TMultiPart = tile.partMap(absDir)
|
val facePart = tile.partMap(absDir)
|
||||||
if (facePart != null && (!(facePart.isInstanceOf[PartFlatWire]) || !canConnectTo(facePart, ForgeDirection.getOrientation(absDir))))
|
val toDir = ForgeDirection.getOrientation(absDir)
|
||||||
|
|
||||||
|
if (facePart != null && (!facePart.isInstanceOf[PartFlatWire] || !canConnectTo(facePart, toDir.getOpposite)))
|
||||||
{
|
{
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -636,6 +638,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
{
|
{
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,10 +651,12 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
val absDir: Int = Rotation.rotateSide(side, r)
|
val absDir: Int = Rotation.rotateSide(side, r)
|
||||||
val pos: BlockCoord = new BlockCoord(tile)
|
val pos: BlockCoord = new BlockCoord(tile)
|
||||||
pos.offset(absDir)
|
pos.offset(absDir)
|
||||||
|
|
||||||
if (!canConnectThroughCorner(pos, absDir ^ 1, side))
|
if (!canConnectThroughCorner(pos, absDir ^ 1, side))
|
||||||
{
|
{
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pos.offset(side)
|
pos.offset(side)
|
||||||
val t: TileMultipart = MultipartUtil.getMultipartTile(world, pos)
|
val t: TileMultipart = MultipartUtil.getMultipartTile(world, pos)
|
||||||
|
|
||||||
|
@ -761,13 +766,13 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
val absDir: Int = Rotation.rotateSide(side, r)
|
val absDir: Int = Rotation.rotateSide(side, r)
|
||||||
if (canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r))
|
if (canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r))
|
||||||
{
|
{
|
||||||
val oldConn: Int = connectionMask
|
val oldConn: Int = PartFlatWire.this.connectionMask
|
||||||
connectionMask |= 0x1 << r
|
PartFlatWire.this.connectionMask |= 0x1 << r
|
||||||
if (renderThisCorner(wire))
|
if (renderThisCorner(wire))
|
||||||
{
|
{
|
||||||
connectionMask |= 0x100000 << r
|
PartFlatWire.this.connectionMask |= 0x100000 << r
|
||||||
}
|
}
|
||||||
if (oldConn != connectionMask)
|
if (oldConn != PartFlatWire.this.connectionMask)
|
||||||
{
|
{
|
||||||
sendConnUpdate
|
sendConnUpdate
|
||||||
}
|
}
|
||||||
|
@ -781,9 +786,9 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
val absDir: Int = Rotation.rotateSide(side, r)
|
val absDir: Int = Rotation.rotateSide(side, r)
|
||||||
if (canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r))
|
if (canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r))
|
||||||
{
|
{
|
||||||
val oldConn: Int = connectionMask
|
val oldConn: Int = PartFlatWire.this.connectionMask
|
||||||
connectionMask |= 0x10 << r
|
PartFlatWire.this.connectionMask |= 0x10 << r
|
||||||
if (oldConn != connectionMask)
|
if (oldConn != PartFlatWire.this.connectionMask)
|
||||||
{
|
{
|
||||||
sendConnUpdate()
|
sendConnUpdate()
|
||||||
}
|
}
|
||||||
|
@ -797,9 +802,9 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
val absDir: Int = Rotation.rotateSide(side, r)
|
val absDir: Int = Rotation.rotateSide(side, r)
|
||||||
if (canConnectTo(wire, ForgeDirection.getOrientation(absDir)))
|
if (canConnectTo(wire, ForgeDirection.getOrientation(absDir)))
|
||||||
{
|
{
|
||||||
val oldConn: Int = connectionMask
|
val oldConn: Int = PartFlatWire.this.connectionMask
|
||||||
connectionMask |= 0x100 << r
|
PartFlatWire.this.connectionMask |= 0x100 << r
|
||||||
if (oldConn != connectionMask)
|
if (oldConn != PartFlatWire.this.connectionMask)
|
||||||
{
|
{
|
||||||
sendConnUpdate()
|
sendConnUpdate()
|
||||||
}
|
}
|
||||||
|
@ -814,7 +819,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
||||||
private def getComponent(obj: AnyRef, from: ForgeDirection): DCNode =
|
private def getComponent(obj: AnyRef, from: ForgeDirection): DCNode =
|
||||||
{
|
{
|
||||||
if (obj.isInstanceOf[INodeProvider])
|
if (obj.isInstanceOf[INodeProvider])
|
||||||
return obj.asInstanceOf[INodeProvider].getNode(classOf[DCNode], from).asInstanceOf[DCNode]
|
return obj.asInstanceOf[INodeProvider].getNode(classOf[DCNode], from)
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue