Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void farm(Block block) {
- this.area++;
- this.lastFarm = System.currentTimeMillis();
- this.first = false;
- state.addBlockToRegen(block);
- getColor().getBlock().apply(block);
- List < LinkedList < Block >> tracks = new ArrayList < LinkedList < Block >> ();
- List < LinkedList < Block >> closedPolygons = new ArrayList < LinkedList < Block >> ();
- tracks.add(new LinkedList < Block > (Arrays.asList(block)));
- while (tracks.size() != 0) {
- LinkedList < Block > track = tracks.get(0);
- Block currentBlock = track.getLast();
- List < BlockFace > matchingFaces = new ArrayList < BlockFace > ();
- for (BlockFace face: Arrays.asList(new BlockFace[] {
- BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST
- }))
- if (getColor().getBlock().match(currentBlock.getRelative(face))) matchingFaces.add(face);
- int index;
- if ((index = track.indexOf(currentBlock)) > 0) matchingFaces.remove(currentBlock.getFace(track.get(index - 1)));
- else if (matchingFaces.size() < 2) return;
- if (matchingFaces.size() == 0) {
- tracks.remove(track);
- continue;
- }
- for (index = 0; index < matchingFaces.size(); index++) {
- if (track.contains(currentBlock.getRelative(matchingFaces.get(index)))) {
- if (currentBlock.getRelative(matchingFaces.get(index)).equals(block)) closedPolygons.add(track);
- tracks.remove(track); //crash ici
- continue;
- }
- if (index == matchingFaces.size() - 1) {
- track.add(currentBlock.getRelative(matchingFaces.get(index)));
- break;
- }
- LinkedList < Block > newTrack = new LinkedList < Block > (track);
- newTrack.add(currentBlock.getRelative(matchingFaces.get(index)));
- tracks.add(newTrack);
- }
- }
- getPlayer().sendMessage("Polygons: " + closedPolygons.size());
- for (LinkedList < Block > polygon: closedPolygons) {
- int xPos[] = new int[polygon.size()], zPos[] = new int[polygon.size()];
- for (int i = 0; i < polygon.size(); i++) {
- xPos[i] = polygon.get(i).getX();
- zPos[i] = polygon.get(i).getZ();
- }
- Polygon poly = new Polygon(xPos, zPos, polygon.size());
- List < Block > contained = new ArrayList < Block > ();
- int minX = MathUtil.getMin(xPos), maxX = MathUtil.getMax(xPos) + 1;
- int minZ = MathUtil.getMin(zPos), maxZ = MathUtil.getMax(zPos) + 1;
- for (int x = minX; x < maxX; x++)
- for (int z = minZ; z < maxZ; z++)
- if (poly.contains(x, z)) contained.add(block.getWorld().getBlockAt(x, block.getY(), z));
- boolean doContinue = false;
- for (Block containedBlock: contained) {
- if (!((BlockFarmersConfig) state.getGame().getConfig()).canFarm(containedBlock)) {
- doContinue = true;
- break;
- }
- }
- getPlayer().sendMessage(" Blocks: " + contained.size());
- if (doContinue) continue;
- for (Block containedBlock: contained) {
- state.addBlockToRegen(containedBlock);
- getColor().getBlock().apply(containedBlock);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment