diff --git a/src/main/resources/assets/opencomputers/loot/loot.properties b/src/main/resources/assets/opencomputers/loot/loot.properties index b7b1b1b53..4e9e7d187 100644 --- a/src/main/resources/assets/opencomputers/loot/loot.properties +++ b/src/main/resources/assets/opencomputers/loot/loot.properties @@ -12,7 +12,7 @@ Network=network:1:dyeLime OpenIRC=irc:1:dyeLightBlue OpenLoader=openloader:1:dyeMagenta OpenOS=openos:0:dyeGreen -OPPM=oppm:1:dyeCyan +OPPM=oppm:0:dyeCyan # Higher chance to find the dig program, because it has the most immediate # use - OpenOS is craftable and IRC can be downloaded once an internet card # is available - which one needs anyway, to use the program... diff --git a/src/main/scala/li/cil/oc/server/machine/Machine.scala b/src/main/scala/li/cil/oc/server/machine/Machine.scala index e43d35ee8..39d5120f1 100644 --- a/src/main/scala/li/cil/oc/server/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/machine/Machine.scala @@ -117,19 +117,17 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach } case _ => 0 })) - val oldArchitecture = architecture - architecture = null + var newArchitecture: Architecture = null components.find { case stack: ItemStack => Option(Driver.driverFor(stack, host.getClass)) match { case Some(driver: Processor) if driver.slot(stack) == Slot.CPU => Option(driver.architecture(stack)) match { case Some(clazz) => - if (oldArchitecture == null || oldArchitecture.getClass != clazz) { - architecture = clazz.getConstructor(classOf[machine.Machine]).newInstance(this) - if (node.network != null) architecture.onConnect() + if (architecture == null || architecture.getClass != clazz) { + newArchitecture = clazz.getConstructor(classOf[machine.Machine]).newInstance(this) } else { - architecture = oldArchitecture + newArchitecture = architecture } true case _ => false @@ -138,6 +136,12 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach } case _ => false } + // This needs to operate synchronized against the worker thread, to avoid the + // architecture changing while it is currently being executed. + if (newArchitecture != architecture) this.synchronized { + architecture = newArchitecture + if (architecture != null && node.network != null) architecture.onConnect() + } hasMemory = Option(architecture).fold(false)(_.recomputeMemory(components)) }