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