Jump to content

Text on custom sign block shown even when behind an object [1.19.2]


RInventor7

Recommended Posts

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.

Link to comment
Share on other sites

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?

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.

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...

×   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.