Grid class - is where cool stuff happens.
Its receive an 2d list of string with 1 char keys and map of key-Ingredient pairs.
Then it parsing input to generate IIngredient[][]
array that can be used in vanilla recipes.addShaped()
or modded crafting grids (like Astral Sorcery Altairs).
Grid
(gridStr asstring[]
, options asIIngredient[string]
)
Providing instance of Grid
class.
gridStr
can be any size, not just 3x3.
Each string can be vary size too.
var grid = Grid([
"-===-",
"",
"-===-"
], ingrs);
If the first element of gridStr
is "pretty"
, each even character would be ignored. This exists to make big grids looks prettier.
Shortand for "pretty"
is "𝓹"
var a = Grid([
"𝓹",
"* * *",
"* * *"
], ingrs);
var b = Grid([
"pretty",
"*-*-*-",
"*-*-*-"
], ingrs);
// ^ Both equal to >
var c = Grid([
"***",
"***"
], ingrs);
Type: string
Return error string if something wrong (for example if grid options have no keys listed in grid string array)
val grid = Grid([], {});
# Would print "Grid string have no elements"
if (!isNull(grid.error)) print(grid.error);
Type: int
Maximum grid sizes by X (width) and Y (height).
grid.shaped() as
IIngredient[][]
Create an 2d array to use in shaped recipes.
If gridStr
had spaces " "
, they would be replaced to null
s.
# Forestry's Carpenters accept this kind of array
mods.forestry.Carpenter.addRecipe(<forestry:letters>, Grid([
"AAA",
"AAA"], {
A: <thermalfoundation:material:800>
}).shaped(), 40, <liquid:water> * 250);
# Can be used in Vanilla recipes too
recipes.addShaped(output, grid.shaped());
grid.shapeless() as
IIngredient[]
Create an 1d array to use in shapeless recipes.
All spaces " "
and wrong ingredients would be ignored, so resulted array never has null
s.
recipes.addShapeless(output, grid.shapeless());
grid.getMainIngredient() as
IIngredient
Returns IIngredient
that grid think most important in craft. Usually, its less used item, closest to center of grid.
# Returns ingrs.I
Grid(["###",
"-I-",
"-#-"
], ingrs).getMainIngredient();
# Returns ingrs.B
Grid(["AA",
"AB"
], ingrs).getMainIngredient();
grid.toString([style as
string[]
]) asstring
Return string representation of grid.
Parameters
style
optional - array of keywords that control additional features:
"pretty"
- Would generate spaces between characters in grid string and adds"pretty"
keyword. Ignored with"dense"
"dense"
- No new lines would be added"fancy"
- Would add item names. Ignored with"no_map"
"no_map"
- Instead of stringify bothgridStr
andoptions
, onlygridStr
would be outputted
Examples
Note how command characters ╲
and .
substituted into normal ingredient letters.
More about command characters below.
val grid = Grid([
"ABA",
"╲C."], {
A: <ore:logWood>, # Oak Log
B: <ore:plankWood>, # Oak Wood Planks
C: <ore:ingotIron> # Iron Ingot
});
grid.toString(["pretty", "fancy"]);
/* Outputs:
["pretty",
"A B A",
"B C B"], {
"A": <ore:logWood>, # Oak Log
"B": <ore:plankWood>, # Oak Wood Planks
"C": <ore:ingotIron> # Iron Ingot
}
*/
String array can contain special characters that mirror ingredients in different axes.
This can help when you building huge recipes manually and won't insert same letter 4 times for each side.
Remember: if command character would be used as key in options
, it functionality would be ignored and would be used as regular character key.
" "
in string array meansnull
"."
try to find ingredients by mirroring, in order:- By vertical axis
←→
" " " " "A ." => "A A" " " " "
- By horisontal axis
↕
" A " " A " " " => " " " . " " A "
- Both axis
⮤⮧
" A " " A " "B " => "B " " ." " B" " . " " A "
- By vertical axis
"╲"
or","
try to find ingredients by mirroring aroundx=y
axis🡕🡗
" A " " A " "╲ ╲" => "A B" " B " " B "
Real example from Enigmatica2: Expert - Extended:
# Mekanism Creative Energy
var creativeCube = <mekanism:energycube>.withTag({tier:4,mekData:{energyStored:1.7976931348623157E308}});
craft.make(creativeCube, ["pretty",
"◘ ◘ ◙ ◙ τ . . . .",
"◘ ◊ V □ □ . . . .",
"Ψ V W ◽ ⁵ . . . .",
"Ψ ⌂ ◽ ■ ☻ . . . .",
"κ ⌂ ⁵ ⫲ X . . . .",
". . . . . . . . .",
". . . . . . . . .",
". . . . . . . . .",
". . . . . . . . ."], list);
Using Bone to make recipes is just "helper". Some functions you can use manually in code.
craft.make(output as
IItemStack
, gridStr asstring[]
, options asIIngredient[string]
, [fnc asIRecipeFunction
])
Alias: craft.shaped
Create new Crafting Table shaped recipe.
Unique recipe name generated automatically.
This and all functions of craft
is stable for any kind of wrong arguments. If you did a mistake, warning will be outputted in crafttweaker.log
without an exception error.
Parameters
output
- Item that used as outputgridStr
- String array with letters represents ingredients. See rules and tricks at Grid section.options
- Map, where keys is letters fromgridStr
and values as input ingredients.fnc
optional - Recipe Function that would be just transfered into vanillarecipes.addShaped()
function
Examples
// Remove vanilla chest and add custom shaped recipe
recipes.remove(<minecraft:chest>);
craft.make(<minecraft:chest> * 2, [
"uwu",
"wBw",
"uwu"], {
"w": <ore:plankTreatedWood>,
"B": <minecraft:stone_button>,
"u": <ore:logWood>
});
craft.shapeless(output as
IItemStack
, gridStr asstring
, options asIIngredient[string]
, [fnc asIRecipeFunction
])
Same as craft.make
, but shapeless
Parameters
gridStr
-string
(!) instead ofstring[]
unlike incraft.make()
. Also can't use"pretty"
keyword (See more: Grid)
Examples
craft.shapeless(<gendustry:pollen_kit> * 4, "AC-DC", {
A: <forestry:crafting_material:2>,
C: <gendustry:labware>,
D: <ore:dustEmerald>
});
// Note that "-" character is not defined in options. It would be just omitted in resulting recipe
craft.remake(output as
IItemStack
, gridStr asstring[]
, options asIIngredient[string]
, [fnc asIRecipeFunction
])
Alias: craft.reshaped
Same as craft.make
, but would remove old recipe first by calling
recipes.remove(output);
craft.reshapeless(output as
IItemStack
, gridStr asstring
, options asIIngredient[string]
, [fnc asIRecipeFunction
])
Same as craft.remake
, but shapeless
Examples
# Lesser blaze powder
craft.reshapeless(<minecraft:blaze_powder>, "A", {
A: <minecraft:blaze_rod>
});