mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
Fixes a potential NPE in adapter if block driver returns null environment.
This commit is contained in:
parent
e0a7e75027
commit
f169cae801
@ -51,31 +51,39 @@ class Adapter extends traits.Environment with Analyzable {
|
|||||||
case Some(newDriver) => blocks(d.ordinal()) match {
|
case Some(newDriver) => blocks(d.ordinal()) match {
|
||||||
case Some((oldEnvironment, driver)) =>
|
case Some((oldEnvironment, driver)) =>
|
||||||
if (newDriver != driver) {
|
if (newDriver != driver) {
|
||||||
// This is... odd. Maybe moved by some other mod?
|
// This is... odd. Maybe moved by some other mod? First, clean up.
|
||||||
node.disconnect(oldEnvironment.node)
|
blocks(d.ordinal()) = None
|
||||||
val environment = newDriver.createEnvironment(world, x, y, z)
|
|
||||||
blocks(d.ordinal()) = Some((environment, newDriver))
|
|
||||||
updatingBlocks -= oldEnvironment
|
updatingBlocks -= oldEnvironment
|
||||||
|
blocksData(d.ordinal()) = None
|
||||||
|
node.disconnect(oldEnvironment.node)
|
||||||
|
|
||||||
|
// Then rebuild - if we have something.
|
||||||
|
val environment = newDriver.createEnvironment(world, x, y, z)
|
||||||
|
if (environment != null) {
|
||||||
|
blocks(d.ordinal()) = Some((environment, newDriver))
|
||||||
|
if (environment.canUpdate) {
|
||||||
|
updatingBlocks += environment
|
||||||
|
}
|
||||||
|
blocksData(d.ordinal()) = Some(new BlockData(environment.getClass.getName, new NBTTagCompound()))
|
||||||
|
node.connect(environment.node)
|
||||||
|
}
|
||||||
|
} // else: the more things change, the more they stay the same.
|
||||||
|
case _ =>
|
||||||
|
// A challenger appears. Maybe.
|
||||||
|
val environment = newDriver.createEnvironment(world, x, y, z)
|
||||||
|
if (environment != null) {
|
||||||
|
blocks(d.ordinal()) = Some((environment, newDriver))
|
||||||
if (environment.canUpdate) {
|
if (environment.canUpdate) {
|
||||||
updatingBlocks += environment
|
updatingBlocks += environment
|
||||||
}
|
}
|
||||||
|
blocksData(d.ordinal()) match {
|
||||||
|
case Some(data) if data.name == environment.getClass.getName =>
|
||||||
|
environment.load(data.data)
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
blocksData(d.ordinal()) = Some(new BlockData(environment.getClass.getName, new NBTTagCompound()))
|
blocksData(d.ordinal()) = Some(new BlockData(environment.getClass.getName, new NBTTagCompound()))
|
||||||
node.connect(environment.node)
|
node.connect(environment.node)
|
||||||
} // else: the more things change, the more they stay the same.
|
|
||||||
case _ =>
|
|
||||||
// A challenger appears.
|
|
||||||
val environment = newDriver.createEnvironment(world, x, y, z)
|
|
||||||
blocks(d.ordinal()) = Some((environment, newDriver))
|
|
||||||
if (environment.canUpdate) {
|
|
||||||
updatingBlocks += environment
|
|
||||||
}
|
}
|
||||||
blocksData(d.ordinal()) match {
|
|
||||||
case Some(data) if data.name == environment.getClass.getName =>
|
|
||||||
environment.load(data.data)
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
blocksData(d.ordinal()) = Some(new BlockData(environment.getClass.getName, new NBTTagCompound()))
|
|
||||||
node.connect(environment.node)
|
|
||||||
}
|
}
|
||||||
case _ => blocks(d.ordinal()) match {
|
case _ => blocks(d.ordinal()) match {
|
||||||
case Some((environment, driver)) =>
|
case Some((environment, driver)) =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user