Added priority getter to NamedBlock interface.

This commit is contained in:
Florian Nücke 2014-10-05 15:17:35 +02:00
parent bc842a150b
commit 272b9000ff
2 changed files with 20 additions and 3 deletions

View File

@ -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.
* <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();
}

View File

@ -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.")