SHOW:
|
|
- or go back to the newest paste.
| 1 | - | public void farm(Block block) |
| 1 | + | public void farm(Block block) {
|
| 2 | - | {
|
| 2 | + | this.area++; |
| 3 | - | this.area++; |
| 3 | + | this.lastFarm = System.currentTimeMillis(); |
| 4 | - | this.lastFarm = System.currentTimeMillis(); |
| 4 | + | this.first = false; |
| 5 | - | this.first = false; |
| 5 | + | state.addBlockToRegen(block); |
| 6 | - | state.addBlockToRegen(block); |
| 6 | + | getColor().getBlock().apply(block); |
| 7 | - | getColor().getBlock().apply(block); |
| 7 | + | List < LinkedList < Block >> tracks = new ArrayList < LinkedList < Block >> (); |
| 8 | - | |
| 8 | + | List < LinkedList < Block >> closedPolygons = new ArrayList < LinkedList < Block >> (); |
| 9 | ||
| 10 | tracks.add(new LinkedList < Block > (Arrays.asList(block))); | |
| 11 | - | List<LinkedList<Block>> tracks = new ArrayList<LinkedList<Block>>(); |
| 11 | + | |
| 12 | - | List<LinkedList<Block>> closedPolygons = new ArrayList<LinkedList<Block>>(); |
| 12 | + | while (tracks.size() != 0) {
|
| 13 | - | |
| 13 | + | LinkedList < Block > track = tracks.get(0); |
| 14 | - | tracks.add(new LinkedList<Block>(Arrays.asList(block))); |
| 14 | + | Block currentBlock = track.getLast(); |
| 15 | - | |
| 15 | + | |
| 16 | - | while(tracks.size() != 0) |
| 16 | + | List < BlockFace > matchingFaces = new ArrayList < BlockFace > (); |
| 17 | - | {
|
| 17 | + | |
| 18 | - | LinkedList<Block> track = tracks.get(0); |
| 18 | + | for (BlockFace face: Arrays.asList(new BlockFace[] {
|
| 19 | - | Block currentBlock = track.getLast(); |
| 19 | + | BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST |
| 20 | - | |
| 20 | + | })) |
| 21 | - | List<BlockFace> matchingFaces = new ArrayList<BlockFace>(); |
| 21 | + | if (getColor().getBlock().match(currentBlock.getRelative(face))) matchingFaces.add(face); |
| 22 | - | |
| 22 | + | |
| 23 | - | for(BlockFace face : Arrays.asList(new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}))
|
| 23 | + | int index; |
| 24 | - | if(getColor().getBlock().match(currentBlock.getRelative(face))) |
| 24 | + | if ((index = track.indexOf(currentBlock)) > 0) matchingFaces.remove(currentBlock.getFace(track.get(index - 1))); |
| 25 | - | matchingFaces.add(face); |
| 25 | + | else if (matchingFaces.size() < 2) return; |
| 26 | - | |
| 26 | + | |
| 27 | - | int index; |
| 27 | + | if (matchingFaces.size() == 0) {
|
| 28 | - | if((index = track.indexOf(currentBlock)) > 0) |
| 28 | + | tracks.remove(track); |
| 29 | - | matchingFaces.remove(currentBlock.getFace(track.get(index - 1))); |
| 29 | + | continue; |
| 30 | - | else if(matchingFaces.size() < 2) |
| 30 | + | |
| 31 | - | return; |
| 31 | + | |
| 32 | - | |
| 32 | + | for (index = 0; index < matchingFaces.size(); index++) {
|
| 33 | - | if(matchingFaces.size() == 0) |
| 33 | + | if (track.contains(currentBlock.getRelative(matchingFaces.get(index)))) {
|
| 34 | - | {
|
| 34 | + | if (currentBlock.getRelative(matchingFaces.get(index)).equals(block)) closedPolygons.add(track); |
| 35 | - | tracks.remove(track); |
| 35 | + | tracks.remove(track); //crash ici |
| 36 | continue; | |
| 37 | } | |
| 38 | - | |
| 38 | + | |
| 39 | - | for(index = 0; index < matchingFaces.size(); index++) |
| 39 | + | if (index == matchingFaces.size() - 1) {
|
| 40 | - | {
|
| 40 | + | track.add(currentBlock.getRelative(matchingFaces.get(index))); |
| 41 | - | if(track.contains(currentBlock.getRelative(matchingFaces.get(index)))) |
| 41 | + | break; |
| 42 | - | {
|
| 42 | + | |
| 43 | - | if(currentBlock.getRelative(matchingFaces.get(index)).equals(block)) |
| 43 | + | |
| 44 | - | closedPolygons.add(track); |
| 44 | + | LinkedList < Block > newTrack = new LinkedList < Block > (track); |
| 45 | - | tracks.remove(track); //crash ici |
| 45 | + | newTrack.add(currentBlock.getRelative(matchingFaces.get(index))); |
| 46 | - | continue; |
| 46 | + | tracks.add(newTrack); |
| 47 | - | } |
| 47 | + | |
| 48 | - | |
| 48 | + | } |
| 49 | - | if(index == matchingFaces.size() - 1) |
| 49 | + | |
| 50 | - | {
|
| 50 | + | getPlayer().sendMessage("Polygons: " + closedPolygons.size());
|
| 51 | - | track.add(currentBlock.getRelative(matchingFaces.get(index))); |
| 51 | + | |
| 52 | - | break; |
| 52 | + | for (LinkedList < Block > polygon: closedPolygons) {
|
| 53 | - | } |
| 53 | + | int xPos[] = new int[polygon.size()], zPos[] = new int[polygon.size()]; |
| 54 | - | |
| 54 | + | |
| 55 | - | LinkedList<Block> newTrack = new LinkedList<Block>(track); |
| 55 | + | for (int i = 0; i < polygon.size(); i++) {
|
| 56 | - | newTrack.add(currentBlock.getRelative(matchingFaces.get(index))); |
| 56 | + | xPos[i] = polygon.get(i).getX(); |
| 57 | - | tracks.add(newTrack); |
| 57 | + | zPos[i] = polygon.get(i).getZ(); |
| 58 | } | |
| 59 | ||
| 60 | Polygon poly = new Polygon(xPos, zPos, polygon.size()); | |
| 61 | - | getPlayer().sendMessage("Polygons: " + closedPolygons.size());
|
| 61 | + | |
| 62 | - | |
| 62 | + | List < Block > contained = new ArrayList < Block > (); |
| 63 | - | for(LinkedList<Block> polygon : closedPolygons) |
| 63 | + | |
| 64 | - | {
|
| 64 | + | int minX = MathUtil.getMin(xPos), maxX = MathUtil.getMax(xPos) + 1; |
| 65 | - | int xPos[] = new int[polygon.size()], zPos[] = new int[polygon.size()]; |
| 65 | + | int minZ = MathUtil.getMin(zPos), maxZ = MathUtil.getMax(zPos) + 1; |
| 66 | - | |
| 66 | + | |
| 67 | - | for(int i = 0; i < polygon.size(); i++) |
| 67 | + | for (int x = minX; x < maxX; x++) |
| 68 | - | {
|
| 68 | + | for (int z = minZ; z < maxZ; z++) |
| 69 | - | xPos[i] = polygon.get(i).getX(); |
| 69 | + | if (poly.contains(x, z)) contained.add(block.getWorld().getBlockAt(x, block.getY(), z)); |
| 70 | - | zPos[i] = polygon.get(i).getZ(); |
| 70 | + | |
| 71 | boolean doContinue = false; | |
| 72 | - | |
| 72 | + | |
| 73 | - | Polygon poly = new Polygon(xPos, zPos, polygon.size()); |
| 73 | + | for (Block containedBlock: contained) {
|
| 74 | - | |
| 74 | + | if (!((BlockFarmersConfig) state.getGame().getConfig()).canFarm(containedBlock)) {
|
| 75 | - | List<Block> contained = new ArrayList<Block>(); |
| 75 | + | doContinue = true; |
| 76 | - | |
| 76 | + | break; |
| 77 | - | int minX = MathUtil.getMin(xPos), maxX = MathUtil.getMax(xPos) + 1; |
| 77 | + | |
| 78 | - | int minZ = MathUtil.getMin(zPos), maxZ = MathUtil.getMax(zPos) + 1; |
| 78 | + | |
| 79 | - | |
| 79 | + | |
| 80 | - | for(int x = minX; x < maxX; x++) |
| 80 | + | getPlayer().sendMessage(" Blocks: " + contained.size());
|
| 81 | - | for(int z = minZ; z < maxZ; z++) |
| 81 | + | |
| 82 | - | if(poly.contains(x, z)) |
| 82 | + | if (doContinue) continue; |
| 83 | - | contained.add(block.getWorld().getBlockAt(x, block.getY(), z)); |
| 83 | + | |
| 84 | - | |
| 84 | + | for (Block containedBlock: contained) {
|
| 85 | - | boolean doContinue = false; |
| 85 | + | state.addBlockToRegen(containedBlock); |
| 86 | - | |
| 86 | + | getColor().getBlock().apply(containedBlock); |
| 87 | - | for(Block containedBlock : contained) |
| 87 | + | |
| 88 | - | {
|
| 88 | + | } |
| 89 | - | if(!((BlockFarmersConfig) state.getGame().getConfig()).canFarm(containedBlock)) |
| 89 | + | |
| 90 | - | {
|
| 90 | + | } |