2012-05-06 23:32:59 +00:00
|
|
|
/*
|
|
|
|
* The FML Forge Mod Loader suite.
|
|
|
|
* Copyright (C) 2012 cpw
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2.1 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
package net.minecraft.src;
|
|
|
|
|
|
|
|
import java.awt.Graphics2D;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.awt.image.ImageObserver;
|
|
|
|
|
2012-09-21 22:17:56 +00:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2012-05-10 22:54:25 +00:00
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
2012-05-24 08:35:37 +00:00
|
|
|
import cpw.mods.fml.client.FMLTextureFX;
|
2012-05-06 23:32:59 +00:00
|
|
|
|
|
|
|
/**
|
2012-09-21 22:17:56 +00:00
|
|
|
* A texture override for animations, it takes a vertical image of
|
2012-05-06 23:32:59 +00:00
|
|
|
* texture frames and constantly rotates them in the texture.
|
|
|
|
*/
|
2012-05-24 08:35:37 +00:00
|
|
|
public class ModTextureAnimation extends FMLTextureFX
|
2012-05-06 23:32:59 +00:00
|
|
|
{
|
|
|
|
private final int tickRate;
|
2012-05-25 05:48:15 +00:00
|
|
|
private byte[][] images;
|
2012-05-06 23:32:59 +00:00
|
|
|
private int index = 0;
|
|
|
|
private int ticks = 0;
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-05-06 23:32:59 +00:00
|
|
|
private String targetTex = null;
|
2012-05-25 05:48:15 +00:00
|
|
|
private BufferedImage imgData = null;
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-05-06 23:32:59 +00:00
|
|
|
public ModTextureAnimation(int icon, int target, BufferedImage image, int tickCount)
|
|
|
|
{
|
|
|
|
this(icon, 1, target, image, tickCount);
|
|
|
|
}
|
|
|
|
|
2012-09-21 22:17:56 +00:00
|
|
|
public ModTextureAnimation(int icon, int size, int target, BufferedImage image, int tickCount)
|
2012-05-06 23:32:59 +00:00
|
|
|
{
|
|
|
|
this(icon, size, (target == 0 ? "/terrain.png" : "/gui/items.png"), image, tickCount);
|
|
|
|
}
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-05-06 23:32:59 +00:00
|
|
|
public ModTextureAnimation(int icon, int size, String target, BufferedImage image, int tickCount)
|
|
|
|
{
|
|
|
|
super(icon);
|
2012-08-02 19:20:30 +00:00
|
|
|
RenderEngine re = FMLClientHandler.instance().getClient().field_71446_o;
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-05-06 23:32:59 +00:00
|
|
|
targetTex = target;
|
2012-08-02 19:20:30 +00:00
|
|
|
field_76849_e = size;
|
|
|
|
field_76847_f = re.func_78341_b(target);
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-05-06 23:32:59 +00:00
|
|
|
tickRate = tickCount;
|
|
|
|
ticks = tickCount;
|
2012-05-25 05:48:15 +00:00
|
|
|
imgData = image;
|
|
|
|
}
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-05-25 05:48:15 +00:00
|
|
|
@Override
|
|
|
|
public void setup()
|
|
|
|
{
|
|
|
|
super.setup();
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-05-25 05:48:15 +00:00
|
|
|
int sWidth = imgData.getWidth();
|
|
|
|
int sHeight = imgData.getHeight();
|
|
|
|
int tWidth = tileSizeBase;
|
|
|
|
int tHeight = tileSizeBase;
|
2012-09-21 22:17:56 +00:00
|
|
|
|
|
|
|
|
2012-05-06 23:32:59 +00:00
|
|
|
int frames = (int)Math.floor((double)(sHeight / sWidth));
|
|
|
|
|
|
|
|
if (frames < 1)
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException(String.format("Attempted to create a TextureAnimation with no complete frames: %dx%d", sWidth, sHeight));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
images = new byte[frames][];
|
2012-05-25 05:48:15 +00:00
|
|
|
BufferedImage image = imgData;
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-05-06 23:32:59 +00:00
|
|
|
if (sWidth != tWidth)
|
|
|
|
{
|
|
|
|
BufferedImage b = new BufferedImage(tWidth, tHeight * frames, 6);
|
|
|
|
Graphics2D g = b.createGraphics();
|
2012-05-25 05:48:15 +00:00
|
|
|
g.drawImage(imgData, 0, 0, tWidth, tHeight * frames, 0, 0, sWidth, sHeight, (ImageObserver)null);
|
2012-05-06 23:32:59 +00:00
|
|
|
g.dispose();
|
|
|
|
image = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int frame = 0; frame < frames; frame++)
|
|
|
|
{
|
2012-05-19 00:16:41 +00:00
|
|
|
int[] pixels = new int[tileSizeSquare];
|
2012-05-06 23:32:59 +00:00
|
|
|
image.getRGB(0, tHeight * frame, tWidth, tHeight, pixels, 0, tWidth);
|
2012-05-19 00:16:41 +00:00
|
|
|
images[frame] = new byte[tileSizeSquare << 2];
|
2012-05-06 23:32:59 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < pixels.length; i++)
|
|
|
|
{
|
|
|
|
int i4 = i * 4;
|
|
|
|
images[frame][i4 + 0] = (byte)(pixels[i] >> 16 & 255);
|
|
|
|
images[frame][i4 + 1] = (byte)(pixels[i] >> 8 & 255);
|
|
|
|
images[frame][i4 + 2] = (byte)(pixels[i] >> 0 & 255);
|
|
|
|
images[frame][i4 + 3] = (byte)(pixels[i] >> 24 & 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-09-17 15:46:09 +00:00
|
|
|
public void func_76846_a()
|
2012-05-06 23:32:59 +00:00
|
|
|
{
|
|
|
|
if (++ticks >= tickRate)
|
|
|
|
{
|
|
|
|
if (++index >= images.length)
|
|
|
|
{
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-02 19:20:30 +00:00
|
|
|
field_76852_a = images[index];
|
2012-05-06 23:32:59 +00:00
|
|
|
ticks = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-09-21 22:17:56 +00:00
|
|
|
|
2012-09-17 15:46:09 +00:00
|
|
|
public void func_76845_a(RenderEngine renderEngine)
|
|
|
|
{
|
|
|
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, field_76847_f);
|
|
|
|
}
|
2012-09-24 21:22:16 +00:00
|
|
|
|
|
|
|
// TODO: REMOVE THIS - just for you dan200
|
|
|
|
@Deprecated
|
|
|
|
public void func_783_a()
|
|
|
|
{
|
|
|
|
func_76846_a();
|
|
|
|
}
|
|
|
|
|
2012-05-06 23:32:59 +00:00
|
|
|
}
|