Posted January 5, 20223 yr For my mod, I want to render a block in a custom GUI screen, similar to how the player model is rendered in the vanilla inventory. I've looked at the InventoryScreen code, but that isn't too helpful, since it's rendering an Entity, not a Block. I've guessed that I can maybe use `BlockRendererDispatcher.renderSingleBlock()`, but haven't made much headway, and can't find any examples of this after a couple hours of googling. Here's what I have, which doesn't crash or anything, but nothing shows up in the Screen when this is called: PoseStack poseStack1 = RenderSystem.getModelViewStack(); BlockState blockState = new BlockState(Blocks.STONE, null, null); MultiBufferSource.BufferSource bufferSource = MultiBufferSource.immediate(new BufferBuilder(2097152)); Minecraft.getInstance().getBlockRenderer().renderSingleBlock(blockState, poseStack1, bufferSource, 15728880, OverlayTexture.NO_OVERLAY, EmptyModelData.INSTANCE); There are a few specific things I have questions on: 1. Is this the correct approach for rendering a block (vanilla stone) in a GUI screen? 2. Do I need either of the other two parameters of the BlockState? 3. Do I need to fetch the BufferSource from somewhere else, or does instantiating a new one like above work? I know there's probably a LOT of concepts I don't understand here about rendering (just started learning a couple of days ago), but ANY help is appreciated here! Edited January 6, 20223 yr by lukebickell fix code block
January 6, 20223 yr Author With some help from some discord folks and some finagling, I got a 3d block rendering in a GUI! ItemStack item = new ItemStack(Blocks.DIAMOND_BLOCK); RenderSystem.enableBlend(); RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); PoseStack poseStack = RenderSystem.getModelViewStack(); poseStack.pushPose(); poseStack.translate(150, 150, (100.0F)); poseStack.translate(8.0D, 8.0D, 0.0D); poseStack.scale(1.0F, -1.0F, 1.0F); poseStack.scale(16.0F, 16.0F, 16.0F); RenderSystem.applyModelViewMatrix(); float angle = (System.currentTimeMillis() / 100) % 360; Quaternion rotation = Vector3f.YP.rotationDegrees(angle); PoseStack blockPoseStack = new PoseStack(); blockPoseStack.pushPose(); blockPoseStack.mulPose(rotation); blockPoseStack.scale(8, 8, 8); MultiBufferSource.BufferSource bufferSource = Minecraft.getInstance().renderBuffers().bufferSource(); Minecraft.getInstance().getItemRenderer().renderStatic(item, ItemTransforms.TransformType.FIXED, 0, 0, blockPoseStack, bufferSource, 0); bufferSource.endBatch(); poseStack.popPose(); RenderSystem.applyModelViewMatrix(); A lot of the setup code was taken from the `ItemRenderer.renderGuiItem()` function, so I'm not really sure what's necessary and what isn't. Only problem now is that the block appears very dark. I've tried using `Lighting.setupFor3DItems()`, but that hasn't seemed to do anything
January 6, 20223 yr Author https://cdn.discordapp.com/attachments/418125698486632448/928492784397201408/minecraft-blockspin-dark.gif The above gif shows how the block is there and rotating, but totally dark. I've added RenderSystem.enableDepthTest(); Lighting.setupFor3DItems(); before the final popPose, but that doesn't seem to make a difference
January 7, 20223 yr Author At last, figured it out; I was missing two parameters in the renderStatic method: Minecraft.getInstance().getItemRenderer().renderStatic(item, ItemTransforms.TransformType.FIXED, 0, 0, blockPoseStack, bufferSource, 0); to Minecraft.getInstance().getItemRenderer().renderStatic(item, ItemTransforms.TransformType.FIXED, 15728880, OverlayTexture.NO_OVERLAY, blockPoseStack, bufferSource, 0); I have no idea what the 15728880 value is, which is probably why I didn't understand why it was necessary.
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.