    001package net.minecraft.world.gen.structure;
    002
    003import java.util.List;
    004import java.util.Random;
    005import net.minecraft.block.Block;
    006import net.minecraft.world.World;
    007
    008public class ComponentMineshaftCross extends StructureComponent
    009{
    010    private final int corridorDirection;
    011    private final boolean isMultipleFloors;
    012
    013    public ComponentMineshaftCross(int par1, Random par2Random, StructureBoundingBox par3StructureBoundingBox, int par4)
    014    {
    015        super(par1);
    016        this.corridorDirection = par4;
    017        this.boundingBox = par3StructureBoundingBox;
    018        this.isMultipleFloors = par3StructureBoundingBox.getYSize() > 3;
    019    }
    020
    021    public static StructureBoundingBox findValidPlacement(List par0List, Random par1Random, int par2, int par3, int par4, int par5)
    022    {
    023        StructureBoundingBox structureboundingbox = new StructureBoundingBox(par2, par3, par4, par2, par3 + 2, par4);
    024
    025        if (par1Random.nextInt(4) == 0)
    026        {
    027            structureboundingbox.maxY += 4;
    028        }
    029
    030        switch (par5)
    031        {
    032            case 0:
    033                structureboundingbox.minX = par2 - 1;
    034                structureboundingbox.maxX = par2 + 3;
    035                structureboundingbox.maxZ = par4 + 4;
    036                break;
    037            case 1:
    038                structureboundingbox.minX = par2 - 4;
    039                structureboundingbox.minZ = par4 - 1;
    040                structureboundingbox.maxZ = par4 + 3;
    041                break;
    042            case 2:
    043                structureboundingbox.minX = par2 - 1;
    044                structureboundingbox.maxX = par2 + 3;
    045                structureboundingbox.minZ = par4 - 4;
    046                break;
    047            case 3:
    048                structureboundingbox.maxX = par2 + 4;
    049                structureboundingbox.minZ = par4 - 1;
    050                structureboundingbox.maxZ = par4 + 3;
    051        }
    052
    053        return StructureComponent.findIntersecting(par0List, structureboundingbox) != null ? null : structureboundingbox;
    054    }
    055
    056    /**
    057     * Initiates construction of the Structure Component picked, at the current Location of StructGen
    058     */
    059    public void buildComponent(StructureComponent par1StructureComponent, List par2List, Random par3Random)
    060    {
    061        int i = this.getComponentType();
    062
    063        switch (this.corridorDirection)
    064        {
    065            case 0:
    066                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ + 1, 0, i);
    067                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, 1, i);
    068                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, 3, i);
    069                break;
    070            case 1:
    071                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ - 1, 2, i);
    072                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ + 1, 0, i);
    073                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, 1, i);
    074                break;
    075            case 2:
    076                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ - 1, 2, i);
    077                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, 1, i);
    078                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, 3, i);
    079                break;
    080            case 3:
    081                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ - 1, 2, i);
    082                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ + 1, 0, i);
    083                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, 3, i);
    084        }
    085
    086        if (this.isMultipleFloors)
    087        {
    088            if (par3Random.nextBoolean())
    089            {
    090                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + 1, this.boundingBox.minY + 3 + 1, this.boundingBox.minZ - 1, 2, i);
    091            }
    092
    093            if (par3Random.nextBoolean())
    094            {
    095                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY + 3 + 1, this.boundingBox.minZ + 1, 1, i);
    096            }
    097
    098            if (par3Random.nextBoolean())
    099            {
    100                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY + 3 + 1, this.boundingBox.minZ + 1, 3, i);
    101            }
    102
    103            if (par3Random.nextBoolean())
    104            {
    105                StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + 1, this.boundingBox.minY + 3 + 1, this.boundingBox.maxZ + 1, 0, i);
    106            }
    107        }
    108    }
    109
    110    /**
    111     * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at
    112     * the end, it adds Fences...
    113     */
    114    public boolean addComponentParts(World par1World, Random par2Random, StructureBoundingBox par3StructureBoundingBox)
    115    {
    116        if (this.isLiquidInStructureBoundingBox(par1World, par3StructureBoundingBox))
    117        {
    118            return false;
    119        }
    120        else
    121        {
    122            if (this.isMultipleFloors)
    123            {
    124                this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ, this.boundingBox.maxX - 1, this.boundingBox.minY + 3 - 1, this.boundingBox.maxZ, 0, 0, false);
    125                this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxX, this.boundingBox.minY + 3 - 1, this.boundingBox.maxZ - 1, 0, 0, false);
    126                this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX + 1, this.boundingBox.maxY - 2, this.boundingBox.minZ, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.maxZ, 0, 0, false);
    127                this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX, this.boundingBox.maxY - 2, this.boundingBox.minZ + 1, this.boundingBox.maxX, this.boundingBox.maxY, this.boundingBox.maxZ - 1, 0, 0, false);
    128                this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX + 1, this.boundingBox.minY + 3, this.boundingBox.minZ + 1, this.boundingBox.maxX - 1, this.boundingBox.minY + 3, this.boundingBox.maxZ - 1, 0, 0, false);
    129            }
    130            else
    131            {
    132                this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.maxZ, 0, 0, false);
    133                this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxX, this.boundingBox.maxY, this.boundingBox.maxZ - 1, 0, 0, false);
    134            }
    135
    136            this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.minX + 1, this.boundingBox.maxY, this.boundingBox.minZ + 1, Block.planks.blockID, 0, false);
    137            this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ - 1, this.boundingBox.minX + 1, this.boundingBox.maxY, this.boundingBox.maxZ - 1, Block.planks.blockID, 0, false);
    138            this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.maxX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.minZ + 1, Block.planks.blockID, 0, false);
    139            this.fillWithBlocks(par1World, par3StructureBoundingBox, this.boundingBox.maxX - 1, this.boundingBox.minY, this.boundingBox.maxZ - 1, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.maxZ - 1, Block.planks.blockID, 0, false);
    140
    141            for (int i = this.boundingBox.minX; i <= this.boundingBox.maxX; ++i)
    142            {
    143                for (int j = this.boundingBox.minZ; j <= this.boundingBox.maxZ; ++j)
    144                {
    145                    int k = this.getBlockIdAtCurrentPosition(par1World, i, this.boundingBox.minY - 1, j, par3StructureBoundingBox);
    146
    147                    if (k == 0)
    148                    {
    149                        this.placeBlockAtCurrentPosition(par1World, Block.planks.blockID, 0, i, this.boundingBox.minY - 1, j, par3StructureBoundingBox);
    150                    }
    151                }
    152            }
    153
    154            return true;
    155        }
    156    }
    157}