From 5cb549741f6a741ab53cfd58d449d9772d33a853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 8 Feb 2014 16:05:40 +0100 Subject: [PATCH] added interface to allow overriding name for compound drivers --- .../java/li/cil/oc/api/driver/NamedBlock.java | 19 +++++++++++++++++++ .../server/driver/CompoundBlockDriver.scala | 5 +++++ 2 files changed, 24 insertions(+) create mode 100644 src/main/java/li/cil/oc/api/driver/NamedBlock.java 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/java/li/cil/oc/server/driver/CompoundBlockDriver.scala b/src/main/java/li/cil/oc/server/driver/CompoundBlockDriver.scala index 3b319ce31..d46fd8edd 100644 --- a/src/main/java/li/cil/oc/server/driver/CompoundBlockDriver.scala +++ b/src/main/java/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.block.Block import net.minecraft.inventory.IInventory import net.minecraft.item.{Item, ItemStack} @@ -31,6 +32,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.getBlockTileEntity(x, y, z) match { case inventory: IInventory => return inventory.getInvName.stripPrefix("container.") } catch {