    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 var4 = this.getComponentType();
    027        int var6 = this.boundingBox.getYSize() - 3 - 1;
    028
    029        if (var6 <= 0)
    030        {
    031            var6 = 1;
    032        }
    033
    034        int var5;
    035        StructureComponent var7;
    036        StructureBoundingBox var8;
    037
    038        for (var5 = 0; var5 < this.boundingBox.getXSize(); var5 += 4)
    039        {
    040            var5 += par3Random.nextInt(this.boundingBox.getXSize());
    041
    042            if (var5 + 3 > this.boundingBox.getXSize())
    043            {
    044                break;
    045            }
    046
    047            var7 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + var5, this.boundingBox.minY + par3Random.nextInt(var6) + 1, this.boundingBox.minZ - 1, 2, var4);
    048
    049            if (var7 != null)
    050            {
    051                var8 = var7.getBoundingBox();
    052                this.roomsLinkedToTheRoom.add(new StructureBoundingBox(var8.minX, var8.minY, this.boundingBox.minZ, var8.maxX, var8.maxY, this.boundingBox.minZ + 1));
    053            }
    054        }
    055
    056        for (var5 = 0; var5 < this.boundingBox.getXSize(); var5 += 4)
    057        {
    058            var5 += par3Random.nextInt(this.boundingBox.getXSize());
    059
    060            if (var5 + 3 > this.boundingBox.getXSize())
    061            {
    062                break;
    063            }
    064
    065            var7 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + var5, this.boundingBox.minY + par3Random.nextInt(var6) + 1, this.boundingBox.maxZ + 1, 0, var4);
    066
    067            if (var7 != null)
    068            {
    069                var8 = var7.getBoundingBox();
    070                this.roomsLinkedToTheRoom.add(new StructureBoundingBox(var8.minX, var8.minY, this.boundingBox.maxZ - 1, var8.maxX, var8.maxY, this.boundingBox.maxZ));
    071            }
    072        }
    073
    074        for (var5 = 0; var5 < this.boundingBox.getZSize(); var5 += 4)
    075        {
    076            var5 += par3Random.nextInt(this.boundingBox.getZSize());
    077
    078            if (var5 + 3 > this.boundingBox.getZSize())
    079            {
    080                break;
    081            }
    082
    083            var7 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY + par3Random.nextInt(var6) + 1, this.boundingBox.minZ + var5, 1, var4);
    084
    085            if (var7 != null)
    086            {
    087                var8 = var7.getBoundingBox();
    088                this.roomsLinkedToTheRoom.add(new StructureBoundingBox(this.boundingBox.minX, var8.minY, var8.minZ, this.boundingBox.minX + 1, var8.maxY, var8.maxZ));
    089            }
    090        }
    091
    092        for (var5 = 0; var5 < this.boundingBox.getZSize(); var5 += 4)
    093        {
    094            var5 += par3Random.nextInt(this.boundingBox.getZSize());
    095
    096            if (var5 + 3 > this.boundingBox.getZSize())
    097            {
    098                break;
    099            }
    100
    101            var7 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY + par3Random.nextInt(var6) + 1, this.boundingBox.minZ + var5, 3, var4);
    102
    103            if (var7 != null)
    104            {
    105                var8 = var7.getBoundingBox();
    106                this.roomsLinkedToTheRoom.add(new StructureBoundingBox(this.boundingBox.maxX - 1, var8.minY, var8.minZ, this.boundingBox.maxX, var8.maxY, var8.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 var4 = this.roomsLinkedToTheRoom.iterator();
    126
    127            while (var4.hasNext())
    128            {
    129                StructureBoundingBox var5 = (StructureBoundingBox)var4.next();
    130                this.fillWithBlocks(par1World, par3StructureBoundingBox, var5.minX, var5.maxY - 2, var5.minZ, var5.maxX, var5.maxY, var5.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}