From fe4ee85d8173b3442530f330509568c58206018f Mon Sep 17 00:00:00 2001 From: mezz Date: Mon, 21 Jan 2019 22:46:03 -0800 Subject: [PATCH] Fix #1471 Remove texture pack sizing restrictions --- src/main/java/mezz/jei/gui/GuiHelper.java | 50 ++---- .../elements/DrawableNineSliceTexture.java | 140 ++++++++------- .../mezz/jei/gui/elements/DrawableSprite.java | 80 +++++++++ .../mezz/jei/gui/textures/JeiTextureMap.java | 161 ------------------ .../mezz/jei/gui/textures/TextureInfo.java | 84 +++++++-- .../java/mezz/jei/gui/textures/Textures.java | 40 +++-- src/main/resources/jei_at.cfg | 5 - 7 files changed, 257 insertions(+), 303 deletions(-) create mode 100644 src/main/java/mezz/jei/gui/elements/DrawableSprite.java diff --git a/src/main/java/mezz/jei/gui/GuiHelper.java b/src/main/java/mezz/jei/gui/GuiHelper.java index e897d9016..0ba6c35b7 100644 --- a/src/main/java/mezz/jei/gui/GuiHelper.java +++ b/src/main/java/mezz/jei/gui/GuiHelper.java @@ -1,6 +1,5 @@ package mezz.jei.gui; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.ResourceLocation; import mezz.jei.api.IGuiHelper; @@ -17,7 +16,7 @@ import mezz.jei.gui.elements.DrawableBuilder; import mezz.jei.gui.elements.DrawableIngredient; import mezz.jei.gui.elements.DrawableNineSliceTexture; -import mezz.jei.gui.textures.JeiTextureMap; +import mezz.jei.gui.elements.DrawableSprite; import mezz.jei.gui.textures.TextureInfo; import mezz.jei.gui.textures.Textures; import mezz.jei.util.ErrorUtil; @@ -49,28 +48,22 @@ public class GuiHelper implements IGuiHelper { public GuiHelper(IIngredientRegistry ingredientRegistry, Textures textures) { this.ingredientRegistry = ingredientRegistry; this.slotDrawable = createDrawable(textures.slot); - this.nineSliceSlot = createNineSliceDrawable(textures.slot, 4, 4, 4, 4); + this.nineSliceSlot = createNineSliceDrawable(textures.slot); this.tabSelected = createDrawable(textures.tabSelected); this.tabUnselected = createDrawable(textures.tabUnselected); - this.buttonDisabled = createNineSliceDrawable(textures.buttonDisabled, 2, 2, 2, 2); - this.buttonEnabled = createNineSliceDrawable(textures.buttonEnabled, 2, 2, 2, 2); - this.buttonHighlight = createNineSliceDrawable(textures.buttonHighlight, 2, 2, 2, 2); - this.guiBackground = createNineSliceDrawable(textures.guiBackground, 16, 16, 16, 16); - this.recipeBackground = createNineSliceDrawable(textures.recipeBackground, 16, 16, 16, 16); - this.searchBackground = createNineSliceDrawable(textures.searchBackground, 4, 4, 4, 4); - this.catalystTab = createNineSliceDrawable(textures.catalystTab, 8, 9, 8, 8); - - this.shapelessIcon = drawableBuilder(textures.shapelessIcon) - .trim(1, 2, 1, 1) - .build(); - this.arrowPrevious = drawableBuilder(textures.arrowPrevious) - .trim(0, 0, 1, 1) - .build(); - this.arrowNext = drawableBuilder(textures.arrowNext) - .trim(0, 0, 1, 1) - .build(); + this.buttonDisabled = createNineSliceDrawable(textures.buttonDisabled); + this.buttonEnabled = createNineSliceDrawable(textures.buttonEnabled); + this.buttonHighlight = createNineSliceDrawable(textures.buttonHighlight); + this.guiBackground = createNineSliceDrawable(textures.guiBackground); + this.recipeBackground = createNineSliceDrawable(textures.recipeBackground); + this.searchBackground = createNineSliceDrawable(textures.searchBackground); + this.catalystTab = createNineSliceDrawable(textures.catalystTab); + + this.shapelessIcon = createDrawable(textures.shapelessIcon); + this.arrowPrevious = createDrawable(textures.arrowPrevious); + this.arrowNext = createDrawable(textures.arrowNext); this.recipeTransfer = createDrawable(textures.recipeTransfer); this.configButtonIcon = createDrawable(textures.configButtonIcon); @@ -121,22 +114,11 @@ public ITickTimer createTickTimer(int ticksPerCycle, int maxValue, boolean count } private IDrawableStatic createDrawable(TextureInfo textureInfo) { - return drawableBuilder(textureInfo).build(); + return new DrawableSprite(textureInfo); } - private DrawableNineSliceTexture createNineSliceDrawable(TextureInfo textureInfo, int leftWidth, int rightWidth, int topHeight, int bottomHeight) { - JeiTextureMap textureMap = textureInfo.getTextureMap(); - TextureAtlasSprite sprite = textureInfo.getSprite(); - int scale = textureInfo.getScale(); - return new DrawableNineSliceTexture(textureMap.getLocation(), sprite.getOriginX() / scale, sprite.getOriginY() / scale, sprite.getIconWidth() / scale, sprite.getIconHeight() / scale, leftWidth, rightWidth, topHeight, bottomHeight, textureMap.getWidth() / scale, textureMap.getHeight() / scale); - } - - private IDrawableBuilder drawableBuilder(TextureInfo textureInfo) { - JeiTextureMap textureMap = textureInfo.getTextureMap(); - TextureAtlasSprite sprite = textureInfo.getSprite(); - int scale = textureInfo.getScale(); - return drawableBuilder(textureMap.getLocation(), sprite.getOriginX() / scale, sprite.getOriginY() / scale, sprite.getIconWidth() / scale, sprite.getIconHeight() / scale) - .setTextureSize(textureMap.getWidth() / scale, textureMap.getHeight() / scale); + private DrawableNineSliceTexture createNineSliceDrawable(TextureInfo textureInfo) { + return new DrawableNineSliceTexture(textureInfo); } public IDrawableStatic getTabSelected() { diff --git a/src/main/java/mezz/jei/gui/elements/DrawableNineSliceTexture.java b/src/main/java/mezz/jei/gui/elements/DrawableNineSliceTexture.java index f8488ced9..22b8d82a4 100644 --- a/src/main/java/mezz/jei/gui/elements/DrawableNineSliceTexture.java +++ b/src/main/java/mezz/jei/gui/elements/DrawableNineSliceTexture.java @@ -3,116 +3,96 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; +import mezz.jei.gui.textures.TextureInfo; + /** * Breaks a texture into 9 pieces so that it can be scaled to any size. * Draws the corners and then repeats any middle textures to fill the remaining area. */ public class DrawableNineSliceTexture { - private final ResourceLocation resourceLocation; - private final int u; - private final int v; - private final int width; - private final int height; - private final int leftWidth; - private final int rightWidth; - private final int topHeight; - private final int bottomHeight; - private final int textureWidth; - private final int textureHeight; - - public DrawableNineSliceTexture(ResourceLocation resourceLocation, int u, int v, int width, int height, int leftWidth, int rightWidth, int topHeight, int bottomHeight, int textureWidth, int textureHeight) { - this.resourceLocation = resourceLocation; - this.u = u; - this.v = v; - this.width = width; - this.height = height; - this.leftWidth = leftWidth; - this.rightWidth = rightWidth; - this.topHeight = topHeight; - this.bottomHeight = bottomHeight; - this.textureWidth = textureWidth; - this.textureHeight = textureHeight; + private final TextureInfo info; + + public DrawableNineSliceTexture(TextureInfo info) { + this.info = info; } public void draw(Minecraft minecraft, int xOffset, int yOffset, int width, int height) { + ResourceLocation location = info.getLocation(); + TextureAtlasSprite sprite = info.getSprite(); + int leftWidth = info.getSliceLeft(); + int rightWidth = info.getSliceRight(); + int topHeight = info.getSliceTop(); + int bottomHeight = info.getSliceBottom(); + int textureWidth = info.getWidth(); + int textureHeight = info.getHeight(); + TextureManager textureManager = minecraft.getTextureManager(); - textureManager.bindTexture(resourceLocation); + textureManager.bindTexture(location); + + float uMin = sprite.getMinU(); + float uMax = sprite.getMaxU(); + float vMin = sprite.getMinV(); + float vMax = sprite.getMaxV(); + float uSize = uMax - uMin; + float vSize = vMax - vMin; - final int uMiddle = u + leftWidth; - final int uRight = u + this.width - rightWidth; - final int vMiddle = v + topHeight; - final int vBottom = v + this.height - bottomHeight; - final int middleWidth = uRight - uMiddle; - final int middleHeight = vBottom - vMiddle; + float uLeft = uMin + uSize * (leftWidth / (float) textureWidth); + float uRight = uMax - uSize * (rightWidth / (float) textureWidth); + float vTop = vMin + vSize * (topHeight / (float) textureHeight); + float vBottom = vMax - vSize * (bottomHeight / (float) textureHeight); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX); // left top - draw(bufferBuilder, u, v, leftWidth, topHeight, xOffset, yOffset); + draw(bufferBuilder, uMin, vMin, uLeft, vTop, xOffset, yOffset, leftWidth, topHeight); // left bottom - draw(bufferBuilder, u, vBottom, leftWidth, bottomHeight, xOffset, yOffset + height - bottomHeight); + draw(bufferBuilder, uMin, vBottom, uLeft, vMax, xOffset, yOffset + height - bottomHeight, leftWidth, bottomHeight); // right top - draw(bufferBuilder, uRight, v, rightWidth, topHeight, xOffset + width - rightWidth, yOffset); + draw(bufferBuilder, uRight, vMin, uMax, vTop, xOffset + width - rightWidth, yOffset, rightWidth, topHeight); // right bottom - draw(bufferBuilder, uRight, vBottom, rightWidth, bottomHeight, xOffset + width - rightWidth, yOffset + height - bottomHeight); + draw(bufferBuilder, uRight, vBottom, uMax, vMax, xOffset + width - rightWidth, yOffset + height - bottomHeight, rightWidth, bottomHeight); - final int tiledMiddleWidth = width - leftWidth - rightWidth; - final int tiledMiddleHeight = height - topHeight - bottomHeight; + int middleWidth = textureWidth - leftWidth - rightWidth; + int middleHeight = textureWidth - topHeight - bottomHeight; + int tiledMiddleWidth = width - leftWidth - rightWidth; + int tiledMiddleHeight = height - topHeight - bottomHeight; if (tiledMiddleWidth > 0) { // top edge - drawTiled(bufferBuilder, uMiddle, v, middleWidth, topHeight, xOffset + leftWidth, yOffset, tiledMiddleWidth, topHeight); + drawTiled(bufferBuilder, uLeft, vMin, uRight, vTop, xOffset + leftWidth, yOffset, tiledMiddleWidth, topHeight, middleWidth, topHeight); // bottom edge - drawTiled(bufferBuilder, uMiddle, vBottom, middleWidth, bottomHeight, xOffset + leftWidth, yOffset + height - bottomHeight, tiledMiddleWidth, bottomHeight); + drawTiled(bufferBuilder, uLeft, vBottom, uRight, vMax, xOffset + leftWidth, yOffset + height - bottomHeight, tiledMiddleWidth, bottomHeight, middleWidth, bottomHeight); } if (tiledMiddleHeight > 0) { // left side - drawTiled(bufferBuilder, u, vMiddle, leftWidth, middleHeight, xOffset, yOffset + topHeight, leftWidth, tiledMiddleHeight); + drawTiled(bufferBuilder, uMin, vTop, uLeft, vBottom, xOffset, yOffset + topHeight, leftWidth, tiledMiddleHeight, leftWidth, middleHeight); // right side - drawTiled(bufferBuilder, uRight, vMiddle, rightWidth, middleHeight, xOffset + width - rightWidth, yOffset + topHeight, rightWidth, tiledMiddleHeight); + drawTiled(bufferBuilder, uRight, vTop, uMax, vBottom, xOffset + width - rightWidth, yOffset + topHeight, rightWidth, tiledMiddleHeight, rightWidth, middleHeight); } if (tiledMiddleHeight > 0 && tiledMiddleWidth > 0) { // middle area - drawTiled(bufferBuilder, uMiddle, vMiddle, middleWidth, middleHeight, xOffset + leftWidth, yOffset + topHeight, tiledMiddleWidth, tiledMiddleHeight); + drawTiled(bufferBuilder, uLeft, vTop, uRight, vBottom, xOffset + leftWidth, yOffset + topHeight, tiledMiddleWidth, tiledMiddleHeight, middleWidth, middleHeight); } tessellator.draw(); } - private void draw(BufferBuilder bufferBuilder, int u, int v, int width, int height, int xOffset, int yOffset) { - double widthScale = 1.0 / textureWidth; - double heightScale = 1.0 / textureHeight; - double u1 = u * widthScale; - double v1 = (v + height) * heightScale; - double u2 = (u + width) * widthScale; - double v2 = v * heightScale; - - bufferBuilder.pos(xOffset, yOffset + height, 0) - .tex(u1, v1) - .endVertex(); - bufferBuilder.pos(xOffset + width, yOffset + height, 0) - .tex(u2, v1) - .endVertex(); - bufferBuilder.pos(xOffset + width, yOffset, 0) - .tex(u2, v2) - .endVertex(); - bufferBuilder.pos(xOffset, yOffset, 0) - .tex(u1, v2) - .endVertex(); - } + private void drawTiled(BufferBuilder bufferBuilder, float uMin, float vMin, float uMax, float vMax, int xOffset, int yOffset, int tiledWidth, int tiledHeight, int width, int height) { + int xTileCount = tiledWidth / width; + int xRemainder = tiledWidth - (xTileCount * width); + int yTileCount = tiledHeight / height; + int yRemainder = tiledHeight - (yTileCount * height); - private void drawTiled(BufferBuilder bufferBuilder, int u, int v, int width, int height, int xOffset, int yOffset, int tiledWidth, int tiledHeight) { - final int xTileCount = tiledWidth / width; - final int xRemainder = tiledWidth - (xTileCount * width); - final int yTileCount = tiledHeight / height; - final int yRemainder = tiledHeight - (yTileCount * height); + int yStart = yOffset + tiledHeight; - final int yStart = yOffset + tiledHeight; + float uSize = uMax - uMin; + float vSize = vMax - vMin; for (int xTile = 0; xTile <= xTileCount; xTile++) { for (int yTile = 0; yTile <= yTileCount; yTile++) { @@ -121,11 +101,29 @@ private void drawTiled(BufferBuilder bufferBuilder, int u, int v, int width, int int x = xOffset + (xTile * width); int y = yStart - ((yTile + 1) * height); if (tileWidth > 0 && tileHeight > 0) { - int maskTop = height - tileHeight; int maskRight = width - tileWidth; - draw(bufferBuilder, u, v + maskTop, width - maskRight, height - maskTop, x, y + maskTop); + int maskTop = height - tileHeight; + float uOffset = (maskRight / (float) width) * uSize; + float vOffset = (maskTop / (float) height) * vSize; + + draw(bufferBuilder, uMin, vMin + vOffset, uMax - uOffset, vMax, x, y + maskTop, tileWidth, tileHeight); } } } } + + private static void draw(BufferBuilder bufferBuilder, float minU, double minV, float maxU, float maxV, int xOffset, int yOffset, int width, int height) { + bufferBuilder.pos(xOffset, yOffset + height, 0) + .tex(minU, maxV) + .endVertex(); + bufferBuilder.pos(xOffset + width, yOffset + height, 0) + .tex(maxU, maxV) + .endVertex(); + bufferBuilder.pos(xOffset + width, yOffset, 0) + .tex(maxU, minV) + .endVertex(); + bufferBuilder.pos(xOffset, yOffset, 0) + .tex(minU, minV) + .endVertex(); + } } diff --git a/src/main/java/mezz/jei/gui/elements/DrawableSprite.java b/src/main/java/mezz/jei/gui/elements/DrawableSprite.java new file mode 100644 index 000000000..5d72ea26e --- /dev/null +++ b/src/main/java/mezz/jei/gui/elements/DrawableSprite.java @@ -0,0 +1,80 @@ +package mezz.jei.gui.elements; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.ResourceLocation; + +import mezz.jei.api.gui.IDrawableStatic; +import mezz.jei.gui.textures.TextureInfo; + +public class DrawableSprite implements IDrawableStatic { + private final TextureInfo info; + + public DrawableSprite(TextureInfo info) { + this.info = info; + } + + @Override + public int getWidth() { + return info.getWidth(); + } + + @Override + public int getHeight() { + return info.getHeight(); + } + + @Override + public void draw(Minecraft minecraft, int xOffset, int yOffset) { + draw(minecraft, xOffset, yOffset, 0, 0, 0, 0); + } + + @Override + public void draw(Minecraft minecraft, int xOffset, int yOffset, int maskTop, int maskBottom, int maskLeft, int maskRight) { + ResourceLocation location = info.getLocation(); + TextureAtlasSprite sprite = info.getSprite(); + int textureWidth = info.getWidth(); + int textureHeight = info.getHeight(); + + TextureManager textureManager = minecraft.getTextureManager(); + textureManager.bindTexture(location); + + maskTop += info.getTrimTop(); + maskBottom += info.getTrimBottom(); + maskLeft += info.getTrimLeft(); + maskRight += info.getTrimRight(); + + int x = xOffset + maskLeft; + int y = yOffset + maskTop; + int width = textureWidth - maskRight - maskLeft; + int height = textureHeight - maskBottom - maskTop; + float uSize = sprite.getMaxU() - sprite.getMinU(); + float vSize = sprite.getMaxV() - sprite.getMinV(); + + float minU = sprite.getMinU() + uSize * (maskLeft / (float) textureWidth); + float minV = sprite.getMinV() + vSize * (maskTop / (float) textureHeight); + float maxU = sprite.getMaxU() - uSize * (maskRight / (float) textureWidth); + float maxV = sprite.getMaxV() - vSize * (maskBottom / (float) textureHeight); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferBuilder = tessellator.getBuffer(); + bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX); + bufferBuilder.pos(x, y + height, 0) + .tex(minU, maxV) + .endVertex(); + bufferBuilder.pos(x + width, y + height, 0) + .tex(maxU, maxV) + .endVertex(); + bufferBuilder.pos(x + width, y, 0) + .tex(maxU, minV) + .endVertex(); + bufferBuilder.pos(x, y, 0) + .tex(minU, minV) + .endVertex(); + tessellator.draw(); + } +} diff --git a/src/main/java/mezz/jei/gui/textures/JeiTextureMap.java b/src/main/java/mezz/jei/gui/textures/JeiTextureMap.java index 681d566b7..8ed5e17bf 100644 --- a/src/main/java/mezz/jei/gui/textures/JeiTextureMap.java +++ b/src/main/java/mezz/jei/gui/textures/JeiTextureMap.java @@ -1,35 +1,16 @@ package mezz.jei.gui.textures; -import java.io.IOException; -import java.util.Map; - -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 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.util.ReportedException; import net.minecraft.util.ResourceLocation; -import com.google.common.collect.Maps; import mezz.jei.config.Constants; -import mezz.jei.util.Log; -import org.apache.commons.io.IOUtils; @SideOnly(Side.CLIENT) public class JeiTextureMap extends TextureMap { private final ResourceLocation location; - private int width; - private int height; public JeiTextureMap(String basePathIn) { super(basePathIn, null, true); @@ -46,146 +27,4 @@ public void loadTexture(IResourceManager resourceManager) { this.deleteGlTexture(); this.loadTextureAtlas(resourceManager); } - - @Override - public void loadTextureAtlas(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", this.mapRegisteredSprites.size()); - - for (Map.Entry entry : this.mapRegisteredSprites.entrySet()) { - TextureAtlasSprite textureatlassprite = entry.getValue(); - ResourceLocation resourcelocation = this.getResourceLocation(textureatlassprite); - bar.step(resourcelocation.getPath()); - IResource iresource = null; - - if (textureatlassprite.hasCustomLoader(resourceManager, resourcelocation)) { - if (textureatlassprite.load(resourceManager, resourcelocation, l -> mapRegisteredSprites.get(l.toString()))) { - 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); - bar = ProgressManager.push("Texture creation", 2); - - bar.step("Stitching"); - stitcher.doStitch(); - - Log.get().info("Created: {}x{} {}-atlas", stitcher.getCurrentWidth(), stitcher.getCurrentHeight(), this.basePath); - this.width = stitcher.getCurrentWidth(); - this.height = stitcher.getCurrentHeight(); - 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.get().error("Unable to parse metadata from {}", resourcelocation, runtimeexception); - flag = false; - } catch (IOException ioexception) { - Log.get().error("Using missing texture, unable to load {}", resourcelocation, ioexception); - flag = false; - return flag; - } finally { - IOUtils.closeQuietly(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.addDetail("Sprite name", texture::getIconName); - crashreportcategory.addDetail("Sprite size", () -> texture.getIconWidth() + " x " + texture.getIconHeight()); - crashreportcategory.addDetail("Sprite frames", () -> 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.getNamespace(), String.format("%s/%s%s", this.basePath, resourcelocation.getPath(), ".png")); - } - - public int getWidth() { - return width; - } - - public int getHeight() { - return height; - } } diff --git a/src/main/java/mezz/jei/gui/textures/TextureInfo.java b/src/main/java/mezz/jei/gui/textures/TextureInfo.java index 8e9408949..e39a65dfb 100644 --- a/src/main/java/mezz/jei/gui/textures/TextureInfo.java +++ b/src/main/java/mezz/jei/gui/textures/TextureInfo.java @@ -1,38 +1,90 @@ package mezz.jei.gui.textures; import net.minecraft.client.renderer.texture.TextureAtlasSprite; - -import mezz.jei.util.Log; +import net.minecraft.util.ResourceLocation; public class TextureInfo { - private final JeiTextureMap textureMap; + private final ResourceLocation location; private final TextureAtlasSprite sprite; private final int width; private final int height; + private int sliceLeft; + private int sliceRight; + private int sliceTop; + private int sliceBottom; + private int trimLeft; + private int trimRight; + private int trimTop; + private int trimBottom; - public TextureInfo(JeiTextureMap textureMap, TextureAtlasSprite sprite, int width, int height) { - this.textureMap = textureMap; + public TextureInfo(ResourceLocation location, TextureAtlasSprite sprite, int width, int height) { + this.location = location; this.sprite = sprite; - this.width = width; this.height = height; } - public JeiTextureMap getTextureMap() { - return textureMap; + public TextureInfo slice(int left, int right, int top, int bottom) { + this.sliceLeft = left; + this.sliceRight = right; + this.sliceTop = top; + this.sliceBottom = bottom; + return this; + } + + public TextureInfo trim(int left, int right, int top, int bottom) { + this.trimLeft = sliceLeft; + this.trimRight = sliceRight; + this.trimTop = sliceTop; + this.trimBottom = sliceBottom; + return this; + } + + public ResourceLocation getLocation() { + return location; } public TextureAtlasSprite getSprite() { return sprite; } - public int getScale() { - int xScale = sprite.getIconWidth() / width; - int yScale = sprite.getIconHeight() / height; - if (xScale != yScale || xScale * width != sprite.getIconWidth() || xScale == 0) { - Log.get().error("Texture has the wrong dimensions. Expected a multiple of: ({}x{}) {}", width, height, sprite); - return 1; - } - return xScale; + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public int getSliceLeft() { + return sliceLeft; + } + + public int getSliceRight() { + return sliceRight; + } + + public int getSliceTop() { + return sliceTop; + } + + public int getSliceBottom() { + return sliceBottom; + } + + public int getTrimLeft() { + return trimLeft; + } + + public int getTrimRight() { + return trimRight; + } + + public int getTrimTop() { + return trimTop; + } + + public int getTrimBottom() { + return trimBottom; } } diff --git a/src/main/java/mezz/jei/gui/textures/Textures.java b/src/main/java/mezz/jei/gui/textures/Textures.java index 59fea68bf..936e04987 100644 --- a/src/main/java/mezz/jei/gui/textures/Textures.java +++ b/src/main/java/mezz/jei/gui/textures/Textures.java @@ -33,20 +33,31 @@ public class Textures { public Textures(JeiTextureMap textureMap) { this.textureMap = textureMap; - this.slot = registerGuiSprite("slot", 18, 18); + this.slot = registerGuiSprite("slot", 18, 18) + .slice(4, 4, 4, 4); this.tabSelected = registerGuiSprite("tab_selected", 24, 24); this.tabUnselected = registerGuiSprite("tab_unselected", 24, 24); - this.buttonDisabled = registerGuiSprite("button_disabled", 20, 20); - this.buttonEnabled = registerGuiSprite("button_enabled", 20, 20); - this.buttonHighlight = registerGuiSprite("button_highlight", 20, 20); - this.guiBackground = registerGuiSprite("gui_background", 64, 64); - this.recipeBackground = registerGuiSprite("recipe_background", 64, 64); - this.searchBackground = registerGuiSprite("search_background", 20, 20); - this.catalystTab = registerGuiSprite("catalyst_tab", 28, 28); + this.buttonDisabled = registerGuiSprite("button_disabled", 20, 20) + .slice(2, 2, 2, 2); + this.buttonEnabled = registerGuiSprite("button_enabled", 20, 20) + .slice(2, 2, 2, 2); + this.buttonHighlight = registerGuiSprite("button_highlight", 20, 20) + .slice(2, 2, 2, 2); + this.guiBackground = registerGuiSprite("gui_background", 64, 64) + .slice(16, 16, 16, 16); + this.recipeBackground = registerGuiSprite("recipe_background", 64, 64) + .slice(16, 16, 16, 16); + this.searchBackground = registerGuiSprite("search_background", 20, 20) + .slice(4, 4, 4, 4); + this.catalystTab = registerGuiSprite("catalyst_tab", 28, 28) + .slice(8, 9, 8, 8); - this.shapelessIcon = registerGuiSprite("icons/shapeless_icon", 36, 36); - this.arrowPrevious = registerGuiSprite("icons/arrow_previous", 9, 9); - this.arrowNext = registerGuiSprite("icons/arrow_next", 9, 9); + this.shapelessIcon = registerGuiSprite("icons/shapeless_icon", 36, 36) + .trim(1, 2, 1, 1); + this.arrowPrevious = registerGuiSprite("icons/arrow_previous", 9, 9) + .trim(0, 0, 1, 1); + this.arrowNext = registerGuiSprite("icons/arrow_next", 9, 9) + .trim(0, 0, 1, 1); this.recipeTransfer = registerGuiSprite("icons/recipe_transfer", 7, 7); this.configButtonIcon = registerGuiSprite("icons/config_button", 16, 16); this.configButtonCheatIcon = registerGuiSprite("icons/config_button_cheat", 16, 16); @@ -58,10 +69,7 @@ public Textures(JeiTextureMap textureMap) { private TextureInfo registerGuiSprite(String name, int width, int height) { TextureAtlasSprite textureAtlasSprite = textureMap.registerSprite(new ResourceLocation(Constants.MOD_ID, "gui/" + name)); - return new TextureInfo(textureMap, textureAtlasSprite, width, height); - } - - public JeiTextureMap getTextureMap() { - return textureMap; + ResourceLocation location = textureMap.getLocation(); + return new TextureInfo(location, textureAtlasSprite, width, height); } } diff --git a/src/main/resources/jei_at.cfg b/src/main/resources/jei_at.cfg index 1ce8651ba..6b09235a6 100644 --- a/src/main/resources/jei_at.cfg +++ b/src/main/resources/jei_at.cfg @@ -3,11 +3,6 @@ public net.minecraft.client.renderer.RenderItem func_191965_a(Lnet/minecraft/cli public net.minecraft.client.renderer.RenderItem func_191961_a(Lnet/minecraft/client/renderer/block/model/IBakedModel;Lnet/minecraft/item/ItemStack;)V # renderModel #TextureMap -protected net.minecraft.client.renderer.texture.TextureMap field_94252_e # mapUploadedSprites -protected net.minecraft.client.renderer.texture.TextureMap field_94258_i # listAnimatedSprites -protected net.minecraft.client.renderer.texture.TextureMap field_94249_f # missingImage -protected net.minecraft.client.renderer.texture.TextureMap field_94254_c # basePath -protected net.minecraft.client.renderer.texture.TextureMap field_110574_e # mapRegisteredSprites protected net.minecraft.client.renderer.texture.TextureMap func_110569_e()V # initMissingImage #GuiRecipeBook