use of net.minecraft.client.resources.data.AnimationFrame in project Charset by CharsetMC.
the class TextureAtlasSpriteCustom method addFrameTextureData.
protected void addFrameTextureData(int width, int height, int[] pixels, @Nullable IResource resource) {
AnimationMetadataSection section = resource != null ? resource.getMetadata("animation") : null;
this.clearFramesTextureData();
if (section == null) {
this.setIconWidth(width);
this.setIconHeight(height);
int[][] pixelsCtr = new int[Minecraft.getMinecraft().getTextureMapBlocks().getMipmapLevels() + 1][];
pixelsCtr[0] = pixels;
framesTextureData.add(pixelsCtr);
} else {
this.setIconWidth(width);
this.setIconHeight(width);
int i = height / width;
if (section.getFrameCount() > 0) {
for (Integer index : section.getFrameIndexSet()) {
if (index >= i) {
throw new RuntimeException("invalid frameindex " + index);
}
while (framesTextureData.size() < index) {
framesTextureData.add(null);
}
int[] data = new int[width * width];
int[][] container = new int[Minecraft.getMinecraft().getTextureMapBlocks().getMipmapLevels() + 1][];
System.arraycopy(pixels, width * width * index, data, 0, width * width);
container[0] = data;
framesTextureData.set(index, container);
}
} else {
List<AnimationFrame> frames = new ArrayList<>(i);
for (int index = 0; index < i; index++) {
int[] data = new int[width * width];
int[][] container = new int[Minecraft.getMinecraft().getTextureMapBlocks().getMipmapLevels() + 1][];
System.arraycopy(pixels, width * width * index, data, 0, width * width);
container[0] = data;
framesTextureData.add(container);
frames.add(new AnimationFrame(index, -1));
}
section = new AnimationMetadataSection(frames, width, height, section.getFrameTime(), section.isInterpolate());
}
try {
ANIMATION_METADATA_SETTER.invokeExact((TextureAtlasSprite) this, section);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
use of net.minecraft.client.resources.data.AnimationFrame in project UtilityClient2 by Utility-Client.
the class TextureAtlasSprite method loadSprite.
public void loadSprite(BufferedImage[] images, AnimationMetadataSection meta) throws IOException {
this.resetSprite();
int i = images[0].getWidth();
int j = images[0].getHeight();
this.width = i;
this.height = j;
int[][] aint = new int[images.length][];
for (int k = 0; k < images.length; ++k) {
BufferedImage bufferedimage = images[k];
if (bufferedimage != null) {
if (k > 0 && (bufferedimage.getWidth() != i >> k || bufferedimage.getHeight() != j >> k)) {
throw new RuntimeException(String.format("Unable to load miplevel: %d, image is size: %dx%d, expected %dx%d", new Object[] { Integer.valueOf(k), Integer.valueOf(bufferedimage.getWidth()), Integer.valueOf(bufferedimage.getHeight()), Integer.valueOf(i >> k), Integer.valueOf(j >> k) }));
}
aint[k] = new int[bufferedimage.getWidth() * bufferedimage.getHeight()];
bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), aint[k], 0, bufferedimage.getWidth());
}
}
if (meta == null) {
if (j != i) {
throw new RuntimeException("broken aspect ratio and not an animation");
}
this.framesTextureData.add(aint);
} else {
int j1 = j / i;
int k1 = i;
int l = i;
this.height = this.width;
if (meta.getFrameCount() > 0) {
Iterator iterator = meta.getFrameIndexSet().iterator();
while (iterator.hasNext()) {
int i1 = ((Integer) iterator.next()).intValue();
if (i1 >= j1) {
throw new RuntimeException("invalid frameindex " + i1);
}
this.allocateFrameTextureData(i1);
this.framesTextureData.set(i1, getFrameTextureData(aint, k1, l, i1));
}
this.animationMetadata = meta;
} else {
List<AnimationFrame> list = Lists.<AnimationFrame>newArrayList();
for (int l1 = 0; l1 < j1; ++l1) {
this.framesTextureData.add(getFrameTextureData(aint, k1, l, l1));
list.add(new AnimationFrame(l1, -1));
}
this.animationMetadata = new AnimationMetadataSection(list, this.width, this.height, meta.getFrameTime(), meta.isInterpolate());
}
}
}
Aggregations