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