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

Hi! I have created a custom sign block. Works almost like regular Minecraft wall sign. The problem is that if the sign is inside a house, the player can see the custom redered text that is on the sign even from outside of the house. How to stop the text from being rendered when there is an object between the sign block and the player?

I tried to create a custom method for that which checks if there is a solid object between the block and player. But sometimes the text is still rendered too early and it shines through some solid block. I couldn't find any Minecraft code showing how to achieve that. Here is my function:

public static boolean shouldRenderText(LevelAccessor world, BlockPos blockPos, BlockPos playerPos, int range) {
  boolean shouldRender = true;
  int bX = blockPos.getX();
  int bY = blockPos.getY();
  int bZ = blockPos.getZ();
  int pX = playerPos.getX();
  int pY = playerPos.getY();
  int pZ = playerPos.getZ();
  Vec3 bp = new Vec3(pX-bX, pY-bY, pZ-bZ);

  if (bp.length() > range)
    return false;

  double max = Math.abs(bp.x);
  if (Math.abs(bp.y) > max)
    max = Math.abs(bp.y);
  if (Math.abs(bp.z) > max)
    max = Math.abs(bp.z);

  double stepX = bp.x/max;
  double stepY = bp.y/max;
  double stepZ = bp.z/max;

  for(int i = 1; i < max; i++) {
    double x = bX + (i*stepX);
    double y = bY + (i*stepY);
    double z = bZ + (i*stepZ);
    if (PTMBlock.isSolid(world, Math.floor(x), y, z))
      shouldRender = false;
    if (PTMBlock.isSolid(world, Math.ceil(x), y, z))
      shouldRender = false;

    if (PTMBlock.isSolid(world, x, y, Math.floor(z)))
      shouldRender = false;
    if (PTMBlock.isSolid(world, x, y, Math.ceil(z)))
      shouldRender = false;

    if (PTMBlock.isSolid(world, Math.floor(x), y, Math.floor(z)))
      shouldRender = false;
    if (PTMBlock.isSolid(world, Math.ceil(x), y, Math.ceil(z)))
      shouldRender = false;

    if (PTMBlock.isSolid(world, Math.ceil(x), y, Math.floor(z)))
      shouldRender = false;
    if (PTMBlock.isSolid(world, Math.floor(x), y, Math.ceil(z)))
      shouldRender = false;

    if (!shouldRender)
      return false;
  }
  return shouldRender;
}

The PTMBlock#isSolid will just get a block at the position and will check if it is solid or not. Any ideas how to make this system more efficient or if there may be already is a functions that does that? Thanks.

1 hour ago, RInventor7 said:

I tried to create a custom method for that which checks if there is a solid object between the block and player. But sometimes the text is still rendered too early and it shines through some solid block. I couldn't find any Minecraft code showing how to achieve that. Here is my function:

 

Why not just look at how vanilla does it in SignRenderer#renderSignText?

  • Author
7 minutes ago, ChampionAsh5357 said:

Why not just look at how vanilla does it in SignRenderer#renderSignText?

I have looked SignRenderer class many times and just now, but there is no method called renderSignText in that class.

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.