Added protection for other mods causing crashes when drawing an item or display name

This commit is contained in:
raoulvdberge
2017-09-08 12:27:31 +02:00
parent 015156dcd3
commit 20d6e540e3
3 changed files with 37 additions and 16 deletions

View File

@@ -4,6 +4,7 @@
- Added Project E integration for the External Storage on the Transmutation Table (raoulvdberge)
- Added Project E integration for the energy values of Solderer items (raoulvdberge)
- Added support for more than 4 grid tabs in the Grid by putting filters IN filters (raoulvdberge)
- Added protection for other mods causing crashes when drawing an item or display name (raoulvdberge)
- Fixed network not disconnecting when Controller is broken (raoulvdberge)
- Fixed bug where when multiple Fortune Upgrades are inserted, it chooses the first Fortune Upgrade instead of the highest one (raoulvdberge)
- Fixed some translations having too big "Craft" text (raoulvdberge)

View File

@@ -261,7 +261,11 @@ public abstract class GuiBase extends GuiContainer {
zLevel = 200.0F;
itemRender.zLevel = 200.0F;
itemRender.renderItemIntoGUI(stack, x, y);
try {
itemRender.renderItemIntoGUI(stack, x, y);
} catch (Throwable t) {
// NO OP
}
if (withOverlay) {
drawItemOverlay(stack, text, x, y);
@@ -272,7 +276,11 @@ public abstract class GuiBase extends GuiContainer {
}
public void drawItemOverlay(ItemStack stack, @Nullable String text, int x, int y) {
itemRender.renderItemOverlayIntoGUI(fontRenderer, stack, x, y, "");
try {
itemRender.renderItemOverlayIntoGUI(fontRenderer, stack, x, y, "");
} catch (Throwable t) {
// NO OP
}
if (text != null) {
drawQuantity(x, y, text);

View File

@@ -58,7 +58,11 @@ public class GridStackItem implements IGridStack {
@Override
public String getName() {
return stack.getDisplayName();
try {
return stack.getDisplayName();
} catch (Throwable t) {
return "";
}
}
@Override
@@ -69,7 +73,11 @@ public class GridStackItem implements IGridStack {
@Override
public String[] getOreIds() {
if (oreIds == null) {
oreIds = Arrays.stream(OreDictionary.getOreIDs(stack)).mapToObj(OreDictionary::getOreName).collect(Collectors.toList()).toArray(new String[0]);
if (stack.isEmpty()) {
oreIds = new String[]{};
} else {
oreIds = Arrays.stream(OreDictionary.getOreIDs(stack)).mapToObj(OreDictionary::getOreName).collect(Collectors.toList()).toArray(new String[0]);
}
}
return oreIds;
@@ -77,22 +85,26 @@ public class GridStackItem implements IGridStack {
@Override
public String getTooltip(boolean quantity) {
List<String> lines = stack.getTooltip(Minecraft.getMinecraft().player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL);
try {
List<String> lines = stack.getTooltip(Minecraft.getMinecraft().player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL);
// From GuiScreen#renderToolTip
for (int i = 0; i < lines.size(); ++i) {
if (i == 0) {
lines.set(i, stack.getRarity().rarityColor + lines.get(i));
} else {
lines.set(i, TextFormatting.GRAY + lines.get(i));
// From GuiScreen#renderToolTip
for (int i = 0; i < lines.size(); ++i) {
if (i == 0) {
lines.set(i, stack.getRarity().rarityColor + lines.get(i));
} else {
lines.set(i, TextFormatting.GRAY + lines.get(i));
}
}
}
if (quantity && !lines.isEmpty()) {
lines.set(0, lines.get(0) + " " + TextFormatting.GRAY + "(" + RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(stack.getCount()) + "x)" + TextFormatting.RESET);
}
if (quantity && !lines.isEmpty()) {
lines.set(0, lines.get(0) + " " + TextFormatting.GRAY + "(" + RenderUtils.QUANTITY_FORMATTER_UNFORMATTED.format(stack.getCount()) + "x)" + TextFormatting.RESET);
}
return lines.stream().collect(Collectors.joining("\n"));
return lines.stream().collect(Collectors.joining("\n"));
} catch (Throwable t) {
return "";
}
}
@Override