Skip to content

Instantly share code, notes, and snippets.

@Barteks2x
Created December 21, 2017 16:53
Show Gist options
  • Save Barteks2x/6cdb507400d5ac4c4a83c4bd337ce22f to your computer and use it in GitHub Desktop.
Save Barteks2x/6cdb507400d5ac4c4a83c4bd337ce22f to your computer and use it in GitHub Desktop.
stdin
@Override public void drawForeground(GuiRenderer renderer, int mouseX, int mouseY, float partialTick) {
renderer.next();
Tessellator.getInstance().draw();
ITextureObject blockTexture = Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
// half of that on the left, half on the right
int addPadding =
(int) Math.round((getAvailableWidth() - getLineStates() * UIBlockStateButton.SIZE) * 0.5);
double offsetY = getOffsetY();
double pixelsOffset = offsetY * (getContentHeight() - getHeight());
int lineStart = (int) (pixelsOffset / UIBlockStateButton.SIZE);
int lineEnd = MathHelper.ceil((pixelsOffset + getAvailableHeight()) / UIBlockStateButton.SIZE);
int itemStart = lineStart * getLineStates();
int itemEnd = (lineEnd + 1) * getLineStates();//the first item of the next line after
for (int i = itemStart; i < itemEnd; i++) {
if (i >= allStates.size() || i < 0) {
continue;
}
int line = i / getLineStates();
int num = i % getLineStates();
RenderHelper.disableStandardItemLighting();
RenderHelper.enableGUIStandardItemLighting();
GlStateManager.enableRescaleNormal();
GlStateManager.enableDepth();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockTexture.getGlTextureId());
drawState(allStates.get(i), num * UIBlockStateButton.SIZE + PADDING_HORIZ + addPadding,
(int) (line * UIBlockStateButton.SIZE - pixelsOffset + PADDING_VERT));
}
renderer.next();
GlStateManager.disableRescaleNormal();
}
private void drawState(IBlockState state, int x, int y) {
GlStateManager.pushAttrib();
GlStateManager.pushMatrix();
GlStateManager.translate((float) this.screenX() + x, (float) this.screenY() + 16f + y, 100.0F);
GlStateManager.scale(12.0F, 12.0F, -12.0F);
GlStateManager.rotate(210.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(45.0F, 0.0F, 1.0F, 0.0F);
BufferBuilder buf = Tessellator.getInstance().getBuffer();
buf.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
Minecraft.getMinecraft().getBlockRendererDispatcher().renderBlock(state, BlockPos.ORIGIN,
DummyWorld.getInstanceWithBlockState(state), buf);
Tessellator.getInstance().draw();
if (state.getBlock().hasTileEntity(state)) {
TileEntity te = state.getBlock().createTileEntity(null, state);
if (te != null) {
TileEntitySpecialRenderer<TileEntity> tileentityspecialrenderer =
TileEntityRendererDispatcher.instance.<TileEntity>getRenderer(te);
if (tileentityspecialrenderer != null) {
TileEntityItemStackRenderer.instance.renderByItem(new ItemStack(state.getBlock()));
}
}
}
GlStateManager.popMatrix();
GlStateManager.popAttrib();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment