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.util.MathHelper;
007 import net.minecraft.world.World;
008
009 public class ComponentVillageField2 extends ComponentVillage
010 {
011 private int averageGroundLevel = -1;
012 private int field_82675_b;
013 private int field_82676_c;
014
015 public ComponentVillageField2(ComponentVillageStartPiece par1ComponentVillageStartPiece, int par2, Random par3Random, StructureBoundingBox par4StructureBoundingBox, int par5)
016 {
017 super(par1ComponentVillageStartPiece, par2);
018 this.coordBaseMode = par5;
019 this.boundingBox = par4StructureBoundingBox;
020 this.field_82675_b = this.pickRandomCrop(par3Random);
021 this.field_82676_c = this.pickRandomCrop(par3Random);
022 }
023
024 /**
025 * Returns a crop type to be planted on this field.
026 */
027 private int pickRandomCrop(Random par1Random)
028 {
029 switch (par1Random.nextInt(5))
030 {
031 case 0:
032 return Block.carrot.blockID;
033 case 1:
034 return Block.potato.blockID;
035 default:
036 return Block.crops.blockID;
037 }
038 }
039
040 public static ComponentVillageField2 func_74902_a(ComponentVillageStartPiece par0ComponentVillageStartPiece, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
041 {
042 StructureBoundingBox var8 = StructureBoundingBox.getComponentToAddBoundingBox(par3, par4, par5, 0, 0, 0, 7, 4, 9, par6);
043 return canVillageGoDeeper(var8) && StructureComponent.findIntersecting(par1List, var8) == null ? new ComponentVillageField2(par0ComponentVillageStartPiece, par7, par2Random, var8, par6) : null;
044 }
045
046 /**
047 * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at
048 * the end, it adds Fences...
049 */
050 public boolean addComponentParts(World par1World, Random par2Random, StructureBoundingBox par3StructureBoundingBox)
051 {
052 if (this.averageGroundLevel < 0)
053 {
054 this.averageGroundLevel = this.getAverageGroundLevel(par1World, par3StructureBoundingBox);
055
056 if (this.averageGroundLevel < 0)
057 {
058 return true;
059 }
060
061 this.boundingBox.offset(0, this.averageGroundLevel - this.boundingBox.maxY + 4 - 1, 0);
062 }
063
064 this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 1, 0, 6, 4, 8, 0, 0, false);
065 this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 0, 1, 2, 0, 7, Block.tilledField.blockID, Block.tilledField.blockID, false);
066 this.fillWithBlocks(par1World, par3StructureBoundingBox, 4, 0, 1, 5, 0, 7, Block.tilledField.blockID, Block.tilledField.blockID, false);
067 this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 0, 0, 0, 0, 8, Block.wood.blockID, Block.wood.blockID, false);
068 this.fillWithBlocks(par1World, par3StructureBoundingBox, 6, 0, 0, 6, 0, 8, Block.wood.blockID, Block.wood.blockID, false);
069 this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 0, 0, 5, 0, 0, Block.wood.blockID, Block.wood.blockID, false);
070 this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 0, 8, 5, 0, 8, Block.wood.blockID, Block.wood.blockID, false);
071 this.fillWithBlocks(par1World, par3StructureBoundingBox, 3, 0, 1, 3, 0, 7, Block.waterMoving.blockID, Block.waterMoving.blockID, false);
072 int var4;
073
074 for (var4 = 1; var4 <= 7; ++var4)
075 {
076 this.placeBlockAtCurrentPosition(par1World, this.field_82675_b, MathHelper.getRandomIntegerInRange(par2Random, 2, 7), 1, 1, var4, par3StructureBoundingBox);
077 this.placeBlockAtCurrentPosition(par1World, this.field_82675_b, MathHelper.getRandomIntegerInRange(par2Random, 2, 7), 2, 1, var4, par3StructureBoundingBox);
078 this.placeBlockAtCurrentPosition(par1World, this.field_82676_c, MathHelper.getRandomIntegerInRange(par2Random, 2, 7), 4, 1, var4, par3StructureBoundingBox);
079 this.placeBlockAtCurrentPosition(par1World, this.field_82676_c, MathHelper.getRandomIntegerInRange(par2Random, 2, 7), 5, 1, var4, par3StructureBoundingBox);
080 }
081
082 for (var4 = 0; var4 < 9; ++var4)
083 {
084 for (int var5 = 0; var5 < 7; ++var5)
085 {
086 this.clearCurrentPositionBlocksUpwards(par1World, var5, 4, var4, par3StructureBoundingBox);
087 this.fillCurrentPositionBlocksDownwards(par1World, Block.dirt.blockID, 0, var5, -1, var4, par3StructureBoundingBox);
088 }
089 }
090
091 return true;
092 }
093 }