    001    package net.minecraft.world.gen.structure;
    002
    003    import java.util.List;
    004    import java.util.Random;
    005    import net.minecraft.block.Block;
    006    import net.minecraft.tileentity.TileEntityMobSpawner;
    007    import net.minecraft.world.World;
    008
    009    import net.minecraftforge.common.ChestGenHooks;
    010    import static net.minecraftforge.common.ChestGenHooks.*;
    011
    012    public class ComponentMineshaftCorridor extends StructureComponent
    013    {
    014        private final boolean hasRails;
    015        private final boolean hasSpiders;
    016        private boolean spawnerPlaced;
    017
    018        /**
    019         * A count of the different sections of this mine. The space between ceiling supports.
    020         */
    021        private int sectionCount;
    022
    023        public ComponentMineshaftCorridor(int par1, Random par2Random, StructureBoundingBox par3StructureBoundingBox, int par4)
    024        {
    025            super(par1);
    026            this.coordBaseMode = par4;
    027            this.boundingBox = par3StructureBoundingBox;
    028            this.hasRails = par2Random.nextInt(3) == 0;
    029            this.hasSpiders = !this.hasRails && par2Random.nextInt(23) == 0;
    030
    031            if (this.coordBaseMode != 2 && this.coordBaseMode != 0)
    032            {
    033                this.sectionCount = par3StructureBoundingBox.getXSize() / 5;
    034            }
    035            else
    036            {
    037                this.sectionCount = par3StructureBoundingBox.getZSize() / 5;
    038            }
    039        }
    040
    041        public static StructureBoundingBox findValidPlacement(List par0List, Random par1Random, int par2, int par3, int par4, int par5)
    042        {
    043            StructureBoundingBox var6 = new StructureBoundingBox(par2, par3, par4, par2, par3 + 2, par4);
    044            int var7;
    045
    046            for (var7 = par1Random.nextInt(3) + 2; var7 > 0; --var7)
    047            {
    048                int var8 = var7 * 5;
    049
    050                switch (par5)
    051                {
    052                    case 0:
    053                        var6.maxX = par2 + 2;
    054                        var6.maxZ = par4 + (var8 - 1);
    055                        break;
    056                    case 1:
    057                        var6.minX = par2 - (var8 - 1);
    058                        var6.maxZ = par4 + 2;
    059                        break;
    060                    case 2:
    061                        var6.maxX = par2 + 2;
    062                        var6.minZ = par4 - (var8 - 1);
    063                        break;
    064                    case 3:
    065                        var6.maxX = par2 + (var8 - 1);
    066                        var6.maxZ = par4 + 2;
    067                }
    068
    069                if (StructureComponent.findIntersecting(par0List, var6) == null)
    070                {
    071                    break;
    072                }
    073            }
    074
    075            return var7 > 0 ? var6 : null;
    076        }
    077
    078        /**
    079         * Initiates construction of the Structure Component picked, at the current Location of StructGen
    080         */
    081        public void buildComponent(StructureComponent par1StructureComponent, List par2List, Random par3Random)
    082        {
    083            int var4 = this.getComponentType();
    084            int var5 = par3Random.nextInt(4);
    085
    086            switch (this.coordBaseMode)
    087            {
    088                case 0:
    089                    if (var5 <= 1)
    090                    {
    091                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.maxZ + 1, this.coordBaseMode, var4);
    092                    }
    093                    else if (var5 == 2)
    094                    {
    095                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.maxZ - 3, 1, var4);
    096                    }
    097                    else
    098                    {
    099                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.maxZ - 3, 3, var4);
    100                    }
    101
    102                    break;
    103                case 1:
    104                    if (var5 <= 1)
    105                    {
    106                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.minZ, this.coordBaseMode, var4);
    107                    }
    108                    else if (var5 == 2)
    109                    {
    110                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.minZ - 1, 2, var4);
    111                    }
    112                    else
    113                    {
    114                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.maxZ + 1, 0, var4);
    115                    }
    116
    117                    break;
    118                case 2:
    119                    if (var5 <= 1)
    120                    {
    121                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.minZ - 1, this.coordBaseMode, var4);
    122                    }
    123                    else if (var5 == 2)
    124                    {
    125                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.minZ, 1, var4);
    126                    }
    127                    else
    128                    {
    129                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.minZ, 3, var4);
    130                    }
    131
    132                    break;
    133                case 3:
    134                    if (var5 <= 1)
    135                    {
    136                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.minZ, this.coordBaseMode, var4);
    137                    }
    138                    else if (var5 == 2)
    139                    {
    140                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX - 3, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.minZ - 1, 2, var4);
    141                    }
    142                    else
    143                    {
    144                        StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX - 3, this.boundingBox.minY - 1 + par3Random.nextInt(3), this.boundingBox.maxZ + 1, 0, var4);
    145                    }
    146            }
    147
    148            if (var4 < 8)
    149            {
    150                int var6;
    151                int var7;
    152
    153                if (this.coordBaseMode != 2 && this.coordBaseMode != 0)
    154                {
    155                    for (var6 = this.boundingBox.minX + 3; var6 + 3 <= this.boundingBox.maxX; var6 += 5)
    156                    {
    157                        var7 = par3Random.nextInt(5);
    158
    159                        if (var7 == 0)
    160                        {
    161                            StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, var6, this.boundingBox.minY, this.boundingBox.minZ - 1, 2, var4 + 1);
    162                        }
    163                        else if (var7 == 1)
    164                        {
    165                            StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, var6, this.boundingBox.minY, this.boundingBox.maxZ + 1, 0, var4 + 1);
    166                        }
    167                    }
    168                }
    169                else
    170                {
    171                    for (var6 = this.boundingBox.minZ + 3; var6 + 3 <= this.boundingBox.maxZ; var6 += 5)
    172                    {
    173                        var7 = par3Random.nextInt(5);
    174
    175                        if (var7 == 0)
    176                        {
    177                            StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY, var6, 1, var4 + 1);
    178                        }
    179                        else if (var7 == 1)
    180                        {
    181                            StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY, var6, 3, var4 + 1);
    182                        }
    183                    }
    184                }
    185            }
    186        }
    187
    188        /**
    189         * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at
    190         * the end, it adds Fences...
    191         */
    192        public boolean addComponentParts(World par1World, Random par2Random, StructureBoundingBox par3StructureBoundingBox)
    193        {
    194            if (this.isLiquidInStructureBoundingBox(par1World, par3StructureBoundingBox))
    195            {
    196                return false;
    197            }
    198            else
    199            {
    200                int var8 = this.sectionCount * 5 - 1;
    201                this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 0, 0, 2, 1, var8, 0, 0, false);
    202                this.randomlyFillWithBlocks(par1World, par3StructureBoundingBox, par2Random, 0.8F, 0, 2, 0, 2, 2, var8, 0, 0, false);
    203
    204                if (this.hasSpiders)
    205                {
    206                    this.randomlyFillWithBlocks(par1World, par3StructureBoundingBox, par2Random, 0.6F, 0, 0, 0, 2, 1, var8, Block.web.blockID, 0, false);
    207                }
    208
    209                int var9;
    210                int var10;
    211                int var11;
    212
    213                for (var9 = 0; var9 < this.sectionCount; ++var9)
    214                {
    215                    var10 = 2 + var9 * 5;
    216                    this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 0, var10, 0, 1, var10, Block.fence.blockID, 0, false);
    217                    this.fillWithBlocks(par1World, par3StructureBoundingBox, 2, 0, var10, 2, 1, var10, Block.fence.blockID, 0, false);
    218
    219                    if (par2Random.nextInt(4) == 0)
    220                    {
    221                        this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 2, var10, 0, 2, var10, Block.planks.blockID, 0, false);
    222                        this.fillWithBlocks(par1World, par3StructureBoundingBox, 2, 2, var10, 2, 2, var10, Block.planks.blockID, 0, false);
    223                    }
    224                    else
    225                    {
    226                        this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 2, var10, 2, 2, var10, Block.planks.blockID, 0, false);
    227                    }
    228
    229                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.1F, 0, 2, var10 - 1, Block.web.blockID, 0);
    230                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.1F, 2, 2, var10 - 1, Block.web.blockID, 0);
    231                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.1F, 0, 2, var10 + 1, Block.web.blockID, 0);
    232                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.1F, 2, 2, var10 + 1, Block.web.blockID, 0);
    233                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.05F, 0, 2, var10 - 2, Block.web.blockID, 0);
    234                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.05F, 2, 2, var10 - 2, Block.web.blockID, 0);
    235                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.05F, 0, 2, var10 + 2, Block.web.blockID, 0);
    236                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.05F, 2, 2, var10 + 2, Block.web.blockID, 0);
    237                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.05F, 1, 2, var10 - 1, Block.torchWood.blockID, 0);
    238                    this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.05F, 1, 2, var10 + 1, Block.torchWood.blockID, 0);
    239
    240                    ChestGenHooks info = ChestGenHooks.getInfo(MINESHAFT_CORRIDOR);
    241
    242                    if (par2Random.nextInt(100) == 0)
    243                    {
    244                        this.generateStructureChestContents(par1World, par3StructureBoundingBox, par2Random, 2, 0, var10 - 1, info.getItems(), info.getCount(par2Random));
    245                    }
    246
    247                    if (par2Random.nextInt(100) == 0)
    248                    {
    249                        this.generateStructureChestContents(par1World, par3StructureBoundingBox, par2Random, 0, 0, var10 + 1, info.getItems(), info.getCount(par2Random));
    250                    }
    251
    252                    if (this.hasSpiders && !this.spawnerPlaced)
    253                    {
    254                        var11 = this.getYWithOffset(0);
    255                        int var12 = var10 - 1 + par2Random.nextInt(3);
    256                        int var13 = this.getXWithOffset(1, var12);
    257                        var12 = this.getZWithOffset(1, var12);
    258
    259                        if (par3StructureBoundingBox.isVecInside(var13, var11, var12))
    260                        {
    261                            this.spawnerPlaced = true;
    262                            par1World.setBlockWithNotify(var13, var11, var12, Block.mobSpawner.blockID);
    263                            TileEntityMobSpawner var14 = (TileEntityMobSpawner)par1World.getBlockTileEntity(var13, var11, var12);
    264
    265                            if (var14 != null)
    266                            {
    267                                var14.setMobID("CaveSpider");
    268                            }
    269                        }
    270                    }
    271                }
    272
    273                for (var9 = 0; var9 <= 2; ++var9)
    274                {
    275                    for (var10 = 0; var10 <= var8; ++var10)
    276                    {
    277                        var11 = this.getBlockIdAtCurrentPosition(par1World, var9, -1, var10, par3StructureBoundingBox);
    278
    279                        if (var11 == 0)
    280                        {
    281                            this.placeBlockAtCurrentPosition(par1World, Block.planks.blockID, 0, var9, -1, var10, par3StructureBoundingBox);
    282                        }
    283                    }
    284                }
    285
    286                if (this.hasRails)
    287                {
    288                    for (var9 = 0; var9 <= var8; ++var9)
    289                    {
    290                        var10 = this.getBlockIdAtCurrentPosition(par1World, 1, -1, var9, par3StructureBoundingBox);
    291
    292                        if (var10 > 0 && Block.opaqueCubeLookup[var10])
    293                        {
    294                            this.randomlyPlaceBlock(par1World, par3StructureBoundingBox, par2Random, 0.7F, 1, 0, var9, Block.rail.blockID, this.getMetadataWithOffset(Block.rail.blockID, 0));
    295                        }
    296                    }
    297                }
    298
    299                return true;
    300            }
    301        }
    302    }