Jump to content

[1.7.10] Trying to make an api and a few question about an api.


drok0920

Recommended Posts

Hello,

I would like to make an api for my medieval/battle themed mod i'm working on.  But i'm not sure how to make an api and can i use the api in my own mod?  In the api i think i know what im doing but it gives an error.  I have this method in my api:

public void registerElemental(IBFMEntityElemental elemental) {


}

and it gives me this error:

Illegal modifier for the interface method registerElemental; only public & abstract are permitted

I have folowed the Creating an api topic but it gives me an error. Please help.

 

Thank you,

Drok

Link to comment
Share on other sites

By the "can i use it in my mod" statement all i mean was when I want to make a mob based on the api i make can i actually implement IElemental or do i have to do it a different way?

 

It is your code, so you can do what you want.  I think it is good practice that if you are creating an API for others to use, that you also use it within your mod(s) because this helps ensure that it is correctly implemented and behaves identically to your own mod.

 

Note that an API doesn't have to be a Java Interface.  Even though the "I" in API means interface, interface is just a generic term regarding accessing code from other code.  An API just means that you are presenting some public methods in an un-obfuscated (and ideally well documented) way so that other code can call it.

 

From the error, it seems that you're trying to implement a Java interface.  That is fine (an API can include Java interfaces).  Can you post the whole code for your interface class?

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

Link to comment
Share on other sites

This is pretty basic java. An interface method cannot have a body.

 

His code doesn't have a body.  That isn't the problem.

 

I think the problem is that for interfaces you don't need to declare scope -- it is automatically public.  Secondly, you can't use static methods in interfaces in Java.

 

So I think you should delete all the public scoping and static declarations.  Instead something like:

 

interface IBFMEntityElemental {

       
       
        void registerElemental(IBFMEntityElemental elemental) {
               
               
        }
       
       
}

 

Anyway, back to your earlier questions, how you develop your API depends on what you want to allow people to do with it.

 

For example, a Java interface is useful for categorizing (like using instanceof to confirm that some class implements it).  So imagine that you want to allow other modders to indicate that their entities should be treated specially by code in your mod.  You can then provide an API for a Java interface called something like ISpecialEntity, and then in your code you can check for instanceof ISpecialEntity to find those that others have added the interface to.

 

Alternatively, maybe you want to make sure you can get information about other modders' classes.  For example maybe you have a werefwolf mod and you want other modders to make other were creatures and you will need to know whether they are in "were-form".  Then you could make an API for a Java interface called something like IWerewolf that has a method called inWereForm().  The other modders that decide to extend IWerewolf would be reminded to implement the inWereForm() method so then your mod would be able to check them for the were state.

 

However, an API can also contain classes and regular methods.  Don't get confused and think that an API has to be Java interfaces only.  For example, if you have a method in your mod called spawnCoolEntity() and you want to allow others to spawn them in their code then you could make that method an API. 

 

So it really depends if your API is proving access to functionality in your mod, or instead you're asking others to implement functionality that you can call on. 

 

What exactly are you making your API for?  I think that in your case that registering an elemental would be an actual class method -- not an interface -- because the code for registering would be written by you.  Other mods could call your registration method.

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

Link to comment
Share on other sites

No, shieldbug1 is correct. The method body is the { and }

 

When making an interface, the methods are declared as:

public interface SomeInterface {
        void someMethod(int par1, String par2String, Object par3Object);
}

 

 

 

And then we can get onto the actual topic of API's themselves. Anything that is a public/public static method can be called an API. The definition of what is an API in one's code... It's a very obscure line.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

You use whatever you want to use. There is a lot of debate about what is considered an 'API'. Generally, an API in this case would be an interface that you handle yourself, but it is not limited to it.

 

Example:

 

You have an item that transforms blocks into other blocks.

You create an interface called something like ITransformable. Inside this interface you'd have methods like resultBlock() and resultMetadata(), that have return types of Block and int. Other things could include void methods like onTransform() and postTransform().

