Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<ChunkCoordinates> getStructureGeneration(boolean firstTimeScan) {
- return getStructureGeneration(firstTimeScan, false); //default to wall behavior
- }
- /*
- * firstTimeScan: makes it generate the heightmap, should only be true when the area is in natural state, if false it depends on the heightmap
- * scanForStraitPath: Path behavior,
- */
- public List<ChunkCoordinates> getStructureGeneration(boolean firstTimeScan, boolean scanForStraitPath) {
- //does the math, needs first time init knowledge
- //if firstTimeScan true, we scan for ground from world data
- //if firstTimeScan false, we use the heightmap to know how far down to scan
- //passes/erases through trees etc from top down scan, hits a proper ground
- //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
- //pattern config
- double stepDistLength = 0.3D;
- double stepDistThickness = 0.5D;
- double thickness2 = (double)thickness/2D;
- //int lastTopY = this.team.spawn.posY;
- //needs move
- //int blockID = Block.cobblestone.blockID;
- List<ChunkCoordinates> data = new ArrayList<ChunkCoordinates>();
- List<Integer> redundancyData = new ArrayList<Integer>();
- World world = DimensionManager.getWorld(team.dimID);
- if (world != null) {
- double vecX = posPointEnd.posX - posPointStart.posX;
- double vecY = (posPointEnd.posY+height-1) - (posPointStart.posY+height-1);
- double vecZ = posPointEnd.posZ - posPointStart.posZ;
- if (!scanForStraitPath) {
- vecY = (posPointStart.posY+height-1) - (posPointStart.posY+height-1);
- }
- double dist = (double)Math.sqrt(vecX * vecX + vecY * vecY + vecZ * vecZ);
- for (double curDist = 0 - thickness2; curDist <= dist + thickness2; curDist += stepDistLength) {
- double posX = posPointStart.posX + (vecX / dist * curDist);
- double posY = (posPointStart.posY+height-1) + (vecY / dist * curDist);
- double posZ = posPointStart.posZ + (vecZ / dist * curDist);
- Vec3 vec = Vec3.createVectorHelper(vecX / dist, vecY / dist, vecZ / dist);
- vec.rotateAroundY((float) Math.toRadians(90));
- for (double i = -thickness2; i < thickness2; i+=stepDistThickness) {
- int posXInt = MathHelper.floor_double(posX + (vec.xCoord * i));
- int posYInt = MathHelper.floor_double(posY);
- int posZInt = MathHelper.floor_double(posZ + (vec.zCoord * i));
- //double posX2 = posX + vec.xCoord * i;
- //double posZ2 = posZ + vec.zCoord * i;
- int topY = 127; //temp default to help debug, fail = its in the air
- if (firstTimeScan) {
- topY = posYInt;
- if (!scanForStraitPath) {
- int id = world.getBlockId(posXInt, topY, posZInt);
- while (id != 0) id = world.getBlockId(posXInt, ++topY, posZInt);
- topY = getTopGroundBlock(world, posXInt, topY, posZInt);
- }
- heightMap.put(ChunkCoordIntPair.chunkXZ2Int(posXInt, posZInt), topY); //has redundant additions, ok because its a hashmap
- } else {
- //ChunkCoordIntPair pair = new ChunkCoordIntPair(MathHelper.floor_double(posX), MathHelper.floor_double(posZ));
- if (heightMap.containsKey(ChunkCoordIntPair.chunkXZ2Int(posXInt, posZInt))) {
- 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
- } else {
- System.out.println("CRITICAL: MultiLinkedLine getStructureGeneration() heightmap missing data or vector generation changed since firstTimeScan run");
- }
- }
- for (int ii = posYInt; ii >= topY; ii--) {
- int id = world.getBlockId(posXInt, ii, posZInt);
- if (isSafeToGenerateOver(id)) {
- ChunkCoordinates coords = new ChunkCoordinates(posXInt, ii, posZInt);
- //System.out.println("coords.hashCode() " + PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ));
- if (!redundancyData.contains(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ))) {
- data.add(coords);
- redundancyData.add(PathPointEx.makeHash(coords.posX, coords.posY, coords.posZ));
- }
- //world.setBlock(posXInt, ii, posZInt, blockID);
- }
- }
- }
- }
- } else {
- System.out.println("critical error world obj null");
- }
- return data;
- }
- public int getStructureHealth(List<ChunkCoordinates> parStructure, boolean andUpdateMaxHealth) {
- float totalHealthCur = 0;
- float totalHealthMax = 0; //only accurate when this is run on a fully untouched building (no block removals)
- World world = DimensionManager.getWorld(team.dimID);
- int blockCount = 0;
- if (world != null) {
- for (int i = 0; i < parStructure.size(); i++) {
- ChunkCoordinates coords = parStructure.get(i);
- int x = coords.posX;
- int y = coords.posY;
- int z = coords.posZ;
- int id = world.getBlockId(x, y, z);
- //System.out.println("coords: " + x + " - " + y + " - " + z + " = " + id);
- if (id != 0) {
- blockCount++;
- BlockDataPoint bdp = ServerTickHandler.wd.getBlockDataGrid(world).getBlockDataIfExists(x, y, z);
- float maxHealth = BlockStaticDataMap.getBlockMaxHealth(id);
- if (bdp == null) {
- totalHealthCur += maxHealth;
- } else {
- totalHealthCur += bdp.health;
- //System.out.println("bdp.health " + bdp.health);
- }
- totalHealthMax += maxHealth;
- }
- }
- }
- if (andUpdateMaxHealth) {
- healthMax = (int)totalHealthMax;
- }
- System.out.println("blockCount: " + blockCount);
- return (int)totalHealthCur;
- }
- public void print(List<ChunkCoordinates> parStructure) {
- int blockID = Block.cobblestone.blockID;
- World world = DimensionManager.getWorld(team.dimID);
- if (world != null) {
- for (int i = 0; i < parStructure.size(); i++) {
- ChunkCoordinates coords = parStructure.get(i);
- world.setBlock(coords.posX, coords.posY, coords.posZ, blockID);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement