    001package net.minecraft.world.gen.structure;
    002
    003import java.util.Iterator;
    004import java.util.LinkedList;
    005import java.util.List;
    006import java.util.Random;
    007import net.minecraft.block.Block;
    008import net.minecraft.world.World;
    009
    010public class ComponentMineshaftRoom extends StructureComponent
    011{
    012    /** List of other Mineshaft components linked to this room. */
    013    private List roomsLinkedToTheRoom = new LinkedList();
    014
    015    public ComponentMineshaftRoom(int par1, Random par2Random, int par3, int par4)
    016    {
    017        super(par1);
    018        this.boundingBox = new StructureBoundingBox(par3, 50, par4, par3 + 7 + par2Random.nextInt(6), 54 + par2Random.nextInt(6), par4 + 7 + par2Random.nextInt(6));
    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        int i = this.getComponentType();
    027        int j = this.boundingBox.getYSize() - 3 - 1;
    028
    029        if (j <= 0)
    030        {
    031            j = 1;
    032        }
    033
    034        int k;
    035        StructureComponent structurecomponent1;
    036        StructureBoundingBox structureboundingbox;
    037
    038        for (k = 0; k < this.boundingBox.getXSize(); k += 4)
    039        {
    040            k += par3Random.nextInt(this.boundingBox.getXSize());
    041
    042            if (k + 3 > this.boundingBox.getXSize())
    043            {
    044                break;
    045            }
    046
    047            structurecomponent1 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + k, this.boundingBox.minY + par3Random.nextInt(j) + 1, this.boundingBox.minZ - 1, 2, i);
    048
    049            if (structurecomponent1 != null)
    050            {
    051                structureboundingbox = structurecomponent1.getBoundingBox();
    052                this.roomsLinkedToTheRoom.add(new StructureBoundingBox(structureboundingbox.minX, structureboundingbox.minY, this.boundingBox.minZ, structureboundingbox.maxX, structureboundingbox.maxY, this.boundingBox.minZ + 1));
    053            }
    054        }
    055
    056        for (k = 0; k < this.boundingBox.getXSize(); k += 4)
    057        {
    058            k += par3Random.nextInt(this.boundingBox.getXSize());
    059
    060            if (k + 3 > this.boundingBox.getXSize())
    061            {
    062                break;
    063            }
    064
    065            structurecomponent1 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + k, this.boundingBox.minY + par3Random.nextInt(j) + 1, this.boundingBox.maxZ + 1, 0, i);
    066
    067            if (structurecomponent1 != null)
    068            {
    069                structureboundingbox = structurecomponent1.getBoundingBox();
    070                this.roomsLinkedToTheRoom.add(new StructureBoundingBox(structureboundingbox.minX, structureboundingbox.minY, this.boundingBox.maxZ - 1, structureboundingbox.maxX, structureboundingbox.maxY, this.boundingBox.maxZ));
    071            }
    072        }
    073
    074        for (k = 0; k < this.boundingBox.getZSize(); k += 4)
    075        {
    076            k += par3Random.nextInt(this.boundingBox.getZSize());
    077
    078            if (k + 3 > this.boundingBox.getZSize())
    079            {
    080                break;
    081            }
    082
    083            structurecomponent1 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY + par3Random.nextInt(j) + 1, this.boundingBox.minZ + k, 1, i);
    084
    085            if (structurecomponent1 != null)
    086            {
    087                structureboundingbox = structurecomponent1.getBoundingBox();
    088                this.roomsLinkedToTheRoom.add(new StructureBoundingBox(this.boundingBox.minX, structureboundingbox.minY, structureboundingbox.minZ, this.boundingBox.minX + 1, structureboundingbox.maxY, structureboundingbox.maxZ));
    089            }
    090        }
    091
    092        for (k = 0; k < this.boundingBox.getZSize(); k += 4)
    093        {
    094            k += par3Random.nextInt(this.boundingBox.getZSize());
    095
    096            if (k + 3 > this.boundingBox.getZSize())
    097            {
    098                break;
    099            }
    100
    101            structurecomponent1 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY + par3Random.nextInt(j) + 1, this.boundingBox.minZ + k, 3, i);
    102
    103            if (structurecomponent1 != null)
    104            {
    105                structureboundingbox = structurecomponent1.getBoundingBox();
    106                this.roomsLinkedToTheRoom.add(new StructureBoundingBox(this.boundingBox.maxX - 1, structureboundingbox.minY, structureboundingbox.minZ, this.boundingBox.maxX, structureboundingbox.maxY, structureboundingbox.maxZ));
    107            }
    108        }
    109    }
    110
    111    /**
    112     * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at
    113     * the end, it adds Fences...
    114     */
    115    public boolean addComponentParts(World par1World, Random par2Random, StructureBoundingBox par3StructureBoundingBox)
    116    {
    117        if (this.isLiquidInStructureBoundingBox(par1World, par3StructureBoundingBox))
    118        {
    119            return false;
    120        }
    121        else
    122        {
    123            this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ, this.boundingBox.maxX, this.boundingBox.minY, this.boundingBox.maxZ, Block.dirt.blockID, 0, true);
    124            this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX, this.boundingBox.minY + 1, this.boundingBox.minZ, this.boundingBox.maxX, Math.min(this.boundingBox.minY + 3, this.boundingBox.maxY), this.boundingBox.maxZ, 0, 0, false);
    125            Iterator iterator = this.roomsLinkedToTheRoom.iterator();
    126
    127            while (iterator.hasNext())
    128            {
    129                StructureBoundingBox structureboundingbox1 = (StructureBoundingBox)iterator.next();
    130                this.fillWithBlocks(par1World, par3StructureBoundingBox, structureboundingbox1.minX, structureboundingbox1.maxY - 2, structureboundingbox1.minZ, structureboundingbox1.maxX, structureboundingbox1.maxY, structureboundingbox1.maxZ, 0, 0, false);
    131            }
    132
    133            this.randomlyRareFillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX, this.boundingBox.minY + 4, this.boundingBox.minZ, this.boundingBox.maxX, this.boundingBox.maxY, this.boundingBox.maxZ, 0, false);
    134            return true;
    135        }
    136    }
    137}