    001package net.minecraft.world.gen.structure;
    002
    003public class StructureBoundingBox
    004{
    005    /** The first x coordinate of a bounding box. */
    006    public int minX;
    007
    008    /** The first y coordinate of a bounding box. */
    009    public int minY;
    010
    011    /** The first z coordinate of a bounding box. */
    012    public int minZ;
    013
    014    /** The second x coordinate of a bounding box. */
    015    public int maxX;
    016
    017    /** The second y coordinate of a bounding box. */
    018    public int maxY;
    019
    020    /** The second z coordinate of a bounding box. */
    021    public int maxZ;
    022
    023    public StructureBoundingBox() {}
    024
    025    /**
    026     * returns a new StructureBoundingBox with MAX values
    027     */
    028    public static StructureBoundingBox getNewBoundingBox()
    029    {
    030        return new StructureBoundingBox(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
    031    }
    032
    033    /**
    034     * used to project a possible new component Bounding Box - to check if it would cut anything already spawned
    035     */
    036    public static StructureBoundingBox getComponentToAddBoundingBox(int par0, int par1, int par2, int par3, int par4, int par5, int par6, int par7, int par8, int par9)
    037    {
    038        switch (par9)
    039        {
    040            case 0:
    041                return new StructureBoundingBox(par0 + par3, par1 + par4, par2 + par5, par0 + par6 - 1 + par3, par1 + par7 - 1 + par4, par2 + par8 - 1 + par5);
    042            case 1:
    043                return new StructureBoundingBox(par0 - par8 + 1 + par5, par1 + par4, par2 + par3, par0 + par5, par1 + par7 - 1 + par4, par2 + par6 - 1 + par3);
    044            case 2:
    045                return new StructureBoundingBox(par0 + par3, par1 + par4, par2 - par8 + 1 + par5, par0 + par6 - 1 + par3, par1 + par7 - 1 + par4, par2 + par5);
    046            case 3:
    047                return new StructureBoundingBox(par0 + par5, par1 + par4, par2 + par3, par0 + par8 - 1 + par5, par1 + par7 - 1 + par4, par2 + par6 - 1 + par3);
    048            default:
    049                return new StructureBoundingBox(par0 + par3, par1 + par4, par2 + par5, par0 + par6 - 1 + par3, par1 + par7 - 1 + par4, par2 + par8 - 1 + par5);
    050        }
    051    }
    052
    053    public StructureBoundingBox(StructureBoundingBox par1StructureBoundingBox)
    054    {
    055        this.minX = par1StructureBoundingBox.minX;
    056        this.minY = par1StructureBoundingBox.minY;
    057        this.minZ = par1StructureBoundingBox.minZ;
    058        this.maxX = par1StructureBoundingBox.maxX;
    059        this.maxY = par1StructureBoundingBox.maxY;
    060        this.maxZ = par1StructureBoundingBox.maxZ;
    061    }
    062
    063    public StructureBoundingBox(int par1, int par2, int par3, int par4, int par5, int par6)
    064    {
    065        this.minX = par1;
    066        this.minY = par2;
    067        this.minZ = par3;
    068        this.maxX = par4;
    069        this.maxY = par5;
    070        this.maxZ = par6;
    071    }
    072
    073    public StructureBoundingBox(int par1, int par2, int par3, int par4)
    074    {
    075        this.minX = par1;
    076        this.minZ = par2;
    077        this.maxX = par3;
    078        this.maxZ = par4;
    079        this.minY = 1;
    080        this.maxY = 512;
    081    }
    082
    083    /**
    084     * Returns whether the given bounding box intersects with this one. Args: structureboundingbox
    085     */
    086    public boolean intersectsWith(StructureBoundingBox par1StructureBoundingBox)
    087    {
    088        return this.maxX >= par1StructureBoundingBox.minX && this.minX <= par1StructureBoundingBox.maxX && this.maxZ >= par1StructureBoundingBox.minZ && this.minZ <= par1StructureBoundingBox.maxZ && this.maxY >= par1StructureBoundingBox.minY && this.minY <= par1StructureBoundingBox.maxY;
    089    }
    090
    091    /**
    092     * Discover if a coordinate is inside the bounding box area.
    093     */
    094    public boolean intersectsWith(int par1, int par2, int par3, int par4)
    095    {
    096        return this.maxX >= par1 && this.minX <= par3 && this.maxZ >= par2 && this.minZ <= par4;
    097    }
    098
    099    /**
    100     * Expands a bounding box's dimensions to include the supplied bounding box.
    101     */
    102    public void expandTo(StructureBoundingBox par1StructureBoundingBox)
    103    {
    104        this.minX = Math.min(this.minX, par1StructureBoundingBox.minX);
    105        this.minY = Math.min(this.minY, par1StructureBoundingBox.minY);
    106        this.minZ = Math.min(this.minZ, par1StructureBoundingBox.minZ);
    107        this.maxX = Math.max(this.maxX, par1StructureBoundingBox.maxX);
    108        this.maxY = Math.max(this.maxY, par1StructureBoundingBox.maxY);
    109        this.maxZ = Math.max(this.maxZ, par1StructureBoundingBox.maxZ);
    110    }
    111
    112    /**
    113     * Offsets the current bounding box by the specified coordinates. Args: x, y, z
    114     */
    115    public void offset(int par1, int par2, int par3)
    116    {
    117        this.minX += par1;
    118        this.minY += par2;
    119        this.minZ += par3;
    120        this.maxX += par1;
    121        this.maxY += par2;
    122        this.maxZ += par3;
    123    }
    124
    125    /**
    126     * Returns true if block is inside bounding box
    127     */
    128    public boolean isVecInside(int par1, int par2, int par3)
    129    {
    130        return par1 >= this.minX && par1 <= this.maxX && par3 >= this.minZ && par3 <= this.maxZ && par2 >= this.minY && par2 <= this.maxY;
    131    }
    132
    133    /**
    134     * Returns width of a bounding box
    135     */
    136    public int getXSize()
    137    {
    138        return this.maxX - this.minX + 1;
    139    }
    140
    141    /**
    142     * Returns height of a bounding box
    143     */
    144    public int getYSize()
    145    {
    146        return this.maxY - this.minY + 1;
    147    }
    148
    149    /**
    150     * Returns length of a bounding box
    151     */
    152    public int getZSize()
    153    {
    154        return this.maxZ - this.minZ + 1;
    155    }
    156
    157    public int getCenterX()
    158    {
    159        return this.minX + (this.maxX - this.minX + 1) / 2;
    160    }
    161
    162    public int getCenterY()
    163    {
    164        return this.minY + (this.maxY - this.minY + 1) / 2;
    165    }
    166
    167    public int getCenterZ()
    168    {
    169        return this.minZ + (this.maxZ - this.minZ + 1) / 2;
    170    }
    171
    172    public String toString()
    173    {
    174        return "(" + this.minX + ", " + this.minY + ", " + this.minZ + "; " + this.maxX + ", " + this.maxY + ", " + this.maxZ + ")";
    175    }
    176}