From 7667df0caf286570e26bd9ccbccfac724dae8cd7 Mon Sep 17 00:00:00 2001 From: LexManos Date: Thu, 24 May 2012 22:48:15 -0700 Subject: [PATCH] Fixed up ModTexture* classes to use the ITextureFX events to resize the image as needed. Also fixed ModTextureStatic's not being applied properly. --- .../minecraft/src/ModTextureAnimation.java | 30 +++++------ .../net/minecraft/src/ModTextureStatic.java | 50 ++++++++++--------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/fml/client/net/minecraft/src/ModTextureAnimation.java b/fml/client/net/minecraft/src/ModTextureAnimation.java index b178df1cb8..dc10509f35 100644 --- a/fml/client/net/minecraft/src/ModTextureAnimation.java +++ b/fml/client/net/minecraft/src/ModTextureAnimation.java @@ -32,11 +32,12 @@ import static org.lwjgl.opengl.GL11.*; public class ModTextureAnimation extends FMLTextureFX { private final int tickRate; - private final byte[][] images; + private byte[][] images; private int index = 0; private int ticks = 0; private String targetTex = null; + private BufferedImage imgData = null; public ModTextureAnimation(int icon, int target, BufferedImage image, int tickCount) { @@ -59,13 +60,18 @@ public class ModTextureAnimation extends FMLTextureFX tickRate = tickCount; ticks = tickCount; + imgData = image; + } + + @Override + public void setup() + { + super.setup(); - func_782_a(re); - - int sWidth = image.getWidth(); - int sHeight = image.getHeight(); - int tWidth = GL11.glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH) >> 4; - int tHeight = GL11.glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT) >> 4; + int sWidth = imgData.getWidth(); + int sHeight = imgData.getHeight(); + int tWidth = tileSizeBase; + int tHeight = tileSizeBase; int frames = (int)Math.floor((double)(sHeight / sWidth)); @@ -77,19 +83,13 @@ public class ModTextureAnimation extends FMLTextureFX else { images = new byte[frames][]; - - if (tWidth != tileSizeBase || tHeight != tileSizeBase) - { - log.warning(String.format("Animation Override %s is not applied - there is a mismatch between the underlying texture (%s) size %d,%d and the current texture tile size %d", target, tWidth, tHeight, tileSizeBase)); - errored = true; - return; - } + BufferedImage image = imgData; if (sWidth != tWidth) { BufferedImage b = new BufferedImage(tWidth, tHeight * frames, 6); Graphics2D g = b.createGraphics(); - g.drawImage(image, 0, 0, tWidth, tHeight * frames, 0, 0, sWidth, sHeight, (ImageObserver)null); + g.drawImage(imgData, 0, 0, tWidth, tHeight * frames, 0, 0, sWidth, sHeight, (ImageObserver)null); g.dispose(); image = b; } diff --git a/fml/client/net/minecraft/src/ModTextureStatic.java b/fml/client/net/minecraft/src/ModTextureStatic.java index e672402ab8..30482aa896 100644 --- a/fml/client/net/minecraft/src/ModTextureStatic.java +++ b/fml/client/net/minecraft/src/ModTextureStatic.java @@ -31,6 +31,8 @@ public class ModTextureStatic extends FMLTextureFX private int[] pixels = null; private String targetTex = null; private int storedSize; + private BufferedImage overrideData = null; + private int needApply = 2; public ModTextureStatic(int icon, int target, BufferedImage image) @@ -52,32 +54,27 @@ public class ModTextureStatic extends FMLTextureFX storedSize = size; field_1129_e = size; field_1128_f = re.func_1070_a(target); - - func_782_a(re); + overrideData = image; + } + + @Override + public void setup() + { + super.setup(); + int sWidth = overrideData.getWidth(); + int sHeight = overrideData.getHeight(); - int sWidth = image.getWidth(); - int sHeight = image.getHeight(); - int tWidth = GL11.glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH ) >> 4; - int tHeight = GL11.glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT) >> 4; - - if (tWidth != tileSizeBase || tHeight != tileSizeBase) - { - log.warning(String.format("Override is not applied - there is a mismatch between the underlying texture (%s) size %d,%d and the current texture tile size %d", target, tWidth, tHeight, tileSizeBase)); - errored=true; - return; - } pixels = new int[tileSizeSquare]; - - if (tWidth == sWidth && tHeight == sHeight) + if (tileSizeBase == sWidth && tileSizeBase == sHeight) { - image.getRGB(0, 0, sWidth, sHeight, pixels, 0, sWidth); + overrideData.getRGB(0, 0, sWidth, sHeight, pixels, 0, sWidth); } else { - BufferedImage tmp = new BufferedImage(tWidth, tHeight, 6); + BufferedImage tmp = new BufferedImage(tileSizeBase, tileSizeBase, 6); Graphics2D gfx = tmp.createGraphics(); - gfx.drawImage(image, 0, 0, tWidth, tHeight, 0, 0, sWidth, sHeight, (ImageObserver)null); - tmp.getRGB(0, 0, tWidth, tHeight, pixels, 0, tWidth); + gfx.drawImage(overrideData, 0, 0, tileSizeBase, tileSizeBase, 0, 0, sWidth, sHeight, (ImageObserver)null); + tmp.getRGB(0, 0, tileSizeBase, tileSizeBase, pixels, 0, tileSizeBase); gfx.dispose(); } @@ -86,12 +83,17 @@ public class ModTextureStatic extends FMLTextureFX public void func_783_a() { - // Force the tile size to zero: generally we only need to stamp our static image once - field_1129_e = 0; if (oldanaglyph != field_1131_c) { update(); - field_1129_e = storedSize; + } + // This makes it so we only apply the texture to the target texture when we need to, + //due to the fact that update is called when the Effect is first registered, we actually + //need to wait for the next one. + field_1129_e = (needApply == 0 ? 0 : storedSize); + if (needApply > 0) + { + needApply--; } } @@ -102,6 +104,7 @@ public class ModTextureStatic extends FMLTextureFX public void update() { + needApply = 2; for (int idx = 0; idx < pixels.length; idx++) { int i = idx * 4; @@ -169,7 +172,8 @@ public class ModTextureStatic extends FMLTextureFX @Override - public String toString() { + public String toString() + { return String.format("ModTextureStatic %s @ %d", targetTex, field_1126_b); } }