From b3939c0b52fcfe142d57613873dcd89c3d7ad975 Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Sat, 12 Apr 2014 18:49:25 +0100 Subject: [PATCH] Update ComputerCraft API. No idea if I've implemented IPeripheral.equals() correctly, its documentation is not the most helpful. --- .../dan200/computer/api/ComputerCraftAPI.java | 163 ----------- .../computer/api/IHostedPeripheral.java | 44 --- .../computer/api/IPeripheralHandler.java | 15 - .../computercraft/api/ComputerCraftAPI.java | 261 ++++++++++++++++++ .../api/filesystem}/IMount.java | 12 +- .../api/filesystem}/IWritableMount.java | 13 +- .../api/lua}/ILuaContext.java | 14 +- .../api/lua}/ILuaObject.java | 8 +- .../api/media}/IMedia.java | 18 +- .../api/media/IMediaProvider.java | 23 ++ .../api/peripheral}/IComputerAccess.java | 45 +-- .../api/peripheral}/IPeripheral.java | 49 ++-- .../api/peripheral/IPeripheralProvider.java | 23 ++ .../redstone/IBundledRedstoneProvider.java | 23 ++ .../api/turtle/ITurtleAccess.java | 155 +++++++++++ .../api/turtle/ITurtleCommand.java | 25 ++ .../api/turtle}/ITurtleUpgrade.java | 64 ++--- .../api/turtle/TurtleAnimation.java | 21 ++ .../api/turtle/TurtleCommandResult.java | 54 ++++ .../api/turtle}/TurtleSide.java | 6 +- .../api/turtle}/TurtleUpgradeType.java | 6 +- .../api/turtle}/TurtleVerb.java | 4 +- common/dan200/turtle/api/ITurtleAccess.java | 158 ----------- .../turtle/api/ITurtleCommandHandler.java | 25 -- common/dan200/turtle/api/TurtleAPI.java | 78 ------ .../client/render/RenderPartTransmitter.java | 2 +- .../common/IAdvancedBoundingBlock.java | 2 +- .../tile/TileEntityAdvancedBoundingBlock.java | 23 +- .../TileEntityAdvancedElectricMachine.java | 4 +- .../common/tile/TileEntityBasicMachine.java | 8 +- .../common/tile/TileEntityChanceMachine.java | 4 +- .../common/tile/TileEntityDigitalMiner.java | 10 +- .../tile/TileEntityElectricMachine.java | 4 +- .../tile/TileEntityElectrolyticSeparator.java | 10 +- .../common/tile/TileEntityEnergyCube.java | 10 +- .../common/tile/TileEntityFactory.java | 18 +- .../tile/TileEntityMetallurgicInfuser.java | 10 +- .../mekanism/common/tile/TileEntityPRC.java | 4 +- .../common/tile/TileEntityTeleporter.java | 10 +- .../common/tile/TileEntityBioGenerator.java | 4 +- .../common/tile/TileEntityGenerator.java | 16 +- .../common/tile/TileEntityHeatGenerator.java | 4 +- .../tile/TileEntityHydrogenGenerator.java | 4 +- .../common/tile/TileEntitySolarGenerator.java | 4 +- .../common/tile/TileEntityWindTurbine.java | 4 +- 45 files changed, 779 insertions(+), 683 deletions(-) delete mode 100644 common/dan200/computer/api/ComputerCraftAPI.java delete mode 100644 common/dan200/computer/api/IHostedPeripheral.java delete mode 100644 common/dan200/computer/api/IPeripheralHandler.java create mode 100644 common/dan200/computercraft/api/ComputerCraftAPI.java rename common/dan200/{computer/api => computercraft/api/filesystem}/IMount.java (83%) rename common/dan200/{computer/api => computercraft/api/filesystem}/IWritableMount.java (80%) rename common/dan200/{computer/api => computercraft/api/lua}/ILuaContext.java (68%) rename common/dan200/{computer/api => computercraft/api/lua}/ILuaObject.java (74%) rename common/dan200/{computer/api => computercraft/api/media}/IMedia.java (80%) create mode 100644 common/dan200/computercraft/api/media/IMediaProvider.java rename common/dan200/{computer/api => computercraft/api/peripheral}/IComputerAccess.java (55%) rename common/dan200/{computer/api => computercraft/api/peripheral}/IPeripheral.java (69%) create mode 100644 common/dan200/computercraft/api/peripheral/IPeripheralProvider.java create mode 100644 common/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java create mode 100644 common/dan200/computercraft/api/turtle/ITurtleAccess.java create mode 100644 common/dan200/computercraft/api/turtle/ITurtleCommand.java rename common/dan200/{turtle/api => computercraft/api/turtle}/ITurtleUpgrade.java (58%) create mode 100644 common/dan200/computercraft/api/turtle/TurtleAnimation.java create mode 100644 common/dan200/computercraft/api/turtle/TurtleCommandResult.java rename common/dan200/{turtle/api => computercraft/api/turtle}/TurtleSide.java (80%) rename common/dan200/{turtle/api => computercraft/api/turtle}/TurtleUpgradeType.java (79%) rename common/dan200/{turtle/api => computercraft/api/turtle}/TurtleVerb.java (85%) delete mode 100644 common/dan200/turtle/api/ITurtleAccess.java delete mode 100644 common/dan200/turtle/api/ITurtleCommandHandler.java delete mode 100644 common/dan200/turtle/api/TurtleAPI.java diff --git a/common/dan200/computer/api/ComputerCraftAPI.java b/common/dan200/computer/api/ComputerCraftAPI.java deleted file mode 100644 index 9278dd0fe..000000000 --- a/common/dan200/computer/api/ComputerCraftAPI.java +++ /dev/null @@ -1,163 +0,0 @@ -/** - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ - -package dan200.computer.api; -import java.lang.reflect.Method; -import net.minecraft.world.World; - -/** - * The static entry point to the ComputerCraft API. - * Members in this class must be called after mod_ComputerCraft has been initialised, - * but may be called before it is fully loaded. - */ -public class ComputerCraftAPI -{ - /** - * Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.
- * Use in conjuction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
- * @param world The world for which the save dir should be created. This should be the serverside world object. - * @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computer/disk" - * @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
- * eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing. - * @see #createSaveDirMount(World, String) - */ - public static int createUniqueNumberedSaveDir( World world, String parentSubPath ) - { - findCC(); - if( computerCraft_createUniqueNumberedSaveDir != null ) - { - try { - return ((Integer)computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath )).intValue(); - } catch (Exception e){ - // It failed - } - } - return -1; - } - - /** - * Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.
- * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the - * users save directory onto a computers file system.
- * @param world The world for which the save dir can be found. This should be the serverside world object. - * @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".
- * Use createUniqueNumberedSaveDir() to create a new numbered folder to use. - * @param capacity The ammount of data that can be stored in the directory before it fills up, in bytes. - * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() - * to mount this on a Computers' file system. - * @see #createUniqueNumberedSaveDir(World, String) - * @see IComputerAccess#mount(String, IMount) - * @see IComputerAccess#mountWritable(String, IWritableMount) - * @see IMount - * @see IMountWritable - */ - public static IWritableMount createSaveDirMount( World world, String subPath, long capacity ) - { - findCC(); - if( computerCraft_createSaveDirMount != null ) - { - try { - return (IWritableMount)computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity ); - } catch (Exception e){ - // It failed - } - } - return null; - } - - /** - * Creates a file system mount to a resource folder, and returns it.
- * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder onto a computers file system.
- * The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain resources with the same domain and path.
- * @param class A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class - * @param domain The domain under which to look for resources. eg: "mymod" - * @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles" - * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() - * to mount this on a Computers' file system. - * @see IComputerAccess#mount(String, IMount) - * @see IComputerAccess#mountWritable(String, IMountWritable) - * @see IMount - */ - public static IMount createResourceMount( Class modClass, String domain, String subPath ) - { - findCC(); - if( computerCraft_createResourceMount != null ) - { - try { - return (IMount)computerCraft_createResourceMount.invoke( null, modClass, domain, subPath ); - } catch (Exception e){ - // It failed - } - } - return null; - } - - /** - * Registers a peripheral handler for a TileEntity that you do not have access to. Only - * use this if you want to expose IPeripheral on a TileEntity from another mod. For your own - * mod, just implement IPeripheral on the TileEntity directly. - * @see IPeripheral - * @see IPeripheralHandler - */ - public static void registerExternalPeripheral( Class clazz, IPeripheralHandler handler ) - { - findCC(); - if (computerCraft_registerExternalPeripheral != null) - { - try { - computerCraft_registerExternalPeripheral.invoke(null, clazz, handler); - } catch (Exception e){ - // It failed - } - } - } - - // The functions below here are private, and are used to interface with the non-API ComputerCraft classes. - // Reflection is used here so you can develop your mod in MCP without decompiling ComputerCraft and including - // it in your solution. - - private static void findCC() - { - if( !ccSearched ) { - try { - computerCraft = Class.forName( "dan200.ComputerCraft" ); - computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class[] { - World.class, String.class - } ); - computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class[] { - World.class, String.class, Long.TYPE - } ); - computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class[] { - Class.class, String.class, String.class - } ); - computerCraft_registerExternalPeripheral = findCCMethod( "registerExternalPeripheral", new Class[] { - Class.class, IPeripheralHandler.class - } ); - } catch( Exception e ) { - net.minecraft.server.MinecraftServer.getServer().logInfo( "ComputerCraftAPI: ComputerCraft not found." ); - } finally { - ccSearched = true; - } - } - } - - private static Method findCCMethod( String name, Class[] args ) - { - try { - return computerCraft.getMethod( name, args ); - } catch( NoSuchMethodException e ) { - net.minecraft.server.MinecraftServer.getServer().logInfo( "ComputerCraftAPI: ComputerCraft method " + name + " not found." ); - return null; - } - } - - private static boolean ccSearched = false; - private static Class computerCraft = null; - private static Method computerCraft_createUniqueNumberedSaveDir = null; - private static Method computerCraft_createSaveDirMount = null; - private static Method computerCraft_createResourceMount = null; - private static Method computerCraft_registerExternalPeripheral = null; -} diff --git a/common/dan200/computer/api/IHostedPeripheral.java b/common/dan200/computer/api/IHostedPeripheral.java deleted file mode 100644 index 68cf3fd77..000000000 --- a/common/dan200/computer/api/IHostedPeripheral.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ - -package dan200.computer.api; -import dan200.computer.api.IPeripheral; - -/** - * A subclass of IPeripheral specifically for peripherals - * created by ITurtleUpgrade's of type Peripheral. When an - * IHostedPeripheral is created, its IPeripheral methods will be called - * just as if the peripheral was a seperate adjacent block in the world, - * and update() will be called once per tick. - * @see ITurtleUpgrade - */ -public interface IHostedPeripheral extends IPeripheral -{ - /** - * A method called on each hosted peripheral once per tick, on the main thread - * over the lifetime of the turtle or block. May be used to update the state - * of the peripheral, and may interact with IComputerAccess or ITurtleAccess - * however it likes at this time. - */ - public void update(); - - /** - * A method called whenever data is read from the Turtle's NBTTag, - * over the lifetime of the turtle. You should only use this for - * reading data you want to stay with the peripheral. - * @param nbttagcompound The peripheral's NBTTag - */ - public void readFromNBT( net.minecraft.nbt.NBTTagCompound nbttagcompound ); - - /** - * A method called whenever data is written to the Turtle's NBTTag, - * over the lifetime of the turtle. You should only use this for - * writing data you want to stay with the peripheral. - * @param nbttagcompound The peripheral's NBTTag. - * @param ID The turtle's ID. - */ - public void writeToNBT( net.minecraft.nbt.NBTTagCompound nbttagcompound ); -} diff --git a/common/dan200/computer/api/IPeripheralHandler.java b/common/dan200/computer/api/IPeripheralHandler.java deleted file mode 100644 index 18487d854..000000000 --- a/common/dan200/computer/api/IPeripheralHandler.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ - -package dan200.computer.api; - -/** - * TODO: Document me - */ -public interface IPeripheralHandler -{ - public IHostedPeripheral getPeripheral( net.minecraft.tileentity.TileEntity tile ); -} diff --git a/common/dan200/computercraft/api/ComputerCraftAPI.java b/common/dan200/computercraft/api/ComputerCraftAPI.java new file mode 100644 index 000000000..ee7048472 --- /dev/null +++ b/common/dan200/computercraft/api/ComputerCraftAPI.java @@ -0,0 +1,261 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api; + +import dan200.computercraft.api.filesystem.IMount; +import dan200.computercraft.api.filesystem.IWritableMount; +import dan200.computercraft.api.media.IMediaProvider; +import dan200.computercraft.api.peripheral.IPeripheralProvider; +import dan200.computercraft.api.redstone.IBundledRedstoneProvider; +import dan200.computercraft.api.turtle.ITurtleUpgrade; +import net.minecraft.world.World; + +import java.lang.reflect.Method; + +/** + * The static entry point to the ComputerCraft API. + * Members in this class must be called after mod_ComputerCraft has been initialised, + * but may be called before it is fully loaded. + */ +public final class ComputerCraftAPI +{ + /** + * Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.
+ * Use in conjuction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
+ * @param world The world for which the save dir should be created. This should be the serverside world object. + * @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk" + * @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
+ * eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing. + * @see #createSaveDirMount(World, String, long) + */ + public static int createUniqueNumberedSaveDir( World world, String parentSubPath ) + { + findCC(); + if( computerCraft_createUniqueNumberedSaveDir != null ) + { + try { + return ((Integer)computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath )).intValue(); + } catch (Exception e){ + // It failed + } + } + return -1; + } + + /** + * Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.
+ * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the + * users save directory onto a computers file system.
+ * @param world The world for which the save dir can be found. This should be the serverside world object. + * @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".
+ * Use createUniqueNumberedSaveDir() to create a new numbered folder to use. + * @param capacity The ammount of data that can be stored in the directory before it fills up, in bytes. + * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() + * to mount this on a Computers' file system. + * @see #createUniqueNumberedSaveDir(World, String) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount) + * @see dan200.computercraft.api.filesystem.IMount + * @see IWritableMount + */ + public static IWritableMount createSaveDirMount( World world, String subPath, long capacity ) + { + findCC(); + if( computerCraft_createSaveDirMount != null ) + { + try { + return (IWritableMount)computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity ); + } catch (Exception e){ + // It failed + } + } + return null; + } + + /** + * Creates a file system mount to a resource folder, and returns it.
+ * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder onto a computers file system.
+ * The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain resources with the same domain and path.
+ * @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class + * @param domain The domain under which to look for resources. eg: "mymod" + * @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles" + * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() + * to mount this on a Computers' file system. + * @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, IWritableMount) + * @see dan200.computercraft.api.filesystem.IMount + */ + public static IMount createResourceMount( Class modClass, String domain, String subPath ) + { + findCC(); + if( computerCraft_createResourceMount != null ) + { + try { + return (IMount)computerCraft_createResourceMount.invoke( null, modClass, domain, subPath ); + } catch (Exception e){ + // It failed + } + } + return null; + } + + /** + * Registers a peripheral handler to convert blocks into IPeripheral implementations. + * @see dan200.computercraft.api.peripheral.IPeripheral + * @see dan200.computercraft.api.peripheral.IPeripheralProvider + */ + public static void registerPeripheralProvider( IPeripheralProvider handler ) + { + findCC(); + if ( computerCraft_registerPeripheralProvider != null) + { + try { + computerCraft_registerPeripheralProvider.invoke( null, handler ); + } catch (Exception e){ + // It failed + } + } + } + + /** + * Registers a new turtle turtle for use in ComputerCraft. After calling this, + * users should be able to craft Turtles with your new turtle. It is recommended to call + * this during the load() method of your mod. + * @see dan200.computercraft.api.turtle.ITurtleUpgrade + */ + public static void registerTurtleUpgrade( ITurtleUpgrade upgrade ) + { + if( upgrade != null ) + { + findCC(); + if( computerCraft_registerTurtleUpgrade != null ) + { + try { + computerCraft_registerTurtleUpgrade.invoke( null, upgrade ); + } catch( Exception e ) { + // It failed + } + } + } + } + + /** + * Registers a bundled redstone handler to provide bundled redstone output for blocks + * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider + */ + public static void registerBundledRedstoneProvider( IBundledRedstoneProvider handler ) + { + findCC(); + if( computerCraft_registerBundledRedstoneProvider != null ) + { + try { + computerCraft_registerBundledRedstoneProvider.invoke( null, handler ); + } catch (Exception e){ + // It failed + } + } + } + + /** + * If there is a Computer or Turtle at a certain position in the world, get it's bundled redstone output. + * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider + * @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. + * If there is no block capable of emitting bundled redstone at the location, -1 will be returned. + */ + public static int getBundledRedstoneOutput( World world, int x, int y, int z, int side ) + { + findCC(); + if( computerCraft_getDefaultBundledRedstoneOutput != null ) + { + try { + return ((Integer)computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, x, y, z, side )).intValue(); + } catch (Exception e){ + // It failed + } + } + return -1; + } + + /** + * Registers a media handler to provide IMedia implementations for Items + * @see dan200.computercraft.api.media.IMediaProvider + */ + public static void registerMediaProvider( IMediaProvider handler ) + { + findCC(); + if( computerCraft_registerMediaProvider != null ) + { + try { + computerCraft_registerMediaProvider.invoke( null, handler ); + } catch (Exception e){ + // It failed + } + } + } + + // The functions below here are private, and are used to interface with the non-API ComputerCraft classes. + // Reflection is used here so you can develop your mod in MCP without decompiling ComputerCraft and including + // it in your solution. + + private static void findCC() + { + if( !ccSearched ) { + try { + computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" ); + computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class[]{ + World.class, String.class + } ); + computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class[] { + World.class, String.class, Long.TYPE + } ); + computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class[] { + Class.class, String.class, String.class + } ); + computerCraft_registerPeripheralProvider = findCCMethod( "registerPeripheralProvider", new Class[] { + IPeripheralProvider.class + } ); + computerCraft_registerTurtleUpgrade = findCCMethod( "registerTurtleUpgrade", new Class[] { + ITurtleUpgrade.class + } ); + computerCraft_registerBundledRedstoneProvider = findCCMethod( "registerBundledRedstoneProvider", new Class[] { + IBundledRedstoneProvider.class + } ); + computerCraft_getDefaultBundledRedstoneOutput = findCCMethod( "getDefaultBundledRedstoneOutput", new Class[] { + World.class, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE + } ); + computerCraft_registerMediaProvider = findCCMethod( "registerMediaProvider", new Class[] { + IMediaProvider.class + } ); + } catch( Exception e ) { + System.out.println( "ComputerCraftAPI: ComputerCraft not found." ); + } finally { + ccSearched = true; + } + } + } + + private static Method findCCMethod( String name, Class[] args ) + { + try { + return computerCraft.getMethod( name, args ); + } catch( NoSuchMethodException e ) { + System.out.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." ); + return null; + } + } + + private static boolean ccSearched = false; + private static Class computerCraft = null; + private static Method computerCraft_createUniqueNumberedSaveDir = null; + private static Method computerCraft_createSaveDirMount = null; + private static Method computerCraft_createResourceMount = null; + private static Method computerCraft_registerPeripheralProvider = null; + private static Method computerCraft_registerTurtleUpgrade = null; + private static Method computerCraft_registerBundledRedstoneProvider = null; + private static Method computerCraft_getDefaultBundledRedstoneOutput = null; + private static Method computerCraft_registerMediaProvider = null; +} diff --git a/common/dan200/computer/api/IMount.java b/common/dan200/computercraft/api/filesystem/IMount.java similarity index 83% rename from common/dan200/computer/api/IMount.java rename to common/dan200/computercraft/api/filesystem/IMount.java index 69ff32314..e340496be 100644 --- a/common/dan200/computer/api/IMount.java +++ b/common/dan200/computercraft/api/filesystem/IMount.java @@ -1,21 +1,21 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.computer.api; +package dan200.computercraft.api.filesystem; import java.io.IOException; import java.io.InputStream; import java.util.List; /** - * Represents a read only part of a virtual filesystem that can be mounted onto a computer using IComputerAccess.mount(). + * Represents a read only part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount(). * Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount() or ComputerCraftAPI.createResourceMount(), or you're free to implement it yourselves! - * @see ComputerCraftAPI#createSaveDirMount(World, String) - * @see ComputerCraftAPI#createResourceMount(Class, String, String) - * @see IComputerAccess#mount(String, IMount) + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) + * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, IMount) * @see IWritableMount */ public interface IMount diff --git a/common/dan200/computer/api/IWritableMount.java b/common/dan200/computercraft/api/filesystem/IWritableMount.java similarity index 80% rename from common/dan200/computer/api/IWritableMount.java rename to common/dan200/computercraft/api/filesystem/IWritableMount.java index 7fa8db3f1..9c3bb43d5 100644 --- a/common/dan200/computer/api/IWritableMount.java +++ b/common/dan200/computercraft/api/filesystem/IWritableMount.java @@ -1,21 +1,20 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.computer.api; +package dan200.computercraft.api.filesystem; import java.io.IOException; import java.io.OutputStream; -import java.util.List; /** - * Represents a part of a virtual filesystem that can be mounted onto a computer using IComputerAccess.mount() or IComputerAccess.mountWritable(), that can also be written to. + * Represents a part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount() or IComputerAccess.mountWritable(), that can also be written to. * Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount(), or you're free to implement it yourselves! - * @see ComputerCraftAPI#createSaveDirMount(World, String) - * @see IComputerAccess#mountWritable(String, IMount) - * @see IMount + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IMount) + * @see dan200.computercraft.api.filesystem.IMount */ public interface IWritableMount extends IMount { diff --git a/common/dan200/computer/api/ILuaContext.java b/common/dan200/computercraft/api/lua/ILuaContext.java similarity index 68% rename from common/dan200/computer/api/ILuaContext.java rename to common/dan200/computercraft/api/lua/ILuaContext.java index eb3193905..e4ba2414c 100644 --- a/common/dan200/computer/api/ILuaContext.java +++ b/common/dan200/computercraft/api/lua/ILuaContext.java @@ -1,10 +1,10 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.computer.api; +package dan200.computercraft.api.lua; /** * An interface passed to peripherals and ILuaObjects' by computers or turtles, providing methods @@ -15,12 +15,12 @@ package dan200.computer.api; public interface ILuaContext { /** - * Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly equivalent to os.pullEvent() in lua. + * Wait for an event to occur on the computercraft, suspending the thread until it arises. This method is exactly equivalent to os.pullEvent() in lua. * @param filter A specific event to wait for, or null to wait for any event * @return An object array containing the name of the event that occurred, and any event parameters * @throws Exception If the user presses CTRL+T to terminate the current program while pullEvent() is waiting for an event, a "Terminated" exception will be thrown here. - * Do not attempt to block this exception, unless you wish to prevent termination, which is not recommended. - * @throws InterruptedException If the user shuts down or reboots the computer while pullEvent() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computer will leak memory and end up in a broken state. + * Do not attempt to common this exception, unless you wish to prevent termination, which is not recommended. + * @throws InterruptedException If the user shuts down or reboots the computercraft while pullEvent() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. */ public Object[] pullEvent( String filter ) throws Exception, InterruptedException; @@ -28,7 +28,7 @@ public interface ILuaContext * The same as pullEvent(), except "terminated" events are ignored. Only use this if you want to prevent program termination, which is not recommended. This method is exactly equivalent to os.pullEventRaw() in lua. * @param filter A specific event to wait for, or null to wait for any event * @return An object array containing the name of the event that occurred, and any event parameters - * @throws InterruptedException If the user shuts down or reboots the computer while pullEventRaw() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computer will leak memory and end up in a broken state. + * @throws InterruptedException If the user shuts down or reboots the computercraft while pullEventRaw() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. * @see #pullEvent(String) */ public Object[] pullEventRaw( String filter ) throws InterruptedException; @@ -38,7 +38,7 @@ public interface ILuaContext * Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to coroutine.yield() in lua. Use pullEvent() if you wish to wait for events. * @param arguments An object array containing the arguments to pass to coroutine.yield() * @return An object array containing the return values from coroutine.yield() - * @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computer will leak memory and end up in a broken state. + * @throws InterruptedException If the user shuts down or reboots the computercraft the coroutine is suspended, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. * @see #pullEvent(String) */ public Object[] yield( Object[] arguments ) throws InterruptedException; diff --git a/common/dan200/computer/api/ILuaObject.java b/common/dan200/computercraft/api/lua/ILuaObject.java similarity index 74% rename from common/dan200/computer/api/ILuaObject.java rename to common/dan200/computercraft/api/lua/ILuaObject.java index a063fa5b4..7fbd96003 100644 --- a/common/dan200/computer/api/ILuaObject.java +++ b/common/dan200/computercraft/api/lua/ILuaObject.java @@ -1,10 +1,10 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.computer.api; +package dan200.computercraft.api.lua; /** * An interface for representing custom objects returned by IPeripheral.callMethod() calls. @@ -14,13 +14,13 @@ public interface ILuaObject { /** * Get the names of the methods that this object implements. This works the same as IPeripheral.getMethodNames(). See that method for detailed documentation. - * @see IPeripheral#getMethodNames() + * @see dan200.computercraft.api.peripheral.IPeripheral#getMethodNames() */ public String[] getMethodNames(); /** * Called when a user calls one of the methods that this object implements. This works the same as IPeripheral.callMethod(). See that method for detailed documentation. - * @see IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[]) + * @see dan200.computercraft.api.peripheral.IPeripheral#callMethod(dan200.computercraft.api.peripheral.IComputerAccess, ILuaContext, int, Object[]) */ public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws Exception; } diff --git a/common/dan200/computer/api/IMedia.java b/common/dan200/computercraft/api/media/IMedia.java similarity index 80% rename from common/dan200/computer/api/IMedia.java rename to common/dan200/computercraft/api/media/IMedia.java index 52660af03..637a29708 100644 --- a/common/dan200/computer/api/IMedia.java +++ b/common/dan200/computercraft/api/media/IMedia.java @@ -1,12 +1,14 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.computer.api; -import net.minecraft.world.World; +package dan200.computercraft.api.media; + +import dan200.computercraft.api.filesystem.IMount; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; /** * Represents an item that can be placed in a disk drive and used by a Computer. @@ -44,14 +46,14 @@ public interface IMedia public String getAudioRecordName( ItemStack stack ); /** - * If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will be mounted onto the filesystem of the computer while the media is in the disk drive. + * If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will be mounted onto the filesystem of the computercraft while the media is in the disk drive. * @param stack The itemstack to inspect. * @param world The world in which the item and disk drive reside. * @return The mount, or null if this item does not represent an item with data. If the IMount returned also implements IWritableMount, it will mounted using mountWritable() - * @see IMount - * @see IWritableMount - * @see ComputerCraftAPI#createSaveDirMount(World, String) - * @see ComputerCraftAPI#createResourceMount(Class, String, String) + * @see dan200.computercraft.api.filesystem.IMount + * @see dan200.computercraft.api.filesystem.IWritableMount + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long) + * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) */ public IMount createDataMount( ItemStack stack, World world ); } diff --git a/common/dan200/computercraft/api/media/IMediaProvider.java b/common/dan200/computercraft/api/media/IMediaProvider.java new file mode 100644 index 000000000..33e53ed4b --- /dev/null +++ b/common/dan200/computercraft/api/media/IMediaProvider.java @@ -0,0 +1,23 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.media; + +import net.minecraft.item.ItemStack; + +/** + * This interface is used to provide IMedia implementations for ItemStack + * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) + */ +public interface IMediaProvider +{ + /** + * Produce an IMedia implementation from an ItemStack. + * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) + * @return an IMedia implementation, or null if the item is not something you wish to handle + */ + public IMedia getMedia( ItemStack stack ); +} diff --git a/common/dan200/computer/api/IComputerAccess.java b/common/dan200/computercraft/api/peripheral/IComputerAccess.java similarity index 55% rename from common/dan200/computer/api/IComputerAccess.java rename to common/dan200/computercraft/api/peripheral/IComputerAccess.java index 72784a0a0..7d4b6e735 100644 --- a/common/dan200/computer/api/IComputerAccess.java +++ b/common/dan200/computercraft/api/peripheral/IComputerAccess.java @@ -1,10 +1,13 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.computer.api; +package dan200.computercraft.api.peripheral; + +import dan200.computercraft.api.filesystem.IMount; +import dan200.computercraft.api.filesystem.IWritableMount; /** * The interface passed to peripherals by computers or turtles, providing methods @@ -15,24 +18,24 @@ public interface IComputerAccess { /** * Mount a mount onto the computers' file system in a read only mode.
- * @param desiredLoction The location on the computer's file system where you would like the mount to be mounted. - * @param mount The mount object to mount on the computer. These can be obtained by calling ComputerCraftAPI.createSaveDirMount(), ComputerCraftAPI.createResourceMount() or by creating your own objects that implement the IMount interface. - * @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. - * @see ComputerCraftAPI#createSaveDirMount(World, String) - * @see ComputerCraftAPI#createResourceMount(Class, String, String) - * @see #mountWritable(String, IWritableMount) + * @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted. + * @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount(), ComputerCraftAPI.createResourceMount() or by creating your own objects that implement the IMount interface. + * @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) + * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) + * @see #mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount) * @see #unmount(String) - * @see IMount + * @see dan200.computercraft.api.filesystem.IMount */ public String mount( String desiredLocation, IMount mount ); /** * Mount a mount onto the computers' file system in a writable mode.
- * @param desiredLoction The location on the computer's file system where you would like the mount to be mounted. - * @param mount The mount object to mount on the computer. These can be obtained by calling ComputerCraftAPI.createSaveDirMount() or by creating your own objects that implement the IWritableMount interface. - * @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. - * @see ComputerCraftAPI#createSaveDirMount(World, String) - * @see ComputerCraftAPI#createResourceMount(Class, String, String) + * @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted. + * @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount() or by creating your own objects that implement the IWritableMount interface. + * @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) + * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) * @see #mount(String, IMount) * @see #unmount(String) * @see IMount @@ -53,7 +56,7 @@ public interface IComputerAccess public void unmount( String location ); /** - * Returns the numerical ID of this computer.
+ * Returns the numerical ID of this computercraft.
* This is the same number obtained by calling os.getComputerID() or running the "id" program from lua, * and is guarunteed unique. This number will be positive. * @return The identifier. @@ -61,8 +64,8 @@ public interface IComputerAccess public int getID(); /** - * Causes an event to be raised on this computer, which the computer can respond to by calling - * os.pullEvent(). This can be used to notify the computer when things happen in the world or to + * Causes an event to be raised on this computercraft, which the computercraft can respond to by calling + * os.pullEvent(). This can be used to notify the computercraft when things happen in the world or to * this peripheral. * @param event A string identifying the type of event that has occurred, this will be * returned as the first value from os.pullEvent(). It is recommended that you @@ -73,17 +76,17 @@ public interface IComputerAccess * be supplied as extra return values to os.pullEvent(). Objects in the array will be converted * to lua data types in the same fashion as the return values of IPeripheral.callMethod().
* You may supply null to indicate that no arguments are to be supplied. - * @see IPeripheral#callMethod + * @see dan200.computercraft.api.peripheral.IPeripheral#callMethod */ public void queueEvent( String event, Object[] arguments ); /** - * Get a string, unique to the computer, by which the computer refers to this peripheral. + * Get a string, unique to the computercraft, by which the computercraft refers to this peripheral. * For directly attached peripherals this will be "left","right","front","back",etc, but * for peripherals attached remotely it will be different. It is good practice to supply - * this string when raising events to the computer, so that the computer knows from + * this string when raising events to the computercraft, so that the computercraft knows from * which peripheral the event came. - * @return A string unique to the computer, but not globally. + * @return A string unique to the computercraft, but not globally. */ public String getAttachmentName(); } diff --git a/common/dan200/computer/api/IPeripheral.java b/common/dan200/computercraft/api/peripheral/IPeripheral.java similarity index 69% rename from common/dan200/computer/api/IPeripheral.java rename to common/dan200/computercraft/api/peripheral/IPeripheral.java index 672431809..3fff7b826 100644 --- a/common/dan200/computer/api/IPeripheral.java +++ b/common/dan200/computercraft/api/peripheral/IPeripheral.java @@ -1,15 +1,17 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.computer.api; +package dan200.computercraft.api.peripheral; + +import dan200.computercraft.api.lua.ILuaContext; /** * The interface that defines a peripheral. This should be implemented by the - * TileEntity of any block that you wish to be interacted with by - * computer or turtle. + * TileEntity of any common that you wish to be interacted with by + * computercraft or turtle. */ public interface IPeripheral { @@ -30,16 +32,16 @@ public interface IPeripheral public String[] getMethodNames(); /** - * This is called when a lua program on an attached computer calls peripheral.call() with + * This is called when a lua program on an attached computercraft calls peripheral.call() with * one of the methods exposed by getMethodNames().
*
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * when interacting with minecraft objects. - * @param computer The interface to the computer that is making the call. Remember that multiple + * @param computer The interface to the computercraft that is making the call. Remember that multiple * computers can be attached to a peripheral at once. * @param context The context of the currently running lua thread. This can be used to wait for events * or otherwise yield. - * @param method An integer identifying which of the methods from getMethodNames() the computer + * @param method An integer identifying which of the methods from getMethodNames() the computercraft * wishes to call. The integer indicates the index into the getMethodNames() table * that corresponds to the string passed into peripheral.call() * @param arguments An array of objects, representing the arguments passed into peripheral.call().
@@ -60,47 +62,38 @@ public interface IPeripheral public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws Exception; /** - * Is called before the computer attempts to attach to the peripheral, and should return whether to allow - * the attachment. Use this to restrict the number of computers that can attach, or to limit attachments to - * certain world directions.
- * If true is returned, attach() will be called shortly afterwards, and the computer will be able to make method calls. - * If false is returned, attach() will not be called, and the peripheral will be invisible to the computer. - * @param side The world direction (0=bottom, 1=top, etc) that the computer lies relative to the peripheral. - * @return Whether to allow the attachment, as a boolean. - * @see #attach - */ - public boolean canAttachToSide( int side ); - - /** - * Is called when canAttachToSide has returned true, and a computer is attaching to the peripheral. - * This will occur when a peripheral is placed next to an active computer, when a computer is turned on next to a peripheral, + * Is called when canAttachToSide has returned true, and a computercraft is attaching to the peripheral. + * This will occur when a peripheral is placed next to an active computercraft, when a computercraft is turned on next to a peripheral, * or when a turtle travels into a square next to a peripheral. - * Between calls to attach() and detach(), the attached computer can make method calls on the peripheral using peripheral.call(). + * Between calls to attach() and detach(), the attached computercraft can make method calls on the peripheral using peripheral.call(). * This method can be used to keep track of which computers are attached to the peripheral, or to take action when attachment * occurs.
*
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * when interacting with minecraft objects. - * @param computer The interface to the computer that is being attached. Remember that multiple + * @param computer The interface to the computercraft that is being attached. Remember that multiple * computers can be attached to a peripheral at once. - * @see #canAttachToSide * @see #detach */ public void attach( IComputerAccess computer ); /** - * Is called when a computer is detaching from the peripheral. - * This will occur when a computer shuts down, when the peripheral is removed while attached to computers, + * Is called when a computercraft is detaching from the peripheral. + * This will occur when a computercraft shuts down, when the peripheral is removed while attached to computers, * or when a turtle moves away from a square attached to a peripheral. * This method can be used to keep track of which computers are attached to the peripheral, or to take action when detachment * occurs.
*
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * when interacting with minecraft objects. - * @param computer The interface to the computer that is being detached. Remember that multiple + * @param computer The interface to the computercraft that is being detached. Remember that multiple * computers can be attached to a peripheral at once. - * @see #canAttachToSide * @see #detach */ public void detach( IComputerAccess computer ); + + /** + * TODO: Document me + */ + public boolean equals( IPeripheral other ); } diff --git a/common/dan200/computercraft/api/peripheral/IPeripheralProvider.java b/common/dan200/computercraft/api/peripheral/IPeripheralProvider.java new file mode 100644 index 000000000..aeb354f3b --- /dev/null +++ b/common/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -0,0 +1,23 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.peripheral; + +import net.minecraft.world.World; + +/** + * This interface is used to create peripheral implementations for blocks + * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) + */ +public interface IPeripheralProvider +{ + /** + * Produce an peripheral implementation from a block location. + * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) + * @return a peripheral, or null if there is not a peripheral here you'd like to handle. + */ + public IPeripheral getPeripheral( World world, int x, int y, int z, int side ); +} diff --git a/common/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java b/common/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java new file mode 100644 index 000000000..6d5d400dd --- /dev/null +++ b/common/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java @@ -0,0 +1,23 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.redstone; + +import net.minecraft.world.World; + +/** + * This interface is used to provide bundled redstone output for blocks + * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) + */ +public interface IBundledRedstoneProvider +{ + /** + * Produce an bundled redstone output from a block location. + * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) + * @return a number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to handle this block + */ + public int getBundledRedstoneOutput( World world, int x, int y, int z, int side ); +} diff --git a/common/dan200/computercraft/api/turtle/ITurtleAccess.java b/common/dan200/computercraft/api/turtle/ITurtleAccess.java new file mode 100644 index 000000000..34851eb76 --- /dev/null +++ b/common/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -0,0 +1,155 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.peripheral.IPeripheral; +import net.minecraft.inventory.IInventory; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +/** + * The interface passed to turtle by turtles, providing methods that they can call. + * This should not be implemented by your classes. Do not interact with turtles except via this interface and ITurtleUpgrade. + */ +public interface ITurtleAccess +{ + /** + * Returns the world in which the turtle resides. + * @return the world in which the turtle resides. + */ + public World getWorld(); + + /** + * Returns a vector containing the integer co-ordinates at which the turtle resides. + * @return a vector containing the integer co-ordinates at which the turtle resides. + */ + public ChunkCoordinates getPosition(); + + /** + * TODO: Document me + */ + public boolean teleportTo( World world, int x, int y, int z ); + + /** + * Returns a vector containing the floating point co-ordinates at which the turtle is rendered. + * This will shift when the turtle is moving. + * @param f The subframe fraction + * @return a vector containing the floating point co-ordinates at which the turtle resides. + */ + public Vec3 getVisualPosition( float f ); + + /** + * TODO: Document me + */ + public float getVisualYaw( float f ); + + /** + * Returns the world direction the turtle is currently facing. + * @return the world direction the turtle is currently facing. + */ + public int getDirection(); + + /** + * TODO: Document me + */ + public void setDirection( int dir ); + + /** + * TODO: Document me + */ + public int getSelectedSlot(); + + /** + * TODO: Document me + */ + public void setSelectedSlot( int slot ); + + /** + * TODO: Document me + */ + public IInventory getInventory(); + + /** + * TODO: Document me + */ + public boolean isFuelNeeded(); + + /** + * TODO: Document me + */ + public int getFuelLevel(); + + /** + * TODO: Document me + */ + public void setFuelLevel( int fuel ); + + /** + * TODO: Document me + */ + public int getFuelLimit(); + + /** + * Removes some fuel from the turtles fuel supply. Negative numbers can be passed in to INCREASE the fuel level of the turtle. + * @return Whether the turtle was able to consume the ammount of fuel specified. Will return false if you supply a number + * greater than the current fuel level of the turtle. + */ + public boolean consumeFuel( int fuel ); + + /** + * TODO: Document me + */ + public void addFuel( int fuel ); + + /** + * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed + * on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up + * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will + * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the + * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. + * @param command an object which will execute the custom command when its point in the queue is reached + * @return the objects the command returned when executed. you should probably return these to the player + * unchanged if called from a peripheral method. + * @see ITurtleCommand + */ + public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws Exception; + + /** + * TODO: Document me + */ + public void playAnimation( TurtleAnimation animation ); + + /** + * Returns the turtle on the specified side of the turtle, if there is one. + * @return the turtle on the specified side of the turtle, if there is one. + */ + public ITurtleUpgrade getUpgrade( TurtleSide side ); + + /** + * TODO: Document me + */ + public void setUpgrade( TurtleSide side, ITurtleUpgrade upgrade ); + + /** + * Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one. + * @return the peripheral created by the upgrade on the specified side of the turtle, if there is one. + */ + public IPeripheral getPeripheral( TurtleSide side ); + + /** + * TODO: Document me + */ + public NBTTagCompound getUpgradeNBTData( TurtleSide side ); + + /** + * TODO: Document me + */ + public void updateUpgradeNBTData( TurtleSide side ); +} diff --git a/common/dan200/computercraft/api/turtle/ITurtleCommand.java b/common/dan200/computercraft/api/turtle/ITurtleCommand.java new file mode 100644 index 000000000..0d37d8785 --- /dev/null +++ b/common/dan200/computercraft/api/turtle/ITurtleCommand.java @@ -0,0 +1,25 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +/** + * An interface for objects executing custom turtle commands, used with ITurtleAccess.issueCommand + * @see ITurtleAccess#issueCommand(ITurtleCommand) + */ +public interface ITurtleCommand +{ + /** + * Will be called by the turtle on the main thread when it is time to execute the custom command. + * The handler should either perform the work of the command, and return success, or return + * failure with an error message to indicate the command cannot be executed at this time. + * @param turtle access to the turtle for whom the command was issued + * @return TurtleCommandResult.success() or TurtleCommandResult.failure( errorMessage ) + * @see ITurtleAccess#issueCommand(ITurtleCommand) + * @see dan200.computercraft.api.turtle.TurtleCommandResult + */ + public TurtleCommandResult execute( ITurtleAccess turtle ); +} diff --git a/common/dan200/turtle/api/ITurtleUpgrade.java b/common/dan200/computercraft/api/turtle/ITurtleUpgrade.java similarity index 58% rename from common/dan200/turtle/api/ITurtleUpgrade.java rename to common/dan200/computercraft/api/turtle/ITurtleUpgrade.java index 3af5127b6..8d9e1c6a1 100644 --- a/common/dan200/turtle/api/ITurtleUpgrade.java +++ b/common/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -1,39 +1,41 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.turtle.api; +package dan200.computercraft.api.turtle; + +import dan200.computercraft.api.peripheral.IPeripheral; +import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; -import dan200.computer.api.*; /** - * The primary interface for defining an upgrade for Turtles. A turtle upgrade + * The primary interface for defining an turtle for Turtles. A turtle turtle * can either be a new tool, or a new peripheral. - * @see TurtleAPI#registerUpgrade( ITurtleUpgrade ) + * @see dan200.computercraft.api.ComputerCraftAPI#registerUpgrade( ITurtleUpgrade ) */ public interface ITurtleUpgrade { /** - * Gets a unique numerical identifier representing this type of turtle upgrade. - * Like Minecraft block and item IDs, you should strive to make this number unique - * among all turtle upgrades that have been released for ComputerCraft. + * Gets a unique numerical identifier representing this type of turtle turtle. + * Like Minecraft common and item IDs, you should strive to make this number unique + * among all turtle turtle that have been released for ComputerCraft. * The ID must be in the range 64 to 255, as the ID is stored as an 8-bit value, - * and 0-64 is reserved for future use by ComputerCraft. The upgrade will + * and 0-64 is reserved for future use by ComputerCraft. The turtle will * fail registration if an already used ID is specified. - * @see TurtleAPI#registerUpgrade( ITurtleUpgrade ) + * @see dan200.computercraft.api.ComputerCraftAPI#registerUpgrade( ITurtleUpgrade ) */ public int getUpgradeID(); /** - * Return a String to describe this type of upgrade in turtle item names. + * Return a String to describe this type of turtle in turtle item names. * Examples of built-in adjectives are "Wireless", "Mining" and "Crafty". */ public String getAdjective(); /** - * Return whether this upgrade adds a tool or a peripheral to the turtle. + * Return whether this turtle adds a tool or a peripheral to the turtle. * Currently, turtle crafting is restricted to one tool & one peripheral per turtle. * @see TurtleUpgradeType for the differences between the two. */ @@ -41,31 +43,26 @@ public interface ITurtleUpgrade /** * Return an item stack representing the type of item that a turtle must be crafted - * with to create a turtle which holds this upgrade. + * with to create a turtle which holds this turtle. * Currently, turtle crafting is restricted to one tool & one peripheral per turtle. */ - public net.minecraft.item.ItemStack getCraftingItem(); + public ItemStack getCraftingItem(); - /** - * Return whether this turtle upgrade is an easter egg, and should be attempted to be hidden - * from the creative mode inventory and recipe book plugins. - */ - public boolean isSecret(); - - /** - * Will only be called for Peripheral upgrades. Creates a peripheral for a turtle - * being placed using this upgrade. The peripheral created will be stored + /** + * Will only be called for Peripheral turtle. Creates a peripheral for a turtle + * being placed using this turtle. The peripheral created will be stored * for the lifetime of the turtle, will have update() called once-per-tick, and will be * attach'd detach'd and have methods called in the same manner as a Computer peripheral. - * @param turtle Access to the turtle that the peripheral is being created for. - * @param side Which side of the turtle (left or right) that the upgrade resides on. - * @returns The newly created peripheral. You may return null if this upgrade is a Tool + * + * @param turtle Access to the turtle that the peripheral is being created for. + * @param side Which side of the turtle (left or right) that the turtle resides on. + * @return The newly created peripheral. You may return null if this turtle is a Tool * and this method is not expected to be called. */ - public IHostedPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side ); + public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side ); /** - * Will only be called for Tool upgrades. Called when turtle.dig() or turtle.attack() is called + * Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called * by the turtle, and the tool is required to do some work. * @param turtle Access to the turtle that the tool resides on. * @param side Which side of the turtle (left or right) the tool resides on. @@ -75,13 +72,13 @@ public interface ITurtleUpgrade * whether dig, digUp or digDown was called. * @return Whether the turtle was able to perform the action, and hence whether the turtle.dig() * or turtle.attack() lua method should return true. If true is returned, the tool will perform - * a swinging animation. You may return false if this upgrade is a Peripheral + * a swinging animation. You may return null if this turtle is a Peripheral * and this method is not expected to be called. */ - public boolean useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, int direction ); + public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, int direction ); /** - * Called to obtain the Icon to be used when rendering a turtle peripheral. Needs to be a "block" + * Called to obtain the Icon to be used when rendering a turtle peripheral. Needs to be a "common" * type Icon for now, as there is no way to determine which texture sheet an Icon is from by the * Icon itself. * @param turtle Access to the turtle that the peripheral resides on. @@ -89,4 +86,9 @@ public interface ITurtleUpgrade * @return The Icon that you wish to be used to render your turtle peripheral. */ public Icon getIcon( ITurtleAccess turtle, TurtleSide side ); + + /** + * TODO: Document me + */ + public void update( ITurtleAccess turtle, TurtleSide side ); } diff --git a/common/dan200/computercraft/api/turtle/TurtleAnimation.java b/common/dan200/computercraft/api/turtle/TurtleAnimation.java new file mode 100644 index 000000000..b907e6247 --- /dev/null +++ b/common/dan200/computercraft/api/turtle/TurtleAnimation.java @@ -0,0 +1,21 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +public enum TurtleAnimation +{ + None, + MoveForward, + MoveBack, + MoveUp, + MoveDown, + TurnLeft, + TurnRight, + SwingLeftTool, + SwingRightTool, + Wait, +} diff --git a/common/dan200/computercraft/api/turtle/TurtleCommandResult.java b/common/dan200/computercraft/api/turtle/TurtleCommandResult.java new file mode 100644 index 000000000..7a94ae6f6 --- /dev/null +++ b/common/dan200/computercraft/api/turtle/TurtleCommandResult.java @@ -0,0 +1,54 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +public final class TurtleCommandResult +{ + private static final TurtleCommandResult s_success = new TurtleCommandResult( true, null ); + private static final TurtleCommandResult s_emptyFailure = new TurtleCommandResult( false, null ); + + public static TurtleCommandResult success() + { + return s_success; + } + + public static TurtleCommandResult failure() + { + return failure( null ); + } + + public static TurtleCommandResult failure( String errorMessage ) + { + if( errorMessage != null ) + { + return new TurtleCommandResult( false, errorMessage ); + } + else + { + return s_emptyFailure; + } + } + + private final boolean m_success; + private final String m_errorMessage; + + private TurtleCommandResult( boolean success, String errorMessage ) + { + m_success = success; + m_errorMessage = errorMessage; + } + + public boolean isSuccess() + { + return m_success; + } + + public String getErrorMessage() + { + return m_errorMessage; + } +} diff --git a/common/dan200/turtle/api/TurtleSide.java b/common/dan200/computercraft/api/turtle/TurtleSide.java similarity index 80% rename from common/dan200/turtle/api/TurtleSide.java rename to common/dan200/computercraft/api/turtle/TurtleSide.java index 3459d7772..e125d8010 100644 --- a/common/dan200/turtle/api/TurtleSide.java +++ b/common/dan200/computercraft/api/turtle/TurtleSide.java @@ -1,13 +1,13 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.turtle.api; +package dan200.computercraft.api.turtle; /** - * An enum representing the two sides of the turtle that a turtle upgrade might reside. + * An enum representing the two sides of the turtle that a turtle turtle might reside. */ public enum TurtleSide { diff --git a/common/dan200/turtle/api/TurtleUpgradeType.java b/common/dan200/computercraft/api/turtle/TurtleUpgradeType.java similarity index 79% rename from common/dan200/turtle/api/TurtleUpgradeType.java rename to common/dan200/computercraft/api/turtle/TurtleUpgradeType.java index a65fed8ac..ef84ee9b1 100644 --- a/common/dan200/turtle/api/TurtleUpgradeType.java +++ b/common/dan200/computercraft/api/turtle/TurtleUpgradeType.java @@ -1,13 +1,13 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.turtle.api; +package dan200.computercraft.api.turtle; /** - * An enum representing the two different types of upgrades that an ITurtleUpgrade + * An enum representing the two different types of turtle that an ITurtleUpgrade * implementation can add to a turtle. * @see ITurtleUpgrade */ diff --git a/common/dan200/turtle/api/TurtleVerb.java b/common/dan200/computercraft/api/turtle/TurtleVerb.java similarity index 85% rename from common/dan200/turtle/api/TurtleVerb.java rename to common/dan200/computercraft/api/turtle/TurtleVerb.java index a1b2531af..3a8fb092e 100644 --- a/common/dan200/turtle/api/TurtleVerb.java +++ b/common/dan200/computercraft/api/turtle/TurtleVerb.java @@ -1,10 +1,10 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -package dan200.turtle.api; +package dan200.computercraft.api.turtle; /** * An enum representing the two different actions that an ITurtleUpgrade of type diff --git a/common/dan200/turtle/api/ITurtleAccess.java b/common/dan200/turtle/api/ITurtleAccess.java deleted file mode 100644 index f996bf47e..000000000 --- a/common/dan200/turtle/api/ITurtleAccess.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ - -package dan200.turtle.api; -import dan200.computer.api.*; - -/** - * The interface passed to upgrades by turtles, providing methods that they can call. - * This should not be implemented by your classes. Do not interact with turtles except via this interface and ITurtleUpgrade. - */ -public interface ITurtleAccess -{ - /** - * Returns the world in which the turtle resides. - * @return the world in which the turtle resides. - */ - public net.minecraft.world.World getWorld(); - - /** - * Returns a vector containing the integer block co-ordinates at which the turtle resides. - * @return a vector containing the integer block co-ordinates at which the turtle resides. - */ - public net.minecraft.util.Vec3 getPosition(); - - /** - * Returns a vector containing the co-ordinates at which the turtle is rendered. - * This will shift when the turtle is moving. - * @param f The subframe fraction - * @return a vector containing the integer block co-ordinates at which the turtle resides. - */ - public net.minecraft.util.Vec3 getVisualPosition( float f ); - - /** - * Returns the world direction the turtle is currently facing. - * @return the world direction the turtle is currently facing. - */ - public int getFacingDir(); - - /** - * Returns the size of the turtles inventory, in number of slots. This will currently always be 16. - * @return the size of the turtles inventory, in number of slots. This will currently always be 16. - */ - public int getInventorySize(); - - /** - * Returns which slot the turtle currently has selected in its inventory using turtle.select(). - * Unlike the 1-based lua representation, this will be between 0 and getInventorySize() - 1. - * @return which slot the turtle currently has selected in its inventory - */ - public int getSelectedSlot(); - - /** - * Returns the item stack that the turtle has in one of its inventory slots. - * @param index which inventory slot to retreive, should be between 0 and getInventorySize() - 1 - * @return the item stack that the turtle has in one of its inventory slots. May be null. - */ - public net.minecraft.item.ItemStack getSlotContents( int index ); - - /** - * Changes the item stack that the turtle has in one of its inventory slots. - * @param index which inventory slot to change, should be between 0 and getInventorySize() - 1 - * @param stack an item stack to put in the slot. May be null. - */ - public void setSlotContents( int index, net.minecraft.item.ItemStack stack ); - - /** - * Tries to store an item stack into the turtles current inventory, starting from the turtles - * currently selected inventory slot. - * @param stack The item stack to try and store. - * @return true if the stack was completely stored in the inventory, false if - * it was only partially stored, or could not fit at all. If false is returned - * and the stack was partially stored, the ItemStack passed into "stack" will now - * represent the stack of items that is left over. - */ - public boolean storeItemStack( net.minecraft.item.ItemStack stack ); - - /** - * Drops an item stack from the turtle onto the floor, or into an inventory is there is one - * adjacent to the turtle in the direction specified. - * @param stack The item stack to drop. - * @param dir The world direction to drop the item - * @return true if the stack was dropped, or completely stored in the adjacent inventory, false if - * it was only partially stored in the adjacent inventory, or could not fit at all. If false is returned - * and the stack was partially stored, the ItemStack passed into "stack" will now - * represent the stack of items that is left over. - */ - public boolean dropItemStack( net.minecraft.item.ItemStack stack, int dir ); - - /** - * "Deploys" an item stack in the direction specified. This simulates a player right clicking, and calls onItemUse() on the Item class. - * Will return true if some kind of deployment happened, and may modify the item stack. For block item types, this can be - * used to place blocks. Some kinds of items (such as shears when facing a sheep) may modify the turtles inventory during this call. - * @param stack The item stack to deploy - * @param dir The world direction to deploy the item - * @return true if the stack was deployed, false if it was not. - */ - public boolean deployWithItemStack( net.minecraft.item.ItemStack stack, int dir ); - - /** - * Tries to "attack" entities with an item stack in the direction specified. This simulates a player left clicking, but will - * not affect blocks. If an entity is attacked and killed during this call, its dropped items will end up in the turtles - * inventory. - * @param stack The item stack to attack with - * @param dir The world direction to attack with the item - * @return true if something was attacked, false if it was not - */ - public boolean attackWithItemStack( net.minecraft.item.ItemStack stack, int dir, float damageMultiplier ); - - /** - * Returns the current fuel level of the turtle, this is the same integer returned by turtle.getFuelLevel(), - * that decreases by 1 every time the turtle moves. Can be used to have your tool or peripheral require or supply - * fuel to the turtle. - * @return the fuel level - */ - public int getFuelLevel(); - - /** - * Tries to increase the fuel level of a turtle by burning an item stack. If the item passed in is a fuel source, fuel - * will increase and true will be returned. Otherwise, nothing will happen and false will be returned. - * @param stack The stack to try to refuel with - * @return Whether the turtle was refueled - */ - public boolean refuelWithItemStack( net.minecraft.item.ItemStack stack ); - - /** - * Removes some fuel from the turtles fuel supply. Negative numbers can be passed in to INCREASE the fuel level of the turtle. - * @return Whether the turtle was able to consume the ammount of fuel specified. Will return false if you supply a number - * greater than the current fuel level of the turtle. - */ - public boolean consumeFuel( int fuel ); - - /** - * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed - * on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up - * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will - * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the - * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. - * @param handler an object which will execute the custom command when its point in the queue is reached - * @return the unique command identifier described above - * @see ITurtleCommandHandler - */ - public int issueCommand( ITurtleCommandHandler handler ); - - /** - * Returns the upgrade on the specified side of the turtle, if there is one. - * @return the upgrade on the specified side of the turtle, if there is one. - */ - public ITurtleUpgrade getUpgrade( TurtleSide side ); - - /** - * Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one. - * @return the peripheral created by the upgrade on the specified side of the turtle, if there is one. - */ - public IHostedPeripheral getPeripheral( TurtleSide side ); -} diff --git a/common/dan200/turtle/api/ITurtleCommandHandler.java b/common/dan200/turtle/api/ITurtleCommandHandler.java deleted file mode 100644 index 255d28e22..000000000 --- a/common/dan200/turtle/api/ITurtleCommandHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ - -package dan200.turtle.api; - -/** - * An interface for objects executing custom turtle commands, used with ITurtleAccess.issueCommand - * @see ITurtleAccess#issueCommand( ITurtleCommandHandler ) - */ -public interface ITurtleCommandHandler -{ - /** - * Will be called by the turtle on the main thread when it is time to execute the custom command. - * The handler should either perform the work of the command, and return true for success, or return - * false to indicate failure if the command cannot be executed at this time. - * @param turtle access to the turtle for whom the command was issued - * @return true for success, false for failure. If true is returned, the turtle will wait 0.4 seconds - * before executing the next command in its queue, as it does for the standard turtle commands. - * @see ITurtleAccess#issueCommand( ITurtleCommandHandler ) - */ - public boolean handleCommand( ITurtleAccess turtle ); -} diff --git a/common/dan200/turtle/api/TurtleAPI.java b/common/dan200/turtle/api/TurtleAPI.java deleted file mode 100644 index 3e3c5c1f2..000000000 --- a/common/dan200/turtle/api/TurtleAPI.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only. - * For help using the API, and posting your mods, visit the forums at computercraft.info. - */ - -package dan200.turtle.api; -import java.lang.reflect.Method; - -/** - * The static entry point to the ComputerCraft Turtle Upgrade API. - * Members in this class must be called after mod_CCTurtle has been initialised, - * but may be called before it is fully loaded. - */ -public class TurtleAPI -{ - /** - * Registers a new turtle upgrade for use in ComputerCraft. After calling this, - * users should be able to craft Turtles with your new upgrade. It is recommended to call - * this during the load() method of your mod. - * @throws Exception if you try to register an upgrade with an already used or reserved upgradeID - * @see ITurtleUpgrade - */ - public static void registerUpgrade( ITurtleUpgrade upgrade ) - { - if( upgrade != null ) - { - findCCTurtle(); - if( ccTurtle_registerTurtleUpgrade != null ) - { - try { - ccTurtle_registerTurtleUpgrade.invoke( null, new Object[]{ upgrade } ); - } catch( Exception e ) { - // It failed - } - } - } - } - - // The functions below here are private, and are used to interface with the non-API ComputerCraft classes. - // Reflection is used here so you can develop your mod in MCP without decompiling ComputerCraft and including - // it in your solution. - - private static void findCCTurtle() - { - if( !ccTurtleSearched ) { - // Search for CCTurtle - try { - ccTurtle = Class.forName( "dan200.CCTurtle" ); - ccTurtle_registerTurtleUpgrade = findCCTurtleMethod( "registerTurtleUpgrade", new Class[] { - ITurtleUpgrade.class - } ); - - } catch( ClassNotFoundException e ) { - System.out.println("ComputerCraftAPI: CCTurtle not found."); - - } finally { - ccTurtleSearched = true; - - } - } - } - - private static Method findCCTurtleMethod( String name, Class[] args ) - { - try { - return ccTurtle.getMethod( name, args ); - - } catch( NoSuchMethodException e ) { - System.out.println("ComputerCraftAPI: CCTurtle method " + name + " not found."); - return null; - } - } - - private static boolean ccTurtleSearched = false; - private static Class ccTurtle = null; - private static Method ccTurtle_registerTurtleUpgrade = null; -} diff --git a/common/mekanism/client/render/RenderPartTransmitter.java b/common/mekanism/client/render/RenderPartTransmitter.java index 7d8636972..a9ff77d98 100644 --- a/common/mekanism/client/render/RenderPartTransmitter.java +++ b/common/mekanism/client/render/RenderPartTransmitter.java @@ -288,7 +288,7 @@ public class RenderPartTransmitter implements IIconRegister CCRenderState.changeTexture(MekanismRenderer.getBlocksTexture()); GL11.glTranslated(pos.x, pos.y, pos.z); - + boolean gas = fluid.isGaseous(); for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) diff --git a/common/mekanism/common/IAdvancedBoundingBlock.java b/common/mekanism/common/IAdvancedBoundingBlock.java index 5943c8ccc..1d6ee6cf8 100644 --- a/common/mekanism/common/IAdvancedBoundingBlock.java +++ b/common/mekanism/common/IAdvancedBoundingBlock.java @@ -10,7 +10,7 @@ import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import buildcraft.api.power.IPowerReceptor; import cofh.api.energy.IEnergyHandler; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IPeripheral; public interface IAdvancedBoundingBlock extends IBoundingBlock, ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IPowerReceptor, IEnergyTile, IStrictEnergyStorage, IEnergyHandler, IPeripheral, IFilterAccess { diff --git a/common/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java b/common/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java index 19f4114e2..ca2f8a2bc 100644 --- a/common/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java +++ b/common/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java @@ -19,9 +19,9 @@ import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler.PowerReceiver; import cofh.api.energy.IEnergyHandler; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.peripheral.IPeripheral; public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock implements ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IPowerReceptor, IEnergyTile, IStrictEnergyStorage, IEnergyHandler, IPeripheral, IFilterAccess { @@ -440,17 +440,6 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp return getInv().callMethod(computer, context, method, arguments); } - @Override - public boolean canAttachToSide(int side) - { - if(getInv() == null) - { - return false; - } - - return getInv().canAttachToSide(side); - } - @Override public void attach(IComputerAccess computer) { @@ -473,6 +462,12 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp getInv().detach(computer); } + @Override + public boolean equals(IPeripheral other) + { + return this == other; + } + @Override public NBTTagCompound getFilterData(NBTTagCompound nbtTags) { diff --git a/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java b/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java index 9ddfcfd69..fbd6ef008 100644 --- a/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java +++ b/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java @@ -26,8 +26,8 @@ import net.minecraftforge.common.ForgeDirection; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicMachine implements IGasHandler, ITubeConnection { diff --git a/common/mekanism/common/tile/TileEntityBasicMachine.java b/common/mekanism/common/tile/TileEntityBasicMachine.java index ab9027fff..afe21a30d 100644 --- a/common/mekanism/common/tile/TileEntityBasicMachine.java +++ b/common/mekanism/common/tile/TileEntityBasicMachine.java @@ -23,8 +23,8 @@ import net.minecraft.util.ResourceLocation; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.peripheral.IPeripheral; public abstract class TileEntityBasicMachine extends TileEntityElectricBlock implements IElectricMachine, IPeripheral, IActiveState, IInvConfiguration, IUpgradeTile, IHasSound, IRedstoneControl { @@ -245,9 +245,9 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp } @Override - public boolean canAttachToSide(int side) + public boolean equals(IPeripheral other) { - return true; + return this == other; } @Override diff --git a/common/mekanism/common/tile/TileEntityChanceMachine.java b/common/mekanism/common/tile/TileEntityChanceMachine.java index d46d7e35b..031bab9a6 100644 --- a/common/mekanism/common/tile/TileEntityChanceMachine.java +++ b/common/mekanism/common/tile/TileEntityChanceMachine.java @@ -14,8 +14,8 @@ import mekanism.common.util.InventoryUtils; import mekanism.common.util.MekanismUtils; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; public class TileEntityChanceMachine extends TileEntityBasicMachine { diff --git a/common/mekanism/common/tile/TileEntityDigitalMiner.java b/common/mekanism/common/tile/TileEntityDigitalMiner.java index 90f928337..b4088e06e 100644 --- a/common/mekanism/common/tile/TileEntityDigitalMiner.java +++ b/common/mekanism/common/tile/TileEntityDigitalMiner.java @@ -48,9 +48,9 @@ import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.peripheral.IPeripheral; public class TileEntityDigitalMiner extends TileEntityElectricBlock implements IPeripheral, IUpgradeTile, IRedstoneControl, IActiveState, IAdvancedBoundingBlock { @@ -1283,9 +1283,9 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I } @Override - public boolean canAttachToSide(int side) + public boolean equals(IPeripheral other) { - return true; + return this == other; } @Override diff --git a/common/mekanism/common/tile/TileEntityElectricMachine.java b/common/mekanism/common/tile/TileEntityElectricMachine.java index c0dfd9b13..b8fc5d904 100644 --- a/common/mekanism/common/tile/TileEntityElectricMachine.java +++ b/common/mekanism/common/tile/TileEntityElectricMachine.java @@ -11,8 +11,8 @@ import mekanism.common.util.InventoryUtils; import mekanism.common.util.MekanismUtils; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; public abstract class TileEntityElectricMachine extends TileEntityBasicMachine { diff --git a/common/mekanism/common/tile/TileEntityElectrolyticSeparator.java b/common/mekanism/common/tile/TileEntityElectrolyticSeparator.java index a6211ffa8..2b29e916f 100644 --- a/common/mekanism/common/tile/TileEntityElectrolyticSeparator.java +++ b/common/mekanism/common/tile/TileEntityElectrolyticSeparator.java @@ -37,9 +37,9 @@ import net.minecraftforge.fluids.IFluidHandler; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.peripheral.IPeripheral; public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock implements IFluidHandler, IPeripheral, ITubeConnection, ISustainedTank, IGasHandler { @@ -537,9 +537,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp } @Override - public boolean canAttachToSide(int side) + public boolean equals(IPeripheral other) { - return true; + return this == other; } @Override diff --git a/common/mekanism/common/tile/TileEntityEnergyCube.java b/common/mekanism/common/tile/TileEntityEnergyCube.java index 2b2f1a145..8bb01113d 100644 --- a/common/mekanism/common/tile/TileEntityEnergyCube.java +++ b/common/mekanism/common/tile/TileEntityEnergyCube.java @@ -19,9 +19,9 @@ import net.minecraftforge.common.ForgeDirection; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.peripheral.IPeripheral; public class TileEntityEnergyCube extends TileEntityElectricBlock implements IPeripheral, IRedstoneControl { @@ -180,9 +180,9 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IPe } @Override - public boolean canAttachToSide(int side) + public boolean equals(IPeripheral other) { - return true; + return this == other; } @Override diff --git a/common/mekanism/common/tile/TileEntityFactory.java b/common/mekanism/common/tile/TileEntityFactory.java index b89433dd4..0048981f2 100644 --- a/common/mekanism/common/tile/TileEntityFactory.java +++ b/common/mekanism/common/tile/TileEntityFactory.java @@ -39,9 +39,9 @@ import net.minecraftforge.common.ForgeDirection; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.peripheral.IPeripheral; public class TileEntityFactory extends TileEntityElectricBlock implements IPeripheral, IActiveState, IInvConfiguration, IUpgradeTile, IHasSound, IRedstoneControl, IGasHandler, ITubeConnection { @@ -741,18 +741,18 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip } } - @Override - public boolean canAttachToSide(int side) - { - return true; - } - @Override public void attach(IComputerAccess computer) {} @Override public void detach(IComputerAccess computer) {} + @Override + public boolean equals(IPeripheral other) + { + return this == other; + } + @Override public double getMaxEnergy() { diff --git a/common/mekanism/common/tile/TileEntityMetallurgicInfuser.java b/common/mekanism/common/tile/TileEntityMetallurgicInfuser.java index 2e8b9883a..423245fc4 100644 --- a/common/mekanism/common/tile/TileEntityMetallurgicInfuser.java +++ b/common/mekanism/common/tile/TileEntityMetallurgicInfuser.java @@ -33,9 +33,9 @@ import net.minecraft.nbt.NBTTagCompound; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.peripheral.IPeripheral; public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implements IPeripheral, IActiveState, IInvConfiguration, IUpgradeTile, IHasSound, IRedstoneControl { @@ -470,9 +470,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem } @Override - public boolean canAttachToSide(int side) + public boolean equals(IPeripheral other) { - return true; + return this == other; } @Override diff --git a/common/mekanism/common/tile/TileEntityPRC.java b/common/mekanism/common/tile/TileEntityPRC.java index ea1b4bfb9..213b586b0 100644 --- a/common/mekanism/common/tile/TileEntityPRC.java +++ b/common/mekanism/common/tile/TileEntityPRC.java @@ -41,8 +41,8 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; public class TileEntityPRC extends TileEntityBasicMachine implements IFluidHandler, IGasHandler, ITubeConnection { diff --git a/common/mekanism/common/tile/TileEntityTeleporter.java b/common/mekanism/common/tile/TileEntityTeleporter.java index 3dff14384..0a8b471c9 100644 --- a/common/mekanism/common/tile/TileEntityTeleporter.java +++ b/common/mekanism/common/tile/TileEntityTeleporter.java @@ -35,9 +35,9 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.peripheral.IPeripheral; public class TileEntityTeleporter extends TileEntityElectricBlock implements IPeripheral { @@ -582,9 +582,9 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe } @Override - public boolean canAttachToSide(int side) + public boolean equals(IPeripheral other) { - return true; + return this == other; } @Override diff --git a/common/mekanism/generators/common/tile/TileEntityBioGenerator.java b/common/mekanism/generators/common/tile/TileEntityBioGenerator.java index 7da209355..bc55d336c 100644 --- a/common/mekanism/generators/common/tile/TileEntityBioGenerator.java +++ b/common/mekanism/generators/common/tile/TileEntityBioGenerator.java @@ -23,8 +23,8 @@ import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; public class TileEntityBioGenerator extends TileEntityGenerator implements IFluidHandler { diff --git a/common/mekanism/generators/common/tile/TileEntityGenerator.java b/common/mekanism/generators/common/tile/TileEntityGenerator.java index 5528785a7..372ef34a7 100644 --- a/common/mekanism/generators/common/tile/TileEntityGenerator.java +++ b/common/mekanism/generators/common/tile/TileEntityGenerator.java @@ -23,8 +23,8 @@ import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.IPeripheral; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.peripheral.IPeripheral; public abstract class TileEntityGenerator extends TileEntityElectricBlock implements IPowerReceptor, IPeripheral, IActiveState, IHasSound, IRedstoneControl { @@ -162,18 +162,18 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem return getInvName(); } - @Override - public boolean canAttachToSide(int side) - { - return true; - } - @Override public void attach(IComputerAccess computer) {} @Override public void detach(IComputerAccess computer) {} + @Override + public boolean equals(IPeripheral other) + { + return this == other; + } + @Override public boolean canSetFacing(int side) { diff --git a/common/mekanism/generators/common/tile/TileEntityHeatGenerator.java b/common/mekanism/generators/common/tile/TileEntityHeatGenerator.java index f793eb2f4..d6aa333ad 100644 --- a/common/mekanism/generators/common/tile/TileEntityHeatGenerator.java +++ b/common/mekanism/generators/common/tile/TileEntityHeatGenerator.java @@ -20,8 +20,8 @@ import net.minecraftforge.fluids.IFluidHandler; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; public class TileEntityHeatGenerator extends TileEntityGenerator implements IFluidHandler { diff --git a/common/mekanism/generators/common/tile/TileEntityHydrogenGenerator.java b/common/mekanism/generators/common/tile/TileEntityHydrogenGenerator.java index 54c7e6c5b..ffde68601 100644 --- a/common/mekanism/generators/common/tile/TileEntityHydrogenGenerator.java +++ b/common/mekanism/generators/common/tile/TileEntityHydrogenGenerator.java @@ -21,8 +21,8 @@ import net.minecraftforge.common.ForgeDirection; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; public class TileEntityHydrogenGenerator extends TileEntityGenerator implements IGasHandler, ITubeConnection { diff --git a/common/mekanism/generators/common/tile/TileEntitySolarGenerator.java b/common/mekanism/generators/common/tile/TileEntitySolarGenerator.java index 2223bda21..bef6cec7a 100644 --- a/common/mekanism/generators/common/tile/TileEntitySolarGenerator.java +++ b/common/mekanism/generators/common/tile/TileEntitySolarGenerator.java @@ -16,8 +16,8 @@ import net.minecraftforge.common.ForgeDirection; import com.google.common.io.ByteArrayDataInput; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; public class TileEntitySolarGenerator extends TileEntityGenerator { diff --git a/common/mekanism/generators/common/tile/TileEntityWindTurbine.java b/common/mekanism/generators/common/tile/TileEntityWindTurbine.java index f56870246..fef4ad35d 100644 --- a/common/mekanism/generators/common/tile/TileEntityWindTurbine.java +++ b/common/mekanism/generators/common/tile/TileEntityWindTurbine.java @@ -6,8 +6,8 @@ import mekanism.common.util.ChargeUtils; import mekanism.common.util.MekanismUtils; import mekanism.generators.common.MekanismGenerators; import net.minecraft.item.ItemStack; -import dan200.computer.api.IComputerAccess; -import dan200.computer.api.ILuaContext; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.lua.ILuaContext; public class TileEntityWindTurbine extends TileEntityGenerator implements IBoundingBlock {