    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    import net.minecraftforge.common.DungeonHooks;
    006    import net.minecraftforge.common.MinecraftForge;
    007
    008    public class WorldGenDungeons extends WorldGenerator
    009    {
    010        public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    011        {
    012            byte var6 = 3;
    013            int var7 = par2Random.nextInt(2) + 2;
    014            int var8 = par2Random.nextInt(2) + 2;
    015            int var9 = 0;
    016            int var10;
    017            int var11;
    018            int var12;
    019
    020            for (var10 = par3 - var7 - 1; var10 <= par3 + var7 + 1; ++var10)
    021            {
    022                for (var11 = par4 - 1; var11 <= par4 + var6 + 1; ++var11)
    023                {
    024                    for (var12 = par5 - var8 - 1; var12 <= par5 + var8 + 1; ++var12)
    025                    {
    026                        Material var13 = par1World.getBlockMaterial(var10, var11, var12);
    027
    028                        if (var11 == par4 - 1 && !var13.isSolid())
    029                        {
    030                            return false;
    031                        }
    032
    033                        if (var11 == par4 + var6 + 1 && !var13.isSolid())
    034                        {
    035                            return false;
    036                        }
    037
    038                        if ((var10 == par3 - var7 - 1 || var10 == par3 + var7 + 1 || var12 == par5 - var8 - 1 || var12 == par5 + var8 + 1) && var11 == par4 && par1World.isAirBlock(var10, var11, var12) && par1World.isAirBlock(var10, var11 + 1, var12))
    039                        {
    040                            ++var9;
    041                        }
    042                    }
    043                }
    044            }
    045
    046            if (var9 >= 1 && var9 <= 5)
    047            {
    048                for (var10 = par3 - var7 - 1; var10 <= par3 + var7 + 1; ++var10)
    049                {
    050                    for (var11 = par4 + var6; var11 >= par4 - 1; --var11)
    051                    {
    052                        for (var12 = par5 - var8 - 1; var12 <= par5 + var8 + 1; ++var12)
    053                        {
    054                            if (var10 != par3 - var7 - 1 && var11 != par4 - 1 && var12 != par5 - var8 - 1 && var10 != par3 + var7 + 1 && var11 != par4 + var6 + 1 && var12 != par5 + var8 + 1)
    055                            {
    056                                par1World.setBlockWithNotify(var10, var11, var12, 0);
    057                            }
    058                            else if (var11 >= 0 && !par1World.getBlockMaterial(var10, var11 - 1, var12).isSolid())
    059                            {
    060                                par1World.setBlockWithNotify(var10, var11, var12, 0);
    061                            }
    062                            else if (par1World.getBlockMaterial(var10, var11, var12).isSolid())
    063                            {
    064                                if (var11 == par4 - 1 && par2Random.nextInt(4) != 0)
    065                                {
    066                                    par1World.setBlockWithNotify(var10, var11, var12, Block.cobblestoneMossy.blockID);
    067                                }
    068                                else
    069                                {
    070                                    par1World.setBlockWithNotify(var10, var11, var12, Block.cobblestone.blockID);
    071                                }
    072                            }
    073                        }
    074                    }
    075                }
    076
    077                var10 = 0;
    078
    079                while (var10 < 2)
    080                {
    081                    var11 = 0;
    082
    083                    while (true)
    084                    {
    085                        if (var11 < 3)
    086                        {
    087                            label210:
    088                            {
    089                                var12 = par3 + par2Random.nextInt(var7 * 2 + 1) - var7;
    090                                int var14 = par5 + par2Random.nextInt(var8 * 2 + 1) - var8;
    091
    092                                if (par1World.isAirBlock(var12, par4, var14))
    093                                {
    094                                    int var15 = 0;
    095
    096                                    if (par1World.getBlockMaterial(var12 - 1, par4, var14).isSolid())
    097                                    {
    098                                        ++var15;
    099                                    }
    100
    101                                    if (par1World.getBlockMaterial(var12 + 1, par4, var14).isSolid())
    102                                    {
    103                                        ++var15;
    104                                    }
    105
    106                                    if (par1World.getBlockMaterial(var12, par4, var14 - 1).isSolid())
    107                                    {
    108                                        ++var15;
    109                                    }
    110
    111                                    if (par1World.getBlockMaterial(var12, par4, var14 + 1).isSolid())
    112                                    {
    113                                        ++var15;
    114                                    }
    115
    116                                    if (var15 == 1)
    117                                    {
    118                                        par1World.setBlockWithNotify(var12, par4, var14, Block.chest.blockID);
    119                                        TileEntityChest var16 = (TileEntityChest)par1World.getBlockTileEntity(var12, par4, var14);
    120
    121                                        if (var16 != null)
    122                                        {
    123                                            for (int var17 = 0; var17 < DungeonHooks.getDungeonLootTries(); ++var17)
    124                                            {
    125                                                ItemStack var18 = DungeonHooks.getRandomDungeonLoot(par2Random);
    126
    127                                                if (var18 != null)
    128                                                {
    129                                                    var16.setInventorySlotContents(par2Random.nextInt(var16.getSizeInventory()), var18);
    130                                                }
    131                                            }
    132                                        }
    133
    134                                        break label210;
    135                                    }
    136                                }
    137
    138                                ++var11;
    139                                continue;
    140                            }
    141                        }
    142
    143                        ++var10;
    144                        break;
    145                    }
    146                }
    147
    148                par1World.setBlockWithNotify(par3, par4, par5, Block.mobSpawner.blockID);
    149                TileEntityMobSpawner var19 = (TileEntityMobSpawner)par1World.getBlockTileEntity(par3, par4, par5);
    150
    151                if (var19 != null)
    152                {
    153                    var19.setMobID(DungeonHooks.getRandomDungeonMob(par2Random));
    154                }
    155                else
    156                {
    157                    System.err.println("Failed to fetch mob spawner entity at (" + par3 + ", " + par4 + ", " + par5 + ")");
    158                }
    159
    160                return true;
    161            }
    162            else
    163            {
    164                return false;
    165            }
    166        }
    167
    168        /**
    169         * Picks potentially a random item to add to a dungeon chest.
    170         */
    171        private ItemStack pickCheckLootItem(Random par1Random)
    172        {
    173            int var2 = par1Random.nextInt(11);
    174            return var2 == 0 ? new ItemStack(Item.saddle) : (var2 == 1 ? new ItemStack(Item.ingotIron, par1Random.nextInt(4) + 1) : (var2 == 2 ? new ItemStack(Item.bread) : (var2 == 3 ? new ItemStack(Item.wheat, par1Random.nextInt(4) + 1) : (var2 == 4 ? new ItemStack(Item.gunpowder, par1Random.nextInt(4) + 1) : (var2 == 5 ? new ItemStack(Item.silk, par1Random.nextInt(4) + 1) : (var2 == 6 ? new ItemStack(Item.bucketEmpty) : (var2 == 7 && par1Random.nextInt(100) == 0 ? new ItemStack(Item.appleGold) : (var2 == 8 && par1Random.nextInt(2) == 0 ? new ItemStack(Item.redstone, par1Random.nextInt(4) + 1) : (var2 == 9 && par1Random.nextInt(10) == 0 ? new ItemStack(Item.itemsList[Item.record13.shiftedIndex + par1Random.nextInt(2)]) : (var2 == 10 ? new ItemStack(Item.dyePowder, 1, 3) : null))))))))));
    175        }
    176
    177        /**
    178         * Randomly decides which spawner to use in a dungeon
    179         */
    180        private String pickMobSpawner(Random par1Random)
    181        {
    182            int var2 = par1Random.nextInt(4);
    183            return var2 == 0 ? "Skeleton" : (var2 == 1 ? "Zombie" : (var2 == 2 ? "Zombie" : (var2 == 3 ? "Spider" : "")));
    184        }
    185    }