Skip to content

Instantly share code, notes, and snippets.

@tterrag1098
Created September 24, 2017 04:03
Show Gist options
  • Save tterrag1098/9eacfa50e40befd440c076b642717736 to your computer and use it in GitHub Desktop.
Save tterrag1098/9eacfa50e40befd440c076b642717736 to your computer and use it in GitHub Desktop.
private void renderModel(IBakedModel model, int color, ItemStack stack)
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
List<BakedQuad> allquads = new ArrayList<>();
for (EnumFacing enumfacing : EnumFacing.values())
{
allquads.addAll(model.getQuads((IBlockState)null, enumfacing, 0L));
}
allquads.addAll(model.getQuads((IBlockState)null, (EnumFacing)null, 0L));
Deque<Pair<List<BakedQuad>, int[]>> segmentedQuads = new ArrayDeque<>();
for (BakedQuad q : allquads) {
Pair<List<BakedQuad>, int[]> tail = segmentedQuads.peekLast();
int[] light = { 0, 0 };
if (q.getFormat() != DefaultVertexFormats.ITEM && q.getFormat().getElements().contains(DefaultVertexFormats.TEX_2S)) {
int lmapIndex = q.getFormat().getElements().indexOf(DefaultVertexFormats.TEX_2S);
QuadGatheringTransformer qgt = new QuadGatheringTransformer() {
@Override
public void setTexture(TextureAtlasSprite texture){}
@Override
public void setQuadTint(int tint){}
@Override
public void setQuadOrientation(EnumFacing orientation){}
@Override
public void setApplyDiffuseLighting(boolean diffuse){}
@Override
protected void processQuad()
{
int[] totalLight = new int[2];
for (int i = 0; i < 4; i++) {
float blight = (quadData[lmapIndex][i][0] * 0xFFFF) / 0x20;
float slight = (quadData[lmapIndex][i][1] * 0xFFFF) / 0x20;
totalLight[0] += (int) blight;
totalLight[1] += (int) slight;
}
light[0] = totalLight[0] / 4;
light[1] = totalLight[1] / 4;
}
};
qgt.setVertexFormat(q.getFormat());
q.pipe(qgt);
}
if (tail == null || !Arrays.equals(light, tail.getValue())) {
segmentedQuads.add(Pair.of(Lists.newArrayList(q), light));
} else {
tail.getLeft().add(q);
}
}
for (Pair<List<BakedQuad>, int[]> segment : segmentedQuads) {
bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
float emissive = segment.getRight()[1] / 15f;
GL11.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_EMISSION, RenderHelper.setColorBuffer(emissive, emissive, emissive, 1));
float bl = segment.getRight()[0] * 16, sl = segment.getRight()[1] * 16;
float lastBl = OpenGlHelper.lastBrightnessX, lastSl = OpenGlHelper.lastBrightnessY;
if (bl > lastBl && sl > lastSl) {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, bl, sl);
} else if (bl > lastBl) {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, bl, lastSl);
} else if (sl > lastSl) {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastBl, sl);
}
this.renderQuads(bufferbuilder, segment.getLeft(), color, stack);
tessellator.draw();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastBl, lastSl);
GL11.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_EMISSION, RenderHelper.setColorBuffer(0, 0, 0, 1));
}
}
private void renderModel(IBakedModel model, int color, ItemStack stack)
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.ITEM);
for (EnumFacing enumfacing : EnumFacing.values())
{
this.renderQuads(bufferbuilder, model.getQuads((IBlockState)null, enumfacing, 0L), color, stack);
}
this.renderQuads(bufferbuilder, model.getQuads((IBlockState)null, (EnumFacing)null, 0L), color, stack);
tessellator.draw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment