Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.18.2] Rendering a block model clientside only


Recommended Posts

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?

Link to comment
Share on other sites

Posted (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));
    bp.getX() - originPos.getX(),
    bp.getY() - originPos.getY(),
    bp.getZ() - originPos.getZ());
    bs, matrix,


Edited by SoLegendary
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.

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.


  • Create New...

Important Information

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