Advertisement
Guest User

Untitled

a guest
Dec 29th, 2021
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1.     // prevent moused over blocks being outlined in the usual way (ie. by raytracing from player to block)
  2.     @SubscribeEvent
  3.     public static void onHighlightBlockEvent(DrawSelectionEvent.HighlightBlock evt) {
  4.         if (MC.level != null) {
  5.             drawSelectionBox(evt.getMatrix());
  6.             evt.setCanceled(true);
  7.         }
  8.     }
  9.  
  10.     static BlockPos testBlockPos = new BlockPos(346,64,-273);
  11.  
  12.     public static void drawSelectionBox(PoseStack matrix)
  13.     {
  14.         Entity camEntity = MC.getCameraEntity();
  15.         BlockPos blockpos = testBlockPos;
  16.         BlockState blockstate = MC.level.getBlockState(blockpos);
  17.         double d0 = camEntity.getX();
  18.         double d1 = camEntity.getY() + camEntity.getEyeHeight();
  19.         double d2 = camEntity.getZ();
  20.  
  21.         if (!blockstate.isAir()) {
  22.             VertexConsumer vertexConsumer = MC.renderBuffers().bufferSource().getBuffer(RenderType.lines());
  23.  
  24.             final double xIn = (double) blockpos.getX() - d0;
  25.             final double yIn = (double) blockpos.getY() - d1;
  26.             final double zIn = (double) blockpos.getZ() - d2;
  27.  
  28.             VoxelShape shapeIn = blockstate.getShape(MC.level, blockpos); // need to put back in ISelectionThingo?
  29.             Matrix4f matrix4f = matrix.last().pose();
  30.  
  31.             shapeIn.forAllEdges((x0, y0, z0, x1, y1, z1) ->
  32.             {
  33.                 vertexConsumer.vertex(matrix4f, (float) (x0 + xIn), (float) (y0 + yIn), (float) (z0 + zIn)).color(1.0f,1.0f,1.0f,1.0f).endVertex();
  34.                 vertexConsumer.vertex(matrix4f, (float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).color(1.0f,1.0f,1.0f,1.0f).endVertex();
  35.             });
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement