mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 10:51:55 -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;
|
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/>
|
* <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
|
* block's component containing the list of methods from all drivers that apply
|
||||||
* to the block.
|
* to the block.
|
||||||
* <p/>
|
* <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
|
* list of methods should be shown for a block - for example, you may want to
|
||||||
* suppress inventory functionality if your TileEntity implements IInventory.
|
* suppress inventory functionality if your TileEntity implements IInventory.
|
||||||
* <p/>
|
* <p/>
|
||||||
* To do so, implement this interface and provide the names of the allowed
|
* To do so, implement this interface in the <em>environment</em> that you
|
||||||
* methods from {@link #whitelistedMethods(World, int, int, int)}.
|
* 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/>
|
* <p/>
|
||||||
* <em>Important</em>: if multiple drivers apply to a single block that each
|
* <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
|
* 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
|
* for. Note that the names must <em>exactly</em> match the names of the
|
||||||
* methods they allow.
|
* methods they allow.
|
||||||
*
|
*
|
||||||
* @param world the world containing the block to get the whitelist for.
|
* @return the list of allowed methods.
|
||||||
* @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.
|
|
||||||
*/
|
*/
|
||||||
String[] whitelistedMethods(World world, int x, int y, int z);
|
String[] whitelistedMethods();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package li.cil.oc.api.driver;
|
package li.cil.oc.api.driver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface can be added to block drivers to provide a 'preferred name' in
|
* This interface can be added to <em>environments</em> generated by block
|
||||||
* case the driver is merged with other block drivers (interface based drivers
|
* drivers to provide a 'preferred name' in case the driver is merged with
|
||||||
* such as for <tt>IInventory</tt>).
|
* 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 {
|
public interface NamedBlock {
|
||||||
/**
|
/**
|
||||||
@ -15,6 +20,5 @@ public interface NamedBlock {
|
|||||||
*
|
*
|
||||||
* @return the preferred name.
|
* @return the preferred name.
|
||||||
*/
|
*/
|
||||||
// TODO Provide world, x, y, z here in the next bigger API version.
|
|
||||||
String preferredName();
|
String preferredName();
|
||||||
}
|
}
|
||||||
|
@ -37,5 +37,5 @@
|
|||||||
@cpw.mods.fml.common.API(
|
@cpw.mods.fml.common.API(
|
||||||
owner = "OpenComputers|Core",
|
owner = "OpenComputers|Core",
|
||||||
provides = "OpenComputersAPI",
|
provides = "OpenComputersAPI",
|
||||||
apiVersion = "1.4.12")
|
apiVersion = "1.4.13")
|
||||||
package li.cil.oc.api;
|
package li.cil.oc.api;
|
@ -9,6 +9,7 @@ import net.minecraft.inventory.IInventory
|
|||||||
import net.minecraft.item.{Item, ItemStack}
|
import net.minecraft.item.{Item, ItemStack}
|
||||||
import net.minecraft.tileentity.TileEntity
|
import net.minecraft.tileentity.TileEntity
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
|
import li.cil.oc.api.network.ManagedEnvironment
|
||||||
|
|
||||||
class CompoundBlockDriver(val blocks: driver.Block*) extends driver.Block {
|
class CompoundBlockDriver(val blocks: driver.Block*) extends driver.Block {
|
||||||
override def createEnvironment(world: World, x: Int, y: Int, z: Int) = {
|
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)
|
} filter (_ != null)
|
||||||
if (list.isEmpty) 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))
|
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
|
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 {
|
for (block <- blocks) block match {
|
||||||
case named: NamedBlock => return named.preferredName
|
case named: NamedBlock => return named.preferredName
|
||||||
case _ =>
|
case _ =>
|
||||||
|
@ -6,9 +6,8 @@ import li.cil.oc.api.network._
|
|||||||
import li.cil.oc.util.ExtendedNBT._
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
import li.cil.oc.{OpenComputers, api}
|
import li.cil.oc.{OpenComputers, api}
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
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,
|
// 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
|
// but let's play it safe and use the least possible visibility based on
|
||||||
// the drivers we encapsulate.
|
// the drivers we encapsulate.
|
||||||
|
@ -157,7 +157,7 @@ object Component {
|
|||||||
case multi: CompoundBlockEnvironment => multi.environments.map {
|
case multi: CompoundBlockEnvironment => multi.environments.map {
|
||||||
case (_, environment) =>
|
case (_, environment) =>
|
||||||
environment match {
|
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 _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
environment.getClass: Class[_]
|
environment.getClass: Class[_]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user