This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
distantcam's profile picture

Native Java Api Possible?

Started by distantcam, 20 October 2013 - 09:45 PM
distantcam #1
Posted 20 October 2013 - 11:45 PM
Is it possible to make a native API in Java and have it picked up in ComputerCraft?

If so, how would I do that?
Bubba #2
Posted 21 October 2013 - 01:19 AM
You can write java code that is executed by computers using peripherals. Check out this link for the very plain basics. Beyond that, I'm in the process of writing up a peripheral tutorial which may or may not get posted sometime this month (between frequent MC/Forge updates and real life, I've had a lot of trouble getting anything done). Assuming you don't already have background modding experience, check out this to learn about actually making a mod.

As for making an actual API that has no physical block in the world, I'm afraid that's quite difficult. You can make blocks in the world into peripherals, as exampled by OpenPeripheral, but making an API without a peripheral is essentially impossible without deobfuscating/messing around with native CC code, which is not allowed.
distantcam #3
Posted 21 October 2013 - 11:04 AM
I had thought about doing it as a peripheral, so I'm glad that'll work and was the right track.

Is it worth asking if future versions of ComputerCraft could support native APIs?

Those links were helpful, thanks! Now to relearn Java (it's been 11+ years).
Lyqyd #4
Posted 21 October 2013 - 12:31 PM
Is it worth asking if future versions of ComputerCraft could support native APIs?

They already do; see "Peripherals". As for java code loaded solely from Lua code, that will never happen.
distantcam #5
Posted 21 October 2013 - 07:34 PM
They already do; see "Peripherals". As for java code loaded solely from Lua code, that will never happen.

I meant without needing a peripheral.

I'm curious as to why loading java as an API without a peripheral would never happen. Is it a security problem? Technical problem?
Lyqyd #6
Posted 21 October 2013 - 07:46 PM
Probably both, but a big concern would be that it would allow code to break out of the Lua sandbox.
distantcam #7
Posted 21 October 2013 - 08:33 PM
Interesting.

Wait, does that mean that peripherals run outside the Lua sandbox? So peripherals are running in Minecraft outside of ComputerCraft?

That's a pretty neat way of dealing with plugins that might potentially crash and bring down Computercraft. Although really that's just shoving the problem back onto Minecraft. ;)/>
theoriginalbit #8
Posted 21 October 2013 - 08:38 PM
Wait, does that mean that peripherals run outside the Lua sandbox? So peripherals are running in Minecraft outside of ComputerCraft?
Peripherals are a Minecraft mod that interfaces with ComputerCraft, so of course they run outside of the Lua sandbox.
Bubba #9
Posted 22 October 2013 - 03:27 PM
Alright, well I've posted the peripheral tutorial here. Note that the tutorial is still in it's early stages so may have slightly incorrect and/or not understandable information. Hopefully it will help you out. You can check out the full code here if you would prefer to learn by example.
jay5476 #10
Posted 24 October 2013 - 12:08 AM
Alright, well I've posted the peripheral tutorial here. Note that the tutorial is still in it's early stages so may have slightly incorrect and/or not understandable information. Hopefully it will help you out. You can check out the full code here if you would prefer to learn by example.
great tutorial btw,

but yes a peripheral will call back into its java programming so maybe just add a peripheral like a command block where a method can be called with some code as an argument and then it can be run somehow