Jump to content

[1.12.1] Implementation of an API (Baubles)


Recommended Posts

Posted (edited)

I kinda hate to ask you peoples yet another thing after you helped me so recently, but that's what you're here for, right?

 

I'd like to use Baubles so my existing items can be equipped in the slots created by baubles. Unfortunately, the only guide I can find for using APIs is this, and it was published in early 2014, and last edited in early 2015. So yeah, I'm not sure how reliable that is, and whether or not it'll break my existing code if I try to follow it.

 

So this post basically just comes down to "hey, hey someone more experienced than me please help me figure out how to use the Baubles API"

Again, all my code can be found here.

 

Thanks in advance!

(This post assumes the 1.12 baubles version will work in 1.12.1)

Edited by Fijal
Posted

How will you use the API? Will it have to be downloaded separately or do you want it integrated into your mod?

If it is integrated into the mod, you can download the de-obf.jar and use winrar to copy the packages and assets in.

If it is downloaded separately, in IntelliJ you can add dependencies in Project > Modules > Dependencies. You add the .jar there

Posted (edited)

Few notes, I don't own Winrar so I'm using 7Zip and I'm using Eclipse instead of IntelliJ which I could never setup properly.

 

I'd be making it integrated into the mod I because I assume that makes for easier downloading.

So, I downloaded the file called Baubles-1.12-1.5.1-deobf, extract the files using 7Zip, and based on something I read, I put the extracted files in /src/api/.

All the files I extracted are .Class, not .Java, so Eclipse can't read them. Is that supposed to happen, or if I'm integrating it should I have downloaded the source version of Baubles?

 

Edit: If I were going to make it so Baubles must be downloaded separately (and it works if I do this so maybe I will), how do I make an item equipable in a Baubles-added slot? Is there an example item somewhere?

 

 

Edited by Fijal
Posted

There is your problem.
Thats not how that should be done. Baubles in an independend mod and its api is just something you can access.
 

Since there does not seem to be a maven repository for baubles just put the jar in a new libs/ folder in your project root.

And run: gradle --refresh-dependencies

It should become available as a library in your working environment.

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

You can use any Git repository (like Baubles) as a Maven dependency through JitPack. I do this in my mod here.

 

You can also use CurseForge as a Maven repository through its API (see the Maven section).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I put Baubles-1.12-1.5.1-debof.jar in */libs/, ran ./gradlew setupDecompWorkspace --refresh-dependencies,(because I'm using powershell, the new default win10 1703, and I did setupDecomp thing because you have to run something before the --refresh thing.) opened up Eclipse, typed "IBauble" to get quick access to a Baubles file, and it said something like class file error and asked for a source.

 

Then thinking maybe I should try the API version of Baubles I downloaded Baubles-1.12-1.5.1-debof.jar, and did the same thing. This time it worked. Is it supposed to be like that?

Posted (edited)
8 minutes ago, Choonster said:

You can use any Git repository (like Baubles) as a Maven dependency through JitPack. I do this in my mod here.

 

You can also use CurseForge as a Maven repository through its API (see the Maven section).

So, I just put

deobfCompile "com.github.azanor:Baubles:${baubles_version}"

in the dependencies section of my build.gradle

and

maven { url 'https://jitpack.io' }

to the repositories sections build.gradle and I won't need a baubles.jar?

 

Or would you suggest the CurseForge API?

 

 

Edited by Fijal
Posted
Just now, Fijal said:

So, I just put


deobfCompile "com.github.azanor:Baubles:${baubles_version}"

in the dependencies section of my build.gradle

and


maven { url 'https://jitpack.io' }

to the repositories sections build.gradle and I won't need a baubles.jar?

 

Yes, once you've done that you don't need to manually download the Baubles JAR.

 

Make sure you actually define the baubles_version variable somewhere (e.g. in gradle.properties). This is the tag or commit ID that you want to depend on.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)

So, gathering this all into one post, I put deobfCompile "com.github.azanor:Baubles:${baubles_version}" and maven { url 'https://jitpack.io' } in their respective sections of my build.gradle, make a gradle.properties file, and place baubles_version=7035b13 (which is still the latest commit) in it.

 

Do I need to place my versions of the following in gradle.properties as well?

mod_name=TestMod3
package_group=choonster.testmod3

mc_version=1.12.1
forge_version=14.22.0.2462

 

Also, will I be able to view BaublesApi.class as if I had the .jar?

Edited by Fijal
Posted
2 minutes ago, Fijal said:

So, gathering this all into one post, I put deobfCompile "com.github.azanor:Baubles:${baubles_version}" and maven { url 'https://jitpack.io' } in their respective sections of my build.gradle, make a gradle.properties file, and place baubles_version=7035b13 (which is still the latest commit) in it.

 

Yes.

 

2 minutes ago, Fijal said:

Do I need to place my versions of the following in gradle.properties as well?

 

You don't have to, I only have them there because my buildscript uses those variables. I do recommend doing something similar in your own buildscript.

 

3 minutes ago, Fijal said:

