Jump to content

[1.7.10, UNSOLVED] - TileEntitySpecialRenderer - Inside-out rendering


DND91

Recommended Posts

Hello folks!

 

I gott a funny problem; https://gyazo.com/98fab1d3454ecc28e63ebce276a5ecc8

My render class renders everything reverse, if i get the rendering to turn around it will fix everything... so the code is for some reason doing everything wrong. I know it has todo something todo with the GL.glEnable and such but cannot figure out what needs to be enabaled or disableded.

 

Any clues what needs to be added?

 

package hok.chompzki.biocristals.croot.cristal;

import hok.chompzki.biocristals.registrys.ItemRegistry;

import org.lwjgl.opengl.GL11;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

public class SpeciallRenenderGhost extends TileEntitySpecialRenderer {

private static final double renderMinX = 0;
private static final double renderMaxX = 1.0D;
private static final double renderMinZ = 0;
private static final double renderMaxZ = 1.0D;
private static final double renderMinY = 0;

@Override
public void renderTileEntityAt(TileEntity tile, double x,
		double y, double z, float partialTick) {

	BlockGhost holder = (BlockGhost)tile.getBlockType();
	World world = tile.getWorldObj();

	Block target = Blocks.dirt;//holder.getBlock(world, tile.xCoord, tile.yCoord, tile.zCoord);

	if(target == null){
		tile.markDirty();
		tile.getWorldObj().markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
		return ;
	}

	EntityPlayer player = Minecraft.getMinecraft().thePlayer;

	if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() == ItemRegistry.researchBook){
		RenderBlocks renderer = new RenderBlocks(world);
		renderer.clearOverrideBlockTexture();
		renderer.setRenderBounds(0.0D, 1.0D, 0.0D, 1.0D, 0.0D, 1.0D);


		renderer.setRenderFromInside(false);
		renderer.enableAO = false;


		this.bindTexture(TextureMap.locationBlocksTexture);

		Tessellator tessellator = Tessellator.instance;

		//SOMETHING IS MISSING HERE
		GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
		GL11.glPushMatrix();
		//GL11.glEnable(GL11.GL_BLEND);
		//GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
		//GL11.glRotatef(180F, 0, 0, 0);
		GL11.glTranslated(x, y, z);




		//GL11.glColor4f(1.0f, 1.0f, 1.0f, transparancy);
		tessellator.startDrawingQuads();
	    
		int l = target.colorMultiplier(world, tile.xCoord, tile.yCoord, tile.zCoord);
        float f = (float)(l >> 16 & 255) / 255.0F;
        float f1 = (float)(l >> 8 & 255) / 255.0F;
        float f2 = (float)(l & 255) / 255.0F;
        
		renderStandardBlockWithColorMultiplier(renderer, holder, target, tile.xCoord, tile.yCoord, tile.zCoord, f, f1, f2);


		tessellator.draw();
		//GL11.glDisable(GL11.GL_BLEND);
		GL11.glPopMatrix();
		GL11.glPopAttrib();
		return;
	}
}

public boolean renderStandardBlockWithColorMultiplier(RenderBlocks renderer, BlockGhost ghost, Block target, int p_147736_2_, int p_147736_3_, int p_147736_4_, float p_147736_5_, float p_147736_6_, float p_147736_7_)
    {
        Tessellator tessellator = Tessellator.instance;
        boolean flag = false;
        float f3 = 0.5F;
        float f4 = 1.0F;
        float f5 = 0.8F;
        float f6 = 0.6F;
        float f7 = f4 * p_147736_5_;
        float f8 = f4 * p_147736_6_;
        float f9 = f4 * p_147736_7_;
        float f10 = f3;
        float f11 = f5;
        float f12 = f6;
        float f13 = f3;
        float f14 = f5;
        float f15 = f6;
        float f16 = f3;
        float f17 = f5;
        float f18 = f6;

        int l = target.getMixedBrightnessForBlock(renderer.blockAccess, p_147736_2_, p_147736_3_, p_147736_4_);
        
        float transparancy = 1.0f;
        
        if (ghost.shouldSideBeRendered(renderer.blockAccess, p_147736_2_, p_147736_3_ - 1, p_147736_4_, 0))
        {
        tessellator.setBrightness(255);
        tessellator.setColorRGBA_F(f10, f13, f16, transparancy);
        renderer.renderFaceYNeg(target, (double)0, (double)0, (double)0, renderer.getBlockIcon(target, renderer.blockAccess, p_147736_2_, p_147736_3_, p_147736_4_, 0));
    	flag = true;
        }
        
        if (ghost.shouldSideBeRendered(renderer.blockAccess, p_147736_2_, p_147736_3_ + 1, p_147736_4_, 1))
        {
        	tessellator.setBrightness(255);
        tessellator.setColorRGBA_F(f7, f8, f9, transparancy);
        renderer.renderFaceYPos(target, (double)0, (double)0, (double)0, renderer.getBlockIcon(target, renderer.blockAccess, p_147736_2_, p_147736_3_, p_147736_4_, 1));
        flag = true;
        }
        
        IIcon iicon;
        
        if (ghost.shouldSideBeRendered(renderer.blockAccess, p_147736_2_, p_147736_3_, p_147736_4_ - 1, 2))
        {
        	tessellator.setBrightness(255);
        tessellator.setColorRGBA_F(f11, f14, f17, transparancy);
        iicon = renderer.getBlockIcon(target, renderer.blockAccess, p_147736_2_, p_147736_3_, p_147736_4_, 2);
        renderer.renderFaceZNeg(target, (double)0, (double)0, (double)0, iicon);
        flag = true;
        }
        
        if (ghost.shouldSideBeRendered(renderer.blockAccess, p_147736_2_, p_147736_3_, p_147736_4_ + 1, 3))
        {
        	tessellator.setBrightness(255);
        tessellator.setColorRGBA_F(f11, f14, f17, transparancy);
        iicon = renderer.getBlockIcon(target, renderer.blockAccess, p_147736_2_, p_147736_3_, p_147736_4_, 3);
        renderer.renderFaceZPos(target, (double)0, (double)0, (double)0, iicon);
        flag = true;
        }
       
        if (ghost.shouldSideBeRendered(renderer.blockAccess, p_147736_2_ - 1, p_147736_3_, p_147736_4_, 4))
        {
        	tessellator.setBrightness(255);
        tessellator.setColorRGBA_F(f12, f15, f18, transparancy);
        iicon = renderer.getBlockIcon(target, renderer.blockAccess, p_147736_2_, p_147736_3_, p_147736_4_, 4);
        renderer.renderFaceXNeg(target, (double)0, (double)0, (double)0, iicon);
        flag = true;
        }
        
        if (ghost.shouldSideBeRendered(renderer.blockAccess, p_147736_2_ + 1, p_147736_3_, p_147736_4_, 5))
        {
        	tessellator.setBrightness(255);
        tessellator.setColorRGBA_F(f12, f15, f18, transparancy);
        iicon = renderer.getBlockIcon(target, renderer.blockAccess, p_147736_2_, p_147736_3_, p_147736_4_, 5);
        renderer.renderFaceXPos(target, (double)0, (double)0, (double)0, iicon);
        flag = true;
        }
        
        return flag;
    }

public void renderFaceYNeg(Block p_147768_1_, double p_147768_2_, double p_147768_4_, double p_147768_6_, IIcon p_147768_8_)
    {
        Tessellator tessellator = Tessellator.instance;

        double d3 = (double)p_147768_8_.getInterpolatedU(this.renderMinX * 16.0D);
        double d4 = (double)p_147768_8_.getInterpolatedU(this.renderMaxX * 16.0D);
        double d5 = (double)p_147768_8_.getInterpolatedV(this.renderMinZ * 16.0D);
        double d6 = (double)p_147768_8_.getInterpolatedV(this.renderMaxZ * 16.0D);
        

        double d7 = d4;
        double d8 = d3;
        double d9 = d5;
        double d10 = d6;
        
        double d11 = p_147768_2_ + this.renderMinX;
        double d12 = p_147768_2_ + this.renderMaxX;
        double d13 = p_147768_4_ + this.renderMinY;
        double d14 = p_147768_6_ + this.renderMinZ;
        double d15 = p_147768_6_ + this.renderMaxZ;

     
        tessellator.addVertexWithUV(d11, d13, d15, d8, d10);
        tessellator.addVertexWithUV(d11, d13, d14, d3, d5);
        tessellator.addVertexWithUV(d12, d13, d14, d7, d9);
        tessellator.addVertexWithUV(d12, d13, d15, d4, d6);
        
    }
}

Link to comment
Share on other sites

Didn't look completely through the code, but I think you could try playing with ```GL11.glCullFace()``` with parameter GL_FRONT and GL_BACK. Remember to restore that to GL_BACK as it's likely to be the standard option.

 

Also it looks like you are trying to render blocks using standard methods. Then you should probably avoid all that render code copiese, which might cause your problems and are subject to error.

 

Here is a similar piece of code in TERenderer I have written, hope that could be useful for you:

/**
* Vanilla mc block rendering pipeline caches block rendering. If you want to render some block
* that renders dynamically and wants to use the original IIcon approach, use this on your TileEntity.
*/
public class RenderDynamicBlock extends TileEntitySpecialRenderer {

public static RenderBlocks renderBlocks = RenderBlocks.getInstance();

@Override
public void renderTileEntityAt(TileEntity t, double x,
		double y, double z, float pt) {
	Block blockType = t.getBlockType();

	Tessellator tes = Tessellator.instance;
	tes.setColorOpaque_F(1.0F, 1.0F, 1.0F);

	renderBlocks.blockAccess = t.getWorldObj();

	{
		if (Minecraft.isAmbientOcclusionEnabled()) {
                GL11.glShadeModel(GL11.GL_SMOOTH);
            } else {
                GL11.glShadeModel(GL11.GL_FLAT);
            }
		RenderHelper.disableStandardItemLighting();

		RenderUtils.loadTexture(TextureMap.locationBlocksTexture);
            
		tes.startDrawingQuads();
		tes.setTranslation(x - t.xCoord, y - t.yCoord, z - t.zCoord);

		renderBlocks.renderBlockAllFaces(blockType, t.xCoord, t.yCoord, t.zCoord);
		tes.setTranslation(0, 0, 0);
		tes.draw();

		RenderHelper.enableStandardItemLighting();
	}
}

}

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm using Modrinth as a launcher for a forge modpack on 1.20.1, and can't diagnose the issue on the crash log myself. Have tried repairing the Minecraft instillation as well as removing a few mods that have been problematic for me in the past to no avail. Crash log is below, if any further information is necessary let me know. Thank you! https://paste.ee/p/k6xnS
    • Hey folks. I am working on a custom "Mecha" entity (extended from LivingEntity) that the player builds up from blocks that should get modular stats depending on the used blocks. e.g. depending on what will be used for the legs, the entity will have a different jump strength. However, something unexpected is happening when trying to override a few of LivingEntity's functions and using my new own "Mecha" specific fields: instead of their actual instance-specific value, the default value is used (0f for a float, null for an object...) This is especially strange as when executing with the same entity from a point in the code specific to the mecha entity, the correct value is used. Here are some code snippets to better illustrate what I mean: /* The main Mecha class, cut down for brevity */ public class Mecha extends LivingEntity { protected float jumpMultiplier; //somewhere later during the code when spawning the entity, jumpMultiplier is set to something like 1.5f //changing the access to public didn't help @Override //Overridden from LivingEntity, this function is only used in the jumpFromGround() function, used in the aiStep() function, used in the LivingEntity tick() function protected float getJumpPower() { //something is wrong with this function //for some reason I can't correctly access the fields and methods from the instanciated entity when I am in one of those overridden protected functions. this is very annoying LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 0f return this.jumpMultiplier * super.getJumpPower(); } //The code above does not operate properly. Written as is, the entity will not jump, and adding debug logs shows that when executing the code, the value of this.jumpMultiplier is 0f //in contrast, it will be the correct value when done here: @Override public void tick() { super.tick(); //inherited LivingEntity logic //Custom logic LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 1.5f } } My actual code is slightly different, as the jumpMuliplier is stored in another object (so I am calling "this.legModule.getJumpPower()" instead of the float), but even using a simple float exactly like in the code above didn't help. When running my usual code, the object I try to use is found to be null instead, leading to a crash from a nullPointerException. Here is the stacktrace of said crash: The full code can be viewed here. I have found a workaround in the case of jump strength, but have already found the same problem for another parameter I want to do, and I do not understand why the code is behaving as such, and I would very much like to be able to override those methods as intended - they seemed to work just fine like that for vanilla mobs... Any clues as to what may be happening here?
    • Please delete post. Had not noticed the newest edition for 1.20.6 which resolves the issue.
    • https://paste.ee/p/GTgAV Here's my debug log, I'm on 1.18.2 with forge 40.2.4 and I just want to get it to work!! I cant find any mod names in the error part and I would like some help from the pros!! I have 203 mods at the moment.
  • Topics

×
×
  • Create New...

Important Information

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