diff --git a/src/main/java/li/cil/oc/api/driver/NamedBlock.java b/src/main/java/li/cil/oc/api/driver/NamedBlock.java index 4aca4e1e1..c27e32a17 100644 --- a/src/main/java/li/cil/oc/api/driver/NamedBlock.java +++ b/src/main/java/li/cil/oc/api/driver/NamedBlock.java @@ -21,4 +21,20 @@ public interface NamedBlock { * @return the preferred name. */ String preferredName(); + + /** + * This is used to determine which name to use in case multiple + * environments with this interface are merged. + *
+ * If multiple named environments are merged the one with the + * highest priority is selected. Negative values are + * allowed. The recommended default value is therefore zero. + * + * If multiple environments with the same priority exist, the + * result is unspecified. It will usually result in the environment + * of the driver that was registered first. + * + * @return the priority with which to use this name. + */ + int priority(); } diff --git a/src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala b/src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala index c42f9b177..604845620 100644 --- a/src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala +++ b/src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala @@ -30,9 +30,10 @@ class CompoundBlockDriver(val blocks: driver.Block*) extends driver.Block { } private def tryGetName(world: World, x: Int, y: Int, z: Int, environments: Seq[ManagedEnvironment]): String = { - for (environment <- environments) environment match { - case named: NamedBlock => return named.preferredName - case _ => + environments.collect { + case named: NamedBlock => named + }.sortBy(_.priority).headOption match { + case Some(named) => return named.preferredName } try world.getTileEntity(x, y, z) match { case inventory: IInventory if !Strings.isNullOrEmpty(inventory.getInventoryName) => return inventory.getInventoryName.stripPrefix("container.")