Jump to content

Using API's?


jordsta95

Recommended Posts

Hey there, I am wondering how to use API's, and how to have my mod use them.

Reason being I would like to make items in my mods have things such as Thaumcraft aspects. But I would want the mod to work without the player having the mods installed... dunno if that's possible.

Thanks for the help

-Jordan

Why bother?

Link to comment
Share on other sites

Pretend for a second that I know next to nothing about modding :P

 

But thanks for telling me it's possible :)

 

So, what exactly do I do?

Do I add all the API stuff into my src folder (not my mod's of course), and then reference it as I would my own but instead of MyModName.ClassFile it would be APIName.ClassFile ?

Why bother?

Link to comment
Share on other sites

I'll pretend you know a few things in Java.  :P

 

You can use the API directly like you would with any class, this is called a strong reference in Java.

It means code will crash if an used part of the API isn't installed. ("Class not found exception"...you might have seen that already)

You can have weak reference by using reflection. This a powerful tool to use, perfectly suited in your case. Well coded, new things will happen if an API is installed, but no crash on other situation.

You can start learning reflection here: http://docs.oracle.com/javase/tutorial/reflect/

 

If you are unsure about it, you can start by using strong reference, and if you find the API easy to use and worth the effort, you can convert strong references to weak with reflection :)

Link to comment
Share on other sites

And then maybe release 2 versions 1 API compat and one not?

your choice really, if you use strong reference it will generally be faster. but you if the mod is not installed then it wont work (like gotolink said)

 

if you need to reflect all the time (like every milisecond) then reflection might not be such a good idea but if its only for setup then reflection is awesome!

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

well example in one of my mod i need to read value from a private field in some class, using reflection i am able to get a reference to that object, save it elsewhere and read the value i need from that reference. so i technicly use reflection only 1 time, to get the reference and after i dont need it. basicly its slow while im getting the reference for the first time and after that everythign is smooth.

 

on the other side sometimes youll need to constantly use reflection so that not super efficient

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Oh right, so if it were (for example) something like a timer from RedPower, or some sort of redstone thing that can essentially update every tick, it may be better to do a strong reference?

But if it were just to check for a file, and if it was there then do XYZ it may just be better to do a weak one?

 

Or do I have that wrong?

Why bother?

Link to comment
Share on other sites

no you got it right in my case i want to have access to the Timer reference in Minecraft (for rendering). so i only need to copy the reference once since it will be the exact same timer during your whole session. but in the case of redstone theres redstone all over the world so you dont want to have reference to everything. what you would do is use reflection every time you need to access it but that slow

 

btw when we say slow we mean "slower then strong reference" in some case reflection will be "slow" but still fast enough so that your fps wont drop

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

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 want to download Forge 1.20.6, but when I press download, it redirects me to Adfocus and does not provide any download. I have never encountered such a problem when I downloaded Forge 1.18.2 at least 12 months ago.
    • did you find any solutions? i have the same problem and also that mahito doesnt transform
    • Here's a simple example to solve this particular issue: public class ModArmorMaterials { public static final DeferredRegister<ArmorMaterial> ARMORS = DeferredRegister.create(Registries.ARMOR_MATERIAL, MyModName.MOD_ID); public static final RegistryObject<ArmorMaterial> COPPER = registerArmor("copper", Util.make(new EnumMap<>(ArmorItem.Type.class), enumMap -> { enumMap.put(ArmorItem.Type.BOOTS, 1); enumMap.put(ArmorItem.Type.LEGGINGS, 4); enumMap.put(ArmorItem.Type.CHESTPLATE, 5); enumMap.put(ArmorItem.Type.HELMET, 2); enumMap.put(ArmorItem.Type.BODY, 4); }), 12, SoundEvents.ARMOR_EQUIP_IRON, 0.0F, 0.0F, () -> Ingredient.of(Items.COPPER_INGOT)); private static RegistryObject<ArmorMaterial> registerArmor(String pGroup, EnumMap<ArmorItem.Type, Integer> pEnumMap, int pEnchantmentValue, Holder<SoundEvent> pEquipSound, float pToughness, float pKnockbackResistance, Supplier<Ingredient> pRepairIngredient) { List<ArmorMaterial.Layer> pLayerList = List.of(new ArmorMaterial.Layer(new ResourceLocation(pGroup))); return registerArmor(pGroup, pEnumMap, pEnchantmentValue, pEquipSound, pToughness, pKnockbackResistance, pRepairIngredient, pLayerList); } private static RegistryObject<ArmorMaterial> registerArmor( String pGroup, EnumMap<ArmorItem.Type, Integer> pEnumMap, int pEnchantmentValue, Holder<SoundEvent> pEquipSound, float pToughness, float pKnockbackResistance, Supplier<Ingredient> pRepairIngredient, List<ArmorMaterial.Layer> pLayerList) { return ARMORS.register(pGroup, () -> new ArmorMaterial(pEnumMap, pEnchantmentValue, pEquipSound, pRepairIngredient, pLayerList, pToughness, pKnockbackResistance)); } public static void register(IEventBus eventBus) { ARMORS.register(eventBus); } } Essentially, the TierSortingRegistry has been removed and so you now need to set up your own DeferredRegister. Please see the minecraftforge GitHub for more information; I found this solution through their issues (https://github.com/MinecraftForge/MinecraftForge/issues/9961)
    • How did I even leave that in there? I’ll try it in a bit, that very well could be it.
  • Topics

×
×
  • Create New...

Important Information

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