diff --git a/src/main/java/li/cil/oc/api/driver/MethodWhitelist.java b/src/main/java/li/cil/oc/api/driver/MethodWhitelist.java index 655de5989..0bb8814c5 100644 --- a/src/main/java/li/cil/oc/api/driver/MethodWhitelist.java +++ b/src/main/java/li/cil/oc/api/driver/MethodWhitelist.java @@ -1,11 +1,12 @@ package li.cil.oc.api.driver; -import net.minecraft.world.World; - /** - * This interface can be implemented by drivers to enforce a method whitelist. + * This interface can be implemented by environments to enforce a method + * whitelist. *
- * When drivers are collected for a block, they are combined, resulting in the + * When drivers are collected for a block, they are combined into a compound + * driver. This compound driver will in turn generate a compound environment + * that wraps the contributing environments. Which in turn results in the * block's component containing the list of methods from all drivers that apply * to the block. * @@ -13,8 +14,9 @@ import net.minecraft.world.World; * list of methods should be shown for a block - for example, you may want to * suppress inventory functionality if your TileEntity implements IInventory. * - * To do so, implement this interface and provide the names of the allowed - * methods from {@link #whitelistedMethods(World, int, int, int)}. + * To do so, implement this interface in the environment that you + * return from your driver's {@link Block#createEnvironment(net.minecraft.world.World, int, int, int)} + * method, and provide the names of the allowed methods from {@link #whitelistedMethods()}. * * Important: if multiple drivers apply to a single block that each * provide a whitelist, the list of allowed methods is the intersection of the @@ -26,10 +28,7 @@ public interface MethodWhitelist { * for. Note that the names must exactly match the names of the * methods they allow. * - * @param world the world containing the block to get the whitelist for. - * @param x the X coordinate of the block to get the whitelist for. - * @param y the Y coordinate of the block to get the whitelist for. - * @param z the Z coordinate of the block to get the whitelist for. + * @return the list of allowed methods. */ - String[] whitelistedMethods(World world, int x, int y, int z); + String[] whitelistedMethods(); } diff --git a/src/main/java/li/cil/oc/api/driver/NamedBlock.java b/src/main/java/li/cil/oc/api/driver/NamedBlock.java index e78eb9950..4aca4e1e1 100644 --- a/src/main/java/li/cil/oc/api/driver/NamedBlock.java +++ b/src/main/java/li/cil/oc/api/driver/NamedBlock.java @@ -1,9 +1,14 @@ 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). + * This interface can be added to environments generated by block + * drivers to provide a 'preferred name' in case the driver is merged with + * other block drivers (interface based drivers such as for IInventory). + * + * This was previously to be implemented on the driver itself, but that has been + * deprecated. Implement it in the environment returned from the block driver's + * {@link Block#createEnvironment(net.minecraft.world.World, int, int, int)} + * method instead. */ public interface NamedBlock { /** @@ -15,6 +20,5 @@ public interface NamedBlock { * * @return the preferred name. */ - // TODO Provide world, x, y, z here in the next bigger API version. String preferredName(); } diff --git a/src/main/java/li/cil/oc/api/package-info.java b/src/main/java/li/cil/oc/api/package-info.java index 0f727e0da..5eccdfff5 100644 --- a/src/main/java/li/cil/oc/api/package-info.java +++ b/src/main/java/li/cil/oc/api/package-info.java @@ -37,5 +37,5 @@ @cpw.mods.fml.common.API( owner = "OpenComputers|Core", provides = "OpenComputersAPI", - apiVersion = "1.4.12") + apiVersion = "1.4.13") package li.cil.oc.api; \ No newline at end of file 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 5b8070e44..769b3494f 100644 --- a/src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala +++ b/src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala @@ -9,6 +9,7 @@ import net.minecraft.inventory.IInventory import net.minecraft.item.{Item, ItemStack} import net.minecraft.tileentity.TileEntity import net.minecraft.world.World +import li.cil.oc.api.network.ManagedEnvironment class CompoundBlockDriver(val blocks: driver.Block*) extends driver.Block { override def createEnvironment(world: World, x: Int, y: Int, z: Int) = { @@ -19,7 +20,7 @@ class CompoundBlockDriver(val blocks: driver.Block*) extends driver.Block { } } filter (_ != null) if (list.isEmpty) null - else new CompoundBlockEnvironment(world, x, y, z, cleanName(tryGetName(world, x, y, z)), list: _*) + else new CompoundBlockEnvironment(cleanName(tryGetName(world, x, y, z, list.map(_._2))), list: _*) } override def worksWith(world: World, x: Int, y: Int, z: Int) = blocks.forall(_.worksWith(world, x, y, z)) @@ -29,7 +30,12 @@ class CompoundBlockDriver(val blocks: driver.Block*) extends driver.Block { case _ => false } - private def tryGetName(world: World, x: Int, y: Int, z: Int): String = { + 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 _ => + } + // TODO Deprecated, remove in 1.3. for (block <- blocks) block match { case named: NamedBlock => return named.preferredName case _ => diff --git a/src/main/scala/li/cil/oc/server/driver/CompoundBlockEnvironment.scala b/src/main/scala/li/cil/oc/server/driver/CompoundBlockEnvironment.scala index ffad841cf..5ca08c598 100644 --- a/src/main/scala/li/cil/oc/server/driver/CompoundBlockEnvironment.scala +++ b/src/main/scala/li/cil/oc/server/driver/CompoundBlockEnvironment.scala @@ -6,9 +6,8 @@ import li.cil.oc.api.network._ import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.{OpenComputers, api} import net.minecraft.nbt.NBTTagCompound -import net.minecraft.world.World -class CompoundBlockEnvironment(val world: World, val x: Int, val y: Int, val z: Int, val name: String, val environments: (driver.Block, ManagedEnvironment)*) extends ManagedEnvironment { +class CompoundBlockEnvironment(val name: String, val environments: (driver.Block, ManagedEnvironment)*) extends ManagedEnvironment { // Block drivers with visibility < network usually won't make much sense, // but let's play it safe and use the least possible visibility based on // the drivers we encapsulate. diff --git a/src/main/scala/li/cil/oc/server/network/Component.scala b/src/main/scala/li/cil/oc/server/network/Component.scala index f97659a20..b1d3b078a 100644 --- a/src/main/scala/li/cil/oc/server/network/Component.scala +++ b/src/main/scala/li/cil/oc/server/network/Component.scala @@ -157,7 +157,7 @@ object Component { case multi: CompoundBlockEnvironment => multi.environments.map { case (_, environment) => environment match { - case list: MethodWhitelist => whitelists += Option(list.whitelistedMethods(multi.world, multi.x, multi.y, multi.z)).fold(Set.empty[String])(_.toSet) + case list: MethodWhitelist => whitelists += Option(list.whitelistedMethods).fold(Set.empty[String])(_.toSet) case _ => } environment.getClass: Class[_]