mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-11 08:16:19 -04:00
Added priority getter to NamedBlock interface.
This commit is contained in:
parent
bc842a150b
commit
272b9000ff
@ -21,4 +21,20 @@ public interface NamedBlock {
|
|||||||
* @return the preferred name.
|
* @return the preferred name.
|
||||||
*/
|
*/
|
||||||
String preferredName();
|
String preferredName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is used to determine which name to use in case multiple
|
||||||
|
* environments with this interface are merged.
|
||||||
|
* <p/>
|
||||||
|
* If multiple named environments are merged the one with the
|
||||||
|
* <em>highest</em> priority is selected. Negative values are
|
||||||
|
* allowed. The recommended default value is therefore zero.
|
||||||
|
* <p/>
|
||||||
|
* 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();
|
||||||
}
|
}
|
||||||
|
@ -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 = {
|
private def tryGetName(world: World, x: Int, y: Int, z: Int, environments: Seq[ManagedEnvironment]): String = {
|
||||||
for (environment <- environments) environment match {
|
environments.collect {
|
||||||
case named: NamedBlock => return named.preferredName
|
case named: NamedBlock => named
|
||||||
case _ =>
|
}.sortBy(_.priority).headOption match {
|
||||||
|
case Some(named) => return named.preferredName
|
||||||
}
|
}
|
||||||
try world.getTileEntity(x, y, z) match {
|
try world.getTileEntity(x, y, z) match {
|
||||||
case inventory: IInventory if !Strings.isNullOrEmpty(inventory.getInventoryName) => return inventory.getInventoryName.stripPrefix("container.")
|
case inventory: IInventory if !Strings.isNullOrEmpty(inventory.getInventoryName) => return inventory.getInventoryName.stripPrefix("container.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user