001package net.minecraft.world.gen.structure;
002
003import java.util.List;
004import java.util.Random;
005import net.minecraft.block.Block;
006import net.minecraft.util.MathHelper;
007import net.minecraft.world.World;
008
009public class ComponentVillagePathGen extends ComponentVillageRoadPiece
010{
011    private int averageGroundLevel;
012
013    public ComponentVillagePathGen(ComponentVillageStartPiece par1ComponentVillageStartPiece, int par2, Random par3Random, StructureBoundingBox par4StructureBoundingBox, int par5)
014    {
015        super(par1ComponentVillageStartPiece, par2);
016        this.coordBaseMode = par5;
017        this.boundingBox = par4StructureBoundingBox;
018        this.averageGroundLevel = Math.max(par4StructureBoundingBox.getXSize(), par4StructureBoundingBox.getZSize());
019    }
020
021    /**
022     * Initiates construction of the Structure Component picked, at the current Location of StructGen
023     */
024    public void buildComponent(StructureComponent par1StructureComponent, List par2List, Random par3Random)
025    {
026        boolean flag = false;
027        int i;
028        StructureComponent structurecomponent1;
029
030        for (i = par3Random.nextInt(5); i < this.averageGroundLevel - 8; i += 2 + par3Random.nextInt(5))
031        {
032            structurecomponent1 = this.getNextComponentNN((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, 0, i);
033
034            if (structurecomponent1 != null)
035            {
036                i += Math.max(structurecomponent1.boundingBox.getXSize(), structurecomponent1.boundingBox.getZSize());
037                flag = true;
038            }
039        }
040
041        for (i = par3Random.nextInt(5); i < this.averageGroundLevel - 8; i += 2 + par3Random.nextInt(5))
042        {
043            structurecomponent1 = this.getNextComponentPP((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, 0, i);
044
045            if (structurecomponent1 != null)
046            {
047                i += Math.max(structurecomponent1.boundingBox.getXSize(), structurecomponent1.boundingBox.getZSize());
048                flag = true;
049            }
050        }
051
052        if (flag && par3Random.nextInt(3) > 0)
053        {
054            switch (this.coordBaseMode)
055            {
056                case 0:
057                    StructureVillagePieces.getNextStructureComponentVillagePath((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.maxZ - 2, 1, this.getComponentType());
058                    break;
059                case 1:
060                    StructureVillagePieces.getNextStructureComponentVillagePath((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ - 1, 2, this.getComponentType());
061                    break;
062                case 2:
063                    StructureVillagePieces.getNextStructureComponentVillagePath((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ, 1, this.getComponentType());
064                    break;
065                case 3:
066                    StructureVillagePieces.getNextStructureComponentVillagePath((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, this.boundingBox.maxX - 2, this.boundingBox.minY, this.boundingBox.minZ - 1, 2, this.getComponentType());
067            }
068        }
069
070        if (flag && par3Random.nextInt(3) > 0)
071        {
072            switch (this.coordBaseMode)
073            {
074                case 0:
075                    StructureVillagePieces.getNextStructureComponentVillagePath((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.maxZ - 2, 3, this.getComponentType());
076                    break;
077                case 1:
078                    StructureVillagePieces.getNextStructureComponentVillagePath((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.maxZ + 1, 0, this.getComponentType());
079                    break;
080                case 2:
081                    StructureVillagePieces.getNextStructureComponentVillagePath((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ, 3, this.getComponentType());
082                    break;
083                case 3:
084                    StructureVillagePieces.getNextStructureComponentVillagePath((ComponentVillageStartPiece)par1StructureComponent, par2List, par3Random, this.boundingBox.maxX - 2, this.boundingBox.minY, this.boundingBox.maxZ + 1, 0, this.getComponentType());
085            }
086        }
087    }
088
089    public static StructureBoundingBox func_74933_a(ComponentVillageStartPiece par0ComponentVillageStartPiece, List par1List, Random par2Random, int par3, int par4, int par5, int par6)
090    {
091        for (int i1 = 7 * MathHelper.getRandomIntegerInRange(par2Random, 3, 5); i1 >= 7; i1 -= 7)
092        {
093            StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(par3, par4, par5, 0, 0, 0, 3, 3, i1, par6);
094
095            if (StructureComponent.findIntersecting(par1List, structureboundingbox) == null)
096            {
097                return structureboundingbox;
098            }
099        }
100
101        return null;
102    }
103
104    /**
105     * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at
106     * the end, it adds Fences...
107     */
108    public boolean addComponentParts(World par1World, Random par2Random, StructureBoundingBox par3StructureBoundingBox)
109    {
110        int i = this.getBiomeSpecificBlock(Block.gravel.blockID, 0);
111
112        for (int j = this.boundingBox.minX; j <= this.boundingBox.maxX; ++j)
113        {
114            for (int k = this.boundingBox.minZ; k <= this.boundingBox.maxZ; ++k)
115            {
116                if (par3StructureBoundingBox.isVecInside(j, 64, k))
117                {
118                    int l = par1World.getTopSolidOrLiquidBlock(j, k) - 1;
119                    par1World.setBlockAndMetadataWithNotify(j, l, k, i, 0, 2);
120                }
121            }
122        }
123
124        return true;
125    }
126}