Jump to content

Recommended Posts

Posted

I am porting LanteaCraft to 1.12, and i cant figure out how to change everything that uses Tesselate to using BufferBuilder

here is one method (it contains most of the stuff i dont know how to port):

private void renderItemIn2D(Tessellator t, float u1, float v0, float u0, float v1, int w, int h, float p_78439_7_) {
		t.startDrawingQuads();
		t.setNormal(0.0F, 0.0F, 1.0F);
		t.addVertexWithUV(0.0D, 0.0D, 0.0D, (double) u1, (double) v1);
		t.addVertexWithUV(1.0D, 0.0D, 0.0D, (double) u0, (double) v1);
		t.addVertexWithUV(1.0D, 1.0D, 0.0D, (double) u0, (double) v0);
		t.addVertexWithUV(0.0D, 1.0D, 0.0D, (double) u1, (double) v0);
		t.draw();
		t.startDrawingQuads();
		t.setNormal(0.0F, 0.0F, -1.0F);
		t.addVertexWithUV(0.0D, 1.0D, (double) (0.0F - p_78439_7_), (double) u1, (double) v0);
		t.addVertexWithUV(1.0D, 1.0D, (double) (0.0F - p_78439_7_), (double) u0, (double) v0);
		t.addVertexWithUV(1.0D, 0.0D, (double) (0.0F - p_78439_7_), (double) u0, (double) v1);
		t.addVertexWithUV(0.0D, 0.0D, (double) (0.0F - p_78439_7_), (double) u1, (double) v1);
		t.draw();
		float f5 = 0.5F * (u1 - u0) / (float) w;
		float f6 = 0.5F * (v1 - v0) / (float) h;
		t.startDrawingQuads();
		t.setNormal(-1.0F, 0.0F, 0.0F);
		int k;
		float f7;
		float f8;

		for (k = 0; k < w; ++k) {
			f7 = (float) k / (float) w;
			f8 = u1 + (u0 - u1) * f7 - f5;
			t.addVertexWithUV((double) f7, 0.0D, (double) (0.0F - p_78439_7_), (double) f8, (double) v1);
			t.addVertexWithUV((double) f7, 0.0D, 0.0D, (double) f8, (double) v1);
			t.addVertexWithUV((double) f7, 1.0D, 0.0D, (double) f8, (double) v0);
			t.addVertexWithUV((double) f7, 1.0D, (double) (0.0F - p_78439_7_), (double) f8, (double) v0);
		}

		t.draw();
		t.startDrawingQuads();
		t.setNormal(1.0F, 0.0F, 0.0F);
		float f9;

		for (k = 0; k < w; ++k) {
			f7 = (float) k / (float) w;
			f8 = u1 + (u0 - u1) * f7 - f5;
			f9 = f7 + 1.0F / (float) w;
			t.addVertexWithUV((double) f9, 1.0D, (double) (0.0F - p_78439_7_), (double) f8, (double) v0);
			t.addVertexWithUV((double) f9, 1.0D, 0.0D, (double) f8, (double) v0);
			t.addVertexWithUV((double) f9, 0.0D, 0.0D, (double) f8, (double) v1);
			t.addVertexWithUV((double) f9, 0.0D, (double) (0.0F - p_78439_7_), (double) f8, (double) v1);
		}

		t.draw();
		t.startDrawingQuads();
		t.setNormal(0.0F, 1.0F, 0.0F);

		for (k = 0; k < h; ++k) {
			f7 = (float) k / (float) h;
			f8 = v1 + (v0 - v1) * f7 - f6;
			f9 = f7 + 1.0F / (float) h;
			t.addVertexWithUV(0.0D, (double) f9, 0.0D, (double) u1, (double) f8);
			t.addVertexWithUV(1.0D, (double) f9, 0.0D, (double) u0, (double) f8);
			t.addVertexWithUV(1.0D, (double) f9, (double) (0.0F - p_78439_7_), (double) u0, (double) f8);
			t.addVertexWithUV(0.0D, (double) f9, (double) (0.0F - p_78439_7_), (double) u1, (double) f8);
		}

		t.draw();
		t.startDrawingQuads();
		t.setNormal(0.0F, -1.0F, 0.0F);

		for (k = 0; k < h; ++k) {
			f7 = (float) k / (float) h;
			f8 = v1 + (v0 - v1) * f7 - f6;
			t.addVertexWithUV(1.0D, (double) f7, 0.0D, (double) u0, (double) f8);
			t.addVertexWithUV(0.0D, (double) f7, 0.0D, (double) u1, (double) f8);
			t.addVertexWithUV(0.0D, (double) f7, (double) (0.0F - p_78439_7_), (double) u1, (double) f8);
			t.addVertexWithUV(1.0D, (double) f7, (double) (0.0F - p_78439_7_), (double) u0, (double) f8);
		}

		t.draw();
	}

