From 4c8d5e2f4399e0e9107d5ef152bc31809920474c Mon Sep 17 00:00:00 2001 From: mezz Date: Sun, 6 Nov 2016 01:51:43 -0800 Subject: [PATCH] Move Forestry GUI icons to a new TextureMap --- build.gradle | 7 +- .../java/forestry/api/core/IErrorState.java | 6 +- .../forestry/api/core/ITextureManager.java | 18 +- .../java/forestry/api/core/package-info.java | 2 +- .../forestry/api/mail/IPostalCarrier.java | 6 +- .../java/forestry/api/mail/package-info.java | 2 +- .../apiculture/gui/widgets/HabitatSlot.java | 2 +- .../forestry/core/errors/EnumErrorCode.java | 13 +- .../forestry/core/gui/ledgers/Ledger.java | 17 +- .../forestry/core/gui/slots/SlotForestry.java | 7 +- .../core/gui/widgets/GameTokenWidget.java | 15 +- .../core/proxy/ProxyRenderClient.java | 68 ++++--- .../forestry/core/render/TextureManager.java | 53 +++-- .../core/render/TextureMapForestry.java | 187 ++++++++++++++++++ .../gui/widgets/MemorizedRecipeSlot.java | 10 +- .../java/forestry/farming/gui/FarmLedger.java | 9 +- .../forestry/mail/gui/GuiMailboxInfo.java | 12 +- .../mail/gui/widgets/AddresseeSlot.java | 9 +- .../textures/gui/mail/carrier.player.png | Bin 179 -> 175 bytes .../textures/gui/mail/carrier.trader.png | Bin 163 -> 159 bytes src/main/resources/forestry_at.cfg | 8 + 21 files changed, 347 insertions(+), 104 deletions(-) create mode 100644 src/main/java/forestry/core/render/TextureMapForestry.java create mode 100644 src/main/resources/forestry_at.cfg diff --git a/build.gradle b/build.gradle index d64012893..f489ec6fb 100755 --- a/build.gradle +++ b/build.gradle @@ -98,6 +98,9 @@ processResources { exclude 'mcmod.info' exclude '**/*.md' } + + // Move access transformers to META-INF + rename '(.+_at.cfg)', 'META-INF/$1' } // prevent java 8's strict doclint for javadocs from failing builds @@ -108,7 +111,9 @@ allprojects { } jar { - + manifest { + attributes 'FMLAT': 'forestry_at.cfg' + } } task sourcesJar(type: Jar) { diff --git a/src/main/java/forestry/api/core/IErrorState.java b/src/main/java/forestry/api/core/IErrorState.java index c752583a1..0442dd8e1 100644 --- a/src/main/java/forestry/api/core/IErrorState.java +++ b/src/main/java/forestry/api/core/IErrorState.java @@ -6,7 +6,6 @@ package forestry.api.core; import net.minecraft.client.renderer.texture.TextureAtlasSprite; - import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -27,7 +26,10 @@ public interface IErrorState { @SideOnly(Side.CLIENT) void registerSprite(); - @SideOnly(value = Side.CLIENT) + /** + * Sprite registered to the Gui Texture Map at {@link ITextureManager} + */ + @SideOnly(Side.CLIENT) TextureAtlasSprite getSprite(); } diff --git a/src/main/java/forestry/api/core/ITextureManager.java b/src/main/java/forestry/api/core/ITextureManager.java index e1b2a16c6..6e12fee3f 100644 --- a/src/main/java/forestry/api/core/ITextureManager.java +++ b/src/main/java/forestry/api/core/ITextureManager.java @@ -6,13 +6,29 @@ package forestry.api.core; import net.minecraft.client.renderer.texture.TextureAtlasSprite; - +import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +/** + * Get the instance from {@link ForestryAPI#textureManager}. + */ @SideOnly(Side.CLIENT) public interface ITextureManager { + /** + * Location of the Forestry Gui Texture Map. + * Used for binding with {@link net.minecraft.client.renderer.texture.TextureManager#bindTexture(ResourceLocation)} + */ + ResourceLocation getGuiTextureMap(); + + /** + * Get a texture atlas sprite that has been registered by Forestry, for Forestry's Gui Texture Map. + */ TextureAtlasSprite getDefault(String ident); + /** + * Register a sprite with Forestry's Gui Texture Map. + */ + TextureAtlasSprite registerGuiSprite(ResourceLocation location); } diff --git a/src/main/java/forestry/api/core/package-info.java b/src/main/java/forestry/api/core/package-info.java index be9abfd21..9a7a6451e 100644 --- a/src/main/java/forestry/api/core/package-info.java +++ b/src/main/java/forestry/api/core/package-info.java @@ -3,7 +3,7 @@ * * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ -@API(apiVersion = "5.0.0", owner = "Forestry", provides = "ForestryAPI|core") +@API(apiVersion = "5.1.0", owner = "Forestry", provides = "ForestryAPI|core") package forestry.api.core; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/forestry/api/mail/IPostalCarrier.java b/src/main/java/forestry/api/mail/IPostalCarrier.java index 6b979e587..b027c8b1d 100644 --- a/src/main/java/forestry/api/mail/IPostalCarrier.java +++ b/src/main/java/forestry/api/mail/IPostalCarrier.java @@ -5,10 +5,10 @@ ******************************************************************************/ package forestry.api.mail; +import forestry.api.core.ITextureManager; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.item.ItemStack; import net.minecraft.world.World; - import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -31,6 +31,10 @@ public interface IPostalCarrier { */ String getName(); + /** + * Sprite registered to the Gui Texture Map at {@link ITextureManager}. + * Must be 26 pixels wide and 15 pixels tall. The texture itself must be 26x26 square to be accepted by the texture map. + */ @SideOnly(Side.CLIENT) TextureAtlasSprite getSprite(); diff --git a/src/main/java/forestry/api/mail/package-info.java b/src/main/java/forestry/api/mail/package-info.java index 9d66f8243..e191eccbb 100644 --- a/src/main/java/forestry/api/mail/package-info.java +++ b/src/main/java/forestry/api/mail/package-info.java @@ -3,7 +3,7 @@ * * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ -@API(apiVersion = "3.0.0", owner = "ForestryAPI|core", provides = "ForestryAPI|mail") +@API(apiVersion = "3.1.0", owner = "ForestryAPI|core", provides = "ForestryAPI|mail") package forestry.api.mail; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/forestry/apiculture/gui/widgets/HabitatSlot.java b/src/main/java/forestry/apiculture/gui/widgets/HabitatSlot.java index 051fefe1c..173195782 100644 --- a/src/main/java/forestry/apiculture/gui/widgets/HabitatSlot.java +++ b/src/main/java/forestry/apiculture/gui/widgets/HabitatSlot.java @@ -70,7 +70,7 @@ public class HabitatSlot extends Widget { GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); } - Proxies.render.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); + Proxies.render.bindTexture(TextureManager.getInstance().getGuiTextureMap()); manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, getIcon(), 16, 16); } } diff --git a/src/main/java/forestry/core/errors/EnumErrorCode.java b/src/main/java/forestry/core/errors/EnumErrorCode.java index 6b5935018..6d88d24e9 100644 --- a/src/main/java/forestry/core/errors/EnumErrorCode.java +++ b/src/main/java/forestry/core/errors/EnumErrorCode.java @@ -5,16 +5,14 @@ ******************************************************************************/ package forestry.core.errors; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.ResourceLocation; - -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorState; import forestry.core.config.Constants; import forestry.core.render.TextureManager; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public enum EnumErrorCode implements IErrorState { @@ -112,7 +110,8 @@ public enum EnumErrorCode implements IErrorState { @SideOnly(Side.CLIENT) @Override public void registerSprite() { - texture = TextureManager.registerSprite(new ResourceLocation(Constants.MOD_ID, "gui/errors/" + iconName)); + ResourceLocation location = new ResourceLocation(Constants.MOD_ID, "gui/errors/" + iconName); + texture = TextureManager.getInstance().registerGuiSprite(location); } @SideOnly(Side.CLIENT) diff --git a/src/main/java/forestry/core/gui/ledgers/Ledger.java b/src/main/java/forestry/core/gui/ledgers/Ledger.java index b0127f550..41c70b2c3 100644 --- a/src/main/java/forestry/core/gui/ledgers/Ledger.java +++ b/src/main/java/forestry/core/gui/ledgers/Ledger.java @@ -13,18 +13,17 @@ package forestry.core.gui.ledgers; import java.awt.Rectangle; import java.util.List; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.util.ResourceLocation; - import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.SessionVars; import forestry.core.gui.GuiForestry; import forestry.core.proxy.Proxies; import forestry.core.render.ForestryResource; +import forestry.core.render.TextureManager; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; /** * Side ledger for guis @@ -214,9 +213,13 @@ public abstract class Ledger { } protected void drawSprite(TextureAtlasSprite sprite, int x, int y) { + drawSprite(TextureManager.getInstance().getGuiTextureMap(), sprite, x, y); + } + + protected void drawSprite(ResourceLocation textureMap, TextureAtlasSprite sprite, int x, int y) { if (sprite != null) { GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0F); - Proxies.render.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); + Proxies.render.bindTexture(textureMap); manager.gui.drawTexturedModalRect(x, y, sprite, 16, 16); } } diff --git a/src/main/java/forestry/core/gui/slots/SlotForestry.java b/src/main/java/forestry/core/gui/slots/SlotForestry.java index c2b21cf06..6b8d59090 100755 --- a/src/main/java/forestry/core/gui/slots/SlotForestry.java +++ b/src/main/java/forestry/core/gui/slots/SlotForestry.java @@ -10,14 +10,14 @@ ******************************************************************************/ package forestry.core.gui.slots; +import forestry.core.gui.tooltips.IToolTipProvider; +import forestry.core.gui.tooltips.ToolTip; +import forestry.core.render.TextureManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import forestry.core.gui.tooltips.IToolTipProvider; -import forestry.core.gui.tooltips.ToolTip; - public class SlotForestry extends Slot implements IToolTipProvider { private boolean isPhantom; @@ -31,6 +31,7 @@ public class SlotForestry extends Slot implements IToolTipProvider { if (inventory == null) { throw new IllegalArgumentException("Inventory must not be null"); } + setBackgroundLocation(TextureManager.getInstance().getGuiTextureMap()); this.stackLimit = -1; } diff --git a/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java b/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java index deb8421c8..740ed40f5 100644 --- a/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java +++ b/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java @@ -10,12 +10,6 @@ ******************************************************************************/ package forestry.core.gui.widgets; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; - import forestry.core.gui.GuiUtil; import forestry.core.gui.tooltips.ToolTip; import forestry.core.network.packets.PacketGuiSelectRequest; @@ -23,6 +17,10 @@ import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; import forestry.core.tiles.EscritoireGame; import forestry.core.tiles.EscritoireGameToken; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; public class GameTokenWidget extends Widget { private final ItemStack HIDDEN_TOKEN = new ItemStack(Items.BOOK); @@ -70,8 +68,9 @@ public class GameTokenWidget extends Widget { GlStateManager.disableDepth(); for (String ident : getToken().getOverlayIcons()) { - Proxies.render.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); - TextureAtlasSprite icon = TextureManager.getInstance().getDefault(ident); + TextureManager textureManager = TextureManager.getInstance(); + Proxies.render.bindTexture(textureManager.getGuiTextureMap()); + TextureAtlasSprite icon = textureManager.getDefault(ident); manager.gui.drawTexturedModalRect(startX + xPos + 3, startY + yPos + 3, icon, 16, 16); } GlStateManager.enableDepth(); diff --git a/src/main/java/forestry/core/proxy/ProxyRenderClient.java b/src/main/java/forestry/core/proxy/ProxyRenderClient.java index 6dec954c6..832aad75c 100644 --- a/src/main/java/forestry/core/proxy/ProxyRenderClient.java +++ b/src/main/java/forestry/core/proxy/ProxyRenderClient.java @@ -10,39 +10,10 @@ ******************************************************************************/ package forestry.core.proxy; -import com.google.common.collect.ImmutableMap; - import javax.annotation.Nonnull; import java.util.List; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleManager; -import net.minecraft.client.renderer.ItemMeshDefinition; -import net.minecraft.client.renderer.block.model.ModelBakery; -import net.minecraft.client.renderer.block.model.ModelResourceLocation; -import net.minecraft.client.renderer.block.statemap.IStateMapper; -import net.minecraft.client.renderer.block.statemap.StateMapperBase; -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.client.resources.IResourceManager; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumParticleTypes; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.World; - -import net.minecraftforge.client.model.ModelLoader; -import net.minecraftforge.client.model.ModelLoaderRegistry; -import net.minecraftforge.common.animation.ITimeValue; -import net.minecraftforge.common.model.animation.IAnimationStateMachine; - +import com.google.common.collect.ImmutableMap; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IHiveTile; @@ -66,12 +37,40 @@ import forestry.core.render.RenderEscritoire; import forestry.core.render.RenderMachine; import forestry.core.render.RenderMill; import forestry.core.render.RenderNaturalistChest; +import forestry.core.render.TextureManager; +import forestry.core.render.TextureMapForestry; import forestry.core.tiles.TileAnalyzer; import forestry.core.tiles.TileBase; import forestry.core.tiles.TileEscritoire; import forestry.core.tiles.TileMill; import forestry.core.tiles.TileNaturalistChest; import forestry.core.utils.VectUtil; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleManager; +import net.minecraft.client.renderer.ItemMeshDefinition; +import net.minecraft.client.renderer.block.model.ModelBakery; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.renderer.block.statemap.IStateMapper; +import net.minecraft.client.renderer.block.statemap.StateMapperBase; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; +import net.minecraft.world.World; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.common.animation.ITimeValue; +import net.minecraftforge.common.model.animation.IAnimationStateMachine; public class ProxyRenderClient extends ProxyRender { @@ -85,6 +84,15 @@ public class ProxyRenderClient extends ProxyRender { return true; } + @Override + public void initRendering() { + TextureManager textureManager = TextureManager.getInstance(); + TextureMapForestry textureMap = textureManager.getTextureMap(); + + Minecraft minecraft = Minecraft.getMinecraft(); + minecraft.renderEngine.loadTickableTexture(TextureManager.getInstance().getGuiTextureMap(), textureMap); + } + @Override public TileEntitySpecialRenderer getRenderDefaultMachine(String gfxBase) { if (gfxBase == null) { diff --git a/src/main/java/forestry/core/render/TextureManager.java b/src/main/java/forestry/core/render/TextureManager.java index 338aa2909..ee4171a08 100755 --- a/src/main/java/forestry/core/render/TextureManager.java +++ b/src/main/java/forestry/core/render/TextureManager.java @@ -11,31 +11,27 @@ package forestry.core.render; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.item.Item; -import net.minecraft.util.ResourceLocation; - -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import forestry.api.core.ForestryAPI; import forestry.api.core.ISpriteRegister; import forestry.api.core.ITextureManager; import forestry.core.config.Constants; import forestry.core.proxy.Proxies; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.Item; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class TextureManager implements ITextureManager { - + public static final ResourceLocation LOCATION_FORESTRY_TEXTURE = new ResourceLocation("textures/atlas/forestry.png"); private static final TextureManager INSTANCE = new TextureManager(); - private static final Map defaultIcons = new HashMap<>(); private final List spriteRegisters = new ArrayList<>(); + private final TextureMapForestry textureMap; static { ForestryAPI.textureManager = INSTANCE; @@ -46,6 +42,11 @@ public class TextureManager implements ITextureManager { } private TextureManager() { + this.textureMap = new TextureMapForestry("textures"); + } + + public TextureMapForestry getTextureMap() { + return textureMap; } public static void initDefaultSprites() { @@ -59,22 +60,36 @@ public class TextureManager implements ITextureManager { "slots/blocked", "slots/blocked_2", "slots/liquid", "slots/container", "slots/locked", "mail/carrier.player", "mail/carrier.trader"}; for (String identifier : defaultIconNames) { - ResourceLocation resourceLocation = new ResourceLocation(Constants.MOD_ID, "gui/" + identifier); - TextureAtlasSprite icon = registerSprite(resourceLocation); - defaultIcons.put(identifier, icon); + ResourceLocation resourceLocation = getForestryGuiLocation(identifier); + INSTANCE.registerGuiSprite(resourceLocation); } } + private static ResourceLocation getForestryGuiLocation(String identifier) { + return new ResourceLocation(Constants.MOD_ID, "gui/" + identifier); + } + public static TextureAtlasSprite registerSprite(ResourceLocation location) { TextureMap textureMap = Proxies.common.getClientInstance().getTextureMapBlocks(); return textureMap.registerSprite(location); } @Override - public TextureAtlasSprite getDefault(String ident) { - return defaultIcons.get(ident); + public TextureAtlasSprite getDefault(String identifier) { + ResourceLocation resourceLocation = getForestryGuiLocation(identifier); + return getTextureMap().getAtlasSprite(resourceLocation.toString()); } - + + @Override + public ResourceLocation getGuiTextureMap() { + return LOCATION_FORESTRY_TEXTURE; + } + + @Override + public TextureAtlasSprite registerGuiSprite(ResourceLocation location) { + return getTextureMap().registerSprite(location); + } + public void registerBlock(Block block) { if (block instanceof ISpriteRegister) { spriteRegisters.add((ISpriteRegister) block); diff --git a/src/main/java/forestry/core/render/TextureMapForestry.java b/src/main/java/forestry/core/render/TextureMapForestry.java new file mode 100644 index 000000000..12e467634 --- /dev/null +++ b/src/main/java/forestry/core/render/TextureMapForestry.java @@ -0,0 +1,187 @@ +package forestry.core.render; + +import javax.annotation.Nonnull; +import java.io.Closeable; +import java.io.IOException; +import java.util.Map; + +import com.google.common.collect.Maps; +import forestry.core.utils.Log; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.PngSizeInfo; +import net.minecraft.client.renderer.texture.Stitcher; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.client.resources.IResource; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.crash.ICrashReportDetail; +import net.minecraft.util.ReportedException; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.client.FMLClientHandler; +import net.minecraftforge.fml.common.ProgressManager; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.commons.io.IOUtils; + +@SideOnly(Side.CLIENT) +public class TextureMapForestry extends TextureMap { + private boolean skipFirst = true; + + public TextureMapForestry(String basePathIn) { + super(basePathIn, null, true); + } + + @Override + public void loadTexture(@Nonnull IResourceManager resourceManager) throws IOException { + this.initMissingImage(); + this.deleteGlTexture(); + this.loadTextureAtlas(resourceManager); + } + + @Override + public void loadTextureAtlas(@Nonnull IResourceManager resourceManager) { + int i = Minecraft.getGLMaximumTextureSize(); + Stitcher stitcher = new Stitcher(i, i, 0, 0); + this.mapUploadedSprites.clear(); + this.listAnimatedSprites.clear(); + + ProgressManager.ProgressBar bar = ProgressManager.push("Texture stitching", skipFirst ? 0 : this.mapRegisteredSprites.size()); + + if (!skipFirst) { + for (Map.Entry entry : this.mapRegisteredSprites.entrySet()) { + TextureAtlasSprite textureatlassprite = entry.getValue(); + ResourceLocation resourcelocation = this.getResourceLocation(textureatlassprite); + bar.step(resourcelocation.getResourcePath()); + IResource iresource = null; + + if (textureatlassprite.hasCustomLoader(resourceManager, resourcelocation)) { + if (textureatlassprite.load(resourceManager, resourcelocation)) { + continue; + } + } else + try { + PngSizeInfo pngsizeinfo = PngSizeInfo.makeFromResource(resourceManager.getResource(resourcelocation)); + iresource = resourceManager.getResource(resourcelocation); + boolean flag = iresource.getMetadata("animation") != null; + textureatlassprite.loadSprite(pngsizeinfo, flag); + } catch (RuntimeException runtimeexception) { + FMLClientHandler.instance().trackBrokenTexture(resourcelocation, runtimeexception.getMessage()); + continue; + } catch (IOException ioexception) { + FMLClientHandler.instance().trackMissingTexture(resourcelocation); + continue; + } finally { + IOUtils.closeQuietly(iresource); + } + + stitcher.addSprite(textureatlassprite); + } + } + + ProgressManager.pop(bar); + + this.missingImage.generateMipmaps(0); + stitcher.addSprite(this.missingImage); + skipFirst = false; + bar = ProgressManager.push("Texture creation", 2); + + bar.step("Stitching"); + stitcher.doStitch(); + + Log.info("Created: {}x{} {}-atlas", stitcher.getCurrentWidth(), stitcher.getCurrentHeight(), this.basePath); + bar.step("Allocating GL texture"); + TextureUtil.allocateTextureImpl(this.getGlTextureId(), 0, stitcher.getCurrentWidth(), stitcher.getCurrentHeight()); + Map map = Maps.newHashMap(this.mapRegisteredSprites); + + ProgressManager.pop(bar); + bar = ProgressManager.push("Texture mipmap and upload", stitcher.getStichSlots().size()); + + for (TextureAtlasSprite textureatlassprite1 : stitcher.getStichSlots()) { + bar.step(textureatlassprite1.getIconName()); + if (textureatlassprite1 == this.missingImage || this.generateMipmaps(resourceManager, textureatlassprite1)) { + String s = textureatlassprite1.getIconName(); + map.remove(s); + this.mapUploadedSprites.put(s, textureatlassprite1); + + try { + TextureUtil.uploadTextureMipmap(textureatlassprite1.getFrameTextureData(0), textureatlassprite1.getIconWidth(), textureatlassprite1.getIconHeight(), textureatlassprite1.getOriginX(), textureatlassprite1.getOriginY(), false, false); + } catch (Throwable throwable) { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Stitching texture atlas"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Texture being stitched together"); + crashreportcategory.addCrashSection("Atlas path", this.basePath); + crashreportcategory.addCrashSection("Sprite", textureatlassprite1); + throw new ReportedException(crashreport); + } + + if (textureatlassprite1.hasAnimationMetadata()) { + this.listAnimatedSprites.add(textureatlassprite1); + } + } + } + + for (TextureAtlasSprite textureatlassprite2 : map.values()) { + textureatlassprite2.copyFrom(this.missingImage); + } + + ProgressManager.pop(bar); + } + + private boolean generateMipmaps(IResourceManager resourceManager, final TextureAtlasSprite texture) { + ResourceLocation resourcelocation = this.getResourceLocation(texture); + IResource iresource = null; + label9: + { + boolean flag; + if (texture.hasCustomLoader(resourceManager, resourcelocation)) break label9; + try { + iresource = resourceManager.getResource(resourcelocation); + texture.loadSpriteFrames(iresource, 1); + break label9; + } catch (RuntimeException runtimeexception) { + Log.error("Unable to parse metadata from {}", resourcelocation, runtimeexception); + flag = false; + } catch (IOException ioexception) { + Log.error("Using missing texture, unable to load {}", resourcelocation, ioexception); + flag = false; + return flag; + } finally { + IOUtils.closeQuietly((Closeable) iresource); + } + + return flag; + } + + try { + texture.generateMipmaps(0); + return true; + } catch (Throwable throwable) { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Applying mipmap"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Sprite being mipmapped"); + crashreportcategory.setDetail("Sprite name", new ICrashReportDetail() { + public String call() throws Exception { + return texture.getIconName(); + } + }); + crashreportcategory.setDetail("Sprite size", new ICrashReportDetail() { + public String call() throws Exception { + return texture.getIconWidth() + " x " + texture.getIconHeight(); + } + }); + crashreportcategory.setDetail("Sprite frames", new ICrashReportDetail() { + public String call() throws Exception { + return texture.getFrameCount() + " frames"; + } + }); + crashreportcategory.addCrashSection("Mipmap levels", 0); + throw new ReportedException(crashreport); + } + } + + private ResourceLocation getResourceLocation(TextureAtlasSprite p_184396_1_) { + ResourceLocation resourcelocation = new ResourceLocation(p_184396_1_.getIconName()); + return new ResourceLocation(resourcelocation.getResourceDomain(), String.format("%s/%s%s", this.basePath, resourcelocation.getResourcePath(), ".png")); + } +} diff --git a/src/main/java/forestry/factory/gui/widgets/MemorizedRecipeSlot.java b/src/main/java/forestry/factory/gui/widgets/MemorizedRecipeSlot.java index 50d9b6a76..c7c2dff19 100644 --- a/src/main/java/forestry/factory/gui/widgets/MemorizedRecipeSlot.java +++ b/src/main/java/forestry/factory/gui/widgets/MemorizedRecipeSlot.java @@ -10,17 +10,15 @@ ******************************************************************************/ package forestry.factory.gui.widgets; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.item.ItemStack; - import forestry.core.gui.widgets.ItemStackWidgetBase; import forestry.core.gui.widgets.WidgetManager; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; import forestry.factory.gui.ContainerWorktable; import forestry.factory.recipes.RecipeMemory; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.item.ItemStack; public class MemorizedRecipeSlot extends ItemStackWidgetBase { private static final TextureAtlasSprite lockIcon = TextureManager.getInstance().getDefault("slots/locked"); @@ -45,7 +43,7 @@ public class MemorizedRecipeSlot extends ItemStackWidgetBase { GlStateManager.disableDepth(); if (recipeMemory.isLocked(slotNumber)) { - Proxies.render.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); + Proxies.render.bindTexture(TextureManager.getInstance().getGuiTextureMap()); manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, lockIcon, 16, 16); } diff --git a/src/main/java/forestry/farming/gui/FarmLedger.java b/src/main/java/forestry/farming/gui/FarmLedger.java index cd1df116d..e701372a9 100644 --- a/src/main/java/forestry/farming/gui/FarmLedger.java +++ b/src/main/java/forestry/farming/gui/FarmLedger.java @@ -10,14 +10,14 @@ ******************************************************************************/ package forestry.farming.gui; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; import forestry.core.gui.ledgers.Ledger; import forestry.core.gui.ledgers.LedgerManager; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; import forestry.core.utils.Translator; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; public class FarmLedger extends Ledger { private final IFarmLedgerDelegate delegate; @@ -45,8 +45,7 @@ public class FarmLedger extends Ledger { Minecraft minecraft = Proxies.common.getClientInstance(); TextureMap textureMapBlocks = minecraft.getTextureMapBlocks(); TextureAtlasSprite textureAtlasSprite = textureMapBlocks.getAtlasSprite("minecraft:items/bucket_water"); - - drawSprite(textureAtlasSprite, xIcon, y); + drawSprite(TextureMap.LOCATION_BLOCKS_TEXTURE, textureAtlasSprite, xIcon, y); y += 4; if (!isFullyOpened()) { diff --git a/src/main/java/forestry/mail/gui/GuiMailboxInfo.java b/src/main/java/forestry/mail/gui/GuiMailboxInfo.java index 7dd2bbdd3..1d4156c5b 100755 --- a/src/main/java/forestry/mail/gui/GuiMailboxInfo.java +++ b/src/main/java/forestry/mail/gui/GuiMailboxInfo.java @@ -10,6 +10,11 @@ ******************************************************************************/ package forestry.mail.gui; +import forestry.core.config.Config; +import forestry.core.config.Constants; +import forestry.core.proxy.Proxies; +import forestry.core.render.ForestryResource; +import forestry.mail.POBoxInfo; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.FontRenderer; @@ -21,12 +26,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; import net.minecraft.world.World; -import forestry.core.config.Config; -import forestry.core.config.Constants; -import forestry.core.proxy.Proxies; -import forestry.core.render.ForestryResource; -import forestry.mail.POBoxInfo; - public class GuiMailboxInfo extends Gui { public enum XPosition { @@ -43,6 +42,7 @@ public class GuiMailboxInfo extends Gui { private final FontRenderer fontRendererObj; private POBoxInfo poInfo; + // TODO: this texture is a terrible waste of space in graphics memory, find a better way to do it. private final ResourceLocation textureAlert = new ForestryResource(Constants.TEXTURE_PATH_GUI + "/mailalert.png"); private GuiMailboxInfo() { diff --git a/src/main/java/forestry/mail/gui/widgets/AddresseeSlot.java b/src/main/java/forestry/mail/gui/widgets/AddresseeSlot.java index e6942319a..da209a596 100644 --- a/src/main/java/forestry/mail/gui/widgets/AddresseeSlot.java +++ b/src/main/java/forestry/mail/gui/widgets/AddresseeSlot.java @@ -10,17 +10,16 @@ ******************************************************************************/ package forestry.mail.gui.widgets; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.TextureMap; - import forestry.api.mail.IPostalCarrier; import forestry.api.mail.PostManager; 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.core.render.TextureManager; import forestry.core.utils.Translator; import forestry.mail.gui.ContainerLetter; +import net.minecraft.client.renderer.GlStateManager; public class AddresseeSlot extends Widget { @@ -38,8 +37,8 @@ public class AddresseeSlot extends Widget { IPostalCarrier carrier = PostManager.postRegistry.getCarrier(containerLetter.getCarrierType()); if (carrier != null) { GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0F); - Proxies.render.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); - manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, carrier.getSprite(), 32, 32); + Proxies.render.bindTexture(TextureManager.getInstance().getGuiTextureMap()); + manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, carrier.getSprite(), 26, 26); } } diff --git a/src/main/resources/assets/forestry/textures/gui/mail/carrier.player.png b/src/main/resources/assets/forestry/textures/gui/mail/carrier.player.png index 68a129e2ea81701e2f2384646dd6c6758d465101..2e2d9f8b6274dd68d6bf7b97a82fab04e8220edc 100644 GIT binary patch literal 175 zcmeAS@N?(olHy`uVBq!ia0vp^QXtI23?!pd0{;Rj{s5m4*Z=?jH>4|_Uv4q8TGPSA zq$|y=);z!5 z!p*061yG8yB*-tA!Qt7BG$1F))5S5QBJOS9ZO#S<9+u08^votqDUg-9Rqxw1z14w5 zddE*0HU8aP%WcnaI_`Va@IiG!i^swvsz!<`MunVfS~QvjAHGn|&9uKQ_q(pvg#kghbdTGPSA zWP7UZTA&nTNswPKgTu2MX+Vyhr;B4qMcmoGjhqY$JS_FBhQbz3Cz!f^pI_2iurjFn z?!-TzvpV%|ZhL2te$d!BQ@56~nAPgg&ebxsLQ E0LFkf761SM literal 163 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv{s5m4*Z=?jJD8X>q$|y=);z!5 z!p*061yG8yB*-tA!Qt7BG$6;x)5S5QBJOSfK~4q*9_HOmk67{o%r$oX_xUz`noU>z z`^uJ<6P!7PYa00$&N}j8hiapX<_>1<{wC`~T=kL03aazDZ?=hltP7aT0yK@m)78&q Iol`;+0Bb`wqW}N^ diff --git a/src/main/resources/forestry_at.cfg b/src/main/resources/forestry_at.cfg new file mode 100644 index 000000000..79cce4c8b --- /dev/null +++ b/src/main/resources/forestry_at.cfg @@ -0,0 +1,8 @@ +#TextureMap +public net.minecraft.client.renderer.texture.TextureMap field_94252_e # mapUploadedSprites +public net.minecraft.client.renderer.texture.TextureMap field_94258_i # listAnimatedSprites +public net.minecraft.client.renderer.texture.TextureMap field_94249_f # missingImage +public net.minecraft.client.renderer.texture.TextureMap field_94254_c # basePath +public net.minecraft.client.renderer.texture.TextureMap field_110574_e # mapRegisteredSprites + +public net.minecraft.client.renderer.texture.TextureMap func_110569_e()V # initMissingImage