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