tutorial:pixel_raycast
This is an old revision of the document!
Pixel raycast
Suppose you want to know what block or entity corresponds to a pixel on the screen. This can be done with pixel raycast.
All of this is client side.
There are two types, center pixel (crosshair) and arbitrary pixel.
Special case: Center pixel
This can be done with:
MinecraftClient client = MinecraftClient.getInstance(); HitResult hit = client.crosshairTarget; switch(hit.getType()) { case Type.MISS: //nothing near enough break; case Type.BLOCK: BlockHitResult blockHit = (BlockHitResult) hit; BlockPos blockPos = blockHit.getBlockPos(); BlockState blockState = client.world.getBlockState(blockPos); Block block = blockState.getBlock(); break; case Type.ENTITY: EntityHitResult entityHit = (EntityHitResult) hit; break; }
tutorial/pixel_raycast.1597423572.txt.gz · Last modified: 2020/08/14 16:46 by emmanuelmess