Java exception based on the ordering of terms around an &&
blockgoblin31 opened this issue ยท 5 comments
Issue description
this code:
} else if count == (length as long) as int && (((crushers.length as ulong) as long) as double - enabled[j]) <= i {
breaks things, while the line } else if (((crushers.length as ulong) as long) as double - enabled[j]) <= i && count == (length as long) as int {
works fine. I'll share the script with the working line. crushers is a IRecipeManager[] and length is a variable equal to the length of a WrapperRecipe[]( val length = currentRecipes.length;
). the error is on line 10449 of the crafttweaker.log
Steps to reproduce
umm...idk... just try it ig?
Script used
https://gist.github.com/tuc56/1e9e4acce30d19314dea8b5d76dfffcf
The crafttweaker.log file
https://gist.github.com/tuc56/de785751a0e748a0f9c82efa3bb44899
Minecraft version
1.16
Modloader
Forge
Modloader version
36.2.34
CraftTweaker version
7.1.2.515
Other relevant information
mostly up to date modlist.html here: https://github.com/tuc56/processing-pack/blob/main/modlist.html
The latest.log file
https://gist.github.com/tuc56/68135f4f11d52ec9cdf4c2895445dfca
This script should work, it still isn't ideal but it is much better than what you have
//priority 0 so it loads after all other scripts
#priority 0
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.item.IIngredient;
import mods.mekanism.api.ingredient.ItemStackIngredient;
import crafttweaker.api.registries.IRecipeManager;
import crafttweaker.api.item.MCWeightedItemStack;
import crafttweaker.api.recipes.WrapperRecipe;
//item inputs. Does not accept tags.
val crush = [<item:contenttweaker:core_gem>, <item:contenttweaker:pure_cluster>] as IItemStack[];
//item outputs.
val crushed = [<item:contenttweaker:core_dust>, <item:contenttweaker:pure_powder>] as IItemStack[];
//machines
val crushers = [<recipetype:create:milling>, <recipetype:immersiveengineering:crusher>, <recipetype:create:crushing>, <recipetype:thermal:pulverizer>, <recipetype:mekanism:crushing>] as IRecipeManager[];
//minimum tier of the machine that is enabled
val enabled = [5, 5] as int[];
//loops through each defined machine
for i, crusher in crushers{
//gets all the recipes of the machine
var currentRecipes = crusher.getAllRecipes() as WrapperRecipe[];
for j, item in crush {
//init as 1 because the final recipe won't add 1 to count
var count = 1;
val length = currentRecipes.length;
for recipe in currentRecipes {
//don't add to the count if there's already a recipe with the ingredient
if item in recipe.ingredients {
} else if (crushers.length as double - enabled[j]) <= i /*checks if the current machine is one of the ones that should be enabled*/ && count == length as int {
//check which recipetype we're doing currently and add a recipe to that
if crusher == <recipetype:create:milling> {
<recipetype:create:milling>.addRecipe("milling"+"_"+j as string, [crushed[j]], item);
}
if crusher == <recipetype:immersiveengineering:crusher> {
<recipetype:immersiveengineering:crusher>.addRecipe("crushing_immersive"+"_"+j as string, item, 500, crushed[j]);
}
if crusher == <recipetype:create:crushing> {
<recipetype:create:crushing>.addRecipe("crushing_create"+"_"+j as string, [crushed[j]], item);
}
if crusher == <recipetype:thermal:pulverizer> {
<recipetype:thermal:pulverizer>.addRecipe("pulverising_"+j as string, [crushed[j]], item, 0, 500);
}
if crusher == <recipetype:mekanism:crushing> {
<recipetype:mekanism:crushing>.addRecipe("crushing_mekanism_"+j as string, ItemStackIngredient.from(item), crushed[j]);
}
} else {
count++;
}
}
}
}
The reason they require casting is because they return a usize
type, which currently does not have proper casting rules to other types, this will hopefully be fixed in the near future
and anyway the problem was if I swapped between those two if lines, one produced a java error and the other was fine
what I meant about the casting was stuff like as ulong) as long) as double. I tried like every different combination 4 casts or less and those were the only ones that didnt give a error(I dont remember exactly what the error was, but its based on not knowing which type to use)