Jump to content

[1.10.2] Advanced TileEntity Renderers


Zane49er

Recommended Posts

I have been searching for a way to make the rifts in my mod look how I want them to for a very long time, and I think I've found it - a custom renderer! I want them to have the following properties:

*Fulbright

*any color

*slightly procedural (explained later)

 

My current code can be found here https://github.com/zane49er2/VMC , or in the spoiler.

Spoiler

package zane49er.VolkiharEchoes.features.tileEntities;

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.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.tileentity.TileEntity;

public class RiftRenderer extends TileEntitySpecialRenderer {
	
	int r = 200;
	int g = 200;
	int b = 200;
	
	@Override
	public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick, int destroyStage) {
		GlStateManager.pushMatrix(); {
			GlStateManager.translate(x + 0.5, y + 0.066, z + 0.75);
			//GlStateManager.rotate(90F, 1.0F, 0.0F, 0.0F);
			//GlStateManager.scale(0.25F, 0.25F, 0.25F);
			GlStateManager.color(r, g, b);
	        GlStateManager.disableLighting();
			Tessellator wrt = Tessellator.getInstance();
	        VertexBuffer wr = wrt.getBuffer();
	        wr.begin(7, DefaultVertexFormats.POSITION_COLOR);
	        wr.color(r, g, b, 255);
			wr.pos(x, y, z);
			wr.pos(x+1, y, z);
			wr.pos(x+1, y+1, z);
			wr.pos(x, y+1, z);
			wrt.draw();
		}
		GlStateManager.popMatrix();
	}
}

 

 

This code renders literally nothing, though. I copied it from 3 different places (chest, beacon, and internet) and 2 hours of research, so it might just be that I'm combining way too many methods into the same thing.

 

By "slightly procedural" I mean that there will be a list of 'arms' in the TileEntity that is randomly generated. Those arms are what eventually want to render.

 

I want the final product to look like a 3D crack in the sky from any angle. The closest thing I can think of in reality (or other mods) is a ball of lightning generated by tesla coil or something, but concentrated and larger in the center to look like glass cracking.

 

Is this entirely stupid, or how can I implement it?

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Link to comment
Share on other sites

  • color is a property of a vertex, you can't just put it into a buffer without any context and expect it to work.
  • After defining a vertex you must end it's definition with VertexBuffer::endVertex.
  • There is no point in applying color with GlStateManager as your vertex format already specifies a color.
  • If you are changing states of GlStateManager - reset them after you are done. If you are disabling the lighting before drawing enable it after you are done.
  • You have already translated everything by xyz with GlStateManager.translate. Putting xyz as origin in your vertices is going to translate them again, causing issues.
  • If you want your rendering 'fullbright' disabling lighting is not going to be enough, you will need to specify lightmap coordinates.
16 minutes ago, Zane49er said:

how can I implement it?

That is really up tou you. I do not think there are any tutorials out there that would describe how to render "a rift". You would want to play with rendering untill you achieve the effect you are after.

Link to comment
Share on other sites

I really just have no Idea how the vertexbuffer system works. what I meant by "how can I implement it?" was "how can I make the colored, fullbright, procedural model?"

 

  • Vertexes = vertices = points, so how can color be for vertex and not face? where do I define the color?
  • I'll try putting that just before the draw, but I don't know if that's right
  • good point.
  • thanks
  • thanks
  • how?

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Link to comment
Share on other sites

8 minutes ago, Zane49er said:

Vertexes = vertices = points, so how can color be for vertex and not face?

Have you heard of gradients? How do you think they work? The color is a property of a vertex, aka a point. If you define a point with a red color and a point with a green color the color of the line drawn between those two points will be linearly interpolated.

 

8 minutes ago, Zane49er said:

I'll try putting that just before the draw, but I don't know if that's right

You put it after you define a vertex. When you call pos you define a position element of a vertex. When you call color you define another element of a vertex.

wr.pos(0, 0, 0).color(100, 100, 100, 255).endVertex(); is a fully defined position + color vertex.

 

8 minutes ago, Zane49er said:

how?

You would either select a vertex format that uses lightmap as one of it's vertex elements or manualy set it with OpenGlHelper.setLightmapTextureCoords. If you use the later do not forget to reset it back.

 

Additionally if your vertex format does not include UVs(texture) disable it before rendering(GlStateManager.disableTexture2D) and enable it after you are done.

Edited by V0idWa1k3r
  • Like 1
Link to comment
Share on other sites

this:

Spoiler

package zane49er.VolkiharEchoes.features.tileEntities;

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.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.tileentity.TileEntity;

public class RiftRenderer extends TileEntitySpecialRenderer {
	
	int r = 200;
	int g = 200;
	int b = 200;
	
