Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AnimatedImageComponent implements ICustomComponent {
- IVariable image;
- IVariable ticks_per_frame;
- IVariable texture_height;
- IVariable texture_width;
- private transient ResourceLocation animatedImage;
- private transient int xOffset;
- private transient int yOffset;
- private transient int currentFrame = 0;
- private transient int imageHeight;
- private transient int imageWidth;
- private transient int height;
- private transient int width;
- private int frames;
- @Override
- public void build(int x, int y, int page) {
- xOffset = x;
- yOffset = y;
- }
- @Override
- public void render(MatrixStack matrixStack, IComponentRenderContext context, float v, int i, int i1) {
- if (context.getTicksInBook() % ticks_per_frame.asNumber().intValue() == 0) {
- currentFrame++;
- }
- if (currentFrame >= frames) {
- currentFrame = 0;
- }
- Minecraft.getInstance().getTextureManager().bindTexture(animatedImage);
- AbstractGui.drawTexture(matrixStack, xOffset, yOffset, 0, height * currentFrame, width / 4, height / 4, imageWidth, imageHeight);
- }
- @Override
- public void onVariablesAvailable(UnaryOperator<IVariable> lookup) {
- image = lookup.apply(image);
- ticks_per_frame = lookup.apply(ticks_per_frame);
- this.animatedImage = new ResourceLocation(image.asString());
- texture_height = lookup.apply(texture_height);
- texture_width = lookup.apply(texture_width);
- imageHeight = texture_height.asNumber().intValue();
- imageWidth = texture_width.asNumber().intValue();
- height = imageWidth;
- width = imageWidth;
- this.frames = imageHeight / imageWidth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement