Jump to content

Recommended Posts

Posted (edited)

Hey all, first time posting. I'm having difficulty with rendering a simple cube in a tileentities TESR, I'm not great with rendering in general, so any help would be appreciated.


EDIT: I should note that I have simplified this code to be as bare bones as it can be, until I can get the cube to render correctly.

https://github.com/The-PurpleOrange/Arcanacraft/blob/master/src/main/java/com/tyhone/arcanacraft/client/render/tesr/RenderTileEntityJar.java
There's the offender

When using DefaultVertexFormats.BLOCK I get this, but with DefaultVertexFormats.POSITION I get a cube, but I cant control the rgba, and it randomly flickers and goes invisible. POSITION _COLOR does something similar to BLOCK as well
2017-12-15_17_25_52.png.970b23dd27073c1453c3b16f1c4524fe.png

 

Heres the TESR code:

public void render(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage, float alpha){
		TileEntityJar jar = (TileEntityJar) te;
		double fluidLevel = jar.getFluidLevel();
		double maxFluid = jar.getMaxFluid();
		String fluidType = jar.getFluidType();
		
		if(true){
			
			Tessellator tess = Tessellator.getInstance();
			BufferBuilder buffer = tess.getBuffer();
			
			GlStateManager.pushMatrix();

			//Render smooth stuff
		    RenderHelper.disableStandardItemLighting();
		    GlStateManager.enableBlend();
		    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

		    /*if(Minecraft.isAmbientOcclusionEnabled()) {
		      GL11.glShadeModel(GL11.GL_SMOOTH);
		    }
		    else {
		      GL11.glShadeModel(GL11.GL_FLAT);
		    }*/

		    GlStateManager.translate(x, y+1, z);
		    
			buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
			buffer.color(255, 0, 0, 255);

		    buildQuad(buffer, 0, 0, 0, 1, 1, 1, EnumFacing.DOWN);
		    buildQuad(buffer, 0, 0, 0, 1, 1, 1, EnumFacing.UP);
		    buildQuad(buffer, 0, 0, 0, 1, 1, 1, EnumFacing.NORTH);
		    buildQuad(buffer, 0, 0, 0, 1, 1, 1, EnumFacing.SOUTH);
		    buildQuad(buffer, 0, 0, 0, 1, 1, 1, EnumFacing.EAST);
		    buildQuad(buffer, 0, 0, 0, 1, 1, 1, EnumFacing.WEST);
		    
		    tess.draw();

		    GlStateManager.disableBlend();
		    GlStateManager.popMatrix();
		    RenderHelper.enableStandardItemLighting();
		}
	}

 

And here is buildQuad:

public static void buildQuad(BufferBuilder renderer, double x, double y, double z, double w, double h, double d, EnumFacing face) {

		double s = 0.1;
		double x1 = x + s;
		double x2 = x + w - s;
		double y1 = y + s;
		double y2 = y + h - s;
		double z1 = z + s;
		double z2 = z + d - s;

		switch(face) {
		case DOWN:
			renderer.pos(x1, y1, z1).endVertex();
			renderer.pos(x2, y1, z1).endVertex();
			renderer.pos(x2, y1, z2).endVertex();
			renderer.pos(x1, y1, z2).endVertex();
			break;
		case UP:
			renderer.pos(x1, y2, z1).endVertex();
			renderer.pos(x1, y2, z2).endVertex();
			renderer.pos(x2, y2, z2).endVertex();
			renderer.pos(x2, y2, z1).endVertex();
			break;
		case NORTH:
			renderer.pos(x1, y1, z1).endVertex();
			renderer.pos(x1, y2, z1).endVertex();
			renderer.pos(x2, y2, z1).endVertex();
			renderer.pos(x2, y1, z1).endVertex();
			break;
		case SOUTH:
			renderer.pos(x1, y1, z2).endVertex();
			renderer.pos(x2, y1, z2).endVertex();
			renderer.pos(x2, y2, z2).endVertex();
			renderer.pos(x1, y2, z2).endVertex();
			break;
		case WEST:
			renderer.pos(x1, y1, z1).endVertex();
			renderer.pos(x1, y1, z2).endVertex();
			renderer.pos(x1, y2, z2).endVertex();
			renderer.pos(x1, y2, z1).endVertex();
			break;
		case EAST:
			renderer.pos(x2, y1, z1).endVertex();
			renderer.pos(x2, y2, z1).endVertex();
			renderer.pos(x2, y2, z2).endVertex();
			renderer.pos(x2, y1, z2).endVertex();
			break;
		}
	}

 

Edited by Tyhone
  • 9 months later...
Posted

SORRY FOR NECROING AN OLD THREAD!

If anyone wants examples of how to use DefaultVertexFormats.BLOCK look at net.minecraft.client.renderer.BlockFluidRenderer or

Spoiler

// debug quad
VertexBuffer.pos(0, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 0).lightmap(240, 0).endVertex();
VertexBuffer.pos(0, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 1).lightmap(240, 0).endVertex();
VertexBuffer.pos(1, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 1).lightmap(240, 0).endVertex();
VertexBuffer.pos(1, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 0).lightmap(240, 0).endVertex();

 

If anyone wants examples of how to use DefaultVertexFormats.POSITION_TEX look at net.minecraft.client.renderer.ItemRenderer or RenderTileEntityAlchemicArray.java

 

If anyone wants examples of how to use DefaultVertexFormats.POSITION_TEX_COLOR look at net.minecraft.client.renderer.RenderGlobal or ClientUtil.java

 

Examples for everything except block are pretty easy to find with your IDE's search

  • Like 1
  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.