Merge branch 'master' of github.com:MightyPirates/OpenComputers into MC1.7

This commit is contained in:
Florian Nücke 2014-04-06 19:19:47 +02:00
commit 0acecde4e6
6 changed files with 29 additions and 21 deletions

View File

@ -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.
* <p/>
* 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.
* <p/>
@ -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.
* <p/>
* 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 <em>environment</em> 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()}.
* <p/>
* <em>Important</em>: 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 <em>exactly</em> 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();
}

View File

@ -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 <tt>IInventory</tt>).
* This interface can be added to <em>environments</em> 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 <tt>IInventory</tt>).
* <p/>
* 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();
}

View File

@ -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;

View File

@ -8,6 +8,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) = {
@ -18,7 +19,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))
@ -28,7 +29,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 _ =>

View File

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

View File

@ -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[_]