001package net.minecraft.world.gen.structure;
002
003import java.util.Iterator;
004import java.util.LinkedList;
005import java.util.Random;
006import net.minecraft.world.World;
007
008public abstract class StructureStart
009{
010    /** List of all StructureComponents that are part of this structure */
011    protected LinkedList components = new LinkedList();
012    protected StructureBoundingBox boundingBox;
013
014    public StructureBoundingBox getBoundingBox()
015    {
016        return this.boundingBox;
017    }
018
019    public LinkedList getComponents()
020    {
021        return this.components;
022    }
023
024    /**
025     * Keeps iterating Structure Pieces and spawning them until the checks tell it to stop
026     */
027    public void generateStructure(World par1World, Random par2Random, StructureBoundingBox par3StructureBoundingBox)
028    {
029        Iterator iterator = this.components.iterator();
030
031        while (iterator.hasNext())
032        {
033            StructureComponent structurecomponent = (StructureComponent)iterator.next();
034
035            if (structurecomponent.getBoundingBox().intersectsWith(par3StructureBoundingBox) && !structurecomponent.addComponentParts(par1World, par2Random, par3StructureBoundingBox))
036            {
037                iterator.remove();
038            }
039        }
040    }
041
042    /**
043     * Calculates total bounding box based on components' bounding boxes and saves it to boundingBox
044     */
045    protected void updateBoundingBox()
046    {
047        this.boundingBox = StructureBoundingBox.getNewBoundingBox();
048        Iterator iterator = this.components.iterator();
049
050        while (iterator.hasNext())
051        {
052            StructureComponent structurecomponent = (StructureComponent)iterator.next();
053            this.boundingBox.expandTo(structurecomponent.getBoundingBox());
054        }
055    }
056
057    /**
058     * offsets the structure Bounding Boxes up to a certain height, typically 63 - 10
059     */
060    protected void markAvailableHeight(World par1World, Random par2Random, int par3)
061    {
062        int j = 63 - par3;
063        int k = this.boundingBox.getYSize() + 1;
064
065        if (k < j)
066        {
067            k += par2Random.nextInt(j - k);
068        }
069
070        int l = k - this.boundingBox.maxY;
071        this.boundingBox.offset(0, l, 0);
072        Iterator iterator = this.components.iterator();
073
074        while (iterator.hasNext())
075        {
076            StructureComponent structurecomponent = (StructureComponent)iterator.next();
077            structurecomponent.getBoundingBox().offset(0, l, 0);
078        }
079    }
080
081    protected void setRandomHeight(World par1World, Random par2Random, int par3, int par4)
082    {
083        int k = par4 - par3 + 1 - this.boundingBox.getYSize();
084        boolean flag = true;
085        int l;
086
087        if (k > 1)
088        {
089            l = par3 + par2Random.nextInt(k);
090        }
091        else
092        {
093            l = par3;
094        }
095
096        int i1 = l - this.boundingBox.minY;
097        this.boundingBox.offset(0, i1, 0);
098        Iterator iterator = this.components.iterator();
099
100        while (iterator.hasNext())
101        {
102            StructureComponent structurecomponent = (StructureComponent)iterator.next();
103            structurecomponent.getBoundingBox().offset(0, i1, 0);
104        }
105    }
106
107    /**
108     * currently only defined for Villages, returns true if Village has more than 2 non-road components
109     */
110    public boolean isSizeableStructure()
111    {
112        return true;
113    }
114}