diff --git a/src/main/java/li/cil/oc/api/driver/NamedBlock.java b/src/main/java/li/cil/oc/api/driver/NamedBlock.java new file mode 100644 index 000000000..b1e1ba4e5 --- /dev/null +++ b/src/main/java/li/cil/oc/api/driver/NamedBlock.java @@ -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 IInventory). + */ +public interface NamedBlock { + /** + * The preferred name, in case the driver is merged with others. + *
+ * 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(); +} 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 5c003732a..5d1ac4e71 100644 --- a/src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala +++ b/src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala @@ -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 {