Creating Peripherals and Turtle Upgrades (Updated for 1.5)
#1
Posted 13 March 2012 - 01:47 PM
The peripheral API can now be found in the "api" folder of the main ComputerCraft download
For peripherals, the download includes the source files for the two interfaces you need to interact with to make peripherals. All you need to do is create a new block with a TileEntity, and have the entity implement IPeripheral.
For turtle upgrades, create a class implementing ITurtleUpgrade, and call TurtleAPI.registerUpgrade() during your mod load() method. Turtle upgrades can either be new tools for your turtle (like the Pickaxe, Sword, etc), or new peripherals that permanently attach to the turtle (like the turtles' Wireless Modem or Crafting Table), and turtles with the upgrades can be created by crafting. In order to correctly store the types of turtle upgrade that each turtle has, each turtle upgrade designed must have a unique "UpgradeID", which is an integer in the range 0-255. When you release your upgrade, please use the following wiki page to choose an unused ID: http://www.computerc...tle_Upgrade_IDs
Both parts of the API include complete, thorough javadoc documentation. To make a mod, add these files to your MCP install, and implement the requisite interfaces. You do not need to and should not distribute the class files for these files with your mod. If all goes well, when you re-obfuscate your mod and install alongside ComputerCraft, your computers should be able to interact with your peripherals using the "peripheral" API, and turtles should be able to be crafted with your upgrades.
Feel free to post any questions about the API you have in this thread, but please read the documenation first, and be aware that this API is designed for users who already know how to produce mods for Minecraft, so we won't help you with basic mod setup.
Happy hacking!
#2
Posted 13 March 2012 - 04:02 PM
dan200, on 13 March 2012 - 01:47 PM, said:
If all goes well, then when you re-obfuscate your mod and install alongside ComputerCraft, and place your block alongside a computer, and the computer will be able to access it via the "peripheral" API in Lua.
What I did understood was that we make the periph, and it's methods are already implemented in Lua.
#3
Posted 13 March 2012 - 04:44 PM
rockymc, on 13 March 2012 - 04:02 PM, said:
dan200, on 13 March 2012 - 01:47 PM, said:
And then you just have to make sure to implement the two Interfaces correctly that Dan provided, so that the peripheral API can interact with your methods.
It's all in the documentation really.
#4
Posted 13 March 2012 - 05:58 PM
Espen, on 13 March 2012 - 04:44 PM, said:
rockymc, on 13 March 2012 - 04:02 PM, said:
dan200, on 13 March 2012 - 01:47 PM, said:
And then you just have to make sure to implement the two Interfaces correctly that Dan provided, so that the peripheral API can interact with your methods.
It's all in the documentation really.
You really need to implement IComputerAccess?
#5
Posted 13 March 2012 - 08:31 PM
rockymc, on 13 March 2012 - 05:58 PM, said:
Espen, on 13 March 2012 - 04:44 PM, said:
rockymc, on 13 March 2012 - 04:02 PM, said:
dan200, on 13 March 2012 - 01:47 PM, said:
And then you just have to make sure to implement the two Interfaces correctly that Dan provided, so that the peripheral API can interact with your methods.
It's all in the documentation really.
You really need to implement IComputerAccess?
You don't implement IComputerAccess. Read the javadocs.
#6
Posted 16 March 2012 - 09:37 AM
(an example use case could be linking a machine module to a receiver, by having the module read the ID / location / whatever of it's parent from the disk. Doing so via an API future-proofs any changes to where files are stored outside the game)
#7
Posted 28 April 2012 - 11:46 PM
oreillynz, on 16 March 2012 - 09:37 AM, said:
(an example use case could be linking a machine module to a receiver, by having the module read the ID / location / whatever of it's parent from the disk. Doing so via an API future-proofs any changes to where files are stored outside the game)
Something like that should be handled by your "device driver" (aka API) inside the computer / turtle. Your peripheral device can send any data with queueEvent into the computer. The computer can answer with a call of one of your api functions. For example if your peripheral wants it preferences to be loaded from disk (or from elsewhere) you could send an event from Java to the computer. Something like queueEvent("extModule_wantMyConfiguration")
The computer(your device driver) should react to this event by sending the required information. Inside the computer you can just use the file api to load the data from the virtual file system.
It works like in real computers. It would be terrible if your pc mouse could have direct access to your filesystem and delete some files (probably "cat.txt" /> ).
If your peripheral should work on it's own you can save your own data independently from the attached computer in any place you like. It doesn't have to be inside the "computer" folder. If the device wants to store something in the attached computer it should always go through the computer.
#8
Posted 21 May 2012 - 02:34 PM
#9
Posted 21 May 2012 - 02:58 PM
#10
Posted 21 July 2012 - 11:59 AM
#11
Posted 23 July 2012 - 10:04 PM
#12
Posted 24 July 2012 - 10:00 AM
#13
Posted 26 July 2012 - 11:52 AM
So please change the following functions:
attach(IComputerAccess computer, java.lang.String computerSide, int worldSide)
worldSide will be 0,1,2,3,4 or 5 depending on the side relative to the peripheral where the computer/cable got attched
detach(IComputerAccess computer, String computerSide)
computerSide will be the same as computerSide from attach to specify which connection was broken.
These changes would really be very helpful!
xuma
#14
Posted 26 July 2012 - 02:37 PM
#15
Posted 26 July 2012 - 03:00 PM
#16
Posted 26 July 2012 - 04:45 PM
And getting your location is easy - you use the coords in your tile entity - should be easy to find out where the computer is from that location.
#17
Posted 26 July 2012 - 06:22 PM
And yes getting coordinates is also easy as long as the connection is not only done with Peripheral cables. But for this case Xfel is responsible.
So updating the API would maybe simplify the work of Peripheral Developers but is not needed. Thanks for your time I'll try going with what I have this should be possible.
#18
Posted 30 July 2012 - 09:55 AM
#20
Posted 01 August 2012 - 04:36 AM
that would be truly great if you can.
if you cant then that's ok />
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users