and here is another one:

public void renderDefaultInventoryBlock(Block block, int metadata, Trans3 trans, BlockModelRenderer rb) {
		setUpTextureOverride(rb);
		setColorMultiplier(0xffffff);
		Tessellator tess = Tessellator.getInstance();
		BufferBuilder buff = tess.getBuffer();
		buff.setColorOpaque_F(1, 1, 1);
		buff.begin(7, DefaultVertexFormats.BLOCK);
		GL11.glTranslatef(0.0f, -0.1f, 0.0f);
		renderCube(buff, trans, null, block, 0, 0, 0, metadata, 0xf000f0);
		tess.draw();
	}

im thanking anyone  in advance for helping me

Posted

In order to port the code given in the first example you need to understand how BufferBuilder works in the first place.

Instead of Tessellator that gave a way to create vertices with predefined formats and alter their parts minecraft now has a BufferBuilder that allows you to build those vertices from scratch the way you need them. 

So a BufferBuilder is just a way to define vertices. Vertices are just a collection of data that is passed to the rendering pipeline. You start by specifying some property(usually position) and end with the .endVertex() call. It allows you to pack data into a vertex. You specify the vertex format when you start the drawing operation and you must use that format for all the vertices you are drawing in that pass.

So for example to put position, texture and color into the vertex you would do

BufferBuilder bb = ...; // Set to some value
bb.begin(GL11.GL_QUADS /* Defines the amount of vertices per shape */ , DefaultVertexFormats.POSITION_TEX_COLOR);
bb.pos(x, y, z).tex(u, v).color(r, g, b, a).endVertex();
... // Define other vertices

There are various formats too. The format name usually defines the way you define a vertex but if it is something obscure like BLOCK you can see it's components and their ordering in the DefaultVertexFormats class.

 

Now as for adapting the old code. Let's look at the code at hand

t.startDrawingQuads();
t.setNormal(0.0F, 0.0F, 1.0F);
t.addVertexWithUV(0.0D, 0.0D, 0.0D, (double) u1, (double) v1);
t.addVertexWithUV(1.0D, 0.0D, 0.0D, (double) u0, (double) v1);
t.addVertexWithUV(1.0D, 1.0D, 0.0D, (double) u0, (double) v0);
t.addVertexWithUV(0.0D, 1.0D, 0.0D, (double) u1, (double) v0);
t.draw();

So what does this code do? It draws a quad, since it only defines 4 vertices which make a quad together. You can also easily see the data these vertices are composed of - they have a position(the first 3 variables in the addVertexWithUV method), texture coordinates(the last two variables in the addVertexWithUV method) and a normal(the setNormal method). Thus to adapt this code you need a similar format - POSITION_TEX_NORMAL is that format.

Now when you know the format the rest is easy - just define the vertices using BufferBuilder with that format:

BufferBuilder bb = ...; // Set to some value
bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL);
bb.pos(0, 0, 0).tex(u1, v1).normal(0, 0, 1).endVertex();
bb.pos(1, 0, 0).tex(u0, v1).normal(0, 0, 1).endVertex();
bb.pos(1, 1, 0).tex(u0, v0).normal(0, 0, 1).endVertex();
bb.pos(0, 1, 0).tex(u1, v0).normal(0, 0, 1).endVertex();
Tessellator.getInstance().draw();

And you are done. A big optimization can be made by not splitting each quad into each own pass but instead specifying all quads in one draw pass.

 

As for the second method - I do not see an issue with it. It already uses BufferBuilder.

Posted

Your also going to want to swap out Block + Metadata for an IBlockState

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)

Posted
9 hours ago, OmegaRogue said:

and what does 


buff.putNormal(x,y,z);

do?

https://en.wikipedia.org/wiki/Vertex_normal

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)

Posted

I already told you how to handle the setNormal change. Include the normals per vertex. Old Tessellator had global states which would get applied to vertices. New BufferBuilder doesn't have them and as such you have to specify them for each vertex.

putX simply puts the raw data passed into the raw int buffer instead of putting it into corresponding buffers with a corresponding format. Unless you know what you are doing you should be using simple vertex creation operations, like pos, color, normal, tex and lightmap.

Posted

You will probably also be using BLOCK and ITEM vertex formats. Heres how to upload with them

BLOCK:

bufferBuilder.pos(x, y, z).color(red, green, blue, alpha).tex(minU, maxV).lightmap(skyLight, blockLight).endVertex();

ITEM:

bufferBuilder.pos(x, y, z).color(red, green, blue, alpha).tex(minU, maxV).normal(x, y, z).endVertex();
//theres also an element (1 byte) called padding in the ITEM format, however, since there is no method to create it, I assume it is literally padding and is automatically added if needed

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.