CraftTweaker

CraftTweaker

151M Downloads

Getting an item by name (string)

copygirl opened this issue · 2 comments

commented

For the purpose of simplifying certain types of scripts, it would be nice to be able to get an item by name, where the name is a string, rather than using bracket handlers - which I believe could not work with string concatenation.

Here is an example script using this:

import mods.jei.JEI;

var tool_types = [ "shovel", "pickaxe", "axe", "sword", "hoe"] as string[];
var embers_materials = [ "copper", "silver", "lead", "aluminum", "bronze", "electrum", "nickel", "tin" ] as string[];
var mystical_world_materials = [ "copper", "silver" ] as string[];

for tool in tool_types {
    for mat in embers_materials
        JEI.removeAndHide(game.getItem("embers:" + tool + "_" + mat));
    for mat in mystical_world_materials
        JEI.removeAndHide(game.getItem("mysticalworld:" + mat + "_" + tool));
    // May have to use .defaultInstance on the IItemDefinition
}

If this is already possible, then I apologize. I could not find a way to do this in the documentation.

commented

Thank you. To be fair, the search on the documentation is practically useless when looking for common words, and searching online (and even for code in this repo) did not yield anything to me.