Also, will I be able to view BaublesApi.class as if I had the .jar?

 

Yes, the source code from the repository will be linked to the JAR in your IDE.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

So I deleted all .jar files from */libs/ so it's completely empty now, and did all the stuff we talked about up above, ran ./gradlew setupDecompWorkspace --refresh-dependencies, launched eclipse and I can no longer find any classes named BaublesAPI.class or anything similar. Should I have kept a .jar file in */libs/?

Posted
13 minutes ago, Fijal said:

So I deleted all .jar files from */libs/ so it's completely empty now, and did all the stuff we talked about up above, ran ./gradlew setupDecompWorkspace --refresh-dependencies, launched eclipse and I can no longer find any classes named BaublesAPI.class or anything similar. Should I have kept a .jar file in */libs/?


You probably need to refresh your IDE project. I think the way to do this for Eclipse is by re-running the eclipse Gradle task. If you were using IDEA, you'd just click the Refresh all Gradle Projects button in its Gradle window.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)

oooh it works now. Thanks! I thought I wouldn't need to re-run that bit.

 

Does Baubles still have that example ring? Or was that removed? I ask  because I'm not seeing it, and I imagine that would be helpful for making my own custom items.

 

Edit: nvm, I found it just as I asked...

Edited by Fijal
  • 2 years later...
Posted

I'm using eclipse IDE I've followed this thread and tried everything and can't figure out how to get this to work properly. The version you have is out of date now it is 1.5.2, but every time i try to refresh dependencies it says

  startup failed:
  build file 'C:\MinecraftModing\ElementalBaubles\build.gradle': 43: unexpected token: com.github.azanor:Baubles:1.5.2 @ line 43, column 12.
        Compile "com.github.azanor:Baubles:1.5.2"

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
    • Hi here is an update. I was able to fix the code so my mod does not crash Minecraft. Please understand that I am new to modding but I honestly am having a hard time understanding how anyone can get this to work without having extensive programming and debugging experience as well as searching across the Internet, multiple gen AI bots (claude, grok, openai), and examining source code hidden in the gradle directory and in various github repositories. I guess I am wrong because clearly there are thousands of mods so maybe I am just a newbie. Ok, rant over, here is a step by step summary so others can save the 3 days it took me to figure this out.   1. First, I am using forge 54.1.0 and Minecraft 1.21.4 2. I am creating a mod to add a shotgun to Minecraft 3. After creating the mod and compiling it, I installed the .jar file to the proper directory in Minecraft and used 1.21.4-forge-54.1.0 4. The mod immediately crashed with the error: Caused by: java.lang.NullPointerException: Item id not set 5. Using the stack trace, I determined that the Exception was being thrown from the net.minecraft.world.item.Item.Properties class 6. It seems that there are no javadocs for this class, so I used IntelliJ which was able to provide a decompiled version of the class, which I then examined to see the source of the error. Side question: Are there javadocs? 7. This method, specifically, was the culprit: protected String effectiveDescriptionId() {      return this.descriptionId.get(Objects.requireNonNull(this.id, "Item id not set"));  } 8. Now my quest was to determine how to set this.id. Looking at the same source file, I determined there was another method:  public Item.Properties setId(ResourceKey<Item> pId) {             this.id = pId;             return this;   } 9. So now, I need to figure out how to call setId(). This required working backwards a bit. Starting from the constructor, I stubbed out the variable p which is of type Item.Properties public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); Rather than putting this all on one line, I split it up for readability like this: private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); Here is was the missing function, setId(), which takes a type of ResourceKey<Item>. My next problem is that due to the apparent lack of documentation (I tried searching the docs on this site) I could not determine the full import path to ResourceKey. I did some random searching on the Internet and stumbled across a Github repository which gave two clues: import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; Then I created the rk variable like this: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); And now putting it all together in order: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); This compiled and the mod no longer crashes. I still have more to do on it, but hopefully this will save someone hours. I welcome any feedback and if I missed some obvious modding resource or tutorial that has this information. If not, I might suggest we add it somewhere for people trying to write a mod that doesn't crash. Thank you !!!  
    • I will keep adding to this thread with more information in case anyone can help, or at the very least I can keep my troubleshooting organized. I decided to downgrade to 54.1.0 in the hopes that this would fix the issue but it didn't. At least now I am on a "recommended" version. The crash report did confirm my earlier post that the Exception is coming from effectiveDescriptionId(). I'll continue to see if I can find a way to set the ID manually.   Caused by: java.lang.NullPointerException: Item id not set         at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item$Properties.effectiveDescriptionId(Item.java:465) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item.<init>(Item.java:111) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ShotgunItem.<init>(ShotgunItem.java:19) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ModItems.lambda$static$0(ModItems.java:15) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister$EventDispatcher.lambda$handleEvent      
    • It just randomly stop working after a rebooted my dedicated server PLEASE HELP!   com.google.gson   Failed to start the minecraft server com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $  
  • Topics

×
×
  • Create New...

Important Information

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