303

pyramids

303
Mar 28th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.73 KB | None | 0 0
  1. package net.minecraft.src;
  2. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  3. // Jad home page: http://www.kpdus.com/jad.html
  4. // Decompiler options: packimports(3) braces deadcode
  5.  
  6. import java.util.Random;
  7.  
  8. public class WorldGenPyramid extends WorldGenerator {
  9.  
  10.     public WorldGenPyramid() {
  11.     }
  12.  
  13.  
  14.     public boolean generate(World world, Random random, int i, int j, int k) {
  15.         //if(world.getBlockId(i + random.nextInt(16), j, k + random.nextInt(16)) == Block.sand.blockID )
  16.         // mummy pyramid init
  17.         pyramids = 298;
  18.         rows = 35;
  19.         columns = 35;
  20.         backgroundCode = 0;
  21.         wallCode = 20;  //7
  22.         pathCode = 15;
  23.         emptyCode = 0;
  24.         visitedCode = 4;
  25.         maze = new int[rows+1][columns+1];
  26.         /*
  27.            int area = 0;
  28.            for(int c = 0; c < 20; c++)
  29.            {
  30.  
  31.            area += world.getBlockId(i, j + c + 1, k);
  32.  
  33.  
  34.            }
  35.            */
  36.         int area = 0;
  37.  
  38.         for(int ii = 0; ii < 20; ii += 2) {
  39.             for(int i1 = -2 + ii; i1 < rows - ii + 2; i1 += 2) {
  40.                 for(int j1 = -2 + ii; j1 < columns - ii + 2; j1 += 2) {
  41.                     if(world.getBlockId(i + i1, j + ii, k + j1) !=0) area++;
  42.                 }
  43.             }
  44.         }
  45.  
  46.         ModLoader.getMinecraftInstance().ingameGUI.addChatMessage("PYARMID RESULTS :" + String.valueOf(area));
  47.  
  48.         if(world.getBlockId(i + random.nextInt(16), j-1, k + random.nextInt(16)) == 12 && area < 200)
  49.             //if(world.getBlockId(i + random.nextInt(16), j, k + random.nextInt(16)) != 0 && area < 200)
  50.             //&& world.canExistingBlockSeeTheSky(i + random.nextInt(16), j + 1, k + random.nextInt(16))
  51.         {
  52.             makeMaze();
  53.             ModLoader.getMinecraftInstance().ingameGUI.addChatMessage("BUILT A PYRAMID!!!");
  54.  
  55.             // create pyramid out of sandstone
  56.             for(int ii = -2; ii < 21; ii++) {
  57.                 for(int i1 = -2 + ii; i1 < rows - ii + 2; i1++) {
  58.                     for(int j1 = -2 + ii; j1 < columns - ii + 2; j1++) {
  59.                         world.setBlock(i + i1, j + ii, k + j1, 24); // 24
  60.                     }
  61.                 }
  62.             }
  63.  
  64.             // place maze
  65.             for(int i1 = 0; i1 < rows; i1++) {
  66.                 for(int j1 = 0; j1 < columns; j1++) {
  67.                     // create blocks
  68.                     //j = 70;
  69.                     //i = 6;
  70.                     //k = 6;
  71.                     world.setBlock(i + i1, j, k + j1, maze[i1][j1]);
  72.                     world.setBlock(i + i1, j - 1, k + j1, maze[i1][j1]);
  73.                     world.setBlock(i + i1, j - 2, k + j1, Block.bedrock.blockID);
  74.                 }
  75.             }
  76.  
  77.             // make some adjustments to pyramid
  78.             // add glass
  79.             for(int pp = 0; pp < 30; pp++) {
  80.                 int rx = rand.nextInt(rows -6)+3;
  81.                 int ry = rand.nextInt(columns -6)+3;
  82.  
  83.                 if(maze[rx][ry] == 7) {
  84.                     world.setBlock(i + rx, j, k + ry, Block.glass.blockID);
  85.                 }
  86.             }
  87.  
  88.             // add sandstone
  89.             for(int pq = 0; pq < 30; pq++) {
  90.                 int rx = rand.nextInt(rows -6)+3;
  91.                 int ry = rand.nextInt(columns -6)+3;
  92.  
  93.                 if(maze[rx][ry] == 7) {
  94.                     world.setBlock(i + rx, j-1, k + ry, Block.sandStone.blockID);
  95.                 }
  96.             }
  97.  
  98.             // add torches
  99.             for(int pq = 0; pq < 30; pq++) {
  100.                 int rx = rand.nextInt(rows -6)+3;
  101.                 int ry = rand.nextInt(columns -6)+3;
  102.  
  103.                 if(maze[rx][ry] == 7) {
  104.                     world.setBlock(i + rx, j, k + ry, Block.torchWood.blockID);
  105.                 }
  106.             }
  107.  
  108.             // spawners
  109.             int spawnbox = 0;
  110.  
  111.             while(spawnbox < 6) {
  112.                 int xx = rand.nextInt(rows-3);
  113.                 int yy = rand.nextInt(columns-3);
  114.                 xx++;
  115.                 yy++;
  116.  
  117.                 if(maze[xx][yy] == wallCode) { //7
  118.                     spawnbox++;
  119.                     world.setBlock(i+xx, j-1, k+yy,0);
  120.                     world.setBlockWithNotify(i+xx, j-1, k+yy, Block.mobSpawner.blockID);
  121.                     TileEntityMobSpawner spawner = new TileEntityMobSpawner();
  122.                     world.setBlockTileEntity(i+xx, j-1, k+yy, spawner);
  123.  
  124.                     if(rand.nextInt(5)==0) {
  125.                         spawner.setMobID("BlackSoul");
  126.                     } else {
  127.                         spawner.setMobID("Mummy");
  128.                     }
  129.                 }
  130.             }
  131.  
  132.             // entrance
  133.             world.setBlock(i+1, j-1, k, 0);
  134.             world.setBlock(i+1, j, k, 0);
  135.  
  136.             for(int t=0; t<5; t++) {
  137.                 world.setBlock(i+1, j-1, k-t, 0);
  138.                 world.setBlock(i+1, j, k-t, 0);
  139.                 world.setBlock(i+1, j, k-t, Block.torchWood.blockID);
  140.             }
  141.  
  142.             world.setBlock(i-1, j, k-5, Block.torchWood.blockID);
  143.             world.setBlock(i+1, j, k-5, Block.torchWood.blockID);
  144.             world.setBlock(i, j, k-5, Block.torchWood.blockID);
  145.  
  146.             // clear to surface obstructions
  147.             for(int w = 1; w< 25; w++) {
  148.                 world.setBlock(i-1, j+w, k-5, 0);
  149.                 world.setBlock(i+1, j+w, k-5, 0);
  150.                 world.setBlock(i, j+w, k-5, 0);
  151.             }
  152.  
  153.             world.setBlock(i, j+26, k-5, Block.torchWood.blockID);
  154.             /*
  155.                EntityFX fx = new EntitySlimeFX(world, i+1, j, k -5, Item.slimeBall);
  156.                fx.renderDistanceWeight = 10D;
  157.                fx.particleTextureIndex = 94;
  158.                ModLoader.getMinecraftInstance().effectRenderer.addEffect(fx);
  159.  
  160. */
  161.             int i5 = Item.bone.shiftedIndex;
  162.             float f = 0.7F;
  163.             double d = (double)(world.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  164.             double d1 = (double)(world.rand.nextFloat() * f) + (double)(1.0F - f) * 0.20000000000000001D + 0.59999999999999998D;
  165.             double d2 = (double)(world.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  166.             EntityItem entityitem = new EntityItem(world, (double)i + d - 2, (double)j + d1, (double)k + d2 - 2, new ItemStack(i5, 5, 0));
  167.             entityitem.delayBeforeCanPickup = 10;
  168.             world.entityJoinedWorld(entityitem);
  169.             // treasure
  170.             world.setBlock(i + rows - 2, j-1, k + columns - 2, 54);
  171.             TileEntityChest chest = new TileEntityChest();
  172.             world.setBlockTileEntity(i + rows - 2, j-1, k + columns - 2, chest);
  173.  
  174.             // set other slots with goodies!
  175.             for(int x = 1; x < chest.getSizeInventory(); x++) {
  176.                 int b = rand.nextInt(30);
  177.  
  178.                 if(b==0) {
  179.                     chest.setInventorySlotContents(x, new ItemStack(mod_MoreCreepsAndWeirdos.goodonut.shiftedIndex, rand.nextInt(16), 0));
  180.                 }
  181.  
  182.                 if(b==1) {
  183.                     chest.setInventorySlotContents(x, new ItemStack(mod_MoreCreepsAndWeirdos.bandaid.shiftedIndex, rand.nextInt(16), 0));
  184.                 }
  185.  
  186.                 if(b==2) {
  187.                     chest.setInventorySlotContents(x, new ItemStack(mod_MoreCreepsAndWeirdos.raygun.shiftedIndex, rand.nextInt(4), 0));
  188.                 }
  189.  
  190.                 if(b==3) {
  191.                     chest.setInventorySlotContents(x, new ItemStack(mod_MoreCreepsAndWeirdos.money.shiftedIndex, rand.nextInt(16), 0));
  192.                 }
  193.  
  194.                 if(b==4) {
  195.                     chest.setInventorySlotContents(x, new ItemStack(mod_MoreCreepsAndWeirdos.blorpcola.shiftedIndex, rand.nextInt(10), 0));
  196.                 }
  197.  
  198.                 if(b==5) {
  199.                     chest.setInventorySlotContents(x, new ItemStack(Item.bread, 1, 0));
  200.                 }
  201.  
  202.                 if(b==6) {
  203.                     chest.setInventorySlotContents(x, new ItemStack(Item.appleGold, 1, 0));
  204.                 }
  205.  
  206.                 if(b==7) {
  207.                     chest.setInventorySlotContents(x, new ItemStack(Item.ingotGold, rand.nextInt(3), 0));
  208.                 }
  209.  
  210.                 if(b==8) {
  211.                     chest.setInventorySlotContents(x, new ItemStack(Item.ingotIron, rand.nextInt(5), 0));
  212.                 }
  213.  
  214.                 if(b==9) {
  215.                     chest.setInventorySlotContents(x, new ItemStack(Item.gunpowder, rand.nextInt(4), 0));
  216.                 }
  217.  
  218.                 if(b==10) {
  219.                     chest.setInventorySlotContents(x, new ItemStack(Item.egg, rand.nextInt(3), 0));
  220.                 }
  221.  
  222.                 if(b==11) {
  223.                     chest.setInventorySlotContents(x, new ItemStack(Item.wheat, rand.nextInt(12), 0));
  224.                 }
  225.  
  226.                 if(b==12) {
  227.                     chest.setInventorySlotContents(x, new ItemStack(mod_MoreCreepsAndWeirdos.goodonut.shiftedIndex, rand.nextInt(16), 0));
  228.                 }
  229.  
  230.                 if(b==13) {
  231.                     chest.setInventorySlotContents(x, new ItemStack(Item.diamond, rand.nextInt(2), 0));
  232.                 }
  233.             }
  234.  
  235.             // PyramidGuardian
  236.             // clear space
  237.             world.setBlockWithNotify(i + rows - 3, j-1, k + columns - 3, 0);
  238.             world.setBlockWithNotify(i + rows - 3, j, k + columns - 3, 0);
  239.             // set guardian
  240.             EntityPyramidGuardian entitypyramidguardian = new EntityPyramidGuardian(world);
  241.             entitypyramidguardian.setLocationAndAngles(i + rows - 3, j-1, k + columns - 3, 360F, 0.0F);
  242.             entitypyramidguardian.motionX = 0;
  243.             entitypyramidguardian.motionY = 0;
  244.             entitypyramidguardian.motionZ = 0;
  245.             world.entityJoinedWorld(entitypyramidguardian);
  246.  
  247.             // seal top of maze
  248.             for(int i1 = 0; i1 < rows; i1++) {
  249.                 for(int j1 = 0; j1 < columns; j1++) {
  250.                     world.setBlock(i + i1, j + 1, k + j1, 7); // 7
  251.                 }
  252.             }
  253.  
  254.             pyramids = 0;
  255.             return true;
  256.         }
  257.  
  258.         return false;
  259.     }
  260.  
  261.  
  262.  
  263.     public void makeMaze() {
  264.         int i,j;
  265.         int emptyCt = 0; // number of rooms
  266.         int wallCt = 0;  // number of walls
  267.         int[] wallrow = new int[(rows*columns)/2];  // position of walls between rooms
  268.         int[] wallcol = new int[(rows*columns)/2];
  269.  
  270.         for (i = 0; i<rows; i++)  // start with everything being a wall
  271.             for (j = 0; j < columns; j++)
  272.                 maze[i][j] = wallCode;
  273.  
  274.         for (i = 1; i<rows-1; i += 2)  // make a grid of empty rooms
  275.             for (j = 1; j<columns-1; j += 2) {
  276.                 emptyCt++;
  277.                 maze[i][j] = -emptyCt;  // each room is represented by a different negative number
  278.  
  279.                 if (i < rows-2) {  // record info about wall below this room
  280.                     wallrow[wallCt] = i+1;
  281.                     wallcol[wallCt] = j;
  282.                     wallCt++;
  283.                 }
  284.  
  285.                 if (j < columns-2) {  // record info about wall to right of this room
  286.                     wallrow[wallCt] = i;
  287.                     wallcol[wallCt] = j+1;
  288.                     wallCt++;
  289.                 }
  290.             }
  291.  
  292.         int r;
  293.  
  294.         for (i=wallCt-1; i>0; i--) {
  295.             r = (int)(Math.random() * i);  // choose a wall randomly and maybe tear it down
  296.             // tearDown(wallrow[r],wallcol[r]);
  297.  
  298.             if (wallrow[r] % 2 == 1 && maze[wallrow[r]][wallcol[r]-1] != maze[wallrow[r]][wallcol[r]+1]) {
  299.                 // row is odd; wall separates rooms horizontally
  300.                 fill(wallrow[r], wallcol[r]-1, maze[wallrow[r]][wallcol[r]-1], maze[wallrow[r]][wallcol[r]+1]);
  301.                 maze[wallrow[r]][wallcol[r]] = maze[wallrow[r]][wallcol[r]+1];
  302.                 //putSquare(row,col,emptyCode);
  303.                 // try { wait(speedSleep); }
  304.                 // catch (InterruptedException e) { }
  305.             } else if (wallrow[r] % 2 == 0 && maze[wallrow[r]-1][wallcol[r]] != maze[wallrow[r]+1][wallcol[r]]) {
  306.                 // row is even; wall separates rooms vertically
  307.                 fill(wallrow[r]-1, wallcol[r], maze[wallrow[r]-1][wallcol[r]], maze[wallrow[r]+1][wallcol[r]]);
  308.                 maze[wallrow[r]][wallcol[r]] = maze[wallrow[r]+1][wallcol[r]];
  309.                 // putSquare(row,col,emptyCode);
  310.                 //  try { wait(speedSleep); }
  311.                 //  catch (InterruptedException e) { }
  312.             }
  313.  
  314.             wallrow[r] = wallrow[i];
  315.             wallcol[r] = wallcol[i];
  316.         }
  317.  
  318.         for (i=1; i<rows-1; i++)  // replace negative values in maze[][] with emptyCode
  319.             for (j=1; j<columns-1; j++)
  320.                 if (maze[i][j] < 0)
  321.                     maze[i][j] = emptyCode;
  322.     }
  323.  
  324.     public void tearDown(int row, int col) {
  325.         if (row % 2 == 1 && maze[row][col-1] != maze[row][col+1]) {
  326.             // row is odd; wall separates rooms horizontally
  327.             fill(row, col-1, maze[row][col-1], maze[row][col+1]);
  328.             maze[row][col] = maze[row][col+1];
  329.             //putSquare(row,col,emptyCode);
  330.             // try { wait(speedSleep); }
  331.             // catch (InterruptedException e) { }
  332.         } else if (row % 2 == 0 && maze[row-1][col] != maze[row+1][col]) {
  333.             // row is even; wall separates rooms vertically
  334.             fill(row-1, col, maze[row-1][col], maze[row+1][col]);
  335.             maze[row][col] = maze[row+1][col];
  336.             // putSquare(row,col,emptyCode);
  337.             //  try { wait(speedSleep); }
  338.             //  catch (InterruptedException e) { }
  339.         }
  340.     }
  341.  
  342.     public void fill(int row, int col, int replace, int replaceWith) {
  343.         // called by tearDown() to change "room codes".
  344.         if(row < 0) {
  345.             row = 0;
  346.         }
  347.  
  348.         if(col < 0) {
  349.             row = 0;
  350.         }
  351.  
  352.         if(row > rows ) {
  353.             row = rows;
  354.         }
  355.  
  356.         if(col > columns) {
  357.             col = columns;
  358.         }
  359.  
  360.         if (maze[row][col] == replace) {
  361.             maze[row][col] = replaceWith;
  362.             fill(row+1,col,replace,replaceWith);
  363.             fill(row-1,col,replace,replaceWith);
  364.             fill(row,col+1,replace,replaceWith);
  365.             fill(row,col-1,replace,replaceWith);
  366.         }
  367.     }
  368.  
  369.     public static Random rand = new Random();
  370.  
  371.     public static final int blockIDs[] = new int[] {
  372.         Block.crops.blockID, Block.sapling.blockID, Block.pumpkin.blockID, Block.plantRed.blockID, Block.plantYellow.blockID,
  373.             Block.mushroomBrown.blockID, Block.mushroomRed.blockID
  374.     };
  375.  
  376.     private int count;
  377.     private int pyramids;
  378.     public int rows;
  379.     public int columns;
  380.     public int maze[][];
  381.     public static int backgroundCode;
  382.     public static int wallCode;
  383.     public static int pathCode;
  384.     public static int emptyCode;
  385.     public static int visitedCode;
  386.     public TileEntityChest chest;
  387.  
  388. }
Advertisement
Add Comment
Please, Sign In to add comment