Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

  • Author

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 by SoLegendary

  • Author

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.

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.

  • Author

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.