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