mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-15 09:34:53 +00:00
Initial 1.7 commit
This commit is contained in:
1 parent
34154fc011
commit
ca675b5f31
72 files changed
+2967
-3335
No files matched your search
@@ -1,150 +1,148 @@
|
||||
package codechicken.lib.render;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import codechicken.lib.render.SpriteSheetManager.SpriteSheet;
|
||||
import codechicken.lib.render.TextureUtils.IIconRegister;
|
||||
import codechicken.lib.render.TextureUtils.IIconSelfRegister;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
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.client.resources.IResourceManager;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TextureSpecial extends TextureAtlasSprite implements IIconRegister
|
||||
{
|
||||
public class TextureSpecial extends TextureAtlasSprite implements IIconSelfRegister {
|
||||
//sprite sheet fields
|
||||
private int spriteIndex;
|
||||
private SpriteSheet spriteSheet;
|
||||
|
||||
|
||||
//textureFX fields
|
||||
private TextureFX textureFX;
|
||||
|
||||
private int blankSize = -1;
|
||||
|
||||
private int blankSize = -1;
|
||||
private ArrayList<TextureDataHolder> baseTextures;
|
||||
|
||||
|
||||
private boolean selfRegister;
|
||||
public int atlasIndex;
|
||||
|
||||
protected TextureSpecial(String par1)
|
||||
{
|
||||
|
||||
protected TextureSpecial(String par1) {
|
||||
super(par1);
|
||||
}
|
||||
|
||||
public TextureSpecial addTexture(TextureDataHolder t)
|
||||
{
|
||||
if(baseTextures == null)
|
||||
|
||||
public TextureSpecial addTexture(TextureDataHolder t) {
|
||||
if (baseTextures == null)
|
||||
baseTextures = new ArrayList<TextureDataHolder>();
|
||||
baseTextures.add(t);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextureSpecial baseFromSheet(SpriteSheet spriteSheet, int spriteIndex)
|
||||
{
|
||||
|
||||
public TextureSpecial baseFromSheet(SpriteSheet spriteSheet, int spriteIndex) {
|
||||
this.spriteSheet = spriteSheet;
|
||||
this.spriteIndex = spriteIndex;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextureSpecial addTextureFX(TextureFX fx)
|
||||
{
|
||||
|
||||
public TextureSpecial addTextureFX(TextureFX fx) {
|
||||
textureFX = fx;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initSprite(int sheetWidth, int sheetHeight, int originX, int originY, boolean rotated)
|
||||
{
|
||||
public void initSprite(int sheetWidth, int sheetHeight, int originX, int originY, boolean rotated) {
|
||||
super.initSprite(sheetWidth, sheetHeight, originX, originY, rotated);
|
||||
if(textureFX != null)
|
||||
if (textureFX != null)
|
||||
textureFX.onTextureDimensionsUpdate(width, height);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateAnimation()
|
||||
{
|
||||
if(textureFX != null)
|
||||
{
|
||||
public void updateAnimation() {
|
||||
if (textureFX != null) {
|
||||
textureFX.update();
|
||||
if(textureFX.changed())
|
||||
TextureUtil.uploadTextureSub(textureFX.imageData, width, height, originX, originY, false, false);
|
||||
if (textureFX.changed())
|
||||
TextureUtil.uploadTextureSub(0, textureFX.imageData, width, height, originX, originY, false, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean load(ResourceManager manager, ResourceLocation location)
|
||||
{
|
||||
if(baseTextures != null)
|
||||
{
|
||||
for(TextureDataHolder tex : baseTextures)
|
||||
{
|
||||
framesTextureData.add(tex.data);
|
||||
public boolean hasCustomLoader(IResourceManager manager, ResourceLocation location) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addFrame(int[] data) {
|
||||
GameSettings settings = Minecraft.getMinecraft().gameSettings;
|
||||
BufferedImage[] images = new BufferedImage[settings.mipmapLevels+1];
|
||||
images[0] = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
images[0].setRGB(0, 0, width, height, data, 0, width);
|
||||
|
||||
super.loadSprite(images, null, settings.anisotropicFiltering > 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean load(IResourceManager manager, ResourceLocation location) {
|
||||
if (baseTextures != null) {
|
||||
for (TextureDataHolder tex : baseTextures) {
|
||||
width = tex.width;
|
||||
height = tex.height;
|
||||
addFrame(tex.data);
|
||||
}
|
||||
}
|
||||
|
||||
if(spriteSheet != null)
|
||||
{
|
||||
|
||||
if (spriteSheet != null) {
|
||||
TextureDataHolder tex = spriteSheet.createSprite(spriteIndex);
|
||||
width = tex.width;
|
||||
height = tex.height;
|
||||
framesTextureData.add(tex.data);
|
||||
addFrame(tex.data);
|
||||
}
|
||||
|
||||
if(blankSize > 0)
|
||||
{
|
||||
|
||||
if (blankSize > 0) {
|
||||
width = height = blankSize;
|
||||
framesTextureData.add(new int[blankSize*blankSize]);
|
||||
addFrame(new int[blankSize * blankSize]);
|
||||
}
|
||||
|
||||
if(framesTextureData.isEmpty())
|
||||
throw new RuntimeException("No base frame for texture: "+getIconName());
|
||||
|
||||
return true;
|
||||
|
||||
if (framesTextureData.isEmpty())
|
||||
throw new RuntimeException("No base frame for texture: " + getIconName());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasAnimationMetadata()
|
||||
{
|
||||
public boolean hasAnimationMetadata() {
|
||||
return textureFX != null || super.hasAnimationMetadata();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getFrameCount()
|
||||
{
|
||||
if(textureFX != null)
|
||||
public int getFrameCount() {
|
||||
if (textureFX != null)
|
||||
return 1;
|
||||
|
||||
|
||||
return super.getFrameCount();
|
||||
}
|
||||
|
||||
public TextureSpecial blank(int size)
|
||||
{
|
||||
public TextureSpecial blank(int size) {
|
||||
blankSize = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextureSpecial selfRegister()
|
||||
{
|
||||
|
||||
public TextureSpecial selfRegister() {
|
||||
selfRegister = true;
|
||||
TextureUtils.addIconRegistrar(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerIcons(IconRegister register)
|
||||
{
|
||||
if(selfRegister)
|
||||
((TextureMap)register).setTextureEntry(getIconName(), this);
|
||||
public void registerIcons(IIconRegister register) {
|
||||
if (selfRegister)
|
||||
((TextureMap) register).setTextureEntry(getIconName(), this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int atlasIndex()
|
||||
{
|
||||
public int atlasIndex() {
|
||||
return atlasIndex;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user