I tried to work the matrix and vec3d calculations myself for a while, but its just to much for me.
Minecraft 1.20.6, Java
public class FloatingIconHudOverlay implements HudRenderCallback {
private final List<FloatingIconSupplier> iconSuppliers;
private static final ArrayList<BlockEntity> blockEntitiesToRender = new ArrayList<>();
public FloatingIconHudOverlay(List<FloatingIconSupplier> iconSuppliers) {
this.iconSuppliers = iconSuppliers;
}
public static void addRenderedBlockEntity(BlockEntity blockEntity) {
blockEntitiesToRender.add(blockEntity);
}
@Override
public void onHudRender(DrawContext drawContext, float tickDelta) {
if (!MinecraftClient.isHudEnabled())
return;
var player = MinecraftClient.getInstance().player;
if (player == null) {
return;
}
var world = player.getWorld();
if (world == null)
return;
// Render a 2D icon (sprite or texture, whatever is easier) for each BlockEntity in the blockEntitiesToRender list
// it should be rendered on the hud, to make it visible through other blocks, when the player is looking into the direction of the block
// The icon should always show centered on the block and always face the camera flat (like any on hud icon)
Any help would be really appreciated, I am getting desperate.
(I tried about 20 approaches, but conversions from camera vectors to matrices etc. to get the different calculations inside mincraft rendering systems are just to much.
Tried e.g. using the same logic as the textrenderer does in EntityRenderer for the label, but I cant get it to work for non-text)
Glad to help in reverse with non-render related code