	@Override
	public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick, int destroyStage) {
		GlStateManager.pushMatrix(); {
			GlStateManager.translate(x + 0.5, y + 0.066, z + 0.75);
			//GlStateManager.rotate(90F, 1.0F, 0.0F, 0.0F);
			//GlStateManager.scale(0.25F, 0.25F, 0.25F);
			//GlStateManager.color(r, g, b);
	        GlStateManager.disableLighting();
	        GlStateManager.disableTexture2D();
			Tessellator wrt = Tessellator.getInstance();
	        VertexBuffer wr = wrt.getBuffer();
	        wr.begin(7, DefaultVertexFormats.POSITION_COLOR);
			wr.pos(0, 0, 0).color(r, b, g, 255).lightmap(255, 255).endVertex();
			wr.pos(1, 0, 0).color(r, b, g, 255).lightmap(255, 255).endVertex();
			wr.pos(1, 1, 0).color(r, b, g, 255).lightmap(255, 255).endVertex();
			wr.pos(0, 1, 0).color(r, b, g, 255).lightmap(255, 255).endVertex();
			wrt.draw();
	        GlStateManager.enableLighting();
	        GlStateManager.enableTexture2D();
		}
		GlStateManager.popMatrix();
	}
}

 

still does nothing.

Edited by Zane49er

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Link to comment
Share on other sites

Spoiler

package zane49er.VolkiharEchoes.features.tileEntities;

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.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.tileentity.TileEntity;

public class RiftRenderer extends TileEntitySpecialRenderer {
	
	int r = 200;
	int g = 200;
	int b = 200;
	
	@Override
	public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick, int destroyStage) {
		GlStateManager.pushMatrix(); {
			GlStateManager.translate(x + 0.5, y + 0.066, z + 0.75);
			//GlStateManager.rotate(90F, 1.0F, 0.0F, 0.0F);
			//GlStateManager.scale(0.25F, 0.25F, 0.25F);
			//GlStateManager.color(r, g, b);
	        GlStateManager.disableLighting();
	        GlStateManager.disableTexture2D();
			Tessellator wrt = Tessellator.getInstance();
	        VertexBuffer wr = wrt.getBuffer();
	        wr.begin(7, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR);
			wr.pos(0, 0, 0).lightmap(255, 255).color(r, b, g, 255).endVertex();
			wr.pos(1, 0, 0).lightmap(255, 255).color(r, b, g, 255).endVertex();
			wr.pos(1, 1, 0).lightmap(255, 255).color(r, b, g, 255).endVertex();
			wr.pos(0, 1, 0).lightmap(255, 255).color(r, b, g, 255).endVertex();
			wrt.draw();
	        GlStateManager.enableLighting();
	        GlStateManager.enableTexture2D();
		}
		GlStateManager.popMatrix();
	}
}

2017-08-03_01.21.57.png2017-08-03_01.21.37.png2017-08-03_01.21.24.png

It's definitely rendering something now! I still don't get light maps or why they have stretched to infinity.

Edited by Zane49er

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Link to comment
Share on other sites

The ordering matters. If your format is POSITION_TEX_LMAP_COLOR then you must specify a position, a set of UVs, a lightmap and color in that order. Also as this format uses UVs you shouldn't disable the texture. You should also provide a set of UVs that makes sense, not fill it with zeroes.

Additionally I believe that lightmap of 255 255 is actually pretty dark. I use 240 240 when I want full brightness.

 

As you've pretty much got it done here is a code snippet that renders your quad:

wr.pos(0, 0, 0).tex(0, 0).lightmap(240, 240).color(r, b, g, 255).endVertex();
wr.pos(1, 0, 0).tex(1, 0).lightmap(240, 240).color(r, b, g, 255).endVertex();
wr.pos(1, 1, 0).tex(1, 1).lightmap(240, 240).color(r, b, g, 255).endVertex();
wr.pos(0, 1, 0).tex(0, 1).lightmap(240, 240).color(r, b, g, 255).endVertex();

Note that it rendrs whatever texture was bound last, and it is a small face that only renders when you look at it from a specific side. This is most likely not what you want to achieve but it is a starting point, I suppose ;)

Link to comment
Share on other sites

Ideally It'd have no texture, but I only saw the one format with light map... is there something I'm missing? Also, thanks a lot for the help. This is, indeed, a start... and often the math stuff is easier than the language stuff for me, so I expect most of the work is in that start.

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Link to comment
Share on other sites

Just now, Zane49er said:

Ideally It'd have no texture, but I only saw the one format with light map... is there something I'm missing?

You can use 

39 minutes ago, V0idWa1k3r said:

OpenGlHelper.setLightmapTextureCoords

 Store the previous coordinates in locals(the current coordinates are stored in OpenGlHelper.lastBrightnessX and OpenGlHelper.lastBrightnessY), set the coordinates to whatever you want, render your thing and reset them back. The target parameter for OpenGlHelper.setLightmapTextureCoords would be OpenGlHelper.lightmapTexUnit

 

  • Like 1
Link to comment
Share on other sites

Spoiler

package zane49er.VolkiharEchoes.features.tileEntities;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.client.renderer.OpenGlHelper;

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.client.renderer.VertexBuffer;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

import net.minecraft.client.renderer.vertex.DefaultVertexFormats;

