Jump to content

Using an API


TheCupcakeisalie

Recommended Posts

Ok, so I want to use the Cofhlib API, but I have to idea where to actually *put* the API. I am using eclipse and have my mod set up there, so do I just need to extract the API into eclipse? Also I re-set up my dev enviroment when updating my forge, and instead of putting things into a hiearchy, eclipse now lists all packages on the same level and displays them as mod.stuff.morestuff, and all the minecraft packages are the same way, they are all listed as net.minecraft.whatever, which makes it nigh impossible to read or find where things are easily. Sorry for probobly very nooby questions, thanks for all the help.

Link to comment
Share on other sites

You are using the cofh api? How are you doing that, I am trying to but I can not find any download for the api, only the whole cofh core, and it downloads as a zip file, and I have trouble importing the zip and adding it to my build path, as it doesnt show any of the source. I succesfully installed the IC2 api as it ships as a jar.  How do I go about getting the correct stuff into my workspace for implementing?

Edit:I figured it out and found a CofhLib Jar. Thanks for everyone thats helped.

Link to comment
Share on other sites

I think people often get confused about what an API is.  I get confused about it too, but here is my understanding (feel free to correct me).

 

Normally after compilation and obfuscation a Java mod's functionality isn't really accessible in a human-readable and accessible way. However, people making a mod can choose to expose functionality as an API by constructing their build (I think you can identify API code in the build.gradle if you're creating an API) such that portions are not obfuscated and can be referenced by their original method name.

 

The trick then is to make your dev environment "know about" this API so that when you use the API methods in your code there isn't any error.  I think there may be two ways -- you can bring the source over but segregate it as required code that doesn't get built into your mod (I think that is what diesieben07 is suggesting above), or you can actually bring the actual mod into your run location so it is accessed similar to how it will be  when you mod is actually published.

 

What you don't want to do is to bring their source code into your mod.  Yes you want Eclipse to recognize the methods from the API, but that should be like other libraries instead of actually part of your code.

 

I don't know all the details to do the above right, but that is the general concept.  You might want to check out CoolAlias' tutorial on APIs: http://www.minecraftforum.net/topic/2496232-tutorial-modding-with-apis/

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I think people are confusing "using open source code" with "using an API".  If someone writes an "API" but then gives out the open source code for it, you certainly are allowed to use it.  But that is just copying code, not using an API.

 

An API is an agreed upon set of calls between two independently developed pieces of code. 

 

Also not including the api would make your mod dependent on the mod it belongs wouldn't it?

 

That's the whole point.  You want to take advantage of the other developers' effort by depending on it.  Imagine I made a mod that did some cool world generation and had and API called generateCoolWorld().  You would use my mod (required dependency) and call that method.  But I could independently keep improving what that does -- maybe fix bugs, or make it even cooler world.  You could drop in any version of my mod and the API would be there for you -- the API is like a "contract" or standard.  You should never have to re-build your mod because I fixed a bug in my API.  You just update my mod instead.

 

There is nothing wrong with using open source code, but if you're building it then I'm pretty sure it isn't an "API".

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

If your are including an API because you want a soft-dependency (integration if the mod is present, otherwise just don't integrate) you are doing it wrong. Use the Annotations in the Optional class from FML. They allow you to handle this without including the API code.

 

Yes, I should have mentioned that.  Here is tutorial on @Optional annotation.  http://minalien.com/minecraft-forge-feature-spotlight-optional-annotation/

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

maby im confused because the redstone flux api isnt specifically designed to allow mods to interact with Thermal Expansion it allows any mod to interact with any other mod using the api even if there are no cofh mods installed.

I guess i will just have to do some research and try to wrap my head around it starting with the links you provided.

 

Edit:

There is nothing wrong with using open source code, but if you're building it then I'm pretty sure it isn't an "API".

What do you mean by "building" I am i am implementing the apis interfaces

 

If your are including an API because you want a soft-dependency (integration if the mod is present, otherwise just don't integrate) you are doing it wrong. Use the Annotations in the Optional class from FML. They allow you to handle this without including the API code.

 

I am using is as the power system for my mod and it dose not in any way dependent on any other mod but it wont function without the api so i am dependent on the api itself not the mod it belongs to.

 

 

 

I am the author of Draconic Evolution

Link to comment
Share on other sites

Ok i must ask is an interface considered an api? because the redstone flux api dosnt contain any methods just a set of interfaces.

 

Edit: i just realized that was a stupid question "Application Programming Interface"

 

This is kinda a complicated question.  As diesieben07 indicates, the word "interface" can mean different things.  In Java it specifically means a set of public unimplemented methods (someday soon Java will support "default" methods in interfaces allowing some implementation) that enforces compliance on those classes that implement it.

 

The Java interfaces are mostly intended for enforcing compliance within an internal development team.  For example, if I had a team of software coders working on something I could define the interfaces for them to implement and then they would go off an implement them and I would be sure that the result would have the methods I expect so I could assign another software developer to write code that calls those interfaces. 

 

There is a secondary use of Java interfaces in helping provide "multiple inheritance".  This is because Java allows you to test instanceof for interfaces.  You can only extend one class, but you can implement multiple interfaces.  So if I wanted to group a bunch of classes that were not extending the same parent class I could define an empty interface and have all the classes implement it and then I could treat them all as instances of that interface.  Not sure if you know what I mean, but I do find this useful sometimes.

 

An API is usually a bit more "external".  It is telling other people how to access the functionality and resources of your code.  But you might have no interaction with those people at all.  You just publish your compiled code and a documented API and they can use it how they want.

 

I'm not entirely sure why someone would put a Java interface in an API.  It is not directly callable because the interface isn't implemented.  It can be used to allow the mod with the API to "discover" and use your classes though.  For example, imagine that there was a mod that wanted to add sea life entities to Minecraft and they wanted to be aware if your mod also has sea life entities.  Then the API could provide a Java interface for sea life, you could implement that interface in your seal life entity classes, and in their mod whenever they tested for instanceof they would also see all your entities (and further know how to access them, through the methods the interface forces you to implement).

 

Not sure if that is entirely clear.  But I would say that generally a Java interface is more about internal developers working together on the same code base, and an API is about external developers being able to interact with your code product.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Ok so i understood most of what you just said and a lot of it i already knew from the java tutorials i have read.

It seems to me from everything you have told me the Redstone flux api isnt like most apis its just a universal energy system that mods can implement in order to be compatible with each other.

I am the author of Draconic Evolution

Link to comment
Share on other sites

Ok so i understood most of what you just said and a lot of it i already knew from the java tutorials i have read.

It seems to me from everything you have told me the Redstone flux api isnt like most apis its just a universal energy system that mods can implement in order to be compatible with each other.

 

Basically if I want my mod to work with yours I can choose to:

1) just say "hey can you make some deobfuscated methods that we agree on?"  No Java interface but just trust you'll implement the methods as agreed.

b) say "I'll expose an deobfuscated API in my obfuscated mod that exposes a Java interface that you can implement (without needing source)"

z) say "Here's source code for a Java interface that I hope you expose as a deobfuscated API in your obfuscated mod."

 

All three methods can work, but are just different perspectives on the same problem.  Sounds like Redstone is taking the third approach.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.