Conflicts:
	src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala
This commit is contained in:
Florian Nücke 2014-02-08 16:15:59 +01:00
commit 4e71de049a
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package li.cil.oc.api.driver;
/**
* This interface can be added to block drivers to provide a 'preferred name' in
* case the driver is merged with other block drivers (interface based drivers
* such as for <tt>IInventory</tt>).
*/
public interface NamedBlock {
/**
* The preferred name, in case the driver is merged with others.
* <p/>
* If multiple drivers with a preferred name are merged, the first one is
* picked. This should usually not happen, since this is only intended to
* be implemented by drivers for actual tile entities (not interfaces).
*
* @return the preferred name.
*/
String preferredName();
}

View File

@ -3,6 +3,7 @@ package li.cil.oc.server.driver
import com.google.common.base.Strings
import cpw.mods.fml.relauncher.ReflectionHelper
import li.cil.oc.api.driver
import li.cil.oc.api.driver.NamedBlock
import net.minecraft.inventory.IInventory
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.tileentity.TileEntity
@ -30,6 +31,10 @@ class CompoundBlockDriver(val blocks: driver.Block*) extends driver.Block {
}
private def tryGetName(world: World, x: Int, y: Int, z: Int): String = {
for (block <- blocks) block match {
case named: NamedBlock => return named.preferredName
case _ =>
}
try world.getTileEntity(x, y, z) match {
case inventory: IInventory => return inventory.getInventoryName.stripPrefix("container.")
} catch {