import net.minecraft.tileentity.TileEntity;

 

public class RiftRenderer extends TileEntitySpecialRenderer {

 

int r = 255;

int g = 0;

int b = 0;

 

@Override

public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick, int destroyStage) {

GlStateManager.pushMatrix(); {

 

float PBX = OpenGlHelper.lastBrightnessX;

float PBY = OpenGlHelper.lastBrightnessX;

 

//GlStateManager.translate(x + 0.5, y + 0.066, z + 0.75);

//GlStateManager.rotate(90F, 1.0F, 0.0F, 0.0F);

//GlStateManager.scale(0.25F, 0.25F, 0.25F);

 

Tessellator wrt = Tessellator.getInstance();

VertexBuffer wr = wrt.getBuffer();

 

GlStateManager.disableLighting();

GlStateManager.disableTexture2D();

OpenGlHelper.setLightmapTextureCoords(240, 240, 240);

 

wr.begin(7, DefaultVertexFormats.POSITION_COLOR);

wr.pos(0, 0, 0).color(r, b, g, 255).endVertex();

wr.pos(1, 0, 0).color(r, b, g, 255).endVertex();

wr.pos(1, 1, 0).color(r, b, g, 255).endVertex();

wr.pos(0, 1, 0).color(r, b, g, 255).endVertex();

 

wr.begin(7, DefaultVertexFormats.POSITION_COLOR);

wr.pos(0, 0, 0).color(r, b, g, 255).endVertex();

wr.pos(0, 1, 0).color(r, b, g, 255).endVertex();

wr.pos(1, 1, 0).color(r, b, g, 255).endVertex();

wr.pos(1, 0, 0).color(r, b, g, 255).endVertex();

 

wrt.draw();

 

GlStateManager.enableLighting();

GlStateManager.enableTexture2D();

OpenGlHelper.setLightmapTextureCoords(???, ???, ???);

 

}

GlStateManager.popMatrix();

}

}

I am now even more confused about how minecraft's Lightmaps work...

This crashes the game (even without the use of ??? as an integer)

Really, a 3d lightmap? or a strange integer in a float lightmap?

??????

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Link to comment
Share on other sites

Thanks, everything is working!

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Link to comment
Share on other sites

Okay, one more thing: can I make it so it renders no matter how far away you are? Like a beacon, instead of a sign, it is still visible when you are several chunks away.

2017-08-03_11.27.14.png

There are a few rifts, signs, and chests surrounding the beam.

Edited by Zane49er

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Link to comment
Share on other sites

good point, I'm still not really used to having access to them... I just managed to decompile Minecraft on Wednesday. :P

 

edit: hmmm, this:

public boolean isGlobalRenderer(TileEntityRift te) {

return true;

}

 

doesn't work...

Edited by Zane49er

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Link to comment
Share on other sites

You need to potentially override TileEntity::getRenderBoundingBox and TileEntity::getMaxRenderDistanceSquared. The first method dictates whether to render your TE if it is's origin is not within camera's viewport, the second one dictates the distance to stop rendering your TE at. Mind the "squared" in the name of the method. By default it returns 4096 that translates to 64 blocks.

  • Like 1
Link to comment
Share on other sites

Yep, that was it! thanks again for all the help.

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

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 need help making a block generate an explosion im new to modding so i dont know how to do it.
    • okay.. ';D i did my good old technique of troubleshooting modpack (disabling ALL the mods and gradually in parts enabbling them and lauching game, enabling more mods, launching e.t.c) and managed to narrow it down to one mod.... it was "better smithing table" causing all the errors and making several mods to spit errors.. Same way by FIRSTLY turning on "better smithing tables" and seeing which mods it clashed with was: "Doggy Tallents Next" "bartering station" "Curios API" And further i wasn't able to check what mods conflicted b'cuz it was like: it was working with X mods, enabled 10 more mods, crashed. procedurally disabled all of them and still was crashing, disabled some more mods, worked. enabled back mods with which it was crashing and now it wasn't  i can't understand why and what mods are bad but i'm happy i somehow got the main error causer which again was "better smithing table". Without that mod everything works just fine. SOLVED (?)
    • So I'm creating yet another minecraft modpack and stumbled upon error I've never encoutered.. I tried to troubleshoot it myself and it always worked but this time I didn't manage.. Here is minecraft crash report: https://pastebin.com/EVqzdDKg I can't find how or from where to post debug.log  I'm sorry, can someone help me? (as a disclaimer - i've tried already reinstalling minecraft and java)
    • It works without mods, I've ran it through the launcher by itself and runs perfectly fine, when I open it through Forge I can get through to the launcher but when I go to open the world it loads then gives me the error code 1. Is there anymore info that could help diagnose it?
    • Also had the issue. GLAD TO TELL YOU I HAVE THE FIX! Create: Applied Kinetic literally says "Replace all inscriber recipes with Create's sequenced assembly recipe". When I turned off this mod it worked fine. I also didn't use that mod of the pack i played so it didn't matter for me.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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