MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.59k stars 431 forks source link

src code for PowerConverter object #320

Closed sibomots closed 10 years ago

sibomots commented 10 years ago

This isn't a bug issue, but a request for help.

I'm trying to learn a bit about how the energy source/sink model works and the PowerConverter block is a good example I think.

Maybe I'm just blind, but I cannot seem to find the source for the Block (TileEntity?) of the PowerConverter that receives MJ/RF and passes a form of energy to a ComputerCase block.

I'm building an entirely different mod but it requires the transfer of energy and I'm just looking for examples of objects that have abstractions that are similiar.

PM me directly if you can help.

I made a post here: http://www.minecraftforge.net/forum/index.php/topic,20063.0.html that summarizes the question better.

Thank you.

Techokami commented 10 years ago

You might have a tough time here. OpenComputers uses Scala, so unless you're using Scala as well...

sibomots commented 10 years ago

The objects from OpenComputers like PowerConverter are not implemented in the actual mod.jar with Java? But Scala?

Date: Thu, 12 Jun 2014 12:13:16 -0700 From: notifications@github.com To: OpenComputers@noreply.github.com CC: sibomots@outlook.com Subject: Re: [OpenComputers] src code for PowerConverter object (#320)

You might have a tough time here. OpenComputers uses Scala, so unless you're using Scala as well...

— Reply to this email directly or view it on GitHub.

Techokami commented 10 years ago

Correct. The only aspects of this mod that are Java are the APIs for other mods to integrate with OpenComputers, and the component network tick handler. Everything else is done in Scala.

sibomots commented 10 years ago

Interesting.

I'm working on a Frankenstein mod and my first TileEntity is a Tesla Coil that can be charged and then emit bolts (arcing electricity).

I think I'm ok but still challenged on dealing with third party energy like MJ or RF. I could ignore third party energy systems and use my own, but that seems inconvenient for making the things in my mod interoperate with other logical choices / alternatives for power sources.

Thanks for the feedback.

I didn't know mods could be written in Scala. Is there a benefit over Java?

Sent from my Windows Phone


From: Christopher Trumbourmailto:notifications@github.com Sent: ‎6/‎12/‎2014 12:41 PM To: MightyPirates/OpenComputersmailto:OpenComputers@noreply.github.com Cc: sibomotsmailto:sibomots@outlook.com Subject: Re: [OpenComputers] src code for PowerConverter object (#320)

Correct. The only aspects of this mod that are Java are the APIs for other mods to integrate with OpenComputers, and the component network tick handler. Everything else is done in Scala.


Reply to this email directly or view it on GitHub: https://github.com/MightyPirates/OpenComputers/issues/320#issuecomment-45938513

fnuecke commented 10 years ago

It's a matter of taste, mostly. Scala does allow writing things a lot more concisely in many scenarios, but can also be a little quirky to work with (in particular when coming from Java and having to interweave it with Java code).

The implementations of BC, IC2, TE and UE interfaces can be found here.

LordFokas commented 10 years ago

if you need a Java reference of RF I have a few :) the CoFH API brings a base implementation, which is easy to use and understand.

sibomots commented 10 years ago

OK.

I really appreciate the insight. I'm not new at Java, but new at MC modding. So it's with a lot of enthusiasm that I venture into this domain.

My first goal is to write a mod that implements a complete Steampunk energy/device system. As I go through the process I'm troubled that in order to play nice with the rest of the components (pipes, fluids, tanks, etc..) made in other mods I have to decide whether or not to link in their library interfaces or discover them at run-time via reflection and build adapters that dynamically handle the interconnections.

I'm not sure the best route to take. One hand I want it to be independent, the other hand I want it to be fool proof. Maybe that's too naïve.

My first challenge is to simply make an energy sink, source and transmission between using native (the mod I'm coding) methods.

As a life long C/C++ programmer myself would you suggest that Scala is worth a look? I admit I haven't even played with it.

Much appreciated. By the way, where I work (Xbox One motherboard and silicon development), we use Lua quite a bit to automate lab equipment to measure signals through external scopes and robots. So it was interesting when I found Lua as the interpretive language in the MC computer suite. I had to chuckle. But it makes sense, I guess ;-)

Thanks, good to hear from you.

Date: Fri, 13 Jun 2014 01:57:19 -0700 From: notifications@github.com To: OpenComputers@noreply.github.com CC: sibomots@outlook.com Subject: Re: [OpenComputers] src code for PowerConverter object (#320)

It's a matter of taste, mostly. Scala does allow writing things a lot more concisely in many scenarios, but can also be a little quirky to work with (in particular when coming from Java and having to interweave it with Java code).

The implementations of BC, IC2, TE and UE interfaces can be found here.

— Reply to this email directly or view it on GitHub.

sibomots commented 10 years ago

I'm looking at the Scala code now you linked. That's exactly what I was looking for, the nuts and bolts example of how adapters (I guess you're calling them traits, which may be a nomenclature that is in the Scala language perhaps.. Reading their docs too.. Interesting.)

I'll have to think of a way to try making HelloWorld mod in Scala and see how it feels.

Date: Fri, 13 Jun 2014 01:57:19 -0700 From: notifications@github.com To: OpenComputers@noreply.github.com CC: sibomots@outlook.com Subject: Re: [OpenComputers] src code for PowerConverter object (#320)

It's a matter of taste, mostly. Scala does allow writing things a lot more concisely in many scenarios, but can also be a little quirky to work with (in particular when coming from Java and having to interweave it with Java code).

The implementations of BC, IC2, TE and UE interfaces can be found here.

— Reply to this email directly or view it on GitHub.

fnuecke commented 10 years ago

I'd say it can't hurt to play around a bit with Scala. If you have some background in functional programing you'll feel at home pretty quickly, I'd think. Although that's not necessary, one of the nice things about Scala is that you can mix functional and imperative programming however you like. A big feature in Scala are traits. They're basically Java interfaces with actual code, reducing code-duplication dramatically. Oh, and they can be used for multiple inheritance (class extends multiple traits which each in turn can extend an actual class, not just other traits). Scala also has REPL which allow for easy experimentation.

As for implementing other Mod's APIs, if you haven't already, do have a look at FML's Optional.* annotations. They allow for soft dependencies (FML will strip out non-present mods' APIs via ASM based on these annotations). One could probably even argue that there's no excuse besides laziness for including other mods' APIs in a published mod JAR these days ;-)

Lua... while I have a long-lasting love for the language, one of the main reasons for picking it over other languages was actually that it can (with a bit of extra work on the C side) be fully persisted, coroutines and all, allowing proper saving (as opposed to having to reboot computers after loading).

Good luck with your modding :-)