Jump to content




Creating Peripherals and Turtle Upgrades (Updated for 1.5)


65 replies to this topic

#1 dan200

  • Administrators
  • 542 posts
  • LocationCambridge, England

Posted 13 March 2012 - 01:47 PM

The ComputerCraft Peripheral API is a way for minecraft mod authors to make blocks that can be interacted with by ComputerCraft computers and turtles, in the same manner as Disk Drives, Modems and Monitors, or to make Turtle upgrades that can be crafted into new types of Turtles.

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 rockymc

  • Members
  • 103 posts

Posted 13 March 2012 - 04:02 PM

Just a question: how do we make the methods for the Peripheral in Lua? Because what I understood here was:

View Postdan200, 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 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 13 March 2012 - 04:44 PM

View Postrockymc, on 13 March 2012 - 04:02 PM, said:

Just a question: how do we make the methods for the Peripheral in Lua? Because what I understood here was:

View Postdan200, 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.
You program the methods within Java, of course. What these methods will do is up to you.
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 rockymc

  • Members
  • 103 posts

Posted 13 March 2012 - 05:58 PM

View PostEspen, on 13 March 2012 - 04:44 PM, said:

View Postrockymc, on 13 March 2012 - 04:02 PM, said:

Just a question: how do we make the methods for the Peripheral in Lua? Because what I understood here was:

View Postdan200, 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.
You program the methods within Java, of course. What these methods will do is up to you.
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 dan200

  • Administrators
  • 542 posts
  • LocationCambridge, England

Posted 13 March 2012 - 08:31 PM

View Postrockymc, on 13 March 2012 - 05:58 PM, said:

View PostEspen, on 13 March 2012 - 04:44 PM, said:

View Postrockymc, on 13 March 2012 - 04:02 PM, said:

Just a question: how do we make the methods for the Peripheral in Lua? Because what I understood here was:

View Postdan200, 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.
You program the methods within Java, of course. What these methods will do is up to you.
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 oreillynz

  • New Members
  • 14 posts

Posted 16 March 2012 - 09:37 AM

Just in case the file structure changes in future, could an API function be added to get the file handler(s) for the contents of a disk?
(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 Bunny83

  • New Members
  • 2 posts

Posted 28 April 2012 - 11:46 PM

View Postoreillynz, on 16 March 2012 - 09:37 AM, said:

Just in case the file structure changes in future, could an API function be added to get the file handler(s) for the contents of a disk?
(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 louitzie

  • Members
  • 50 posts

Posted 21 May 2012 - 02:34 PM

is it possible to get a turtles inventory?

#9 Xfel

    Peripheral Designer

  • Members
  • 515 posts

Posted 21 May 2012 - 02:58 PM

Turtles implement the IInventory interface like any chest or furnace. At least, it is accessible to buildcraft and redpower item processors.

#10 zwap1233

  • Members
  • 37 posts

Posted 21 July 2012 - 11:59 AM

whit "TileEntity" do you mean the basemod class or the block class?

#11 xuma202

  • Members
  • 288 posts
  • LocationBonn Germany

Posted 23 July 2012 - 10:04 PM

For a SMP mod do I have to call queueEvent on all Clients or is this synchronized by Computer Craft already, guess so.

#12 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 24 July 2012 - 10:00 AM

What you have to remember about ComputerCraft in SMP is that all the logic is handled server side. You only have to call QueueEvent on the server.

#13 xuma202

  • Members
  • 288 posts
  • LocationBonn Germany

Posted 26 July 2012 - 11:52 AM

I'd like to suggest a change in the IPeripheral API. With Peripheral Cable (http://www.computerc...eral-cable-v02/) one computer can now be connected to a peripheral more than just one time. When now the computer detaches from the peripheral you have no chance to determine which connection was broken.

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 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 26 July 2012 - 02:37 PM

I see your point, however in vanilla usage it works fine - if anything, it should be Xfel who needs to handle this. Changing the interface would mean current peripherals would be incompatible with the future version. You could probably do it by counting how many times you attached, and only fully detach when the specified IComputerAccess has detached all instances.

#15 xuma202

  • Members
  • 288 posts
  • LocationBonn Germany

Posted 26 July 2012 - 03:00 PM

Yes I'll ask Xfel for that. But getting the side where the Computer is placed has nothing to do with the peripheralcables. I would also apreciate having access to the Coords and the orientation of a Computer. And updates are needed anyways at least when porting the peripherals to CC 1.4 or later MC 1.3.

#16 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 26 July 2012 - 04:45 PM

You can just store it when you connect to the peripheral. I'm not going to add something that will change the interface on an update which won't break compatibility with existing peripherals. Why would you need the side anyway on detach?

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 xuma202

  • Members
  • 288 posts
  • LocationBonn Germany

Posted 26 July 2012 - 06:22 PM

Ok That's right I know that the Computer can only change it's position if it's not at all attached to a peripheral.

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 xuma202

  • Members
  • 288 posts
  • LocationBonn Germany

Posted 30 July 2012 - 09:55 AM

Dan are you sure you've putten up the right link. When I download it it not contains anything related to TurtleUpgrades and the archive is called ComputerCraftAPI1.32.zip

#19 dan200

  • Administrators
  • 542 posts
  • LocationCambridge, England

Posted 30 July 2012 - 12:13 PM

View Postxuma202, on 30 July 2012 - 09:55 AM, said:

Dan are you sure you've putten up the right link. When I download it it not contains anything related to TurtleUpgrades and the archive is called ComputerCraftAPI1.32.zip

My bad. Fixed now.

#20 djblocksaway

    Epic Coderz

  • New Members
  • 397 posts
  • LocationAustralia

Posted 01 August 2012 - 04:36 AM

dan200 would you do the honor of joining my computercraft server o.o

that would be truly great if you can.

if you cant then that's ok :ph34r:/>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users