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

    • I have created a custom entity that extends "TamableAnimal", but I am wanting to have it spawn in the ocean. I have it spawning right now, but it spawns way too frequently even with weight set to 1. I am guessing it is because it is rolling in the spawn pool of land animals since TameableAnimal extends Animal and is different than WaterAnimal, and since no land animals spawn in the ocean it just fills every inch up with my custom entity. I have followed basic tutorials for spawning entities with Forge, but I feel like I am missing something about how to change what spawn pool this custom entity ends up in. Is it possible to change that or do I need to refactor it to be based off of WaterAnimal to get those spawn? My biome modifier JSON file: { "type": "forge:add_spawns", "biomes": "#minecraft:is_ocean", "spawners": { "type": "darwinsmysticalmounts:water_wyvern", "weight": 20, "minCount": 1, "maxCount": 1 } } My client event: event.register(ModEntityTypes.WATER_WYVERN.get(), SpawnPlacements.Type.NO_RESTRICTIONS, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, WaterWyvernEntity::checkWaterWyvernSpawnRules, SpawnPlacementRegisterEvent.Operation.REPLACE); And the actual custom spawn rule that makes it spawn in the water: public static boolean checkWaterWyvernSpawnRules(EntityType<WaterWyvernEntity> pAnimal, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) { return pPos.getY() > pLevel.getSeaLevel() - 16 && pLevel.getFluidState(pPos.below()).is(FluidTags.WATER); }  
    • Starting today, I am unable to load my modded minecraft world. Forge crash log initially said it was a specific mod called Doggy Talents, which I disabled. Then it blamed JEI, and when that was disabled it blamed another mod so I assume it's something more than a specific mod. Minecraft launcher log claims "Exit Code 1". Nothing had changed since last night when it was working fine Forge Log: https://pastebin.com/S1GiBGVJ Client Log: https://pastebin.com/aLwuGUNL  
    • “Courage doesn’t mean you don’t get afraid. Courage means you don’t let fear stop you.” This mantra has been my guiding light throughout my life as a military doctor. After years of serving my country, I dedicated myself to healing others and making a positive impact on the lives of my fellow soldiers and their families. My commitment to service extended beyond the battlefield; I was determined to secure a stable future for my own family. With my hard-earned savings, I invested $470,000 in cryptocurrency, believing it would provide the financial foundation we needed. However, one fateful day during a particularly intense deployment, everything changed. While treating a patient amid an attack, my phone slipped from my hands and crashed to the ground. In the chaos, I realized I hadn’t backed up my cryptocurrency wallet recovery phrase, thinking I had plenty of time to do so later. When I attempted to access my funds that night, panic surged through me—I could no longer access my wallet. My dreams of financial security and stability were vanishing right before my eyes. The betrayal I felt was profound. It was as if I had not only failed myself but also my family, who relied on me to provide for them. Each day at the hospital reminded me of my commitment to healing, and now I was left feeling helpless in the face of adversity. I feared losing everything I had worked so hard for, and the emotional toll was unbearable.  In my desperation, I reached out to trusted colleagues and friends. One fellow veteran mentioned TECH CYBER FORCE RECOVERY Tool, a reputable team known for their expertise in recovering lost digital assets. REACH OUT TO THEM WWW.techcyberforcerecovery.info https://wa.me/message/BJPIMH5UTNLKL1 
    • I am using AMD, yes. I downloaded the website's drivers and am still having the issue. I also used the Cleanup Utility just in case. 
    • I can't figure out how to upload it any other way, so I made a google drive link; hopefully that works https://drive.google.com/file/d/165vmAMoLtb55wzwYHh3vBfHlJ-Wrgm_y/view?usp=sharing
  • Topics

×
×
  • Create New...

Important Information

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