GregTechCE / GregTech

GregTech rewrite for modern versions of Minecraft
GNU Lesser General Public License v3.0
271 stars 150 forks source link

[Suggestion] Additional CT Getters for Mats and OreDict #1015

Open Epic428 opened 4 years ago

Epic428 commented 4 years ago

I'd like to propose new CT Getters to get specific arrays of data on Ore Dictionary entries and Material Lists. Specifically, looking for arrays which would contain a list of all plate OreDict entries, stick entries, screw, gear etc. Additionally looking for arrays which would provide lists of all materials used for tools.

Take for example the CT script below. It only modifies recipes for about half of the possible wire cutter varieties so they can be crafted in an artisan workbench. However, if I extrapolate the data to include all Hammer, File, Drill, Screwdriver, etc. varieties the amount of hard coded data necessary begins to pile up.

import mods.artisanworktables.builder.RecipeBuilder;
import mods.gregtech.material.Material;
import crafttweaker.item.IItemStack;
import crafttweaker.item.IIngredient;
import crafttweaker.oredict.IOreDict;
import crafttweaker.oredict.IOreDictEntry;

print("***** Artisan Wire Cutters!!! *****");

//Set array of materials with proper case
val matArray = ["iron", "bronze", "steel", "darmstadtium", "damascus_steel", "blue_steel", "magnalium", "wrought_iron", "aluminium",
  "ultimet", "hssg", "naquadah_alloy", "naquadah_enriched"] as string[];

//Set array of OreDict mats with proper case
val oreDictArray = ["Iron", "Bronze", "Steel", "Darmstadtium", "DamascusSteel", "BlueSteel", "Magnalium", "WroughtIron", "Aluminium",
    "Ultimet", "Hssg", "NaquadahAlloy", "NaquadahEnriched"] as string[];

//Loop through material array and create recipe for wire cutter tool.
for i, mat in matArray{

  //set plate oredict for current material
  var def = "plate" ~ oreDictArray[i];
  val plate = oreDict.get(def) as IOreDictEntry;

  //set rod oredict for current material
  def = "stick" ~ oreDictArray[i];
  val rod = oreDict.get(def) as IOreDictEntry;

  //set rod oredict for current material
  def = "screw" ~ oreDictArray[i];
  val screw = oreDict.get(def) as IOreDictEntry;

  //Create Recipe for Tool with proper material
  RecipeBuilder.get("engineer")
    .setShaped([
      [plate, null, plate],
      [null, screw, null],
      [rod, null, rod]])
      .addTool(<ore:craftingToolFile>, 1)
      .addTool(<ore:craftingToolScrewdriver>, 1)
      .addTool(<ore:craftingToolHardHammer>, 1)
      .addOutput(<gregtech:meta_tool:13>.withTag({
"GT.ToolStats": {Material:mat}}))
      .create();
}

Being able to call a method which returns and array of oreDict entries for various components and materials would make this much more efficient and easier to handle.

so for example you could have a variable oreDictEntry that calls a method of getPlates() and returns an array containing all plate oreDict entries like so `[, ,...]

same thing would work for Materials - being able to get a list of materials which are all fluids, or all dusts, or ingots, or usable for tools, etc.

I'm not sure, off the top of my head what other use cases these getters would have beyond being able to modify large amounts of tool recipes but it is possible they could be useful elsewhere as well.

Archengius commented 4 years ago

I don't have such lists ready until late preinit, and they are used for ore dictionary-driven recipe generation in GTCE primarily. I don't see methods like that needed because they are very specialised. While I can give you these lists (but beware they're not complete at the stage CT runs in), I suggest using more standardized approach used in GTCE: ore dictionary processing handlers, which will be called in special stage to generate recipes. Example case:

OrePrefix.get("plate").registerProcessingHandler(function(prefix, material, itemStack) {
    //Do something with material/item stack there
});
Epic428 commented 4 years ago

Is OrePrefix something I can use in crafttweaker? This is my first time playing around with it so still learning.

The sample script I posted above is the script I’m currently using and with subsequent recipes it hasn’t been terribly difficult to replicate it since at this point I have about 60 materials hardcoded into an array. My goal is to make the scripts more optimized but allow for any possible changes in materials or oredict entries down the line without needing to be rewritten.

I’m ok with a different approach to accomplishing the goal if such suggestions aren’t feasible or don’t make sense.

Edit: ok looking at the docs for crafttweaker again I see where I can get an IOreDictEntry with a given prefix. So that’s useful. I’ll keep looking to see how I can improve this further.

Reading further if I could pull a master list of ores then get the ore entries from there maybe I could make this work differently.