Skip to content

UniDictAPI

Wanderson edited this page Dec 11, 2021 · 12 revisions

What is UniDictAPI

our API has some usefull features, like, the possibility to Blacklist ItemStacks directly from other mods.

also, it has a Resource Gathering API, our CraftTweaker Support only exists because of UniDictAPI.

How to use UniDictAPI?

in order to use it, you must download our -dev.jar, it is avaiable for almost all UniDict versions. after, you must include it on your project as a dependency.

How many files does UniDictAPI have?

for now, just one.

How to Blacklist an ItemStack?

there is an static method on our API, addItemStackToBlackList(ItemStack), just pass any ItemStacks that you want to Blacklist.

How does the Resource Gathering works?

UniDict is an unification mod, in order to it to work, it needed to gather Resouces, though, a lot of these Resources were unused, then we decided to move it to our API, in order to this gathering be somehow usefull.

How to Gather Resources?

UniDictAPI Resource Gathering may be a bit memory-heavy, so, please do not create a static final reference to it, otherwise we may endup having a memory leak.

In order to use it, you first need to get the it's instance, by calling wanion.unidict.UniDict.getAPI()

Note: you can only get this instance up to the end of the LoadComplete LoadStage, trying to get it later will result in a NullPointerException.

then, with the instance, you can just call wanion.unidict.api.UniDictAPI.getResources(String...).

it require some strings, these strings are the kinds that you want and them will act like a filter, like, you can pass it "ore", "ingot", and it will return a List that all Resources contains ores and ingots, so you don't have to check one by one if it really has the "kinds" that you want.

Note : to check all the avaiable kinds, enable B:kindsDump in config/unidict/UniDict.cfg.

Note2 : since the kinds are dynamically generated, the kinds list may vary depending on the mods that you have installed.

Why UniDictAPI would be usefull to my mod?

when we create a mod that adds processing, we have a few options in order to create our recipes:

  1. we hardcode the Recipes directly on the source code.
  2. we create our own Resource Gathering.

on the first case, we would have to hardcode absolutely all the Recipes, which can quickly become boring.

on the second case, it will take a lot of time...

using UniDictAPI, you don't have to worry about these boring stuffs, so you can focus on what really matters, your mod.

Is there any usage example?

yeah, see:

// first we get the Instance of UniDictAPI.
UniDictAPI uniDictAPI = UniDict.getAPI();

// getting the actual kind id isn't required, but it is a good practice, the methods accepts strings without any issues.
int ore = Resource.getKindFromName("ore");
int dust = Resource.getKindFromName("dust");

// we are getting the resources that contains ore, and dust.
// the getResources method acts as a filter, so we don't need to null-check the resources later.
// note: there is no limit here, so we could add way more than just ore, and dust.
List<Resource> oresAndDusts = uniDictAPI.getResources(ore, dust);

// let's consider this map our recipes.
Map<ItemStack, ItemStack> recipes = new HashMap<>();

// now we are going to loop though the Resource List, in order to create our recipes.
// the parameter of getMainEntry is the desired StackSize
// there is also the possibility to pass an ItemStack to it, it will use the StackSize of the given ItemStack.
for (Resource resource : oresAndDusts)
    recipes.put(resource.getChild(ore).getMainEntry(), resource.getChild(dust).getMainEntry(2));

or, if you prefer, checkout this gist

that's all, within 7 source lines, you just created the recipes for some kind of ore doubling machine.