    001package net.minecraft.world.gen.structure;
    002
    003import java.util.ArrayList;
    004import java.util.Iterator;
    005import java.util.List;
    006import java.util.Random;
    007
    008public class StructureStrongholdPieces
    009{
    010    private static final StructureStrongholdPieceWeight[] pieceWeightArray = new StructureStrongholdPieceWeight[] {new StructureStrongholdPieceWeight(ComponentStrongholdStraight.class, 40, 0), new StructureStrongholdPieceWeight(ComponentStrongholdPrison.class, 5, 5), new StructureStrongholdPieceWeight(ComponentStrongholdLeftTurn.class, 20, 0), new StructureStrongholdPieceWeight(ComponentStrongholdRightTurn.class, 20, 0), new StructureStrongholdPieceWeight(ComponentStrongholdRoomCrossing.class, 10, 6), new StructureStrongholdPieceWeight(ComponentStrongholdStairsStraight.class, 5, 5), new StructureStrongholdPieceWeight(ComponentStrongholdStairs.class, 5, 5), new StructureStrongholdPieceWeight(ComponentStrongholdCrossing.class, 5, 4), new StructureStrongholdPieceWeight(ComponentStrongholdChestCorridor.class, 5, 4), new StructureStrongholdPieceWeight2(ComponentStrongholdLibrary.class, 10, 2), new StructureStrongholdPieceWeight3(ComponentStrongholdPortalRoom.class, 20, 1)};
    011    private static List structurePieceList;
    012    private static Class strongComponentType;
    013    static int totalWeight = 0;
    014    private static final StructureStrongholdStones strongholdStones = new StructureStrongholdStones((StructureStrongholdPieceWeight2)null);
    015
    016    /**
    017     * sets up Arrays with the Structure pieces and their weights
    018     */
    019    public static void prepareStructurePieces()
    020    {
    021        structurePieceList = new ArrayList();
    022        StructureStrongholdPieceWeight[] var0 = pieceWeightArray;
    023        int var1 = var0.length;
    024
    025        for (int var2 = 0; var2 < var1; ++var2)
    026        {
    027            StructureStrongholdPieceWeight var3 = var0[var2];
    028            var3.instancesSpawned = 0;
    029            structurePieceList.add(var3);
    030        }
    031
    032        strongComponentType = null;
    033    }
    034
    035    private static boolean canAddStructurePieces()
    036    {
    037        boolean var0 = false;
    038        totalWeight = 0;
    039        StructureStrongholdPieceWeight var2;
    040
    041        for (Iterator var1 = structurePieceList.iterator(); var1.hasNext(); totalWeight += var2.pieceWeight)
    042        {
    043            var2 = (StructureStrongholdPieceWeight)var1.next();
    044
    045            if (var2.instancesLimit > 0 && var2.instancesSpawned < var2.instancesLimit)
    046            {
    047                var0 = true;
    048            }
    049        }
    050
    051        return var0;
    052    }
    053
    054    /**
    055     * translates the PieceWeight class to the Component class
    056     */
    057    private static ComponentStronghold getStrongholdComponentFromWeightedPiece(Class par0Class, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
    058    {
    059        Object var8 = null;
    060
    061        if (par0Class == ComponentStrongholdStraight.class)
    062        {
    063            var8 = ComponentStrongholdStraight.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    064        }
    065        else if (par0Class == ComponentStrongholdPrison.class)
    066        {
    067            var8 = ComponentStrongholdPrison.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    068        }
    069        else if (par0Class == ComponentStrongholdLeftTurn.class)
    070        {
    071            var8 = ComponentStrongholdLeftTurn.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    072        }
    073        else if (par0Class == ComponentStrongholdRightTurn.class)
    074        {
    075            var8 = ComponentStrongholdRightTurn.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    076        }
    077        else if (par0Class == ComponentStrongholdRoomCrossing.class)
    078        {
    079            var8 = ComponentStrongholdRoomCrossing.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    080        }
    081        else if (par0Class == ComponentStrongholdStairsStraight.class)
    082        {
    083            var8 = ComponentStrongholdStairsStraight.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    084        }
    085        else if (par0Class == ComponentStrongholdStairs.class)
    086        {
    087            var8 = ComponentStrongholdStairs.getStrongholdStairsComponent(par1List, par2Random, par3, par4, par5, par6, par7);
    088        }
    089        else if (par0Class == ComponentStrongholdCrossing.class)
    090        {
    091            var8 = ComponentStrongholdCrossing.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    092        }
    093        else if (par0Class == ComponentStrongholdChestCorridor.class)
    094        {
    095            var8 = ComponentStrongholdChestCorridor.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    096        }
    097        else if (par0Class == ComponentStrongholdLibrary.class)
    098        {
    099            var8 = ComponentStrongholdLibrary.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    100        }
    101        else if (par0Class == ComponentStrongholdPortalRoom.class)
    102        {
    103            var8 = ComponentStrongholdPortalRoom.findValidPlacement(par1List, par2Random, par3, par4, par5, par6, par7);
    104        }
    105
    106        return (ComponentStronghold)var8;
    107    }
    108
    109    private static ComponentStronghold getNextComponent(ComponentStrongholdStairs2 par0ComponentStrongholdStairs2, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
    110    {
    111        if (!canAddStructurePieces())
    112        {
    113            return null;
    114        }
    115        else
    116        {
    117            if (strongComponentType != null)
    118            {
    119                ComponentStronghold var8 = getStrongholdComponentFromWeightedPiece(strongComponentType, par1List, par2Random, par3, par4, par5, par6, par7);
    120                strongComponentType = null;
    121
    122                if (var8 != null)
    123                {
    124                    return var8;
    125                }
    126            }
    127
    128            int var13 = 0;
    129
    130            while (var13 < 5)
    131            {
    132                ++var13;
    133                int var9 = par2Random.nextInt(totalWeight);
    134                Iterator var10 = structurePieceList.iterator();
    135
    136                while (var10.hasNext())
    137                {
    138                    StructureStrongholdPieceWeight var11 = (StructureStrongholdPieceWeight)var10.next();
    139                    var9 -= var11.pieceWeight;
    140
    141                    if (var9 < 0)
    142                    {
    143                        if (!var11.canSpawnMoreStructuresOfType(par7) || var11 == par0ComponentStrongholdStairs2.strongholdPieceWeight)
    144                        {
    145                            break;
    146                        }
    147
    148                        ComponentStronghold var12 = getStrongholdComponentFromWeightedPiece(var11.pieceClass, par1List, par2Random, par3, par4, par5, par6, par7);
    149
    150                        if (var12 != null)
    151                        {
    152                            ++var11.instancesSpawned;
    153                            par0ComponentStrongholdStairs2.strongholdPieceWeight = var11;
    154
    155                            if (!var11.canSpawnMoreStructures())
    156                            {
    157                                structurePieceList.remove(var11);
    158                            }
    159
    160                            return var12;
    161                        }
    162                    }
    163                }
    164            }
    165
    166            StructureBoundingBox var14 = ComponentStrongholdCorridor.func_74992_a(par1List, par2Random, par3, par4, par5, par6);
    167
    168            if (var14 != null && var14.minY > 1)
    169            {
    170                return new ComponentStrongholdCorridor(par7, par2Random, var14, par6);
    171            }
    172            else
    173            {
    174                return null;
    175            }
    176        }
    177    }
    178
    179    private static StructureComponent getNextValidComponent(ComponentStrongholdStairs2 par0ComponentStrongholdStairs2, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
    180    {
    181        if (par7 > 50)
    182        {
    183            return null;
    184        }
    185        else if (Math.abs(par3 - par0ComponentStrongholdStairs2.getBoundingBox().minX) <= 112 && Math.abs(par5 - par0ComponentStrongholdStairs2.getBoundingBox().minZ) <= 112)
    186        {
    187            ComponentStronghold var8 = getNextComponent(par0ComponentStrongholdStairs2, par1List, par2Random, par3, par4, par5, par6, par7 + 1);
    188
    189            if (var8 != null)
    190            {
    191                par1List.add(var8);
    192                par0ComponentStrongholdStairs2.field_75026_c.add(var8);
    193            }
    194
    195            return var8;
    196        }
    197        else
    198        {
    199            return null;
    200        }
    201    }
    202
    203    static StructureComponent getNextValidComponentAccess(ComponentStrongholdStairs2 par0ComponentStrongholdStairs2, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
    204    {
    205        return getNextValidComponent(par0ComponentStrongholdStairs2, par1List, par2Random, par3, par4, par5, par6, par7);
    206    }
    207
    208    static Class setComponentType(Class par0Class)
    209    {
    210        strongComponentType = par0Class;
    211        return par0Class;
    212    }
    213
    214    static StructureStrongholdStones getStrongholdStones()
    215    {
    216        return strongholdStones;
    217    }
    218}