Then if you or anyone else would like your block to be transformable you make it implement ITransformable, and return the appropriate block and metadata.

 

In your item class you'd check if the block you're clicking is an instance of ITransformable. If it is, you then call onTransform() so you can let the modder do their own functionality, then transform the block with world.setBlock(transformable.resultBlock(), x, y, z) and metadata with world.setBlockMetadata(transformable.resultMetadata(), x, y, z), then call transformable.postTransform() to allow the modder to do any finishing up they want.

 

You want to think an interface out as much as you can, because changing an interface is looked down upon a lot.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Link to comment
Share on other sites

ok i got it now but lets say this is an entity can you give some examples for an api for that?

 

You should first decide what you want other mods to be able to do, then figure out what API you need to support that.

 

For example, do you want them to be able extend your entity class?  In that case you could go as far as putting the the whole entity class into the API.

 

Do you want them to just be able to control the custom functionality of your entity in some ways?  Then make those special methods in your entity class an API (i.e. create another API class that calls the methods from your mod class).

 

Do you want to have them create entities that you can interact with?  then make a Java interface that you want them to implement.

 

It all depends on what you want the interaction between the mods to be.

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

    • Here's the newest crash: https://pastebin.com/mumDeWzW Seems to have something to do with JEI Also delete that server file? Also the newest log: https://pastebin.com/ATH8dbWc
    • Recently started to attempt 1.20.1 modding, in registering idle, walk and attack animations in the mob entity class i've run into two issues:   a) idle and walk animations seem to play simultaneously  + the mob itself does not seem to walk private static final EntityDataAccessor<Boolean> ATTACKING = SynchedEntityData.defineId(MugaEntity.class, EntityDataSerializers.BOOLEAN); public MugaEntity(EntityType<? extends Monster > pEntityType, Level pLevel) { super(pEntityType, pLevel); } public final AnimationState idleAnimationState = new AnimationState(); private int idleAnimationTimeout = 1; public final AnimationState attackAnimationState = new AnimationState(); public int attackAnimationTimeout = 0; @Override public void tick() { super.tick(); if(this.level().isClientSide()) { setupAnimationStates(); } } private void setupAnimationStates () { if(this.idleAnimationTimeout <= 0) { this.idleAnimationTimeout = this.random.nextInt(30) + 60; this.idleAnimationState.start(this.tickCount); } else { --this.idleAnimationTimeout; } if (this.isAttacking() && attackAnimationTimeout <= 0 ) { attackAnimationTimeout = 20; attackAnimationState.start(this.tickCount); } else { --this.attackAnimationTimeout; } if(this.isAttacking()) { attackAnimationState.stop(); } } @Override protected void updateWalkAnimation(float pPartialTick) { float f; if(this.getPose() == Pose.STANDING) { f=Math.min(pPartialTick * 3.0F, 1.0F); } else { f= 0.0F; } this.walkAnimation.update(f, 0.2F); } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(ATTACKING, false); } public void setAttacking(boolean attacking) { this.entityData.set(ATTACKING, attacking); } public boolean isAttacking() { return this.entityData.get(ATTACKING); } b) the attack animation is never played on attack, despite being registered  @Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.animateWalk(ModAnimationDefinitions.MUGA_WALKING, limbSwing, limbSwingAmount, 1f, 1f ); this.animate(((MugaEntity)entity).idleAnimationState, ModAnimationDefinitions.MUGA_IDLE, ageInTicks, 1f); this.animate(((MugaEntity)entity).attackAnimationState, ModAnimationDefinitions.MUGA_ATTACK, ageInTicks, 1f); }
    • Maybe there are some more broken files - check the new crash-report - the file name is mentioned in the first lines   If it is another crash, add it here
    • Thanks. Found and deleted it, but it doesn't change anything. When joining a new file is created, the screen freezes/ does not respond in typical manner and I have to close it then. I deleted it in curseforge>minecraft>instances>Modpack>saves>World>serverconfig Should I have deleted it anywhere else?
  • Topics

×
×
  • Create New...

Important Information

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