Jump to content

Rendering custom chest with animated texture


D4RSORC

Recommended Posts

I'm having problems with rendering my custom chest using animated texture. I'm using TESR with code from ender chest. The problem is that TileEntitySpecialRenderer#bindTexture() doesn't support animated textures. I also tried adding my texture to the TextureMap but I don't know how to use AtlasSprite in this renderer. Any help would be appreciated.

Here is my TileEntitySpecialRenderer:

Spoiler

package com.d4rsorc.ultimatestorage.tile;

import com.d4rsorc.ultimatestorage.UltimateStorage;

import net.minecraft.client.model.ModelChest;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class TESRUltimateChest extends TileEntitySpecialRenderer<TileEntityInfiniteStorage>
{
	private static final ResourceLocation ULTIMATE_CHEST_TEXTURE = new ResourceLocation(UltimateStorage.MODID + ":textures/blocks/ultimate_chest.png");
    private final ModelChest modelChest = new ModelChest();

    public void render(TileEntityInfiniteStorage te, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
    {
        int i = 0;

        if (te.hasWorld())
        {
            i = te.getBlockMetadata();
        }

        if (destroyStage >= 0)
        {
            this.bindTexture(DESTROY_STAGES[destroyStage]);
            GlStateManager.matrixMode(5890);
            GlStateManager.pushMatrix();
            GlStateManager.scale(4.0F, 4.0F, 1.0F);
            GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
            GlStateManager.matrixMode(5888);
        }
        else
        {
        	this.bindTexture(ULTIMATE_CHEST_TEXTURE);
        }
        

        GlStateManager.pushMatrix();
        
        GlStateManager.enableRescaleNormal();
        GlStateManager.color(1.0F, 1.0F, 1.0F, alpha);
        GlStateManager.translate((float)x, (float)y + 1.0F, (float)z + 1.0F);
        GlStateManager.scale(1.0F, -1.0F, -1.0F);
        GlStateManager.translate(0.5F, 0.5F, 0.5F);     
        
        int j = 0;

        if (i == 2)
        {
            j = 180;
        }

        if (i == 3)
        {
            j = 0;
        }

        if (i == 4)
        {
            j = 90;
        }

        if (i == 5)
        {
            j = -90;
        }

        GlStateManager.rotate((float)j, 0.0F, 1.0F, 0.0F);
        GlStateManager.translate(-0.5F, -0.5F, -0.5F);
        float f = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks;
        f = 1.0F - f;
        f = 1.0F - f * f * f;
        this.modelChest.chestLid.rotateAngleX = -(f * ((float)Math.PI / 2F));
        this.modelChest.renderAll();
        GlStateManager.disableRescaleNormal();
        GlStateManager.popMatrix();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

        if (destroyStage >= 0)
        {
            GlStateManager.matrixMode(5890);
            GlStateManager.popMatrix();
            GlStateManager.matrixMode(5888);
        }
    }

}

 

 

Link to comment
Share on other sites

Yea, I tried that and that's what I got:

Spoiler

2018-12-08_23_29_04.png.8c14c058f86a34070d4c66885bc17056.png2018-12-08_23_29_05.png.50b23ef3eab1759c4e9506bcc9e39725.png

If I bind the global texture map I need somehow get only the part where my texture is. The only solution I can think of rn is to split my animation into single frames and bind different texture corresponding to frame I want to render.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.