Advertisement
Corosus

Untitled

Dec 21st, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.63 KB | None | 0 0
  1. public List<ChunkCoordinatesBlock> getStructureGenerationPattern(List<ChunkCoordinatesBlock> parData, List<Integer> redundancyData, boolean firstTimeScan, boolean scanForStraitPath) {
  2.        
  3.         //does the math, needs first time init knowledge
  4.        
  5.         //if firstTimeScan true, we scan for ground from world data
  6.         //if firstTimeScan false, we use the heightmap to know how far down to scan
  7.        
  8.         //passes/erases through trees etc from top down scan, hits a proper ground
  9.        
  10.         //where does air space for walkability through come into play? added in here or outside this? if set here, health calculator could skip it fairly easily
  11.        
  12.         //pattern config
  13.         double stepDistLength = 0.3D;
  14.         double stepDistThickness = 0.5D;
  15.         double thickness2 = (double)thickness/2D;
  16.         //int lastTopY = this.team.spawn.posY;
  17.        
  18.         int blockIDGen = getGenBlockBase();
  19.        
  20.         //List<ChunkCoordinates> data = new ArrayList<ChunkCoordinates>();
  21.         //List<Integer> redundancyData = new ArrayList<Integer>();
  22.        
  23.         double rot = getAngle();
  24.        
  25.         //rot = 222;
  26.        
  27.         if (rot < 0) rot += 360;
  28.         while (rot > 90) rot -= 90;
  29.         double val = Math.max(0.0D, Math.abs(Math.cos(Math.toRadians(rot-45))) * 1.0D);
  30.        
  31.         //System.out.println(val);
  32.        
  33.         World world = DimensionManager.getWorld(team.dimID);
  34.         if (world != null) {
  35.            
  36.             double vecX = posPointEnd.posX - posPointStart.posX;
  37.             double vecY = (posPointEnd.posY+height-1) - (posPointStart.posY+height-1);
  38.             double vecZ = posPointEnd.posZ - posPointStart.posZ;
  39.            
  40.             if (!scanForStraitPath) {
  41.                 vecY = (posPointStart.posY+height-1) - (posPointStart.posY+height-1);
  42.             }
  43.  
  44.             double dist = (double)Math.sqrt(vecX * vecX + vecY * vecY + vecZ * vecZ);
  45.            
  46.             for (double curDist = 0 - thickness2; curDist <= dist + thickness2; curDist += stepDistLength) {
  47.                 double posX = posPointStart.posX + (vecX / dist * curDist);
  48.                 double posY = (posPointStart.posY+height-1) + (vecY / dist * curDist);
  49.                 double posZ = posPointStart.posZ + (vecZ / dist * curDist);
  50.                
  51.                 Vec3 vec = Vec3.createVectorHelper(vecX / dist, vecY / dist, vecZ / dist);
  52.                 vec.rotateAroundY((float) Math.toRadians(90));
  53.                
  54.                
  55.                
  56.                 for (double i = -thickness2; i-stepDistThickness < thickness2; i += stepDistThickness) {
  57.                    
  58.                     int posXInt = MathHelper.floor_double(posX + (vec.xCoord * i));
  59.                     int posYInt = MathHelper.floor_double(posY);
  60.                    
  61.                     int posZInt = MathHelper.floor_double(posZ + (vec.zCoord * i));
  62.                    
  63.                     //double posX2 = posX + vec.xCoord * i;
  64.                     //double posZ2 = posZ + vec.zCoord * i;
  65.                    
  66.                     int topY = 127; //temp default to help debug, fail = its in the air
  67.                     if (firstTimeScan) {
  68.                         topY = posYInt;
  69.                         if (!scanForStraitPath) {
  70.                             int id = world.getBlockId(posXInt, topY, posZInt);
  71.                             while (id != 0) id = world.getBlockId(posXInt, ++topY, posZInt);
  72.                             topY = getTopGroundBlock(world, posXInt, topY, posZInt);
  73.                         }
  74.                         heightMap.put(ChunkCoordIntPair.chunkXZ2Int(posXInt, posZInt), topY); //has redundant additions, ok because its a hashmap
  75.                     } else {
  76.                         //ChunkCoordIntPair pair = new ChunkCoordIntPair(MathHelper.floor_double(posX), MathHelper.floor_double(posZ));
  77.                         if (heightMap.containsKey(ChunkCoordIntPair.chunkXZ2Int(posXInt, posZInt))) {
  78.                             topY = 0+heightMap.get(ChunkCoordIntPair.chunkXZ2Int(posXInt, posZInt)); //why 1+ exactly? where does the y mismatch happen? first gen has a missing y layer, other ones dont
  79.                         } else {
  80.                             //System.out.println("CRITICAL: MultiLinkedLine getStructureGeneration() heightmap missing data or vector generation changed since firstTimeScan run");
  81.                         }
  82.                     }
  83.                    
  84.                     //downwards gen
  85.                     for (int ii = posYInt; ii >= topY; ii--) {
  86.                         int id = world.getBlockId(posXInt, ii, posZInt);
  87.                        
  88.                         //if (id == 0/*isSafeToGenerateOver(id)*/) {
  89.                             ChunkCoordinatesBlock coords = new ChunkCoordinatesBlock(posXInt, ii, posZInt, blockIDGen);
  90.                             //System.out.println("coords.hashCode() " + PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ));
  91.                             if (!redundancyData.contains(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ))) {
  92.                                 parData.add(coords);
  93.                                 redundancyData.add(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ));
  94.                             }
  95.                            
  96.                             //world.setBlock(posXInt, ii, posZInt, blockID);
  97.                         //}
  98.                     }
  99.                    
  100.                     if (curDist > thickness2/2 && curDist < dist - thickness2/2) {
  101.                         if (/*i == -thickness2 || */i-val <= -thickness2 || i+stepDistThickness+val >= thickness2) {
  102.                             int id = world.getBlockId(posXInt, posYInt+1, posZInt);
  103.                             //if (id == 0/*isSafeToGenerateOver(id)*/) {
  104.                                 ChunkCoordinatesBlock coords = new ChunkCoordinatesBlock(posXInt, posYInt+1, posZInt, getGenBlockRailing());
  105.                                 if (!redundancyData.contains(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ))) {
  106.                                     parData.add(coords);
  107.                                     redundancyData.add(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ));
  108.                                 }
  109.                             //}
  110.                         }
  111.                     }
  112.                    
  113.                     //upwards air clearance gen
  114.                     for (int ii = posYInt+1; ii < posYInt+1+walkwayYClearance; ii++) {
  115.                         int id = world.getBlockId(posXInt, ii, posZInt);
  116.                         ChunkCoordinatesBlock coords = new ChunkCoordinatesBlock(posXInt, ii, posZInt, 0);
  117.                         if (!redundancyData.contains(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ))) {
  118.                             parData.add(coords);
  119.                             redundancyData.add(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ));
  120.                         }
  121.                     }
  122.                    
  123.                     //railings
  124.                    
  125.                    
  126.                 }
  127.             }
  128.         } else {
  129.             System.out.println("critical error world obj null");
  130.         }
  131.        
  132.         return parData;
  133.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement