CraftTweaker

CraftTweaker

151M Downloads

Feature Request: Arrays in a List

Laifsyn opened this issue ยท 6 comments

commented

Describe the feature you'd like

#PseudoCode:
var array1 = [Item1, Item2] IItemStack[];
var array2 = [Item1, Item2] IItemStack[];
list.add(array1);
list.add(array2);
ResultArray = list;
craftingTable.addShaped(ARandomName, MyOutput, ResultArray);
// craftingTable.addShaped(ARandomName, MyOutput, [ResultArray[0] , ResultArray[1]]);

Describe alternatives you've considered

No response

Additional context

idk what happened with BetterNether, but it seems the iterated recipes doesn't show on my REI, and so to fix it, I want to re-add the recipes in a manner that could be considered automatic, but without the ability to use arrays or cast arrays into list, It's more convenient for me to just semi automatically create the recipes

Minecraft version

1.18

Modloader

All

commented

but without the ability to use arrays or cast arrays into list

Lists and Arrays can be converted from one another.

import stdlib.List;

var array = ['a', 'b', 'c'] as string[];
var list = array as stdlib.List<string>;

You can have Lists whose base type is an array, by specifying the proper type.

import stdlib.List;

var stringArray_List = new List<string[]>;
stringArray_List.add(["a", "b", "c"]);

Though, why don't you just use a nested array then?

var stringArray_Array = [
    ["a", "b", "c"]
] as string[][];

?

idk what happened with BetterNether, but it seems the iterated recipes doesn't show on my REI

I do not know what BetterNether does either, nor do I understand what you mean by iterated recipes, so I cannot provide further insight.

If you need help with scripts, it may be easier to ask on The BlameJared discord server (if you have a discord account)
https://discord.blamejared.com/

As your issue is written right now, I do not understand this request nor the reasoning behind it.

commented

I still don't quite understand your usecase.
So you want to have a list of 2D arrays for something?

Like e.g.

import stdlib.List;
import crafttweaker.api.ingredient.IIngredient;

var list = new List<IIngredient[][]>();

var dirt = <item:minecraft:dirt>;
list.add([[dirt], [dirt], [dirt]]);
list.add([[dirt], [dirt], [dirt]]);

for index, theRecipe in list {
    craftingTable.addShaped("name_" + index, <item:minecraft:diamond>, theRecipe);
}

One thing you need to be careful of, is that you may not have two recipes with the same name in CraftTweaker, as they would override each other.

commented

Essentially this is what I'm looking for - Able to cast an Array[] var into a List[index]

val dirt = <item:minecraft:dirt>;
var Ingredient3x3Array = [[dirt],[dirt],[dirt]] as IIngredient[][];
var list as stdlib.List<IIngredient[]>;
list.add(Ingredient3x3Array); 
craftingTable.addShaped("name", <item:minecraft:diamond>, list[0])//Let's just assume that whoever adds this as IIngredient, is expected to have added a correct 3x3 array to list[index]

Context. When using removeByRegex, you can get the recipe path name. Which is technically having the recipe's mapdata as long you concatenate the correct namespace.

When you get the IIngredients of the retrieved recipes, you get a list(?)/array(?) of the Ingredients. And I wanted to cast that whole list(Or array?) into a another list's single index. (even if it's a 1D Array, it can be converted into a 2D with a for loop by calling the array in List[index]) so I wouldn't need to do iterative math like List.length()/9, which on second thought might be realiseable.

The second part is allowing the Add Recipes method to accept a array-ed var, which didn't work when I tried (I might've written something wrong though if it actually works)

As for BetterEnd/BetterNether part, I've had issues with their recipes because it sometimes doesn't show on REI for some weird reason, and I wanted to iterate these recipes and re-do them(technically renaming them) so they consistently show on REI

commented

Yes. the name would be casted to NameList[n-index] and the full IIngredients[](or IIngredients[][]) to IngredientList[n-index]

commented

Is this still an issue?
The code from the example above should already be working?

commented

Closing this due to no reply and issue is most likely resolved.