    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 var4 = this.components.iterator();
    030
    031        while (var4.hasNext())
    032        {
    033            StructureComponent var5 = (StructureComponent)var4.next();
    034
    035            if (var5.getBoundingBox().intersectsWith(par3StructureBoundingBox) && !var5.addComponentParts(par1World, par2Random, par3StructureBoundingBox))
    036            {
    037                var4.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 var1 = this.components.iterator();
    049
    050        while (var1.hasNext())
    051        {
    052            StructureComponent var2 = (StructureComponent)var1.next();
    053            this.boundingBox.expandTo(var2.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 var4 = 63 - par3;
    063        int var5 = this.boundingBox.getYSize() + 1;
    064
    065        if (var5 < var4)
    066        {
    067            var5 += par2Random.nextInt(var4 - var5);
    068        }
    069
    070        int var6 = var5 - this.boundingBox.maxY;
    071        this.boundingBox.offset(0, var6, 0);
    072        Iterator var7 = this.components.iterator();
    073
    074        while (var7.hasNext())
    075        {
    076            StructureComponent var8 = (StructureComponent)var7.next();
    077            var8.getBoundingBox().offset(0, var6, 0);
    078        }
    079    }
    080
    081    protected void setRandomHeight(World par1World, Random par2Random, int par3, int par4)
    082    {
    083        int var5 = par4 - par3 + 1 - this.boundingBox.getYSize();
    084        boolean var6 = true;
    085        int var10;
    086
    087        if (var5 > 1)
    088        {
    089            var10 = par3 + par2Random.nextInt(var5);
    090        }
    091        else
    092        {
    093            var10 = par3;
    094        }
    095
    096        int var7 = var10 - this.boundingBox.minY;
    097        this.boundingBox.offset(0, var7, 0);
    098        Iterator var8 = this.components.iterator();
    099
    100        while (var8.hasNext())
    101        {
    102            StructureComponent var9 = (StructureComponent)var8.next();
    103            var9.getBoundingBox().offset(0, var7, 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}