Guard against IOOBEs when rendering the new spell trade icon, fixes #565

This commit is contained in:
Electroblob77
2020-12-20 00:16:17 +00:00
parent d23c15476a
commit ddfffd3d31
@@ -90,28 +90,30 @@ public class WizardTradeTweaksHandler {
// New spell indicator // New spell indicator
if(gui.inventorySlots instanceof ContainerMerchant){ if(gui.inventorySlots instanceof ContainerMerchant){
// Can't use getCurrentRecipe because that only gets updated when the correct items are given if(tradeIndex < trades.size()){ // Seems to happen with certain mods' GUIs
MerchantRecipe recipe = trades.get(tradeIndex);
if(recipe != null && recipe.getItemToSell().getItem() instanceof ItemSpellBook){ // Can't use getCurrentRecipe because that only gets updated when the correct items are given
MerchantRecipe recipe = trades.get(tradeIndex);
EntityPlayer player = Minecraft.getMinecraft().player; if(recipe != null && recipe.getItemToSell().getItem() instanceof ItemSpellBook){
Spell spell = Spell.byMetadata(recipe.getItemToSell().getMetadata());
if(Wizardry.settings.discoveryMode && !player.isCreative() && Wizardry.proxy.shouldDisplayDiscovered(spell, recipe.getItemToSell()) EntityPlayer player = Minecraft.getMinecraft().player;
&& WizardData.get(player) != null && !WizardData.get(player).hasSpellBeenDiscovered(spell)){ Spell spell = Spell.byMetadata(recipe.getItemToSell().getMetadata());
int x = gui.inventorySlots.getSlot(2).xPos + 14;
int y = gui.inventorySlots.getSlot(2).yPos - 17;
RenderHelper.enableGUIStandardItemLighting(); if(Wizardry.settings.discoveryMode && !player.isCreative() && Wizardry.proxy.shouldDisplayDiscovered(spell, recipe.getItemToSell())
GlStateManager.color(1, 1, 1); && WizardData.get(player) != null && !WizardData.get(player).hasSpellBeenDiscovered(spell)){
Minecraft.getMinecraft().renderEngine.bindTexture(NEW_SPELL_ICON);
int frame = Math.max(player.ticksExisted/ANIMATION_FRAME_TIME % ANIMATION_PERIOD - (ANIMATION_PERIOD - ANIMATION_FRAMES), 0); int x = gui.inventorySlots.getSlot(2).xPos + 14;
DrawingUtils.drawTexturedRect(x, y, 0, frame * ICON_HEIGHT, ICON_WIDTH, ICON_HEIGHT, ICON_WIDTH, ICON_HEIGHT * ANIMATION_FRAMES); int y = gui.inventorySlots.getSlot(2).yPos - 17;
RenderHelper.disableStandardItemLighting(); RenderHelper.enableGUIStandardItemLighting();
GlStateManager.color(1, 1, 1);
Minecraft.getMinecraft().renderEngine.bindTexture(NEW_SPELL_ICON);
int frame = Math.max(player.ticksExisted / ANIMATION_FRAME_TIME % ANIMATION_PERIOD - (ANIMATION_PERIOD - ANIMATION_FRAMES), 0);
DrawingUtils.drawTexturedRect(x, y, 0, frame * ICON_HEIGHT, ICON_WIDTH, ICON_HEIGHT, ICON_WIDTH, ICON_HEIGHT * ANIMATION_FRAMES);
RenderHelper.disableStandardItemLighting();
// int mouseX = event.getMouseX() - gui.getGuiLeft(); // int mouseX = event.getMouseX() - gui.getGuiLeft();
// int mouseY = event.getMouseY() - gui.getGuiTop(); // int mouseY = event.getMouseY() - gui.getGuiTop();
@@ -120,6 +122,7 @@ public class WizardTradeTweaksHandler {
// GuiUtils.drawHoveringText(Collections.singletonList("You haven't discovered this spell yet"), mouseX, // GuiUtils.drawHoveringText(Collections.singletonList("You haven't discovered this spell yet"), mouseX,
// mouseY, gui.width, gui.height, 150, Minecraft.getMinecraft().fontRenderer); // mouseY, gui.width, gui.height, 150, Minecraft.getMinecraft().fontRenderer);
// } // }
}
} }
} }
} }