-
Notifications
You must be signed in to change notification settings - Fork 107
[EN] Dev Cheat Sheet
The purpose of this page is for developers to document helpful functions for future use. If you have any JavaScript or java code that would be nice to share please put it here.
Here is an example of turning an item tag into an array, you can omit any part as necessary.
const tag_array = Ingredient.of('#forge:tag').itemIds.toArray().map(String);
- .itemIds This accesses the list of item ids from that ingredient tag. The result is a Java Set.
- .toArray() This converts the list (which is a Java Set) into a JavaScript array.
- .map(String) This converts each item ID in the array to a string. Required for most js functions, but not all.
Here is an example of using an array in a recipe to produce the same array, except the original item. Useful for stonecutters, dyeing, etc.
const tag_array = Ingredient.of('#forge:tag').itemIds.toArray().map(String);
tag_array.forEach(item => {
event.stonecutting(item,
Ingredient.of('#forge:tag').subtract(item)
).id(`tfg:stonecutter/${item.replace(/:/g, "/")}`)
})
Note: If you are using multiple inputs or multiple subtractions to will have to format it like this example:
let example = Ingredient.of('#forge:tag').subtract('item:1').subtract('item:2').withCount(8)
The example below is used in the armor trim builder.
materials.forEach(material => {
const trimfilepaths = [
`kubejs/data/minecraft/trim_material/${material.materialName}.json`,
`kubejs/data/tfc/trim_material/${material.materialName}.json`
];
const newtrimdata = {
asset_name: material.materialName,
description: {
color: material.nameColor,
translate: `trim_material.tfc.${material.materialName}`
},
ingredient: material.itemName,
item_model_index: material.indexNumber
};
trimfilepaths.forEach(trimfilepaths => {
const existingData = JsonIO.read(trimfilepaths);
// Only write if the file is missing or contents are different
if (JSON.stringify(existingData) !== JSON.stringify(newtrimdata)) {
JsonIO.write(trimfilepaths, newtrimdata);
}
});
});
- Declare the file paths. (example above:
trimfilepaths
) - Create a const version of the json information. (example above:
newtrimdata
) - For each file path, read its contents, and write new data if missing. (example above: existingData)
Useful for seeing how recipe Jsons are currently written so that you can edit them.
event.forEachRecipe({ id: string }, (recipe) => {
console.log(recipe.json.toString());
});
- You can replace
{id: string}
with any kubejs recipe method; like{type: string}
or{mod: string}
for example.
Pre-made utility script can be found at: gtceu/utility.js
And the global array at: gtceu/constants.js
You can add circuit numbers to gtceu by overwritting its json like so:
event.findRecipes({ id: string }).forEach(recipe => {
// Get the existing "inputs" JsonObject
const inputs = recipe.json.get("inputs");
// Get the current item array or create a new one
const itemArray = inputs.has("item") ? Java.from(inputs.get("item")) : [];
// Push the circuit input Json
itemArray.push({
content: {
type: "gtceu:circuit",
configuration: 1
},
chance: 0,
maxChance: 10000,
tierChanceBoost: 0
});
// Set the updated item array back into the inputs
inputs.add("item", itemArray);
// Re-apply modified inputs into recipe JSON
recipe.json.add("inputs", inputs);
});
You can also directly overwrite the inputs as well, this will remove any other pre-existing inputs:
event.findRecipes({ id: string }).forEach(recipe => {
recipe.json.add("inputs",
{
item: [
{
content: {
type: "gtceu:circuit",
configuration: 1
},
chance: 0,
maxChance: 10000,
tierChanceBoost: 0
}
]
}
)
})
- You can replace
{id: string}
with any kubejs recipe method; like{type: string}
or{mod: string}
for example.
How to write chanced input/output ingredients for gtceu recipes.
.chancedOutput('minecraft:dirt', 100, 0)
.chancedInput('minecraft:dirt', 100, 0)
.chancedFluidInput(Fluid.of('minecraft:water', 100), 1000, 0)
.chancedFluidOutput('minecraft:water 1000', 100, 0)
- First number is the chance with 1 being 0.01% and 10000 being 100%
- Second number is the increase with each energy tier (this feature is scrapped for GTm 7.0)
In order to use particle types from other mods without making them dependencies you can use ForgeRegistries.PARTICLE_TYPES.getValue()
. Here is an example using ae2:lightning_fx
. If the mod isnt present it will fallback to minecraft:end_rod
.
@Override
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
for (int i = 0; i < 4; i++) {
if (level.isClientSide) {
ParticleType<?> pt = ForgeRegistries.PARTICLE_TYPES.getValue(new ResourceLocation("ae2", "lightning_fx"));
if (pt instanceof SimpleParticleType) {
level.addAlwaysVisibleParticle((SimpleParticleType) pt, true,
pos.getX() + 0.5 + (random.nextFloat() - 0.5) * 0.5,
pos.getY() + random.nextDouble(),
pos.getZ() + 0.5 + (random.nextFloat() - 0.5) * 0.5,
0.1, 0.1, 0.1);
} else {
// Fallback with vanilla particle
level.addAlwaysVisibleParticle(ParticleTypes.END_ROD, true,
pos.getX() + 0.5,
pos.getY() + 0.5,
pos.getZ() + 0.5,
0.1, 0.1, 0.1);
}
}
}
}
If your mixin overrides anything in minecraft or injects into a method that was inherited from something in minecraft, your mixin needs remap = true
. Everything else should use remap = false
.
To get a mixin's remap path, right-click the method in intellij and hit Copy Special > Mixin Target Reference
If you want to generate a recipe for a gregtech machine without greate generating a recipe (for example, a bender recipe that you don't want in the mech press), put _electric_only
or _manual_only
on the end of the recipe ID.
(_manual_only
is inspired by base create, where this suffix stops create from generating a bulk blasting recipe from a smelting recipe, etc)
You can grow planters instantly by right-clicking them with a block of bedrock.
If you've got a custom material with a more complex chemical formula, but you need to tell gregtech "it's composed of X oxygen, Y hydrogen, Z whatever" for it to generate decomp recipes, you can use:
material.setFormula("Al2Si2O5(OH)4", true)
to change the chemical formula tooltip to whatever you'd like! I think the true
turns the numbers into subscripts.
The gregtech discord has a bot for checking your chemical formulas are balanced. Here's an example.
For solid items, 1 mol = however many atoms are in that molecule of that item, so 1 mol of Al2O3 is 5 sapphire dust.
For liquid items it's the opposite, where 1 mol = 1 bucket. So 1 mol of H2O is one bucket.