Posted March 4, 20232 yr 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.
March 4, 20232 yr 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?
March 4, 20232 yr 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.