Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

My block has a json model and a tesr. In the TESR I am rendering some small stuff that could change frequently like the energy storage level of the block. To do that I am using the Tesselator and the VertexBuffer but the textures don't seem to be rendered. I already checked that the TextureAtlasSprites I am using are the ones they should be and also that the TESR is even called. This is what I tried:

package XFactHD.thermalreactors.client.render.tesr;

import XFactHD.thermalreactors.client.utils.ClientEventHandler;
import XFactHD.thermalreactors.common.blocks.machine.misc.TileEntityEnergyCellPlutonium;
import XFactHD.thermalreactors.common.utils.LogHelper;
import XFactHD.thermalreactors.common.utils.Reference;
import XFactHD.thermalreactors.common.utils.Utils;
import XFactHD.thermalreactors.common.utils.property.PropertyHolder;
import XFactHD.thermalreactors.common.utils.property.enums.ConnectionStatus;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.property.IExtendedBlockState;
import org.lwjgl.opengl.GL11;

import java.util.HashMap;

@SuppressWarnings("unchecked")
public class TileEntityEnergyCellPlutoniumRenderer extends TileEntitySpecialRenderer<TileEntityEnergyCellPlutonium>
{
    @Override
    public void renderTileEntityAt(TileEntityEnergyCellPlutonium te, double x, double y, double z, float partialTicks, int destroyStage)
    {
        EnumFacing facing = te.getWorld().getBlockState(te.getPos()).getValue(PropertyHolder.ORIENTATION_CARDINAL);
        int chargeLevel = 8 * (te.getEnergyStored(null) / te.getMaxEnergyStored(null));
        HashMap<EnumFacing, ConnectionStatus> sideAccess = ((IExtendedBlockState)te.getWorld().getBlockState(te.getPos()).getBlock().getExtendedState(te.getWorld().getBlockState(te.getPos()), te.getWorld(), te.getPos())).getValue(PropertyHolder.CONNECTION_STATUS);

        GlStateManager.pushMatrix();
        GlStateManager.translate(x, y, z);

        Tessellator tess = Tessellator.getInstance();
        VertexBuffer buffer = tess.getBuffer();

        //Connection Status
        //NORTH
        TextureAtlasSprite spriteNorth = sideAccess.get(EnumFacing.NORTH).getTexture();
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        buffer.pos(0, 1, 0).tex(spriteNorth.getInterpolatedU(1), spriteNorth.getInterpolatedV(1)).endVertex();
        buffer.pos(1, 1, 0).tex(spriteNorth.getInterpolatedU(1), spriteNorth.getInterpolatedV(0)).endVertex();
        buffer.pos(1, 0, 0).tex(spriteNorth.getInterpolatedU(0), spriteNorth.getInterpolatedV(0)).endVertex();
        buffer.pos(0, 0, 0).tex(spriteNorth.getInterpolatedU(0), spriteNorth.getInterpolatedV(1)).endVertex();
        tess.draw();

        //EAST
        TextureAtlasSprite spriteEast = sideAccess.get(EnumFacing.NORTH).getTexture();
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        buffer.pos(1, 0, 0).tex(spriteEast.getInterpolatedU(1), spriteEast.getInterpolatedV(1)).endVertex();
        buffer.pos(1, 1, 0).tex(spriteEast.getInterpolatedU(1), spriteEast.getInterpolatedV(0)).endVertex();
        buffer.pos(1, 1, 1).tex(spriteEast.getInterpolatedU(0), spriteEast.getInterpolatedV(0)).endVertex();
        buffer.pos(1, 0, 1).tex(spriteEast.getInterpolatedU(0), spriteEast.getInterpolatedV(1)).endVertex();
        tess.draw();

        //SOUTH
        TextureAtlasSprite spriteSouth = sideAccess.get(EnumFacing.NORTH).getTexture();
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        buffer.pos(0, 0, 1).tex(spriteSouth.getInterpolatedU(1), spriteSouth.getInterpolatedV(1)).endVertex();
        buffer.pos(1, 0, 1).tex(spriteSouth.getInterpolatedU(1), spriteSouth.getInterpolatedV(0)).endVertex();
        buffer.pos(1, 1, 1).tex(spriteSouth.getInterpolatedU(0), spriteSouth.getInterpolatedV(0)).endVertex();
        buffer.pos(0, 1, 1).tex(spriteSouth.getInterpolatedU(0), spriteSouth.getInterpolatedV(1)).endVertex();
        tess.draw();

        //WEST
        TextureAtlasSprite spriteWest = sideAccess.get(EnumFacing.NORTH).getTexture();
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        buffer.pos(0, 0, 1).tex(spriteWest.getInterpolatedU(1), spriteWest.getInterpolatedV(1)).endVertex();
        buffer.pos(0, 1, 1).tex(spriteWest.getInterpolatedU(1), spriteWest.getInterpolatedV(0)).endVertex();
        buffer.pos(0, 1, 0).tex(spriteWest.getInterpolatedU(0), spriteWest.getInterpolatedV(0)).endVertex();
        buffer.pos(0, 0, 0).tex(spriteWest.getInterpolatedU(0), spriteWest.getInterpolatedV(1)).endVertex();
        tess.draw();

        //UP
        TextureAtlasSprite spriteUp = sideAccess.get(EnumFacing.NORTH).getTexture();
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        buffer.pos(1, 1, 1).tex(spriteUp.getInterpolatedU(1), spriteUp.getInterpolatedV(1)).endVertex();
        buffer.pos(1, 1, 0).tex(spriteUp.getInterpolatedU(1), spriteUp.getInterpolatedV(0)).endVertex();
        buffer.pos(0, 1, 0).tex(spriteUp.getInterpolatedU(0), spriteUp.getInterpolatedV(0)).endVertex();
        buffer.pos(0, 1, 1).tex(spriteUp.getInterpolatedU(0), spriteUp.getInterpolatedV(1)).endVertex();
        tess.draw();

        //DOWN
        TextureAtlasSprite spriteDown = sideAccess.get(EnumFacing.NORTH).getTexture();
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        buffer.pos(0, 0, 1).tex(spriteDown.getInterpolatedU(1), spriteDown.getInterpolatedV(1)).endVertex();
        buffer.pos(0, 0, 0).tex(spriteDown.getInterpolatedU(1), spriteDown.getInterpolatedV(0)).endVertex();
        buffer.pos(1, 0, 0).tex(spriteDown.getInterpolatedU(0), spriteDown.getInterpolatedV(0)).endVertex();
        buffer.pos(1, 0, 1).tex(spriteDown.getInterpolatedU(0), spriteDown.getInterpolatedV(1)).endVertex();
        tess.draw();

        //Energy Meter
        GlStateManager.rotate(Utils.getRotationAngleFromFacingCardinal(facing), 0, 1, 0);
        TextureAtlasSprite spriteDisplay = ClientEventHandler.INSTANCE.energyLevel[chargeLevel];
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        buffer.pos(0, 1, 0).tex(spriteDisplay.getInterpolatedU(1), spriteDisplay.getInterpolatedV(1)).endVertex();
        buffer.pos(1, 1, 0).tex(spriteDisplay.getInterpolatedU(1), spriteDisplay.getInterpolatedV(0)).endVertex();
        buffer.pos(1, 0, 0).tex(spriteDisplay.getInterpolatedU(0), spriteDisplay.getInterpolatedV(0)).endVertex();
        buffer.pos(0, 0, 0).tex(spriteDisplay.getInterpolatedU(0), spriteDisplay.getInterpolatedV(1)).endVertex();
        tess.draw();

        GlStateManager.popMatrix();
    }
}

Wouldn't it be easier to use the block states file and just set the bar to a different texture/model? Though if your trying to make it dynamic then I cant be much help.

The block this is for has connection indicators on all 6 sides (like the Thermal Expansion Energy Cells) and an energy display at the front. Those things can change very often and letting the game rerender the whole chunk because of this one stupid block would be very performance intensive. That's why I am using a TESR.

I tried some completely different stuff and while doing so I found out something really strange: As soon as I drop an item somewhere where I can see the item and the block, the tesselator renders completely black surfaces onto the block. If I use GlStateManager.color(1, 1, 1, 0), which effectively removes the alpha parts of the textures, nothing is rendered.

Does anybody have an idea what the problem could be?

Yeah, makes sense ::) . Thank you.

I have now bound the texture but now the TESR doesn't render anything. I know that the TextureAtlasSprites point to the right texture as the getIconName method gives back the name I expected for the TextureAtlasSprite I should get from

sideAccess.get(EnumFacing.WHATEVER).getTexture();

and I also don't get missing texture errors for those textures

Does somebody know why nothing at all is rendered now?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.