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