From f0a17025c78c5d39f83682d1ecc455ac5a8f28cf Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 23 Sep 2015 06:44:54 +0200 Subject: [PATCH] Fixed a bug with a concurrentModificationException sometimes spamming the console when looking at recipes in NEI Closes https://github.com/Ellpeck/ActuallyAdditions/issues/13 --- .../actuallyadditions/event/TooltipEvent.java | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/event/TooltipEvent.java b/src/main/java/ellpeck/actuallyadditions/event/TooltipEvent.java index 10b124322..504cb7ed0 100644 --- a/src/main/java/ellpeck/actuallyadditions/event/TooltipEvent.java +++ b/src/main/java/ellpeck/actuallyadditions/event/TooltipEvent.java @@ -48,40 +48,38 @@ public class TooltipEvent{ if(screen != null && !(screen instanceof GuiBooklet) && screen instanceof GuiContainer){ GuiContainer gui = (GuiContainer)screen; if(gui.inventorySlots != null && gui.inventorySlots.inventorySlots != null && !gui.inventorySlots.inventorySlots.isEmpty()){ - for(Object o : gui.inventorySlots.inventorySlots){ - if(o instanceof Slot){ - Slot slot = (Slot)o; + for(int i = 0; i < gui.inventorySlots.inventorySlots.size(); i++){ + Slot slot = gui.inventorySlots.getSlot(i); - int guiLeft = ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 4); - int guiTop = ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 5); - int mouseX = Mouse.getEventX()*gui.width/Minecraft.getMinecraft().displayWidth-guiLeft; - int mouseY = gui.height-Mouse.getEventY()*gui.height/Minecraft.getMinecraft().displayHeight-1-guiTop; + int guiLeft = ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 4); + int guiTop = ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 5); + int mouseX = Mouse.getEventX()*gui.width/Minecraft.getMinecraft().displayWidth-guiLeft; + int mouseY = gui.height-Mouse.getEventY()*gui.height/Minecraft.getMinecraft().displayHeight-1-guiTop; - if(mouseX >= slot.xDisplayPosition-1 && mouseY >= slot.yDisplayPosition-1 && mouseX <= slot.xDisplayPosition+16 && mouseY <= slot.yDisplayPosition+16){ - ItemStack stack = slot.getStack(); - if(stack != null){ - for(BookletPage page : InitBooklet.pagesWithItemStackData){ - if(page.getItemStackForPage() != null && page.getItemStackForPage().isItemEqual(stack)){ - int keyCode = KeyBinds.keybindOpenBooklet.getKeyCode(); - if(!ConfigBoolValues.NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled() || Minecraft.getMinecraft().thePlayer.inventory.hasItem(InitItems.itemLexicon)){ - if(ConfigBoolValues.SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled()){ - event.toolTip.add(EnumChatFormatting.GOLD+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".keyToSeeRecipe", keyCode > 0 && keyCode < Keyboard.KEYBOARD_SIZE ? "'"+Keyboard.getKeyName(keyCode)+"'" : "[NONE]")); - } - if(Keyboard.isKeyDown(KeyBinds.keybindOpenBooklet.getKeyCode())){ - GuiBooklet book = new GuiBooklet(); - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); - Minecraft.getMinecraft().displayGuiScreen(book); - book.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.BUTTONS_PER_PAGE+1, true); - book.openChapter(page.getChapter(), page); - } + if(mouseX >= slot.xDisplayPosition-1 && mouseY >= slot.yDisplayPosition-1 && mouseX <= slot.xDisplayPosition+16 && mouseY <= slot.yDisplayPosition+16){ + ItemStack stack = slot.getStack(); + if(stack != null){ + for(BookletPage page : InitBooklet.pagesWithItemStackData){ + if(page.getItemStackForPage() != null && page.getItemStackForPage().isItemEqual(stack)){ + int keyCode = KeyBinds.keybindOpenBooklet.getKeyCode(); + if(!ConfigBoolValues.NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled() || Minecraft.getMinecraft().thePlayer.inventory.hasItem(InitItems.itemLexicon)){ + if(ConfigBoolValues.SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled()){ + event.toolTip.add(EnumChatFormatting.GOLD+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".keyToSeeRecipe", keyCode > 0 && keyCode < Keyboard.KEYBOARD_SIZE ? "'"+Keyboard.getKeyName(keyCode)+"'" : "[NONE]")); } - else{ - if(ConfigBoolValues.SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled()){ - event.toolTip.addAll(Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(EnumChatFormatting.DARK_RED+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".noBookletInInventory"), GuiBooklet.TOOLTIP_SPLIT_LENGTH)); - } + if(Keyboard.isKeyDown(KeyBinds.keybindOpenBooklet.getKeyCode())){ + GuiBooklet book = new GuiBooklet(); + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); + Minecraft.getMinecraft().displayGuiScreen(book); + book.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.BUTTONS_PER_PAGE+1, true); + book.openChapter(page.getChapter(), page); } - break; } + else{ + if(ConfigBoolValues.SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled()){ + event.toolTip.addAll(Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(EnumChatFormatting.DARK_RED+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".noBookletInInventory"), GuiBooklet.TOOLTIP_SPLIT_LENGTH)); + } + } + break; } } }