@Override public void execute(SyncBlockList aSyncList) { fMaze.build(); initializeArea(); if (!ceilingInTopLevel) { for (int x = 0; x < fMaze.width; x++) { for (int z = 0; z < fMaze.depth; z++) { Maze.Cell lCell = fMaze.get(x, fMaze.height - 1, z); lCell.links[Maze.DirectionTop].broken = true; } } } for (Passage lPas : passages) { Maze.Cell lCell = null; if (lPas.mazePos.x >= 0) { lCell = fMaze.get(lPas.mazePos.x, lPas.mazePos.y, lPas.mazePos.z); } else { int x = (lPas.pos.x - (borderThickness + wallThickness)) / (corridorWidth + wallThickness); int y = (lPas.pos.y - (borderThickness + ceilingThickness)) / (corridorHeight + ceilingThickness); int z = (lPas.pos.z - (borderThickness + wallThickness)) / (corridorWidth + wallThickness); if (x < 0) x = 0; if (x > fMaze.width) x = fMaze.width - 1; if (y < 0) y = 0; if (y > fMaze.height) y = fMaze.height - 1; if (z < 0) z = 0; if (z > fMaze.depth) z = fMaze.depth - 1; lCell = fMaze.get(x, y, z); } if (lPas.up) lCell.links[Maze.DirectionTop].broken = true; if (lPas.down) lCell.links[Maze.DirectionBottom].broken = true; if (lPas.left) lCell.links[Maze.DirectionLeft].broken = true; if (lPas.right) lCell.links[Maze.DirectionRight].broken = true; if (lPas.forward) lCell.links[Maze.DirectionForward].broken = true; if (lPas.backward) lCell.links[Maze.DirectionBackward].broken = true; } for (int x = 0; x < fMaze.width; x++) { for (int y = 0; y < fMaze.height; y++) { for (int z = 0; z < fMaze.depth; z++) { Maze.Cell lCell = fMaze.get(x, y, z); setCellEmpty(x, y, z); for (int d = 0; d < 6; d++) { if (lCell.links[d].broken) { breakWall(x, y, z, d); } } } } } if (placeTorches) { Random lRnd = new Random(); for (int x = 0; x < fMaze.width; x++) { for (int y = 0; y < fMaze.height; y++) { for (int z = 0; z < fMaze.depth; z++) { Maze.Cell lCell = fMaze.get(x, y, z); if (!lCell.links[Maze.DirectionBottom].broken) { if (lRnd.nextInt(100) < chanceForTorches) { BlockAreaItem lItem = area.get(getX(x), getY(y), getZ(z)); lItem.id = Material.TORCH.getId(); lItem.data = (byte) 5; } } } } } } if (placeLadders && fMaze.height > 1) { for (int x = 0; x < fMaze.width; x++) { for (int y = 0; y < (fMaze.height - 1); y++) { for (int z = 0; z < fMaze.depth; z++) { Maze.Cell lCell = fMaze.get(x, y, z); if (lCell.links[Maze.DirectionTop].broken) { Maze.Cell lCellTop = fMaze.get(x, y + 1, z); for (int d = 2; d < 6; d++) { if (!lCell.links[d].broken && !lCellTop.links[d].broken) { int lcx = 0; int lcz = 0; if (fMaze.getDeltaX(d) > 0) { lcx = corridorWidth - 1; } if (fMaze.getDeltaZ(d) > 0) { lcz = corridorWidth - 1; } for (int ldy = 0; ldy < (corridorHeight * 2 + ceilingThickness); ldy++) { BlockAreaItem lItem = area.get(getX(x) + lcx, getY(y) + ldy, getZ(z) + lcz); lItem.id = Material.LADDER.getId(); lItem.data = (byte) fMazeToLadderDirs[d]; } break; } } } } } } } if (placeChests) { Random lRnd = new Random(); for (int x = 0; x < fMaze.width; x++) { for (int y = 0; y < fMaze.height; y++) { for (int z = 0; z < fMaze.depth; z++) { Maze.Cell lCell = fMaze.get(x, y, z); if (!lCell.links[Maze.DirectionTop].broken && !lCell.links[Maze.DirectionBottom].broken) { int lBCount = 0; int lFDir = 0; for (int d = 2; d < 6; d++) { if (lCell.links[d].broken) { lBCount++; } else { lFDir = d; } } if (lBCount < 2 && lRnd.nextInt(100) < chanceForChests) { BlockAreaItem lItem = area.get(getX(x), getY(y), getZ(z)); lItem.id = Material.CHEST.getId(); lItem.data = (byte) fMazeToLadderDirs[lFDir]; lItem.itemStacks = chestItems.getNext(y); /*lItem.itemStacks = new ItemStack[1]; lItem.itemStacks[0] = new ItemStack(Material.GOLD_BLOCK, 1, (short)0, (byte)0);*/ } } } } } } if (placeWoodenDoors) { Random lRnd = new Random(); for (int x = 0; x < fMaze.width; x++) { for (int y = 0; y < fMaze.height; y++) { for (int z = 0; z < fMaze.depth; z++) { Maze.Cell lCell = fMaze.get(x, y, z); if (!lCell.links[Maze.DirectionTop].broken && !lCell.links[Maze.DirectionBottom].broken) { for (int d = 2; d < 6; d++) { if (lCell.links[d].broken && lRnd.nextInt(100) < chanceForWoodenDoors) { int lcx = fMaze.getDeltaX(d) > 0 ? corridorWidth : 0; int lcz = fMaze.getDeltaZ(d) > 0 ? corridorWidth : 0; int xx = getX(x); int yy = getY(y); int zz = getZ(z); int lfx = fMaze.getDeltaZ(d) > 0 ? 1 : 0; int lfz = fMaze.getDeltaX(d) > 0 ? 1 : 0; for (int ld = 0; ld < corridorWidth; ld++) { for (int ly = 0; ly < corridorHeight; ly++) { if (ld > 0 || ly > 1) { BlockAreaItem lItem = area.get(xx + lcx + lfx * ld, yy + ly, zz + lcz + lfz * ld); Mat lMat = wallMaterials.getNext(y); lItem.id = lMat.material.getId(); lItem.data = lMat.data; } else { BlockAreaItem lItem = area.get(xx + lcx + lfx * ld, yy + ly, zz + lcz + lfz * ld); lItem.id = Material.WOODEN_DOOR.getId(); lItem.data = (byte) (ly > 0 ? 8 : 0); } } } break; } } } } } } } if (placeEntities) { Random lRnd = new Random(); for (int x = 0; x < fMaze.width; x++) { for (int y = 0; y < fMaze.height; y++) { for (int z = 0; z < fMaze.depth; z++) { for (EntityItem lItem : entities) { if (lRnd.nextInt(100) < lItem.chance) { BlockPosition lPos = new BlockPosition(getX(x), getY(y), getZ(z)); int lCount = lItem.amount; if (lCount < lItem.maxAmount) { lCount += lRnd.nextInt(lItem.maxAmount - lCount + 1); } for (int i = 0; i < lCount; i++) { BlockAreaEntity lEntity = area.newEntity(); lEntity.type = lItem.type; lEntity.location = lPos; } } } } } } } /* Statistics int fStats[] = new int[6]; fStats[0]=fStats[1]=fStats[2]=fStats[3]=fStats[4]=fStats[5]=0; for(int x=0; x<fMaze.width; x++) { for(int y=0; y<fMaze.height; y++) { for(int z=0; z<fMaze.depth; z++) { Maze.Cell lCell = fMaze.get(x, y, z); for(int d=0; d<6;d++) { if (lCell.links[d].broken) { fStats[d]++; } } } } } quest.log("0=" + fStats[0] + " 1=" + fStats[1] + " 2=" + fStats[2] + " 3=" + fStats[3] + " 4=" + fStats[4] + " 5=" + fStats[5]); */ area.toList(aSyncList, from, blockPlaceMode); }
protected void initializeArea() { if (wallMaterials.isEmpty() && floorMaterials.isEmpty()) { area.clear(fMat, baseMaterialData); } else { area.clear(fMat, baseMaterialData); for (int x = 0; x < fMaze.width; x++) { for (int y = 0; y < fMaze.height; y++) { for (int z = 0; z < fMaze.depth; z++) { int xx = getX(x); int yy = getY(y); int zz = getZ(z); for (int lx = 0; lx < corridorWidth; lx++) { for (int lz = 0; lz < corridorWidth; lz++) { BlockAreaItem lItem; Mat lMat; lItem = area.get(xx + lx, yy - 1, zz + lz); lMat = floorMaterials.getNext(y); lItem.id = lMat.material.getId(); lItem.data = lMat.data; lItem = area.get(xx + lx, yy + corridorHeight, zz + lz); lMat = ceilingMaterials.getNext(y); lItem.id = lMat.material.getId(); lItem.data = lMat.data; } } for (int ly = 0; ly < corridorHeight; ly++) { for (int lx = 0; lx < corridorWidth; lx++) { BlockAreaItem lItem; Mat lMat; lItem = area.get(xx + lx, yy + ly, zz - 1); lMat = wallMaterials.getNext(y); lItem.id = lMat.material.getId(); lItem.data = lMat.data; lItem = area.get(xx + lx, yy + ly, zz + corridorWidth); lMat = wallMaterials.getNext(y); lItem.id = lMat.material.getId(); lItem.data = lMat.data; } for (int lz = 0; lz < corridorWidth; lz++) { BlockAreaItem lItem; Mat lMat; lItem = area.get(xx - 1, yy + ly, zz + lz); lMat = wallMaterials.getNext(y); lItem.id = lMat.material.getId(); lItem.data = lMat.data; lItem = area.get(xx + corridorWidth, yy + ly, zz + lz); lMat = wallMaterials.getNext(y); lItem.id = lMat.material.getId(); lItem.data = lMat.data; } } } } } } }