    001    package net.minecraft.src;
    002
    003    import java.util.ArrayList;
    004    import java.util.Iterator;
    005    import java.util.List;
    006    import java.util.Random;
    007
    008    import cpw.mods.fml.common.registry.VillagerRegistry;
    009
    010    public class StructureVillagePieces
    011    {
    012        public static ArrayList getStructureVillageWeightedPieceList(Random par0Random, int par1)
    013        {
    014            ArrayList var2 = new ArrayList();
    015            var2.add(new StructureVillagePieceWeight(ComponentVillageHouse4_Garden.class, 4, MathHelper.getRandomIntegerInRange(par0Random, 2 + par1, 4 + par1 * 2)));
    016            var2.add(new StructureVillagePieceWeight(ComponentVillageChurch.class, 20, MathHelper.getRandomIntegerInRange(par0Random, 0 + par1, 1 + par1)));
    017            var2.add(new StructureVillagePieceWeight(ComponentVillageHouse1.class, 20, MathHelper.getRandomIntegerInRange(par0Random, 0 + par1, 2 + par1)));
    018            var2.add(new StructureVillagePieceWeight(ComponentVillageWoodHut.class, 3, MathHelper.getRandomIntegerInRange(par0Random, 2 + par1, 5 + par1 * 3)));
    019            var2.add(new StructureVillagePieceWeight(ComponentVillageHall.class, 15, MathHelper.getRandomIntegerInRange(par0Random, 0 + par1, 2 + par1)));
    020            var2.add(new StructureVillagePieceWeight(ComponentVillageField.class, 3, MathHelper.getRandomIntegerInRange(par0Random, 1 + par1, 4 + par1)));
    021            var2.add(new StructureVillagePieceWeight(ComponentVillageField2.class, 3, MathHelper.getRandomIntegerInRange(par0Random, 2 + par1, 4 + par1 * 2)));
    022            var2.add(new StructureVillagePieceWeight(ComponentVillageHouse2.class, 15, MathHelper.getRandomIntegerInRange(par0Random, 0, 1 + par1)));
    023            var2.add(new StructureVillagePieceWeight(ComponentVillageHouse3.class, 8, MathHelper.getRandomIntegerInRange(par0Random, 0 + par1, 3 + par1 * 2)));
    024            VillagerRegistry.addExtraVillageComponents(var2, par0Random, par1);
    025
    026            Iterator var3 = var2.iterator();
    027
    028            while (var3.hasNext())
    029            {
    030                if (((StructureVillagePieceWeight)var3.next()).villagePiecesLimit == 0)
    031                {
    032                    var3.remove();
    033                }
    034            }
    035
    036            return var2;
    037        }
    038
    039        private static int func_75079_a(List par0List)
    040        {
    041            boolean var1 = false;
    042            int var2 = 0;
    043            StructureVillagePieceWeight var4;
    044
    045            for (Iterator var3 = par0List.iterator(); var3.hasNext(); var2 += var4.villagePieceWeight)
    046            {
    047                var4 = (StructureVillagePieceWeight)var3.next();
    048
    049                if (var4.villagePiecesLimit > 0 && var4.villagePiecesSpawned < var4.villagePiecesLimit)
    050                {
    051                    var1 = true;
    052                }
    053            }
    054
    055            return var1 ? var2 : -1;
    056        }
    057
    058        private static ComponentVillage func_75083_a(ComponentVillageStartPiece par0ComponentVillageStartPiece, StructureVillagePieceWeight par1StructureVillagePieceWeight, List par2List, Random par3Random, int par4, int par5, int par6, int par7, int par8)
    059        {
    060            Class var9 = par1StructureVillagePieceWeight.villagePieceClass;
    061            Object var10 = null;
    062
    063            if (var9 == ComponentVillageHouse4_Garden.class)
    064            {
    065                var10 = ComponentVillageHouse4_Garden.func_74912_a(par0ComponentVillageStartPiece, par2List, par3Random, par4, par5, par6, par7, par8);
    066            }
    067            else if (var9 == ComponentVillageChurch.class)
    068            {
    069                var10 = ComponentVillageChurch.func_74919_a(par0ComponentVillageStartPiece, par2List, par3Random, par4, par5, par6, par7, par8);
    070            }
    071            else if (var9 == ComponentVillageHouse1.class)
    072            {
    073                var10 = ComponentVillageHouse1.func_74898_a(par0ComponentVillageStartPiece, par2List, par3Random, par4, par5, par6, par7, par8);
    074            }
    075            else if (var9 == ComponentVillageWoodHut.class)
    076            {
    077                var10 = ComponentVillageWoodHut.func_74908_a(par0ComponentVillageStartPiece, par2List, par3Random, par4, par5, par6, par7, par8);
    078            }
    079            else if (var9 == ComponentVillageHall.class)
    080            {
    081                var10 = ComponentVillageHall.func_74906_a(par0ComponentVillageStartPiece, par2List, par3Random, par4, par5, par6, par7, par8);
    082            }
    083            else if (var9 == ComponentVillageField.class)
    084            {
    085                var10 = ComponentVillageField.func_74900_a(par0ComponentVillageStartPiece, par2List, par3Random, par4, par5, par6, par7, par8);
    086            }
    087            else if (var9 == ComponentVillageField2.class)
    088            {
    089                var10 = ComponentVillageField2.func_74902_a(par0ComponentVillageStartPiece, par2List, par3Random, par4, par5, par6, par7, par8);
    090            }
    091            else if (var9 == ComponentVillageHouse2.class)
    092            {
    093                var10 = ComponentVillageHouse2.func_74915_a(par0ComponentVillageStartPiece, par2List, par3Random, par4, par5, par6, par7, par8);
    094            }
    095            else if (var9 == ComponentVillageHouse3.class)
    096            {
    097                var10 = ComponentVillageHouse3.func_74921_a(par0ComponentVillageStartPiece, par2List, par3Random, par4, par5, par6, par7, par8);
    098            }
    099            else
    100            {
    101                var10 = VillagerRegistry.getVillageComponent(par1StructureVillagePieceWeight, par0ComponentVillageStartPiece , par2List, par3Random, par4, par5, par6, par7, par8);
    102            }
    103
    104            return (ComponentVillage)var10;
    105        }
    106
    107        /**
    108         * attempts to find a next Village Component to be spawned
    109         */
    110        private static ComponentVillage getNextVillageComponent(ComponentVillageStartPiece par0ComponentVillageStartPiece, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
    111        {
    112            int var8 = func_75079_a(par0ComponentVillageStartPiece.structureVillageWeightedPieceList);
    113
    114            if (var8 <= 0)
    115            {
    116                return null;
    117            }
    118            else
    119            {
    120                int var9 = 0;
    121
    122                while (var9 < 5)
    123                {
    124                    ++var9;
    125                    int var10 = par2Random.nextInt(var8);
    126                    Iterator var11 = par0ComponentVillageStartPiece.structureVillageWeightedPieceList.iterator();
    127
    128                    while (var11.hasNext())
    129                    {
    130                        StructureVillagePieceWeight var12 = (StructureVillagePieceWeight)var11.next();
    131                        var10 -= var12.villagePieceWeight;
    132
    133                        if (var10 < 0)
    134                        {
    135                            if (!var12.canSpawnMoreVillagePiecesOfType(par7) || var12 == par0ComponentVillageStartPiece.structVillagePieceWeight && par0ComponentVillageStartPiece.structureVillageWeightedPieceList.size() > 1)
    136                            {
    137                                break;
    138                            }
    139
    140                            ComponentVillage var13 = func_75083_a(par0ComponentVillageStartPiece, var12, par1List, par2Random, par3, par4, par5, par6, par7);
    141
    142                            if (var13 != null)
    143                            {
    144                                ++var12.villagePiecesSpawned;
    145                                par0ComponentVillageStartPiece.structVillagePieceWeight = var12;
    146
    147                                if (!var12.canSpawnMoreVillagePieces())
    148                                {
    149                                    par0ComponentVillageStartPiece.structureVillageWeightedPieceList.remove(var12);
    150                                }
    151
    152                                return var13;
    153                            }
    154                        }
    155                    }
    156                }
    157
    158                StructureBoundingBox var14 = ComponentVillageTorch.func_74904_a(par0ComponentVillageStartPiece, par1List, par2Random, par3, par4, par5, par6);
    159
    160                if (var14 != null)
    161                {
    162                    return new ComponentVillageTorch(par0ComponentVillageStartPiece, par7, par2Random, var14, par6);
    163                }
    164                else
    165                {
    166                    return null;
    167                }
    168            }
    169        }
    170
    171        /**
    172         * attempts to find a next Structure Component to be spawned, private Village function
    173         */
    174        private static StructureComponent getNextVillageStructureComponent(ComponentVillageStartPiece par0ComponentVillageStartPiece, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
    175        {
    176            if (par7 > 50)
    177            {
    178                return null;
    179            }
    180            else if (Math.abs(par3 - par0ComponentVillageStartPiece.getBoundingBox().minX) <= 112 && Math.abs(par5 - par0ComponentVillageStartPiece.getBoundingBox().minZ) <= 112)
    181            {
    182                ComponentVillage var8 = getNextVillageComponent(par0ComponentVillageStartPiece, par1List, par2Random, par3, par4, par5, par6, par7 + 1);
    183
    184                if (var8 != null)
    185                {
    186                    int var9 = (var8.boundingBox.minX + var8.boundingBox.maxX) / 2;
    187                    int var10 = (var8.boundingBox.minZ + var8.boundingBox.maxZ) / 2;
    188                    int var11 = var8.boundingBox.maxX - var8.boundingBox.minX;
    189                    int var12 = var8.boundingBox.maxZ - var8.boundingBox.minZ;
    190                    int var13 = var11 > var12 ? var11 : var12;
    191
    192                    if (par0ComponentVillageStartPiece.getWorldChunkManager().areBiomesViable(var9, var10, var13 / 2 + 4, MapGenVillage.villageSpawnBiomes))
    193                    {
    194                        par1List.add(var8);
    195                        par0ComponentVillageStartPiece.field_74932_i.add(var8);
    196                        return var8;
    197                    }
    198                }
    199
    200                return null;
    201            }
    202            else
    203            {
    204                return null;
    205            }
    206        }
    207
    208        private static StructureComponent getNextComponentVillagePath(ComponentVillageStartPiece par0ComponentVillageStartPiece, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
    209        {
    210            if (par7 > 3 + par0ComponentVillageStartPiece.terrainType)
    211            {
    212                return null;
    213            }
    214            else if (Math.abs(par3 - par0ComponentVillageStartPiece.getBoundingBox().minX) <= 112 && Math.abs(par5 - par0ComponentVillageStartPiece.getBoundingBox().minZ) <= 112)
    215            {
    216                StructureBoundingBox var8 = ComponentVillagePathGen.func_74933_a(par0ComponentVillageStartPiece, par1List, par2Random, par3, par4, par5, par6);
    217
    218                if (var8 != null && var8.minY > 10)
    219                {
    220                    ComponentVillagePathGen var9 = new ComponentVillagePathGen(par0ComponentVillageStartPiece, par7, par2Random, var8, par6);
    221                    int var10 = (var9.boundingBox.minX + var9.boundingBox.maxX) / 2;
    222                    int var11 = (var9.boundingBox.minZ + var9.boundingBox.maxZ) / 2;
    223                    int var12 = var9.boundingBox.maxX - var9.boundingBox.minX;
    224                    int var13 = var9.boundingBox.maxZ - var9.boundingBox.minZ;
    225                    int var14 = var12 > var13 ? var12 : var13;
    226
    227                    if (par0ComponentVillageStartPiece.getWorldChunkManager().areBiomesViable(var10, var11, var14 / 2 + 4, MapGenVillage.villageSpawnBiomes))
    228                    {
    229                        par1List.add(var9);
    230                        par0ComponentVillageStartPiece.field_74930_j.add(var9);
    231                        return var9;
    232                    }
    233                }
    234
    235                return null;
    236            }
    237            else
    238            {
    239                return null;
    240            }
    241        }
    242
    243        /**
    244         * attempts to find a next Structure Component to be spawned
    245         */
    246        static StructureComponent getNextStructureComponent(ComponentVillageStartPiece par0ComponentVillageStartPiece, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
    247        {
    248            return getNextVillageStructureComponent(par0ComponentVillageStartPiece, par1List, par2Random, par3, par4, par5, par6, par7);
    249        }
    250
    251        static StructureComponent getNextStructureComponentVillagePath(ComponentVillageStartPiece par0ComponentVillageStartPiece, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
    252        {
    253            return getNextComponentVillagePath(par0ComponentVillageStartPiece, par1List, par2Random, par3, par4, par5, par6, par7);
    254        }
    255    }