svdragster

raycast

May 23rd, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. final List<Entity> nearby = player.getNearbyEntities(6, 6, 6);
  2.  
  3. Location pointA = player.getEyeLocation();
  4. Location pointB = player.getEyeLocation().add(player.getEyeLocation().getDirection().normalize().multiply(5));
  5. int numberOfPointsBetweenAAndB = 25;
  6.  
  7. World tempWorld = pointA.getWorld();
  8. int timeIterated = 0;
  9. double xIncrement = 0.0D;
  10. double yIncrement = 0.0D;
  11. double zIncrement = 0.0D;
  12. double currentX = 0.0D;
  13. double currentY = 0.0D;
  14. double currentZ = 0.0D;
  15.  
  16. VisibleCheck:
  17. for (int i = 0; i < numberOfPointsBetweenAAndB; i++) {
  18.     if (timeIterated > numberOfPointsBetweenAAndB) {
  19.         break VisibleCheck;
  20.     }
  21.     Location thisLoc;
  22.     if (timeIterated == 0) {
  23.         currentX = pointA.getX();
  24.         currentY = pointA.getY();
  25.         currentZ = pointA.getZ();
  26.         xIncrement = (currentX - pointB.getX()) / numberOfPointsBetweenAAndB;
  27.         yIncrement = (currentY - pointB.getY()) / numberOfPointsBetweenAAndB;
  28.         zIncrement = (currentZ - pointB.getZ()) / numberOfPointsBetweenAAndB;
  29.         thisLoc = new Location(tempWorld, currentX, currentY, currentZ);
  30.         timeIterated++;
  31.     } else {
  32.         currentX -= xIncrement;
  33.         currentY -= yIncrement;
  34.         currentZ -= zIncrement;
  35.         thisLoc = new Location(tempWorld, currentX, currentY, currentZ);
  36.     }
  37.  
  38.     Block block = tempWorld.getBlockAt(thisLoc);
  39.  
  40.     if (block.getType() != Material.AIR) {
  41.         airOnly = false;
  42.         if (!Raziel.isTransparent(block.getType())) {
  43.             break VisibleCheck;
  44.         }
  45.     }
  46.  
  47.     for (Entity nearbyEntity : nearby) {
  48.         if (nearbyEntity.getType() == EntityType.PLAYER && !nearbyEntity.equals(player)) {
  49.             final LivingEntity living = (LivingEntity) nearbyEntity;
  50.             final Location loc = nearbyEntity.getLocation();
  51.            
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment