Advertisement
Corosus

Untitled

Dec 21st, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.05 KB | None | 0 0
  1. public List<ChunkCoordinates> getStructureGeneration(boolean firstTimeScan) {
  2.         return getStructureGeneration(firstTimeScan, false); //default to wall behavior
  3.     }
  4.    
  5.     /*
  6.      * firstTimeScan: makes it generate the heightmap, should only be true when the area is in natural state, if false it depends on the heightmap
  7.      * scanForStraitPath: Path behavior,
  8.      */
  9.     public List<ChunkCoordinates> getStructureGeneration(boolean firstTimeScan, boolean scanForStraitPath) {
  10.        
  11.         //does the math, needs first time init knowledge
  12.        
  13.         //if firstTimeScan true, we scan for ground from world data
  14.         //if firstTimeScan false, we use the heightmap to know how far down to scan
  15.        
  16.         //passes/erases through trees etc from top down scan, hits a proper ground
  17.        
  18.         //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
  19.        
  20.         //pattern config
  21.         double stepDistLength = 0.3D;
  22.         double stepDistThickness = 0.5D;
  23.         double thickness2 = (double)thickness/2D;
  24.         //int lastTopY = this.team.spawn.posY;
  25.        
  26.         //needs move
  27.         //int blockID = Block.cobblestone.blockID;
  28.        
  29.         List<ChunkCoordinates> data = new ArrayList<ChunkCoordinates>();
  30.         List<Integer> redundancyData = new ArrayList<Integer>();
  31.        
  32.         World world = DimensionManager.getWorld(team.dimID);
  33.         if (world != null) {
  34.            
  35.             double vecX = posPointEnd.posX - posPointStart.posX;
  36.             double vecY = (posPointEnd.posY+height-1) - (posPointStart.posY+height-1);
  37.             double vecZ = posPointEnd.posZ - posPointStart.posZ;
  38.            
  39.             if (!scanForStraitPath) {
  40.                 vecY = (posPointStart.posY+height-1) - (posPointStart.posY+height-1);
  41.             }
  42.  
  43.             double dist = (double)Math.sqrt(vecX * vecX + vecY * vecY + vecZ * vecZ);
  44.            
  45.             for (double curDist = 0 - thickness2; curDist <= dist + thickness2; curDist += stepDistLength) {
  46.                 double posX = posPointStart.posX + (vecX / dist * curDist);
  47.                 double posY = (posPointStart.posY+height-1) + (vecY / dist * curDist);
  48.                 double posZ = posPointStart.posZ + (vecZ / dist * curDist);
  49.                
  50.                 Vec3 vec = Vec3.createVectorHelper(vecX / dist, vecY / dist, vecZ / dist);
  51.                 vec.rotateAroundY((float) Math.toRadians(90));
  52.                
  53.                
  54.                
  55.                 for (double i = -thickness2; i < thickness2; i+=stepDistThickness) {
  56.                    
  57.                     int posXInt = MathHelper.floor_double(posX + (vec.xCoord * i));
  58.                     int posYInt = MathHelper.floor_double(posY);
  59.                    
  60.                     int posZInt = MathHelper.floor_double(posZ + (vec.zCoord * i));
  61.                    
  62.                     //double posX2 = posX + vec.xCoord * i;
  63.                     //double posZ2 = posZ + vec.zCoord * i;
  64.                    
  65.                     int topY = 127; //temp default to help debug, fail = its in the air
  66.                     if (firstTimeScan) {
  67.                         topY = posYInt;
  68.                         if (!scanForStraitPath) {
  69.                             int id = world.getBlockId(posXInt, topY, posZInt);
  70.                             while (id != 0) id = world.getBlockId(posXInt, ++topY, posZInt);
  71.                             topY = getTopGroundBlock(world, posXInt, topY, posZInt);
  72.                         }
  73.                         heightMap.put(ChunkCoordIntPair.chunkXZ2Int(posXInt, posZInt), topY); //has redundant additions, ok because its a hashmap
  74.                     } else {
  75.                         //ChunkCoordIntPair pair = new ChunkCoordIntPair(MathHelper.floor_double(posX), MathHelper.floor_double(posZ));
  76.                         if (heightMap.containsKey(ChunkCoordIntPair.chunkXZ2Int(posXInt, posZInt))) {
  77.                             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
  78.                         } else {
  79.                             System.out.println("CRITICAL: MultiLinkedLine getStructureGeneration() heightmap missing data or vector generation changed since firstTimeScan run");
  80.                         }
  81.                     }
  82.                    
  83.                     for (int ii = posYInt; ii >= topY; ii--) {
  84.                         int id = world.getBlockId(posXInt, ii, posZInt);
  85.                        
  86.                         if (isSafeToGenerateOver(id)) {
  87.                             ChunkCoordinates coords = new ChunkCoordinates(posXInt, ii, posZInt);
  88.                             //System.out.println("coords.hashCode() " + PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ));
  89.                             if (!redundancyData.contains(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ))) {
  90.                                 data.add(coords);
  91.                                 redundancyData.add(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ));
  92.                             }
  93.                            
  94.                             //world.setBlock(posXInt, ii, posZInt, blockID);
  95.                         }
  96.                     }
  97.                    
  98.                 }
  99.             }
  100.         } else {
  101.             System.out.println("critical error world obj null");
  102.         }
  103.        
  104.         return data;
  105.     }
  106.  
  107. public int getStructureHealth(List<ChunkCoordinates> parStructure, boolean andUpdateMaxHealth) {
  108.         float totalHealthCur = 0;
  109.         float totalHealthMax = 0; //only accurate when this is run on a fully untouched building (no block removals)
  110.         World world = DimensionManager.getWorld(team.dimID);
  111.         int blockCount = 0;
  112.         if (world != null) {
  113.             for (int i = 0; i < parStructure.size(); i++) {
  114.                 ChunkCoordinates coords = parStructure.get(i);
  115.                 int x = coords.posX;
  116.                 int y = coords.posY;
  117.                 int z = coords.posZ;
  118.                
  119.                 int id = world.getBlockId(x, y, z);
  120.                 //System.out.println("coords: " + x + " - " + y + " - " + z + " = " + id);
  121.                 if (id != 0) {
  122.                     blockCount++;
  123.                     BlockDataPoint bdp = ServerTickHandler.wd.getBlockDataGrid(world).getBlockDataIfExists(x, y, z);
  124.                     float maxHealth = BlockStaticDataMap.getBlockMaxHealth(id);
  125.                     if (bdp == null) {
  126.                         totalHealthCur += maxHealth;
  127.                     } else {
  128.                         totalHealthCur += bdp.health;
  129.                         //System.out.println("bdp.health " + bdp.health);
  130.                     }
  131.                     totalHealthMax += maxHealth;
  132.                 }
  133.                
  134.             }
  135.         }
  136.         if (andUpdateMaxHealth) {
  137.             healthMax = (int)totalHealthMax;
  138.         }
  139.         System.out.println("blockCount: " + blockCount);
  140.        
  141.         return (int)totalHealthCur;
  142.     }
  143.    
  144.     public void print(List<ChunkCoordinates> parStructure) {
  145.         int blockID = Block.cobblestone.blockID;
  146.         World world = DimensionManager.getWorld(team.dimID);
  147.         if (world != null) {
  148.             for (int i = 0; i < parStructure.size(); i++) {
  149.                 ChunkCoordinates coords = parStructure.get(i);
  150.                 world.setBlock(coords.posX, coords.posY, coords.posZ, blockID);
  151.             }
  152.         }
  153.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement