Fix crash when transferring recipe

This commit is contained in:
Discreater committed 2022-11-18 17:04:41 +08:00
1 parent 29565d8b16
commit 903743d0a3
6 files changed
+48 -19

No files matched your search

@@ -147,9 +147,8 @@ public class CostList {
addCatalyst(next.one.getLabel(Recipe.IO.CATALYST));
next = find(true);
}
if (count++ > 1000 && player != null) {
player.addChatMessage(
new ChatComponentTranslation("jecalculation.chat.max_loop"));
if (count++ > 1000) {
Utilities.addChatMessage(Utilities.ChatMessage.MAX_LOOP);
break;
}
}
@@ -83,8 +83,14 @@ public class Adapter {
if (resultStack != null)
outputs.add(resultStack.items);
for (IAdapter adapter : adapters) {
adapter.handleRecipe(recipe, index, inputs, outputs);
try {
for (IAdapter adapter : adapters) {
adapter.handleRecipe(recipe, index, inputs, outputs);
}
} catch (Exception e) {
Utilities.addChatMessage(Utilities.ChatMessage.RECIPE_TRANSFER_ERROR);
JustEnoughCalculation.logger.error("Exception when handling recipe: " + recipe.getClass().getName());
e.printStackTrace();
}
}
}
@@ -18,6 +18,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
import net.minecraftforge.fluids.Fluid;
import org.apache.commons.io.FileUtils;
@@ -52,10 +53,10 @@ public class Utilities {
// FLOAT FORMATTING
public static char[] suffix = new char[]{'K', 'M', 'B', 'G', 'T', 'P'};
public static DecimalFormat[] format = new DecimalFormat[]{new DecimalFormat("#."),
new DecimalFormat("#.#"),
new DecimalFormat("#.##"),
new DecimalFormat("#.###"),
new DecimalFormat("#.####")};
new DecimalFormat("#.#"),
new DecimalFormat("#.##"),
new DecimalFormat("#.###"),
new DecimalFormat("#.####")};
public static String cutNumber(float f, int size) {
BiFunction<Float, Integer, String> form = (fl, len) -> format[len - 1 - (int) Math.log10(fl)].format(fl);
@@ -153,6 +154,27 @@ public class Utilities {
return Objects.requireNonNull(ClientUtils.mc().thePlayer);
}
public static void addChatMessage(ChatMessage cm) {
EntityClientPlayerMP player = Utilities.getPlayer();
if (player != null)
player.addChatMessage(new ChatComponentTranslation(cm.get()));
}
public enum ChatMessage {
MAX_LOOP, RECIPE_TRANSFER_ERROR;
private String get() {
switch (this) {
case MAX_LOOP:
return "jecalculation.chat.max_loop";
case RECIPE_TRANSFER_ERROR:
return "jecalculation.chat.recipe_transfer_error";
default:
return "";
}
}
}
public static class Relation<K, V> {
public HashMap<Pair<K, K>, V> data = new HashMap<>();
@@ -287,8 +309,8 @@ public class Utilities {
public static List<String> wrap(String s, int width) {
return new TextWrapper().wrap(s,
ClientUtils.mc().getLanguageManager().getCurrentLanguage().getLanguageCode(),
i -> TextWrapper.renderer.getCharWidth(i), width);
ClientUtils.mc().getLanguageManager().getCurrentLanguage().getLanguageCode(),
i -> TextWrapper.renderer.getCharWidth(i), width);
}
static class TextWrapper {