SoLegendary Posted July 13, 2022 Posted July 13, 2022 I want to use BlockRendererDispatcher.renderSingleBlock() to render a block model in the world clientside only so that the player can see where they're about to place a structure without actually placing it. I have the BlockPos and BlockState of each block I want to render this way, but I don't know how to get the MultiBufferSource and the IModelData. In fact, renderSingleBlock() doesn't even accept any BlockPos as a parameter so how does it know where to render it? Quote
SoLegendary Posted July 13, 2022 Author Posted July 13, 2022 (edited) Ok so I managed to figure out the parameters, but the question of position remains, and my current code is just rendering all of the blocks on top of each other at the centre of my screen (it should be rendering that house). Ok solved it - just forgot to push, translate and pop the matrix - I'll leave my final code below to anyone who wants to know how to do the same thing: My current code (BuildingBlock is my custom class): for (BuildingBlock block : blocksToPlace) { BlockRenderDispatcher renderer = MC.getBlockRenderer(); BlockState bs = block.getBlockState; BlockPos bp = block.blockPos; IModelData modelData = renderer.getBlockModel(bs).getModelData(MC.level, bp, bs, ModelDataManager.getModelData(MC.level, bp)); matrix.pushPose(); matrix.translate( bp.getX() - originPos.getX(), bp.getY() - originPos.getY(), bp.getZ() - originPos.getZ()); renderer.renderSingleBlock( bs, matrix, MC.renderBuffers().crumblingBufferSource(), 15728880, OverlayTexture.NO_OVERLAY, modelData); matrix.popPose(); } Edited July 13, 2022 by SoLegendary Quote
SoLegendary Posted July 13, 2022 Author Posted July 13, 2022 Just one more thing I want to do: create a green OverlayTexture (to indicate the structure is a valid placement that doesn't clip other blocks). It seems the OverlayTexture class only has RED_OVERLAY_V and WHITE_OVERLAY_V available. Quote
bradsk88 Posted July 14, 2022 Posted July 14, 2022 I'm trying to build a similar functionality. Do you have code in a repo somewhere? I'm curious where you got the value of originPos from. Quote
SoLegendary Posted July 14, 2022 Author Posted July 14, 2022 originPos is just the corner of the structure I'm placing, because the structure only has relative BlockPos data starting at (0,0) - this can be wherever you want it to be, whether its the blocks the player is looking at or something else. In my case im building a top down gamemode, so its whatever my mouse cursor is over. Quote
Recommended Posts
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.