From 5f2de3026ebffaa5140d96c0813ca7470fc80287 Mon Sep 17 00:00:00 2001 From: mezz Date: Fri, 13 Nov 2015 23:12:40 -0800 Subject: [PATCH] Clean up widgets and OpenGL gui lighting issues --- .../apiculture/gui/GuiHabitatLocator.java | 145 ++++---------- .../forestry/apiculture/gui/GuiImprinter.java | 6 +- .../apiculture/gui/widgets/HabitatSlot.java | 69 +++++++ .../apiculture/items/HabitatLocatorLogic.java | 5 +- .../apiculture/render/RenderBeeItem.java | 2 - .../java/forestry/core/gui/GuiAlyzer.java | 6 +- .../java/forestry/core/gui/GuiEscritoire.java | 7 +- .../java/forestry/core/gui/GuiForestry.java | 185 ++++-------------- .../forestry/core/gui/GuiForestryTitled.java | 1 + .../core/gui/GuiNaturalistInventory.java | 9 +- src/main/java/forestry/core/gui/GuiUtil.java | 148 ++++++++++++++ .../core/gui/buttons/GuiBetterButton.java | 2 +- .../forestry/core/gui/ledgers/Ledger.java | 3 - .../core/gui/ledgers/LedgerManager.java | 23 +-- .../forestry/core/gui/slots/SlotForestry.java | 4 +- .../core/gui/tooltips/IToolTipProvider.java | 2 +- .../core/gui/widgets/GameTokenWidget.java | 12 +- .../core/gui/widgets/ItemStackWidgetBase.java | 5 +- .../core/gui/widgets/ReservoirWidget.java | 53 +---- .../core/gui/widgets/SocketWidget.java | 2 +- .../forestry/core/gui/widgets/TankWidget.java | 71 ++++--- .../forestry/core/gui/widgets/Widget.java | 7 +- .../forestry/core/render/RenderCrateItem.java | 67 ++++--- .../core/tiles/EscritoireGameToken.java | 4 +- .../forestry/energy/gui/GuiEngineBiogas.java | 98 +--------- .../energy/gui/widgets/BiogasSlot.java | 44 +++++ .../energy/tiles/TileEngineBiogas.java | 113 +++++------ .../java/forestry/farming/gui/GuiFarm.java | 73 +------ .../farming/gui/widgets/FarmLogicSlot.java | 74 +++++++ .../java/forestry/mail/gui/GuiLetter.java | 41 +--- .../java/forestry/mail/gui/GuiTrader.java | 3 +- .../mail/gui/widgets/AddresseeSlot.java | 58 ++++++ 32 files changed, 642 insertions(+), 700 deletions(-) create mode 100644 src/main/java/forestry/apiculture/gui/widgets/HabitatSlot.java create mode 100644 src/main/java/forestry/core/gui/GuiUtil.java create mode 100644 src/main/java/forestry/energy/gui/widgets/BiogasSlot.java create mode 100644 src/main/java/forestry/farming/gui/widgets/FarmLogicSlot.java create mode 100644 src/main/java/forestry/mail/gui/widgets/AddresseeSlot.java diff --git a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java index bafb88f43..a92cd4585 100755 --- a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java @@ -10,15 +10,17 @@ ******************************************************************************/ package forestry.apiculture.gui; +import com.google.common.collect.LinkedListMultimap; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.EnumMap; import java.util.EnumSet; -import java.util.Locale; -import java.util.Map; +import java.util.List; import java.util.Set; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.IIcon; import net.minecraft.util.StatCollector; import net.minecraft.world.biome.BiomeGenBase; @@ -26,30 +28,30 @@ import net.minecraftforge.common.BiomeDictionary; import org.lwjgl.opengl.GL11; +import forestry.apiculture.gui.widgets.HabitatSlot; import forestry.apiculture.inventory.ItemInventoryHabitatLocator; import forestry.core.config.Constants; import forestry.core.gui.GuiForestry; -import forestry.core.gui.widgets.Widget; -import forestry.core.proxy.Proxies; -import forestry.core.render.SpriteSheet; -import forestry.core.render.TextureManager; public class GuiHabitatLocator extends GuiForestry { + private static final LinkedListMultimap habitats = LinkedListMultimap.create(); - private final HabitatSlot[] habitatSlots = new HabitatSlot[]{ - new HabitatSlot(0, "Ocean"), // ocean, beach - new HabitatSlot(1, "Plains"), - new HabitatSlot(2, "Desert"), // desert, desert hills - new HabitatSlot(3, "Forest"), // forest, forestHills, river - new HabitatSlot(4, "Jungle"), // jungle, jungleHills - new HabitatSlot(5, "Taiga"), // taiga, taigaHills - new HabitatSlot(6, "Hills"), // extremeHills, extremeHillsEdge - new HabitatSlot(7, "Swamp"), - new HabitatSlot(8, "Snow"), // Ice plains, mountains, frozen rivers, frozen oceans - new HabitatSlot(9, "Mushroom"), - new HabitatSlot(10, "Nether"), - new HabitatSlot(11, "End")}; - private final Map biomeToHabitat = new EnumMap<>(BiomeDictionary.Type.class); + static { + habitats.putAll("Ocean", Arrays.asList(BiomeDictionary.Type.OCEAN, BiomeDictionary.Type.BEACH)); + habitats.put("Plains", BiomeDictionary.Type.PLAINS); + habitats.put("Desert", BiomeDictionary.Type.SANDY); + habitats.putAll("Forest", Arrays.asList(BiomeDictionary.Type.FOREST, BiomeDictionary.Type.RIVER)); + habitats.put("Jungle", BiomeDictionary.Type.JUNGLE); + habitats.put("Taiga", BiomeDictionary.Type.CONIFEROUS); + habitats.put("Hills", BiomeDictionary.Type.MOUNTAIN); + habitats.put("Swamp", BiomeDictionary.Type.SWAMP); + habitats.put("Snow", BiomeDictionary.Type.SNOWY); + habitats.put("Mushroom", BiomeDictionary.Type.MUSHROOM); + habitats.put("Nether", BiomeDictionary.Type.NETHER); + habitats.put("End", BiomeDictionary.Type.END); + } + + private final List habitatSlots = new ArrayList<>(habitats.size()); private int startX; private int startY; @@ -60,36 +62,23 @@ public class GuiHabitatLocator extends GuiForestry 5) { - x = 18 + (slot.slot - 6) * 20; + int slot = 0; + for (String habitatName : habitats.keySet()) { + int x; + int y; + if (slot > 5) { + x = 18 + (slot - 6) * 20; y = 50; } else { - x = 18 + slot.slot * 20; + x = 18 + slot * 20; y = 32; } - - slot.setPosition(x, y); - this.widgetManager.add(slot); + Collection biomes = habitats.get(habitatName); + HabitatSlot habitatSlot = new HabitatSlot(widgetManager, x, y, habitatName, biomes); + habitatSlots.add(habitatSlot); + widgetManager.add(habitatSlot); + slot++; } - - biomeToHabitat.put(BiomeDictionary.Type.OCEAN, habitatSlots[0]); - biomeToHabitat.put(BiomeDictionary.Type.BEACH, habitatSlots[0]); - biomeToHabitat.put(BiomeDictionary.Type.PLAINS, habitatSlots[1]); - biomeToHabitat.put(BiomeDictionary.Type.SANDY, habitatSlots[2]); - biomeToHabitat.put(BiomeDictionary.Type.FOREST, habitatSlots[3]); - biomeToHabitat.put(BiomeDictionary.Type.RIVER, habitatSlots[3]); - biomeToHabitat.put(BiomeDictionary.Type.JUNGLE, habitatSlots[4]); - biomeToHabitat.put(BiomeDictionary.Type.CONIFEROUS, habitatSlots[5]); - biomeToHabitat.put(BiomeDictionary.Type.MOUNTAIN, habitatSlots[6]); - biomeToHabitat.put(BiomeDictionary.Type.SWAMP, habitatSlots[7]); - biomeToHabitat.put(BiomeDictionary.Type.SNOWY, habitatSlots[8]); - biomeToHabitat.put(BiomeDictionary.Type.MUSHROOM, habitatSlots[9]); - biomeToHabitat.put(BiomeDictionary.Type.NETHER, habitatSlots[10]); - biomeToHabitat.put(BiomeDictionary.Type.END, habitatSlots[11]); } @Override @@ -101,27 +90,18 @@ public class GuiHabitatLocator extends GuiForestry activeBiomeTypes = EnumSet.noneOf(BiomeDictionary.Type.class); - - for (HabitatSlot habitatSlot : habitatSlots) { - habitatSlot.isActive = false; - } - for (BiomeGenBase biome : inventory.getBiomesToSearch()) { Collections.addAll(activeBiomeTypes, BiomeDictionary.getTypesForBiome(biome)); } - for (BiomeDictionary.Type biomeType : activeBiomeTypes) { - HabitatSlot habitatSlot = biomeToHabitat.get(biomeType); - if (habitatSlot != null) { - habitatSlot.isActive = true; - } + for (HabitatSlot habitatSlot : habitatSlots) { + habitatSlot.setActive(activeBiomeTypes); } for (HabitatSlot slot : habitatSlots) { slot.draw(startX, startY); } GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Reset afterwards. - } @Override @@ -131,53 +111,4 @@ public class GuiHabitatLocator extends GuiForestry biomes; + private final String name; + private final String iconIndex; + public boolean isActive = false; + + public HabitatSlot(WidgetManager widgetManager, int xPos, int yPos, String name, Collection biomes) { + super(widgetManager, xPos, yPos); + this.biomes = biomes; + this.name = name; + this.iconIndex = "habitats/" + name.toLowerCase(Locale.ENGLISH); + } + + @Override + public String getLegacyTooltip(EntityPlayer player) { + return name; + } + + public IIcon getIcon() { + return TextureManager.getInstance().getDefault(iconIndex); + } + + public void setActive(Collection biomes) { + isActive = !Collections.disjoint(this.biomes, biomes); + } + + @Override + public void draw(int startX, int startY) { + if (getIcon() != null) { + if (!isActive) { + GL11.glColor4f(0.2f, 0.2f, 0.2f, 0.2f); + } else { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } + + Proxies.render.bindTexture(SpriteSheet.ITEMS); + manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos, getIcon(), 16, 16); + } + } +} diff --git a/src/main/java/forestry/apiculture/items/HabitatLocatorLogic.java b/src/main/java/forestry/apiculture/items/HabitatLocatorLogic.java index 7787d1e85..b3ceef262 100644 --- a/src/main/java/forestry/apiculture/items/HabitatLocatorLogic.java +++ b/src/main/java/forestry/apiculture/items/HabitatLocatorLogic.java @@ -33,6 +33,7 @@ public class HabitatLocatorLogic { private static final int maxChecksPerTick = 100; private static final int maxSearchRadiusIterations = 500; private static final int spacing = 20; + private static final int minBiomeRadius = 8; private static final Set waterBiomes = new HashSet<>(); private static final Set netherBiomes = new HashSet<>(); @@ -151,10 +152,6 @@ public class HabitatLocatorLogic { } private static ChunkCoordinates getChunkCoordinates(Vect pos, World world, Collection biomesToSearch) { - - // to avoid reporting very tiny patches, check around the point want - final int minBiomeRadius = 8; - BiomeGenBase biome; biome = world.getBiomeGenForCoords(pos.x, pos.z); diff --git a/src/main/java/forestry/apiculture/render/RenderBeeItem.java b/src/main/java/forestry/apiculture/render/RenderBeeItem.java index 989e51f82..235e09bfb 100644 --- a/src/main/java/forestry/apiculture/render/RenderBeeItem.java +++ b/src/main/java/forestry/apiculture/render/RenderBeeItem.java @@ -107,7 +107,6 @@ public class RenderBeeItem implements IItemRenderer { float pitch = 1; GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_COLOR_MATERIAL); @@ -152,7 +151,6 @@ public class RenderBeeItem implements IItemRenderer { */ GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_COLOR_MATERIAL); RenderHelper.enableStandardItemLighting(); diff --git a/src/main/java/forestry/core/gui/GuiAlyzer.java b/src/main/java/forestry/core/gui/GuiAlyzer.java index 48d5abb52..fa102ff26 100755 --- a/src/main/java/forestry/core/gui/GuiAlyzer.java +++ b/src/main/java/forestry/core/gui/GuiAlyzer.java @@ -113,10 +113,8 @@ public abstract class GuiAlyzer extends GuiForestry textLayout.drawLine(text0, textLayout.column0); int columnwidth = textLayout.column2 - textLayout.column1 - 2; - RenderHelper.enableStandardItemLighting(); - drawItemStack(iconStacks.get(primary.getUID()), guiLeft + textLayout.column1 + (columnwidth - 20), guiTop + 10); - drawItemStack(iconStacks.get(secondary.getUID()), guiLeft + textLayout.column2 + (columnwidth - 20), guiTop + 10); - RenderHelper.disableStandardItemLighting(); + GuiUtil.drawItemStack(this, iconStacks.get(primary.getUID()), guiLeft + textLayout.column1 + (columnwidth - 20), guiTop + 10); + GuiUtil.drawItemStack(this, iconStacks.get(secondary.getUID()), guiLeft + textLayout.column2 + (columnwidth - 20), guiTop + 10); String primaryName = customPrimaryName == null ? primary.getName() : customPrimaryName; String secondaryName = customSecondaryName == null ? secondary.getName() : customSecondaryName; diff --git a/src/main/java/forestry/core/gui/GuiEscritoire.java b/src/main/java/forestry/core/gui/GuiEscritoire.java index 8e9ea4a64..f788a337e 100755 --- a/src/main/java/forestry/core/gui/GuiEscritoire.java +++ b/src/main/java/forestry/core/gui/GuiEscritoire.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.core.gui; -import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -82,13 +81,10 @@ public class GuiEscritoire extends GuiForestry ext return fontColor; } + public FontRenderer getFontRenderer() { + return fontRendererObj; + } + @Override protected void mouseClicked(int xPos, int yPos, int mouseButton) { super.mouseClicked(xPos, yPos, mouseButton); @@ -179,146 +177,55 @@ public abstract class GuiForestry ext return this.func_146978_c(par1Slot.xDisplayPosition, par1Slot.yDisplayPosition, 16, 16, par2, par3); } - private void drawToolTips(ToolTip toolTips, int mouseX, int mouseY) { - if (toolTips == null) { - return; - } - if (toolTips.isEmpty()) { - return; - } - - int left = this.guiLeft; - int top = this.guiTop; - int length = 0; - int height = 0; - int x; - int y; - - for (ToolTipLine tip : toolTips) { - y = this.fontRendererObj.getStringWidth(tip.toString()); - - height += 10 + tip.getSpacing(); - if (y > length) { - length = y; - } - } - - x = mouseX - left + 12; - y = mouseY - top - 12; - - this.zLevel = 300.0F; - itemRender.zLevel = 300.0F; - Color backgroundColor = new Color(16, 0, 16, 240); - int backgroundColorInt = backgroundColor.getRGB(); - this.drawGradientRect(x - 3, y - 4, x + length + 2, y - 3, backgroundColorInt, backgroundColorInt); - this.drawGradientRect(x - 3, y + height + 1, x + length + 2, y + height + 2, backgroundColorInt, backgroundColorInt); - this.drawGradientRect(x - 3, y - 3, x + length + 2, y + height + 1, backgroundColorInt, backgroundColorInt); - this.drawGradientRect(x - 4, y - 3, x - 3, y + height + 1, backgroundColorInt, backgroundColorInt); - this.drawGradientRect(x + length + 2, y - 3, x + length + 3, y + height + 1, backgroundColorInt, backgroundColorInt); - - Color borderColorTop = new Color(80, 0, 255, 80); - int borderColorTopInt = borderColorTop.getRGB(); - Color borderColorBottom = new Color((borderColorTopInt & 0xfefefe) >> 1 | borderColorTopInt & -0x1000000, true); - int borderColorBottomInt = borderColorBottom.getRGB(); - this.drawGradientRect(x - 3, y - 3 + 1, x - 3 + 1, y + height, borderColorTopInt, borderColorBottomInt); - this.drawGradientRect(x + length + 1, y - 3 + 1, x + length + 2, y + height, borderColorTopInt, borderColorBottomInt); - this.drawGradientRect(x - 3, y - 3, x + length + 2, y - 3 + 1, borderColorTopInt, borderColorTopInt); - this.drawGradientRect(x - 3, y + height, x + length + 2, y + height + 1, borderColorBottomInt, borderColorBottomInt); - - boolean firstLine = true; - for (ToolTipLine tip : toolTips) { - String line = tip.toString(); - - if (!firstLine) { - line = EnumChatFormatting.GRAY + line; - } - - this.fontRendererObj.drawStringWithShadow(line, x, y, -1); - - y += 10 + tip.getSpacing(); - - firstLine = false; - } - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - } - @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - RenderHelper.enableGUIStandardItemLighting(); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - GL11.glPushMatrix(); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + { + RenderHelper.enableGUIStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + ledgerManager.drawTooltips(mouseX, mouseY); - ledgerManager.drawTooltips(mouseX, mouseY); + InventoryPlayer playerInv = mc.thePlayer.inventory; - InventoryPlayer playerInv = mc.thePlayer.inventory; - - if (playerInv.getItemStack() == null) { - drawToolTips(widgetManager.getWidgets(), mouseX, mouseY); - drawToolTips(buttonList, mouseX, mouseY); - drawToolTips(inventorySlots.inventorySlots, mouseX, mouseY); + if (playerInv.getItemStack() == null) { + GuiUtil.drawToolTips(this, widgetManager.getWidgets(), mouseX, mouseY); + GuiUtil.drawToolTips(this, buttonList, mouseX, mouseY); + GuiUtil.drawToolTips(this, inventorySlots.inventorySlots, mouseX, mouseY); + } } - - GL11.glPopMatrix(); GL11.glPopAttrib(); } - private void drawToolTips(Collection objects, int mouseX, int mouseY) { - for (Object obj : objects) { - if (!(obj instanceof IToolTipProvider)) { - continue; - } - IToolTipProvider provider = (IToolTipProvider) obj; - if (!provider.isToolTipVisible()) { - continue; - } - ToolTip tips = provider.getToolTip(); - if (tips == null) { - continue; - } - boolean mouseOver = provider.isMouseOver(mouseX - guiLeft, mouseY - guiTop); - tips.onTick(mouseOver); - if (mouseOver && tips.isReady()) { - tips.refresh(); - drawToolTips(tips, mouseX, mouseY); - } - } - } - @Override protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); bindTexture(textureFile); + int x = (width - xSize) / 2; int y = (height - ySize) / 2; drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - int left = this.guiLeft; - int top = this.guiTop; - GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - RenderHelper.enableGUIStandardItemLighting(); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - GL11.glPushMatrix(); - GL11.glTranslatef(left, top, 0.0F); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + { + RenderHelper.enableGUIStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glPushMatrix(); + { + GL11.glTranslatef(guiLeft, guiTop, 0.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - drawWidgets(); - - GL11.glPopMatrix(); + drawWidgets(); + } + GL11.glPopMatrix(); + } GL11.glPopAttrib(); bindTexture(textureFile); @@ -363,32 +270,6 @@ public abstract class GuiForestry ext super.drawGradientRect(par1, par2, par3, par4, par5, par6); } - public void drawItemStack(ItemStack stack, int xPos, int yPos) { - GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - RenderHelper.enableGUIStandardItemLighting(); - - GL11.glTranslatef(0.0F, 0.0F, 32.0F); - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - FontRenderer font = null; - if (stack != null) { - font = stack.getItem().getFontRenderer(stack); - } - if (font == null) { - font = fontRendererObj; - } - itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), stack, xPos, yPos); - itemRender.renderItemOverlayIntoGUI(font, this.mc.getTextureManager(), stack, xPos, yPos); - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - - RenderHelper.disableStandardItemLighting(); - GL11.glPopAttrib(); - } - /* NEI */ @Override @Optional.Method(modid = "NotEnoughItems") diff --git a/src/main/java/forestry/core/gui/GuiForestryTitled.java b/src/main/java/forestry/core/gui/GuiForestryTitled.java index 7535e4270..06349473e 100644 --- a/src/main/java/forestry/core/gui/GuiForestryTitled.java +++ b/src/main/java/forestry/core/gui/GuiForestryTitled.java @@ -29,5 +29,6 @@ public abstract class GuiForestryTitled length) { + length = y; + } + } + + x = mouseX - left + 12; + y = mouseY - top - 12; + + gui.setZLevel(300.0F); + itemRender.zLevel = 300.0F; + Color backgroundColor = new Color(16, 0, 16, 240); + int backgroundColorInt = backgroundColor.getRGB(); + gui.drawGradientRect(x - 3, y - 4, x + length + 2, y - 3, backgroundColorInt, backgroundColorInt); + gui.drawGradientRect(x - 3, y + height + 1, x + length + 2, y + height + 2, backgroundColorInt, backgroundColorInt); + gui.drawGradientRect(x - 3, y - 3, x + length + 2, y + height + 1, backgroundColorInt, backgroundColorInt); + gui.drawGradientRect(x - 4, y - 3, x - 3, y + height + 1, backgroundColorInt, backgroundColorInt); + gui.drawGradientRect(x + length + 2, y - 3, x + length + 3, y + height + 1, backgroundColorInt, backgroundColorInt); + + Color borderColorTop = new Color(80, 0, 255, 80); + int borderColorTopInt = borderColorTop.getRGB(); + Color borderColorBottom = new Color((borderColorTopInt & 0xfefefe) >> 1 | borderColorTopInt & -0x1000000, true); + int borderColorBottomInt = borderColorBottom.getRGB(); + gui.drawGradientRect(x - 3, y - 3 + 1, x - 3 + 1, y + height, borderColorTopInt, borderColorBottomInt); + gui.drawGradientRect(x + length + 1, y - 3 + 1, x + length + 2, y + height, borderColorTopInt, borderColorBottomInt); + gui.drawGradientRect(x - 3, y - 3, x + length + 2, y - 3 + 1, borderColorTopInt, borderColorTopInt); + gui.drawGradientRect(x - 3, y + height, x + length + 2, y + height + 1, borderColorBottomInt, borderColorBottomInt); + + boolean firstLine = true; + for (ToolTipLine tip : toolTips) { + String line; + + if (firstLine) { + line = tip.toString(); + } else { + line = EnumChatFormatting.GRAY + tip.toString(); + } + + fontRendererObj.drawStringWithShadow(line, x, y, -1); + + y += 10 + tip.getSpacing(); + + firstLine = false; + } + + gui.setZLevel(0.0F); + itemRender.zLevel = 0.0F; + } + + public static void drawToolTips(GuiForestry gui, Collection objects, int mouseX, int mouseY) { + for (Object obj : objects) { + if (!(obj instanceof IToolTipProvider)) { + continue; + } + IToolTipProvider provider = (IToolTipProvider) obj; + if (!provider.isToolTipVisible()) { + continue; + } + ToolTip tips = provider.getToolTip(mouseX - gui.getGuiLeft(), mouseY - gui.getGuiTop()); + if (tips == null) { + continue; + } + boolean mouseOver = provider.isMouseOver(mouseX - gui.getGuiLeft(), mouseY - gui.getGuiTop()); + tips.onTick(mouseOver); + if (mouseOver && tips.isReady()) { + tips.refresh(); + drawToolTips(gui, tips, mouseX, mouseY); + } + } + } +} diff --git a/src/main/java/forestry/core/gui/buttons/GuiBetterButton.java b/src/main/java/forestry/core/gui/buttons/GuiBetterButton.java index 1fe1d26d2..10e401a1f 100755 --- a/src/main/java/forestry/core/gui/buttons/GuiBetterButton.java +++ b/src/main/java/forestry/core/gui/buttons/GuiBetterButton.java @@ -112,7 +112,7 @@ public class GuiBetterButton extends GuiButton implements IToolTipProvider { } @Override - public ToolTip getToolTip() { + public ToolTip getToolTip(int mouseX, int mouseY) { return toolTip; } diff --git a/src/main/java/forestry/core/gui/ledgers/Ledger.java b/src/main/java/forestry/core/gui/ledgers/Ledger.java index aba8abcd0..e645881db 100644 --- a/src/main/java/forestry/core/gui/ledgers/Ledger.java +++ b/src/main/java/forestry/core/gui/ledgers/Ledger.java @@ -197,13 +197,10 @@ public abstract class Ledger { } protected void drawIcon(IIcon icon, int x, int y) { - if (icon != null) { - GL11.glDisable(GL11.GL_LIGHTING); GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); Proxies.render.bindTexture(SpriteSheet.ITEMS); manager.gui.drawTexturedModelRectFromIcon(x, y, icon, 16, 16); - GL11.glEnable(GL11.GL_LIGHTING); } } diff --git a/src/main/java/forestry/core/gui/ledgers/LedgerManager.java b/src/main/java/forestry/core/gui/ledgers/LedgerManager.java index 6867824b9..e1f5079b1 100644 --- a/src/main/java/forestry/core/gui/ledgers/LedgerManager.java +++ b/src/main/java/forestry/core/gui/ledgers/LedgerManager.java @@ -10,13 +10,9 @@ ******************************************************************************/ package forestry.core.gui.ledgers; -import com.google.common.collect.ImmutableSet; - import java.util.ArrayList; import java.util.List; -import net.minecraft.client.Minecraft; - import org.lwjgl.opengl.GL11; import forestry.api.core.IErrorSource; @@ -24,10 +20,10 @@ import forestry.api.core.IErrorState; import forestry.core.config.SessionVars; import forestry.core.errors.FakeErrorSource; import forestry.core.gui.GuiForestry; -import forestry.core.proxy.Proxies; +import forestry.core.gui.GuiUtil; +import forestry.core.gui.tooltips.ToolTip; public class LedgerManager { - private final List ledgers = new ArrayList<>(); private final List errorLedgers = new ArrayList<>(); @@ -75,7 +71,6 @@ public class LedgerManager { } private Ledger getAtPosition(int mX, int mY) { - if (ledgers.size() > 0) { final int xShift = ((gui.width - gui.getSizeX()) / 2) + gui.getSizeX(); int yShift = ((gui.height - gui.getSizeY()) / 2) + 8; @@ -116,7 +111,6 @@ public class LedgerManager { } public void drawLedgers() { - int yPos = 8; for (Ledger ledger : ledgers) { @@ -154,19 +148,12 @@ public class LedgerManager { } public void drawTooltips(int mouseX, int mouseY) { - Ledger ledger = getAtPosition(mouseX, mouseY); if (ledger != null) { - int startX = mouseX - ((gui.width - gui.getSizeX()) / 2) + 12; - int startY = mouseY - ((gui.height - gui.getSizeY()) / 2) - 12; - - String tooltip = ledger.getTooltip(); - Minecraft minecraft = Proxies.common.getClientInstance(); - int textWidth = minecraft.fontRenderer.getStringWidth(tooltip); - gui.drawGradientRect(startX - 3, startY - 3, startX + textWidth + 3, startY + 8 + 3, 0xc0000000, 0xc0000000); - minecraft.fontRenderer.drawStringWithShadow(tooltip, startX, startY, -1); + ToolTip toolTip = new ToolTip(); + toolTip.add(ledger.getTooltip()); + GuiUtil.drawToolTips(gui, toolTip, mouseX, mouseY); } - } public void handleMouseClicked(int x, int y, int mouseButton) { diff --git a/src/main/java/forestry/core/gui/slots/SlotForestry.java b/src/main/java/forestry/core/gui/slots/SlotForestry.java index efd0dd5ec..c2b21cf06 100755 --- a/src/main/java/forestry/core/gui/slots/SlotForestry.java +++ b/src/main/java/forestry/core/gui/slots/SlotForestry.java @@ -96,9 +96,11 @@ public class SlotForestry extends Slot implements IToolTipProvider { /** * @return the toolTips + * @param mouseX + * @param mouseY */ @Override - public ToolTip getToolTip() { + public ToolTip getToolTip(int mouseX, int mouseY) { return toolTips; } diff --git a/src/main/java/forestry/core/gui/tooltips/IToolTipProvider.java b/src/main/java/forestry/core/gui/tooltips/IToolTipProvider.java index f4d02d456..186632a46 100755 --- a/src/main/java/forestry/core/gui/tooltips/IToolTipProvider.java +++ b/src/main/java/forestry/core/gui/tooltips/IToolTipProvider.java @@ -15,7 +15,7 @@ package forestry.core.gui.tooltips; */ public interface IToolTipProvider { - ToolTip getToolTip(); + ToolTip getToolTip(int mouseX, int mouseY); boolean isToolTipVisible(); diff --git a/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java b/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java index dd9d67dad..004246fa4 100644 --- a/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java +++ b/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java @@ -14,9 +14,11 @@ import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; import org.lwjgl.opengl.GL11; +import forestry.core.gui.GuiUtil; import forestry.core.network.PacketGuiSelectRequest; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; @@ -65,18 +67,14 @@ public class GameTokenWidget extends Widget { tokenStack = token.getTokenStack(); } - GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glEnable(GL11.GL_DEPTH_TEST); - RenderHelper.enableGUIStandardItemLighting(); - manager.gui.drawItemStack(tokenStack, startX + xPos + 3, startY + yPos + 3); - RenderHelper.disableStandardItemLighting(); - GL11.glPopAttrib(); + GuiUtil.drawItemStack(manager.gui, tokenStack, startX + xPos + 3, startY + yPos + 3); manager.gui.setZLevel(150f); for (String ident : getToken().getOverlayIcons()) { RenderHelper.enableGUIStandardItemLighting(); Proxies.render.bindTexture(SpriteSheet.ITEMS); - manager.gui.drawTexturedModelRectFromIcon(startX + xPos + 3, startY + yPos + 3, TextureManager.getInstance().getDefault(ident), 16, 16); + IIcon icon = TextureManager.getInstance().getDefault(ident); + manager.gui.drawTexturedModelRectFromIcon(startX + xPos + 3, startY + yPos + 3, icon, 16, 16); RenderHelper.disableStandardItemLighting(); } manager.gui.setZLevel(0f); diff --git a/src/main/java/forestry/core/gui/widgets/ItemStackWidgetBase.java b/src/main/java/forestry/core/gui/widgets/ItemStackWidgetBase.java index d412ff5d6..697702e55 100644 --- a/src/main/java/forestry/core/gui/widgets/ItemStackWidgetBase.java +++ b/src/main/java/forestry/core/gui/widgets/ItemStackWidgetBase.java @@ -13,6 +13,7 @@ package forestry.core.gui.widgets; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import forestry.core.gui.GuiUtil; import forestry.core.gui.tooltips.ToolTip; import forestry.core.proxy.Proxies; @@ -27,12 +28,12 @@ public abstract class ItemStackWidgetBase extends Widget { public void draw(int startX, int startY) { ItemStack itemStack = getItemStack(); if (itemStack != null) { - manager.gui.drawItemStack(itemStack, xPos + startX, yPos + startY); + GuiUtil.drawItemStack(manager.gui, itemStack, xPos + startX, yPos + startY); } } @Override - public ToolTip getToolTip() { + public ToolTip getToolTip(int mouseX, int mouseY) { EntityPlayer player = Proxies.common.getPlayer(); ItemStack itemStack = getItemStack(); ToolTip tip = new ToolTip(); diff --git a/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java b/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java index 7f04b99da..21488e68d 100755 --- a/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java +++ b/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java @@ -10,61 +10,10 @@ ******************************************************************************/ package forestry.core.gui.widgets; -import net.minecraft.util.IIcon; - -import net.minecraftforge.fluids.FluidStack; - -import org.lwjgl.opengl.GL11; - -import forestry.core.proxy.Proxies; -import forestry.core.render.SpriteSheet; - public class ReservoirWidget extends TankWidget { - public ReservoirWidget(WidgetManager manager, int xPos, int yPos, int slot) { super(manager, xPos, yPos, slot); this.height = 16; - } - - @Override - public void draw(int startX, int startY) { - - FluidStack contents = getTank().getFluid(); - if (contents == null || contents.amount <= 0 || contents.getFluid() == null) { - return; - } - IIcon liquidIcon = contents.getFluid().getIcon(contents); - if (liquidIcon == null) { - return; - } - - int squaled = (contents.amount * height) / getTank().getCapacity(); - if (squaled > height) { - squaled = height; - } - - Proxies.render.bindTexture(SpriteSheet.BLOCKS); - int start = 0; - - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); - while (true) { - int x; - - if (squaled > 16) { - x = 16; - squaled -= 16; - } else { - x = squaled; - squaled = 0; - } - - manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos + height - x - start, liquidIcon, 16, 16 - (16 - x)); - start = start + 16; - - if (x == 0 || squaled == 0) { - break; - } - } - + this.drawOverlay = false; } } diff --git a/src/main/java/forestry/core/gui/widgets/SocketWidget.java b/src/main/java/forestry/core/gui/widgets/SocketWidget.java index 221654172..dede50d54 100755 --- a/src/main/java/forestry/core/gui/widgets/SocketWidget.java +++ b/src/main/java/forestry/core/gui/widgets/SocketWidget.java @@ -45,7 +45,7 @@ public class SocketWidget extends Widget { } @Override - public ToolTip getToolTip() { + public ToolTip getToolTip(int mouseX, int mouseY) { return toolTip; } diff --git a/src/main/java/forestry/core/gui/widgets/TankWidget.java b/src/main/java/forestry/core/gui/widgets/TankWidget.java index 3a11ed491..c45a39fad 100755 --- a/src/main/java/forestry/core/gui/widgets/TankWidget.java +++ b/src/main/java/forestry/core/gui/widgets/TankWidget.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.gui.widgets; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -36,6 +37,7 @@ public class TankWidget extends Widget { private int overlayTexX = 176; private int overlayTexY = 0; private int slot = 0; + protected boolean drawOverlay = true; public TankWidget(WidgetManager manager, int xPos, int yPos, int slot) { super(manager, xPos, yPos); @@ -62,7 +64,7 @@ public class TankWidget extends Widget { @Override public void draw(int startX, int startY) { IFluidTank tank = getTank(); - if (tank == null) { + if (tank == null || tank.getCapacity() <= 0) { return; } @@ -70,44 +72,49 @@ public class TankWidget extends Widget { if (contents == null || contents.amount <= 0 || contents.getFluid() == null) { return; } + IIcon liquidIcon = contents.getFluid().getIcon(contents); if (liquidIcon == null) { return; } - int squaled = (contents.amount * height) / getTank().getCapacity(); - Proxies.render.bindTexture(SpriteSheet.BLOCKS); - int start = 0; - - GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); - while (true) { - int x; - - if (squaled > 16) { - x = 16; - squaled -= 16; - } else { - x = squaled; - squaled = 0; - } - - manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos + height - x - start, liquidIcon, 16, 16 - (16 - x)); - start = start + 16; - - if (x == 0 || squaled == 0) { - break; - } + int scaledLiquid = (contents.amount * height) / tank.getCapacity(); + if (scaledLiquid > height) { + scaledLiquid = height; } - Proxies.render.bindTexture(manager.gui.textureFile); - manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, overlayTexX, overlayTexY, 16, 60); + Proxies.render.bindTexture(SpriteSheet.BLOCKS); + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); + { + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); + + int start = 0; + while (scaledLiquid > 0) { + int x; + + if (scaledLiquid > 16) { + x = 16; + scaledLiquid -= 16; + } else { + x = scaledLiquid; + scaledLiquid = 0; + } + + manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos + height - x - start, liquidIcon, 16, x); + start += 16; + } + + if (drawOverlay) { + Proxies.render.bindTexture(manager.gui.textureFile); + manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, overlayTexX, overlayTexY, 16, 60); + } + } GL11.glPopAttrib(); } @Override - public ToolTip getToolTip() { + public ToolTip getToolTip(int mouseX, int mouseY) { IFluidTank tank = getTank(); if (!(tank instanceof StandardTank)) { return null; @@ -117,14 +124,16 @@ public class TankWidget extends Widget { @Override public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { - ItemStack itemstack = manager.minecraft.thePlayer.inventory.getItemStack(); + EntityPlayer player = manager.minecraft.thePlayer; + ItemStack itemstack = player.inventory.getItemStack(); if (itemstack == null) { return; } Item held = itemstack.getItem(); - if (held instanceof IToolPipette && manager.gui.inventorySlots instanceof IContainerLiquidTanks) { - ((IContainerLiquidTanks) manager.gui.inventorySlots).handlePipetteClickClient(slot, manager.minecraft.thePlayer); + Container container = manager.gui.inventorySlots; + if (held instanceof IToolPipette && container instanceof IContainerLiquidTanks) { + ((IContainerLiquidTanks) container).handlePipetteClickClient(slot, player); } } } diff --git a/src/main/java/forestry/core/gui/widgets/Widget.java b/src/main/java/forestry/core/gui/widgets/Widget.java index 909c82283..635ad2b39 100755 --- a/src/main/java/forestry/core/gui/widgets/Widget.java +++ b/src/main/java/forestry/core/gui/widgets/Widget.java @@ -20,10 +20,9 @@ import forestry.core.proxy.Proxies; * Basic non-ItemStack slot */ public abstract class Widget implements IToolTipProvider { - protected final WidgetManager manager; - protected int xPos; - protected int yPos; + protected final int xPos; + protected final int yPos; protected int width = 16; protected int height = 16; @@ -44,7 +43,7 @@ public abstract class Widget implements IToolTipProvider { public abstract void draw(int startX, int startY); @Override - public ToolTip getToolTip() { + public ToolTip getToolTip(int mouseX, int mouseY) { String line = getLegacyTooltip(Proxies.common.getClientInstance().thePlayer); if (line != null && !line.isEmpty()) { ToolTip tip = new ToolTip(); diff --git a/src/main/java/forestry/core/render/RenderCrateItem.java b/src/main/java/forestry/core/render/RenderCrateItem.java index 1f77c47d9..617cd89c2 100644 --- a/src/main/java/forestry/core/render/RenderCrateItem.java +++ b/src/main/java/forestry/core/render/RenderCrateItem.java @@ -169,7 +169,6 @@ public class RenderCrateItem implements IItemRenderer { } private void renderIn3D(ItemStack stack) { - GL11.glPushMatrix(); Tessellator tessellator = Tessellator.instance; if (RenderManager.instance.renderEngine == null) { return; @@ -205,37 +204,45 @@ public class RenderCrateItem implements IItemRenderer { ItemRenderer.renderItemIn2D(tessellator, maxU, minV, minU, maxV, icon.getIconWidth(), icon.getIconHeight(), PIXEL); if (stack.hasEffect(pass)) { - GL11.glDepthFunc(GL11.GL_EQUAL); - GL11.glDisable(GL11.GL_LIGHTING); - RenderManager.instance.renderEngine.bindTexture(GLINT_TEXTURE); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); - float f13 = 0.76F; - GL11.glColor4f(0.5F * f13, 0.25F * f13, 0.8F * f13, 1.0F); - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glPushMatrix(); - float f14 = 0.125F; - GL11.glScalef(f14, f14, f14); - float f15 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; - GL11.glTranslatef(f15, 0.0F, 0.0F); - GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); - ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, PIXEL); - GL11.glPopMatrix(); - GL11.glPushMatrix(); - GL11.glScalef(f14, f14, f14); - f15 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; - GL11.glTranslatef(-f15, 0.0F, 0.0F); - GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); - ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, PIXEL); - GL11.glPopMatrix(); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - GL11.glDisable(GL11.GL_BLEND); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glDepthFunc(GL11.GL_LEQUAL); + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); + { + GL11.glDepthFunc(GL11.GL_EQUAL); + GL11.glDisable(GL11.GL_LIGHTING); + RenderManager.instance.renderEngine.bindTexture(GLINT_TEXTURE); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + + float f13 = 0.76F; + float f14 = 0.125F; + float f15 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; + GL11.glColor4f(0.5F * f13, 0.25F * f13, 0.8F * f13, 1.0F); + + GL11.glMatrixMode(GL11.GL_TEXTURE); + + GL11.glPushMatrix(); + { + GL11.glScalef(f14, f14, f14); + GL11.glTranslatef(f15, 0.0F, 0.0F); + GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, PIXEL); + } + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + { + GL11.glScalef(f14, f14, f14); + f15 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; + GL11.glTranslatef(-f15, 0.0F, 0.0F); + GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, PIXEL); + } + GL11.glPopMatrix(); + + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } + GL11.glPopAttrib(); } } - - GL11.glPopMatrix(); } private void renderAsEntityFlat(ItemStack stack) { diff --git a/src/main/java/forestry/core/tiles/EscritoireGameToken.java b/src/main/java/forestry/core/tiles/EscritoireGameToken.java index c794d5d99..4aac42827 100644 --- a/src/main/java/forestry/core/tiles/EscritoireGameToken.java +++ b/src/main/java/forestry/core/tiles/EscritoireGameToken.java @@ -17,6 +17,7 @@ import net.minecraft.nbt.NBTTagCompound; import forestry.api.core.INBTTagable; import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IIndividual; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; @@ -99,7 +100,8 @@ public class EscritoireGameToken implements INBTTagable, IStreamable { return 0xffffff; } - int iconColor = AlleleManager.alleleRegistry.getIndividual(tokenStack).getGenome().getPrimary().getIconColour(0); + IIndividual individual = AlleleManager.alleleRegistry.getIndividual(tokenStack); + int iconColor = individual.getGenome().getPrimary().getIconColour(0); if (state == State.MATCHED) { return ColourUtil.multiplyRGBComponents(iconColor, 0.7f); diff --git a/src/main/java/forestry/energy/gui/GuiEngineBiogas.java b/src/main/java/forestry/energy/gui/GuiEngineBiogas.java index 7c5505758..fe7c795f7 100644 --- a/src/main/java/forestry/energy/gui/GuiEngineBiogas.java +++ b/src/main/java/forestry/energy/gui/GuiEngineBiogas.java @@ -10,112 +10,32 @@ ******************************************************************************/ package forestry.energy.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.IIcon; - -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; - -import org.lwjgl.opengl.GL11; import forestry.core.config.Constants; import forestry.core.gui.widgets.TankWidget; -import forestry.core.gui.widgets.Widget; -import forestry.core.gui.widgets.WidgetManager; -import forestry.core.proxy.Proxies; -import forestry.core.render.SpriteSheet; -import forestry.core.utils.StringUtil; +import forestry.energy.gui.widgets.BiogasSlot; import forestry.energy.tiles.TileEngineBiogas; public class GuiEngineBiogas extends GuiEngine { - - protected class BiogasSlot extends Widget { - - public BiogasSlot(WidgetManager manager, int xPos, int yPos) { - super(manager, xPos, yPos); - this.height = 16; - } - - @Override - public void draw(int startX, int startY) { - - if (inventory == null || inventory.getTotalTime() <= 0) { - return; - } - - Fluid fluid = FluidRegistry.getFluid(inventory.getCurrentFluidId()); - if (fluid == null) { - return; - } - IIcon liquidIcon = fluid.getIcon(); - if (liquidIcon == null) { - return; - } - - int squaled = (inventory.getBurnTime() * height) / inventory.getTotalTime(); - if (squaled > height) { - squaled = height; - } - - Proxies.render.bindTexture(SpriteSheet.BLOCKS); - int start = 0; - - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); - while (true) { - int x; - - if (squaled > 16) { - x = 16; - squaled -= 16; - } else { - x = squaled; - squaled = 0; - } - - // drawTexturedModalRect(startX + xPos, startY + yPos + height - x - start, imgColumn * 16, imgLine * 16, 16, 16 - (16 - x)); - manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos + height - x - start, liquidIcon, 16, 16 - (16 - x)); - start = start + 16; - - if (x == 0 || squaled == 0) { - break; - } - } - - Proxies.render.bindTexture(textureFile); - } - - @Override - public String getLegacyTooltip(EntityPlayer player) { - Fluid fluid = FluidRegistry.getFluid(inventory.getCurrentFluidId()); - if (fluid == null) { - return StringUtil.localize("gui.empty"); - } - - return fluid.getLocalizedName(new FluidStack(fluid, 1)); - } - } - public GuiEngineBiogas(InventoryPlayer inventory, TileEngineBiogas tile) { super(Constants.TEXTURE_PATH_GUI + "/bioengine.png", new ContainerEngineBiogas(inventory, tile), tile); - widgetManager.add(new TankWidget(this.widgetManager, 89, 19, 0)); - widgetManager.add(new TankWidget(this.widgetManager, 107, 19, 1)); + widgetManager.add(new TankWidget(widgetManager, 89, 19, 0)); + widgetManager.add(new TankWidget(widgetManager, 107, 19, 1)); - widgetManager.add(new BiogasSlot(this.widgetManager, 30, 47)); + widgetManager.add(new BiogasSlot(widgetManager, 30, 47, 2)); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - int temp = inventory.getOperatingTemperatureScaled(16); - if (temp > 16) { - temp = 16; + int temperature = inventory.getOperatingTemperatureScaled(16); + if (temperature > 16) { + temperature = 16; } - if (temp > 0) { - drawTexturedModalRect(guiLeft + 53, guiTop + 47 + 16 - temp, 176, 60 + 16 - temp, 4, temp); + if (temperature > 0) { + drawTexturedModalRect(guiLeft + 53, guiTop + 47 + 16 - temperature, 176, 60 + 16 - temperature, 4, temperature); } - } } diff --git a/src/main/java/forestry/energy/gui/widgets/BiogasSlot.java b/src/main/java/forestry/energy/gui/widgets/BiogasSlot.java new file mode 100644 index 000000000..c3def307c --- /dev/null +++ b/src/main/java/forestry/energy/gui/widgets/BiogasSlot.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.gui.widgets; + +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidTank; + +import forestry.core.gui.tooltips.ToolTip; +import forestry.core.gui.widgets.ReservoirWidget; +import forestry.core.gui.widgets.WidgetManager; +import forestry.core.utils.StringUtil; + +public class BiogasSlot extends ReservoirWidget { + public BiogasSlot(WidgetManager manager, int xPos, int yPos, int slot) { + super(manager, xPos, yPos, slot); + } + + @Override + public ToolTip getToolTip(int mouseX, int mouseY) { + IFluidTank tank = getTank(); + ToolTip toolTip = new ToolTip(); + FluidStack fluid = tank.getFluid(); + if (fluid == null) { + toolTip.add(StringUtil.localize("gui.empty")); + } else { + toolTip.add(fluid.getLocalizedName()); + } + + return toolTip; + } + + @Override + public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { + // do not allow pipette + } +} diff --git a/src/main/java/forestry/energy/tiles/TileEngineBiogas.java b/src/main/java/forestry/energy/tiles/TileEngineBiogas.java index 627f9f7dd..658e3408e 100644 --- a/src/main/java/forestry/energy/tiles/TileEngineBiogas.java +++ b/src/main/java/forestry/energy/tiles/TileEngineBiogas.java @@ -44,11 +44,9 @@ import forestry.energy.inventory.InventoryEngineBiogas; public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILiquidTankTile, IFluidHandler { private final FilteredTank fuelTank; private final FilteredTank heatingTank; + private final StandardTank burnTank; private final TankManager tankManager; - private int burnTime; - private int totalTime; - private int currentFluidId = -1; private boolean shutdown; // true if the engine is too cold and needs to warm itself up. public TileEngineBiogas() { @@ -60,19 +58,9 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi fuelTank.tankMode = StandardTank.TankMode.DEFAULT; heatingTank = new FilteredTank(Constants.ENGINE_TANK_CAPACITY, FluidRegistry.LAVA); heatingTank.tankMode = StandardTank.TankMode.INPUT; - this.tankManager = new TankManager(this, fuelTank, heatingTank); - } - - public int getBurnTime() { - return burnTime; - } - - public int getTotalTime() { - return totalTime; - } - - public int getCurrentFluidId() { - return currentFluidId; + burnTank = new StandardTank(Constants.BUCKET_VOLUME); + burnTank.tankMode = StandardTank.TankMode.INTERNAL; + this.tankManager = new TankManager(this, fuelTank, heatingTank, burnTank); } @Override @@ -80,6 +68,10 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi return tankManager; } + public Fluid getBurnTankFluidType() { + return burnTank.getFluidType(); + } + @Override public void updateServerSide() { super.updateServerSide(); @@ -95,7 +87,7 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi boolean hasHeat = getHeatLevel() > 0.2 || heatingTank.getFluidAmount() > 0; errorLogic.setCondition(!hasHeat, EnumErrorCode.NO_HEAT); - boolean hasFuel = burnTime > 0 || fuelTank.getFluidAmount() > 0; + boolean hasFuel = burnTank.getFluidAmount() > 0 || fuelTank.getFluidAmount() > 0; errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL); } @@ -107,7 +99,7 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi currentOutput = 0; - if (isRedstoneActivated() && (fuelTank.getFluidAmount() >= Constants.BUCKET_VOLUME || burnTime > 0)) { + if (isRedstoneActivated() && (fuelTank.getFluidAmount() >= Constants.BUCKET_VOLUME || burnTank.getFluidAmount() > 0)) { double heatStage = getHeatLevel(); @@ -124,26 +116,22 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi } // We need a minimum temperature to generate energy - if (heatStage > 0.2) - - { - if (burnTime > 0) { - burnTime--; - currentOutput = determineFuelValue(FluidRegistry.getFluid(currentFluidId)); + if (heatStage > 0.2) { + if (burnTank.getFluidAmount() > 0) { + FluidStack drained = burnTank.drain(1, true); + currentOutput = determineFuelValue(drained.getFluid()); energyManager.generateEnergy(currentOutput); } else { - burnTime = totalTime = determineBurnTime(fuelTank.getFluid().getFluid()); - currentFluidId = fuelTank.getFluid().getFluid().getID(); - fuelTank.drain(Constants.BUCKET_VOLUME, true); + FluidStack fuel = fuelTank.drain(Constants.BUCKET_VOLUME, true); + int burnTime = determineBurnTime(fuel.getFluid()); + fuel.amount = burnTime; + burnTank.setCapacity(burnTime); + burnTank.setFluid(fuel); } } else { shutdown(true); } } - - if (burnTime <= 0) { - currentFluidId = -1; - } } private void shutdown(boolean val) { @@ -185,7 +173,7 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi int generate = 0; - if (isRedstoneActivated() && burnTime > 0) { + if (isRedstoneActivated() && burnTank.getFluidAmount() > 0) { double heatStage = getHeatLevel(); if (heatStage >= 0.75) { generate += Constants.ENGINE_BRONZE_HEAT_GENERATION_ENERGY * 3; @@ -226,16 +214,16 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi // / STATE INFORMATION @Override protected boolean isBurning() { - return mayBurn() && burnTime > 0; + return mayBurn() && burnTank.getFluidAmount() > 0; } @Override public int getBurnTimeRemainingScaled(int i) { - if (totalTime == 0) { + if (burnTank.getCapacity() == 0) { return 0; } - return (burnTime * i) / totalTime; + return (burnTank.getFluidAmount() * i) / burnTank.getCapacity(); } public int getOperatingTemperatureScaled(int i) { @@ -246,32 +234,29 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - burnTime = nbt.getInteger("EngineBurnTime"); - totalTime = nbt.getInteger("EngineTotalTime"); - - if (nbt.hasKey("currentFluid")) { - Fluid fluid = FluidRegistry.getFluid(nbt.getString("currentFluid")); - if (fluid != null) { - currentFluidId = fluid.getID(); + //legacy + { + if (nbt.hasKey("currentFluid")) { + Fluid fluid = FluidRegistry.getFluid(nbt.getString("currentFluid")); + if (fluid != null) { + int burnTime = nbt.getInteger("EngineBurnTime"); + int totalTime = nbt.getInteger("EngineTotalTime"); + burnTank.setCapacity(totalTime); + burnTank.setFluid(new FluidStack(fluid, burnTime)); + } } } + if (nbt.hasKey("shutdown")) { + shutdown = nbt.getBoolean("shutdown"); + } tankManager.readFromNBT(nbt); - } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - - nbt.setInteger("EngineBurnTime", burnTime); - nbt.setInteger("EngineTotalTime", totalTime); - - Fluid fluid = FluidRegistry.getFluid(currentFluidId); - if (fluid != null) { - nbt.setString("currentFluid", fluid.getName()); - } - + nbt.setBoolean("shutdown", shutdown); tankManager.writeToNBT(nbt); } @@ -295,34 +280,26 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi public void getGUINetworkData(int id, int data) { switch (id) { case 0: - burnTime = data; - break; - case 1: - totalTime = data; - break; - case 2: currentOutput = data; break; - case 3: + case 1: energyManager.fromGuiInt(data); break; - case 4: + case 2: heat = data; break; - case 5: - currentFluidId = data; + case 3: + burnTank.setCapacity(data); break; } } @Override public void sendGUINetworkData(Container containerEngine, ICrafting iCrafting) { - iCrafting.sendProgressBarUpdate(containerEngine, 0, burnTime); - iCrafting.sendProgressBarUpdate(containerEngine, 1, totalTime); - iCrafting.sendProgressBarUpdate(containerEngine, 2, currentOutput); - iCrafting.sendProgressBarUpdate(containerEngine, 3, energyManager.toGuiInt()); - iCrafting.sendProgressBarUpdate(containerEngine, 4, heat); - iCrafting.sendProgressBarUpdate(containerEngine, 5, currentFluidId); + iCrafting.sendProgressBarUpdate(containerEngine, 0, currentOutput); + iCrafting.sendProgressBarUpdate(containerEngine, 1, energyManager.toGuiInt()); + iCrafting.sendProgressBarUpdate(containerEngine, 2, heat); + iCrafting.sendProgressBarUpdate(containerEngine, 3, burnTank.getCapacity()); } // IFluidHandler diff --git a/src/main/java/forestry/farming/gui/GuiFarm.java b/src/main/java/forestry/farming/gui/GuiFarm.java index e4b2d7d86..91ff5c750 100755 --- a/src/main/java/forestry/farming/gui/GuiFarm.java +++ b/src/main/java/forestry/farming/gui/GuiFarm.java @@ -11,22 +11,15 @@ package forestry.farming.gui; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.IIcon; - -import org.lwjgl.opengl.GL11; import forestry.api.farming.FarmDirection; -import forestry.api.farming.IFarmLogic; import forestry.core.config.Constants; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.ledgers.ClimateLedger; import forestry.core.gui.ledgers.OwnerLedger; -import forestry.core.gui.tooltips.ToolTip; import forestry.core.gui.widgets.SocketWidget; import forestry.core.gui.widgets.TankWidget; -import forestry.core.gui.widgets.Widget; -import forestry.core.gui.widgets.WidgetManager; -import forestry.core.proxy.Proxies; +import forestry.farming.gui.widgets.FarmLogicSlot; import forestry.farming.multiblock.IFarmControllerInternal; import forestry.farming.tiles.TileFarm; @@ -39,10 +32,12 @@ public class GuiFarm extends GuiForestryTitled { widgetManager.add(new SocketWidget(widgetManager, 69, 40, tile, 0)); - widgetManager.add(new FarmLogicSlot(widgetManager, 69, 22, FarmDirection.NORTH)); - widgetManager.add(new FarmLogicSlot(widgetManager, 69, 58, FarmDirection.SOUTH)); - widgetManager.add(new FarmLogicSlot(widgetManager, 51, 40, FarmDirection.WEST)); - widgetManager.add(new FarmLogicSlot(widgetManager, 87, 40, FarmDirection.EAST)); + IFarmControllerInternal farmController = inventory.getMultiblockLogic().getController(); + + widgetManager.add(new FarmLogicSlot(farmController, widgetManager, 69, 22, FarmDirection.NORTH)); + widgetManager.add(new FarmLogicSlot(farmController, widgetManager, 69, 58, FarmDirection.SOUTH)); + widgetManager.add(new FarmLogicSlot(farmController, widgetManager, 51, 40, FarmDirection.WEST)); + widgetManager.add(new FarmLogicSlot(farmController, widgetManager, 87, 40, FarmDirection.EAST)); this.xSize = 216; this.ySize = 220; @@ -68,58 +63,4 @@ public class GuiFarm extends GuiForestryTitled { } } - private class FarmLogicSlot extends Widget { - - private final FarmDirection farmDirection; - - public FarmLogicSlot(WidgetManager manager, int xPos, int yPos, FarmDirection farmDirection) { - super(manager, xPos, yPos); - this.farmDirection = farmDirection; - } - - private IFarmLogic getLogic() { - return inventory.getMultiblockLogic().getController().getFarmLogic(farmDirection); - } - - private IIcon getIconIndex() { - if (getLogic() == null) { - return null; - } - return getLogic().getIcon(); - } - - @Override - public void draw(int startX, int startY) { - if (getLogic() == null) { - return; - } - - if (getIconIndex() != null) { - GL11.glDisable(GL11.GL_LIGHTING); - Proxies.render.bindTexture(getLogic().getSpriteSheet()); - manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos, getIconIndex(), 16, 16); - GL11.glEnable(GL11.GL_LIGHTING); - } - - } - - @Override - public ToolTip getToolTip() { - return toolTip; - } - - protected final ToolTip toolTip = new ToolTip(250) { - @Override - public void refresh() { - toolTip.clear(); - if (getLogic() == null) { - return; - } - toolTip.add(getLogic().getName()); - toolTip.add("Fertilizer: " + getLogic().getFertilizerConsumption()); - toolTip.add("Water: " + getLogic().getWaterConsumption(inventory.getMultiblockLogic().getController().getFarmLedgerDelegate().getHydrationModifier())); - } - }; - } - } diff --git a/src/main/java/forestry/farming/gui/widgets/FarmLogicSlot.java b/src/main/java/forestry/farming/gui/widgets/FarmLogicSlot.java new file mode 100644 index 000000000..d5dd69e8a --- /dev/null +++ b/src/main/java/forestry/farming/gui/widgets/FarmLogicSlot.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.farming.gui.widgets; + +import net.minecraft.util.IIcon; + +import forestry.api.farming.FarmDirection; +import forestry.api.farming.IFarmLogic; +import forestry.core.gui.tooltips.ToolTip; +import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; +import forestry.core.proxy.Proxies; +import forestry.farming.multiblock.IFarmControllerInternal; + +public class FarmLogicSlot extends Widget { + + private final IFarmControllerInternal farmController; + private final FarmDirection farmDirection; + + public FarmLogicSlot(IFarmControllerInternal farmController, WidgetManager manager, int xPos, int yPos, FarmDirection farmDirection) { + super(manager, xPos, yPos); + this.farmController = farmController; + this.farmDirection = farmDirection; + } + + private IFarmLogic getLogic() { + return farmController.getFarmLogic(farmDirection); + } + + private IIcon getIconIndex() { + if (getLogic() == null) { + return null; + } + return getLogic().getIcon(); + } + + @Override + public void draw(int startX, int startY) { + if (getIconIndex() != null) { + Proxies.render.bindTexture(getLogic().getSpriteSheet()); + manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos, getIconIndex(), 16, 16); + } + } + + @Override + public ToolTip getToolTip(int mouseX, int mouseY) { + if (isMouseOver(mouseX, mouseY)) { + return toolTip; + } else { + return null; + } + } + + protected final ToolTip toolTip = new ToolTip(250) { + @Override + public void refresh() { + toolTip.clear(); + if (getLogic() == null) { + return; + } + toolTip.add(getLogic().getName()); + toolTip.add("Fertilizer: " + getLogic().getFertilizerConsumption()); + toolTip.add("Water: " + getLogic().getWaterConsumption(farmController.getFarmLedgerDelegate().getHydrationModifier())); + } + }; +} diff --git a/src/main/java/forestry/mail/gui/GuiLetter.java b/src/main/java/forestry/mail/gui/GuiLetter.java index 23d53bc91..ccec70a94 100755 --- a/src/main/java/forestry/mail/gui/GuiLetter.java +++ b/src/main/java/forestry/mail/gui/GuiLetter.java @@ -22,8 +22,6 @@ import org.lwjgl.opengl.GL11; import forestry.api.mail.EnumAddressee; import forestry.api.mail.IMailAddress; -import forestry.api.mail.IPostalCarrier; -import forestry.api.mail.PostManager; import forestry.core.config.Constants; import forestry.core.config.SessionVars; import forestry.core.gui.GuiForestry; @@ -31,8 +29,8 @@ import forestry.core.gui.GuiTextBox; import forestry.core.gui.widgets.ItemStackWidget; import forestry.core.gui.widgets.Widget; import forestry.core.proxy.Proxies; -import forestry.core.render.SpriteSheet; import forestry.core.utils.StringUtil; +import forestry.mail.gui.widgets.AddresseeSlot; import forestry.mail.inventory.ItemInventoryLetter; import forestry.mail.network.PacketLetterInfoRequest; @@ -55,7 +53,7 @@ public class GuiLetter extends GuiForestry this.ySize = 227; this.isProcessedLetter = container.getLetter().isProcessed(); - this.widgetManager.add(new AddresseeSlot(16, 12)); + this.widgetManager.add(new AddresseeSlot(widgetManager, 16, 12, container)); this.tradeInfoWidgets = new ArrayList<>(); } @@ -181,9 +179,8 @@ public class GuiLetter extends GuiForestry addTradeInfoWidget(new ItemStackWidget(widgetManager, x, y + 10, container.getTradeInfo().tradegood)); - GL11.glDisable(GL11.GL_LIGHTING); fontRendererObj.drawString(StringUtil.localize("gui.mail.foreveryattached"), guiLeft + x, guiTop + y + 28, fontColor.get("gui.mail.lettertext")); - GL11.glEnable(GL11.GL_LIGHTING); + for (int i = 0; i < container.getTradeInfo().required.length; i++) { addTradeInfoWidget(new ItemStackWidget(widgetManager, x + i * 18, y + 38, container.getTradeInfo().required[i])); } @@ -252,36 +249,4 @@ public class GuiLetter extends GuiForestry container.setText(this.text.getText()); } - protected class AddresseeSlot extends Widget { - - public AddresseeSlot(int xPos, int yPos) { - super(widgetManager, xPos, yPos); - this.width = 26; - this.height = 15; - } - - @Override - public void draw(int startX, int startY) { - IPostalCarrier carrier = PostManager.postRegistry.getCarrier(container.getCarrierType()); - if (carrier != null) { - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); - Proxies.render.bindTexture(SpriteSheet.ITEMS); - drawTexturedModelRectFromIcon(startX + xPos, startY + yPos - 5, carrier.getIcon(), 26, 26); - } - } - - @Override - protected String getLegacyTooltip(EntityPlayer player) { - return StringUtil.localize("gui.addressee." + container.getCarrierType().toString()); - } - - @Override - public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { - if (!isProcessedLetter) { - container.advanceCarrierType(); - } - } - - } - } diff --git a/src/main/java/forestry/mail/gui/GuiTrader.java b/src/main/java/forestry/mail/gui/GuiTrader.java index 31c74e75f..6b06598a0 100755 --- a/src/main/java/forestry/mail/gui/GuiTrader.java +++ b/src/main/java/forestry/mail/gui/GuiTrader.java @@ -11,6 +11,7 @@ package forestry.mail.gui; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.StatCollector; import forestry.core.config.Constants; import forestry.core.gui.GuiForestry; @@ -27,7 +28,7 @@ public class GuiTrader extends GuiForestry { @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - String name = StringUtil.localizeTile(inventory.getUnlocalizedTitle()); + String name = StatCollector.translateToLocal(inventory.getUnlocalizedTitle()); this.fontRendererObj.drawString(name, textLayout.getCenteredOffset(name), 6, fontColor.get("gui.mail.text")); String receive = StringUtil.localize("gui.mail.receive"); diff --git a/src/main/java/forestry/mail/gui/widgets/AddresseeSlot.java b/src/main/java/forestry/mail/gui/widgets/AddresseeSlot.java new file mode 100644 index 000000000..2f9448664 --- /dev/null +++ b/src/main/java/forestry/mail/gui/widgets/AddresseeSlot.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.mail.gui.widgets; + +import net.minecraft.entity.player.EntityPlayer; + +import org.lwjgl.opengl.GL11; + +import forestry.api.mail.IPostalCarrier; +import forestry.api.mail.PostManager; +import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; +import forestry.core.proxy.Proxies; +import forestry.core.render.SpriteSheet; +import forestry.core.utils.StringUtil; +import forestry.mail.gui.ContainerLetter; + +public class AddresseeSlot extends Widget { + + private final ContainerLetter containerLetter; + + public AddresseeSlot(WidgetManager widgetManager, int xPos, int yPos, ContainerLetter containerLetter) { + super(widgetManager, xPos, yPos); + this.containerLetter = containerLetter; + this.width = 26; + this.height = 15; + } + + @Override + public void draw(int startX, int startY) { + IPostalCarrier carrier = PostManager.postRegistry.getCarrier(containerLetter.getCarrierType()); + if (carrier != null) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); + Proxies.render.bindTexture(SpriteSheet.ITEMS); + manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos - 5, carrier.getIcon(), 26, 26); + } + } + + @Override + protected String getLegacyTooltip(EntityPlayer player) { + return StringUtil.localize("gui.addressee." + containerLetter.getCarrierType().toString()); + } + + @Override + public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { + if (!containerLetter.getLetter().isProcessed()) { + containerLetter.advanceCarrierType(); + } + } +}