mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 02:39:48 -04:00
Corrected documentation on MethodWhitelist (it goes into environments, not drivers).
Deprecated NamedBlock going into drivers, it should go into environments now (it being in drivers will no longer be supported in OC 1.3).
This commit is contained in:
parent
3a4d88f589
commit
0119aa1d46
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
@ -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 _ =>
|
||||
|
@ -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.
|
||||
|
@ -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[_]
|
||||
|
Loading…
x
Reference in New Issue
Block a user