2013-07-16 17:58:02 +10:00
|
|
|
package codechicken.lib.render;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import codechicken.lib.render.SpriteSheetManager.SpriteSheet;
|
|
|
|
|
import codechicken.lib.render.TextureUtils.IIconRegister;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
import net.minecraft.client.renderer.texture.IconRegister;
|
|
|
|
|
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.ResourceManager;
|
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public class TextureSpecial extends TextureAtlasSprite implements IIconRegister
|
|
|
|
|
{
|
|
|
|
|
//sprite sheet fields
|
|
|
|
|
private int spriteIndex;
|
|
|
|
|
private SpriteSheet spriteSheet;
|
|
|
|
|
|
|
|
|
|
//textureFX fields
|
|
|
|
|
private TextureFX textureFX;
|
|
|
|
|
|
|
|
|
|
private int blankSize = -1;
|
|
|
|
|
|
|
|
|
|
private ArrayList<TextureDataHolder> baseTextures;
|
|
|
|
|
|
|
|
|
|
private boolean selfRegister;
|
|
|
|
|
public int atlasIndex;
|
|
|
|
|
|
|
|
|
|
protected TextureSpecial(String par1)
|
|
|
|
|
{
|
|
|
|
|
super(par1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TextureSpecial addTexture(TextureDataHolder t)
|
|
|
|
|
{
|
|
|
|
|
if(baseTextures == null)
|
|
|
|
|
baseTextures = new ArrayList<TextureDataHolder>();
|
|
|
|
|
baseTextures.add(t);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TextureSpecial baseFromSheet(SpriteSheet spriteSheet, int spriteIndex)
|
|
|
|
|
{
|
|
|
|
|
this.spriteSheet = spriteSheet;
|
|
|
|
|
this.spriteIndex = spriteIndex;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TextureSpecial addTextureFX(TextureFX fx)
|
|
|
|
|
{
|
|
|
|
|
textureFX = fx;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2013-09-04 13:56:47 +10:00
|
|
|
public void initSprite(int sheetWidth, int sheetHeight, int originX, int originY, boolean rotated)
|
2013-07-16 17:58:02 +10:00
|
|
|
{
|
2013-09-04 13:56:47 +10:00
|
|
|
super.initSprite(sheetWidth, sheetHeight, originX, originY, rotated);
|
2013-07-16 17:58:02 +10:00
|
|
|
if(textureFX != null)
|
2013-09-04 13:56:47 +10:00
|
|
|
textureFX.onTextureDimensionsUpdate(width, height);
|
2013-07-16 17:58:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateAnimation()
|
|
|
|
|
{
|
|
|
|
|
if(textureFX != null)
|
|
|
|
|
{
|
|
|
|
|
textureFX.update();
|
|
|
|
|
if(textureFX.changed())
|
2013-09-04 13:56:47 +10:00
|
|
|
TextureUtil.uploadTextureSub(textureFX.imageData, width, height, originX, originY, false, false);
|
2013-07-16 17:58:02 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean load(ResourceManager manager, ResourceLocation location)
|
|
|
|
|
{
|
|
|
|
|
if(baseTextures != null)
|
|
|
|
|
{
|
|
|
|
|
for(TextureDataHolder tex : baseTextures)
|
|
|
|
|
{
|
2013-09-04 13:56:47 +10:00
|
|
|
framesTextureData.add(tex.data);
|
|
|
|
|
width = tex.width;
|
|
|
|
|
height = tex.height;
|
2013-07-16 17:58:02 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(spriteSheet != null)
|
|
|
|
|
{
|
|
|
|
|
TextureDataHolder tex = spriteSheet.createSprite(spriteIndex);
|
2013-09-04 13:56:47 +10:00
|
|
|
width = tex.width;
|
|
|
|
|
height = tex.height;
|
|
|
|
|
framesTextureData.add(tex.data);
|
2013-07-16 17:58:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(blankSize > 0)
|
|
|
|
|
{
|
2013-09-04 13:56:47 +10:00
|
|
|
width = height = blankSize;
|
|
|
|
|
framesTextureData.add(new int[blankSize*blankSize]);
|
2013-07-16 17:58:02 +10:00
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:56:47 +10:00
|
|
|
if(framesTextureData.isEmpty())
|
2013-07-16 17:58:02 +10:00
|
|
|
throw new RuntimeException("No base frame for texture: "+getIconName());
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2013-09-04 13:56:47 +10:00
|
|
|
public boolean hasAnimationMetadata()
|
2013-07-16 17:58:02 +10:00
|
|
|
{
|
2013-09-04 13:56:47 +10:00
|
|
|
return textureFX != null || super.hasAnimationMetadata();
|
2013-07-16 17:58:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2013-09-04 13:56:47 +10:00
|
|
|
public int getFrameCount()
|
2013-07-16 17:58:02 +10:00
|
|
|
{
|
|
|
|
|
if(textureFX != null)
|
|
|
|
|
return 1;
|
|
|
|
|
|
2013-09-04 13:56:47 +10:00
|
|
|
return super.getFrameCount();
|
2013-07-16 17:58:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TextureSpecial blank(int size)
|
|
|
|
|
{
|
|
|
|
|
blankSize = size;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TextureSpecial selfRegister()
|
|
|
|
|
{
|
|
|
|
|
selfRegister = true;
|
|
|
|
|
TextureUtils.addIconRegistrar(this);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void registerIcons(IconRegister register)
|
|
|
|
|
{
|
|
|
|
|
if(selfRegister)
|
|
|
|
|
((TextureMap)register).setTextureEntry(getIconName(), this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int atlasIndex()
|
|
|
|
|
{
|
|
|
|
|
return atlasIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|